diff options
Diffstat (limited to 'editor/scene_tree_dock.cpp')
-rw-r--r-- | editor/scene_tree_dock.cpp | 75 |
1 files changed, 69 insertions, 6 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 835243e401..da2d22b900 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -52,19 +52,21 @@ void SceneTreeDock::_nodes_drag_begin() { } } -void SceneTreeDock::_input(InputEvent p_event) { +void SceneTreeDock::_input(Ref<InputEvent> p_event) { - if (p_event.type == InputEvent::MOUSE_BUTTON && !p_event.mouse_button.pressed && p_event.mouse_button.button_index == BUTTON_LEFT) { + Ref<InputEventMouseButton> mb = p_event; + + if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { restore_script_editor_on_drag = false; //lost chance } } -void SceneTreeDock::_unhandled_key_input(InputEvent p_event) { +void SceneTreeDock::_unhandled_key_input(Ref<InputEvent> p_event) { if (get_viewport()->get_modal_stack_top()) return; //ignore because of modal window - if (!p_event.key.pressed || p_event.key.echo) + if (!p_event->is_pressed() || p_event->is_echo()) return; if (ED_IS_SHORTCUT("scene_tree/add_child_node", p_event)) { @@ -656,6 +658,21 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } } } break; + + default: { + + if (p_tool >= EDIT_SUBRESOURCE_BASE) { + + int idx = p_tool - EDIT_SUBRESOURCE_BASE; + + ERR_FAIL_INDEX(idx, subresources.size()); + + Object *obj = ObjectDB::get_instance(subresources[idx]); + ERR_FAIL_COND(!obj); + + editor->push_item(obj); + } + } } } @@ -680,8 +697,6 @@ void SceneTreeDock::_notification(int p_what) { button_create_script->set_icon(get_icon("ScriptCreate", "EditorIcons")); button_clear_script->set_icon(get_icon("ScriptRemove", "EditorIcons")); - filter_icon->set_texture(get_icon("Zoom", "EditorIcons")); - filter_icon->set_texture(get_icon("Search", "EditorIcons")); EditorNode::get_singleton()->get_editor_selection()->connect("selection_changed", this, "_selection_changed"); @@ -1662,6 +1677,47 @@ void SceneTreeDock::_nodes_dragged(Array p_nodes, NodePath p_to, int p_type) { _do_reparent(to_node, to_pos, nodes, true); } +void SceneTreeDock::_add_children_to_popup(Object *p_obj, int p_depth) { + + if (p_depth > 8) + return; + + List<PropertyInfo> pinfo; + p_obj->get_property_list(&pinfo); + for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { + + if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) + continue; + if (E->get().hint != PROPERTY_HINT_RESOURCE_TYPE) + continue; + + Variant value = p_obj->get(E->get().name); + if (value.get_type() != Variant::OBJECT) + continue; + Object *obj = value; + if (!obj) + continue; + + Ref<Texture> icon; + + if (has_icon(obj->get_class(), "EditorIcons")) + icon = get_icon(obj->get_class(), "EditorIcons"); + else + icon = get_icon("Object", "EditorIcons"); + + if (menu->get_item_count() == 0) { + menu->add_item(TTR("Sub-Resources:")); + menu->set_item_disabled(0, true); + } + int index = menu->get_item_count(); + menu->add_icon_item(icon, E->get().name.capitalize(), EDIT_SUBRESOURCE_BASE + subresources.size()); + menu->set_item_h_offset(index, p_depth * 10 * EDSCALE); + subresources.push_back(obj->get_instance_ID()); + + _add_children_to_popup(obj, p_depth + 1); + } +} + void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { if (!EditorNode::get_singleton()->get_edited_scene()) { @@ -1683,6 +1739,12 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { menu->clear(); if (selection.size() == 1) { + + subresources.clear(); + _add_children_to_popup(selection.front()->get(), 0); + if (menu->get_item_count() > 0) + menu->add_separator(); + menu->add_icon_shortcut(get_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW); menu->add_icon_shortcut(get_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE); menu->add_separator(); @@ -1829,6 +1891,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel filter->set_h_size_flags(SIZE_EXPAND_FILL); filter_hbc->add_child(filter); filter_icon = memnew(TextureRect); + filter_icon->set_custom_minimum_size(Size2(24 * EDSCALE, 0)); filter_hbc->add_child(filter_icon); filter_icon->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED); filter->connect("text_changed", this, "_filter_changed"); |