Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't allow transforming scene tiles #81971

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions editor/plugins/tiles/tile_map_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions editor/plugins/tiles/tile_map_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class TileMapEditorTilesPlugin : public TileMapSubEditorPlugin {

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;
Expand Down
1 change: 1 addition & 0 deletions scene/resources/tile_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class TileMapPattern : public Resource {
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;
Expand Down