Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/shader/shader_create_dialog.cpp
9902 views
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
31
#include "shader_create_dialog.h"
32
33
#include "core/config/project_settings.h"
34
#include "editor/editor_node.h"
35
#include "editor/gui/editor_file_dialog.h"
36
#include "editor/gui/editor_validation_panel.h"
37
#include "editor/themes/editor_scale.h"
38
#include "scene/resources/shader_include.h"
39
#include "scene/resources/visual_shader.h"
40
#include "servers/rendering/shader_types.h"
41
42
enum ShaderType {
43
SHADER_TYPE_TEXT,
44
SHADER_TYPE_VISUAL,
45
SHADER_TYPE_INC,
46
SHADER_TYPE_MAX,
47
};
48
49
void ShaderCreateDialog::_notification(int p_what) {
50
switch (p_what) {
51
case NOTIFICATION_ENTER_TREE: {
52
String last_lang = EditorSettings::get_singleton()->get_project_metadata("shader_setup", "last_selected_language", "");
53
if (!last_lang.is_empty()) {
54
for (int i = 0; i < type_menu->get_item_count(); i++) {
55
if (type_menu->get_item_text(i) == last_lang) {
56
type_menu->select(i);
57
current_type = i;
58
break;
59
}
60
}
61
} else {
62
type_menu->select(default_type);
63
}
64
65
current_mode = EditorSettings::get_singleton()->get_project_metadata("shader_setup", "last_selected_mode", 0);
66
mode_menu->select(current_mode);
67
} break;
68
69
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
78
path_button->set_button_icon(get_editor_theme_icon(SNAME("Folder")));
79
} break;
80
}
81
}
82
83
void ShaderCreateDialog::_update_language_info() {
84
type_data.clear();
85
86
for (int i = 0; i < SHADER_TYPE_MAX; i++) {
87
ShaderTypeData shader_type_data;
88
if (i == int(SHADER_TYPE_TEXT)) {
89
shader_type_data.use_templates = true;
90
shader_type_data.extensions.push_back("gdshader");
91
shader_type_data.default_extension = "gdshader";
92
} else if (i == int(SHADER_TYPE_INC)) {
93
shader_type_data.extensions.push_back("gdshaderinc");
94
shader_type_data.default_extension = "gdshaderinc";
95
} else {
96
shader_type_data.default_extension = "tres";
97
}
98
shader_type_data.extensions.push_back("res");
99
shader_type_data.extensions.push_back("tres");
100
type_data.push_back(shader_type_data);
101
}
102
}
103
104
void ShaderCreateDialog::_path_hbox_sorted() {
105
if (is_visible()) {
106
int filename_start_pos = initial_base_path.rfind_char('/') + 1;
107
int filename_end_pos = initial_base_path.length();
108
109
if (!is_built_in) {
110
file_path->select(filename_start_pos, filename_end_pos);
111
}
112
113
file_path->set_caret_column(file_path->get_text().length());
114
file_path->set_caret_column(filename_start_pos);
115
116
file_path->grab_focus();
117
}
118
}
119
120
void ShaderCreateDialog::_mode_changed(int p_mode) {
121
current_mode = p_mode;
122
EditorSettings::get_singleton()->set_project_metadata("shader_setup", "last_selected_mode", p_mode);
123
}
124
125
void ShaderCreateDialog::_template_changed(int p_template) {
126
current_template = p_template;
127
EditorSettings::get_singleton()->set_project_metadata("shader_setup", "last_selected_template", p_template);
128
}
129
130
void ShaderCreateDialog::ok_pressed() {
131
if (is_new_shader_created) {
132
_create_new();
133
if (built_in_enabled) {
134
// Only save state of built-in checkbox if it's enabled.
135
EditorSettings::get_singleton()->set_project_metadata("shader_setup", "create_built_in_shader", internal->is_pressed());
136
}
137
} else {
138
_load_exist();
139
}
140
141
is_new_shader_created = true;
142
validation_panel->update();
143
}
144
145
void ShaderCreateDialog::_create_new() {
146
Ref<Resource> shader;
147
Ref<Resource> shader_inc;
148
149
switch (type_menu->get_selected()) {
150
case SHADER_TYPE_TEXT: {
151
Ref<Shader> text_shader;
152
text_shader.instantiate();
153
shader = text_shader;
154
155
StringBuilder code;
156
code += vformat("shader_type %s;\n", mode_menu->get_text().to_snake_case());
157
158
if (current_template == 0) { // Default template.
159
switch (current_mode) {
160
case Shader::MODE_SPATIAL:
161
code += R"(
162
void vertex() {
163
// Called for every vertex the material is visible on.
164
}
165
166
void fragment() {
167
// Called for every pixel the material is visible on.
168
}
169
170
//void light() {
171
// // Called for every pixel for every light affecting the material.
172
// // Uncomment to replace the default light processing function with this one.
173
//}
174
)";
175
break;
176
case Shader::MODE_CANVAS_ITEM:
177
code += R"(
178
void vertex() {
179
// Called for every vertex the material is visible on.
180
}
181
182
void fragment() {
183
// Called for every pixel the material is visible on.
184
}
185
186
//void light() {
187
// // Called for every pixel for every light affecting the CanvasItem.
188
// // Uncomment to replace the default light processing function with this one.
189
//}
190
)";
191
break;
192
case Shader::MODE_PARTICLES:
193
code += R"(
194
void start() {
195
// Called when a particle is spawned.
196
}
197
198
void process() {
199
// Called every frame on existing particles (according to the Fixed FPS property).
200
}
201
)";
202
break;
203
case Shader::MODE_SKY:
204
code += R"(
205
void sky() {
206
// Called for every visible pixel in the sky background, as well as all pixels
207
// in the radiance cubemap.
208
}
209
)";
210
break;
211
case Shader::MODE_FOG:
212
code += R"(
213
void fog() {
214
// Called once for every froxel that is touched by an axis-aligned bounding box
215
// of the associated FogVolume. This means that froxels that just barely touch
216
// a given FogVolume will still be used.
217
}
218
)";
219
}
220
}
221
text_shader->set_code(code.as_string());
222
} break;
223
case SHADER_TYPE_VISUAL: {
224
Ref<VisualShader> visual_shader;
225
visual_shader.instantiate();
226
shader = visual_shader;
227
visual_shader->set_mode(Shader::Mode(current_mode));
228
} break;
229
case SHADER_TYPE_INC: {
230
Ref<ShaderInclude> include;
231
include.instantiate();
232
shader_inc = include;
233
} break;
234
default: {
235
} break;
236
}
237
238
if (shader.is_null()) {
239
String lpath = ProjectSettings::get_singleton()->localize_path(file_path->get_text());
240
shader_inc->set_path(lpath);
241
242
Error error = ResourceSaver::save(shader_inc, lpath, ResourceSaver::FLAG_CHANGE_PATH);
243
if (error != OK) {
244
alert->set_text(TTR("Error - Could not create shader include in filesystem."));
245
alert->popup_centered();
246
return;
247
}
248
249
emit_signal(SNAME("shader_include_created"), shader_inc);
250
} else {
251
if (is_built_in) {
252
Node *edited_scene = get_tree()->get_edited_scene_root();
253
if (likely(edited_scene)) {
254
shader->set_path(edited_scene->get_scene_file_path() + "::" + shader->generate_scene_unique_id());
255
}
256
} else {
257
String lpath = ProjectSettings::get_singleton()->localize_path(file_path->get_text());
258
shader->set_path(lpath);
259
260
Error error = ResourceSaver::save(shader, lpath, ResourceSaver::FLAG_CHANGE_PATH);
261
if (error != OK) {
262
alert->set_text(TTR("Error - Could not create shader in filesystem."));
263
alert->popup_centered();
264
return;
265
}
266
}
267
268
emit_signal(SNAME("shader_created"), shader);
269
}
270
271
file_path->set_text(file_path->get_text().get_base_dir());
272
hide();
273
}
274
275
void ShaderCreateDialog::_load_exist() {
276
String path = file_path->get_text();
277
Ref<Resource> p_shader = ResourceLoader::load(path, "Shader");
278
if (p_shader.is_null()) {
279
alert->set_text(vformat(TTR("Error loading shader from %s"), path));
280
alert->popup_centered();
281
return;
282
}
283
284
emit_signal(SNAME("shader_created"), p_shader);
285
hide();
286
}
287
288
void ShaderCreateDialog::_type_changed(int p_language) {
289
current_type = p_language;
290
ShaderTypeData shader_type_data = type_data.get(p_language);
291
292
String selected_ext = "." + shader_type_data.default_extension;
293
String path = file_path->get_text();
294
String extension = "";
295
296
if (!path.is_empty()) {
297
if (path.contains_char('.')) {
298
extension = path.get_extension();
299
}
300
if (extension.length() == 0) {
301
path += selected_ext;
302
} else {
303
path = path.get_basename() + selected_ext;
304
}
305
} else {
306
path = "shader" + selected_ext;
307
}
308
_path_changed(path);
309
file_path->set_text(path);
310
311
type_menu->set_item_disabled(int(SHADER_TYPE_INC), load_enabled);
312
mode_menu->set_disabled(p_language == SHADER_TYPE_INC);
313
template_menu->set_disabled(!shader_type_data.use_templates);
314
template_menu->clear();
315
316
if (shader_type_data.use_templates) {
317
int last_template = EditorSettings::get_singleton()->get_project_metadata("shader_setup", "last_selected_template", 0);
318
319
template_menu->add_item(TTRC("Default"));
320
template_menu->add_item(TTRC("Empty"));
321
322
template_menu->select(last_template);
323
current_template = last_template;
324
} else {
325
template_menu->add_item(TTRC("N/A"));
326
}
327
328
EditorSettings::get_singleton()->set_project_metadata("shader_setup", "last_selected_language", type_menu->get_item_text(type_menu->get_selected()));
329
validation_panel->update();
330
}
331
332
void ShaderCreateDialog::_built_in_toggled(bool p_enabled) {
333
is_built_in = p_enabled;
334
if (p_enabled) {
335
is_new_shader_created = true;
336
} else {
337
_path_changed(file_path->get_text());
338
}
339
validation_panel->update();
340
}
341
342
void ShaderCreateDialog::_browse_path() {
343
file_browse->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
344
file_browse->set_title(TTR("Open Shader / Choose Location"));
345
file_browse->set_ok_button_text(TTR("Open"));
346
347
file_browse->set_disable_overwrite_warning(true);
348
file_browse->clear_filters();
349
350
List<String> extensions = type_data.get(type_menu->get_selected()).extensions;
351
352
for (const String &E : extensions) {
353
file_browse->add_filter("*." + E);
354
}
355
356
file_browse->set_current_path(file_path->get_text());
357
file_browse->popup_file_dialog();
358
}
359
360
void ShaderCreateDialog::_file_selected(const String &p_file) {
361
String p = ProjectSettings::get_singleton()->localize_path(p_file);
362
file_path->set_text(p);
363
_path_changed(p);
364
365
String filename = p.get_file().get_basename();
366
int select_start = p.rfind(filename);
367
file_path->select(select_start, select_start + filename.length());
368
file_path->set_caret_column(select_start + filename.length());
369
file_path->grab_focus();
370
}
371
372
void ShaderCreateDialog::_path_changed(const String &p_path) {
373
if (is_built_in) {
374
return;
375
}
376
377
is_path_valid = false;
378
is_new_shader_created = true;
379
380
path_error = _validate_path(p_path);
381
if (!path_error.is_empty()) {
382
validation_panel->update();
383
return;
384
}
385
386
Ref<DirAccess> f = DirAccess::create(DirAccess::ACCESS_RESOURCES);
387
String p = ProjectSettings::get_singleton()->localize_path(p_path.strip_edges());
388
if (f->file_exists(p)) {
389
is_new_shader_created = false;
390
}
391
392
is_path_valid = true;
393
validation_panel->update();
394
}
395
396
void ShaderCreateDialog::_path_submitted(const String &p_path) {
397
if (!get_ok_button()->is_disabled()) {
398
ok_pressed();
399
}
400
}
401
402
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) {
403
if (!p_base_path.is_empty()) {
404
initial_base_path = p_base_path.get_basename();
405
file_path->set_text(initial_base_path + "." + type_data.get(type_menu->get_selected()).default_extension);
406
current_type = type_menu->get_selected();
407
} else {
408
initial_base_path = "";
409
file_path->set_text("");
410
}
411
file_path->deselect();
412
413
built_in_enabled = p_built_in_enabled;
414
load_enabled = p_load_enabled;
415
416
if (built_in_enabled) {
417
internal->set_pressed(EditorSettings::get_singleton()->get_project_metadata("shader_setup", "create_built_in_shader", false));
418
}
419
420
if (p_preferred_type > -1) {
421
type_menu->select(p_preferred_type);
422
_type_changed(p_preferred_type);
423
}
424
425
if (p_preferred_mode > -1) {
426
mode_menu->select(p_preferred_mode);
427
_mode_changed(p_preferred_mode);
428
}
429
430
_type_changed(current_type);
431
_path_changed(file_path->get_text());
432
}
433
434
String ShaderCreateDialog::_validate_path(const String &p_path) {
435
String p = p_path.strip_edges();
436
437
if (p.is_empty()) {
438
return TTR("Path is empty.");
439
}
440
if (p.get_file().get_basename().is_empty()) {
441
return TTR("Filename is empty.");
442
}
443
444
p = ProjectSettings::get_singleton()->localize_path(p);
445
if (!p.begins_with("res://")) {
446
return TTR("Path is not local.");
447
}
448
449
Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
450
if (d->change_dir(p.get_base_dir()) != OK) {
451
return TTR("Invalid base path.");
452
}
453
454
Ref<DirAccess> f = DirAccess::create(DirAccess::ACCESS_RESOURCES);
455
if (f->dir_exists(p)) {
456
return TTR("A directory with the same name exists.");
457
}
458
459
String extension = p.get_extension();
460
HashSet<String> extensions;
461
462
List<ShaderCreateDialog::ShaderTypeData>::ConstIterator itr = type_data.begin();
463
for (int i = 0; i < SHADER_TYPE_MAX; ++itr, ++i) {
464
for (const String &ext : itr->extensions) {
465
if (!extensions.has(ext)) {
466
extensions.insert(ext);
467
}
468
}
469
}
470
471
bool found = false;
472
bool match = false;
473
474
for (const String &ext : extensions) {
475
if (ext.nocasecmp_to(extension) == 0) {
476
found = true;
477
for (const String &type_ext : type_data.get(current_type).extensions) {
478
if (type_ext.nocasecmp_to(extension) == 0) {
479
match = true;
480
break;
481
}
482
}
483
break;
484
}
485
}
486
487
if (!found) {
488
return TTR("Invalid extension.");
489
}
490
if (!match) {
491
return TTR("Wrong extension chosen.");
492
}
493
494
return "";
495
}
496
497
void ShaderCreateDialog::_update_dialog() {
498
if (!is_built_in && !is_path_valid) {
499
validation_panel->set_message(MSG_ID_SHADER, TTR("Invalid path."), EditorValidationPanel::MSG_ERROR);
500
}
501
if (!is_built_in && !path_error.is_empty()) {
502
validation_panel->set_message(MSG_ID_PATH, path_error, EditorValidationPanel::MSG_ERROR);
503
} else if (validation_panel->is_valid() && !is_new_shader_created) {
504
validation_panel->set_message(MSG_ID_SHADER, TTR("File exists, it will be reused."), EditorValidationPanel::MSG_OK);
505
}
506
if (!built_in_enabled) {
507
internal->set_pressed(false);
508
}
509
510
if (is_built_in) {
511
file_path->set_editable(false);
512
path_button->set_disabled(true);
513
re_check_path = true;
514
} else {
515
file_path->set_editable(true);
516
path_button->set_disabled(false);
517
if (re_check_path) {
518
re_check_path = false;
519
_path_changed(file_path->get_text());
520
}
521
}
522
523
internal->set_disabled(!built_in_enabled);
524
525
if (is_built_in) {
526
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);
527
}
528
529
if (is_built_in) {
530
set_ok_button_text(TTR("Create"));
531
validation_panel->set_message(MSG_ID_PATH, TTR("Built-in shader (into scene file)."), EditorValidationPanel::MSG_OK);
532
} else if (is_new_shader_created) {
533
set_ok_button_text(TTR("Create"));
534
} else if (load_enabled) {
535
set_ok_button_text(TTR("Load"));
536
if (is_path_valid) {
537
validation_panel->set_message(MSG_ID_PATH, TTR("Will load an existing shader file."), EditorValidationPanel::MSG_OK);
538
}
539
} else {
540
set_ok_button_text(TTR("Create"));
541
validation_panel->set_message(MSG_ID_PATH, TTR("Shader file already exists."), EditorValidationPanel::MSG_ERROR);
542
}
543
}
544
545
void ShaderCreateDialog::_bind_methods() {
546
ClassDB::bind_method(D_METHOD("config", "path", "built_in_enabled", "load_enabled"), &ShaderCreateDialog::config, DEFVAL(true), DEFVAL(true));
547
548
ADD_SIGNAL(MethodInfo("shader_created", PropertyInfo(Variant::OBJECT, "shader", PROPERTY_HINT_RESOURCE_TYPE, "Shader")));
549
ADD_SIGNAL(MethodInfo("shader_include_created", PropertyInfo(Variant::OBJECT, "shader_include", PROPERTY_HINT_RESOURCE_TYPE, "ShaderInclude")));
550
}
551
552
ShaderCreateDialog::ShaderCreateDialog() {
553
_update_language_info();
554
555
// Main Controls.
556
557
gc = memnew(GridContainer);
558
gc->set_columns(2);
559
560
// Error Fields.
561
562
validation_panel = memnew(EditorValidationPanel);
563
validation_panel->add_line(MSG_ID_SHADER, TTR("Shader path/name is valid."));
564
validation_panel->add_line(MSG_ID_PATH, TTR("Will create a new shader file."));
565
validation_panel->add_line(MSG_ID_BUILT_IN);
566
validation_panel->set_update_callback(callable_mp(this, &ShaderCreateDialog::_update_dialog));
567
validation_panel->set_accept_button(get_ok_button());
568
569
// Spacing.
570
571
Control *spacing = memnew(Control);
572
spacing->set_custom_minimum_size(Size2(0, 10 * EDSCALE));
573
574
VBoxContainer *vb = memnew(VBoxContainer);
575
vb->add_child(gc);
576
vb->add_child(spacing);
577
vb->add_child(validation_panel);
578
add_child(vb);
579
580
// Type.
581
582
type_menu = memnew(OptionButton);
583
type_menu->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
584
type_menu->set_accessibility_name(TTRC("Type:"));
585
type_menu->set_custom_minimum_size(Size2(250, 0) * EDSCALE);
586
type_menu->set_h_size_flags(Control::SIZE_EXPAND_FILL);
587
gc->add_child(memnew(Label(TTR("Type:"))));
588
gc->add_child(type_menu);
589
590
for (int i = 0; i < SHADER_TYPE_MAX; i++) {
591
String type;
592
bool invalid = false;
593
switch (i) {
594
case SHADER_TYPE_TEXT:
595
type = "Shader";
596
default_type = i;
597
break;
598
case SHADER_TYPE_VISUAL:
599
type = "VisualShader";
600
break;
601
case SHADER_TYPE_INC:
602
type = "ShaderInclude";
603
break;
604
case SHADER_TYPE_MAX:
605
invalid = true;
606
break;
607
default:
608
invalid = true;
609
break;
610
}
611
if (invalid) {
612
continue;
613
}
614
type_menu->add_item(type);
615
}
616
if (default_type >= 0) {
617
type_menu->select(default_type);
618
}
619
current_type = default_type;
620
type_menu->connect(SceneStringName(item_selected), callable_mp(this, &ShaderCreateDialog::_type_changed));
621
622
// Modes.
623
624
mode_menu = memnew(OptionButton);
625
mode_menu->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
626
mode_menu->set_accessibility_name(TTRC("Mode:"));
627
for (const String &type_name : ShaderTypes::get_singleton()->get_types_list()) {
628
mode_menu->add_item(type_name.capitalize());
629
}
630
gc->add_child(memnew(Label(TTR("Mode:"))));
631
gc->add_child(mode_menu);
632
mode_menu->connect(SceneStringName(item_selected), callable_mp(this, &ShaderCreateDialog::_mode_changed));
633
634
// Templates.
635
636
template_menu = memnew(OptionButton);
637
template_menu->set_accessibility_name(TTRC("Template:"));
638
gc->add_child(memnew(Label(TTR("Template:"))));
639
gc->add_child(template_menu);
640
template_menu->connect(SceneStringName(item_selected), callable_mp(this, &ShaderCreateDialog::_template_changed));
641
642
// Built-in Shader.
643
644
internal = memnew(CheckBox);
645
internal->set_text(TTR("On"));
646
internal->set_accessibility_name(TTRC("Built-in Shader:"));
647
internal->connect(SceneStringName(toggled), callable_mp(this, &ShaderCreateDialog::_built_in_toggled));
648
gc->add_child(memnew(Label(TTR("Built-in Shader:"))));
649
gc->add_child(internal);
650
651
// Path.
652
653
HBoxContainer *hb = memnew(HBoxContainer);
654
hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
655
hb->connect(SceneStringName(sort_children), callable_mp(this, &ShaderCreateDialog::_path_hbox_sorted));
656
file_path = memnew(LineEdit);
657
file_path->connect(SceneStringName(text_changed), callable_mp(this, &ShaderCreateDialog::_path_changed));
658
file_path->set_accessibility_name(TTRC("Path:"));
659
file_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
660
hb->add_child(file_path);
661
register_text_enter(file_path);
662
path_button = memnew(Button);
663
path_button->set_accessibility_name(TTRC("Select"));
664
path_button->connect(SceneStringName(pressed), callable_mp(this, &ShaderCreateDialog::_browse_path));
665
hb->add_child(path_button);
666
gc->add_child(memnew(Label(TTR("Path:"))));
667
gc->add_child(hb);
668
669
// Dialog Setup.
670
671
file_browse = memnew(EditorFileDialog);
672
file_browse->connect("file_selected", callable_mp(this, &ShaderCreateDialog::_file_selected));
673
file_browse->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
674
add_child(file_browse);
675
676
alert = memnew(AcceptDialog);
677
alert->get_label()->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
678
alert->get_label()->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
679
alert->get_label()->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
680
alert->get_label()->set_custom_minimum_size(Size2(325, 60) * EDSCALE);
681
add_child(alert);
682
683
set_ok_button_text(TTR("Create"));
684
set_hide_on_ok(false);
685
686
set_title(TTR("Create Shader"));
687
}
688
689