Skip to content

Commit

Permalink
Merge pull request godotengine#51004 from groud/tilemap_layers
Browse files Browse the repository at this point in the history
Implements TileMap layers and move TileSetPlugins's functions to the TileMap node instead
  • Loading branch information
akien-mga authored Aug 2, 2021
2 parents b9d544b + ad8b5cd commit 5360c20
Show file tree
Hide file tree
Showing 13 changed files with 2,165 additions and 1,507 deletions.
94 changes: 80 additions & 14 deletions doc/classes/TileMap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,43 @@
</method>
<method name="get_cell_alternative_tile" qualifiers="const">
<return type="int" />
<argument index="0" name="coords" type="Vector2i" />
<argument index="1" name="use_proxies" type="bool" />
<argument index="0" name="layer" type="int" />
<argument index="1" name="coords" type="Vector2i" />
<argument index="2" name="use_proxies" type="bool" />
<description>
</description>
</method>
<method name="get_cell_atlas_coords" qualifiers="const">
<return type="Vector2i" />
<argument index="0" name="coords" type="Vector2i" />
<argument index="1" name="use_proxies" type="bool" />
<argument index="0" name="layer" type="int" />
<argument index="1" name="coords" type="Vector2i" />
<argument index="2" name="use_proxies" type="bool" />
<description>
</description>
</method>
<method name="get_cell_source_id" qualifiers="const">
<return type="int" />
<argument index="0" name="coords" type="Vector2i" />
<argument index="1" name="use_proxies" type="bool" />
<argument index="0" name="layer" type="int" />
<argument index="1" name="coords" type="Vector2i" />
<argument index="2" name="use_proxies" type="bool" />
<description>
</description>
</method>
<method name="get_layer_name" qualifiers="const">
<return type="String" />
<argument index="0" name="layer" type="int" />
<description>
</description>
</method>
<method name="get_layer_y_sort_origin" qualifiers="const">
<return type="int" />
<argument index="0" name="layer" type="int" />
<description>
</description>
</method>
<method name="get_layer_z_indexd" qualifiers="const">
<return type="int" />
<argument index="0" name="layer" type="int" />
<description>
</description>
</method>
Expand All @@ -65,6 +86,7 @@
</method>
<method name="get_used_cells" qualifiers="const">
<return type="Vector2i[]" />
<argument index="0" name="layer" type="int" />
<description>
Returns a [Vector2] array with the positions of all cells containing a tile from the tileset (i.e. a tile index different from [code]-1[/code]).
</description>
Expand All @@ -75,6 +97,18 @@
Returns a rectangle enclosing the used (non-empty) tiles of the map.
</description>
</method>
<method name="is_layer_enabled" qualifiers="const">
<return type="bool" />
<argument index="0" name="layer" type="int" />
<description>
</description>
</method>
<method name="is_layer_y_sort_enabled" qualifiers="const">
<return type="bool" />
<argument index="0" name="layer" type="int" />
<description>
</description>
</method>
<method name="map_to_world" qualifiers="const">
<return type="Vector2" />
<argument index="0" name="map_position" type="Vector2i" />
Expand All @@ -84,18 +118,48 @@
</method>
<method name="set_cell">
<return type="void" />
<argument index="0" name="coords" type="Vector2i" />
<argument index="1" name="source_id" type="int" default="-1" />
<argument index="2" name="atlas_coords" type="Vector2i" default="Vector2i(-1, -1)" />
<argument index="3" name="alternative_tile" type="int" default="-1" />
<argument index="0" name="layer" type="int" />
<argument index="1" name="coords" type="Vector2i" />
<argument index="2" name="source_id" type="int" default="-1" />
<argument index="3" name="atlas_coords" type="Vector2i" default="Vector2i(-1, -1)" />
<argument index="4" name="alternative_tile" type="int" default="-1" />
<description>
Sets the tile index for the cell given by a Vector2i.
</description>
</method>
<method name="update_dirty_quadrants">
<method name="set_layer_enabled">
<return type="void" />
<argument index="0" name="layer" type="int" />
<argument index="1" name="enabled" type="bool" />
<description>
</description>
</method>
<method name="set_layer_name">
<return type="void" />
<argument index="0" name="layer" type="int" />
<argument index="1" name="name" type="String" />
<description>
</description>
</method>
<method name="set_layer_y_sort_enabled">
<return type="void" />
<argument index="0" name="layer" type="int" />
<argument index="1" name="y_sort_enabled" type="bool" />
<description>
</description>
</method>
<method name="set_layer_y_sort_origin">
<return type="void" />
<argument index="0" name="layer" type="int" />
<argument index="1" name="y_sort_origin" type="int" />
<description>
</description>
</method>
<method name="set_layer_z_index">
<return type="void" />
<argument index="0" name="layer" type="int" />
<argument index="1" name="z_index" type="int" />
<description>
Updates the tile map's quadrants, allowing things such as navigation and collision shapes to be immediately used if modified.
</description>
</method>
<method name="world_to_map" qualifiers="const">
Expand All @@ -110,9 +174,11 @@
<member name="cell_quadrant_size" type="int" setter="set_quadrant_size" getter="get_quadrant_size" default="16">
The TileMap's quadrant size. Optimizes drawing by batching, using chunks of this size.
</member>
<member name="show_collision" type="int" setter="set_collision_visibility_mode" getter="get_collision_visibility_mode" enum="TileMap.VisibilityMode" default="0">
<member name="collision_visibility_mode" type="int" setter="set_collision_visibility_mode" getter="get_collision_visibility_mode" enum="TileMap.VisibilityMode" default="0">
</member>
<member name="layers_count" type="int" setter="set_layers_count" getter="get_layers_count" default="1">
</member>
<member name="show_navigation" type="int" setter="set_navigation_visibility_mode" getter="get_navigation_visibility_mode" enum="TileMap.VisibilityMode" default="0">
<member name="navigation_visibility_mode" type="int" setter="set_navigation_visibility_mode" getter="get_navigation_visibility_mode" enum="TileMap.VisibilityMode" default="0">
</member>
<member name="tile_set" type="TileSet" setter="set_tileset" getter="get_tileset">
The assigned [TileSet].
Expand Down
2 changes: 0 additions & 2 deletions doc/classes/TileSet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,6 @@
</member>
<member name="uv_clipping" type="bool" setter="set_uv_clipping" getter="is_uv_clipping" default="false">
</member>
<member name="y_sorting" type="bool" setter="set_y_sorting" getter="is_y_sorting" default="false">
</member>
</members>
<constants>
<constant name="TILE_SHAPE_SQUARE" value="0" enum="TileShape">
Expand Down
1 change: 1 addition & 0 deletions editor/icons/TileMapHighlightSelected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions editor/plugins/tiles/tile_atlas_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "core/input/input.h"
#include "core/os/keyboard.h"
#include "scene/2d/tile_map.h"
#include "scene/gui/box_container.h"
#include "scene/gui/label.h"
#include "scene/gui/panel.h"
Expand Down Expand Up @@ -259,7 +260,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.
TileSetPluginAtlasRendering::draw_tile(base_tiles_draw->get_canvas_item(), offset_pos, tile_set, source_id, atlas_coords, 0);
TileMap::draw_tile(base_tiles_draw->get_canvas_item(), offset_pos, tile_set, source_id, atlas_coords, 0);
}
}
}
Expand Down Expand Up @@ -375,7 +376,7 @@ void TileAtlasView::_draw_alternatives() {
}

// Draw the tile.
TileSetPluginAtlasRendering::draw_tile(alternatives_draw->get_canvas_item(), offset_pos, tile_set, source_id, atlas_coords, alternative_id);
TileMap::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
2 changes: 1 addition & 1 deletion editor/plugins/tiles/tile_data_editors.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
#include "editor/editor_node.h"
#include "editor/editor_properties.h"

#include "scene/2d/tile_map.h"
#include "scene/gui/box_container.h"
#include "scene/gui/control.h"
#include "scene/gui/label.h"
#include "scene/resources/tile_set.h"

class TileDataEditor : public VBoxContainer {
GDCLASS(TileDataEditor, VBoxContainer);
Expand Down
Loading

0 comments on commit 5360c20

Please sign in to comment.