diff options
Diffstat (limited to 'editor/scene_tree_editor.cpp')
-rw-r--r-- | editor/scene_tree_editor.cpp | 109 |
1 files changed, 43 insertions, 66 deletions
diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp index dc5eb4bbd0..ff8eaa8897 100644 --- a/editor/scene_tree_editor.cpp +++ b/editor/scene_tree_editor.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -32,9 +32,10 @@ #include "core/message_queue.h" #include "core/print_string.h" +#include "editor/editor_node.h" +#include "editor/node_dock.h" #include "editor/plugins/animation_player_editor_plugin.h" #include "editor/plugins/canvas_item_editor_plugin.h" -#include "editor_node.h" #include "scene/gui/label.h" #include "scene/main/viewport.h" #include "scene/resources/packed_scene.h" @@ -69,10 +70,9 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i emit_signal("open", n->get_filename()); } } else if (p_id == BUTTON_SCRIPT) { - RefPtr script = n->get_script(); - Ref<Script> script_typed = script; + Ref<Script> script_typed = n->get_script(); if (!script_typed.is_null()) - emit_signal("open_script", script); + emit_signal("open_script", script_typed); } else if (p_id == BUTTON_VISIBILITY) { undo_redo->create_action(TTR("Toggle Visible")); @@ -186,25 +186,17 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { TreeItem *item = tree->create_item(p_parent); item->set_text(0, p_node->get_name()); - if (can_rename && !part_of_subscene /*(p_node->get_owner() == get_scene_node() || p_node==get_scene_node())*/) + if (can_rename && !part_of_subscene) item->set_editable(0, true); item->set_selectable(0, true); if (can_rename) { -#ifndef DISABLE_DEPRECATED - if (p_node->has_meta("_editor_collapsed")) { - //remove previous way of storing folding, which did not get along with scene inheritance and instancing - if ((bool)p_node->get_meta("_editor_collapsed")) - p_node->set_display_folded(true); - p_node->set_meta("_editor_collapsed", Variant()); - } -#endif bool collapsed = p_node->is_displayed_folded(); if (collapsed) item->set_collapsed(true); } - Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(p_node, "Node"); + Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(p_node, "Node"); item->set_icon(0, icon); item->set_metadata(0, p_node->get_path()); @@ -331,8 +323,8 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { if (can_open_instance && undo_redo) { //Show buttons only when necessary(SceneTreeDock) to avoid crashes - if (!p_node->is_connected("script_changed", this, "_node_script_changed")) - p_node->connect("script_changed", this, "_node_script_changed", varray(p_node)); + if (!p_node->is_connected_compat("script_changed", this, "_node_script_changed")) + p_node->connect_compat("script_changed", this, "_node_script_changed", varray(p_node)); Ref<Script> script = p_node->get_script(); if (!script.is_null()) { @@ -358,8 +350,8 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { else item->add_button(0, get_icon("GuiVisibilityHidden", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility")); - if (!p_node->is_connected("visibility_changed", this, "_node_visibility_changed")) - p_node->connect("visibility_changed", this, "_node_visibility_changed", varray(p_node)); + if (!p_node->is_connected_compat("visibility_changed", this, "_node_visibility_changed")) + p_node->connect_compat("visibility_changed", this, "_node_visibility_changed", varray(p_node)); _update_visibility_color(p_node, item); } else if (p_node->is_class("Spatial")) { @@ -378,8 +370,8 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { else item->add_button(0, get_icon("GuiVisibilityHidden", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility")); - if (!p_node->is_connected("visibility_changed", this, "_node_visibility_changed")) - p_node->connect("visibility_changed", this, "_node_visibility_changed", varray(p_node)); + if (!p_node->is_connected_compat("visibility_changed", this, "_node_visibility_changed")) + p_node->connect_compat("visibility_changed", this, "_node_visibility_changed", varray(p_node)); _update_visibility_color(p_node, item); } else if (p_node->is_class("AnimationPlayer")) { @@ -496,21 +488,6 @@ void SceneTreeEditor::_node_script_changed(Node *p_node) { MessageQueue::get_singleton()->push_call(this, "_update_tree"); tree_dirty = true; - /* - changes the order :| - TreeItem* item=p_node?_find(tree->get_root(),p_node->get_path()):NULL; - if (p_node->get_script().is_null()) { - - int idx=item->get_button_by_id(0,2); - if (idx>=0) - item->erase_button(0,idx); - } else { - - int idx=item->get_button_by_id(0,2); - if (idx<0) - item->add_button(0,get_icon("Script","EditorIcons"),2); - - }*/ } void SceneTreeEditor::_node_removed(Node *p_node) { @@ -518,12 +495,12 @@ void SceneTreeEditor::_node_removed(Node *p_node) { if (EditorNode::get_singleton()->is_exiting()) return; //speed up exit - if (p_node->is_connected("script_changed", this, "_node_script_changed")) - p_node->disconnect("script_changed", this, "_node_script_changed"); + if (p_node->is_connected_compat("script_changed", this, "_node_script_changed")) + p_node->disconnect_compat("script_changed", this, "_node_script_changed"); if (p_node->is_class("Spatial") || p_node->is_class("CanvasItem")) { - if (p_node->is_connected("visibility_changed", this, "_node_visibility_changed")) - p_node->disconnect("visibility_changed", this, "_node_visibility_changed"); + if (p_node->is_connected_compat("visibility_changed", this, "_node_visibility_changed")) + p_node->disconnect_compat("visibility_changed", this, "_node_visibility_changed"); } if (p_node == selected) { @@ -663,22 +640,22 @@ void SceneTreeEditor::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - get_tree()->connect("tree_changed", this, "_tree_changed"); - get_tree()->connect("node_removed", this, "_node_removed"); - get_tree()->connect("node_renamed", this, "_node_renamed"); - get_tree()->connect("node_configuration_warning_changed", this, "_warning_changed"); + get_tree()->connect_compat("tree_changed", this, "_tree_changed"); + get_tree()->connect_compat("node_removed", this, "_node_removed"); + get_tree()->connect_compat("node_renamed", this, "_node_renamed"); + get_tree()->connect_compat("node_configuration_warning_changed", this, "_warning_changed"); - tree->connect("item_collapsed", this, "_cell_collapsed"); + tree->connect_compat("item_collapsed", this, "_cell_collapsed"); _update_tree(); } break; case NOTIFICATION_EXIT_TREE: { - get_tree()->disconnect("tree_changed", this, "_tree_changed"); - get_tree()->disconnect("node_removed", this, "_node_removed"); - get_tree()->disconnect("node_renamed", this, "_node_renamed"); - tree->disconnect("item_collapsed", this, "_cell_collapsed"); - get_tree()->disconnect("node_configuration_warning_changed", this, "_warning_changed"); + get_tree()->disconnect_compat("tree_changed", this, "_tree_changed"); + get_tree()->disconnect_compat("node_removed", this, "_node_removed"); + get_tree()->disconnect_compat("node_renamed", this, "_node_renamed"); + tree->disconnect_compat("item_collapsed", this, "_cell_collapsed"); + get_tree()->disconnect_compat("node_configuration_warning_changed", this, "_warning_changed"); } break; case NOTIFICATION_THEME_CHANGED: { @@ -859,7 +836,7 @@ void SceneTreeEditor::set_editor_selection(EditorSelection *p_selection) { editor_selection = p_selection; tree->set_select_mode(Tree::SELECT_MULTI); tree->set_cursor_can_exit_tree(false); - editor_selection->connect("selection_changed", this, "_selection_changed"); + editor_selection->connect_compat("selection_changed", this, "_selection_changed"); } void SceneTreeEditor::_update_selection(TreeItem *item) { @@ -928,7 +905,7 @@ Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from return Variant(); //not editable tree Vector<Node *> selected; - Vector<Ref<Texture> > icons; + Vector<Ref<Texture2D> > icons; TreeItem *next = tree->get_next_selected(NULL); while (next) { @@ -1143,7 +1120,7 @@ void SceneTreeEditor::_bind_methods() { ADD_SIGNAL(MethodInfo("node_changed")); ADD_SIGNAL(MethodInfo("nodes_dragged")); ADD_SIGNAL(MethodInfo("nodes_rearranged", PropertyInfo(Variant::ARRAY, "paths"), PropertyInfo(Variant::NODE_PATH, "to_path"), PropertyInfo(Variant::INT, "type"))); - ADD_SIGNAL(MethodInfo("files_dropped", PropertyInfo(Variant::POOL_STRING_ARRAY, "files"), PropertyInfo(Variant::NODE_PATH, "to_path"), PropertyInfo(Variant::INT, "type"))); + ADD_SIGNAL(MethodInfo("files_dropped", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files"), PropertyInfo(Variant::NODE_PATH, "to_path"), PropertyInfo(Variant::INT, "type"))); ADD_SIGNAL(MethodInfo("script_dropped", PropertyInfo(Variant::STRING, "file"), PropertyInfo(Variant::NODE_PATH, "to_path"))); ADD_SIGNAL(MethodInfo("rmb_pressed", PropertyInfo(Variant::VECTOR2, "position"))); @@ -1186,15 +1163,15 @@ SceneTreeEditor::SceneTreeEditor(bool p_label, bool p_can_rename, bool p_can_ope tree->set_drag_forwarding(this); if (p_can_rename) { tree->set_allow_rmb_select(true); - tree->connect("item_rmb_selected", this, "_rmb_select"); - tree->connect("empty_tree_rmb_selected", this, "_rmb_select"); + tree->connect_compat("item_rmb_selected", this, "_rmb_select"); + tree->connect_compat("empty_tree_rmb_selected", this, "_rmb_select"); } - tree->connect("cell_selected", this, "_selected_changed"); - tree->connect("item_edited", this, "_renamed", varray(), CONNECT_DEFERRED); - tree->connect("multi_selected", this, "_cell_multi_selected"); - tree->connect("button_pressed", this, "_cell_button_pressed"); - tree->connect("nothing_selected", this, "_deselect_items"); + tree->connect_compat("cell_selected", this, "_selected_changed"); + tree->connect_compat("item_edited", this, "_renamed", varray(), CONNECT_DEFERRED); + tree->connect_compat("multi_selected", this, "_cell_multi_selected"); + tree->connect_compat("button_pressed", this, "_cell_button_pressed"); + tree->connect_compat("nothing_selected", this, "_deselect_items"); //tree->connect("item_edited", this,"_renamed",Vector<Variant>(),true); error = memnew(AcceptDialog); @@ -1212,7 +1189,7 @@ SceneTreeEditor::SceneTreeEditor(bool p_label, bool p_can_rename, bool p_can_ope blocked = 0; update_timer = memnew(Timer); - update_timer->connect("timeout", this, "_update_tree"); + update_timer->connect_compat("timeout", this, "_update_tree"); update_timer->set_one_shot(true); update_timer->set_wait_time(0.5); add_child(update_timer); @@ -1232,12 +1209,12 @@ void SceneTreeDialog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - connect("confirmed", this, "_select"); + connect_compat("confirmed", this, "_select"); filter->set_right_icon(get_icon("Search", "EditorIcons")); filter->set_clear_button_enabled(true); } break; case NOTIFICATION_EXIT_TREE: { - disconnect("confirmed", this, "_select"); + disconnect_compat("confirmed", this, "_select"); } break; case NOTIFICATION_VISIBILITY_CHANGED: { if (is_visible_in_tree()) @@ -1282,12 +1259,12 @@ SceneTreeDialog::SceneTreeDialog() { filter->set_h_size_flags(SIZE_EXPAND_FILL); filter->set_placeholder(TTR("Filter nodes")); filter->add_constant_override("minimum_spaces", 0); - filter->connect("text_changed", this, "_filter_changed"); + filter->connect_compat("text_changed", this, "_filter_changed"); vbc->add_child(filter); tree = memnew(SceneTreeEditor(false, false, true)); tree->set_v_size_flags(SIZE_EXPAND_FILL); - tree->get_scene_tree()->connect("item_activated", this, "_select"); + tree->get_scene_tree()->connect_compat("item_activated", this, "_select"); vbc->add_child(tree); } |