Skip to content

Commit

Permalink
Merge pull request #48812 from groud/tilemap_scenes_painting
Browse files Browse the repository at this point in the history
Implement scenes tiles in TileMaps
  • Loading branch information
akien-mga authored May 20, 2021
2 parents 342f3ef + d8bb53c commit a6a75e2
Show file tree
Hide file tree
Showing 17 changed files with 1,763 additions and 283 deletions.
2 changes: 1 addition & 1 deletion doc/classes/TileSet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<method name="add_source">
<return type="int">
</return>
<argument index="0" name="atlas_source_id_override" type="TileSetAtlasSource">
<argument index="0" name="atlas_source_id_override" type="TileSetSource">
</argument>
<argument index="1" name="arg1" type="int" default="-1">
</argument>
Expand Down
155 changes: 155 additions & 0 deletions doc/classes/TileSetScenesCollectionSource.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="TileSetScenesCollectionSource" inherits="TileSetSource" version="4.0">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
<method name="create_scene_tile">
<return type="int">
</return>
<argument index="0" name="packed_scene" type="PackedScene">
</argument>
<argument index="1" name="id_override" type="int" default="-1">
</argument>
<description>
</description>
</method>
<method name="get_alternative_tile_id" qualifiers="const">
<return type="int">
</return>
<argument index="0" name="atlas_coords" type="Vector2i">
</argument>
<argument index="1" name="index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_alternative_tiles_count" qualifiers="const">
<return type="int">
</return>
<argument index="0" name="atlas_coords" type="Vector2i">
</argument>
<description>
</description>
</method>
<method name="get_next_scene_tile_id" qualifiers="const">
<return type="int">
</return>
<description>
</description>
</method>
<method name="get_scene_tile_display_placeholder" qualifiers="const">
<return type="bool">
</return>
<argument index="0" name="id" type="int">
</argument>
<description>
</description>
</method>
<method name="get_scene_tile_id">
<return type="int">
</return>
<argument index="0" name="index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_scene_tile_scene" qualifiers="const">
<return type="PackedScene">
</return>
<argument index="0" name="id" type="int">
</argument>
<description>
</description>
</method>
<method name="get_scene_tiles_count">
<return type="int">
</return>
<description>
</description>
</method>
<method name="get_tile_id" qualifiers="const">
<return type="Vector2i">
</return>
<argument index="0" name="index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_tiles_count" qualifiers="const">
<return type="int">
</return>
<description>
</description>
</method>
<method name="has_alternative_tile" qualifiers="const">
<return type="bool">
</return>
<argument index="0" name="atlas_coords" type="Vector2i">
</argument>
<argument index="1" name="alternative_tile" type="int">
</argument>
<description>
</description>
</method>
<method name="has_scene_tile_id">
<return type="bool">
</return>
<argument index="0" name="id" type="int">
</argument>
<description>
</description>
</method>
<method name="has_tile" qualifiers="const">
<return type="bool">
</return>
<argument index="0" name="atlas_coords" type="Vector2i">
</argument>
<description>
</description>
</method>
<method name="remove_scene_tile">
<return type="void">
</return>
<argument index="0" name="id" type="int">
</argument>
<description>
</description>
</method>
<method name="set_scene_tile_display_placeholder">
<return type="void">
</return>
<argument index="0" name="id" type="int">
</argument>
<argument index="1" name="display_placeholder" type="bool">
</argument>
<description>
</description>
</method>
<method name="set_scene_tile_id">
<return type="void">
</return>
<argument index="0" name="id" type="int">
</argument>
<argument index="1" name="new_id" type="int">
</argument>
<description>
</description>
</method>
<method name="set_scene_tile_scene">
<return type="void">
</return>
<argument index="0" name="id" type="int">
</argument>
<argument index="1" name="packed_scene" type="PackedScene">
</argument>
<description>
</description>
</method>
</methods>
<constants>
</constants>
</class>
38 changes: 22 additions & 16 deletions editor/plugins/tiles/tile_atlas_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ void TileAtlasView::_base_tiles_root_control_gui_input(const Ref<InputEvent> &p_
if (mm.is_valid()) {
Transform2D xform = base_tiles_drawing_root->get_transform().affine_inverse();
Vector2i coords = get_atlas_tile_coords_at_pos(xform.xform(mm->get_position()));
if (coords != TileSetAtlasSource::INVALID_ATLAS_COORDS) {
if (coords != TileSetSource::INVALID_ATLAS_COORDS) {
coords = tile_set_atlas_source->get_tile_at_coords(coords);
if (coords != TileSetAtlasSource::INVALID_ATLAS_COORDS) {
if (coords != TileSetSource::INVALID_ATLAS_COORDS) {
base_tiles_root_control->set_tooltip(vformat(TTR("Source: %d\nAtlas coordinates: %s\nAlternative: 0"), source_id, coords));
}
}
Expand All @@ -215,7 +215,7 @@ void TileAtlasView::_draw_base_tiles() {
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) == TileSetAtlasSource::INVALID_ATLAS_COORDS) {
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);
}
Expand All @@ -229,17 +229,23 @@ void TileAtlasView::_draw_base_tiles() {
rect.set_end(Vector2i(texture->get_size().x, margins.y));
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
// Bottom
rect.position = Vector2i(0, margins.y + (grid_size.y * texture_region_size.y));
rect.set_end(texture->get_size());
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
int bottom_border = margins.y + (grid_size.y * texture_region_size.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);
}
// Left
rect.position = Vector2i(0, margins.y);
rect.set_end(Vector2i(margins.x, margins.y + (grid_size.y * texture_region_size.y)));
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
// Right.
rect.position = Vector2i(margins.x + (grid_size.x * texture_region_size.x), margins.y);
rect.set_end(Vector2i(texture->get_size().x, margins.y + (grid_size.y * texture_region_size.y)));
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
int right_border = margins.x + (grid_size.x * texture_region_size.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)));
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
}

// Draw actual tiles, using their properties (modulation, etc...)
for (int i = 0; i < tile_set_atlas_source->get_tiles_count(); i++) {
Expand All @@ -249,7 +255,7 @@ void TileAtlasView::_draw_base_tiles() {
Vector2i offset_pos = (margins + (atlas_coords * texture_region_size) + tile_set_atlas_source->get_tile_texture_region(atlas_coords).size / 2 + tile_set_atlas_source->get_tile_effective_texture_offset(atlas_coords, 0));

// Draw the tile.
TileSetAtlasPluginRendering::draw_tile(base_tiles_draw->get_canvas_item(), offset_pos, tile_set, source_id, atlas_coords, 0);
TileSetPluginAtlasRendering::draw_tile(base_tiles_draw->get_canvas_item(), offset_pos, tile_set, source_id, atlas_coords, 0);
}
}
}
Expand All @@ -268,7 +274,7 @@ void TileAtlasView::_draw_base_tiles_texture_grid() {
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 != TileSetAtlasSource::INVALID_ATLAS_COORDS) {
if (base_tile_coords != TileSetSource::INVALID_ATLAS_COORDS) {
if (base_tile_coords == Vector2i(x, y)) {
// Draw existing tile.
Vector2i size_in_atlas = tile_set_atlas_source->get_tile_size_in_atlas(base_tile_coords);
Expand Down Expand Up @@ -299,7 +305,7 @@ void TileAtlasView::_draw_base_tiles_dark() {
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 == TileSetAtlasSource::INVALID_ATLAS_COORDS) {
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);
}
Expand Down Expand Up @@ -331,7 +337,7 @@ void TileAtlasView::_alternative_tiles_root_control_gui_input(const Ref<InputEve
Vector3i coords3 = get_alternative_tile_at_pos(xform.xform(mm->get_position()));
Vector2i coords = Vector2i(coords3.x, coords3.y);
int alternative_id = coords3.z;
if (coords != TileSetAtlasSource::INVALID_ATLAS_COORDS && alternative_id != TileSetAtlasSource::INVALID_TILE_ALTERNATIVE) {
if (coords != TileSetSource::INVALID_ATLAS_COORDS && alternative_id != TileSetSource::INVALID_TILE_ALTERNATIVE) {
alternative_tiles_root_control->set_tooltip(vformat(TTR("Source: %d\nAtlas coordinates: %s\nAlternative: %d"), source_id, coords, alternative_id));
}
}
Expand Down Expand Up @@ -364,7 +370,7 @@ void TileAtlasView::_draw_alternatives() {
}

// Draw the tile.
TileSetAtlasPluginRendering::draw_tile(alternatives_draw->get_canvas_item(), offset_pos, tile_set, source_id, atlas_coords, alternative_id);
TileSetPluginAtlasRendering::draw_tile(alternatives_draw->get_canvas_item(), offset_pos, tile_set, source_id, atlas_coords, alternative_id);

// Increment the x position.
current_pos.x += transposed ? texture_region.size.y : texture_region.size.x;
Expand Down Expand Up @@ -464,7 +470,7 @@ Vector2i TileAtlasView::get_atlas_tile_coords_at_pos(const Vector2 p_pos) const
return ret;
}

return TileSetAtlasSource::INVALID_ATLAS_COORDS;
return TileSetSource::INVALID_ATLAS_COORDS;
}

void TileAtlasView::_update_alternative_tiles_rect_cache() {
Expand Down Expand Up @@ -506,7 +512,7 @@ Vector3i TileAtlasView::get_alternative_tile_at_pos(const Vector2 p_pos) const {
}
}

return Vector3i(TileSetAtlasSource::INVALID_ATLAS_COORDS.x, TileSetAtlasSource::INVALID_ATLAS_COORDS.y, TileSetAtlasSource::INVALID_TILE_ALTERNATIVE);
return Vector3i(TileSetSource::INVALID_ATLAS_COORDS.x, TileSetSource::INVALID_ATLAS_COORDS.y, TileSetSource::INVALID_TILE_ALTERNATIVE);
}

Rect2i TileAtlasView::get_alternative_tile_rect(const Vector2i p_coords, int p_alternative_tile) {
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/tiles/tile_data_editors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void TileDataTerrainsEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform

Vector<String> components = String(p_property).split("/", true);
if (components[0] == "terrain_mode" || components[0] == "terrain" || components[0] == "terrains_peering_bit") {
TileSetAtlasPluginTerrain::draw_terrains(p_canvas_item, p_transform, p_tile_set, tile_data);
TileSetPluginAtlasTerrain::draw_terrains(p_canvas_item, p_transform, p_tile_set, tile_data);
}
}

Expand Down
Loading

0 comments on commit a6a75e2

Please sign in to comment.