shader_create_dialog.cpp 20 KB

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