diff options
Diffstat (limited to 'tools/editor/scene_tree_dock.cpp')
-rw-r--r-- | tools/editor/scene_tree_dock.cpp | 79 |
1 files changed, 71 insertions, 8 deletions
diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp index 35ddb49465..506dfd3889 100644 --- a/tools/editor/scene_tree_dock.cpp +++ b/tools/editor/scene_tree_dock.cpp @@ -33,6 +33,7 @@ #include "scene/resources/packed_scene.h" #include "editor_settings.h" #include "tools/editor/plugins/canvas_item_editor_plugin.h" +#include "tools/editor/plugins/spatial_editor_plugin.h" #include "script_editor_debugger.h" #include "tools/editor/plugins/script_editor_plugin.h" #include "core/io/resource_saver.h" @@ -42,17 +43,31 @@ #include "scene/main/viewport.h" +void SceneTreeDock::_nodes_drag_begin() { + + + if (restore_script_editor_on_drag) { + EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT); + restore_script_editor_on_drag=false; + } + +} + +void SceneTreeDock::_input(InputEvent p_event) { + + if (p_event.type==InputEvent::MOUSE_BUTTON && !p_event.mouse_button.pressed && p_event.mouse_button.button_index==BUTTON_LEFT) { + restore_script_editor_on_drag=false; //lost chance + } +} void SceneTreeDock::_unhandled_key_input(InputEvent p_event) { if (get_viewport()->get_modal_stack_top()) return; //ignore because of modal window - uint32_t sc = p_event.key.get_scancode_with_modifiers(); if (!p_event.key.pressed || p_event.key.echo) return; - if (ED_IS_SHORTCUT("scene_tree/add_child_node", p_event)) { _tool_selected(TOOL_NEW); } @@ -83,9 +98,11 @@ void SceneTreeDock::_unhandled_key_input(InputEvent p_event) { else if (ED_IS_SHORTCUT("scene_tree/save_branch_as_scene", p_event)) { _tool_selected(TOOL_NEW_SCENE_FROM); } - switch(sc) { - case KEY_MASK_SHIFT|KEY_DELETE: { _tool_selected(TOOL_ERASE, true); } break; - case KEY_DELETE: { _tool_selected(TOOL_ERASE); } break; + else if (ED_IS_SHORTCUT("scene_tree/delete_no_confirm", p_event)) { + _tool_selected(TOOL_ERASE, true); + } + else if (ED_IS_SHORTCUT("scene_tree/delete", p_event)) { + _tool_selected(TOOL_ERASE); } } @@ -667,6 +684,8 @@ void SceneTreeDock::_notification(int p_what) { } button_add->set_icon(get_icon("Add","EditorIcons")); button_instance->set_icon(get_icon("Instance","EditorIcons")); + button_create_script->set_icon(get_icon("Script","EditorIcons")); + filter_icon->set_texture(get_icon("Zoom","EditorIcons")); @@ -698,7 +717,13 @@ void SceneTreeDock::_node_selected() { return; } + if (ScriptEditor::get_singleton()->is_visible()) { + restore_script_editor_on_drag=true; + } + editor->push_item(node); + + } void SceneTreeDock::_node_renamed() { @@ -1280,11 +1305,18 @@ void SceneTreeDock::_delete_confirm() { void SceneTreeDock::_selection_changed() { - if (EditorNode::get_singleton()->get_editor_selection()->get_selection().size()>1) { + int selection_size = EditorNode::get_singleton()->get_editor_selection()->get_selection().size(); + if (selection_size>1) { //automatically turn on multi-edit _tool_selected(TOOL_MULTI_EDIT); } + if (selection_size==1 && EditorNode::get_singleton()->get_editor_selection()->get_selection().front()->key()->get_script().is_null()) { + button_create_script->show(); + } else { + button_create_script->hide(); + } + //tool_buttons[TOOL_MULTI_EDIT]->set_disabled(EditorNode::get_singleton()->get_editor_selection()->get_selection().size()<2); } @@ -1769,7 +1801,7 @@ void SceneTreeDock::_tree_rmb(const Vector2& p_menu_pos) { } menu->add_separator(); - menu->add_icon_item(get_icon("Remove","EditorIcons"),TTR("Delete Node(s)"), TOOL_ERASE, KEY_DELETE); + menu->add_icon_shortcut(get_icon("Remove","EditorIcons"), ED_SHORTCUT("scene_tree/delete", TTR("Delete Node(s)"), KEY_DELETE), TOOL_ERASE); menu->set_size(Size2(1,1)); menu->set_pos(p_menu_pos); @@ -1794,6 +1826,21 @@ void SceneTreeDock::set_filter(const String& p_filter){ scene_tree->set_filter(p_filter); } + +void SceneTreeDock::_focus_node() { + + Node *node = scene_tree->get_selected(); + ERR_FAIL_COND(!node); + + if (node->is_type("CanvasItem")) { + CanvasItemEditorPlugin *editor = editor_data->get_editor("2D")->cast_to<CanvasItemEditorPlugin>(); + editor->get_canvas_item_editor()->focus_selection(); + } else { + SpatialEditorPlugin *editor = editor_data->get_editor("3D")->cast_to<SpatialEditorPlugin>(); + editor->get_spatial_editor()->get_editor_viewport(0)->focus_selection(); + } +} + void SceneTreeDock::_bind_methods() { ObjectTypeDB::bind_method(_MD("_tool_selected"),&SceneTreeDock::_tool_selected,DEFVAL(false)); @@ -1807,6 +1854,8 @@ void SceneTreeDock::_bind_methods() { ObjectTypeDB::bind_method(_MD("_load_request"),&SceneTreeDock::_load_request); ObjectTypeDB::bind_method(_MD("_script_open_request"),&SceneTreeDock::_script_open_request); ObjectTypeDB::bind_method(_MD("_unhandled_key_input"),&SceneTreeDock::_unhandled_key_input); + ObjectTypeDB::bind_method(_MD("_input"),&SceneTreeDock::_input); + ObjectTypeDB::bind_method(_MD("_nodes_drag_begin"),&SceneTreeDock::_nodes_drag_begin); ObjectTypeDB::bind_method(_MD("_delete_confirm"),&SceneTreeDock::_delete_confirm); ObjectTypeDB::bind_method(_MD("_node_prerenamed"),&SceneTreeDock::_node_prerenamed); ObjectTypeDB::bind_method(_MD("_import_subscene"),&SceneTreeDock::_import_subscene); @@ -1816,6 +1865,7 @@ void SceneTreeDock::_bind_methods() { ObjectTypeDB::bind_method(_MD("_files_dropped"),&SceneTreeDock::_files_dropped); ObjectTypeDB::bind_method(_MD("_tree_rmb"),&SceneTreeDock::_tree_rmb); ObjectTypeDB::bind_method(_MD("_filter_changed"),&SceneTreeDock::_filter_changed); + ObjectTypeDB::bind_method(_MD("_focus_node"),&SceneTreeDock::_focus_node); ObjectTypeDB::bind_method(_MD("instance"),&SceneTreeDock::instance); @@ -1846,6 +1896,8 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec ED_SHORTCUT("scene_tree/reparent", TTR("Reparent")); ED_SHORTCUT("scene_tree/merge_from_scene", TTR("Merge From Scene")); ED_SHORTCUT("scene_tree/save_branch_as_scene", TTR("Save Branch as Scene")); + ED_SHORTCUT("scene_tree/delete_no_confirm", TTR("Delete (No Confirm)"), KEY_MASK_SHIFT|KEY_DELETE); + ED_SHORTCUT("scene_tree/delete", TTR("Delete"), KEY_DELETE); tb = memnew( ToolButton ); tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_NEW, false)); @@ -1873,6 +1925,12 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec filter->connect("text_changed",this,"_filter_changed"); + tb = memnew( ToolButton ); + tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_SCRIPT, false)); + tb->set_tooltip(TTR("Create a new script for the selected node.")); + tb->set_shortcut(ED_GET_SHORTCUT("scene_tree/add_script")); + filter_hbc->add_child(tb); + button_create_script=tb; scene_tree = memnew( SceneTreeEditor(false,true,true )); @@ -1887,6 +1945,10 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec scene_tree->connect("open_script",this,"_script_open_request"); scene_tree->connect("nodes_rearranged",this,"_nodes_dragged"); scene_tree->connect("files_dropped",this,"_files_dropped"); + scene_tree->connect("nodes_dragged",this,"_nodes_drag_begin"); + + scene_tree->get_scene_tree()->connect("item_double_clicked", this, "_focus_node"); + scene_tree->get_scene_tree()->set_delayed_text_editor(true); scene_tree->set_undo_redo(&editor_data->get_undo_redo()); scene_tree->set_editor_selection(editor_selection); @@ -1939,7 +2001,8 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec add_child(menu); menu->connect("item_pressed",this,"_tool_selected"); first_enter=true; - + restore_script_editor_on_drag=false; vbc->add_constant_override("separation",4); + set_process_input(true); } |