3030
3131#include " shader_editor_plugin.h"
3232
33+ #include " editor/docks/editor_dock_manager.h"
3334#include " editor/docks/filesystem_dock.h"
3435#include " editor/docks/inspector_dock.h"
3536#include " editor/editor_node.h"
3637#include " editor/editor_string_names.h"
3738#include " editor/editor_undo_redo_manager.h"
38- #include " editor/gui/editor_bottom_panel.h"
3939#include " editor/gui/window_wrapper.h"
4040#include " editor/settings/editor_command_palette.h"
4141#include " editor/shader/shader_create_dialog.h"
@@ -209,13 +209,10 @@ bool ShaderEditorPlugin::handles(Object *p_object) const {
209209
210210void ShaderEditorPlugin::make_visible (bool p_visible) {
211211 if (p_visible) {
212- EditorNode::get_bottom_panel ()-> make_item_visible (window_wrapper );
212+ shader_dock-> make_visible ( );
213213 }
214214}
215215
216- void ShaderEditorPlugin::selected_notify () {
217- }
218-
219216ShaderEditor *ShaderEditorPlugin::get_shader_editor (const Ref<Shader> &p_for_shader) {
220217 for (EditedShader &edited_shader : edited_shaders) {
221218 if (edited_shader.shader == p_for_shader) {
@@ -228,21 +225,14 @@ ShaderEditor *ShaderEditorPlugin::get_shader_editor(const Ref<Shader> &p_for_sha
228225void ShaderEditorPlugin::set_window_layout (Ref<ConfigFile> p_layout) {
229226 restoring_layout = true ;
230227
231- if (EDITOR_GET (" interface/multi_window/restore_windows_on_load" ) && window_wrapper->is_window_available () && p_layout->has_section_key (" ShaderEditor" , " window_rect" )) {
232- window_wrapper->restore_window_from_saved_position (
233- p_layout->get_value (" ShaderEditor" , " window_rect" , Rect2i ()),
234- p_layout->get_value (" ShaderEditor" , " window_screen" , -1 ),
235- p_layout->get_value (" ShaderEditor" , " window_screen_rect" , Rect2i ()));
236- } else {
237- window_wrapper->set_window_enabled (false );
238- }
239-
240228 if (!bool (EDITOR_GET (" editors/shader_editor/behavior/files/restore_shaders_on_load" ))) {
241229 return ;
242230 }
231+
243232 if (!p_layout->has_section (" ShaderEditor" )) {
244233 return ;
245234 }
235+
246236 if (!p_layout->has_section_key (" ShaderEditor" , " open_shaders" ) ||
247237 !p_layout->has_section_key (" ShaderEditor" , " selected_shader" )) {
248238 return ;
@@ -275,23 +265,17 @@ void ShaderEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
275265}
276266
277267void ShaderEditorPlugin::get_window_layout (Ref<ConfigFile> p_layout) {
278- if (window_wrapper->get_window_enabled ()) {
279- p_layout->set_value (" ShaderEditor" , " window_rect" , window_wrapper->get_window_rect ());
280- int screen = window_wrapper->get_window_screen ();
281- p_layout->set_value (" ShaderEditor" , " window_screen" , screen);
282- p_layout->set_value (" ShaderEditor" , " window_screen_rect" , DisplayServer::get_singleton ()->screen_get_usable_rect (screen));
283-
284- } else {
285- if (p_layout->has_section_key (" ShaderEditor" , " window_rect" )) {
286- p_layout->erase_section_key (" ShaderEditor" , " window_rect" );
287- }
288- if (p_layout->has_section_key (" ShaderEditor" , " window_screen" )) {
289- p_layout->erase_section_key (" ShaderEditor" , " window_screen" );
290- }
291- if (p_layout->has_section_key (" ShaderEditor" , " window_screen_rect" )) {
292- p_layout->erase_section_key (" ShaderEditor" , " window_screen_rect" );
293- }
268+ #ifndef DISABLE_DEPRECATED
269+ if (p_layout->has_section_key (" ShaderEditor" , " window_rect" )) {
270+ p_layout->erase_section_key (" ShaderEditor" , " window_rect" );
271+ }
272+ if (p_layout->has_section_key (" ShaderEditor" , " window_screen" )) {
273+ p_layout->erase_section_key (" ShaderEditor" , " window_screen" );
294274 }
275+ if (p_layout->has_section_key (" ShaderEditor" , " window_screen_rect" )) {
276+ p_layout->erase_section_key (" ShaderEditor" , " window_screen_rect" );
277+ }
278+ #endif
295279
296280 Array shaders;
297281 String selected_shader;
@@ -465,10 +449,6 @@ void ShaderEditorPlugin::_close_shader(int p_index) {
465449 if (file_menu->get_parent () != nullptr ) {
466450 file_menu->get_parent ()->remove_child (file_menu);
467451 }
468- if (make_floating->get_parent ()) {
469- make_floating->get_parent ()->remove_child (make_floating);
470- }
471- empty_menu->set_visible (false );
472452 ShaderEditor *shader_editor = Object::cast_to<ShaderEditor>(shader_tabs->get_tab_control (p_index));
473453 ERR_FAIL_NULL (shader_editor);
474454
@@ -479,8 +459,8 @@ void ShaderEditorPlugin::_close_shader(int p_index) {
479459
480460 if (shader_tabs->get_tab_count () == 0 ) {
481461 shader_list->show (); // Make sure the panel is visible, because it can't be toggled without open shaders.
482- empty_menu-> add_child (file_menu );
483- empty_menu-> set_visible ( true );
462+ shader_tabs-> hide ( );
463+ files_split-> add_child (file_menu );
484464 } else {
485465 _switch_to_editor (edited_shaders[shader_tabs->get_current_tab ()].shader_editor );
486466 }
@@ -769,10 +749,6 @@ void ShaderEditorPlugin::drop_data_fw(const Point2 &p_point, const Variant &p_da
769749 }
770750}
771751
772- void ShaderEditorPlugin::_window_changed (bool p_visible) {
773- make_floating->set_visible (!p_visible);
774- }
775-
776752void ShaderEditorPlugin::_set_text_shader_zoom_factor (float p_zoom_factor) {
777753 if (text_shader_zoom_factor == p_zoom_factor) {
778754 return ;
@@ -792,11 +768,8 @@ void ShaderEditorPlugin::_switch_to_editor(ShaderEditor *p_editor, bool p_focus)
792768 if (file_menu->get_parent () != nullptr ) {
793769 file_menu->get_parent ()->remove_child (file_menu);
794770 }
795- if (make_floating->get_parent () != nullptr ) {
796- make_floating->get_parent ()->remove_child (make_floating);
797- }
798- empty_menu->set_visible (false );
799- p_editor->use_menu_bar_items (file_menu, make_floating);
771+ shader_tabs->show ();
772+ p_editor->use_menu_bar (file_menu);
800773 if (p_focus) {
801774 TextShaderEditor *text_shader_editor = Object::cast_to<TextShaderEditor>(p_editor);
802775 if (text_shader_editor) {
@@ -859,6 +832,16 @@ void ShaderEditorPlugin::_notification(int p_what) {
859832 }
860833}
861834
835+ void ShaderEditorPlugin::shortcut_input (const Ref<InputEvent> &p_event) {
836+ if (p_event.is_null () || !p_event->is_pressed () || p_event->is_echo ()) {
837+ return ;
838+ }
839+
840+ if (make_floating_shortcut.is_valid () && make_floating_shortcut->matches_event (p_event)) {
841+ EditorDockManager::get_singleton ()->make_dock_floating (shader_dock);
842+ }
843+ }
844+
862845ShaderEditorPlugin::ShaderEditorPlugin () {
863846 ED_SHORTCUT (" shader_editor/new" , TTRC (" New Shader..." ), KeyModifierMask::CMD_OR_CTRL | Key::N);
864847 ED_SHORTCUT (" shader_editor/new_include" , TTRC (" New Shader Include..." ), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::N);
@@ -868,80 +851,66 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
868851 ED_SHORTCUT (" shader_editor/inspect_native_code" , TTRC (" Inspect Native Shader Code..." ));
869852 ED_SHORTCUT (" shader_editor/copy_path" , TTRC (" Copy Shader Path" ));
870853
871- window_wrapper = memnew (WindowWrapper);
872- window_wrapper->set_window_title (vformat (TTR (" %s - Godot Engine" ), TTR (" Shader Editor" )));
873- window_wrapper->set_margins_enabled (true );
854+ shader_dock = memnew (EditorDock);
855+ shader_dock->set_name (TTRC (" Shader Editor" ));
856+ shader_dock->set_icon_name (" ShaderDock" );
857+ 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));
858+ shader_dock->set_default_slot (DockConstants::DOCK_SLOT_BOTTOM);
859+ shader_dock->set_available_layouts (EditorDock::DOCK_LAYOUT_HORIZONTAL | EditorDock::DOCK_LAYOUT_FLOATING);
860+ EditorDockManager::get_singleton ()->add_dock (shader_dock);
861+
862+ set_process_shortcut_input (true );
874863
875- main_container = memnew (VBoxContainer);
876- Ref<Shortcut> make_floating_shortcut = ED_SHORTCUT_AND_COMMAND (" shader_editor/make_floating" , TTRC (" Make Floating" ));
877- window_wrapper->set_wrapped_control (main_container, make_floating_shortcut);
864+ make_floating_shortcut = ED_SHORTCUT_AND_COMMAND (" shader_editor/make_floating" , TTRC (" Make Floating" ));
878865
879866 files_split = memnew (HSplitContainer);
880867 files_split->set_split_offset (200 * EDSCALE);
881868 files_split->set_v_size_flags (Control::SIZE_EXPAND_FILL);
882-
883- file_menu = memnew (MenuButton);
884- file_menu->set_flat (false );
885- file_menu->set_theme_type_variation (" FlatMenuButton" );
886- file_menu->set_text (TTR (" File" ));
887- file_menu->set_switch_on_hover (true );
888- file_menu->set_shortcut_context (files_split);
889- _setup_popup_menu (FILE, file_menu->get_popup ());
890- file_menu->get_popup ()->connect (SceneStringName (id_pressed), callable_mp (this , &ShaderEditorPlugin::_menu_item_pressed));
891-
892- _set_file_specific_items_disabled (true );
869+ shader_dock->add_child (files_split);
893870
894871 context_menu = memnew (PopupMenu);
895- add_child (context_menu);
896872 context_menu->connect (SceneStringName (id_pressed), callable_mp (this , &ShaderEditorPlugin::_menu_item_pressed));
897-
898- make_floating = memnew (ScreenSelect);
899- make_floating->connect (" request_open_in_screen" , callable_mp (window_wrapper, &WindowWrapper::enable_window_on_screen).bind (true ));
900- if (!make_floating->is_disabled ()) {
901- // Override default ScreenSelect tooltip if multi-window support is available.
902- make_floating->set_tooltip_text (TTR (" Make the shader editor floating." ) + " \n " + TTR (" Right-click to open the screen selector." ));
903- }
904-
905- window_wrapper->connect (" window_visibility_changed" , callable_mp (this , &ShaderEditorPlugin::_window_changed));
873+ add_child (context_menu);
906874
907875 shader_list = memnew (ItemList);
908876 shader_list->set_auto_translate_mode (AUTO_TRANSLATE_MODE_DISABLED);
909877 shader_list->set_v_size_flags (Control::SIZE_EXPAND_FILL);
910878 shader_list->set_theme_type_variation (" ItemListSecondary" );
911879 shader_list->set_custom_minimum_size (Size2 (100 , 60 ) * EDSCALE);
912- files_split->add_child (shader_list);
913880 shader_list->connect (SceneStringName (item_selected), callable_mp (this , &ShaderEditorPlugin::_shader_selected).bind (true ));
914881 shader_list->connect (" item_clicked" , callable_mp (this , &ShaderEditorPlugin::_shader_list_clicked));
915882 shader_list->set_allow_rmb_select (true );
916883 SET_DRAG_FORWARDING_GCD (shader_list, ShaderEditorPlugin);
917-
918- main_container->add_child (files_split);
919- main_container->set_custom_minimum_size (Size2 (100 , 300 ) * EDSCALE);
920-
921- VBoxContainer *shader_vb = memnew (VBoxContainer);
922- shader_vb->set_h_size_flags (Control::SIZE_EXPAND_FILL);
923- files_split->add_child (shader_vb);
924- empty_menu = memnew (HBoxContainer);
925- shader_vb->add_child (empty_menu);
926- empty_menu->add_child (file_menu);
927- empty_menu->add_theme_style_override (SceneStringName (panel), EditorNode::get_singleton ()->get_editor_theme ()->get_stylebox (SNAME (" ScriptEditorPanel" ), EditorStringName (EditorStyles)));
884+ files_split->add_child (shader_list);
928885
929886 shader_tabs = memnew (TabContainer);
930887 shader_tabs->set_custom_minimum_size (Size2 (460 , 300 ) * EDSCALE);
931888 shader_tabs->set_tabs_visible (false );
932889 shader_tabs->set_h_size_flags (Control::SIZE_EXPAND_FILL);
933890 shader_tabs->set_v_size_flags (Control::SIZE_EXPAND_FILL);
934- shader_vb->add_child (shader_tabs);
935891 Ref<StyleBoxEmpty> empty;
936892 empty.instantiate ();
937893 shader_tabs->add_theme_style_override (SceneStringName (panel), empty);
894+ shader_tabs->hide ();
895+ files_split->add_child (shader_tabs);
938896
939- 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));
897+ file_menu = memnew (MenuButton);
898+ file_menu->set_flat (false );
899+ file_menu->set_theme_type_variation (" FlatMenuButton" );
900+ file_menu->set_text (TTRC (" File" ));
901+ file_menu->set_h_size_flags (Control::SIZE_SHRINK_BEGIN);
902+ file_menu->set_v_size_flags (Control::SIZE_SHRINK_BEGIN);
903+ file_menu->set_switch_on_hover (true );
904+ file_menu->set_shortcut_context (files_split);
905+ file_menu->get_popup ()->connect (SceneStringName (id_pressed), callable_mp (this , &ShaderEditorPlugin::_menu_item_pressed));
906+ _setup_popup_menu (FILE, file_menu->get_popup ());
907+ _set_file_specific_items_disabled (true );
908+ files_split->add_child (file_menu);
940909
941910 shader_create_dialog = memnew (ShaderCreateDialog);
942- files_split->add_child (shader_create_dialog);
943911 shader_create_dialog->connect (" shader_created" , callable_mp (this , &ShaderEditorPlugin::_shader_created));
944912 shader_create_dialog->connect (" shader_include_created" , callable_mp (this , &ShaderEditorPlugin::_shader_include_created));
913+ shader_dock->add_child (shader_create_dialog);
945914
946915 Ref<TextShaderLanguagePlugin> text_shader_lang;
947916 text_shader_lang.instantiate ();
@@ -955,5 +924,4 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
955924ShaderEditorPlugin::~ShaderEditorPlugin () {
956925 EditorShaderLanguagePlugin::clear_registered_shader_languages ();
957926 memdelete (file_menu);
958- memdelete (make_floating);
959927}
0 commit comments