Skip to content

Commit 7b9c512

Browse files
committed
Merge pull request #105183 from lodetrick/shader-ui-shuffle
Make shader editor menu position consistent with script editor
2 parents 759fb58 + 07c91e8 commit 7b9c512

File tree

3 files changed

+75
-43
lines changed

3 files changed

+75
-43
lines changed

editor/plugins/shader_editor_plugin.cpp

Lines changed: 72 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void ShaderEditorPlugin::edit(Object *p_object) {
152152
}
153153
es.shader_inc = Ref<ShaderInclude>(si);
154154
TextShaderEditor *text_shader = memnew(TextShaderEditor);
155-
text_shader->get_code_editor()->set_toggle_list_control(left_panel);
155+
text_shader->get_code_editor()->set_toggle_list_control(shader_list);
156156
es.shader_editor = text_shader;
157157
es.shader_editor->edit_shader_include(si);
158158
shader_tabs->add_child(es.shader_editor);
@@ -170,11 +170,11 @@ void ShaderEditorPlugin::edit(Object *p_object) {
170170
Ref<VisualShader> vs = es.shader;
171171
if (vs.is_valid()) {
172172
VisualShaderEditor *vs_editor = memnew(VisualShaderEditor);
173-
vs_editor->set_toggle_list_control(left_panel);
173+
vs_editor->set_toggle_list_control(shader_list);
174174
es.shader_editor = vs_editor;
175175
} else {
176176
TextShaderEditor *text_shader = memnew(TextShaderEditor);
177-
text_shader->get_code_editor()->set_toggle_list_control(left_panel);
177+
text_shader->get_code_editor()->set_toggle_list_control(shader_list);
178178
es.shader_editor = text_shader;
179179
}
180180
shader_tabs->add_child(es.shader_editor);
@@ -189,6 +189,12 @@ void ShaderEditorPlugin::edit(Object *p_object) {
189189
cte->set_zoom_factor(text_shader_zoom_factor);
190190
cte->connect("zoomed", callable_mp(this, &ShaderEditorPlugin::_set_text_shader_zoom_factor));
191191
}
192+
193+
if (text_shader_editor->get_top_bar()) {
194+
text_shader_editor->get_top_bar()->set_h_size_flags(Control::SIZE_EXPAND_FILL);
195+
menu_hb->add_child(text_shader_editor->get_top_bar());
196+
menu_hb->move_child(text_shader_editor->get_top_bar(), 1);
197+
}
192198
}
193199

194200
shader_tabs->set_current_tab(shader_tabs->get_tab_count() - 1);
@@ -255,7 +261,7 @@ void ShaderEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
255261
}
256262

257263
if (p_layout->has_section_key("ShaderEditor", "split_offset")) {
258-
main_split->set_split_offset(p_layout->get_value("ShaderEditor", "split_offset"));
264+
files_split->set_split_offset(p_layout->get_value("ShaderEditor", "split_offset"));
259265
}
260266

261267
_update_shader_list();
@@ -305,7 +311,7 @@ void ShaderEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) {
305311
}
306312
}
307313
p_layout->set_value("ShaderEditor", "open_shaders", shaders);
308-
p_layout->set_value("ShaderEditor", "split_offset", main_split->get_split_offset());
314+
p_layout->set_value("ShaderEditor", "split_offset", files_split->get_split_offset());
309315
p_layout->set_value("ShaderEditor", "selected_shader", selected_shader);
310316
p_layout->set_value("ShaderEditor", "text_shader_zoom_factor", text_shader_zoom_factor);
311317
}
@@ -436,34 +442,38 @@ void ShaderEditorPlugin::_make_script_list_context_menu() {
436442
context_menu->set_item_disabled(context_menu->get_item_index(CLOSE_ALL), shader_tabs->get_tab_count() <= 0);
437443
context_menu->set_item_disabled(context_menu->get_item_index(CLOSE_OTHER_TABS), shader_tabs->get_tab_count() <= 1);
438444

439-
context_menu->set_position(main_split->get_screen_position() + main_split->get_local_mouse_position());
445+
context_menu->set_position(files_split->get_screen_position() + files_split->get_local_mouse_position());
440446
context_menu->reset_size();
441447
context_menu->popup();
442448
}
443449

444450
void ShaderEditorPlugin::_close_shader(int p_index) {
445451
ERR_FAIL_INDEX(p_index, shader_tabs->get_tab_count());
446452

447-
file_menu->get_parent()->remove_child(file_menu);
448-
make_floating->get_parent()->remove_child(make_floating);
449-
450453
Control *c = shader_tabs->get_tab_control(p_index);
454+
VisualShaderEditor *vs_editor = Object::cast_to<VisualShaderEditor>(c);
455+
if (vs_editor) {
456+
file_menu->get_parent()->remove_child(file_menu);
457+
menu_hb->add_child(file_menu);
458+
menu_hb->move_child(file_menu, 0);
459+
460+
make_floating->get_parent()->remove_child(make_floating);
461+
menu_hb->add_child(make_floating);
462+
} else {
463+
memdelete(edited_shaders[p_index].shader_editor->get_top_bar());
464+
}
465+
451466
memdelete(c);
452467
edited_shaders.remove_at(p_index);
453468
_update_shader_list();
454469
EditorUndoRedoManager::get_singleton()->clear_history(); // To prevent undo on deleted graphs.
455470

456-
Control *bar = nullptr;
457471
if (shader_tabs->get_tab_count() == 0) {
458-
left_panel->show(); // Make sure the panel is visible, because it can't be toggled without open shaders.
459-
bar = menu_hb;
472+
shader_list->show(); // Make sure the panel is visible, because it can't be toggled without open shaders.
473+
menu_spacer->show();
460474
} else {
461-
bar = edited_shaders[shader_tabs->get_current_tab()].shader_editor->get_top_bar();
475+
_switch_to_editor(edited_shaders[shader_tabs->get_current_tab()].shader_editor);
462476
}
463-
464-
bar->add_child(file_menu);
465-
bar->move_child(file_menu, 0);
466-
bar->add_child(make_floating);
467477
}
468478

469479
void ShaderEditorPlugin::_close_builtin_shaders_from_scene(const String &p_scene) {
@@ -611,7 +621,7 @@ void ShaderEditorPlugin::_menu_item_pressed(int p_index) {
611621
DisplayServer::get_singleton()->clipboard_set(shader->get_path());
612622
} break;
613623
case TOGGLE_FILES_PANEL: {
614-
left_panel->set_visible(!left_panel->is_visible());
624+
shader_list->set_visible(!shader_list->is_visible());
615625

616626
int index = shader_tabs->get_current_tab();
617627
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
666676
Label *label = memnew(Label(preview_name));
667677
label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Don't translate script names.
668678
drag_preview->add_child(label);
669-
main_split->set_drag_preview(drag_preview);
679+
files_split->set_drag_preview(drag_preview);
670680

671681
Dictionary drag_data;
672682
drag_data["type"] = "shader_list_element";
@@ -775,19 +785,40 @@ void ShaderEditorPlugin::_set_text_shader_zoom_factor(float p_zoom_factor) {
775785
void ShaderEditorPlugin::_switch_to_editor(ShaderEditor *p_editor) {
776786
Control *bar = p_editor->get_top_bar();
777787

778-
int file_menu_index = 0;
779-
780788
VisualShaderEditor *vs_editor = Object::cast_to<VisualShaderEditor>(p_editor);
781789
if (vs_editor) {
782-
file_menu_index = 2; // Toggle Files Panel button + separator
783-
}
790+
file_menu->get_parent()->remove_child(file_menu);
791+
bar->add_child(file_menu);
792+
bar->move_child(file_menu, 2); // Toggle Files Panel button + separator.
784793

785-
file_menu->get_parent()->remove_child(file_menu);
786-
bar->add_child(file_menu);
787-
bar->move_child(file_menu, file_menu_index);
794+
make_floating->get_parent()->remove_child(make_floating);
795+
bar->add_child(make_floating);
796+
} else {
797+
if (menu_spacer->is_visible()) {
798+
menu_spacer->hide();
799+
}
800+
801+
// Just swapped from a visual shader editor.
802+
if (file_menu->get_parent() != menu_hb) {
803+
file_menu->get_parent()->remove_child(file_menu);
804+
menu_hb->add_child(file_menu);
805+
menu_hb->move_child(file_menu, 0);
806+
807+
make_floating->get_parent()->remove_child(make_floating);
808+
menu_hb->add_child(make_floating);
809+
}
810+
}
788811

789-
make_floating->get_parent()->remove_child(make_floating);
790-
bar->add_child(make_floating);
812+
for (int i = 0; i < shader_tabs->get_tab_count(); i++) {
813+
ShaderEditor *se = Object::cast_to<ShaderEditor>(shader_tabs->get_tab_control(i));
814+
if (se && se->get_top_bar()) {
815+
if (se == p_editor) {
816+
se->get_top_bar()->show();
817+
} else {
818+
se->get_top_bar()->hide();
819+
}
820+
}
821+
}
791822
}
792823

793824
void ShaderEditorPlugin::_file_removed(const String &p_removed_file) {
@@ -849,18 +880,19 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
849880
window_wrapper->set_window_title(vformat(TTR("%s - Godot Engine"), TTR("Shader Editor")));
850881
window_wrapper->set_margins_enabled(true);
851882

852-
main_split = memnew(HSplitContainer);
853-
main_split->set_split_offset(200 * EDSCALE);
883+
main_container = memnew(VBoxContainer);
854884
Ref<Shortcut> make_floating_shortcut = ED_SHORTCUT_AND_COMMAND("shader_editor/make_floating", TTRC("Make Floating"));
855-
window_wrapper->set_wrapped_control(main_split, make_floating_shortcut);
885+
window_wrapper->set_wrapped_control(main_container, make_floating_shortcut);
856886

857-
left_panel = memnew(VBoxContainer);
887+
files_split = memnew(HSplitContainer);
888+
files_split->set_split_offset(200 * EDSCALE);
889+
files_split->set_v_size_flags(Control::SIZE_EXPAND_FILL);
858890

859891
menu_hb = memnew(HBoxContainer);
860-
left_panel->add_child(menu_hb);
892+
main_container->add_child(menu_hb);
861893
file_menu = memnew(MenuButton);
862894
file_menu->set_text(TTR("File"));
863-
file_menu->set_shortcut_context(main_split);
895+
file_menu->set_shortcut_context(files_split);
864896
_setup_popup_menu(FILE, file_menu->get_popup());
865897
file_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &ShaderEditorPlugin::_menu_item_pressed));
866898
menu_hb->add_child(file_menu);
@@ -871,7 +903,7 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
871903
add_child(context_menu);
872904
context_menu->connect(SceneStringName(id_pressed), callable_mp(this, &ShaderEditorPlugin::_menu_item_pressed));
873905

874-
menu_hb->add_spacer();
906+
menu_spacer = menu_hb->add_spacer();
875907

876908
make_floating = memnew(ScreenSelect);
877909
make_floating->set_flat(true);
@@ -888,28 +920,28 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
888920
shader_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
889921
shader_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
890922
shader_list->set_theme_type_variation("ItemListSecondary");
891-
left_panel->add_child(shader_list);
923+
files_split->add_child(shader_list);
892924
shader_list->connect(SceneStringName(item_selected), callable_mp(this, &ShaderEditorPlugin::_shader_selected));
893925
shader_list->connect("item_clicked", callable_mp(this, &ShaderEditorPlugin::_shader_list_clicked));
894926
shader_list->set_allow_rmb_select(true);
895927
SET_DRAG_FORWARDING_GCD(shader_list, ShaderEditorPlugin);
896928

897-
main_split->add_child(left_panel);
898-
left_panel->set_custom_minimum_size(Size2(100, 300) * EDSCALE);
929+
main_container->add_child(files_split);
930+
main_container->set_custom_minimum_size(Size2(100, 300) * EDSCALE);
899931

900932
shader_tabs = memnew(TabContainer);
901933
shader_tabs->set_custom_minimum_size(Size2(460, 300) * EDSCALE);
902934
shader_tabs->set_tabs_visible(false);
903935
shader_tabs->set_h_size_flags(Control::SIZE_EXPAND_FILL);
904-
main_split->add_child(shader_tabs);
936+
files_split->add_child(shader_tabs);
905937
Ref<StyleBoxEmpty> empty;
906938
empty.instantiate();
907939
shader_tabs->add_theme_style_override(SceneStringName(panel), empty);
908940

909941
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));
910942

911943
shader_create_dialog = memnew(ShaderCreateDialog);
912-
main_split->add_child(shader_create_dialog);
944+
files_split->add_child(shader_create_dialog);
913945
shader_create_dialog->connect("shader_created", callable_mp(this, &ShaderEditorPlugin::_shader_created));
914946
shader_create_dialog->connect("shader_include_created", callable_mp(this, &ShaderEditorPlugin::_shader_include_created));
915947
}

editor/plugins/shader_editor_plugin.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ class ShaderEditorPlugin : public EditorPlugin {
8484
CONTEXT_VALID_ITEM,
8585
};
8686

87-
HSplitContainer *main_split = nullptr;
88-
VBoxContainer *left_panel = nullptr;
87+
VBoxContainer *main_container = nullptr;
88+
HSplitContainer *files_split = nullptr;
8989
HBoxContainer *menu_hb = nullptr;
90+
Control *menu_spacer = nullptr;
9091

9192
ItemList *shader_list = nullptr;
9293
TabContainer *shader_tabs = nullptr;

editor/plugins/text_shader_editor.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,6 @@ TextShaderEditor::TextShaderEditor() {
12101210
bookmarks_menu->connect("index_pressed", callable_mp(this, &TextShaderEditor::_bookmark_item_pressed));
12111211

12121212
add_child(main_container);
1213-
main_container->add_child(hbc);
12141213
hbc->add_child(edit_menu);
12151214
hbc->add_child(search_menu);
12161215
hbc->add_child(goto_menu);

0 commit comments

Comments
 (0)