@@ -67,36 +67,45 @@ void ShaderCreateDialog::_notification(int p_what) {
6767 } break ;
6868
6969 case NOTIFICATION_THEME_CHANGED: {
70- static const char *shader_types[3 ] = { " Shader" , " VisualShader" , " TextFile" };
71- for (int i = 0 ; i < 3 ; i++) {
72- Ref<Texture2D> icon = get_editor_theme_icon (shader_types[i]);
73- if (icon.is_valid ()) {
74- type_menu->set_item_icon (i, icon);
75- }
76- }
77-
70+ _refresh_type_icons ();
7871 path_button->set_button_icon (get_editor_theme_icon (SNAME (" Folder" )));
7972 } break ;
8073 }
8174}
8275
76+ void ShaderCreateDialog::_refresh_type_icons () {
77+ for (int i = 0 ; i < type_menu->get_item_count (); i++) {
78+ const String item_name = type_menu->get_item_text (i);
79+ Ref<Texture2D> icon = get_editor_theme_icon (item_name);
80+ if (icon.is_valid ()) {
81+ type_menu->set_item_icon (i, icon);
82+ } else {
83+ icon = get_editor_theme_icon (" TextFile" );
84+ if (icon.is_valid ()) {
85+ type_menu->set_item_icon (i, icon);
86+ }
87+ }
88+ }
89+ }
90+
8391void ShaderCreateDialog::_update_language_info () {
8492 type_data.clear ();
8593
8694 for (int i = 0 ; i < SHADER_TYPE_MAX; i++) {
8795 ShaderTypeData shader_type_data;
8896 if (i == int (SHADER_TYPE_TEXT)) {
8997 shader_type_data.use_templates = true ;
90- shader_type_data.extensions .push_back (" gdshader" );
9198 shader_type_data.default_extension = " gdshader" ;
9299 } else if (i == int (SHADER_TYPE_INC)) {
93- shader_type_data.extensions .push_back (" gdshaderinc" );
94100 shader_type_data.default_extension = " gdshaderinc" ;
95101 } else {
96102 shader_type_data.default_extension = " tres" ;
97103 }
104+ shader_type_data.extensions .push_back (shader_type_data.default_extension );
105+ if (shader_type_data.default_extension != " tres" ) {
106+ shader_type_data.extensions .push_back (" tres" );
107+ }
98108 shader_type_data.extensions .push_back (" res" );
99- shader_type_data.extensions .push_back (" tres" );
100109 type_data.push_back (shader_type_data);
101110 }
102111}
@@ -432,31 +441,33 @@ void ShaderCreateDialog::config(const String &p_base_path, bool p_built_in_enabl
432441}
433442
434443String ShaderCreateDialog::_validate_path (const String &p_path) {
435- String p = p_path.strip_edges ();
444+ ERR_FAIL_COND_V (current_type >= type_data.size (), TTR (" Invalid shader type selected." ));
445+ String stripped_file_path = p_path.strip_edges ();
436446
437- if (p .is_empty ()) {
447+ if (stripped_file_path .is_empty ()) {
438448 return TTR (" Path is empty." );
439449 }
440- if (p .get_file ().get_basename ().is_empty ()) {
450+ if (stripped_file_path .get_file ().get_basename ().is_empty ()) {
441451 return TTR (" Filename is empty." );
442452 }
443453
444- p = ProjectSettings::get_singleton ()->localize_path (p );
445- if (!p .begins_with (" res://" )) {
454+ stripped_file_path = ProjectSettings::get_singleton ()->localize_path (stripped_file_path );
455+ if (!stripped_file_path .begins_with (" res://" )) {
446456 return TTR (" Path is not local." );
447457 }
448458
449459 Ref<DirAccess> d = DirAccess::create (DirAccess::ACCESS_RESOURCES);
450- if (d->change_dir (p .get_base_dir ()) != OK) {
460+ if (d->change_dir (stripped_file_path .get_base_dir ()) != OK) {
451461 return TTR (" Invalid base path." );
452462 }
453463
454464 Ref<DirAccess> f = DirAccess::create (DirAccess::ACCESS_RESOURCES);
455- if (f->dir_exists (p )) {
465+ if (f->dir_exists (stripped_file_path )) {
456466 return TTR (" A directory with the same name exists." );
457467 }
458468
459- String extension = p.get_extension ();
469+ const ShaderCreateDialog::ShaderTypeData ¤t_type_data = type_data.get (current_type);
470+ const String file_extension = stripped_file_path.get_extension ();
460471 HashSet<String> extensions;
461472
462473 List<ShaderCreateDialog::ShaderTypeData>::ConstIterator itr = type_data.begin ();
@@ -472,10 +483,10 @@ String ShaderCreateDialog::_validate_path(const String &p_path) {
472483 bool match = false ;
473484
474485 for (const String &ext : extensions) {
475- if (ext.nocasecmp_to (extension ) == 0 ) {
486+ if (ext.nocasecmp_to (file_extension ) == 0 ) {
476487 found = true ;
477- for (const String &type_ext : type_data. get (current_type) .extensions ) {
478- if (type_ext.nocasecmp_to (extension ) == 0 ) {
488+ for (const String &type_ext : current_type_data .extensions ) {
489+ if (type_ext.nocasecmp_to (file_extension ) == 0 ) {
479490 match = true ;
480491 break ;
481492 }
0 commit comments