diff options
Diffstat (limited to 'editor/scene_tree_dock.cpp')
-rw-r--r-- | editor/scene_tree_dock.cpp | 74 |
1 files changed, 69 insertions, 5 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index c4d47c7594..a08a628216 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -45,6 +45,7 @@ #include "editor/plugins/canvas_item_editor_plugin.h" #include "editor/plugins/node_3d_editor_plugin.h" #include "editor/plugins/script_editor_plugin.h" +#include "editor/shader_create_dialog.h" #include "scene/main/window.h" #include "scene/resources/packed_scene.h" #include "servers/display_server.h" @@ -61,7 +62,7 @@ void SceneTreeDock::_quick_open() { instantiate_scenes(quick_open->get_selected_files(), scene_tree->get_selected()); } -void SceneTreeDock::_input(Ref<InputEvent> p_event) { +void SceneTreeDock::input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); Ref<InputEventMouseButton> mb = p_event; @@ -71,7 +72,7 @@ void SceneTreeDock::_input(Ref<InputEvent> p_event) { } } -void SceneTreeDock::_unhandled_key_input(Ref<InputEvent> p_event) { +void SceneTreeDock::unhandled_key_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); if (get_focus_owner() && get_focus_owner()->is_text_field()) { @@ -1142,6 +1143,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { editor_selection->clear(); editor_selection->add_node(new_node); + scene_tree->get_scene_tree()->grab_focus(); } break; default: { @@ -1939,12 +1941,31 @@ void SceneTreeDock::_script_created(Ref<Script> p_script) { _update_script_button(); } +void SceneTreeDock::_shader_created(Ref<Shader> p_shader) { + if (selected_shader_material.is_null()) { + return; + } + + Ref<Shader> existing = selected_shader_material->get_shader(); + + editor_data->get_undo_redo().create_action(TTR("Set Shader")); + editor_data->get_undo_redo().add_do_method(selected_shader_material.ptr(), "set_shader", p_shader); + editor_data->get_undo_redo().add_undo_method(selected_shader_material.ptr(), "set_shader", existing); + editor_data->get_undo_redo().commit_action(); +} + void SceneTreeDock::_script_creation_closed() { script_create_dialog->disconnect("script_created", callable_mp(this, &SceneTreeDock::_script_created)); script_create_dialog->disconnect("confirmed", callable_mp(this, &SceneTreeDock::_script_creation_closed)); script_create_dialog->disconnect("cancelled", callable_mp(this, &SceneTreeDock::_script_creation_closed)); } +void SceneTreeDock::_shader_creation_closed() { + shader_create_dialog->disconnect("shader_created", callable_mp(this, &SceneTreeDock::_shader_created)); + shader_create_dialog->disconnect("confirmed", callable_mp(this, &SceneTreeDock::_shader_creation_closed)); + shader_create_dialog->disconnect("cancelled", callable_mp(this, &SceneTreeDock::_shader_creation_closed)); +} + void SceneTreeDock::_toggle_editable_children_from_selection() { List<Node *> selection = editor_selection->get_selected_node_list(); List<Node *>::Element *e = selection.front(); @@ -2259,7 +2280,7 @@ void SceneTreeDock::_create() { _do_reparent(last_created, -1, nodes, true); } - scene_tree->get_scene_tree()->call_deferred(SNAME("grab_focus")); + scene_tree->get_scene_tree()->grab_focus(); } void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_properties, bool p_remove_old) { @@ -2816,6 +2837,11 @@ void SceneTreeDock::set_filter(const String &p_filter) { scene_tree->set_filter(p_filter); } +void SceneTreeDock::save_branch_to_file(String p_directory) { + new_scene_from_dialog->set_current_dir(p_directory); + _tool_selected(TOOL_NEW_SCENE_FROM); +} + void SceneTreeDock::_focus_node() { Node *node = scene_tree->get_selected(); ERR_FAIL_COND(!node); @@ -2896,6 +2922,42 @@ void SceneTreeDock::open_script_dialog(Node *p_for_node, bool p_extend) { } } +void SceneTreeDock::attach_shader_to_selected() { + if (selected_shader_material.is_null()) { + return; + } + + String path = selected_shader_material->get_path(); + if (path == "") { + String root_path; + if (editor_data->get_edited_scene_root()) { + root_path = editor_data->get_edited_scene_root()->get_filename(); + } + String shader_name; + if (selected_shader_material->get_name().is_empty()) { + shader_name = root_path.get_file(); + } else { + shader_name = selected_shader_material->get_name(); + } + if (root_path == "") { + path = String("res://").plus_file(shader_name); + } else { + path = root_path.get_base_dir().plus_file(shader_name); + } + } + + shader_create_dialog->connect("shader_created", callable_mp(this, &SceneTreeDock::_shader_created)); + shader_create_dialog->connect("confirmed", callable_mp(this, &SceneTreeDock::_shader_creation_closed)); + shader_create_dialog->connect("cancelled", callable_mp(this, &SceneTreeDock::_shader_creation_closed)); + shader_create_dialog->config(path); + shader_create_dialog->popup_centered(); +} + +void SceneTreeDock::open_shader_dialog(Ref<ShaderMaterial> &p_for_material) { + selected_shader_material = p_for_material; + attach_shader_to_selected(); +} + void SceneTreeDock::open_add_child_dialog() { create_dialog->set_base_type("CanvasItem"); _tool_selected(TOOL_NEW, true); @@ -3106,8 +3168,7 @@ void SceneTreeDock::_create_remap_for_resource(RES p_resource, Map<RES, RES> &r_ void SceneTreeDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_set_owners"), &SceneTreeDock::_set_owners); - ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &SceneTreeDock::_unhandled_key_input); - ClassDB::bind_method(D_METHOD("_input"), &SceneTreeDock::_input); + ClassDB::bind_method(D_METHOD("_update_script_button"), &SceneTreeDock::_update_script_button); ClassDB::bind_method(D_METHOD("instantiate"), &SceneTreeDock::instantiate); @@ -3267,6 +3328,9 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel script_create_dialog->set_inheritance_base_type("Node"); add_child(script_create_dialog); + shader_create_dialog = memnew(ShaderCreateDialog); + add_child(shader_create_dialog); + reparent_dialog = memnew(ReparentDialog); add_child(reparent_dialog); reparent_dialog->connect("reparent", callable_mp(this, &SceneTreeDock::_node_reparent)); |