From 225b1d2d768ca415355ea0f5daba9f92e1a93121 Mon Sep 17 00:00:00 2001 From: William Tumeo Date: Wed, 29 Mar 2017 02:16:26 -0300 Subject: [PATCH 1/5] Re-add script button from b77200728e7f2b2dd446a9717c83a20c9aac0ce4 --- editor/scene_tree_dock.cpp | 17 ++++++++++++++++- editor/scene_tree_dock.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 8c2aa4097f2..0d0dbc64147 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -675,6 +675,7 @@ 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")); @@ -1239,11 +1240,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); } @@ -1779,6 +1787,13 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel filter_icon->set_stretch_mode(TextureFrame::STRETCH_KEEP_CENTERED); 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)); vbc->add_child(scene_tree); scene_tree->set_v_size_flags(SIZE_EXPAND | SIZE_FILL); diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h index e651c59d664..c6331c8241a 100644 --- a/editor/scene_tree_dock.h +++ b/editor/scene_tree_dock.h @@ -76,6 +76,7 @@ class SceneTreeDock : public VBoxContainer { ToolButton *button_add; ToolButton *button_instance; + ToolButton *button_create_script; SceneTreeEditor *scene_tree; From 95f747ec9321a484fa97b3f492d783a2be028f66 Mon Sep 17 00:00:00 2001 From: William Tumeo Date: Wed, 29 Mar 2017 03:46:35 -0300 Subject: [PATCH 2/5] Re-add create/load script button and context menu - create from f51b202566e9b2a9deb3eb4836f6e00fb30e8500 - load from 41329f9750379b3c2e506d1e9ed7f6195c812920 --- editor/property_editor.cpp | 12 ++++++- editor/property_editor.h | 1 + editor/scene_tree_dock.cpp | 66 +++++++++++++++++++++++++++++++++++--- editor/scene_tree_dock.h | 8 ++++- 4 files changed, 81 insertions(+), 6 deletions(-) diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 8ab85f072e1..33f50a99c87 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -194,6 +194,12 @@ void CustomPropertyEditor::_menu_option(int p_which) { } } } break; + case OBJ_MENU_NEW_SCRIPT: { + + if (owner->cast_to()) + EditorNode::get_singleton()->get_scene_tree_dock()->open_script_dialog(owner->cast_to()); + + } break; default: { ERR_FAIL_COND(inheritors_array.empty()); @@ -212,6 +218,7 @@ void CustomPropertyEditor::_menu_option(int p_which) { } } break; + default: {} } } @@ -647,7 +654,10 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: menu->clear(); menu->set_size(Size2(1, 1)); - if (hint_text != "") { + if (p_name=="script/script" && hint_text=="Script" && owner->cast_to()) { + menu->add_icon_item(get_icon("Script","EditorIcons"),TTR("New Script"),OBJ_MENU_NEW_SCRIPT); + menu->add_separator(); + } else if (hint_text!="") { int idx = 0; for (int i = 0; i < hint_text.get_slice_count(","); i++) { diff --git a/editor/property_editor.h b/editor/property_editor.h index 52fe6dbaf3e..a585315f093 100644 --- a/editor/property_editor.h +++ b/editor/property_editor.h @@ -63,6 +63,7 @@ class CustomPropertyEditor : public Popup { OBJ_MENU_COPY = 4, OBJ_MENU_PASTE = 5, OBJ_MENU_REIMPORT = 6, + OBJ_MENU_NEW_SCRIPT=7, TYPE_BASE_ID = 100 }; diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 0d0dbc64147..34532fde764 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -58,7 +58,9 @@ void SceneTreeDock::_unhandled_key_input(InputEvent p_event) { } else if (ED_IS_SHORTCUT("scene_tree/duplicate", p_event)) { _tool_selected(TOOL_DUPLICATE); } else if (ED_IS_SHORTCUT("scene_tree/add_script", p_event)) { - _tool_selected(TOOL_SCRIPT); + _tool_selected(TOOL_CREATE_SCRIPT); + } else if (ED_IS_SHORTCUT("scene_tree/load_script", p_event)) { + _tool_selected(TOOL_LOAD_SCRIPT); } else if (ED_IS_SHORTCUT("scene_tree/move_up", p_event)) { _tool_selected(TOOL_MOVE_UP); } else if (ED_IS_SHORTCUT("scene_tree/move_down", p_event)) { @@ -228,6 +230,23 @@ void SceneTreeDock::_replace_with_branch_scene(const String &p_file, Node *base) scene_tree->set_selected(instanced_scene); } +void SceneTreeDock::_file_selected(String p_file) { + RES p_script = ResourceLoader::load(p_file, "Script"); + if (p_script.is_null()) { + accept->get_ok()->set_text(TTR("Ugh")); + accept->set_text(vformat(TTR("Error loading script from %s"), p_file)); + accept->popup_centered_minsize(); + return; + } + + Node *selected = scene_tree->get_selected(); + if (!selected) + return; + selected->set_script(p_script.get_ref_ptr()); + editor->push_item(p_script.operator->()); + file_dialog->hide(); +} + bool SceneTreeDock::_cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node) { int childCount = p_desired_node->get_child_count(); @@ -328,7 +347,22 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { //groups_editor->set_current(current); //groups_editor->popup_centered_ratio(); } break; - case TOOL_SCRIPT: { + case TOOL_LOAD_SCRIPT: { + Node *selected = scene_tree->get_selected(); + if (!selected) + break; + + file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE); + + List extensions; + ResourceLoader::get_recognized_extensions_for_type("Script", &extensions); + file_dialog->clear_filters(); + for (List::Element *E = extensions.front(); E; E = E->next()) + file_dialog->add_filter("*." + E->get() + " ; " + E->get().to_upper()); + + file_dialog->popup_centered_ratio(); + } break; + case TOOL_CREATE_SCRIPT: { Node *selected = scene_tree->get_selected(); if (!selected) @@ -676,6 +710,7 @@ 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")); + button_load_script->set_icon(get_icon("Script", "EditorIcons")); filter_icon->set_texture(get_icon("Zoom", "EditorIcons")); @@ -1248,8 +1283,10 @@ void SceneTreeDock::_selection_changed() { if (selection_size==1 && EditorNode::get_singleton()->get_editor_selection()->get_selection().front()->key()->get_script().is_null()) { button_create_script->show(); + button_load_script->show(); } else { button_create_script->hide(); + button_load_script->hide(); } //tool_buttons[TOOL_MULTI_EDIT]->set_disabled(EditorNode::get_singleton()->get_editor_selection()->get_selection().size()<2); @@ -1671,7 +1708,8 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { //menu->add_icon_item(get_icon("Groups","EditorIcons"),TTR("Edit Groups"),TOOL_GROUP); //menu->add_icon_item(get_icon("Connect","EditorIcons"),TTR("Edit Connections"),TOOL_CONNECT); menu->add_separator(); - menu->add_icon_shortcut(get_icon("Script", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_script"), TOOL_SCRIPT); + menu->add_icon_shortcut(get_icon("Script", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_script"), TOOL_CREATE_SCRIPT); + menu->add_icon_shortcut(get_icon("Script", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/load_script"), TOOL_LOAD_SCRIPT); menu->add_separator(); } @@ -1710,6 +1748,12 @@ void SceneTreeDock::set_filter(const String &p_filter) { scene_tree->set_filter(p_filter); } +void SceneTreeDock::open_script_dialog(Node* p_for_node) { + + scene_tree->set_selected(p_for_node,false); + _tool_selected(TOOL_CREATE_SCRIPT); +} + void SceneTreeDock::_bind_methods() { ObjectTypeDB::bind_method(_MD("_tool_selected"), &SceneTreeDock::_tool_selected, DEFVAL(false)); @@ -1733,6 +1777,7 @@ void SceneTreeDock::_bind_methods() { ObjectTypeDB::bind_method(_MD("_script_dropped"), &SceneTreeDock::_script_dropped); ObjectTypeDB::bind_method(_MD("_tree_rmb"), &SceneTreeDock::_tree_rmb); ObjectTypeDB::bind_method(_MD("_filter_changed"), &SceneTreeDock::_filter_changed); + ObjectTypeDB::bind_method(_MD("_file_selected"), &SceneTreeDock::_file_selected); ObjectTypeDB::bind_method(_MD("instance"), &SceneTreeDock::instance); } @@ -1754,6 +1799,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel ED_SHORTCUT("scene_tree/instance_scene", TTR("Instance Child Scene")); ED_SHORTCUT("scene_tree/change_node_type", TTR("Change Type")); ED_SHORTCUT("scene_tree/add_script", TTR("Add Script")); + ED_SHORTCUT("scene_tree/load_script", TTR("Load Script")); ED_SHORTCUT("scene_tree/move_up", TTR("Move Up"), KEY_MASK_CMD | KEY_UP); ED_SHORTCUT("scene_tree/move_down", TTR("Move Down"), KEY_MASK_CMD | KEY_DOWN); ED_SHORTCUT("scene_tree/duplicate", TTR("Duplicate"), KEY_MASK_CMD | KEY_D); @@ -1788,12 +1834,19 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel filter->connect("text_changed", this, "_filter_changed"); tb = memnew(ToolButton); - tb->connect("pressed", this, "_tool_selected", make_binds(TOOL_SCRIPT, false)); + tb->connect("pressed", this, "_tool_selected", make_binds(TOOL_CREATE_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; + tb = memnew(ToolButton); + tb->connect("pressed", this, "_tool_selected", make_binds(TOOL_LOAD_SCRIPT, false)); + tb->set_tooltip(TTR("Load a script for the selected node.")); + tb->set_shortcut(ED_GET_SHORTCUT("scene_tree/load_script")); + filter_hbc->add_child(tb); + button_load_script = tb; + scene_tree = memnew(SceneTreeEditor(false, true, true)); vbc->add_child(scene_tree); scene_tree->set_v_size_flags(SIZE_EXPAND | SIZE_FILL); @@ -1816,6 +1869,11 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel add_child(create_dialog); create_dialog->connect("create", this, "_create"); + file_dialog = memnew(EditorFileDialog); + add_child(file_dialog); + file_dialog->hide(); + file_dialog->connect("file_selected", this, "_file_selected"); + //groups_editor = memnew( GroupsEditor ); //add_child(groups_editor); //groups_editor->set_undo_redo(&editor_data->get_undo_redo()); diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h index c6331c8241a..3905023fa3e 100644 --- a/editor/scene_tree_dock.h +++ b/editor/scene_tree_dock.h @@ -58,7 +58,8 @@ class SceneTreeDock : public VBoxContainer { TOOL_REPLACE, TOOL_CONNECT, TOOL_GROUP, - TOOL_SCRIPT, + TOOL_CREATE_SCRIPT, + TOOL_LOAD_SCRIPT, TOOL_MOVE_UP, TOOL_MOVE_DOWN, TOOL_DUPLICATE, @@ -73,10 +74,12 @@ class SceneTreeDock : public VBoxContainer { int current_option; CreateDialog *create_dialog; + EditorFileDialog *file_dialog; ToolButton *button_add; ToolButton *button_instance; ToolButton *button_create_script; + ToolButton *button_load_script; SceneTreeEditor *scene_tree; @@ -151,6 +154,8 @@ class SceneTreeDock : public VBoxContainer { void _perform_instance_scenes(const Vector &p_files, Node *parent, int p_pos); void _replace_with_branch_scene(const String &p_file, Node *base); + void _file_selected(String p_file); + protected: void _notification(int p_what); static void _bind_methods(); @@ -169,6 +174,7 @@ public: SceneTreeEditor *get_tree_editor() { return scene_tree; } EditorData *get_editor_data() { return editor_data; } + void open_script_dialog(Node* p_for_node); SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSelection *p_editor_selection, EditorData &p_editor_data); }; From 5d8d51719a3c1a2bf4928063cfa23d89ec06ff07 Mon Sep 17 00:00:00 2001 From: William Tumeo Date: Wed, 29 Mar 2017 04:06:53 -0300 Subject: [PATCH 3/5] Re-add script icons from 544194053a54870320d860f1cf333f45723758b9 --- editor/icons/2x/icon_script_create.png | Bin 0 -> 541 bytes editor/icons/icon_script_create.png | Bin 0 -> 341 bytes editor/icons/source/icon_script_create.svg | 96 +++++++++++++++++++++ editor/scene_tree_dock.cpp | 4 +- 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 editor/icons/2x/icon_script_create.png create mode 100644 editor/icons/icon_script_create.png create mode 100644 editor/icons/source/icon_script_create.svg diff --git a/editor/icons/2x/icon_script_create.png b/editor/icons/2x/icon_script_create.png new file mode 100644 index 0000000000000000000000000000000000000000..67f80e8760f28629ed51ba871edc4ec39fdd15d1 GIT binary patch literal 541 zcmV+&0^qaW|RF9-j-M4O;AP0y54 zH$sRjDP`dMK4BQ*d0v;Z3gE7)s_Q6c=< z4%dMujYgwZ{iW8w=RmF1YW27|ZgS?$9XJ9!<-mMCf7}(gt*+VLr1#@Mt?df8uhws8 zd)K%(ci;%HnF9q7SZnW%F`ogfwE#%j%-M7sI#)s=#2vtLxy-G#_tsk0>oovD5VZK0 zetL31N_kzD<)w4(BFnPh0a_D=;U5c|vbuLSoKB~ibM73t1s2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR4d+lKZ9@l>RHE(#AFciI4D?U=3vTV9}dxOp+Mi%9DOiK!0JFVZo9DN z#P;b;{8M$9@BNl75D-l6S*YXv_AciQ>*swdC;eHu>Q&O(rSE@lJ!a-PiP>SDYWJcI z4390=Ejlh?&LDNr`w~Z5*6p&gyjf|_ZqH|Zwd>!Ugh|Ek5|ckHVpnXDaO%hxzc7Wl z;{D=jF^B6k7|ah(Tc + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 34532fde764..48ae4d63310 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -709,7 +709,7 @@ 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")); + button_create_script->set_icon(get_icon("ScriptCreate","EditorIcons")); button_load_script->set_icon(get_icon("Script", "EditorIcons")); filter_icon->set_texture(get_icon("Zoom", "EditorIcons")); @@ -1708,7 +1708,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { //menu->add_icon_item(get_icon("Groups","EditorIcons"),TTR("Edit Groups"),TOOL_GROUP); //menu->add_icon_item(get_icon("Connect","EditorIcons"),TTR("Edit Connections"),TOOL_CONNECT); menu->add_separator(); - menu->add_icon_shortcut(get_icon("Script", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_script"), TOOL_CREATE_SCRIPT); + menu->add_icon_shortcut(get_icon("ScriptCreate", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_script"), TOOL_CREATE_SCRIPT); menu->add_icon_shortcut(get_icon("Script", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/load_script"), TOOL_LOAD_SCRIPT); menu->add_separator(); } From 1307ff7eb16ecef8683ad8ebda8bfb0338e5204c Mon Sep 17 00:00:00 2001 From: William Tumeo Date: Wed, 29 Mar 2017 17:23:49 -0300 Subject: [PATCH 4/5] Re-add clear script button and context menu from ce5200b30e6d262905912c6571d51ba6f5979bd7 --- editor/scene_tree_dock.cpp | 39 +++++++++++++++++++++++++++++++++++--- editor/scene_tree_dock.h | 2 ++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 48ae4d63310..905f82cc37e 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -61,6 +61,8 @@ void SceneTreeDock::_unhandled_key_input(InputEvent p_event) { _tool_selected(TOOL_CREATE_SCRIPT); } else if (ED_IS_SHORTCUT("scene_tree/load_script", p_event)) { _tool_selected(TOOL_LOAD_SCRIPT); + } else if(ED_IS_SHORTCUT("scene_tree/clear_script", p_event)) { + _tool_selected(TOOL_CLEAR_SCRIPT); } else if (ED_IS_SHORTCUT("scene_tree/move_up", p_event)) { _tool_selected(TOOL_MOVE_UP); } else if (ED_IS_SHORTCUT("scene_tree/move_down", p_event)) { @@ -381,6 +383,18 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { //script_create_dialog->popup_centered_minsize(); } + } break; + case TOOL_CLEAR_SCRIPT: { + Node *selected = scene_tree->get_selected(); + if(!selected) + break; + + Ref