summaryrefslogtreecommitdiff
path: root/editor/plugins/tiles
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins/tiles')
-rw-r--r--editor/plugins/tiles/tile_atlas_view.cpp94
-rw-r--r--editor/plugins/tiles/tile_atlas_view.h4
-rw-r--r--editor/plugins/tiles/tile_data_editors.cpp20
-rw-r--r--editor/plugins/tiles/tile_data_editors.h4
-rw-r--r--editor/plugins/tiles/tile_map_editor.cpp26
-rw-r--r--editor/plugins/tiles/tile_map_editor.h1
-rw-r--r--editor/plugins/tiles/tile_set_atlas_source_editor.cpp92
-rw-r--r--editor/plugins/tiles/tile_set_atlas_source_editor.h6
8 files changed, 153 insertions, 94 deletions
diff --git a/editor/plugins/tiles/tile_atlas_view.cpp b/editor/plugins/tiles/tile_atlas_view.cpp
index f21d5098d3..c064073b77 100644
--- a/editor/plugins/tiles/tile_atlas_view.cpp
+++ b/editor/plugins/tiles/tile_atlas_view.cpp
@@ -97,15 +97,6 @@ Size2i TileAtlasView::_compute_base_tiles_control_size() {
if (texture.is_valid()) {
size = texture->get_size();
}
-
- // Extend the size to all existing tiles.
- Size2i grid_size = tile_set_atlas_source->get_atlas_grid_size();
- for (int i = 0; i < tile_set_atlas_source->get_tiles_count(); i++) {
- Vector2i tile_id = tile_set_atlas_source->get_tile_id(i);
- grid_size = grid_size.max(tile_id + Vector2i(1, 1));
- }
- size = size.max(grid_size * (tile_set_atlas_source->get_texture_region_size() + tile_set_atlas_source->get_separation()) + tile_set_atlas_source->get_margins());
-
return size;
}
@@ -213,43 +204,56 @@ void TileAtlasView::_draw_base_tiles() {
Ref<Texture2D> texture = tile_set_atlas_source->get_texture();
if (texture.is_valid()) {
Vector2i margins = tile_set_atlas_source->get_margins();
+ Vector2i separation = tile_set_atlas_source->get_separation();
Vector2i texture_region_size = tile_set_atlas_source->get_texture_region_size();
-
- // Draw the texture, square by square.
Size2i grid_size = tile_set_atlas_source->get_atlas_grid_size();
+
+ // Draw the texture where there is no tile.
for (int x = 0; x < grid_size.x; x++) {
for (int y = 0; y < grid_size.y; y++) {
Vector2i coords = Vector2i(x, y);
if (tile_set_atlas_source->get_tile_at_coords(coords) == TileSetSource::INVALID_ATLAS_COORDS) {
- Rect2i rect = Rect2i(texture_region_size * coords + margins, texture_region_size);
- base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
+ Rect2i rect = Rect2i((texture_region_size + separation) * coords + margins, texture_region_size + separation);
+ rect = rect.intersection(Rect2i(Vector2(), texture->get_size()));
+ if (rect.size.x > 0 && rect.size.y > 0) {
+ base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
+ base_tiles_draw->draw_rect(rect, Color(0.0, 0.0, 0.0, 0.5));
+ }
}
}
}
// Draw the texture around the grid.
Rect2i rect;
+
// Top.
rect.position = Vector2i();
rect.set_end(Vector2i(texture->get_size().x, margins.y));
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
+ base_tiles_draw->draw_rect(rect, Color(0.0, 0.0, 0.0, 0.5));
+
// Bottom
- int bottom_border = margins.y + (grid_size.y * texture_region_size.y);
+ int bottom_border = margins.y + (grid_size.y * (texture_region_size.y + separation.y));
if (bottom_border < texture->get_size().y) {
rect.position = Vector2i(0, bottom_border);
rect.set_end(texture->get_size());
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
+ base_tiles_draw->draw_rect(rect, Color(0.0, 0.0, 0.0, 0.5));
}
+
// Left
rect.position = Vector2i(0, margins.y);
- rect.set_end(Vector2i(margins.x, margins.y + (grid_size.y * texture_region_size.y)));
+ rect.set_end(Vector2i(margins.x, margins.y + (grid_size.y * (texture_region_size.y + separation.y))));
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
+ base_tiles_draw->draw_rect(rect, Color(0.0, 0.0, 0.0, 0.5));
+
// Right.
- int right_border = margins.x + (grid_size.x * texture_region_size.x);
+ int right_border = margins.x + (grid_size.x * (texture_region_size.x + separation.x));
if (right_border < texture->get_size().x) {
rect.position = Vector2i(right_border, margins.y);
- rect.set_end(Vector2i(texture->get_size().x, margins.y + (grid_size.y * texture_region_size.y)));
+ rect.set_end(Vector2i(texture->get_size().x, margins.y + (grid_size.y * (texture_region_size.y + separation.y))));
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
+ base_tiles_draw->draw_rect(rect, Color(0.0, 0.0, 0.0, 0.5));
}
// Draw actual tiles, using their properties (modulation, etc...)
@@ -258,12 +262,30 @@ void TileAtlasView::_draw_base_tiles() {
for (int frame = 0; frame < tile_set_atlas_source->get_tile_animation_frames_count(atlas_coords); frame++) {
// Update the y to max value.
- int animation_columns = tile_set_atlas_source->get_tile_animation_columns(atlas_coords);
- Vector2i frame_coords = atlas_coords + (tile_set_atlas_source->get_tile_size_in_atlas(atlas_coords) + tile_set_atlas_source->get_tile_animation_separation(atlas_coords)) * ((animation_columns > 0) ? Vector2i(frame % animation_columns, frame / animation_columns) : Vector2i(frame, 0));
- Vector2i offset_pos = (margins + (frame_coords * texture_region_size) + tile_set_atlas_source->get_tile_texture_region(atlas_coords, frame).size / 2 + tile_set_atlas_source->get_tile_effective_texture_offset(atlas_coords, 0));
+ Rect2i base_frame_rect = tile_set_atlas_source->get_tile_texture_region(atlas_coords, frame);
+ Vector2i offset_pos = base_frame_rect.get_center() + tile_set_atlas_source->get_tile_effective_texture_offset(atlas_coords, 0);
// Draw the tile.
TileMap::draw_tile(base_tiles_draw->get_canvas_item(), offset_pos, tile_set, source_id, atlas_coords, 0, frame);
+
+ // Draw, the texture in the separation areas
+ if (separation.x > 0) {
+ Rect2i right_sep_rect = Rect2i(base_frame_rect.get_position() + Vector2i(base_frame_rect.size.x, 0), Vector2i(separation.x, base_frame_rect.size.y));
+ right_sep_rect = right_sep_rect.intersection(Rect2i(Vector2(), texture->get_size()));
+ if (right_sep_rect.size.x > 0 && right_sep_rect.size.y > 0) {
+ base_tiles_draw->draw_texture_rect_region(texture, right_sep_rect, right_sep_rect);
+ base_tiles_draw->draw_rect(right_sep_rect, Color(0.0, 0.0, 0.0, 0.5));
+ }
+ }
+
+ if (separation.y > 0) {
+ Rect2i bottom_sep_rect = Rect2i(base_frame_rect.get_position() + Vector2i(0, base_frame_rect.size.y), Vector2i(base_frame_rect.size.x + separation.x, separation.y));
+ bottom_sep_rect = bottom_sep_rect.intersection(Rect2i(Vector2(), texture->get_size()));
+ if (bottom_sep_rect.size.x > 0 && bottom_sep_rect.size.y > 0) {
+ base_tiles_draw->draw_texture_rect_region(texture, bottom_sep_rect, bottom_sep_rect);
+ base_tiles_draw->draw_rect(bottom_sep_rect, Color(0.0, 0.0, 0.0, 0.5));
+ }
+ }
}
}
}
@@ -299,30 +321,6 @@ void TileAtlasView::_draw_base_tiles_texture_grid() {
}
}
-void TileAtlasView::_draw_base_tiles_dark() {
- Ref<Texture2D> texture = tile_set_atlas_source->get_texture();
- if (texture.is_valid()) {
- Vector2i margins = tile_set_atlas_source->get_margins();
- Vector2i separation = tile_set_atlas_source->get_separation();
- Vector2i texture_region_size = tile_set_atlas_source->get_texture_region_size();
-
- Size2i grid_size = tile_set_atlas_source->get_atlas_grid_size();
-
- // Draw each tile texture region.
- for (int x = 0; x < grid_size.x; x++) {
- for (int y = 0; y < grid_size.y; y++) {
- Vector2i origin = margins + (Vector2i(x, y) * (texture_region_size + separation));
- Vector2i base_tile_coords = tile_set_atlas_source->get_tile_at_coords(Vector2i(x, y));
-
- if (base_tile_coords == TileSetSource::INVALID_ATLAS_COORDS) {
- // Draw the grid.
- base_tiles_dark->draw_rect(Rect2i(origin, texture_region_size), Color(0.0, 0.0, 0.0, 0.5), true);
- }
- }
- }
- }
-}
-
void TileAtlasView::_draw_base_tiles_shape_grid() {
// Draw the shapes.
Color grid_color = EditorSettings::get_singleton()->get("editors/tiles_editor/grid_color");
@@ -453,7 +451,6 @@ void TileAtlasView::set_atlas_source(TileSet *p_tile_set, TileSetAtlasSource *p_
base_tiles_draw->update();
base_tiles_texture_grid->update();
base_tiles_shape_grid->update();
- base_tiles_dark->update();
alternatives_draw->update();
background_left->update();
background_right->update();
@@ -544,7 +541,6 @@ void TileAtlasView::update() {
base_tiles_draw->update();
base_tiles_texture_grid->update();
base_tiles_shape_grid->update();
- base_tiles_dark->update();
alternatives_draw->update();
background_left->update();
background_right->update();
@@ -660,12 +656,6 @@ TileAtlasView::TileAtlasView() {
base_tiles_shape_grid->connect("draw", callable_mp(this, &TileAtlasView::_draw_base_tiles_shape_grid));
base_tiles_drawing_root->add_child(base_tiles_shape_grid);
- base_tiles_dark = memnew(Control);
- base_tiles_dark->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
- base_tiles_dark->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
- base_tiles_dark->connect("draw", callable_mp(this, &TileAtlasView::_draw_base_tiles_dark));
- base_tiles_drawing_root->add_child(base_tiles_dark);
-
// Alternative tiles.
Label *alternative_tiles_label = memnew(Label);
alternative_tiles_label->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
diff --git a/editor/plugins/tiles/tile_atlas_view.h b/editor/plugins/tiles/tile_atlas_view.h
index 5b0df366ae..e1ca3eebee 100644
--- a/editor/plugins/tiles/tile_atlas_view.h
+++ b/editor/plugins/tiles/tile_atlas_view.h
@@ -93,9 +93,6 @@ private:
Control *base_tiles_shape_grid;
void _draw_base_tiles_shape_grid();
- Control *base_tiles_dark;
- void _draw_base_tiles_dark();
-
Size2i _compute_base_tiles_control_size();
// Right side.
@@ -124,7 +121,6 @@ public:
// Left side.
void set_texture_grid_visible(bool p_visible) { base_tiles_texture_grid->set_visible(p_visible); };
- void set_dark_visible(bool p_visible) { base_tiles_dark->set_visible(p_visible); };
void set_tile_shape_grid_visible(bool p_visible) { base_tiles_shape_grid->set_visible(p_visible); };
Vector2i get_atlas_tile_coords_at_pos(const Vector2 p_pos) const;
diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp
index 1a69d19d3c..104f46f773 100644
--- a/editor/plugins/tiles/tile_data_editors.cpp
+++ b/editor/plugins/tiles/tile_data_editors.cpp
@@ -38,8 +38,16 @@
#include "editor/editor_properties.h"
#include "editor/editor_scale.h"
-void TileDataEditor::_call_tile_set_changed() {
- _tile_set_changed();
+void TileDataEditor::_tile_set_changed_plan_update() {
+ _tile_set_changed_update_needed = true;
+ call_deferred("_tile_set_changed_deferred_update");
+}
+
+void TileDataEditor::_tile_set_changed_deferred_update() {
+ if (_tile_set_changed_update_needed) {
+ _tile_set_changed();
+ _tile_set_changed_update_needed = false;
+ }
}
TileData *TileDataEditor::_get_tile_data(TileMapCell p_cell) {
@@ -59,18 +67,20 @@ TileData *TileDataEditor::_get_tile_data(TileMapCell p_cell) {
}
void TileDataEditor::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("_tile_set_changed_deferred_update"), &TileDataEditor::_tile_set_changed_deferred_update);
+
ADD_SIGNAL(MethodInfo("needs_redraw"));
}
void TileDataEditor::set_tile_set(Ref<TileSet> p_tile_set) {
if (tile_set.is_valid()) {
- tile_set->disconnect("changed", callable_mp(this, &TileDataEditor::_call_tile_set_changed));
+ tile_set->disconnect("changed", callable_mp(this, &TileDataEditor::_tile_set_changed_plan_update));
}
tile_set = p_tile_set;
if (tile_set.is_valid()) {
- tile_set->connect("changed", callable_mp(this, &TileDataEditor::_call_tile_set_changed));
+ tile_set->connect("changed", callable_mp(this, &TileDataEditor::_tile_set_changed_plan_update));
}
- _call_tile_set_changed();
+ _tile_set_changed_plan_update();
}
bool DummyObject::_set(const StringName &p_name, const Variant &p_value) {
diff --git a/editor/plugins/tiles/tile_data_editors.h b/editor/plugins/tiles/tile_data_editors.h
index 99998dc779..acb4c5882d 100644
--- a/editor/plugins/tiles/tile_data_editors.h
+++ b/editor/plugins/tiles/tile_data_editors.h
@@ -45,7 +45,9 @@ class TileDataEditor : public VBoxContainer {
GDCLASS(TileDataEditor, VBoxContainer);
private:
- void _call_tile_set_changed();
+ bool _tile_set_changed_update_needed = false;
+ void _tile_set_changed_plan_update();
+ void _tile_set_changed_deferred_update();
protected:
Ref<TileSet> tile_set;
diff --git a/editor/plugins/tiles/tile_map_editor.cpp b/editor/plugins/tiles/tile_map_editor.cpp
index cc5ff90541..c2e86f8b43 100644
--- a/editor/plugins/tiles/tile_map_editor.cpp
+++ b/editor/plugins/tiles/tile_map_editor.cpp
@@ -465,6 +465,7 @@ bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p
}
tile_map->set_cell(tile_map_layer, coords, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
}
+ _fix_invalid_tiles_in_tile_map_selection();
} break;
case DRAG_TYPE_BUCKET: {
Vector<Vector2i> line = TileMapEditor::get_line(tile_map, tile_map->world_to_map(drag_last_mouse_pos), tile_map->world_to_map(mpos));
@@ -483,6 +484,7 @@ bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p
}
}
}
+ _fix_invalid_tiles_in_tile_map_selection();
} break;
default:
break;
@@ -508,6 +510,7 @@ bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p
drag_start_mouse_pos = mpos;
if (tile_map_selection.has(tile_map->world_to_map(drag_start_mouse_pos)) && !mb->is_shift_pressed()) {
// Move the selection
+ _update_selection_pattern_from_tilemap_selection(); // Make sure the pattern is up to date before moving.
drag_type = DRAG_TYPE_MOVE;
drag_modified.clear();
for (Set<Vector2i>::Element *E = tile_map_selection.front(); E; E = E->next()) {
@@ -541,6 +544,7 @@ bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p
}
tile_map->set_cell(tile_map_layer, coords, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
}
+ _fix_invalid_tiles_in_tile_map_selection();
} else if (tool_buttons_group->get_pressed_button() == line_tool_button) {
drag_type = DRAG_TYPE_LINE;
drag_start_mouse_pos = mpos;
@@ -569,6 +573,7 @@ bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p
}
}
}
+ _fix_invalid_tiles_in_tile_map_selection();
}
}
}
@@ -1323,6 +1328,25 @@ void TileMapEditorTilesPlugin::_update_fix_selected_and_hovered() {
}
}
+void TileMapEditorTilesPlugin::_fix_invalid_tiles_in_tile_map_selection() {
+ TileMap *tile_map = Object::cast_to<TileMap>(ObjectDB::get_instance(tile_map_id));
+ if (!tile_map) {
+ return;
+ }
+
+ Set<Vector2i> to_remove;
+ for (Vector2i selected : tile_map_selection) {
+ TileMapCell cell = tile_map->get_cell(tile_map_layer, selected);
+ if (cell.source_id == TileSet::INVALID_SOURCE && cell.get_atlas_coords() == TileSetSource::INVALID_ATLAS_COORDS && cell.alternative_tile == TileSetAtlasSource::INVALID_TILE_ALTERNATIVE) {
+ to_remove.insert(selected);
+ }
+ }
+
+ for (Vector2i cell : to_remove) {
+ tile_map_selection.erase(cell);
+ }
+}
+
void TileMapEditorTilesPlugin::_update_selection_pattern_from_tilemap_selection() {
TileMap *tile_map = Object::cast_to<TileMap>(ObjectDB::get_instance(tile_map_id));
if (!tile_map) {
@@ -1423,6 +1447,8 @@ void TileMapEditorTilesPlugin::_update_tileset_selection_from_selection_pattern(
}
}
_update_bottom_panel();
+ tile_atlas_control->update();
+ alternative_tiles_control->update();
}
void TileMapEditorTilesPlugin::_tile_atlas_control_draw() {
diff --git a/editor/plugins/tiles/tile_map_editor.h b/editor/plugins/tiles/tile_map_editor.h
index 6126db59e9..a1ab3db318 100644
--- a/editor/plugins/tiles/tile_map_editor.h
+++ b/editor/plugins/tiles/tile_map_editor.h
@@ -124,6 +124,7 @@ private:
void _update_selection_pattern_from_tileset_selection();
void _update_tileset_selection_from_selection_pattern();
void _update_fix_selected_and_hovered();
+ void _fix_invalid_tiles_in_tile_map_selection();
///// Bottom panel. ////.
Label *missing_source_label;
diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp
index 3fbd315aec..c43a854d9a 100644
--- a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp
+++ b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp
@@ -520,9 +520,6 @@ void TileSetAtlasSourceEditor::_update_tile_id_label() {
void TileSetAtlasSourceEditor::_update_source_inspector() {
// Update the proxy object.
atlas_source_proxy_object->edit(tile_set, tile_set_atlas_source, tile_set_atlas_source_id);
-
- // Update the "clear outside texture" button.
- tool_advanced_menu_buttom->get_popup()->set_item_disabled(0, !tile_set_atlas_source->has_tiles_outside_texture());
}
void TileSetAtlasSourceEditor::_update_fix_selected_and_hovered_tiles() {
@@ -763,7 +760,11 @@ void TileSetAtlasSourceEditor::_update_tile_data_editors() {
// Update visibility.
bool is_visible = tools_button_group->get_pressed_button() == tool_paint_button;
tile_data_editor_dropdown_button->set_visible(is_visible);
- tile_data_editor_dropdown_button->set_text(TTR("Select a property editor"));
+ if (tile_data_editors_tree->get_selected()) {
+ tile_data_editor_dropdown_button->set_text(tile_data_editors_tree->get_selected()->get_text(0));
+ } else {
+ tile_data_editor_dropdown_button->set_text(TTR("Select a property editor"));
+ }
tile_data_editors_label->set_visible(is_visible);
}
@@ -959,7 +960,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
current_tile_data_editor->forward_painting_atlas_gui_input(tile_atlas_view, tile_set_atlas_source, p_event);
}
// Update only what's needed.
- tile_set_atlas_source_changed_needs_update = false;
+ tile_set_changed_needs_update = false;
tile_atlas_control->update();
tile_atlas_control_unscaled->update();
@@ -1061,7 +1062,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
drag_current_tile = coords;
// Update only what's needed.
- tile_set_atlas_source_changed_needs_update = false;
+ tile_set_changed_needs_update = false;
_update_tile_inspector();
_update_atlas_view();
_update_tile_id_label();
@@ -1101,7 +1102,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
drag_current_tile = new_rect.position;
// Update only what's needed.
- tile_set_atlas_source_changed_needs_update = false;
+ tile_set_changed_needs_update = false;
_update_tile_inspector();
_update_atlas_view();
_update_tile_id_label();
@@ -1600,9 +1601,6 @@ void TileSetAtlasSourceEditor::_menu_option(int p_option) {
undo_redo->commit_action();
_update_tile_id_label();
} break;
- case ADVANCED_CLEANUP_TILES_OUTSIDE_TEXTURE: {
- tile_set_atlas_source->clear_tiles_outside_texture();
- } break;
case ADVANCED_AUTO_CREATE_TILES: {
_auto_create_tiles();
} break;
@@ -2012,12 +2010,12 @@ void TileSetAtlasSourceEditor::_tile_alternatives_control_unscaled_draw() {
}
}
-void TileSetAtlasSourceEditor::_tile_set_atlas_source_changed() {
- tile_set_atlas_source_changed_needs_update = true;
+void TileSetAtlasSourceEditor::_tile_set_changed() {
+ tile_set_changed_needs_update = true;
}
void TileSetAtlasSourceEditor::_tile_proxy_object_changed(String p_what) {
- tile_set_atlas_source_changed_needs_update = false; // Avoid updating too many things.
+ tile_set_changed_needs_update = false; // Avoid updating too many things.
_update_atlas_view();
}
@@ -2035,30 +2033,66 @@ void TileSetAtlasSourceEditor::_undo_redo_inspector_callback(Object *p_undo_redo
#define ADD_UNDO(obj, property) undo_redo->add_undo_property(obj, property, obj->get(property));
- AtlasTileProxyObject *tile_data = Object::cast_to<AtlasTileProxyObject>(p_edited);
- if (tile_data) {
+ undo_redo->start_force_keep_in_merge_ends();
+ AtlasTileProxyObject *tile_data_proxy = Object::cast_to<AtlasTileProxyObject>(p_edited);
+ if (tile_data_proxy) {
Vector<String> components = String(p_property).split("/", true, 2);
if (components.size() == 2 && components[1] == "polygons_count") {
int layer_index = components[0].trim_prefix("physics_layer_").to_int();
int new_polygons_count = p_new_value;
- int old_polygons_count = tile_data->get(vformat("physics_layer_%d/polygons_count", layer_index));
+ int old_polygons_count = tile_data_proxy->get(vformat("physics_layer_%d/polygons_count", layer_index));
if (new_polygons_count < old_polygons_count) {
for (int i = new_polygons_count - 1; i < old_polygons_count; i++) {
- ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/points", layer_index, i));
- ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/one_way", layer_index, i));
- ADD_UNDO(tile_data, vformat("physics_layer_%d/polygon_%d/one_way_margin", layer_index, i));
+ ADD_UNDO(tile_data_proxy, vformat("physics_layer_%d/polygon_%d/points", layer_index, i));
+ ADD_UNDO(tile_data_proxy, vformat("physics_layer_%d/polygon_%d/one_way", layer_index, i));
+ ADD_UNDO(tile_data_proxy, vformat("physics_layer_%d/polygon_%d/one_way_margin", layer_index, i));
}
}
} else if (p_property == "terrain_set") {
- int current_terrain_set = tile_data->get("terrain_set");
+ int current_terrain_set = tile_data_proxy->get("terrain_set");
for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
TileSet::CellNeighbor bit = TileSet::CellNeighbor(i);
if (tile_set->is_valid_peering_bit_terrain(current_terrain_set, bit)) {
- ADD_UNDO(tile_data, "terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]));
+ ADD_UNDO(tile_data_proxy, "terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]));
}
}
}
}
+
+ TileSetAtlasSourceProxyObject *atlas_source_proxy = Object::cast_to<TileSetAtlasSourceProxyObject>(p_edited);
+ if (atlas_source_proxy) {
+ TileSetAtlasSource *atlas_source = atlas_source_proxy->get_edited();
+ ERR_FAIL_COND(!atlas_source);
+
+ PackedVector2Array arr;
+ if (p_property == "texture") {
+ arr = atlas_source->get_tiles_to_be_removed_on_change(p_new_value, atlas_source->get_margins(), atlas_source->get_separation(), atlas_source->get_texture_region_size());
+ } else if (p_property == "margins") {
+ arr = atlas_source->get_tiles_to_be_removed_on_change(atlas_source->get_texture(), p_new_value, atlas_source->get_separation(), atlas_source->get_texture_region_size());
+ } else if (p_property == "separation") {
+ arr = atlas_source->get_tiles_to_be_removed_on_change(atlas_source->get_texture(), atlas_source->get_margins(), p_new_value, atlas_source->get_texture_region_size());
+ } else if (p_property == "texture_region_size") {
+ arr = atlas_source->get_tiles_to_be_removed_on_change(atlas_source->get_texture(), atlas_source->get_margins(), atlas_source->get_separation(), p_new_value);
+ }
+
+ if (!arr.is_empty()) {
+ // Get all properties assigned to a tile.
+ List<PropertyInfo> properties;
+ atlas_source->get_property_list(&properties);
+
+ for (int i = 0; i < arr.size(); i++) {
+ Vector2i coords = arr[i];
+ String prefix = vformat("%d:%d/", coords.x, coords.y);
+ for (PropertyInfo pi : properties) {
+ if (pi.name.begins_with(prefix)) {
+ ADD_UNDO(atlas_source, pi.name);
+ }
+ }
+ }
+ }
+ }
+ undo_redo->end_force_keep_in_merge_ends();
+
#undef ADD_UNDO
}
@@ -2073,8 +2107,8 @@ void TileSetAtlasSourceEditor::edit(Ref<TileSet> p_tile_set, TileSetAtlasSource
}
// Remove listener for old objects.
- if (tile_set_atlas_source) {
- tile_set_atlas_source->disconnect("changed", callable_mp(this, &TileSetAtlasSourceEditor::_tile_set_atlas_source_changed));
+ if (tile_set.is_valid()) {
+ tile_set->disconnect("changed", callable_mp(this, &TileSetAtlasSourceEditor::_tile_set_changed));
}
// Clear the selection.
@@ -2086,8 +2120,8 @@ void TileSetAtlasSourceEditor::edit(Ref<TileSet> p_tile_set, TileSetAtlasSource
tile_set_atlas_source_id = p_source_id;
// Add the listener again.
- if (tile_set_atlas_source) {
- tile_set_atlas_source->connect("changed", callable_mp(this, &TileSetAtlasSourceEditor::_tile_set_atlas_source_changed));
+ if (tile_set.is_valid()) {
+ tile_set->connect("changed", callable_mp(this, &TileSetAtlasSourceEditor::_tile_set_changed));
}
// Update everything.
@@ -2228,7 +2262,7 @@ void TileSetAtlasSourceEditor::_notification(int p_what) {
resize_handle_disabled = get_theme_icon(SNAME("EditorHandleDisabled"), SNAME("EditorIcons"));
break;
case NOTIFICATION_INTERNAL_PROCESS:
- if (tile_set_atlas_source_changed_needs_update) {
+ if (tile_set_changed_needs_update) {
// Update everything.
_update_source_inspector();
@@ -2241,7 +2275,7 @@ void TileSetAtlasSourceEditor::_notification(int p_what) {
_update_tile_data_editors();
_update_current_tile_data_editor();
- tile_set_atlas_source_changed_needs_update = false;
+ tile_set_changed_needs_update = false;
}
break;
default:
@@ -2406,8 +2440,6 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() {
tool_advanced_menu_buttom = memnew(MenuButton);
tool_advanced_menu_buttom->set_flat(true);
- tool_advanced_menu_buttom->get_popup()->add_item(TTR("Cleanup Tiles Outside Texture"), ADVANCED_CLEANUP_TILES_OUTSIDE_TEXTURE);
- tool_advanced_menu_buttom->get_popup()->set_item_disabled(0, true);
tool_advanced_menu_buttom->get_popup()->add_item(TTR("Create Tiles in Non-Transparent Texture Regions"), ADVANCED_AUTO_CREATE_TILES);
tool_advanced_menu_buttom->get_popup()->add_item(TTR("Remove Tiles in Fully Transparent Texture Regions"), ADVANCED_AUTO_REMOVE_TILES);
tool_advanced_menu_buttom->get_popup()->connect("id_pressed", callable_mp(this, &TileSetAtlasSourceEditor::_menu_option));
@@ -2481,6 +2513,8 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() {
tile_atlas_view_missing_source_label->set_v_size_flags(SIZE_EXPAND_FILL);
tile_atlas_view_missing_source_label->hide();
right_panel->add_child(tile_atlas_view_missing_source_label);
+
+ EditorNode::get_singleton()->get_editor_data().add_undo_redo_inspector_hook_callback(callable_mp(this, &TileSetAtlasSourceEditor::_undo_redo_inspector_callback));
}
TileSetAtlasSourceEditor::~TileSetAtlasSourceEditor() {
diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.h b/editor/plugins/tiles/tile_set_atlas_source_editor.h
index 6448b55feb..ea6f2847ae 100644
--- a/editor/plugins/tiles/tile_set_atlas_source_editor.h
+++ b/editor/plugins/tiles/tile_set_atlas_source_editor.h
@@ -78,6 +78,7 @@ private:
int get_id();
void edit(Ref<TileSet> p_tile_set, TileSetAtlasSource *p_tile_set_atlas_source, int p_source_id);
+ TileSetAtlasSource *get_edited() { return tile_set_atlas_source; };
};
// -- Proxy object for a tile, needed by the inspector --
@@ -112,7 +113,7 @@ private:
UndoRedo *undo_redo = EditorNode::get_undo_redo();
- bool tile_set_atlas_source_changed_needs_update = false;
+ bool tile_set_changed_needs_update = false;
// -- Properties painting --
VBoxContainer *tile_data_painting_editor_container;
@@ -189,7 +190,6 @@ private:
TILE_CREATE_ALTERNATIVE,
TILE_DELETE,
- ADVANCED_CLEANUP_TILES_OUTSIDE_TEXTURE,
ADVANCED_AUTO_CREATE_TILES,
ADVANCED_AUTO_REMOVE_TILES,
};
@@ -263,7 +263,7 @@ private:
void _auto_remove_tiles();
AcceptDialog *confirm_auto_create_tiles;
- void _tile_set_atlas_source_changed();
+ void _tile_set_changed();
void _tile_proxy_object_changed(String p_what);
void _atlas_source_proxy_object_changed(String p_what);