shader_create_dialog.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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_scale.h"
  33. #include "editor/gui/editor_file_dialog.h"
  34. #include "editor/gui/editor_validation_panel.h"
  35. #include "scene/resources/shader_include.h"
  36. #include "scene/resources/visual_shader.h"
  37. #include "servers/rendering/shader_types.h"
  38. enum ShaderType {
  39. SHADER_TYPE_TEXT,
  40. SHADER_TYPE_VISUAL,
  41. SHADER_TYPE_INC,
  42. SHADER_TYPE_MAX,
  43. };
  44. void ShaderCreateDialog::_notification(int p_what) {
  45. switch (p_what) {
  46. case NOTIFICATION_ENTER_TREE: {
  47. _update_theme();
  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. _update_theme();
  65. } break;
  66. }
  67. }
  68. void ShaderCreateDialog::_update_theme() {
  69. Ref<Texture2D> shader_icon = gc->get_editor_theme_icon(SNAME("Shader"));
  70. if (shader_icon.is_valid()) {
  71. type_menu->set_item_icon(0, shader_icon);
  72. }
  73. Ref<Texture2D> visual_shader_icon = gc->get_editor_theme_icon(SNAME("VisualShader"));
  74. if (visual_shader_icon.is_valid()) {
  75. type_menu->set_item_icon(1, visual_shader_icon);
  76. }
  77. Ref<Texture2D> include_icon = gc->get_editor_theme_icon(SNAME("TextFile"));
  78. if (include_icon.is_valid()) {
  79. type_menu->set_item_icon(2, include_icon);
  80. }
  81. path_button->set_icon(get_editor_theme_icon(SNAME("Folder")));
  82. }
  83. void ShaderCreateDialog::_update_language_info() {
  84. type_data.clear();
  85. for (int i = 0; i < SHADER_TYPE_MAX; i++) {
  86. ShaderTypeData shader_type_data;
  87. if (i == int(SHADER_TYPE_TEXT)) {
  88. shader_type_data.use_templates = true;
  89. shader_type_data.extensions.push_back("gdshader");
  90. shader_type_data.default_extension = "gdshader";
  91. } else if (i == int(SHADER_TYPE_INC)) {
  92. shader_type_data.extensions.push_back("gdshaderinc");
  93. shader_type_data.default_extension = "gdshaderinc";
  94. } else {
  95. shader_type_data.default_extension = "tres";
  96. }
  97. shader_type_data.extensions.push_back("res");
  98. shader_type_data.extensions.push_back("tres");
  99. type_data.push_back(shader_type_data);
  100. }
  101. }
  102. void ShaderCreateDialog::_path_hbox_sorted() {
  103. if (is_visible()) {
  104. int filename_start_pos = initial_base_path.rfind("/") + 1;
  105. int filename_end_pos = initial_base_path.length();
  106. if (!is_built_in) {
  107. file_path->select(filename_start_pos, filename_end_pos);
  108. }
  109. file_path->set_caret_column(file_path->get_text().length());
  110. file_path->set_caret_column(filename_start_pos);
  111. file_path->grab_focus();
  112. }
  113. }
  114. void ShaderCreateDialog::_mode_changed(int p_mode) {
  115. current_mode = p_mode;
  116. EditorSettings::get_singleton()->set_project_metadata("shader_setup", "last_selected_mode", p_mode);
  117. }
  118. void ShaderCreateDialog::_template_changed(int p_template) {
  119. current_template = p_template;
  120. EditorSettings::get_singleton()->set_project_metadata("shader_setup", "last_selected_template", p_template);
  121. }
  122. void ShaderCreateDialog::ok_pressed() {
  123. if (is_new_shader_created) {
  124. _create_new();
  125. } else {
  126. _load_exist();
  127. }
  128. is_new_shader_created = true;
  129. validation_panel->update();
  130. }
  131. void ShaderCreateDialog::_create_new() {
  132. Ref<Resource> shader;
  133. Ref<Resource> shader_inc;
  134. switch (type_menu->get_selected()) {
  135. case SHADER_TYPE_TEXT: {
  136. Ref<Shader> text_shader;
  137. text_shader.instantiate();
  138. shader = text_shader;
  139. StringBuilder code;
  140. code += vformat("shader_type %s;\n", mode_menu->get_text().to_snake_case());
  141. if (current_template == 0) { // Default template.
  142. switch (current_mode) {
  143. case Shader::MODE_SPATIAL:
  144. code += R"(
  145. void vertex() {
  146. // Called for every vertex the material is visible on.
  147. }
  148. void fragment() {
  149. // Called for every pixel the material is visible on.
  150. }
  151. void light() {
  152. // Called for every pixel for every light affecting the material.
  153. }
  154. )";
  155. break;
  156. case Shader::MODE_CANVAS_ITEM:
  157. code += R"(
  158. void vertex() {
  159. // Called for every vertex the material is visible on.
  160. }
  161. void fragment() {
  162. // Called for every pixel the material is visible on.
  163. }
  164. void light() {
  165. // Called for every pixel for every light affecting the CanvasItem.
  166. }
  167. )";
  168. break;
  169. case Shader::MODE_PARTICLES:
  170. code += R"(
  171. void start() {
  172. // Called when a particle is spawned.
  173. }
  174. void process() {
  175. // Called every frame on existing particles (according to the Fixed FPS property).
  176. }
  177. )";
  178. break;
  179. case Shader::MODE_SKY:
  180. code += R"(
  181. void sky() {
  182. // Called for every visible pixel in the sky background, as well as all pixels
  183. // in the radiance cubemap.
  184. }
  185. )";
  186. break;
  187. case Shader::MODE_FOG:
  188. code += R"(
  189. void fog() {
  190. // Called once for every froxel that is touched by an axis-aligned bounding box
  191. // of the associated FogVolume. This means that froxels that just barely touch
  192. // a given FogVolume will still be used.
  193. }
  194. )";
  195. }
  196. }
  197. text_shader->set_code(code.as_string());
  198. } break;
  199. case SHADER_TYPE_VISUAL: {
  200. Ref<VisualShader> visual_shader;
  201. visual_shader.instantiate();
  202. shader = visual_shader;
  203. visual_shader->set_mode(Shader::Mode(current_mode));
  204. } break;
  205. case SHADER_TYPE_INC: {
  206. Ref<ShaderInclude> include;
  207. include.instantiate();
  208. shader_inc = include;
  209. } break;
  210. default: {
  211. } break;
  212. }
  213. if (shader.is_null()) {
  214. String lpath = ProjectSettings::get_singleton()->localize_path(file_path->get_text());
  215. shader_inc->set_path(lpath);
  216. Error error = ResourceSaver::save(shader_inc, lpath, ResourceSaver::FLAG_CHANGE_PATH);
  217. if (error != OK) {
  218. alert->set_text(TTR("Error - Could not create shader include in filesystem."));
  219. alert->popup_centered();
  220. return;
  221. }
  222. emit_signal(SNAME("shader_include_created"), shader_inc);
  223. } else {
  224. if (!is_built_in) {
  225. String lpath = ProjectSettings::get_singleton()->localize_path(file_path->get_text());
  226. shader->set_path(lpath);
  227. Error error = ResourceSaver::save(shader, lpath, ResourceSaver::FLAG_CHANGE_PATH);
  228. if (error != OK) {
  229. alert->set_text(TTR("Error - Could not create shader in filesystem."));
  230. alert->popup_centered();
  231. return;
  232. }
  233. }
  234. emit_signal(SNAME("shader_created"), shader);
  235. }
  236. file_path->set_text(file_path->get_text().get_base_dir());
  237. hide();
  238. }
  239. void ShaderCreateDialog::_load_exist() {
  240. String path = file_path->get_text();
  241. Ref<Resource> p_shader = ResourceLoader::load(path, "Shader");
  242. if (p_shader.is_null()) {
  243. alert->set_text(vformat(TTR("Error loading shader from %s"), path));
  244. alert->popup_centered();
  245. return;
  246. }
  247. emit_signal(SNAME("shader_created"), p_shader);
  248. hide();
  249. }
  250. void ShaderCreateDialog::_type_changed(int p_language) {
  251. current_type = p_language;
  252. ShaderTypeData shader_type_data = type_data[p_language];
  253. String selected_ext = "." + shader_type_data.default_extension;
  254. String path = file_path->get_text();
  255. String extension = "";
  256. if (!path.is_empty()) {
  257. if (path.contains(".")) {
  258. extension = path.get_extension();
  259. }
  260. if (extension.length() == 0) {
  261. path += selected_ext;
  262. } else {
  263. path = path.get_basename() + selected_ext;
  264. }
  265. } else {
  266. path = "shader" + selected_ext;
  267. }
  268. _path_changed(path);
  269. file_path->set_text(path);
  270. type_menu->set_item_disabled(int(SHADER_TYPE_INC), load_enabled);
  271. mode_menu->set_disabled(p_language == SHADER_TYPE_INC);
  272. template_menu->set_disabled(!shader_type_data.use_templates);
  273. template_menu->clear();
  274. if (shader_type_data.use_templates) {
  275. int last_template = EditorSettings::get_singleton()->get_project_metadata("shader_setup", "last_selected_template", 0);
  276. template_menu->add_item(TTR("Default"));
  277. template_menu->add_item(TTR("Empty"));
  278. template_menu->select(last_template);
  279. current_template = last_template;
  280. } else {
  281. template_menu->add_item(TTR("N/A"));
  282. }
  283. EditorSettings::get_singleton()->set_project_metadata("shader_setup", "last_selected_language", type_menu->get_item_text(type_menu->get_selected()));
  284. validation_panel->update();
  285. }
  286. void ShaderCreateDialog::_built_in_toggled(bool p_enabled) {
  287. is_built_in = p_enabled;
  288. if (p_enabled) {
  289. is_new_shader_created = true;
  290. } else {
  291. _path_changed(file_path->get_text());
  292. }
  293. validation_panel->update();
  294. }
  295. void ShaderCreateDialog::_browse_path() {
  296. file_browse->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
  297. file_browse->set_title(TTR("Open Shader / Choose Location"));
  298. file_browse->set_ok_button_text(TTR("Open"));
  299. file_browse->set_disable_overwrite_warning(true);
  300. file_browse->clear_filters();
  301. List<String> extensions = type_data[type_menu->get_selected()].extensions;
  302. for (const String &E : extensions) {
  303. file_browse->add_filter("*." + E);
  304. }
  305. file_browse->set_current_path(file_path->get_text());
  306. file_browse->popup_file_dialog();
  307. }
  308. void ShaderCreateDialog::_file_selected(const String &p_file) {
  309. String p = ProjectSettings::get_singleton()->localize_path(p_file);
  310. file_path->set_text(p);
  311. _path_changed(p);
  312. String filename = p.get_file().get_basename();
  313. int select_start = p.rfind(filename);
  314. file_path->select(select_start, select_start + filename.length());
  315. file_path->set_caret_column(select_start + filename.length());
  316. file_path->grab_focus();
  317. }
  318. void ShaderCreateDialog::_path_changed(const String &p_path) {
  319. if (is_built_in) {
  320. return;
  321. }
  322. is_path_valid = false;
  323. is_new_shader_created = true;
  324. path_error = _validate_path(p_path);
  325. if (!path_error.is_empty()) {
  326. validation_panel->update();
  327. return;
  328. }
  329. Ref<DirAccess> f = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  330. String p = ProjectSettings::get_singleton()->localize_path(p_path.strip_edges());
  331. if (f->file_exists(p)) {
  332. is_new_shader_created = false;
  333. }
  334. is_path_valid = true;
  335. validation_panel->update();
  336. }
  337. void ShaderCreateDialog::_path_submitted(const String &p_path) {
  338. if (!get_ok_button()->is_disabled()) {
  339. ok_pressed();
  340. }
  341. }
  342. 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) {
  343. if (!p_base_path.is_empty()) {
  344. initial_base_path = p_base_path.get_basename();
  345. file_path->set_text(initial_base_path + "." + type_data[type_menu->get_selected()].default_extension);
  346. current_type = type_menu->get_selected();
  347. } else {
  348. initial_base_path = "";
  349. file_path->set_text("");
  350. }
  351. file_path->deselect();
  352. built_in_enabled = p_built_in_enabled;
  353. load_enabled = p_load_enabled;
  354. if (p_preferred_type > -1) {
  355. type_menu->select(p_preferred_type);
  356. _type_changed(p_preferred_type);
  357. }
  358. if (p_preferred_mode > -1) {
  359. mode_menu->select(p_preferred_mode);
  360. _mode_changed(p_preferred_mode);
  361. }
  362. _type_changed(current_type);
  363. _path_changed(file_path->get_text());
  364. }
  365. String ShaderCreateDialog::_validate_path(const String &p_path) {
  366. String p = p_path.strip_edges();
  367. if (p.is_empty()) {
  368. return TTR("Path is empty.");
  369. }
  370. if (p.get_file().get_basename().is_empty()) {
  371. return TTR("Filename is empty.");
  372. }
  373. p = ProjectSettings::get_singleton()->localize_path(p);
  374. if (!p.begins_with("res://")) {
  375. return TTR("Path is not local.");
  376. }
  377. Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  378. if (d->change_dir(p.get_base_dir()) != OK) {
  379. return TTR("Invalid base path.");
  380. }
  381. Ref<DirAccess> f = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  382. if (f->dir_exists(p)) {
  383. return TTR("A directory with the same name exists.");
  384. }
  385. String extension = p.get_extension();
  386. HashSet<String> extensions;
  387. for (int i = 0; i < SHADER_TYPE_MAX; i++) {
  388. for (const String &ext : type_data[i].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[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("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("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("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("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("sort_children", callable_mp(this, &ShaderCreateDialog::_path_hbox_sorted));
  544. file_path = memnew(LineEdit);
  545. file_path->connect("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. path_button = memnew(Button);
  549. path_button->connect("pressed", callable_mp(this, &ShaderCreateDialog::_browse_path));
  550. hb->add_child(path_button);
  551. gc->add_child(memnew(Label(TTR("Path:"))));
  552. gc->add_child(hb);
  553. // Dialog Setup.
  554. file_browse = memnew(EditorFileDialog);
  555. file_browse->connect("file_selected", callable_mp(this, &ShaderCreateDialog::_file_selected));
  556. file_browse->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  557. add_child(file_browse);
  558. alert = memnew(AcceptDialog);
  559. alert->get_label()->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  560. alert->get_label()->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  561. alert->get_label()->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  562. alert->get_label()->set_custom_minimum_size(Size2(325, 60) * EDSCALE);
  563. add_child(alert);
  564. set_ok_button_text(TTR("Create"));
  565. set_hide_on_ok(false);
  566. set_title(TTR("Create Shader"));
  567. }