diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-11-17 13:49:02 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-11-17 13:49:02 +0100 |
commit | 2ca972ad01e8000aff639c691abce325f1ac01cf (patch) | |
tree | 67851e46f6727ff834c4baccea45c09fc313b72f /editor/plugins/tiles | |
parent | 4829911df27ad6673bf0a62dd8dfd91ead46d627 (diff) | |
parent | b6c1a03d6ce02df531fea663256e99daa756d439 (diff) |
Merge pull request #66557 from MisterMX/fix/tileset-custom-data-type-reload-editor
fix(tileset): Recreate custom data editor if type has changed
Diffstat (limited to 'editor/plugins/tiles')
-rw-r--r-- | editor/plugins/tiles/tile_data_editors.cpp | 5 | ||||
-rw-r--r-- | editor/plugins/tiles/tile_data_editors.h | 2 | ||||
-rw-r--r-- | editor/plugins/tiles/tile_set_atlas_source_editor.cpp | 23 |
3 files changed, 24 insertions, 6 deletions
diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp index a7d90856ac..ce176e3a99 100644 --- a/editor/plugins/tiles/tile_data_editors.cpp +++ b/editor/plugins/tiles/tile_data_editors.cpp @@ -1138,6 +1138,7 @@ void TileDataDefaultEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2 void TileDataDefaultEditor::setup_property_editor(Variant::Type p_type, String p_property, String p_label, Variant p_default_value) { ERR_FAIL_COND_MSG(!property.is_empty(), "Cannot setup TileDataDefaultEditor twice"); property = p_property; + property_type = p_type; // Update everything. if (property_editor) { @@ -1182,6 +1183,10 @@ void TileDataDefaultEditor::_notification(int p_what) { } } +Variant::Type TileDataDefaultEditor::get_property_type() { + return property_type; +} + TileDataDefaultEditor::TileDataDefaultEditor() { undo_redo = EditorNode::get_undo_redo(); diff --git a/editor/plugins/tiles/tile_data_editors.h b/editor/plugins/tiles/tile_data_editors.h index c1560138b2..0a947fce8b 100644 --- a/editor/plugins/tiles/tile_data_editors.h +++ b/editor/plugins/tiles/tile_data_editors.h @@ -220,6 +220,7 @@ protected: StringName type; String property; + Variant::Type property_type; void _notification(int p_what); virtual Variant _get_painted_value(); @@ -237,6 +238,7 @@ public: virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileMapCell p_cell, bool p_selected = false) override; void setup_property_editor(Variant::Type p_type, String p_property, String p_label = "", Variant p_default_value = Variant()); + Variant::Type get_property_type(); TileDataDefaultEditor(); ~TileDataDefaultEditor(); diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp index ab54a093f2..d425862694 100644 --- a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp +++ b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp @@ -737,18 +737,29 @@ void TileSetAtlasSourceEditor::_update_tile_data_editors() { // --- Custom Data --- ADD_TILE_DATA_EDITOR_GROUP("Custom Data"); for (int i = 0; i < tile_set->get_custom_data_layers_count(); i++) { - if (tile_set->get_custom_data_layer_name(i).is_empty()) { - ADD_TILE_DATA_EDITOR(group, vformat("Custom Data %d", i), vformat("custom_data_%d", i)); + String editor_name = vformat("custom_data_%d", i); + String prop_name = tile_set->get_custom_data_layer_name(i); + Variant::Type prop_type = tile_set->get_custom_data_layer_type(i); + + if (prop_name.is_empty()) { + ADD_TILE_DATA_EDITOR(group, vformat("Custom Data %d", i), editor_name); } else { - ADD_TILE_DATA_EDITOR(group, tile_set->get_custom_data_layer_name(i), vformat("custom_data_%d", i)); + ADD_TILE_DATA_EDITOR(group, prop_name, editor_name); + } + + // If the type of the edited property has been changed, delete the + // editor and create a new one. + if (tile_data_editors.has(editor_name) && ((TileDataDefaultEditor *)tile_data_editors[editor_name])->get_property_type() != prop_type) { + tile_data_editors[vformat("custom_data_%d", i)]->queue_delete(); + tile_data_editors.erase(vformat("custom_data_%d", i)); } - if (!tile_data_editors.has(vformat("custom_data_%d", i))) { + if (!tile_data_editors.has(editor_name)) { TileDataDefaultEditor *tile_data_custom_data_editor = memnew(TileDataDefaultEditor()); tile_data_custom_data_editor->hide(); - tile_data_custom_data_editor->setup_property_editor(tile_set->get_custom_data_layer_type(i), vformat("custom_data_%d", i), tile_set->get_custom_data_layer_name(i)); + tile_data_custom_data_editor->setup_property_editor(prop_type, editor_name, prop_name); tile_data_custom_data_editor->connect("needs_redraw", callable_mp((CanvasItem *)tile_atlas_control_unscaled, &Control::queue_redraw)); tile_data_custom_data_editor->connect("needs_redraw", callable_mp((CanvasItem *)alternative_tiles_control_unscaled, &Control::queue_redraw)); - tile_data_editors[vformat("custom_data_%d", i)] = tile_data_custom_data_editor; + tile_data_editors[editor_name] = tile_data_custom_data_editor; } } for (int i = tile_set->get_custom_data_layers_count(); tile_data_editors.has(vformat("custom_data_%d", i)); i++) { |