shader_create_dialog.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /**************************************************************************/
  2. /* shader_create_dialog.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "shader_create_dialog.h"
  31. #include "core/config/project_settings.h"
  32. #include "editor/editor_node.h"
  33. #include "editor/gui/editor_file_dialog.h"
  34. #include "editor/gui/editor_validation_panel.h"
  35. #include "editor/themes/editor_scale.h"
  36. #include "scene/resources/shader_include.h"
  37. #include "scene/resources/visual_shader.h"
  38. #include "servers/rendering/shader_types.h"
  39. enum ShaderType {
  40. SHADER_TYPE_TEXT,
  41. SHADER_TYPE_VISUAL,
  42. SHADER_TYPE_INC,
  43. SHADER_TYPE_MAX,
  44. };
  45. void ShaderCreateDialog::_notification(int p_what) {
  46. switch (p_what) {
  47. case NOTIFICATION_ENTER_TREE: {
  48. String last_lang = EditorSettings::get_singleton()->get_project_metadata("shader_setup", "last_selected_language", "");
  49. if (!last_lang.is_empty()) {
  50. for (int i = 0; i < type_menu->get_item_count(); i++) {
  51. if (type_menu->get_item_text(i) == last_lang) {
  52. type_menu->select(i);
  53. current_type = i;
  54. break;
  55. }
  56. }
  57. } else {
  58. type_menu->select(default_type);
  59. }
  60. current_mode = EditorSettings::get_singleton()->get_project_metadata("shader_setup", "last_selected_mode", 0);
  61. mode_menu->select(current_mode);
  62. } break;
  63. case NOTIFICATION_THEME_CHANGED: {
  64. static const char *shader_types[3] = { "Shader", "VisualShader", "TextFile" };
  65. for (int i = 0; i < 3; i++) {
  66. Ref<Texture2D> icon = get_editor_theme_icon(shader_types[i]);
  67. if (icon.is_valid()) {
  68. type_menu->set_item_icon(i, icon);
  69. }
  70. }
  71. path_button->set_button_icon(get_editor_theme_icon(SNAME("Folder")));
  72. } break;
  73. }
  74. }
  75. void ShaderCreateDialog::_update_language_info() {
  76. type_data.clear();
  77. for (int i = 0; i < SHADER_TYPE_MAX; i++) {
  78. ShaderTypeData shader_type_data;
  79. if (i == int(SHADER_TYPE_TEXT)) {
  80. shader_type_data.use_templates = true;
  81. shader_type_data.extensions.push_back("gdshader");
  82. shader_type_data.default_extension = "gdshader";
  83. } else if (i == int(SHADER_TYPE_INC)) {
  84. shader_type_data.extensions.push_back("gdshaderinc");
  85. shader_type_data.default_extension = "gdshaderinc";
  86. } else {
  87. shader_type_data.default_extension = "tres";
  88. }
  89. shader_type_data.extensions.push_back("res");
  90. shader_type_data.extensions.push_back("tres");
  91. type_data.push_back(shader_type_data);
  92. }
  93. }
  94. void ShaderCreateDialog::_path_hbox_sorted() {
  95. if (is_visible()) {
  96. int filename_start_pos = initial_base_path.rfind_char('/') + 1;
  97. int filename_end_pos = initial_base_path.length();
  98. if (!is_built_in) {
  99. file_path->select(filename_start_pos, filename_end_pos);
  100. }
  101. file_path->set_caret_column(file_path->get_text().length());
  102. file_path->set_caret_column(filename_start_pos);
  103. file_path->grab_focus();
  104. }
  105. }
  106. void ShaderCreateDialog::_mode_changed(int p_mode) {
  107. current_mode = p_mode;
  108. EditorSettings::get_singleton()->set_project_metadata("shader_setup", "last_selected_mode", p_mode);
  109. }
  110. void ShaderCreateDialog::_template_changed(int p_template) {
  111. current_template = p_template;
  112. EditorSettings::get_singleton()->set_project_metadata("shader_setup", "last_selected_template", p_template);
  113. }
  114. void ShaderCreateDialog::ok_pressed() {
  115. if (is_new_shader_created) {
  116. _create_new();
  117. } else {
  118. _load_exist();
  119. }
  120. is_new_shader_created = true;
  121. validation_panel->update();
  122. }
  123. void ShaderCreateDialog::_create_new() {
  124. Ref<Resource> shader;
  125. Ref<Resource> shader_inc;
  126. switch (type_menu->get_selected()) {
  127. case SHADER_TYPE_TEXT: {
  128. Ref<Shader> text_shader;
  129. text_shader.instantiate();
  130. shader = text_shader;
  131. StringBuilder code;
  132. code += vformat("shader_type %s;\n", mode_menu->get_text().to_snake_case());
  133. if (current_template == 0) { // Default template.
  134. switch (current_mode) {
  135. case Shader::MODE_SPATIAL:
  136. code += R"(
  137. void vertex() {
  138. // Called for every vertex the material is visible on.
  139. }
  140. void fragment() {
  141. // Called for every pixel the material is visible on.
  142. }
  143. //void light() {
  144. // // Called for every pixel for every light affecting the material.
  145. // // Uncomment to replace the default light processing function with this one.
  146. //}
  147. )";
  148. break;
  149. case Shader::MODE_CANVAS_ITEM:
  150. code += R"(
  151. void vertex() {
  152. // Called for every vertex the material is visible on.
  153. }
  154. void fragment() {
  155. // Called for every pixel the material is visible on.
  156. }
  157. //void light() {
  158. // // Called for every pixel for every light affecting the CanvasItem.
  159. // // Uncomment to replace the default light processing function with this one.
  160. //}
  161. )";
  162. break;
  163. case Shader::MODE_PARTICLES:
  164. code += R"(
  165. void start() {
  166. // Called when a particle is spawned.
  167. }
  168. void process() {
  169. // Called every frame on existing particles (according to the Fixed FPS property).
  170. }
  171. )";
  172. break;
  173. case Shader::MODE_SKY:
  174. code += R"(
  175. void sky() {
  176. // Called for every visible pixel in the sky background, as well as all pixels
  177. // in the radiance cubemap.
  178. }
  179. )";
  180. break;
  181. case Shader::MODE_FOG:
  182. code += R"(
  183. void fog() {
  184. // Called once for every froxel that is touched by an axis-aligned bounding box
  185. // of the associated FogVolume. This means that froxels that just barely touch
  186. // a given FogVolume will still be used.
  187. }
  188. )";
  189. }
  190. }
  191. text_shader->set_code(code.as_string());
  192. } break;
  193. case SHADER_TYPE_VISUAL: {
  194. Ref<VisualShader> visual_shader;
  195. visual_shader.instantiate();
  196. shader = visual_shader;
  197. visual_shader->set_mode(Shader::Mode(current_mode));
  198. } break;
  199. case SHADER_TYPE_INC: {
  200. Ref<ShaderInclude> include;
  201. include.instantiate();
  202. shader_inc = include;
  203. } break;
  204. default: {
  205. } break;
  206. }
  207. if (shader.is_null()) {
  208. String lpath = ProjectSettings::get_singleton()->localize_path(file_path->get_text());
  209. shader_inc->set_path(lpath);
  210. Error error = ResourceSaver::save(shader_inc, lpath, ResourceSaver::FLAG_CHANGE_PATH);
  211. if (error != OK) {
  212. alert->set_text(TTR("Error - Could not create shader include in filesystem."));
  213. alert->popup_centered();
  214. return;
  215. }
  216. emit_signal(SNAME("shader_include_created"), shader_inc);
  217. } else {
  218. if (is_built_in) {
  219. Node *edited_scene = get_tree()->get_edited_scene_root();
  220. if (likely(edited_scene)) {
  221. shader->set_path(edited_scene->get_scene_file_path() + "::");
  222. }
  223. } else {
  224. String lpath = ProjectSettings::get_singleton()->localize_path(file_path->get_text());
  225. shader->set_path(lpath);
  226. Error error = ResourceSaver::save(shader, lpath, ResourceSaver::FLAG_CHANGE_PATH);
  227. if (error != OK) {
  228. alert->set_text(TTR("Error - Could not create shader in filesystem."));
  229. alert->popup_centered();
  230. return;
  231. }
  232. }
  233. emit_signal(SNAME("shader_created"), shader);
  234. }
  235. file_path->set_text(file_path->get_text().get_base_dir());
  236. hide();
  237. }
  238. void ShaderCreateDialog::_load_exist() {
  239. String path = file_path->get_text();
  240. Ref<Resource> p_shader = ResourceLoader::load(path, "Shader");
  241. if (p_shader.is_null()) {
  242. alert->set_text(vformat(TTR("Error loading shader from %s"), path));
  243. alert->popup_centered();
  244. return;
  245. }
  246. emit_signal(SNAME("shader_created"), p_shader);
  247. hide();
  248. }
  249. void ShaderCreateDialog::_type_changed(int p_language) {
  250. current_type = p_language;
  251. ShaderTypeData shader_type_data = type_data.get(p_language);
  252. String selected_ext = "." + shader_type_data.default_extension;
  253. String path = file_path->get_text();
  254. String extension = "";
  255. if (!path.is_empty()) {
  256. if (path.contains_char('.')) {
  257. extension = path.get_extension();
  258. }
  259. if (extension.length() == 0) {
  260. path += selected_ext;
  261. } else {
  262. path = path.get_basename() + selected_ext;
  263. }
  264. } else {
  265. path = "shader" + selected_ext;
  266. }
  267. _path_changed(path);
  268. file_path->set_text(path);
  269. type_menu->set_item_disabled(int(SHADER_TYPE_INC), load_enabled);
  270. mode_menu->set_disabled(p_language == SHADER_TYPE_INC);
  271. template_menu->set_disabled(!shader_type_data.use_templates);
  272. template_menu->clear();
  273. if (shader_type_data.use_templates) {
  274. int last_template = EditorSettings::get_singleton()->get_project_metadata("shader_setup", "last_selected_template", 0);
  275. template_menu->add_item(TTR("Default"));
  276. template_menu->add_item(TTR("Empty"));
  277. template_menu->select(last_template);
  278. current_template = last_template;
  279. } else {
  280. template_menu->add_item(TTR("N/A"));
  281. }
  282. EditorSettings::get_singleton()->set_project_metadata("shader_setup", "last_selected_language", type_menu->get_item_text(type_menu->get_selected()));
  283. validation_panel->update();
  284. }
  285. void ShaderCreateDialog::_built_in_toggled(bool p_enabled) {
  286. is_built_in = p_enabled;
  287. if (p_enabled) {
  288. is_new_shader_created = true;
  289. } else {
  290. _path_changed(file_path->get_text());
  291. }
  292. validation_panel->update();
  293. }
  294. void ShaderCreateDialog::_browse_path() {
  295. file_browse->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
  296. file_browse->set_title(TTR("Open Shader / Choose Location"));
  297. file_browse->set_ok_button_text(TTR("Open"));
  298. file_browse->set_disable_overwrite_warning(true);
  299. file_browse->clear_filters();
  300. List<String> extensions = type_data.get(type_menu->get_selected()).extensions;
  301. for (const String &E : extensions) {
  302. file_browse->add_filter("*." + E);
  303. }
  304. file_browse->set_current_path(file_path->get_text());
  305. file_browse->popup_file_dialog();
  306. }
  307. void ShaderCreateDialog::_file_selected(const String &p_file) {
  308. String p = ProjectSettings::get_singleton()->localize_path(p_file);
  309. file_path->set_text(p);
  310. _path_changed(p);
  311. String filename = p.get_file().get_basename();
  312. int select_start = p.rfind(filename);
  313. file_path->select(select_start, select_start + filename.length());
  314. file_path->set_caret_column(select_start + filename.length());
  315. file_path->grab_focus();
  316. }
  317. void ShaderCreateDialog::_path_changed(const String &p_path) {
  318. if (is_built_in) {
  319. return;
  320. }
  321. is_path_valid = false;
  322. is_new_shader_created = true;
  323. path_error = _validate_path(p_path);
  324. if (!path_error.is_empty()) {
  325. validation_panel->update();
  326. return;
  327. }
  328. Ref<DirAccess> f = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  329. String p = ProjectSettings::get_singleton()->localize_path(p_path.strip_edges());
  330. if (f->file_exists(p)) {
  331. is_new_shader_created = false;
  332. }
  333. is_path_valid = true;
  334. validation_panel->update();
  335. }
  336. void ShaderCreateDialog::_path_submitted(const String &p_path) {
  337. if (!get_ok_button()->is_disabled()) {
  338. ok_pressed();
  339. }
  340. }
  341. void ShaderCreateDialog::config(const String &p_base_path, bool p_built_in_enabled, bool p_load_enabled, int p_preferred_type, int p_preferred_mode) {
  342. if (!p_base_path.is_empty()) {
  343. initial_base_path = p_base_path.get_basename();
  344. file_path->set_text(initial_base_path + "." + type_data.get(type_menu->get_selected()).default_extension);
  345. current_type = type_menu->get_selected();
  346. } else {
  347. initial_base_path = "";
  348. file_path->set_text("");
  349. }
  350. file_path->deselect();
  351. built_in_enabled = p_built_in_enabled;
  352. load_enabled = p_load_enabled;
  353. if (p_preferred_type > -1) {
  354. type_menu->select(p_preferred_type);
  355. _type_changed(p_preferred_type);
  356. }
  357. if (p_preferred_mode > -1) {
  358. mode_menu->select(p_preferred_mode);
  359. _mode_changed(p_preferred_mode);
  360. }
  361. _type_changed(current_type);
  362. _path_changed(file_path->get_text());
  363. }
  364. String ShaderCreateDialog::_validate_path(const String &p_path) {
  365. String p = p_path.strip_edges();
  366. if (p.is_empty()) {
  367. return TTR("Path is empty.");
  368. }
  369. if (p.get_file().get_basename().is_empty()) {
  370. return TTR("Filename is empty.");
  371. }
  372. p = ProjectSettings::get_singleton()->localize_path(p);
  373. if (!p.begins_with("res://")) {
  374. return TTR("Path is not local.");
  375. }
  376. Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  377. if (d->change_dir(p.get_base_dir()) != OK) {
  378. return TTR("Invalid base path.");
  379. }
  380. Ref<DirAccess> f = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  381. if (f->dir_exists(p)) {
  382. return TTR("A directory with the same name exists.");
  383. }
  384. String extension = p.get_extension();
  385. HashSet<String> extensions;
  386. List<ShaderCreateDialog::ShaderTypeData>::ConstIterator itr = type_data.begin();
  387. for (int i = 0; i < SHADER_TYPE_MAX; ++itr, ++i) {
  388. for (const String &ext : itr->extensions) {
  389. if (!extensions.has(ext)) {
  390. extensions.insert(ext);
  391. }
  392. }
  393. }
  394. bool found = false;
  395. bool match = false;
  396. for (const String &ext : extensions) {
  397. if (ext.nocasecmp_to(extension) == 0) {
  398. found = true;
  399. for (const String &type_ext : type_data.get(current_type).extensions) {
  400. if (type_ext.nocasecmp_to(extension) == 0) {
  401. match = true;
  402. break;
  403. }
  404. }
  405. break;
  406. }
  407. }
  408. if (!found) {
  409. return TTR("Invalid extension.");
  410. }
  411. if (!match) {
  412. return TTR("Wrong extension chosen.");
  413. }
  414. return "";
  415. }
  416. void ShaderCreateDialog::_update_dialog() {
  417. if (!is_built_in && !is_path_valid) {
  418. validation_panel->set_message(MSG_ID_SHADER, TTR("Invalid path."), EditorValidationPanel::MSG_ERROR);
  419. }
  420. if (!is_built_in && !path_error.is_empty()) {
  421. validation_panel->set_message(MSG_ID_PATH, path_error, EditorValidationPanel::MSG_ERROR);
  422. } else if (validation_panel->is_valid() && !is_new_shader_created) {
  423. validation_panel->set_message(MSG_ID_SHADER, TTR("File exists, it will be reused."), EditorValidationPanel::MSG_OK);
  424. }
  425. if (!built_in_enabled) {
  426. internal->set_pressed(false);
  427. }
  428. if (is_built_in) {
  429. file_path->set_editable(false);
  430. path_button->set_disabled(true);
  431. re_check_path = true;
  432. } else {
  433. file_path->set_editable(true);
  434. path_button->set_disabled(false);
  435. if (re_check_path) {
  436. re_check_path = false;
  437. _path_changed(file_path->get_text());
  438. }
  439. }
  440. internal->set_disabled(!built_in_enabled);
  441. if (is_built_in) {
  442. validation_panel->set_message(MSG_ID_BUILT_IN, TTR("Note: Built-in shaders can't be edited using an external editor."), EditorValidationPanel::MSG_INFO, false);
  443. }
  444. if (is_built_in) {
  445. set_ok_button_text(TTR("Create"));
  446. validation_panel->set_message(MSG_ID_PATH, TTR("Built-in shader (into scene file)."), EditorValidationPanel::MSG_OK);
  447. } else if (is_new_shader_created) {
  448. set_ok_button_text(TTR("Create"));
  449. } else if (load_enabled) {
  450. set_ok_button_text(TTR("Load"));
  451. if (is_path_valid) {
  452. validation_panel->set_message(MSG_ID_PATH, TTR("Will load an existing shader file."), EditorValidationPanel::MSG_OK);
  453. }
  454. } else {
  455. set_ok_button_text(TTR("Create"));
  456. validation_panel->set_message(MSG_ID_PATH, TTR("Shader file already exists."), EditorValidationPanel::MSG_ERROR);
  457. }
  458. }
  459. void ShaderCreateDialog::_bind_methods() {
  460. ClassDB::bind_method(D_METHOD("config", "path", "built_in_enabled", "load_enabled"), &ShaderCreateDialog::config, DEFVAL(true), DEFVAL(true));
  461. ADD_SIGNAL(MethodInfo("shader_created", PropertyInfo(Variant::OBJECT, "shader", PROPERTY_HINT_RESOURCE_TYPE, "Shader")));
  462. ADD_SIGNAL(MethodInfo("shader_include_created", PropertyInfo(Variant::OBJECT, "shader_include", PROPERTY_HINT_RESOURCE_TYPE, "ShaderInclude")));
  463. }
  464. ShaderCreateDialog::ShaderCreateDialog() {
  465. _update_language_info();
  466. // Main Controls.
  467. gc = memnew(GridContainer);
  468. gc->set_columns(2);
  469. // Error Fields.
  470. validation_panel = memnew(EditorValidationPanel);
  471. validation_panel->add_line(MSG_ID_SHADER, TTR("Shader path/name is valid."));
  472. validation_panel->add_line(MSG_ID_PATH, TTR("Will create a new shader file."));
  473. validation_panel->add_line(MSG_ID_BUILT_IN);
  474. validation_panel->set_update_callback(callable_mp(this, &ShaderCreateDialog::_update_dialog));
  475. validation_panel->set_accept_button(get_ok_button());
  476. // Spacing.
  477. Control *spacing = memnew(Control);
  478. spacing->set_custom_minimum_size(Size2(0, 10 * EDSCALE));
  479. VBoxContainer *vb = memnew(VBoxContainer);
  480. vb->add_child(gc);
  481. vb->add_child(spacing);
  482. vb->add_child(validation_panel);
  483. add_child(vb);
  484. // Type.
  485. type_menu = memnew(OptionButton);
  486. type_menu->set_custom_minimum_size(Size2(250, 0) * EDSCALE);
  487. type_menu->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  488. gc->add_child(memnew(Label(TTR("Type:"))));
  489. gc->add_child(type_menu);
  490. for (int i = 0; i < SHADER_TYPE_MAX; i++) {
  491. String type;
  492. bool invalid = false;
  493. switch (i) {
  494. case SHADER_TYPE_TEXT:
  495. type = "Shader";
  496. default_type = i;
  497. break;
  498. case SHADER_TYPE_VISUAL:
  499. type = "VisualShader";
  500. break;
  501. case SHADER_TYPE_INC:
  502. type = "ShaderInclude";
  503. break;
  504. case SHADER_TYPE_MAX:
  505. invalid = true;
  506. break;
  507. default:
  508. invalid = true;
  509. break;
  510. }
  511. if (invalid) {
  512. continue;
  513. }
  514. type_menu->add_item(type);
  515. }
  516. if (default_type >= 0) {
  517. type_menu->select(default_type);
  518. }
  519. current_type = default_type;
  520. type_menu->connect(SceneStringName(item_selected), callable_mp(this, &ShaderCreateDialog::_type_changed));
  521. // Modes.
  522. mode_menu = memnew(OptionButton);
  523. for (const String &type_name : ShaderTypes::get_singleton()->get_types_list()) {
  524. mode_menu->add_item(type_name.capitalize());
  525. }
  526. gc->add_child(memnew(Label(TTR("Mode:"))));
  527. gc->add_child(mode_menu);
  528. mode_menu->connect(SceneStringName(item_selected), callable_mp(this, &ShaderCreateDialog::_mode_changed));
  529. // Templates.
  530. template_menu = memnew(OptionButton);
  531. gc->add_child(memnew(Label(TTR("Template:"))));
  532. gc->add_child(template_menu);
  533. template_menu->connect(SceneStringName(item_selected), callable_mp(this, &ShaderCreateDialog::_template_changed));
  534. // Built-in Shader.
  535. internal = memnew(CheckBox);
  536. internal->set_text(TTR("On"));
  537. internal->connect(SceneStringName(toggled), callable_mp(this, &ShaderCreateDialog::_built_in_toggled));
  538. gc->add_child(memnew(Label(TTR("Built-in Shader:"))));
  539. gc->add_child(internal);
  540. // Path.
  541. HBoxContainer *hb = memnew(HBoxContainer);
  542. hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  543. hb->connect(SceneStringName(sort_children), callable_mp(this, &ShaderCreateDialog::_path_hbox_sorted));
  544. file_path = memnew(LineEdit);
  545. file_path->connect(SceneStringName(text_changed), callable_mp(this, &ShaderCreateDialog::_path_changed));
  546. file_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  547. hb->add_child(file_path);
  548. register_text_enter(file_path);
  549. path_button = memnew(Button);
  550. path_button->connect(SceneStringName(pressed), callable_mp(this, &ShaderCreateDialog::_browse_path));
  551. hb->add_child(path_button);
  552. gc->add_child(memnew(Label(TTR("Path:"))));
  553. gc->add_child(hb);
  554. // Dialog Setup.
  555. file_browse = memnew(EditorFileDialog);
  556. file_browse->connect("file_selected", callable_mp(this, &ShaderCreateDialog::_file_selected));
  557. file_browse->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  558. add_child(file_browse);
  559. alert = memnew(AcceptDialog);
  560. alert->get_label()->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  561. alert->get_label()->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  562. alert->get_label()->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  563. alert->get_label()->set_custom_minimum_size(Size2(325, 60) * EDSCALE);
  564. add_child(alert);
  565. set_ok_button_text(TTR("Create"));
  566. set_hide_on_ok(false);
  567. set_title(TTR("Create Shader"));
  568. }