@@ -152,7 +152,7 @@ void ShaderEditorPlugin::edit(Object *p_object) {
152
152
}
153
153
es.shader_inc = Ref<ShaderInclude>(si);
154
154
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 );
156
156
es.shader_editor = text_shader;
157
157
es.shader_editor ->edit_shader_include (si);
158
158
shader_tabs->add_child (es.shader_editor );
@@ -170,11 +170,11 @@ void ShaderEditorPlugin::edit(Object *p_object) {
170
170
Ref<VisualShader> vs = es.shader ;
171
171
if (vs.is_valid ()) {
172
172
VisualShaderEditor *vs_editor = memnew (VisualShaderEditor);
173
- vs_editor->set_toggle_list_control (left_panel );
173
+ vs_editor->set_toggle_list_control (shader_list );
174
174
es.shader_editor = vs_editor;
175
175
} else {
176
176
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 );
178
178
es.shader_editor = text_shader;
179
179
}
180
180
shader_tabs->add_child (es.shader_editor );
@@ -189,6 +189,12 @@ void ShaderEditorPlugin::edit(Object *p_object) {
189
189
cte->set_zoom_factor (text_shader_zoom_factor);
190
190
cte->connect (" zoomed" , callable_mp (this , &ShaderEditorPlugin::_set_text_shader_zoom_factor));
191
191
}
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
+ }
192
198
}
193
199
194
200
shader_tabs->set_current_tab (shader_tabs->get_tab_count () - 1 );
@@ -255,7 +261,7 @@ void ShaderEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
255
261
}
256
262
257
263
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" ));
259
265
}
260
266
261
267
_update_shader_list ();
@@ -305,7 +311,7 @@ void ShaderEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) {
305
311
}
306
312
}
307
313
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 ());
309
315
p_layout->set_value (" ShaderEditor" , " selected_shader" , selected_shader);
310
316
p_layout->set_value (" ShaderEditor" , " text_shader_zoom_factor" , text_shader_zoom_factor);
311
317
}
@@ -436,34 +442,38 @@ void ShaderEditorPlugin::_make_script_list_context_menu() {
436
442
context_menu->set_item_disabled (context_menu->get_item_index (CLOSE_ALL), shader_tabs->get_tab_count () <= 0 );
437
443
context_menu->set_item_disabled (context_menu->get_item_index (CLOSE_OTHER_TABS), shader_tabs->get_tab_count () <= 1 );
438
444
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 ());
440
446
context_menu->reset_size ();
441
447
context_menu->popup ();
442
448
}
443
449
444
450
void ShaderEditorPlugin::_close_shader (int p_index) {
445
451
ERR_FAIL_INDEX (p_index, shader_tabs->get_tab_count ());
446
452
447
- file_menu->get_parent ()->remove_child (file_menu);
448
- make_floating->get_parent ()->remove_child (make_floating);
449
-
450
453
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
+
451
466
memdelete (c);
452
467
edited_shaders.remove_at (p_index);
453
468
_update_shader_list ();
454
469
EditorUndoRedoManager::get_singleton ()->clear_history (); // To prevent undo on deleted graphs.
455
470
456
- Control *bar = nullptr ;
457
471
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 () ;
460
474
} 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 );
462
476
}
463
-
464
- bar->add_child (file_menu);
465
- bar->move_child (file_menu, 0 );
466
- bar->add_child (make_floating);
467
477
}
468
478
469
479
void ShaderEditorPlugin::_close_builtin_shaders_from_scene (const String &p_scene) {
@@ -611,7 +621,7 @@ void ShaderEditorPlugin::_menu_item_pressed(int p_index) {
611
621
DisplayServer::get_singleton ()->clipboard_set (shader->get_path ());
612
622
} break ;
613
623
case TOGGLE_FILES_PANEL: {
614
- left_panel ->set_visible (!left_panel ->is_visible ());
624
+ shader_list ->set_visible (!shader_list ->is_visible ());
615
625
616
626
int index = shader_tabs->get_current_tab ();
617
627
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
666
676
Label *label = memnew (Label (preview_name));
667
677
label->set_auto_translate_mode (AUTO_TRANSLATE_MODE_DISABLED); // Don't translate script names.
668
678
drag_preview->add_child (label);
669
- main_split ->set_drag_preview (drag_preview);
679
+ files_split ->set_drag_preview (drag_preview);
670
680
671
681
Dictionary drag_data;
672
682
drag_data[" type" ] = " shader_list_element" ;
@@ -775,19 +785,40 @@ void ShaderEditorPlugin::_set_text_shader_zoom_factor(float p_zoom_factor) {
775
785
void ShaderEditorPlugin::_switch_to_editor (ShaderEditor *p_editor) {
776
786
Control *bar = p_editor->get_top_bar ();
777
787
778
- int file_menu_index = 0 ;
779
-
780
788
VisualShaderEditor *vs_editor = Object::cast_to<VisualShaderEditor>(p_editor);
781
789
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.
784
793
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
+ }
788
811
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
+ }
791
822
}
792
823
793
824
void ShaderEditorPlugin::_file_removed (const String &p_removed_file) {
@@ -849,18 +880,19 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
849
880
window_wrapper->set_window_title (vformat (TTR (" %s - Godot Engine" ), TTR (" Shader Editor" )));
850
881
window_wrapper->set_margins_enabled (true );
851
882
852
- main_split = memnew (HSplitContainer);
853
- main_split->set_split_offset (200 * EDSCALE);
883
+ main_container = memnew (VBoxContainer);
854
884
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);
856
886
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);
858
890
859
891
menu_hb = memnew (HBoxContainer);
860
- left_panel ->add_child (menu_hb);
892
+ main_container ->add_child (menu_hb);
861
893
file_menu = memnew (MenuButton);
862
894
file_menu->set_text (TTR (" File" ));
863
- file_menu->set_shortcut_context (main_split );
895
+ file_menu->set_shortcut_context (files_split );
864
896
_setup_popup_menu (FILE, file_menu->get_popup ());
865
897
file_menu->get_popup ()->connect (SceneStringName (id_pressed), callable_mp (this , &ShaderEditorPlugin::_menu_item_pressed));
866
898
menu_hb->add_child (file_menu);
@@ -871,7 +903,7 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
871
903
add_child (context_menu);
872
904
context_menu->connect (SceneStringName (id_pressed), callable_mp (this , &ShaderEditorPlugin::_menu_item_pressed));
873
905
874
- menu_hb->add_spacer ();
906
+ menu_spacer = menu_hb->add_spacer ();
875
907
876
908
make_floating = memnew (ScreenSelect);
877
909
make_floating->set_flat (true );
@@ -888,28 +920,28 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
888
920
shader_list->set_auto_translate_mode (AUTO_TRANSLATE_MODE_DISABLED);
889
921
shader_list->set_v_size_flags (Control::SIZE_EXPAND_FILL);
890
922
shader_list->set_theme_type_variation (" ItemListSecondary" );
891
- left_panel ->add_child (shader_list);
923
+ files_split ->add_child (shader_list);
892
924
shader_list->connect (SceneStringName (item_selected), callable_mp (this , &ShaderEditorPlugin::_shader_selected));
893
925
shader_list->connect (" item_clicked" , callable_mp (this , &ShaderEditorPlugin::_shader_list_clicked));
894
926
shader_list->set_allow_rmb_select (true );
895
927
SET_DRAG_FORWARDING_GCD (shader_list, ShaderEditorPlugin);
896
928
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);
899
931
900
932
shader_tabs = memnew (TabContainer);
901
933
shader_tabs->set_custom_minimum_size (Size2 (460 , 300 ) * EDSCALE);
902
934
shader_tabs->set_tabs_visible (false );
903
935
shader_tabs->set_h_size_flags (Control::SIZE_EXPAND_FILL);
904
- main_split ->add_child (shader_tabs);
936
+ files_split ->add_child (shader_tabs);
905
937
Ref<StyleBoxEmpty> empty;
906
938
empty.instantiate ();
907
939
shader_tabs->add_theme_style_override (SceneStringName (panel), empty);
908
940
909
941
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));
910
942
911
943
shader_create_dialog = memnew (ShaderCreateDialog);
912
- main_split ->add_child (shader_create_dialog);
944
+ files_split ->add_child (shader_create_dialog);
913
945
shader_create_dialog->connect (" shader_created" , callable_mp (this , &ShaderEditorPlugin::_shader_created));
914
946
shader_create_dialog->connect (" shader_include_created" , callable_mp (this , &ShaderEditorPlugin::_shader_include_created));
915
947
}
0 commit comments