From 0d83637853218127a5ec81a2bad7825dfc0c3885 Mon Sep 17 00:00:00 2001 From: Logan Detrick Date: Wed, 26 Nov 2025 01:19:02 -0800 Subject: [PATCH] Use new dock system for ShaderDock --- editor/docks/editor_dock_manager.cpp | 9 ++ editor/docks/editor_dock_manager.h | 1 + editor/icons/ShaderDock.svg | 1 + editor/shader/shader_editor.h | 2 +- editor/shader/shader_editor_plugin.cpp | 144 +++++++----------- editor/shader/shader_editor_plugin.h | 13 +- editor/shader/text_shader_editor.cpp | 4 +- editor/shader/text_shader_editor.h | 2 +- editor/shader/visual_shader_editor_plugin.cpp | 4 +- editor/shader/visual_shader_editor_plugin.h | 2 +- 10 files changed, 77 insertions(+), 105 deletions(-) create mode 100644 editor/icons/ShaderDock.svg diff --git a/editor/docks/editor_dock_manager.cpp b/editor/docks/editor_dock_manager.cpp index 1c7d256d9aa..b19ea88842f 100644 --- a/editor/docks/editor_dock_manager.cpp +++ b/editor/docks/editor_dock_manager.cpp @@ -834,6 +834,15 @@ void EditorDockManager::open_dock(EditorDock *p_dock, bool p_set_current) { _update_layout(); } +void EditorDockManager::make_dock_floating(EditorDock *p_dock) { + ERR_FAIL_NULL(p_dock); + ERR_FAIL_COND_MSG(!all_docks.has(p_dock), vformat("Cannot make unknown dock '%s' floating.", p_dock->get_display_title())); + + if (!p_dock->dock_window) { + _open_dock_in_window(p_dock); + } +} + TabContainer *EditorDockManager::get_dock_tab_container(Control *p_dock) const { return Object::cast_to(p_dock->get_parent()); } diff --git a/editor/docks/editor_dock_manager.h b/editor/docks/editor_dock_manager.h index ffa04ae9e96..838b22e4132 100644 --- a/editor/docks/editor_dock_manager.h +++ b/editor/docks/editor_dock_manager.h @@ -146,6 +146,7 @@ public: void close_dock(EditorDock *p_dock); void open_dock(EditorDock *p_dock, bool p_set_current = true); void focus_dock(EditorDock *p_dock); + void make_dock_floating(EditorDock *p_dock); TabContainer *get_dock_tab_container(Control *p_dock) const; diff --git a/editor/icons/ShaderDock.svg b/editor/icons/ShaderDock.svg new file mode 100644 index 00000000000..b0fee9aebf1 --- /dev/null +++ b/editor/icons/ShaderDock.svg @@ -0,0 +1 @@ + diff --git a/editor/shader/shader_editor.h b/editor/shader/shader_editor.h index 3b43c4d9058..ae4e86e1b7c 100644 --- a/editor/shader/shader_editor.h +++ b/editor/shader/shader_editor.h @@ -42,7 +42,7 @@ class ShaderEditor : public Control { public: virtual void edit_shader(const Ref &p_shader) = 0; virtual void edit_shader_include(const Ref &p_shader_inc) {} - virtual void use_menu_bar_items(MenuButton *p_file_menu, Button *p_make_floating) = 0; + virtual void use_menu_bar(MenuButton *p_file_menu) = 0; virtual void apply_shaders() = 0; virtual bool is_unsaved() const = 0; diff --git a/editor/shader/shader_editor_plugin.cpp b/editor/shader/shader_editor_plugin.cpp index ba1c92cc4cf..9e468b033f0 100644 --- a/editor/shader/shader_editor_plugin.cpp +++ b/editor/shader/shader_editor_plugin.cpp @@ -30,12 +30,12 @@ #include "shader_editor_plugin.h" +#include "editor/docks/editor_dock_manager.h" #include "editor/docks/filesystem_dock.h" #include "editor/docks/inspector_dock.h" #include "editor/editor_node.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" -#include "editor/gui/editor_bottom_panel.h" #include "editor/gui/window_wrapper.h" #include "editor/settings/editor_command_palette.h" #include "editor/shader/shader_create_dialog.h" @@ -209,13 +209,10 @@ bool ShaderEditorPlugin::handles(Object *p_object) const { void ShaderEditorPlugin::make_visible(bool p_visible) { if (p_visible) { - EditorNode::get_bottom_panel()->make_item_visible(window_wrapper); + shader_dock->make_visible(); } } -void ShaderEditorPlugin::selected_notify() { -} - ShaderEditor *ShaderEditorPlugin::get_shader_editor(const Ref &p_for_shader) { for (EditedShader &edited_shader : edited_shaders) { if (edited_shader.shader == p_for_shader) { @@ -228,21 +225,14 @@ ShaderEditor *ShaderEditorPlugin::get_shader_editor(const Ref &p_for_sha void ShaderEditorPlugin::set_window_layout(Ref p_layout) { restoring_layout = true; - if (EDITOR_GET("interface/multi_window/restore_windows_on_load") && window_wrapper->is_window_available() && p_layout->has_section_key("ShaderEditor", "window_rect")) { - window_wrapper->restore_window_from_saved_position( - p_layout->get_value("ShaderEditor", "window_rect", Rect2i()), - p_layout->get_value("ShaderEditor", "window_screen", -1), - p_layout->get_value("ShaderEditor", "window_screen_rect", Rect2i())); - } else { - window_wrapper->set_window_enabled(false); - } - if (!bool(EDITOR_GET("editors/shader_editor/behavior/files/restore_shaders_on_load"))) { return; } + if (!p_layout->has_section("ShaderEditor")) { return; } + if (!p_layout->has_section_key("ShaderEditor", "open_shaders") || !p_layout->has_section_key("ShaderEditor", "selected_shader")) { return; @@ -275,23 +265,17 @@ void ShaderEditorPlugin::set_window_layout(Ref p_layout) { } void ShaderEditorPlugin::get_window_layout(Ref p_layout) { - if (window_wrapper->get_window_enabled()) { - p_layout->set_value("ShaderEditor", "window_rect", window_wrapper->get_window_rect()); - int screen = window_wrapper->get_window_screen(); - p_layout->set_value("ShaderEditor", "window_screen", screen); - p_layout->set_value("ShaderEditor", "window_screen_rect", DisplayServer::get_singleton()->screen_get_usable_rect(screen)); - - } else { - if (p_layout->has_section_key("ShaderEditor", "window_rect")) { - p_layout->erase_section_key("ShaderEditor", "window_rect"); - } - if (p_layout->has_section_key("ShaderEditor", "window_screen")) { - p_layout->erase_section_key("ShaderEditor", "window_screen"); - } - if (p_layout->has_section_key("ShaderEditor", "window_screen_rect")) { - p_layout->erase_section_key("ShaderEditor", "window_screen_rect"); - } +#ifndef DISABLE_DEPRECATED + if (p_layout->has_section_key("ShaderEditor", "window_rect")) { + p_layout->erase_section_key("ShaderEditor", "window_rect"); } + if (p_layout->has_section_key("ShaderEditor", "window_screen")) { + p_layout->erase_section_key("ShaderEditor", "window_screen"); + } + if (p_layout->has_section_key("ShaderEditor", "window_screen_rect")) { + p_layout->erase_section_key("ShaderEditor", "window_screen_rect"); + } +#endif Array shaders; String selected_shader; @@ -465,10 +449,6 @@ void ShaderEditorPlugin::_close_shader(int p_index) { if (file_menu->get_parent() != nullptr) { file_menu->get_parent()->remove_child(file_menu); } - if (make_floating->get_parent()) { - make_floating->get_parent()->remove_child(make_floating); - } - empty_menu->set_visible(false); ShaderEditor *shader_editor = Object::cast_to(shader_tabs->get_tab_control(p_index)); ERR_FAIL_NULL(shader_editor); @@ -479,8 +459,8 @@ void ShaderEditorPlugin::_close_shader(int p_index) { if (shader_tabs->get_tab_count() == 0) { shader_list->show(); // Make sure the panel is visible, because it can't be toggled without open shaders. - empty_menu->add_child(file_menu); - empty_menu->set_visible(true); + shader_tabs->hide(); + files_split->add_child(file_menu); } else { _switch_to_editor(edited_shaders[shader_tabs->get_current_tab()].shader_editor); } @@ -769,10 +749,6 @@ void ShaderEditorPlugin::drop_data_fw(const Point2 &p_point, const Variant &p_da } } -void ShaderEditorPlugin::_window_changed(bool p_visible) { - make_floating->set_visible(!p_visible); -} - void ShaderEditorPlugin::_set_text_shader_zoom_factor(float p_zoom_factor) { if (text_shader_zoom_factor == p_zoom_factor) { return; @@ -792,11 +768,8 @@ void ShaderEditorPlugin::_switch_to_editor(ShaderEditor *p_editor, bool p_focus) if (file_menu->get_parent() != nullptr) { file_menu->get_parent()->remove_child(file_menu); } - if (make_floating->get_parent() != nullptr) { - make_floating->get_parent()->remove_child(make_floating); - } - empty_menu->set_visible(false); - p_editor->use_menu_bar_items(file_menu, make_floating); + shader_tabs->show(); + p_editor->use_menu_bar(file_menu); if (p_focus) { TextShaderEditor *text_shader_editor = Object::cast_to(p_editor); if (text_shader_editor) { @@ -859,6 +832,16 @@ void ShaderEditorPlugin::_notification(int p_what) { } } +void ShaderEditorPlugin::shortcut_input(const Ref &p_event) { + if (p_event.is_null() || !p_event->is_pressed() || p_event->is_echo()) { + return; + } + + if (make_floating_shortcut.is_valid() && make_floating_shortcut->matches_event(p_event)) { + EditorDockManager::get_singleton()->make_dock_floating(shader_dock); + } +} + ShaderEditorPlugin::ShaderEditorPlugin() { ED_SHORTCUT("shader_editor/new", TTRC("New Shader..."), KeyModifierMask::CMD_OR_CTRL | Key::N); ED_SHORTCUT("shader_editor/new_include", TTRC("New Shader Include..."), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::N); @@ -868,80 +851,66 @@ ShaderEditorPlugin::ShaderEditorPlugin() { ED_SHORTCUT("shader_editor/inspect_native_code", TTRC("Inspect Native Shader Code...")); ED_SHORTCUT("shader_editor/copy_path", TTRC("Copy Shader Path")); - window_wrapper = memnew(WindowWrapper); - window_wrapper->set_window_title(vformat(TTR("%s - Godot Engine"), TTR("Shader Editor"))); - window_wrapper->set_margins_enabled(true); + shader_dock = memnew(EditorDock); + shader_dock->set_name(TTRC("Shader Editor")); + shader_dock->set_icon_name("ShaderDock"); + shader_dock->set_dock_shortcut(ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_shader_editor_bottom_panel", TTRC("Toggle Shader Editor Dock"), KeyModifierMask::ALT | Key::S)); + shader_dock->set_default_slot(DockConstants::DOCK_SLOT_BOTTOM); + shader_dock->set_available_layouts(EditorDock::DOCK_LAYOUT_HORIZONTAL | EditorDock::DOCK_LAYOUT_FLOATING); + EditorDockManager::get_singleton()->add_dock(shader_dock); - main_container = memnew(VBoxContainer); - Ref make_floating_shortcut = ED_SHORTCUT_AND_COMMAND("shader_editor/make_floating", TTRC("Make Floating")); - window_wrapper->set_wrapped_control(main_container, make_floating_shortcut); + set_process_shortcut_input(true); + + make_floating_shortcut = ED_SHORTCUT_AND_COMMAND("shader_editor/make_floating", TTRC("Make Floating")); files_split = memnew(HSplitContainer); files_split->set_split_offset(200 * EDSCALE); files_split->set_v_size_flags(Control::SIZE_EXPAND_FILL); - - file_menu = memnew(MenuButton); - file_menu->set_flat(false); - file_menu->set_theme_type_variation("FlatMenuButton"); - file_menu->set_text(TTR("File")); - file_menu->set_switch_on_hover(true); - file_menu->set_shortcut_context(files_split); - _setup_popup_menu(FILE, file_menu->get_popup()); - file_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &ShaderEditorPlugin::_menu_item_pressed)); - - _set_file_specific_items_disabled(true); + shader_dock->add_child(files_split); context_menu = memnew(PopupMenu); - add_child(context_menu); context_menu->connect(SceneStringName(id_pressed), callable_mp(this, &ShaderEditorPlugin::_menu_item_pressed)); - - make_floating = memnew(ScreenSelect); - make_floating->connect("request_open_in_screen", callable_mp(window_wrapper, &WindowWrapper::enable_window_on_screen).bind(true)); - if (!make_floating->is_disabled()) { - // Override default ScreenSelect tooltip if multi-window support is available. - make_floating->set_tooltip_text(TTR("Make the shader editor floating.") + "\n" + TTR("Right-click to open the screen selector.")); - } - - window_wrapper->connect("window_visibility_changed", callable_mp(this, &ShaderEditorPlugin::_window_changed)); + add_child(context_menu); shader_list = memnew(ItemList); shader_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); shader_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); shader_list->set_theme_type_variation("ItemListSecondary"); shader_list->set_custom_minimum_size(Size2(100, 60) * EDSCALE); - files_split->add_child(shader_list); shader_list->connect(SceneStringName(item_selected), callable_mp(this, &ShaderEditorPlugin::_shader_selected).bind(true)); shader_list->connect("item_clicked", callable_mp(this, &ShaderEditorPlugin::_shader_list_clicked)); shader_list->set_allow_rmb_select(true); SET_DRAG_FORWARDING_GCD(shader_list, ShaderEditorPlugin); - - main_container->add_child(files_split); - main_container->set_custom_minimum_size(Size2(100, 300) * EDSCALE); - - VBoxContainer *shader_vb = memnew(VBoxContainer); - shader_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); - files_split->add_child(shader_vb); - empty_menu = memnew(HBoxContainer); - shader_vb->add_child(empty_menu); - empty_menu->add_child(file_menu); - empty_menu->add_theme_style_override(SceneStringName(panel), EditorNode::get_singleton()->get_editor_theme()->get_stylebox(SNAME("ScriptEditorPanel"), EditorStringName(EditorStyles))); + files_split->add_child(shader_list); shader_tabs = memnew(TabContainer); shader_tabs->set_custom_minimum_size(Size2(460, 300) * EDSCALE); shader_tabs->set_tabs_visible(false); shader_tabs->set_h_size_flags(Control::SIZE_EXPAND_FILL); shader_tabs->set_v_size_flags(Control::SIZE_EXPAND_FILL); - shader_vb->add_child(shader_tabs); Ref empty; empty.instantiate(); shader_tabs->add_theme_style_override(SceneStringName(panel), empty); + shader_tabs->hide(); + files_split->add_child(shader_tabs); - EditorNode::get_bottom_panel()->add_item(TTRC("Shader Editor"), window_wrapper, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_shader_editor_bottom_panel", TTRC("Toggle Shader Editor Bottom Panel"), KeyModifierMask::ALT | Key::S)); + file_menu = memnew(MenuButton); + file_menu->set_flat(false); + file_menu->set_theme_type_variation("FlatMenuButton"); + file_menu->set_text(TTRC("File")); + file_menu->set_h_size_flags(Control::SIZE_SHRINK_BEGIN); + file_menu->set_v_size_flags(Control::SIZE_SHRINK_BEGIN); + file_menu->set_switch_on_hover(true); + file_menu->set_shortcut_context(files_split); + file_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &ShaderEditorPlugin::_menu_item_pressed)); + _setup_popup_menu(FILE, file_menu->get_popup()); + _set_file_specific_items_disabled(true); + files_split->add_child(file_menu); shader_create_dialog = memnew(ShaderCreateDialog); - files_split->add_child(shader_create_dialog); shader_create_dialog->connect("shader_created", callable_mp(this, &ShaderEditorPlugin::_shader_created)); shader_create_dialog->connect("shader_include_created", callable_mp(this, &ShaderEditorPlugin::_shader_include_created)); + shader_dock->add_child(shader_create_dialog); Ref text_shader_lang; text_shader_lang.instantiate(); @@ -955,5 +924,4 @@ ShaderEditorPlugin::ShaderEditorPlugin() { ShaderEditorPlugin::~ShaderEditorPlugin() { EditorShaderLanguagePlugin::clear_registered_shader_languages(); memdelete(file_menu); - memdelete(make_floating); } diff --git a/editor/shader/shader_editor_plugin.h b/editor/shader/shader_editor_plugin.h index 9a8ef704a8c..8fcbd25c556 100644 --- a/editor/shader/shader_editor_plugin.h +++ b/editor/shader/shader_editor_plugin.h @@ -33,6 +33,7 @@ #include "editor/plugins/editor_plugin.h" class CodeTextEditor; +class EditorDock; class HSplitContainer; class ItemList; class MenuButton; @@ -78,19 +79,16 @@ class ShaderEditorPlugin : public EditorPlugin { CONTEXT, CONTEXT_VALID_ITEM, }; - - VBoxContainer *main_container = nullptr; HSplitContainer *files_split = nullptr; ItemList *shader_list = nullptr; TabContainer *shader_tabs = nullptr; - HBoxContainer *empty_menu = nullptr; MenuButton *file_menu = nullptr; PopupMenu *context_menu = nullptr; - WindowWrapper *window_wrapper = nullptr; - Button *make_floating = nullptr; + EditorDock *shader_dock = nullptr; + Ref make_floating_shortcut; ShaderCreateDialog *shader_create_dialog = nullptr; @@ -120,8 +118,6 @@ class ShaderEditorPlugin : public EditorPlugin { bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); - void _window_changed(bool p_visible); - void _set_text_shader_zoom_factor(float p_zoom_factor); void _update_shader_editor_zoom_factor(CodeTextEditor *p_shader_editor) const; @@ -130,12 +126,13 @@ class ShaderEditorPlugin : public EditorPlugin { protected: void _notification(int p_what); + virtual void shortcut_input(const Ref &p_event) override; + public: virtual String get_plugin_name() const override { return "Shader"; } virtual void edit(Object *p_object) override; virtual bool handles(Object *p_object) const override; virtual void make_visible(bool p_visible) override; - virtual void selected_notify() override; ShaderEditor *get_shader_editor(const Ref &p_for_shader); diff --git a/editor/shader/text_shader_editor.cpp b/editor/shader/text_shader_editor.cpp index 129eefe707f..d906dc46139 100644 --- a/editor/shader/text_shader_editor.cpp +++ b/editor/shader/text_shader_editor.cpp @@ -972,11 +972,10 @@ void TextShaderEditor::edit_shader_include(const Ref &p_shader_in code_editor->set_edited_shader_include(p_shader_inc); } -void TextShaderEditor::use_menu_bar_items(MenuButton *p_file_menu, Button *p_make_floating) { +void TextShaderEditor::use_menu_bar(MenuButton *p_file_menu) { p_file_menu->set_switch_on_hover(true); menu_bar_hbox->add_child(p_file_menu); menu_bar_hbox->move_child(p_file_menu, 0); - menu_bar_hbox->add_child(p_make_floating); } void TextShaderEditor::save_external_data(const String &p_str) { @@ -1283,7 +1282,6 @@ TextShaderEditor::TextShaderEditor() { site_search->set_text(TTR("Online Docs")); site_search->set_tooltip_text(TTR("Open Godot online documentation.")); menu_bar_hbox->add_child(site_search); - menu_bar_hbox->add_child(memnew(VSeparator)); menu_bar_hbox->add_theme_style_override(SceneStringName(panel), EditorNode::get_singleton()->get_editor_theme()->get_stylebox(SNAME("ScriptEditorPanel"), EditorStringName(EditorStyles))); diff --git a/editor/shader/text_shader_editor.h b/editor/shader/text_shader_editor.h index 449adecc63d..1a934412604 100644 --- a/editor/shader/text_shader_editor.h +++ b/editor/shader/text_shader_editor.h @@ -191,7 +191,7 @@ protected: public: virtual void edit_shader(const Ref &p_shader) override; virtual void edit_shader_include(const Ref &p_shader_inc) override; - virtual void use_menu_bar_items(MenuButton *p_file_menu, Button *p_make_floating) override; + virtual void use_menu_bar(MenuButton *p_file_menu) override; virtual void apply_shaders() override; virtual bool is_unsaved() const override; diff --git a/editor/shader/visual_shader_editor_plugin.cpp b/editor/shader/visual_shader_editor_plugin.cpp index 2bca70315d2..4688c14f630 100644 --- a/editor/shader/visual_shader_editor_plugin.cpp +++ b/editor/shader/visual_shader_editor_plugin.cpp @@ -1564,11 +1564,10 @@ void VisualShaderEditor::edit_shader(const Ref &p_shader) { } } -void VisualShaderEditor::use_menu_bar_items(MenuButton *p_file_menu, Button *p_make_floating) { +void VisualShaderEditor::use_menu_bar(MenuButton *p_file_menu) { p_file_menu->set_switch_on_hover(false); toolbar_hflow->add_child(p_file_menu); toolbar_hflow->move_child(p_file_menu, 2); // Toggle Files Panel button + separator. - toolbar_hflow->add_child(p_make_floating); } void VisualShaderEditor::apply_shaders() { @@ -6735,7 +6734,6 @@ VisualShaderEditor::VisualShaderEditor() { site_search->set_text(TTR("Online Docs")); site_search->set_tooltip_text(TTR("Open Godot online documentation.")); toolbar_hflow->add_child(site_search); - toolbar_hflow->add_child(memnew(VSeparator)); VSeparator *separator = memnew(VSeparator); toolbar_hflow->add_child(separator); diff --git a/editor/shader/visual_shader_editor_plugin.h b/editor/shader/visual_shader_editor_plugin.h index 027eb4e6f72..3854315c86b 100644 --- a/editor/shader/visual_shader_editor_plugin.h +++ b/editor/shader/visual_shader_editor_plugin.h @@ -654,7 +654,7 @@ protected: public: virtual void edit_shader(const Ref &p_shader) override; - virtual void use_menu_bar_items(MenuButton *p_file_menu, Button *p_make_floating) override; + virtual void use_menu_bar(MenuButton *p_file_menu) override; virtual void apply_shaders() override; virtual bool is_unsaved() const override; virtual void save_external_data(const String &p_str = "") override;