summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-09-21 14:25:08 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-09-21 14:25:08 +0200
commitfb4c0cf4624b1e3e738cf391e20cf2c08d76be9c (patch)
treee156447eab5c269a9cf3962db5b6704401e2d133
parent44ea5f94707b718335cea619207c06ce836d611f (diff)
parent07a00cf82274c6fb96345947a150f32ff6b399db (diff)
downloadredot-engine-fb4c0cf4624b1e3e738cf391e20cf2c08d76be9c.tar.gz
Merge pull request #81971 from KoBeWi/there_is_only_one_scene
Don't allow transforming scene tiles
-rw-r--r--editor/plugins/tiles/tile_map_editor.cpp36
-rw-r--r--editor/plugins/tiles/tile_map_editor.h1
-rw-r--r--scene/resources/tile_set.h1
3 files changed, 28 insertions, 10 deletions
diff --git a/editor/plugins/tiles/tile_map_editor.cpp b/editor/plugins/tiles/tile_map_editor.cpp
index f5f405d576..69b702bf3f 100644
--- a/editor/plugins/tiles/tile_map_editor.cpp
+++ b/editor/plugins/tiles/tile_map_editor.cpp
@@ -107,17 +107,33 @@ void TileMapEditorTilesPlugin::_update_transform_buttons() {
return;
}
- if (tile_set->get_tile_shape() == TileSet::TILE_SHAPE_SQUARE || selection_pattern->get_size() == Vector2i(1, 1)) {
- transform_button_rotate_left->set_disabled(false);
- transform_button_rotate_left->set_tooltip_text("");
- transform_button_rotate_right->set_disabled(false);
- transform_button_rotate_right->set_tooltip_text("");
+ bool has_scene_tile = false;
+ for (const KeyValue<Vector2i, TileMapCell> &E : selection_pattern->get_pattern()) {
+ if (Object::cast_to<TileSetScenesCollectionSource>(tile_set->get_source(E.value.source_id).ptr())) {
+ has_scene_tile = true;
+ break;
+ }
+ }
+
+ if (has_scene_tile) {
+ _set_transform_buttons_state({}, { transform_button_rotate_left, transform_button_rotate_right, transform_button_flip_h, transform_button_flip_v },
+ TTR("Can't transform scene tiles."));
+ } else if (tile_set->get_tile_shape() != TileSet::TILE_SHAPE_SQUARE && selection_pattern->get_size() != Vector2i(1, 1)) {
+ _set_transform_buttons_state({ transform_button_flip_h, transform_button_flip_v }, { transform_button_rotate_left, transform_button_rotate_right },
+ TTR("Can't rotate patterns when using non-square tile grid."));
} else {
- const String tooltip_text = TTR("Can't rotate patterns when using non-square tile grid.");
- transform_button_rotate_left->set_disabled(true);
- transform_button_rotate_left->set_tooltip_text(tooltip_text);
- transform_button_rotate_right->set_disabled(true);
- transform_button_rotate_right->set_tooltip_text(tooltip_text);
+ _set_transform_buttons_state({ transform_button_rotate_left, transform_button_rotate_right, transform_button_flip_h, transform_button_flip_v }, {}, "");
+ }
+}
+
+void TileMapEditorTilesPlugin::_set_transform_buttons_state(const Vector<Button *> &p_enabled_buttons, const Vector<Button *> &p_disabled_buttons, const String &p_why_disabled) {
+ for (Button *button : p_enabled_buttons) {
+ button->set_disabled(false);
+ button->set_tooltip_text("");
+ }
+ for (Button *button : p_disabled_buttons) {
+ button->set_disabled(true);
+ button->set_tooltip_text(p_why_disabled);
}
}
diff --git a/editor/plugins/tiles/tile_map_editor.h b/editor/plugins/tiles/tile_map_editor.h
index 0b3d9813c3..c9a1efe62d 100644
--- a/editor/plugins/tiles/tile_map_editor.h
+++ b/editor/plugins/tiles/tile_map_editor.h
@@ -118,6 +118,7 @@ private:
void _update_toolbar();
void _update_transform_buttons();
+ void _set_transform_buttons_state(const Vector<Button *> &p_enabled_buttons, const Vector<Button *> &p_disabled_buttons, const String &p_why_disabled);
///// Tilemap editing. /////
bool has_mouse = false;
diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h
index d500169843..722d615b09 100644
--- a/scene/resources/tile_set.h
+++ b/scene/resources/tile_set.h
@@ -137,6 +137,7 @@ public:
Vector2i get_cell_atlas_coords(const Vector2i &p_coords) const;
int get_cell_alternative_tile(const Vector2i &p_coords) const;
+ const HashMap<Vector2i, TileMapCell> &get_pattern() const { return pattern; }
TypedArray<Vector2i> get_used_cells() const;
Size2i get_size() const;