Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/scene/2d/tiles/tile_set_editor.cpp
9906 views
1
/**************************************************************************/
2
/* tile_set_editor.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 "tile_set_editor.h"
32
33
#include "tile_data_editors.h"
34
#include "tiles_editor_plugin.h"
35
36
#include "editor/editor_node.h"
37
#include "editor/editor_undo_redo_manager.h"
38
#include "editor/file_system/editor_file_system.h"
39
#include "editor/gui/editor_file_dialog.h"
40
#include "editor/inspector/editor_inspector.h"
41
#include "editor/settings/editor_settings.h"
42
#include "editor/themes/editor_scale.h"
43
44
#include "scene/gui/box_container.h"
45
#include "scene/gui/control.h"
46
#include "scene/gui/dialogs.h"
47
48
TileSetEditor *TileSetEditor::singleton = nullptr;
49
50
void TileSetEditor::_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
51
ERR_FAIL_COND(tile_set.is_null());
52
53
if (!_can_drop_data_fw(p_point, p_data, p_from)) {
54
return;
55
}
56
57
if (p_from == sources_list) {
58
// Handle dropping a texture in the list of atlas resources.
59
Dictionary d = p_data;
60
Vector<String> files = d["files"];
61
_load_texture_files(files);
62
}
63
}
64
65
bool TileSetEditor::_can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
66
ERR_FAIL_COND_V(tile_set.is_null(), false);
67
68
if (read_only) {
69
return false;
70
}
71
72
if (p_from == sources_list) {
73
Dictionary d = p_data;
74
75
if (!d.has("type")) {
76
return false;
77
}
78
79
// Check if we have a Texture2D.
80
if (String(d["type"]) == "files") {
81
Vector<String> files = d["files"];
82
83
if (files.is_empty()) {
84
return false;
85
}
86
87
for (int i = 0; i < files.size(); i++) {
88
String ftype = EditorFileSystem::get_singleton()->get_file_type(files[i]);
89
90
if (!ClassDB::is_parent_class(ftype, "Texture2D")) {
91
return false;
92
}
93
}
94
95
return true;
96
}
97
}
98
return false;
99
}
100
101
void TileSetEditor::_load_texture_files(const Vector<String> &p_paths) {
102
int source_id = TileSet::INVALID_SOURCE;
103
Vector<Ref<TileSetAtlasSource>> atlases;
104
105
for (const String &p_path : p_paths) {
106
Ref<Texture2D> texture = ResourceLoader::load(p_path);
107
108
if (texture.is_null()) {
109
EditorNode::get_singleton()->show_warning(TTR("Invalid texture selected."));
110
continue;
111
}
112
113
// Retrieve the id for the next created source.
114
source_id = tile_set->get_next_source_id();
115
116
// Actually create the new source.
117
Ref<TileSetAtlasSource> atlas_source = memnew(TileSetAtlasSource);
118
atlas_source->set_texture(texture);
119
atlas_source->set_texture_region_size(tile_set->get_tile_size());
120
121
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
122
undo_redo->create_action(TTR("Add a new atlas source"));
123
undo_redo->add_do_method(*tile_set, "add_source", atlas_source, source_id);
124
undo_redo->add_undo_method(*tile_set, "remove_source", source_id);
125
undo_redo->commit_action();
126
127
atlases.append(atlas_source);
128
}
129
130
if (!atlases.is_empty()) {
131
tile_set_atlas_source_editor->init_new_atlases(atlases);
132
}
133
134
// Update the selected source (thus triggering an update).
135
_update_sources_list(source_id);
136
}
137
138
void TileSetEditor::_update_sources_list(int force_selected_id) {
139
if (tile_set.is_null()) {
140
return;
141
}
142
143
// Get the previously selected id.
144
int old_selected = TileSet::INVALID_SOURCE;
145
if (sources_list->get_current() >= 0) {
146
int source_id = sources_list->get_item_metadata(sources_list->get_current());
147
if (tile_set->has_source(source_id)) {
148
old_selected = source_id;
149
}
150
}
151
152
int to_select = TileSet::INVALID_SOURCE;
153
if (force_selected_id >= 0) {
154
to_select = force_selected_id;
155
} else if (old_selected >= 0) {
156
to_select = old_selected;
157
}
158
159
// Clear the list.
160
sources_list->clear();
161
162
// Update the atlas sources.
163
List<int> source_ids = TilesEditorUtils::get_singleton()->get_sorted_sources(tile_set);
164
for (const int &source_id : source_ids) {
165
TileSetSource *source = *tile_set->get_source(source_id);
166
167
Ref<Texture2D> texture;
168
String item_text;
169
170
// Common to all type of sources.
171
if (!source->get_name().is_empty()) {
172
item_text = source->get_name();
173
}
174
175
// Atlas source.
176
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
177
if (atlas_source) {
178
texture = atlas_source->get_texture();
179
if (item_text.is_empty()) {
180
if (texture.is_valid()) {
181
item_text = texture->get_path().get_file();
182
} else {
183
item_text = vformat(TTR("No Texture Atlas Source (ID: %d)"), source_id);
184
}
185
}
186
}
187
188
// Scene collection source.
189
TileSetScenesCollectionSource *scene_collection_source = Object::cast_to<TileSetScenesCollectionSource>(source);
190
if (scene_collection_source) {
191
texture = get_editor_theme_icon(SNAME("PackedScene"));
192
if (item_text.is_empty()) {
193
if (scene_collection_source->get_scene_tiles_count() > 0) {
194
item_text = vformat(TTR("Scene Collection Source (ID: %d)"), source_id);
195
} else {
196
item_text = vformat(TTR("Empty Scene Collection Source (ID: %d)"), source_id);
197
}
198
}
199
}
200
201
// Use default if not valid.
202
if (item_text.is_empty()) {
203
item_text = vformat(TTR("Unknown Type Source (ID: %d)"), source_id);
204
}
205
if (texture.is_null()) {
206
texture = missing_texture_texture;
207
}
208
209
sources_list->add_item(item_text, texture);
210
sources_list->set_item_metadata(-1, source_id);
211
}
212
213
// Set again the current selected item if needed.
214
if (to_select >= 0) {
215
for (int i = 0; i < sources_list->get_item_count(); i++) {
216
if ((int)sources_list->get_item_metadata(i) == to_select) {
217
sources_list->set_current(i);
218
sources_list->ensure_current_is_visible();
219
if (old_selected != to_select) {
220
sources_list->emit_signal(SceneStringName(item_selected), sources_list->get_current());
221
}
222
break;
223
}
224
}
225
}
226
227
// If nothing is selected, select the first entry.
228
if (sources_list->get_current() < 0 && sources_list->get_item_count() > 0) {
229
sources_list->set_current(0);
230
if (old_selected != int(sources_list->get_item_metadata(0))) {
231
sources_list->emit_signal(SceneStringName(item_selected), sources_list->get_current());
232
}
233
}
234
235
// If there is no source left, hide all editors and show the label.
236
_source_selected(sources_list->get_current());
237
238
// Synchronize the lists.
239
TilesEditorUtils::get_singleton()->set_sources_lists_current(sources_list->get_current());
240
}
241
242
void TileSetEditor::_source_selected(int p_source_index) {
243
ERR_FAIL_COND(tile_set.is_null());
244
245
// Update the selected source.
246
sources_delete_button->set_disabled(p_source_index < 0 || read_only);
247
248
if (p_source_index >= 0) {
249
int source_id = sources_list->get_item_metadata(p_source_index);
250
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(*tile_set->get_source(source_id));
251
TileSetScenesCollectionSource *scenes_collection_source = Object::cast_to<TileSetScenesCollectionSource>(*tile_set->get_source(source_id));
252
if (atlas_source) {
253
no_source_selected_label->hide();
254
tile_set_atlas_source_editor->edit(*tile_set, atlas_source, source_id);
255
tile_set_atlas_source_editor->show();
256
tile_set_scenes_collection_source_editor->hide();
257
} else if (scenes_collection_source) {
258
no_source_selected_label->hide();
259
tile_set_atlas_source_editor->hide();
260
tile_set_scenes_collection_source_editor->edit(*tile_set, scenes_collection_source, source_id);
261
tile_set_scenes_collection_source_editor->show();
262
} else {
263
no_source_selected_label->show();
264
tile_set_atlas_source_editor->hide();
265
tile_set_scenes_collection_source_editor->hide();
266
}
267
} else {
268
no_source_selected_label->show();
269
tile_set_atlas_source_editor->hide();
270
tile_set_scenes_collection_source_editor->hide();
271
}
272
}
273
274
void TileSetEditor::_source_delete_pressed() {
275
ERR_FAIL_COND(tile_set.is_null());
276
277
// Update the selected source.
278
int to_delete = sources_list->get_item_metadata(sources_list->get_current());
279
280
Ref<TileSetSource> source = tile_set->get_source(to_delete);
281
282
// Remove the source.
283
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
284
undo_redo->create_action(TTR("Remove source"));
285
undo_redo->add_do_method(*tile_set, "remove_source", to_delete);
286
undo_redo->add_undo_method(*tile_set, "add_source", source, to_delete);
287
undo_redo->commit_action();
288
289
_update_sources_list();
290
}
291
292
void TileSetEditor::_source_add_id_pressed(int p_id_pressed) {
293
ERR_FAIL_COND(tile_set.is_null());
294
295
switch (p_id_pressed) {
296
case 0: {
297
if (!texture_file_dialog) {
298
texture_file_dialog = memnew(EditorFileDialog);
299
add_child(texture_file_dialog);
300
texture_file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILES);
301
texture_file_dialog->connect("files_selected", callable_mp(this, &TileSetEditor::_load_texture_files));
302
303
List<String> extensions;
304
ResourceLoader::get_recognized_extensions_for_type("Texture2D", &extensions);
305
for (const String &E : extensions) {
306
texture_file_dialog->add_filter("*." + E, E.to_upper());
307
}
308
}
309
texture_file_dialog->popup_file_dialog();
310
} break;
311
case 1: {
312
int source_id = tile_set->get_next_source_id();
313
314
Ref<TileSetScenesCollectionSource> scene_collection_source = memnew(TileSetScenesCollectionSource);
315
316
// Add a new source.
317
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
318
undo_redo->create_action(TTR("Add atlas source"));
319
undo_redo->add_do_method(*tile_set, "add_source", scene_collection_source, source_id);
320
undo_redo->add_undo_method(*tile_set, "remove_source", source_id);
321
undo_redo->commit_action();
322
323
_update_sources_list(source_id);
324
} break;
325
default:
326
ERR_FAIL();
327
}
328
}
329
330
void TileSetEditor::_sources_advanced_menu_id_pressed(int p_id_pressed) {
331
ERR_FAIL_COND(tile_set.is_null());
332
333
switch (p_id_pressed) {
334
case 0: {
335
atlas_merging_dialog->update_tile_set(tile_set);
336
atlas_merging_dialog->popup_centered_ratio(0.5);
337
} break;
338
case 1: {
339
tile_proxies_manager_dialog->update_tile_set(tile_set);
340
tile_proxies_manager_dialog->popup_centered_ratio(0.5);
341
} break;
342
}
343
}
344
345
void TileSetEditor::_set_source_sort(int p_sort) {
346
TilesEditorUtils::get_singleton()->set_sorting_option(p_sort);
347
for (int i = 0; i != TilesEditorUtils::SOURCE_SORT_MAX; i++) {
348
source_sort_button->get_popup()->set_item_checked(i, (i == (int)p_sort));
349
}
350
351
int old_selected = TileSet::INVALID_SOURCE;
352
if (sources_list->get_current() >= 0) {
353
int source_id = sources_list->get_item_metadata(sources_list->get_current());
354
if (tile_set->has_source(source_id)) {
355
old_selected = source_id;
356
}
357
}
358
_update_sources_list(old_selected);
359
360
if (!first_edit) {
361
EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "tile_source_sort", p_sort);
362
}
363
}
364
365
void TileSetEditor::_notification(int p_what) {
366
switch (p_what) {
367
case NOTIFICATION_THEME_CHANGED: {
368
sources_delete_button->set_button_icon(get_editor_theme_icon(SNAME("Remove")));
369
sources_add_button->set_button_icon(get_editor_theme_icon(SNAME("Add")));
370
source_sort_button->set_button_icon(get_editor_theme_icon(SNAME("Sort")));
371
sources_advanced_menu_button->set_button_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));
372
missing_texture_texture = get_editor_theme_icon(SNAME("TileSet"));
373
expanded_area->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), "Tree"));
374
_update_sources_list();
375
} break;
376
377
case NOTIFICATION_INTERNAL_PROCESS: {
378
if (tile_set_changed_needs_update) {
379
if (tile_set.is_valid()) {
380
tile_set->set_edited(true);
381
}
382
383
read_only = false;
384
if (tile_set.is_valid()) {
385
read_only = EditorNode::get_singleton()->is_resource_read_only(tile_set);
386
}
387
388
_update_sources_list();
389
_update_patterns_list();
390
391
sources_add_button->set_disabled(read_only);
392
sources_advanced_menu_button->set_disabled(read_only);
393
source_sort_button->set_disabled(read_only);
394
395
tile_set_changed_needs_update = false;
396
}
397
} break;
398
399
case NOTIFICATION_VISIBILITY_CHANGED: {
400
if (!is_visible_in_tree()) {
401
remove_expanded_editor();
402
}
403
} break;
404
}
405
}
406
407
void TileSetEditor::_patterns_item_list_gui_input(const Ref<InputEvent> &p_event) {
408
ERR_FAIL_COND(tile_set.is_null());
409
410
if (EditorNode::get_singleton()->is_resource_read_only(tile_set)) {
411
return;
412
}
413
414
if (ED_IS_SHORTCUT("tiles_editor/delete", p_event) && p_event->is_pressed() && !p_event->is_echo()) {
415
Vector<int> selected = patterns_item_list->get_selected_items();
416
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
417
undo_redo->create_action(TTR("Remove TileSet patterns"));
418
for (int i = 0; i < selected.size(); i++) {
419
int pattern_index = selected[i];
420
undo_redo->add_do_method(*tile_set, "remove_pattern", pattern_index);
421
undo_redo->add_undo_method(*tile_set, "add_pattern", tile_set->get_pattern(pattern_index), pattern_index);
422
}
423
undo_redo->commit_action();
424
patterns_item_list->accept_event();
425
}
426
}
427
428
void TileSetEditor::_pattern_preview_done(Ref<TileMapPattern> p_pattern, Ref<Texture2D> p_texture) {
429
// TODO optimize ?
430
for (int i = 0; i < patterns_item_list->get_item_count(); i++) {
431
if (patterns_item_list->get_item_metadata(i) == p_pattern) {
432
patterns_item_list->set_item_icon(i, p_texture);
433
break;
434
}
435
}
436
}
437
438
void TileSetEditor::_update_patterns_list() {
439
ERR_FAIL_COND(tile_set.is_null());
440
441
// Recreate the items.
442
patterns_item_list->clear();
443
for (int i = 0; i < tile_set->get_patterns_count(); i++) {
444
int id = patterns_item_list->add_item("");
445
patterns_item_list->set_item_metadata(id, tile_set->get_pattern(i));
446
patterns_item_list->set_item_tooltip(id, vformat(TTR("Index: %d"), i));
447
TilesEditorUtils::get_singleton()->queue_pattern_preview(tile_set, tile_set->get_pattern(i), callable_mp(this, &TileSetEditor::_pattern_preview_done));
448
}
449
450
// Update the label visibility.
451
patterns_help_label->set_visible(patterns_item_list->get_item_count() == 0);
452
}
453
454
void TileSetEditor::_tile_set_changed() {
455
tile_set_changed_needs_update = true;
456
}
457
458
void TileSetEditor::_tab_changed(int p_tab_changed) {
459
split_container->set_visible(p_tab_changed == 0);
460
patterns_item_list->set_visible(p_tab_changed == 1);
461
}
462
463
void TileSetEditor::_move_tile_set_array_element(Object *p_undo_redo, Object *p_edited, const String &p_array_prefix, int p_from_index, int p_to_pos) {
464
EditorUndoRedoManager *undo_redo_man = Object::cast_to<EditorUndoRedoManager>(p_undo_redo);
465
ERR_FAIL_NULL(undo_redo_man);
466
467
TileSet *ed_tile_set = Object::cast_to<TileSet>(p_edited);
468
if (!ed_tile_set) {
469
return;
470
}
471
472
Vector<String> components = String(p_array_prefix).split("/", true, 2);
473
474
// Compute the array indices to save.
475
int begin = 0;
476
int end;
477
if (p_array_prefix == "occlusion_layer_") {
478
end = ed_tile_set->get_occlusion_layers_count();
479
} else if (p_array_prefix == "physics_layer_") {
480
end = ed_tile_set->get_physics_layers_count();
481
} else if (p_array_prefix == "terrain_set_") {
482
end = ed_tile_set->get_terrain_sets_count();
483
} else if (components.size() >= 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int() && components[1] == "terrain_") {
484
int terrain_set = components[0].trim_prefix("terrain_set_").to_int();
485
end = ed_tile_set->get_terrains_count(terrain_set);
486
} else if (p_array_prefix == "navigation_layer_") {
487
end = ed_tile_set->get_navigation_layers_count();
488
} else if (p_array_prefix == "custom_data_layer_") {
489
end = ed_tile_set->get_custom_data_layers_count();
490
} else {
491
ERR_FAIL_MSG("Invalid array prefix for TileSet.");
492
}
493
if (p_from_index < 0) {
494
// Adding new.
495
if (p_to_pos >= 0) {
496
begin = p_to_pos;
497
} else {
498
end = 0; // Nothing to save when adding at the end.
499
}
500
} else if (p_to_pos < 0) {
501
// Removing.
502
begin = p_from_index;
503
} else {
504
// Moving.
505
begin = MIN(p_from_index, p_to_pos);
506
end = MIN(MAX(p_from_index, p_to_pos) + 1, end);
507
}
508
509
#define ADD_UNDO(obj, property) undo_redo_man->add_undo_property(obj, property, obj->get(property));
510
511
// Add undo method to adding array element.
512
if (p_array_prefix == "occlusion_layer_") {
513
if (p_from_index < 0) {
514
undo_redo_man->add_undo_method(ed_tile_set, "remove_occlusion_layer", p_to_pos < 0 ? ed_tile_set->get_occlusion_layers_count() : p_to_pos);
515
}
516
} else if (p_array_prefix == "physics_layer_") {
517
if (p_from_index < 0) {
518
undo_redo_man->add_undo_method(ed_tile_set, "remove_physics_layer", p_to_pos < 0 ? ed_tile_set->get_physics_layers_count() : p_to_pos);
519
}
520
} else if (p_array_prefix == "terrain_set_") {
521
if (p_from_index < 0) {
522
undo_redo_man->add_undo_method(ed_tile_set, "remove_terrain_set", p_to_pos < 0 ? ed_tile_set->get_terrain_sets_count() : p_to_pos);
523
}
524
} else if (components.size() >= 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int() && components[1] == "terrain_") {
525
int terrain_set = components[0].trim_prefix("terrain_set_").to_int();
526
if (p_from_index < 0) {
527
undo_redo_man->add_undo_method(ed_tile_set, "remove_terrain", terrain_set, p_to_pos < 0 ? ed_tile_set->get_terrains_count(terrain_set) : p_to_pos);
528
}
529
} else if (p_array_prefix == "navigation_layer_") {
530
if (p_from_index < 0) {
531
undo_redo_man->add_undo_method(ed_tile_set, "remove_navigation_layer", p_to_pos < 0 ? ed_tile_set->get_navigation_layers_count() : p_to_pos);
532
}
533
} else if (p_array_prefix == "custom_data_layer_") {
534
if (p_from_index < 0) {
535
undo_redo_man->add_undo_method(ed_tile_set, "remove_custom_data_layer", p_to_pos < 0 ? ed_tile_set->get_custom_data_layers_count() : p_to_pos);
536
}
537
}
538
539
// Save layers' properties.
540
List<PropertyInfo> properties;
541
ed_tile_set->get_property_list(&properties);
542
for (PropertyInfo pi : properties) {
543
if (pi.name.begins_with(p_array_prefix)) {
544
String str = pi.name.trim_prefix(p_array_prefix);
545
int to_char_index = 0;
546
while (to_char_index < str.length()) {
547
if (!is_digit(str[to_char_index])) {
548
break;
549
}
550
to_char_index++;
551
}
552
if (to_char_index > 0) {
553
int array_index = str.left(to_char_index).to_int();
554
if (array_index >= begin && array_index < end) {
555
ADD_UNDO(ed_tile_set, pi.name);
556
}
557
}
558
}
559
}
560
561
// Save properties for TileSetAtlasSources tile data
562
for (int i = 0; i < ed_tile_set->get_source_count(); i++) {
563
int source_id = ed_tile_set->get_source_id(i);
564
565
Ref<TileSetAtlasSource> tas = ed_tile_set->get_source(source_id);
566
if (tas.is_valid()) {
567
for (int j = 0; j < tas->get_tiles_count(); j++) {
568
Vector2i tile_id = tas->get_tile_id(j);
569
for (int k = 0; k < tas->get_alternative_tiles_count(tile_id); k++) {
570
int alternative_id = tas->get_alternative_tile_id(tile_id, k);
571
TileData *tile_data = tas->get_tile_data(tile_id, alternative_id);
572
ERR_FAIL_NULL(tile_data);
573
574
// Actually saving stuff.
575
if (p_array_prefix == "occlusion_layer_") {
576
for (int layer_index = begin; layer_index < end; layer_index++) {
577
ADD_UNDO(tile_data, vformat("occlusion_layer_%d/polygon", layer_index));
578
}
579
} else if (p_array_prefix == "physics_layer_") {
580
for (int layer_index = begin; layer_index < end; layer_index++) {
581
ADD_UNDO(tile_data, vformat("physics_layer_%d/polygons_count", layer_index));
582
for (int polygon_index = 0; polygon_index < tile_data->get_collision_polygons_count(layer_index); polygon_index++) {
583
ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/points", layer_index, polygon_index));
584
ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/one_way", layer_index, polygon_index));
585
ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/one_way_margin", layer_index, polygon_index));
586
}
587
}
588
} else if (p_array_prefix == "terrain_set_") {
589
ADD_UNDO(tile_data, "terrain_set");
590
for (int terrain_set_index = begin; terrain_set_index < end; terrain_set_index++) {
591
for (int l = 0; l < TileSet::CELL_NEIGHBOR_MAX; l++) {
592
TileSet::CellNeighbor bit = TileSet::CellNeighbor(l);
593
if (tile_data->is_valid_terrain_peering_bit(bit)) {
594
ADD_UNDO(tile_data, "terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[l]));
595
}
596
}
597
}
598
} else if (components.size() >= 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int() && components[1] == "terrain_") {
599
for (int terrain_index = 0; terrain_index < TileSet::CELL_NEIGHBOR_MAX; terrain_index++) {
600
TileSet::CellNeighbor bit = TileSet::CellNeighbor(terrain_index);
601
if (tile_data->is_valid_terrain_peering_bit(bit)) {
602
ADD_UNDO(tile_data, "terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[terrain_index]));
603
}
604
}
605
} else if (p_array_prefix == "navigation_layer_") {
606
for (int layer_index = begin; layer_index < end; layer_index++) {
607
ADD_UNDO(tile_data, vformat("navigation_layer_%d/polygon", layer_index));
608
}
609
} else if (p_array_prefix == "custom_data_layer_") {
610
for (int layer_index = begin; layer_index < end; layer_index++) {
611
ADD_UNDO(tile_data, vformat("custom_data_%d", layer_index));
612
}
613
}
614
}
615
}
616
}
617
}
618
#undef ADD_UNDO
619
620
// Add do method to add/remove array element.
621
if (p_array_prefix == "occlusion_layer_") {
622
if (p_from_index < 0) {
623
undo_redo_man->add_do_method(ed_tile_set, "add_occlusion_layer", p_to_pos);
624
} else if (p_to_pos < 0) {
625
undo_redo_man->add_do_method(ed_tile_set, "remove_occlusion_layer", p_from_index);
626
} else {
627
undo_redo_man->add_do_method(ed_tile_set, "move_occlusion_layer", p_from_index, p_to_pos);
628
}
629
} else if (p_array_prefix == "physics_layer_") {
630
if (p_from_index < 0) {
631
undo_redo_man->add_do_method(ed_tile_set, "add_physics_layer", p_to_pos);
632
} else if (p_to_pos < 0) {
633
undo_redo_man->add_do_method(ed_tile_set, "remove_physics_layer", p_from_index);
634
} else {
635
undo_redo_man->add_do_method(ed_tile_set, "move_physics_layer", p_from_index, p_to_pos);
636
}
637
} else if (p_array_prefix == "terrain_set_") {
638
if (p_from_index < 0) {
639
undo_redo_man->add_do_method(ed_tile_set, "add_terrain_set", p_to_pos);
640
} else if (p_to_pos < 0) {
641
undo_redo_man->add_do_method(ed_tile_set, "remove_terrain_set", p_from_index);
642
} else {
643
undo_redo_man->add_do_method(ed_tile_set, "move_terrain_set", p_from_index, p_to_pos);
644
}
645
} else if (components.size() >= 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int() && components[1] == "terrain_") {
646
int terrain_set = components[0].trim_prefix("terrain_set_").to_int();
647
if (p_from_index < 0) {
648
undo_redo_man->add_do_method(ed_tile_set, "add_terrain", terrain_set, p_to_pos);
649
} else if (p_to_pos < 0) {
650
undo_redo_man->add_do_method(ed_tile_set, "remove_terrain", terrain_set, p_from_index);
651
} else {
652
undo_redo_man->add_do_method(ed_tile_set, "move_terrain", terrain_set, p_from_index, p_to_pos);
653
}
654
} else if (p_array_prefix == "navigation_layer_") {
655
if (p_from_index < 0) {
656
undo_redo_man->add_do_method(ed_tile_set, "add_navigation_layer", p_to_pos);
657
} else if (p_to_pos < 0) {
658
undo_redo_man->add_do_method(ed_tile_set, "remove_navigation_layer", p_from_index);
659
} else {
660
undo_redo_man->add_do_method(ed_tile_set, "move_navigation_layer", p_from_index, p_to_pos);
661
}
662
} else if (p_array_prefix == "custom_data_layer_") {
663
if (p_from_index < 0) {
664
undo_redo_man->add_do_method(ed_tile_set, "add_custom_data_layer", p_to_pos);
665
} else if (p_to_pos < 0) {
666
undo_redo_man->add_do_method(ed_tile_set, "remove_custom_data_layer", p_from_index);
667
} else {
668
undo_redo_man->add_do_method(ed_tile_set, "move_custom_data_layer", p_from_index, p_to_pos);
669
}
670
}
671
}
672
673
void TileSetEditor::_undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, const String &p_property, const Variant &p_new_value) {
674
EditorUndoRedoManager *undo_redo_man = Object::cast_to<EditorUndoRedoManager>(p_undo_redo);
675
ERR_FAIL_NULL(undo_redo_man);
676
677
#define ADD_UNDO(obj, property) undo_redo_man->add_undo_property(obj, property, obj->get(property));
678
TileSet *ed_tile_set = Object::cast_to<TileSet>(p_edited);
679
if (ed_tile_set) {
680
Vector<String> components = p_property.split("/", true, 3);
681
for (int i = 0; i < ed_tile_set->get_source_count(); i++) {
682
int source_id = ed_tile_set->get_source_id(i);
683
684
Ref<TileSetAtlasSource> tas = ed_tile_set->get_source(source_id);
685
if (tas.is_valid()) {
686
for (int j = 0; j < tas->get_tiles_count(); j++) {
687
Vector2i tile_id = tas->get_tile_id(j);
688
for (int k = 0; k < tas->get_alternative_tiles_count(tile_id); k++) {
689
int alternative_id = tas->get_alternative_tile_id(tile_id, k);
690
TileData *tile_data = tas->get_tile_data(tile_id, alternative_id);
691
ERR_FAIL_NULL(tile_data);
692
693
if (components.size() == 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int() && components[1] == "mode") {
694
ADD_UNDO(tile_data, "terrain_set");
695
ADD_UNDO(tile_data, "terrain");
696
for (int l = 0; l < TileSet::CELL_NEIGHBOR_MAX; l++) {
697
TileSet::CellNeighbor bit = TileSet::CellNeighbor(l);
698
if (tile_data->is_valid_terrain_peering_bit(bit)) {
699
ADD_UNDO(tile_data, "terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[l]));
700
}
701
}
702
} else if (components.size() == 2 && components[0].begins_with("custom_data_layer_") && components[0].trim_prefix("custom_data_layer_").is_valid_int() && components[1] == "type") {
703
int custom_data_layer = components[0].trim_prefix("custom_data_layer_").is_valid_int();
704
ADD_UNDO(tile_data, vformat("custom_data_%d", custom_data_layer));
705
}
706
}
707
}
708
}
709
}
710
}
711
#undef ADD_UNDO
712
}
713
714
void TileSetEditor::edit(Ref<TileSet> p_tile_set) {
715
bool new_read_only_state = false;
716
if (p_tile_set.is_valid()) {
717
new_read_only_state = EditorNode::get_singleton()->is_resource_read_only(p_tile_set);
718
}
719
720
if (p_tile_set == tile_set && new_read_only_state == read_only) {
721
return;
722
}
723
724
// Remove listener.
725
if (tile_set.is_valid()) {
726
tile_set->disconnect_changed(callable_mp(this, &TileSetEditor::_tile_set_changed));
727
}
728
729
// Change the edited object.
730
tile_set = p_tile_set;
731
732
// Read-only status is false by default
733
read_only = new_read_only_state;
734
735
// Add the listener again and check for read-only status.
736
if (tile_set.is_valid()) {
737
sources_add_button->set_disabled(read_only);
738
sources_advanced_menu_button->set_disabled(read_only);
739
source_sort_button->set_disabled(read_only);
740
741
tile_set->connect_changed(callable_mp(this, &TileSetEditor::_tile_set_changed));
742
if (first_edit) {
743
_set_source_sort(EditorSettings::get_singleton()->get_project_metadata("editor_metadata", "tile_source_sort", 0));
744
first_edit = false;
745
} else {
746
_update_sources_list();
747
}
748
_update_patterns_list();
749
}
750
}
751
752
void TileSetEditor::add_expanded_editor(Control *p_editor) {
753
expanded_editor = p_editor;
754
expanded_editor_parent = p_editor->get_parent()->get_instance_id();
755
756
// Find the scrollable control this node belongs to.
757
Node *check_parent = expanded_editor->get_parent();
758
Control *parent_container = nullptr;
759
while (check_parent) {
760
parent_container = Object::cast_to<EditorInspector>(check_parent);
761
if (parent_container) {
762
break;
763
}
764
parent_container = Object::cast_to<ScrollContainer>(check_parent);
765
if (parent_container) {
766
break;
767
}
768
check_parent = check_parent->get_parent();
769
}
770
ERR_FAIL_NULL(parent_container);
771
772
expanded_editor->set_meta("reparented", true);
773
expanded_editor->reparent(expanded_area);
774
expanded_area->show();
775
expanded_area->set_size(Vector2(parent_container->get_global_rect().get_end().x - expanded_area->get_global_position().x, expanded_area->get_size().y));
776
777
for (SplitContainer *split : disable_on_expand) {
778
split->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN);
779
}
780
}
781
782
void TileSetEditor::remove_expanded_editor() {
783
if (!expanded_editor) {
784
return;
785
}
786
787
Node *original_parent = ObjectDB::get_instance<Node>(expanded_editor_parent);
788
if (original_parent) {
789
expanded_editor->remove_meta("reparented");
790
expanded_editor->reparent(original_parent);
791
} else {
792
expanded_editor->queue_free();
793
}
794
expanded_editor = nullptr;
795
expanded_editor_parent = ObjectID();
796
expanded_area->hide();
797
798
for (SplitContainer *split : disable_on_expand) {
799
split->set_dragger_visibility(SplitContainer::DRAGGER_VISIBLE);
800
}
801
}
802
803
void TileSetEditor::register_split(SplitContainer *p_split) {
804
disable_on_expand.push_back(p_split);
805
}
806
807
TileSetEditor::TileSetEditor() {
808
singleton = this;
809
810
set_process_internal(true);
811
812
VBoxContainer *main_vb = memnew(VBoxContainer);
813
add_child(main_vb);
814
main_vb->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
815
816
// TabBar.
817
tabs_bar = memnew(TabBar);
818
tabs_bar->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
819
tabs_bar->set_clip_tabs(false);
820
tabs_bar->add_tab(TTR("Tile Sources"));
821
tabs_bar->add_tab(TTR("Patterns"));
822
tabs_bar->connect("tab_changed", callable_mp(this, &TileSetEditor::_tab_changed));
823
824
tile_set_toolbar = memnew(HBoxContainer);
825
tile_set_toolbar->set_h_size_flags(SIZE_EXPAND_FILL);
826
tile_set_toolbar->add_child(tabs_bar);
827
main_vb->add_child(tile_set_toolbar);
828
829
//// Tiles ////
830
// Split container.
831
split_container = memnew(HSplitContainer);
832
split_container->set_name(TTR("Tiles"));
833
split_container->set_h_size_flags(SIZE_EXPAND_FILL);
834
split_container->set_v_size_flags(SIZE_EXPAND_FILL);
835
main_vb->add_child(split_container);
836
837
// Sources list.
838
VBoxContainer *split_container_left_side = memnew(VBoxContainer);
839
split_container_left_side->set_h_size_flags(SIZE_EXPAND_FILL);
840
split_container_left_side->set_v_size_flags(SIZE_EXPAND_FILL);
841
split_container_left_side->set_stretch_ratio(0.25);
842
split_container_left_side->set_custom_minimum_size(Size2(70, 0) * EDSCALE);
843
split_container->add_child(split_container_left_side);
844
845
source_sort_button = memnew(MenuButton);
846
source_sort_button->set_flat(false);
847
source_sort_button->set_theme_type_variation(SceneStringName(FlatButton));
848
source_sort_button->set_tooltip_text(TTR("Sort Sources"));
849
850
PopupMenu *p = source_sort_button->get_popup();
851
p->connect(SceneStringName(id_pressed), callable_mp(this, &TileSetEditor::_set_source_sort));
852
p->add_radio_check_item(TTR("Sort by ID (Ascending)"), TilesEditorUtils::SOURCE_SORT_ID);
853
p->add_radio_check_item(TTR("Sort by ID (Descending)"), TilesEditorUtils::SOURCE_SORT_ID_REVERSE);
854
p->add_radio_check_item(TTR("Sort by Name (Ascending)"), TilesEditorUtils::SOURCE_SORT_NAME);
855
p->add_radio_check_item(TTR("Sort by Name (Descending)"), TilesEditorUtils::SOURCE_SORT_NAME_REVERSE);
856
p->set_item_checked(TilesEditorUtils::SOURCE_SORT_ID, true);
857
858
sources_list = memnew(ItemList);
859
sources_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
860
sources_list->set_fixed_icon_size(Size2(60, 60) * EDSCALE);
861
sources_list->set_h_size_flags(SIZE_EXPAND_FILL);
862
sources_list->set_v_size_flags(SIZE_EXPAND_FILL);
863
sources_list->set_theme_type_variation("ItemListSecondary");
864
sources_list->connect(SceneStringName(item_selected), callable_mp(this, &TileSetEditor::_source_selected));
865
sources_list->connect(SceneStringName(item_selected), callable_mp(TilesEditorUtils::get_singleton(), &TilesEditorUtils::set_sources_lists_current));
866
sources_list->connect(SceneStringName(visibility_changed), callable_mp(TilesEditorUtils::get_singleton(), &TilesEditorUtils::synchronize_sources_list).bind(sources_list, source_sort_button));
867
sources_list->add_user_signal(MethodInfo("sort_request"));
868
sources_list->connect("sort_request", callable_mp(this, &TileSetEditor::_update_sources_list).bind(-1));
869
sources_list->set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST);
870
SET_DRAG_FORWARDING_CDU(sources_list, TileSetEditor);
871
split_container_left_side->add_child(sources_list);
872
873
HBoxContainer *sources_bottom_actions = memnew(HBoxContainer);
874
sources_bottom_actions->set_alignment(BoxContainer::ALIGNMENT_END);
875
split_container_left_side->add_child(sources_bottom_actions);
876
877
sources_delete_button = memnew(Button);
878
sources_delete_button->set_theme_type_variation(SceneStringName(FlatButton));
879
sources_delete_button->set_disabled(true);
880
sources_delete_button->connect(SceneStringName(pressed), callable_mp(this, &TileSetEditor::_source_delete_pressed));
881
sources_bottom_actions->add_child(sources_delete_button);
882
883
sources_add_button = memnew(MenuButton);
884
sources_add_button->set_flat(false);
885
sources_add_button->set_theme_type_variation(SceneStringName(FlatButton));
886
sources_add_button->get_popup()->add_item(TTR("Atlas"));
887
sources_add_button->get_popup()->set_item_tooltip(-1, TTR("A palette of tiles made from a texture."));
888
sources_add_button->get_popup()->add_item(TTR("Scenes Collection"));
889
sources_add_button->get_popup()->set_item_tooltip(-1, TTR("A collection of scenes that can be instantiated and placed as tiles."));
890
sources_add_button->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &TileSetEditor::_source_add_id_pressed));
891
sources_bottom_actions->add_child(sources_add_button);
892
893
sources_advanced_menu_button = memnew(MenuButton);
894
sources_advanced_menu_button->set_flat(false);
895
sources_advanced_menu_button->set_theme_type_variation(SceneStringName(FlatButton));
896
sources_advanced_menu_button->get_popup()->add_item(TTR("Open Atlas Merging Tool"));
897
sources_advanced_menu_button->get_popup()->add_item(TTR("Manage Tile Proxies"));
898
sources_advanced_menu_button->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &TileSetEditor::_sources_advanced_menu_id_pressed));
899
sources_advanced_menu_button->set_accessibility_name(TTRC("Advanced"));
900
sources_bottom_actions->add_child(sources_advanced_menu_button);
901
sources_bottom_actions->add_child(source_sort_button);
902
903
atlas_merging_dialog = memnew(AtlasMergingDialog);
904
add_child(atlas_merging_dialog);
905
906
tile_proxies_manager_dialog = memnew(TileProxiesManagerDialog);
907
add_child(tile_proxies_manager_dialog);
908
909
// Right side container.
910
VBoxContainer *split_container_right_side = memnew(VBoxContainer);
911
split_container_right_side->set_h_size_flags(SIZE_EXPAND_FILL);
912
split_container_right_side->set_v_size_flags(SIZE_EXPAND_FILL);
913
split_container->add_child(split_container_right_side);
914
915
// No source selected.
916
no_source_selected_label = memnew(Label);
917
no_source_selected_label->set_focus_mode(FOCUS_ACCESSIBILITY);
918
no_source_selected_label->set_text(TTR("No TileSet source selected. Select or create a TileSet source.\nYou can create a new source by using the Add button on the left or by dropping a tileset texture onto the source list."));
919
no_source_selected_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
920
no_source_selected_label->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
921
no_source_selected_label->set_h_size_flags(SIZE_EXPAND_FILL);
922
no_source_selected_label->set_v_size_flags(SIZE_EXPAND_FILL);
923
no_source_selected_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
924
no_source_selected_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
925
split_container_right_side->add_child(no_source_selected_label);
926
927
// Atlases editor.
928
tile_set_atlas_source_editor = memnew(TileSetAtlasSourceEditor);
929
tile_set_atlas_source_editor->set_h_size_flags(SIZE_EXPAND_FILL);
930
tile_set_atlas_source_editor->set_v_size_flags(SIZE_EXPAND_FILL);
931
tile_set_atlas_source_editor->connect("source_id_changed", callable_mp(this, &TileSetEditor::_update_sources_list));
932
split_container_right_side->add_child(tile_set_atlas_source_editor);
933
tile_set_atlas_source_editor->hide();
934
935
// Scenes collection editor.
936
tile_set_scenes_collection_source_editor = memnew(TileSetScenesCollectionSourceEditor);
937
tile_set_scenes_collection_source_editor->set_h_size_flags(SIZE_EXPAND_FILL);
938
tile_set_scenes_collection_source_editor->set_v_size_flags(SIZE_EXPAND_FILL);
939
tile_set_scenes_collection_source_editor->connect("source_id_changed", callable_mp(this, &TileSetEditor::_update_sources_list));
940
split_container_right_side->add_child(tile_set_scenes_collection_source_editor);
941
tile_set_scenes_collection_source_editor->hide();
942
943
//// Patterns ////
944
int thumbnail_size = 64;
945
patterns_item_list = memnew(ItemList);
946
patterns_item_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
947
patterns_item_list->set_max_columns(0);
948
patterns_item_list->set_icon_mode(ItemList::ICON_MODE_TOP);
949
patterns_item_list->set_fixed_column_width(thumbnail_size * 3 / 2);
950
patterns_item_list->set_max_text_lines(2);
951
patterns_item_list->set_fixed_icon_size(Size2(thumbnail_size, thumbnail_size));
952
patterns_item_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
953
patterns_item_list->set_theme_type_variation("ItemListSecondary");
954
patterns_item_list->connect(SceneStringName(gui_input), callable_mp(this, &TileSetEditor::_patterns_item_list_gui_input));
955
main_vb->add_child(patterns_item_list);
956
patterns_item_list->hide();
957
958
patterns_help_label = memnew(Label);
959
patterns_help_label->set_focus_mode(FOCUS_ACCESSIBILITY);
960
patterns_help_label->set_text(TTR("Add new patterns in the TileMap editing mode."));
961
patterns_help_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
962
patterns_help_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
963
patterns_help_label->set_anchors_and_offsets_preset(Control::PRESET_HCENTER_WIDE);
964
patterns_item_list->add_child(patterns_help_label);
965
966
// Expanded editor
967
expanded_area = memnew(PanelContainer);
968
add_child(expanded_area);
969
expanded_area->set_anchors_and_offsets_preset(PRESET_LEFT_WIDE);
970
expanded_area->hide();
971
972
// Registers UndoRedo inspector callback.
973
EditorNode::get_editor_data().add_move_array_element_function(SNAME("TileSet"), callable_mp(this, &TileSetEditor::_move_tile_set_array_element));
974
EditorNode::get_editor_data().add_undo_redo_inspector_hook_callback(callable_mp(this, &TileSetEditor::_undo_redo_inspector_callback));
975
}
976
977
void TileSourceInspectorPlugin::_show_id_edit_dialog(Object *p_for_source) {
978
if (!id_edit_dialog) {
979
id_edit_dialog = memnew(ConfirmationDialog);
980
TileSetEditor::get_singleton()->add_child(id_edit_dialog);
981
982
VBoxContainer *vbox = memnew(VBoxContainer);
983
id_edit_dialog->add_child(vbox);
984
985
Label *label = memnew(Label(TTR("Warning: Modifying a source ID will result in all TileMaps using that source to reference an invalid source instead. This may result in unexpected data loss. Change this ID carefully.")));
986
label->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
987
// Workaround too tall popup window due to text autowrapping. See GH-83546.
988
label->set_custom_minimum_size(Vector2i(400, 0));
989
vbox->add_child(label);
990
991
id_input = memnew(SpinBox);
992
vbox->add_child(id_input);
993
id_input->set_max(INT_MAX);
994
995
id_edit_dialog->connect(SceneStringName(confirmed), callable_mp(this, &TileSourceInspectorPlugin::_confirm_change_id));
996
}
997
edited_source = p_for_source;
998
id_input->set_value(p_for_source->get("id"));
999
id_edit_dialog->popup_centered(Vector2i(400, 0) * EDSCALE);
1000
callable_mp((Control *)id_input->get_line_edit(), &Control::grab_focus).call_deferred();
1001
}
1002
1003
void TileSourceInspectorPlugin::_confirm_change_id() {
1004
edited_source->set("id", id_input->get_value());
1005
id_label->set_text(itos(edited_source->get("id"))); // Use get(), because the provided ID might've been invalid.
1006
}
1007
1008
bool TileSourceInspectorPlugin::can_handle(Object *p_object) {
1009
return p_object && (p_object->is_class("TileSetAtlasSourceProxyObject") || p_object->is_class("TileSetScenesCollectionProxyObject"));
1010
}
1011
1012
bool TileSourceInspectorPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide) {
1013
if (p_path == "id") {
1014
const Variant value = p_object->get("id");
1015
if (value.get_type() == Variant::NIL) { // May happen if the object is not yet initialized.
1016
return true;
1017
}
1018
1019
EditorProperty *ep = memnew(EditorProperty);
1020
1021
HBoxContainer *hbox = memnew(HBoxContainer);
1022
hbox->set_alignment(BoxContainer::ALIGNMENT_CENTER);
1023
1024
id_label = memnew(Label(itos(value)));
1025
id_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1026
hbox->add_child(id_label);
1027
1028
Button *button = memnew(Button(TTR("Edit")));
1029
button->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1030
hbox->add_child(button);
1031
button->connect(SceneStringName(pressed), callable_mp(this, &TileSourceInspectorPlugin::_show_id_edit_dialog).bind(p_object));
1032
1033
ep->add_child(hbox);
1034
add_property_editor(p_path, ep);
1035
return true;
1036
}
1037
return false;
1038
}
1039
1040