diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 6db7d6d414c..613bb4dbf95 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -152,7 +152,7 @@ void ShaderEditorPlugin::edit(Object *p_object) { } es.shader_inc = Ref(si); TextShaderEditor *text_shader = memnew(TextShaderEditor); - text_shader->get_code_editor()->set_toggle_list_control(left_panel); + text_shader->get_code_editor()->set_toggle_list_control(shader_list); es.shader_editor = text_shader; es.shader_editor->edit_shader_include(si); shader_tabs->add_child(es.shader_editor); @@ -170,11 +170,11 @@ void ShaderEditorPlugin::edit(Object *p_object) { Ref vs = es.shader; if (vs.is_valid()) { VisualShaderEditor *vs_editor = memnew(VisualShaderEditor); - vs_editor->set_toggle_list_control(left_panel); + vs_editor->set_toggle_list_control(shader_list); es.shader_editor = vs_editor; } else { TextShaderEditor *text_shader = memnew(TextShaderEditor); - text_shader->get_code_editor()->set_toggle_list_control(left_panel); + text_shader->get_code_editor()->set_toggle_list_control(shader_list); es.shader_editor = text_shader; } shader_tabs->add_child(es.shader_editor); @@ -189,6 +189,12 @@ void ShaderEditorPlugin::edit(Object *p_object) { cte->set_zoom_factor(text_shader_zoom_factor); cte->connect("zoomed", callable_mp(this, &ShaderEditorPlugin::_set_text_shader_zoom_factor)); } + + if (text_shader_editor->get_top_bar()) { + text_shader_editor->get_top_bar()->set_h_size_flags(Control::SIZE_EXPAND_FILL); + menu_hb->add_child(text_shader_editor->get_top_bar()); + menu_hb->move_child(text_shader_editor->get_top_bar(), 1); + } } shader_tabs->set_current_tab(shader_tabs->get_tab_count() - 1); @@ -255,7 +261,7 @@ void ShaderEditorPlugin::set_window_layout(Ref p_layout) { } if (p_layout->has_section_key("ShaderEditor", "split_offset")) { - main_split->set_split_offset(p_layout->get_value("ShaderEditor", "split_offset")); + files_split->set_split_offset(p_layout->get_value("ShaderEditor", "split_offset")); } _update_shader_list(); @@ -305,7 +311,7 @@ void ShaderEditorPlugin::get_window_layout(Ref p_layout) { } } p_layout->set_value("ShaderEditor", "open_shaders", shaders); - p_layout->set_value("ShaderEditor", "split_offset", main_split->get_split_offset()); + p_layout->set_value("ShaderEditor", "split_offset", files_split->get_split_offset()); p_layout->set_value("ShaderEditor", "selected_shader", selected_shader); p_layout->set_value("ShaderEditor", "text_shader_zoom_factor", text_shader_zoom_factor); } @@ -436,7 +442,7 @@ void ShaderEditorPlugin::_make_script_list_context_menu() { context_menu->set_item_disabled(context_menu->get_item_index(CLOSE_ALL), shader_tabs->get_tab_count() <= 0); context_menu->set_item_disabled(context_menu->get_item_index(CLOSE_OTHER_TABS), shader_tabs->get_tab_count() <= 1); - context_menu->set_position(main_split->get_screen_position() + main_split->get_local_mouse_position()); + context_menu->set_position(files_split->get_screen_position() + files_split->get_local_mouse_position()); context_menu->reset_size(); context_menu->popup(); } @@ -444,26 +450,30 @@ void ShaderEditorPlugin::_make_script_list_context_menu() { void ShaderEditorPlugin::_close_shader(int p_index) { ERR_FAIL_INDEX(p_index, shader_tabs->get_tab_count()); - file_menu->get_parent()->remove_child(file_menu); - make_floating->get_parent()->remove_child(make_floating); - Control *c = shader_tabs->get_tab_control(p_index); + VisualShaderEditor *vs_editor = Object::cast_to(c); + if (vs_editor) { + file_menu->get_parent()->remove_child(file_menu); + menu_hb->add_child(file_menu); + menu_hb->move_child(file_menu, 0); + + make_floating->get_parent()->remove_child(make_floating); + menu_hb->add_child(make_floating); + } else { + memdelete(edited_shaders[p_index].shader_editor->get_top_bar()); + } + memdelete(c); edited_shaders.remove_at(p_index); _update_shader_list(); EditorUndoRedoManager::get_singleton()->clear_history(); // To prevent undo on deleted graphs. - Control *bar = nullptr; if (shader_tabs->get_tab_count() == 0) { - left_panel->show(); // Make sure the panel is visible, because it can't be toggled without open shaders. - bar = menu_hb; + shader_list->show(); // Make sure the panel is visible, because it can't be toggled without open shaders. + menu_spacer->show(); } else { - bar = edited_shaders[shader_tabs->get_current_tab()].shader_editor->get_top_bar(); + _switch_to_editor(edited_shaders[shader_tabs->get_current_tab()].shader_editor); } - - bar->add_child(file_menu); - bar->move_child(file_menu, 0); - bar->add_child(make_floating); } void ShaderEditorPlugin::_close_builtin_shaders_from_scene(const String &p_scene) { @@ -611,7 +621,7 @@ void ShaderEditorPlugin::_menu_item_pressed(int p_index) { DisplayServer::get_singleton()->clipboard_set(shader->get_path()); } break; case TOGGLE_FILES_PANEL: { - left_panel->set_visible(!left_panel->is_visible()); + shader_list->set_visible(!shader_list->is_visible()); int index = shader_tabs->get_current_tab(); ERR_FAIL_INDEX(index, shader_tabs->get_tab_count()); @@ -666,7 +676,7 @@ Variant ShaderEditorPlugin::get_drag_data_fw(const Point2 &p_point, Control *p_f Label *label = memnew(Label(preview_name)); label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Don't translate script names. drag_preview->add_child(label); - main_split->set_drag_preview(drag_preview); + files_split->set_drag_preview(drag_preview); Dictionary drag_data; drag_data["type"] = "shader_list_element"; @@ -775,19 +785,40 @@ void ShaderEditorPlugin::_set_text_shader_zoom_factor(float p_zoom_factor) { void ShaderEditorPlugin::_switch_to_editor(ShaderEditor *p_editor) { Control *bar = p_editor->get_top_bar(); - int file_menu_index = 0; - VisualShaderEditor *vs_editor = Object::cast_to(p_editor); if (vs_editor) { - file_menu_index = 2; // Toggle Files Panel button + separator + file_menu->get_parent()->remove_child(file_menu); + bar->add_child(file_menu); + bar->move_child(file_menu, 2); // Toggle Files Panel button + separator. + + make_floating->get_parent()->remove_child(make_floating); + bar->add_child(make_floating); + } else { + if (menu_spacer->is_visible()) { + menu_spacer->hide(); + } + + // Just swapped from a visual shader editor. + if (file_menu->get_parent() != menu_hb) { + file_menu->get_parent()->remove_child(file_menu); + menu_hb->add_child(file_menu); + menu_hb->move_child(file_menu, 0); + + make_floating->get_parent()->remove_child(make_floating); + menu_hb->add_child(make_floating); + } } - file_menu->get_parent()->remove_child(file_menu); - bar->add_child(file_menu); - bar->move_child(file_menu, file_menu_index); - - make_floating->get_parent()->remove_child(make_floating); - bar->add_child(make_floating); + for (int i = 0; i < shader_tabs->get_tab_count(); i++) { + ShaderEditor *se = Object::cast_to(shader_tabs->get_tab_control(i)); + if (se && se->get_top_bar()) { + if (se == p_editor) { + se->get_top_bar()->show(); + } else { + se->get_top_bar()->hide(); + } + } + } } void ShaderEditorPlugin::_file_removed(const String &p_removed_file) { @@ -849,18 +880,19 @@ ShaderEditorPlugin::ShaderEditorPlugin() { window_wrapper->set_window_title(vformat(TTR("%s - Godot Engine"), TTR("Shader Editor"))); window_wrapper->set_margins_enabled(true); - main_split = memnew(HSplitContainer); - main_split->set_split_offset(200 * EDSCALE); + 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_split, make_floating_shortcut); + window_wrapper->set_wrapped_control(main_container, make_floating_shortcut); - left_panel = memnew(VBoxContainer); + files_split = memnew(HSplitContainer); + files_split->set_split_offset(200 * EDSCALE); + files_split->set_v_size_flags(Control::SIZE_EXPAND_FILL); menu_hb = memnew(HBoxContainer); - left_panel->add_child(menu_hb); + main_container->add_child(menu_hb); file_menu = memnew(MenuButton); file_menu->set_text(TTR("File")); - file_menu->set_shortcut_context(main_split); + 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)); menu_hb->add_child(file_menu); @@ -871,7 +903,7 @@ ShaderEditorPlugin::ShaderEditorPlugin() { add_child(context_menu); context_menu->connect(SceneStringName(id_pressed), callable_mp(this, &ShaderEditorPlugin::_menu_item_pressed)); - menu_hb->add_spacer(); + menu_spacer = menu_hb->add_spacer(); make_floating = memnew(ScreenSelect); make_floating->set_flat(true); @@ -888,20 +920,20 @@ ShaderEditorPlugin::ShaderEditorPlugin() { 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"); - left_panel->add_child(shader_list); + files_split->add_child(shader_list); shader_list->connect(SceneStringName(item_selected), callable_mp(this, &ShaderEditorPlugin::_shader_selected)); 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_split->add_child(left_panel); - left_panel->set_custom_minimum_size(Size2(100, 300) * EDSCALE); + main_container->add_child(files_split); + main_container->set_custom_minimum_size(Size2(100, 300) * EDSCALE); 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); - main_split->add_child(shader_tabs); + files_split->add_child(shader_tabs); Ref empty; empty.instantiate(); shader_tabs->add_theme_style_override(SceneStringName(panel), empty); @@ -909,7 +941,7 @@ ShaderEditorPlugin::ShaderEditorPlugin() { button = EditorNode::get_bottom_panel()->add_item(TTR("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)); shader_create_dialog = memnew(ShaderCreateDialog); - main_split->add_child(shader_create_dialog); + 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)); } diff --git a/editor/plugins/shader_editor_plugin.h b/editor/plugins/shader_editor_plugin.h index 84db82d9c2e..999e178e7c6 100644 --- a/editor/plugins/shader_editor_plugin.h +++ b/editor/plugins/shader_editor_plugin.h @@ -84,9 +84,10 @@ class ShaderEditorPlugin : public EditorPlugin { CONTEXT_VALID_ITEM, }; - HSplitContainer *main_split = nullptr; - VBoxContainer *left_panel = nullptr; + VBoxContainer *main_container = nullptr; + HSplitContainer *files_split = nullptr; HBoxContainer *menu_hb = nullptr; + Control *menu_spacer = nullptr; ItemList *shader_list = nullptr; TabContainer *shader_tabs = nullptr; diff --git a/editor/plugins/text_shader_editor.cpp b/editor/plugins/text_shader_editor.cpp index 2aa74973614..48d25952305 100644 --- a/editor/plugins/text_shader_editor.cpp +++ b/editor/plugins/text_shader_editor.cpp @@ -1210,7 +1210,6 @@ TextShaderEditor::TextShaderEditor() { bookmarks_menu->connect("index_pressed", callable_mp(this, &TextShaderEditor::_bookmark_item_pressed)); add_child(main_container); - main_container->add_child(hbc); hbc->add_child(edit_menu); hbc->add_child(search_menu); hbc->add_child(goto_menu);