diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml
index 48ed191db17..9f0b86e8772 100644
--- a/doc/classes/EditorSettings.xml
+++ b/doc/classes/EditorSettings.xml
@@ -448,6 +448,9 @@
The color to use for the TileMap editor's grid.
[b]Note:[/b] Only effective if [member editors/tiles_editor/display_grid] is [code]true[/code].
+
+ Highlight the currently selected TileMapLayer by dimming the other ones in the scene.
+
The color of a graph node's header when it belongs to the "Color" category.
diff --git a/doc/classes/TileMap.xml b/doc/classes/TileMap.xml
index fc19e1de496..bc8a1d7bf17 100644
--- a/doc/classes/TileMap.xml
+++ b/doc/classes/TileMap.xml
@@ -1,5 +1,5 @@
-
+
Node for 2D tile-based maps.
@@ -89,7 +89,8 @@
- Returns the tile alternative ID of the cell on layer [param layer] at [param coords]. If [param use_proxies] is [code]false[/code], ignores the [TileSet]'s tile proxies, returning the raw alternative identifier. See [method TileSet.map_tile_proxy].
+ Returns the tile alternative ID of the cell on layer [param layer] at [param coords].
+ If [param use_proxies] is [code]false[/code], ignores the [TileSet]'s tile proxies, returning the raw alternative identifier. See [method TileSet.map_tile_proxy].
If [param layer] is negative, the layers are accessed from the last one.
@@ -100,7 +101,7 @@
Returns the tile atlas coordinates ID of the cell on layer [param layer] at coordinates [param coords]. Returns [code]Vector2i(-1, -1)[/code] if the cell does not exist.
- If [param use_proxies] is [code]false[/code], ignores the [TileSet]'s tile proxies, returning the raw alternative identifier. See [method TileSet.map_tile_proxy].
+ If [param use_proxies] is [code]false[/code], ignores the [TileSet]'s tile proxies, returning the raw atlas coordinate identifier. See [method TileSet.map_tile_proxy].
If [param layer] is negative, the layers are accessed from the last one.
@@ -111,7 +112,7 @@
Returns the tile source ID of the cell on layer [param layer] at coordinates [param coords]. Returns [code]-1[/code] if the cell does not exist.
- If [param use_proxies] is [code]false[/code], ignores the [TileSet]'s tile proxies, returning the raw alternative identifier. See [method TileSet.map_tile_proxy].
+ If [param use_proxies] is [code]false[/code], ignores the [TileSet]'s tile proxies, returning the raw source identifier. See [method TileSet.map_tile_proxy].
If [param layer] is negative, the layers are accessed from the last one.
@@ -123,7 +124,6 @@
Returns the [TileData] object associated with the given cell, or [code]null[/code] if the cell does not exist or is not a [TileSetAtlasSource].
If [param layer] is negative, the layers are accessed from the last one.
- If [param use_proxies] is [code]false[/code], ignores the [TileSet]'s tile proxies, returning the raw alternative identifier. See [method TileSet.map_tile_proxy].
[codeblock]
func get_clicked_tile_power():
var clicked_cell = tile_map.local_to_map(tile_map.get_local_mouse_position())
@@ -133,6 +133,7 @@
else:
return 0
[/codeblock]
+ If [param use_proxies] is [code]false[/code], ignores the [TileSet]'s tile proxies. See [method TileSet.map_tile_proxy].
@@ -489,6 +490,9 @@
The quadrant size does not apply on Y-sorted layers, as tiles are be grouped by Y position instead in that case.
[b]Note:[/b] As quadrants are created according to the map's coordinate system, the quadrant's "square shape" might not look like square in the TileMap's local coordinate system.
+
+ The [TileSet] used by this [TileMap]. The textures, collisions, and additional behavior of all available tiles are stored here.
+
diff --git a/doc/classes/TileMapLayer.xml b/doc/classes/TileMapLayer.xml
new file mode 100644
index 00000000000..bc8e259599e
--- /dev/null
+++ b/doc/classes/TileMapLayer.xml
@@ -0,0 +1,303 @@
+
+
+
+ Node for 2D tile-based maps.
+
+
+ Node for 2D tile-based maps. A [TileMapLayer] uses a [TileSet] which contain a list of tiles which are used to create grid-based maps. Unlike the [TileMap] node, which is deprecated, [TileMapLayer] has only one layer of tiles. You can use several [TileMapLayer] to achieve the same result as a [TileMap] node.
+ For performance reasons, all TileMap updates are batched at the end of a frame. Notably, this means that scene tiles from a [TileSetScenesCollectionSource] may be initialized after their parent. This is only queued when inside the scene tree.
+ To force an update earlier on, call [method update_internals].
+
+
+
+
+
+
+
+
+
+ Called with a [TileData] object about to be used internally by the [TileMapLayer], allowing its modification at runtime.
+ This method is only called if [method _use_tile_data_runtime_update] is implemented and returns [code]true[/code] for the given tile [param coords].
+ [b]Warning:[/b] The [param tile_data] object's sub-resources are the same as the one in the TileSet. Modifying them might impact the whole TileSet. Instead, make sure to duplicate those resources.
+ [b]Note:[/b] If the properties of [param tile_data] object should change over time, use [method notify_runtime_tile_data_update] to notify the [TileMapLayer] it needs an update.
+
+
+
+
+
+
+ Should return [code]true[/code] if the tile at coordinates [param coords] requires a runtime update.
+ [b]Warning:[/b] Make sure this function only returns [code]true[/code] when needed. Any tile processed at runtime without a need for it will imply a significant performance penalty.
+ [b]Note:[/b] If the result of this function should change, use [method notify_runtime_tile_data_update] to notify the [TileMapLayer] it needs an update.
+
+
+
+
+
+ Clears all cells.
+
+
+
+
+
+
+ Erases the cell at coordinates [param coords].
+
+
+
+
+
+ Clears cells containing tiles that do not exist in the [member tile_set].
+
+
+
+
+
+
+ Returns the tile alternative ID of the cell at coordinates [param coords].
+
+
+
+
+
+
+ Returns the tile atlas coordinates ID of the cell at coordinates [param coords]. Returns [code]Vector2i(-1, -1)[/code] if the cell does not exist.
+
+
+
+
+
+
+ Returns the tile source ID of the cell at coordinates [param coords]. Returns [code]-1[/code] if the cell does not exist.
+
+
+
+
+
+
+ Returns the [TileData] object associated with the given cell, or [code]null[/code] if the cell does not exist or is not a [TileSetAtlasSource].
+ [codeblock]
+ func get_clicked_tile_power():
+ var clicked_cell = tile_map_layer.local_to_map(tile_map_layer.get_local_mouse_position())
+ var data = tile_map_layer.get_cell_tile_data(clicked_cell)
+ if data:
+ return data.get_custom_data("power")
+ else:
+ return 0
+ [/codeblock]
+
+
+
+
+
+
+ Returns the coordinates of the tile for given physics body [RID]. Such an [RID] can be retrieved from [method KinematicCollision2D.get_collider_rid], when colliding with a tile.
+
+
+
+
+
+ Returns the [RID] of the [NavigationServer2D] navigation used by this [TileMapLayer].
+ By default this returns the default [World2D] navigation map, unless a custom map was provided using [method set_navigation_map].
+
+
+
+
+
+
+
+ Returns the neighboring cell to the one at coordinates [param coords], identified by the [param neighbor] direction. This method takes into account the different layouts a TileMap can take.
+
+
+
+
+
+
+ Creates and returns a new [TileMapPattern] from the given array of cells. See also [method set_pattern].
+
+
+
+
+
+
+ Returns the list of all neighboring cells to the one at [param coords].
+
+
+
+
+
+ Returns a [Vector2i] array with the positions of all cells containing a tile. A cell is considered empty if its source identifier equals [code]-1[/code], its atlas coordinate identifier is [code]Vector2(-1, -1)[/code] and its alternative identifier is [code]-1[/code].
+
+
+
+
+
+
+
+
+ Returns a [Vector2i] array with the positions of all cells containing a tile. Tiles may be filtered according to their source ([param source_id]), their atlas coordinates ([param atlas_coords]), or alternative id ([param alternative_tile]).
+ If a parameter has its value set to the default one, this parameter is not used to filter a cell. Thus, if all parameters have their respective default values, this method returns the same result as [method get_used_cells].
+ A cell is considered empty if its source identifier equals [code]-1[/code], its atlas coordinate identifier is [code]Vector2(-1, -1)[/code] and its alternative identifier is [code]-1[/code].
+
+
+
+
+
+ Returns a rectangle enclosing the used (non-empty) tiles of the map.
+
+
+
+
+
+
+ Returns whether the provided [param body] [RID] belongs to one of this [TileMapLayer]'s cells.
+
+
+
+
+
+
+ Returns the map coordinates of the cell containing the given [param local_position]. If [param local_position] is in global coordinates, consider using [method Node2D.to_local] before passing it to this method. See also [method map_to_local].
+
+
+
+
+
+
+
+
+ Returns for the given coordinates [param coords_in_pattern] in a [TileMapPattern] the corresponding cell coordinates if the pattern was pasted at the [param position_in_tilemap] coordinates (see [method set_pattern]). This mapping is required as in half-offset tile shapes, the mapping might not work by calculating [code]position_in_tile_map + coords_in_pattern[/code].
+
+
+
+
+
+
+ Returns the centered position of a cell in the [TileMapLayer]'s local coordinate space. To convert the returned value into global coordinates, use [method Node2D.to_global]. See also [method local_to_map].
+ [b]Note:[/b] This may not correspond to the visual position of the tile, i.e. it ignores the [member TileData.texture_origin] property of individual tiles.
+
+
+
+
+
+ Notifies the [TileMapLayer] node that calls to [method _use_tile_data_runtime_update] or [method _tile_data_runtime_update] will lead to different results. This will thus trigger a [TileMapLayer] update.
+ [b]Warning:[/b] Updating the [TileMapLayer] is computationally expensive and may impact performance. Try to limit the number of calls to this function to avoid unnecessary update.
+ [b]Note:[/b] This does not trigger a direct update of the [TileMapLayer], the update will be done at the end of the frame as usual (unless you call [method update_internals]).
+
+
+
+
+
+
+
+
+
+ Sets the tile identifiers for the cell at coordinates [param coords]. Each tile of the [TileSet] is identified using three parts:
+ - The source identifier [param source_id] identifies a [TileSetSource] identifier. See [method TileSet.set_source_id],
+ - The atlas coordinate identifier [param atlas_coords] identifies a tile coordinates in the atlas (if the source is a [TileSetAtlasSource]). For [TileSetScenesCollectionSource] it should always be [code]Vector2i(0, 0)[/code],
+ - The alternative tile identifier [param alternative_tile] identifies a tile alternative in the atlas (if the source is a [TileSetAtlasSource]), and the scene for a [TileSetScenesCollectionSource].
+ If [param source_id] is set to [code]-1[/code], [param atlas_coords] to [code]Vector2i(-1, -1)[/code], or [param alternative_tile] to [code]-1[/code], the cell will be erased. An erased cell gets [b]all[/b] its identifiers automatically set to their respective invalid values, namely [code]-1[/code], [code]Vector2i(-1, -1)[/code] and [code]-1[/code].
+
+
+
+
+
+
+
+
+
+ Update all the cells in the [param cells] coordinates array so that they use the given [param terrain] for the given [param terrain_set]. If an updated cell has the same terrain as one of its neighboring cells, this function tries to join the two. This function might update neighboring tiles if needed to create correct terrain transitions.
+ If [param ignore_empty_terrains] is true, empty terrains will be ignored when trying to find the best fitting tile for the given terrain constraints.
+ [b]Note:[/b] To work correctly, this method requires the [TileMapLayer]'s TileSet to have terrains set up with all required terrain combinations. Otherwise, it may produce unexpected results.
+
+
+
+
+
+
+
+
+
+ Update all the cells in the [param path] coordinates array so that they use the given [param terrain] for the given [param terrain_set]. The function will also connect two successive cell in the path with the same terrain. This function might update neighboring tiles if needed to create correct terrain transitions.
+ If [param ignore_empty_terrains] is true, empty terrains will be ignored when trying to find the best fitting tile for the given terrain constraints.
+ [b]Note:[/b] To work correctly, this method requires the [TileMapLayer]'s TileSet to have terrains set up with all required terrain combinations. Otherwise, it may produce unexpected results.
+
+
+
+
+
+
+ Sets a custom [param map] as a [NavigationServer2D] navigation map. If not set, uses the default [World2D] navigation map instead.
+
+
+
+
+
+
+
+ Pastes the [TileMapPattern] at the given [param position] in the tile map. See also [method get_pattern].
+
+
+
+
+
+ Triggers a direct update of the [TileMapLayer]. Usually, calling this function is not needed, as [TileMapLayer] node updates automatically when one of its properties or cells is modified.
+ However, for performance reasons, those updates are batched and delayed to the end of the frame. Calling this function will force the [TileMapLayer] to update right away instead.
+ [b]Warning:[/b] Updating the [TileMapLayer] is computationally expensive and may impact performance. Try to limit the number of updates and how many tiles they impact.
+
+
+
+
+
+ Enable or disable collisions.
+
+
+ Show or hide the [TileMapLayer]'s collision shapes. If set to [constant DEBUG_VISIBILITY_MODE_DEFAULT], this depends on the show collision debug settings.
+
+
+ If [code]false[/code], disables this [TileMapLayer] completely (rendering, collision, navigation, scene tiles, etc.)
+
+
+ If [code]true[/code], navigation regions are enabled.
+
+
+ Show or hide the [TileMapLayer]'s navigation meshes. If set to [constant DEBUG_VISIBILITY_MODE_DEFAULT], this depends on the show navigation debug settings.
+
+
+ The [TileMapLayer]'s quadrant size. A quadrant is a group of tiles to be drawn together on a single canvas item, for optimization purposes. [member rendering_quadrant_size] defines the length of a square's side, in the map's coordinate system, that forms the quadrant. Thus, the default quandrant size groups together [code]16 * 16 = 256[/code] tiles.
+ The quadrant size does not apply on a Y-sorted [TileMapLayer], as tiles are be grouped by Y position instead in that case.
+ [b]Note:[/b] As quadrants are created according to the map's coordinate system, the quadrant's "square shape" might not look like square in the [TileMapLayer]'s local coordinate system.
+
+
+ The raw tile map data as a byte array.
+
+
+ The [TileSet] used by this layer. The textures, collisions, and additional behavior of all available tiles are stored here.
+
+
+ If [code]true[/code], this [TileMapLayer] collision shapes will be instantiated as kinematic bodies. This can be needed for moving [TileMapLayer] nodes (i.e. moving platforms).
+
+
+ This Y-sort origin value is added to each tile's Y-sort origin value. This allows, for example, to fake a different height level. This can be useful for top-down view games.
+
+
+
+
+
+ Emitted when this [TileMapLayer]'s properties changes. This includes modified cells, properties, or changes made to its assigned [TileSet].
+ [b]Note:[/b] This signal may be emitted very often when batch-modifying a [TileMapLayer]. Avoid executing complex processing in a connected function, and consider delaying it to the end of the frame instead (i.e. calling [method Object.call_deferred]).
+
+
+
+
+
+ Hide the collisions or navigation debug shapes in the editor, and use the debug settings to determine their visibility in game (i.e. [member SceneTree.debug_collisions_hint] or [member SceneTree.debug_navigation_hint]).
+
+
+ Always hide the collisions or navigation debug shapes.
+
+
+ Always show the collisions or navigation debug shapes.
+
+
+
diff --git a/doc/classes/TileMapLayerGroup.xml b/doc/classes/TileMapLayerGroup.xml
deleted file mode 100644
index 3787d3bb17f..00000000000
--- a/doc/classes/TileMapLayerGroup.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
- Groups a set of tile map layers together, allowing them to share a provided [TileSet].
-
-
- Groups together tile map layers as part or the same map, replacing the [TileMap] node. Child layers will use this node's [member tile_set].
- The editor also uses [TileMapLayerGroup] as a way to store which layers are selected in a given group. This allows highlighting the currently selected layers.
-
-
-
-
-
- The assigned [TileSet]. This TileSet will be applied to all child layers.
-
-
-
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 15409edf6ec..5c1b14c203f 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -2506,8 +2506,8 @@ void EditorNode::_edit_current(bool p_skip_foreign, bool p_skip_inspector_update
editable_info,
info_is_warning);
- Object *editor_owner = is_node ? (Object *)SceneTreeDock::get_singleton() : is_resource ? (Object *)InspectorDock::get_inspector_singleton()
- : (Object *)this;
+ Object *editor_owner = (is_node || current_obj->is_class("MultiNodeEdit")) ? (Object *)SceneTreeDock::get_singleton() : is_resource ? (Object *)InspectorDock::get_inspector_singleton()
+ : (Object *)this;
// Take care of the main editor plugin.
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index ee33e171e3e..89580b83b0b 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -755,6 +755,7 @@ void EditorSettings::_load_defaults(Ref p_extra_config) {
// Tiles editor
_initial_set("editors/tiles_editor/display_grid", true);
+ _initial_set("editors/tiles_editor/highlight_selected_layer", true);
_initial_set("editors/tiles_editor/grid_color", Color(1.0, 0.5, 0.2, 0.5));
// Polygon editor
diff --git a/editor/icons/TileMapLayer.svg b/editor/icons/TileMapLayer.svg
index 1903a87e3b3..90664dee038 100644
--- a/editor/icons/TileMapLayer.svg
+++ b/editor/icons/TileMapLayer.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/editor/plugins/tiles/tile_map_layer_editor.cpp b/editor/plugins/tiles/tile_map_layer_editor.cpp
index ccadc0643b4..ac4708aa066 100644
--- a/editor/plugins/tiles/tile_map_layer_editor.cpp
+++ b/editor/plugins/tiles/tile_map_layer_editor.cpp
@@ -36,9 +36,9 @@
#include "editor/editor_resource_preview.h"
#include "editor/editor_settings.h"
#include "editor/editor_undo_redo_manager.h"
+#include "editor/multi_node_edit.h"
#include "editor/plugins/canvas_item_editor_plugin.h"
#include "editor/themes/editor_scale.h"
-
#include "scene/2d/camera_2d.h"
#include "scene/2d/tile_map_layer.h"
#include "scene/gui/center_container.h"
@@ -107,7 +107,7 @@ void TileMapLayerEditorTilesPlugin::_update_transform_buttons() {
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null() || selection_pattern.is_null()) {
return;
}
@@ -171,7 +171,7 @@ void TileMapLayerEditorTilesPlugin::_update_tile_set_sources_list() {
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -256,7 +256,7 @@ void TileMapLayerEditorTilesPlugin::_update_source_display() {
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -302,7 +302,7 @@ void TileMapLayerEditorTilesPlugin::_patterns_item_list_gui_input(const Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -348,7 +348,7 @@ void TileMapLayerEditorTilesPlugin::_update_patterns_list() {
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -380,7 +380,7 @@ void TileMapLayerEditorTilesPlugin::_update_atlas_view() {
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -401,7 +401,7 @@ void TileMapLayerEditorTilesPlugin::_update_scenes_collection_view() {
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -459,7 +459,7 @@ void TileMapLayerEditorTilesPlugin::_scenes_list_multi_selected(int p_index, boo
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -538,7 +538,7 @@ bool TileMapLayerEditorTilesPlugin::forward_canvas_gui_input(const Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return false;
}
@@ -784,7 +784,7 @@ void TileMapLayerEditorTilesPlugin::forward_canvas_draw_over_viewport(Control *p
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -1021,7 +1021,7 @@ TileMapCell TileMapLayerEditorTilesPlugin::_pick_random_tile(Ref
return TileMapCell();
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return TileMapCell();
}
@@ -1073,7 +1073,7 @@ HashMap TileMapLayerEditorTilesPlugin::_draw_line(Vector2
return HashMap();
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return HashMap();
}
@@ -1122,7 +1122,7 @@ HashMap TileMapLayerEditorTilesPlugin::_draw_rect(Vector2
return HashMap();
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return HashMap();
}
@@ -1181,7 +1181,7 @@ HashMap TileMapLayerEditorTilesPlugin::_draw_bucket_fill(
return HashMap();
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return HashMap();
}
@@ -1293,7 +1293,7 @@ void TileMapLayerEditorTilesPlugin::_stop_dragging() {
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -1601,7 +1601,7 @@ void TileMapLayerEditorTilesPlugin::_update_fix_selected_and_hovered() {
selection_pattern.instantiate();
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
hovered_tile.source_id = TileSet::INVALID_SOURCE;
hovered_tile.set_atlas_coords(TileSetSource::INVALID_ATLAS_COORDS);
@@ -1688,7 +1688,7 @@ void TileMapLayerEditorTilesPlugin::_update_selection_pattern_from_tilemap_selec
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -1709,7 +1709,7 @@ void TileMapLayerEditorTilesPlugin::_update_selection_pattern_from_tileset_tiles
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -1783,7 +1783,7 @@ void TileMapLayerEditorTilesPlugin::_update_selection_pattern_from_tileset_patte
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -1822,7 +1822,7 @@ void TileMapLayerEditorTilesPlugin::_tile_atlas_control_draw() {
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -1901,7 +1901,7 @@ void TileMapLayerEditorTilesPlugin::_tile_atlas_control_gui_input(const Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -2007,7 +2007,7 @@ void TileMapLayerEditorTilesPlugin::_tile_alternatives_control_draw() {
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -2059,7 +2059,7 @@ void TileMapLayerEditorTilesPlugin::_tile_alternatives_control_gui_input(const R
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -2157,16 +2157,21 @@ void TileMapLayerEditorTilesPlugin::edit(ObjectID p_tile_map_layer_id) {
// Disable sort button if the tileset is read-only
TileMapLayer *edited_layer = _get_edited_layer();
+ Ref tile_set;
if (edited_layer) {
- Ref tile_set = edited_layer->get_effective_tile_set();
+ tile_set = edited_layer->get_tile_set();
if (tile_set.is_valid()) {
source_sort_button->set_disabled(EditorNode::get_singleton()->is_resource_read_only(tile_set));
}
}
- if (edited_tile_map_layer_id != p_tile_map_layer_id) {
- edited_tile_map_layer_id = p_tile_map_layer_id;
+ TileMapLayer *new_tile_map_layer = Object::cast_to(ObjectDB::get_instance(edited_tile_map_layer_id));
+ Ref new_tile_set;
+ if (new_tile_map_layer) {
+ new_tile_set = new_tile_map_layer->get_tile_set();
+ }
+ if (tile_set.is_valid() && tile_set != new_tile_set) {
// Clear the selection.
tile_set_selection.clear();
patterns_item_list->deselect_all();
@@ -2531,7 +2536,7 @@ HashMap TileMapLayerEditorTerrainsPlugin::_draw_terrain_p
return HashMap();
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return HashMap();
}
@@ -2583,7 +2588,7 @@ HashMap TileMapLayerEditorTerrainsPlugin::_draw_terrain_p
return HashMap();
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return HashMap();
}
@@ -2630,7 +2635,7 @@ HashMap TileMapLayerEditorTerrainsPlugin::_draw_line(Vect
return HashMap();
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return HashMap();
}
@@ -2654,7 +2659,7 @@ HashMap TileMapLayerEditorTerrainsPlugin::_draw_rect(Vect
return HashMap();
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return HashMap();
}
@@ -2688,7 +2693,7 @@ RBSet TileMapLayerEditorTerrainsPlugin::_get_cells_for_bucket_fill(Vec
return RBSet();
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return RBSet();
}
@@ -2799,7 +2804,7 @@ HashMap TileMapLayerEditorTerrainsPlugin::_draw_bucket_fi
return HashMap();
}
- const Ref &tile_set = edited_layer->get_effective_tile_set();
+ const Ref &tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return HashMap();
}
@@ -2827,7 +2832,7 @@ void TileMapLayerEditorTerrainsPlugin::_stop_dragging() {
return;
}
- const Ref &tile_set = edited_layer->get_effective_tile_set();
+ const Ref &tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -2961,7 +2966,7 @@ void TileMapLayerEditorTerrainsPlugin::_update_selection() {
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -3013,7 +3018,7 @@ bool TileMapLayerEditorTerrainsPlugin::forward_canvas_gui_input(const Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return false;
}
@@ -3150,7 +3155,7 @@ void TileMapLayerEditorTerrainsPlugin::forward_canvas_draw_over_viewport(Control
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -3275,7 +3280,7 @@ void TileMapLayerEditorTerrainsPlugin::_update_terrains_cache() {
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -3342,7 +3347,7 @@ void TileMapLayerEditorTerrainsPlugin::_update_terrains_tree() {
const TileMapLayer *edited_layer = _get_edited_layer();
ERR_FAIL_NULL(edited_layer);
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -3389,7 +3394,7 @@ void TileMapLayerEditorTerrainsPlugin::_update_tiles_list() {
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -3627,57 +3632,258 @@ TileMapLayer *TileMapLayerEditor::_get_edited_layer() const {
return Object::cast_to(ObjectDB::get_instance(edited_tile_map_layer_id));
}
+void TileMapLayerEditor::_find_tile_map_layers_in_scene(Node *p_current, const Node *p_owner, Vector &r_list) const {
+ ERR_FAIL_COND(!p_current || !p_owner);
+ if (p_current != p_owner && p_current->get_owner() != p_owner) {
+ return;
+ }
+ TileMapLayer *layer = Object::cast_to(p_current);
+ if (layer) {
+ r_list.append(layer);
+ }
+ for (int i = 0; i < p_current->get_child_count(); i++) {
+ Node *child = p_current->get_child(i);
+ _find_tile_map_layers_in_scene(child, p_owner, r_list);
+ }
+}
+
+void TileMapLayerEditor::_update_tile_map_layers_in_scene_list_cache() {
+ if (!layers_in_scene_list_cache_needs_update) {
+ return;
+ }
+ EditorNode *en = EditorNode::get_singleton();
+ Node *edited_scene_root = en->get_edited_scene();
+ if (!edited_scene_root) {
+ return;
+ }
+
+ tile_map_layers_in_scene_cache.clear();
+ _find_tile_map_layers_in_scene(edited_scene_root, edited_scene_root, tile_map_layers_in_scene_cache);
+ layers_in_scene_list_cache_needs_update = false;
+}
+
+void TileMapLayerEditor::_node_change(Node *p_node) {
+ if (!layers_in_scene_list_cache_needs_update && p_node->is_part_of_edited_scene() && Object::cast_to(p_node)) {
+ layers_in_scene_list_cache_needs_update = true;
+ }
+}
+
void TileMapLayerEditor::_notification(int p_what) {
switch (p_what) {
+ case NOTIFICATION_READY: {
+ get_tree()->connect("node_added", callable_mp(this, &TileMapLayerEditor::_node_change));
+ get_tree()->connect("node_removed", callable_mp(this, &TileMapLayerEditor::_node_change));
+ } break;
case NOTIFICATION_THEME_CHANGED: {
missing_tile_texture = get_editor_theme_icon(SNAME("StatusWarning"));
warning_pattern_texture = get_editor_theme_icon(SNAME("WarningPattern"));
advanced_menu_button->set_icon(get_editor_theme_icon(SNAME("Tools")));
+ select_previous_layer->set_icon(get_editor_theme_icon(SNAME("MoveUp")));
+ select_next_layer->set_icon(get_editor_theme_icon(SNAME("MoveDown")));
+ select_all_layers->set_icon(get_editor_theme_icon(SNAME("FileList")));
toggle_grid_button->set_icon(get_editor_theme_icon(SNAME("Grid")));
- toggle_grid_button->set_pressed(EDITOR_GET("editors/tiles_editor/display_grid"));
toggle_highlight_selected_layer_button->set_icon(get_editor_theme_icon(SNAME("TileMapHighlightSelected")));
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
- if (is_visible_in_tree() && tileset_changed_needs_update) {
+ if (is_visible_in_tree() && tile_map_layer_changed_needs_update) {
_update_bottom_panel();
- update_layers_selector();
- _update_highlighting_toggle();
+ _update_layers_selector();
tabs_plugins[tabs_bar->get_current_tab()]->tile_set_changed();
CanvasItemEditor::get_singleton()->update_viewport();
- tileset_changed_needs_update = false;
+ tile_map_layer_changed_needs_update = false;
}
} break;
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
if (EditorSettings::get_singleton()->check_changed_settings_in_group("editors/tiles_editor")) {
toggle_grid_button->set_pressed_no_signal(EDITOR_GET("editors/tiles_editor/display_grid"));
+ toggle_highlight_selected_layer_button->set_pressed_no_signal(EDITOR_GET("editors/tiles_editor/highlight_selected_layer"));
}
} break;
}
}
-void TileMapLayerEditor::_bind_methods() {
- ADD_SIGNAL(MethodInfo("change_selected_layer_request", PropertyInfo(Variant::STRING_NAME, "layer_name")));
-}
-
void TileMapLayerEditor::_on_grid_toggled(bool p_pressed) {
EditorSettings::get_singleton()->set("editors/tiles_editor/display_grid", p_pressed);
CanvasItemEditor::get_singleton()->update_viewport();
}
+void TileMapLayerEditor::_select_previous_layer_pressed() {
+ _layers_select_next_or_previous(false);
+}
+
+void TileMapLayerEditor::_select_next_layer_pressed() {
+ _layers_select_next_or_previous(true);
+}
+
+void TileMapLayerEditor::_select_all_layers_pressed() {
+ EditorNode *en = EditorNode::get_singleton();
+ Node *edited_scene_root = en->get_edited_scene();
+ ERR_FAIL_NULL(edited_scene_root);
+
+ en->get_editor_selection()->clear();
+ if (tile_map_layers_in_scene_cache.size() == 1) {
+ en->edit_node(tile_map_layers_in_scene_cache[0]);
+ en->get_editor_selection()->add_node(tile_map_layers_in_scene_cache[0]);
+ } else {
+ _update_tile_map_layers_in_scene_list_cache();
+ Ref multi_node_edit = memnew(MultiNodeEdit);
+ for (TileMapLayer *layer : tile_map_layers_in_scene_cache) {
+ multi_node_edit->add_node(edited_scene_root->get_path_to(layer));
+ en->get_editor_selection()->add_node(layer);
+ }
+ en->push_item(multi_node_edit.ptr());
+ }
+}
+
void TileMapLayerEditor::_layers_selection_item_selected(int p_index) {
- emit_signal("change_selected_layer_request", layers_selection_button->get_item_metadata(p_index));
+ TileMapLayer *edited_layer = _get_edited_layer();
+ ERR_FAIL_NULL(edited_layer);
+
+ TileMap *tile_map = Object::cast_to(edited_layer->get_parent());
+ ERR_FAIL_NULL(tile_map);
+
+ TileMapLayer *new_edited = Object::cast_to(tile_map->get_child(p_index));
+ edit(new_edited);
+}
+
+void TileMapLayerEditor::_update_layers_selector() {
+ const TileMapLayer *edited_layer = _get_edited_layer();
+
+ // Update the selector.
+ layers_selection_button->clear();
+ layers_selection_button->hide();
+ select_all_layers->show();
+ select_next_layer->set_disabled(false);
+ select_previous_layer->set_disabled(false);
+ advanced_menu_button->get_popup()->set_item_disabled(ADVANCED_MENU_EXTRACT_TILE_MAP_LAYERS, true);
+ if (edited_layer) {
+ TileMap *tile_map = Object::cast_to(edited_layer->get_parent());
+ if (tile_map && edited_layer->get_index_in_tile_map() >= 0) {
+ // Build the list of layers.
+ for (int i = 0; i < tile_map->get_layers_count(); i++) {
+ const TileMapLayer *layer = Object::cast_to(tile_map->get_child(i));
+ if (layer) {
+ int index = layers_selection_button->get_item_count();
+ layers_selection_button->add_item(layer->get_name());
+ layers_selection_button->set_item_metadata(index, layer->get_name());
+ if (edited_layer == layer) {
+ layers_selection_button->select(index);
+ }
+ }
+ }
+
+ // Disable selector if there's no layer to select.
+ layers_selection_button->set_disabled(false);
+ if (layers_selection_button->get_item_count() == 0) {
+ layers_selection_button->set_disabled(true);
+ layers_selection_button->set_text(TTR("No Layers"));
+ }
+
+ // Disable next/previous if there's one or less layers.
+ if (layers_selection_button->get_item_count() <= 1) {
+ select_next_layer->set_disabled(true);
+ select_previous_layer->set_disabled(true);
+ }
+ layers_selection_button->show();
+ select_all_layers->hide();
+
+ // Enable the "extract as TileMapLayer" option only if we are editing a TleMap.
+ advanced_menu_button->get_popup()->set_item_disabled(ADVANCED_MENU_EXTRACT_TILE_MAP_LAYERS, false);
+ }
+ } else {
+ select_all_layers->hide();
+ select_next_layer->set_disabled(true);
+ select_previous_layer->set_disabled(true);
+ }
+}
+
+void TileMapLayerEditor::_clear_all_layers_highlighting() {
+ // Note: This function might be removed if we remove the TileMap node at some point.
+ // All processing could be done in _update_all_layers_highlighting otherwise.
+ TileMapLayer *edited_layer = _get_edited_layer();
+
+ // Use default mode.
+ if (edited_layer && edited_layer->get_index_in_tile_map() >= 0) {
+ // For the TileMap node.
+ TileMap *tile_map = Object::cast_to(edited_layer->get_parent());
+ if (tile_map) {
+ for (int i = 0; i < tile_map->get_layers_count(); i++) {
+ TileMapLayer *layer = Object::cast_to(tile_map->get_child(i));
+ layer->set_highlight_mode(TileMapLayer::HIGHLIGHT_MODE_DEFAULT);
+ }
+ }
+ } else {
+ // For other TileMapLayer nodes.
+ _update_tile_map_layers_in_scene_list_cache();
+ for (TileMapLayer *layer : tile_map_layers_in_scene_cache) {
+ layer->set_highlight_mode(TileMapLayer::HIGHLIGHT_MODE_DEFAULT);
+ }
+ }
+}
+
+void TileMapLayerEditor::_update_all_layers_highlighting() {
+ EditorNode *en = EditorNode::get_singleton();
+ Node *edited_scene_root = en->get_edited_scene();
+ if (!edited_scene_root) {
+ return;
+ }
+
+ // Get selected layer.
+ TileMapLayer *edited_layer = _get_edited_layer();
+
+ bool highlight_selected_layer = EDITOR_GET("editors/tiles_editor/highlight_selected_layer");
+ if (edited_layer && highlight_selected_layer) {
+ int edited_z_index = edited_layer->get_z_index();
+
+ if (edited_layer->get_index_in_tile_map() >= 0) {
+ // For the TileMap node.
+ TileMap *tile_map = Object::cast_to(edited_layer->get_parent());
+ ERR_FAIL_NULL(tile_map);
+
+ bool passed = false;
+ for (int i = 0; i < tile_map->get_layers_count(); i++) {
+ TileMapLayer *layer = Object::cast_to(tile_map->get_child(i));
+ if (layer == edited_layer) {
+ passed = true;
+ layer->set_highlight_mode(TileMapLayer::HIGHLIGHT_MODE_DEFAULT);
+ } else {
+ if (passed || layer->get_z_index() > edited_z_index) {
+ layer->set_highlight_mode(TileMapLayer::HIGHLIGHT_MODE_ABOVE);
+ } else {
+ layer->set_highlight_mode(TileMapLayer::HIGHLIGHT_MODE_BELOW);
+ }
+ }
+ }
+ } else {
+ // Update highlight mode for independent layers.
+ _update_tile_map_layers_in_scene_list_cache();
+ bool passed = false;
+ for (TileMapLayer *layer : tile_map_layers_in_scene_cache) {
+ if (layer == edited_layer) {
+ passed = true;
+ layer->set_highlight_mode(TileMapLayer::HIGHLIGHT_MODE_DEFAULT);
+ } else {
+ if (passed || layer->get_z_index() > edited_z_index) {
+ layer->set_highlight_mode(TileMapLayer::HIGHLIGHT_MODE_ABOVE);
+ } else {
+ layer->set_highlight_mode(TileMapLayer::HIGHLIGHT_MODE_BELOW);
+ }
+ }
+ }
+ }
+ }
}
void TileMapLayerEditor::_highlight_selected_layer_button_toggled(bool p_pressed) {
TileMapLayer *edited_layer = _get_edited_layer();
- ERR_FAIL_NULL(edited_layer);
+ if (!edited_layer) {
+ return;
+ }
- TileMapLayerGroup *tile_map_layer_group = Object::cast_to(edited_layer->get_parent());
- ERR_FAIL_NULL(tile_map_layer_group);
-
- tile_map_layer_group->set_highlight_selected_layer(p_pressed);
+ EditorSettings::get_singleton()->set("editors/tiles_editor/highlight_selected_layer", p_pressed);
+ _update_all_layers_highlighting();
}
void TileMapLayerEditor::_advanced_menu_button_id_pressed(int p_id) {
@@ -3686,12 +3892,12 @@ void TileMapLayerEditor::_advanced_menu_button_id_pressed(int p_id) {
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
- if (p_id == 0) { // Replace Tile Proxies
+ if (p_id == ADVANCED_MENU_REPLACE_WITH_PROXIES) { // Replace Tile Proxies
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Replace Tiles with Proxies"));
TypedArray used_cells = edited_layer->get_used_cells();
@@ -3709,32 +3915,75 @@ void TileMapLayerEditor::_advanced_menu_button_id_pressed(int p_id) {
}
}
+ undo_redo->commit_action();
+ } else if (p_id == ADVANCED_MENU_EXTRACT_TILE_MAP_LAYERS) { // Transform internal TileMap layers into TileMapLayers.
+ ERR_FAIL_COND(edited_layer->get_index_in_tile_map() < 0);
+
+ EditorNode *en = EditorNode::get_singleton();
+ Node *edited_scene_root = en->get_edited_scene();
+ ERR_FAIL_NULL(edited_scene_root);
+
+ EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
+ undo_redo->create_action(TTR("Extract TileMap layers as individual TileMapLayer nodes"));
+
+ TileMap *tile_map = Object::cast_to(edited_layer->get_parent());
+ for (int i = 0; i < tile_map->get_layers_count(); i++) {
+ undo_redo->add_do_method(tile_map, "remove_layer", 0);
+ }
+
+ for (int i = 0; i < tile_map->get_layers_count(); i++) {
+ TileMapLayer *new_layer = tile_map->duplicate_layer_from_internal(i);
+ undo_redo->add_do_method(tile_map, "add_child", new_layer);
+ undo_redo->add_do_method(new_layer, "set_owner", edited_scene_root);
+ undo_redo->add_do_property(new_layer, "tile_set", tile_map->get_tileset()); // Workaround for a bug: #89947.
+ undo_redo->add_undo_method(tile_map, "remove_child", new_layer);
+ undo_redo->add_do_reference(new_layer);
+ }
+
+ List prop_list;
+ tile_map->get_property_list(&prop_list);
+ for (PropertyInfo &prop : prop_list) {
+ undo_redo->add_undo_property(tile_map, prop.name, tile_map->get(prop.name));
+ }
undo_redo->commit_action();
}
}
void TileMapLayerEditor::_update_bottom_panel() {
const TileMapLayer *edited_layer = _get_edited_layer();
- if (!edited_layer) {
- return;
+ Ref tile_set;
+ if (edited_layer) {
+ tile_set = edited_layer->get_tile_set();
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ // Update state labels.
+ if (is_multi_node_edit) {
+ cant_edit_label->set_text(TTR("Can't edit multiple layers at once."));
+ cant_edit_label->show();
+ } else if (!edited_layer) {
+ cant_edit_label->set_text(TTR("The selected TileMap has no layer to edit."));
+ cant_edit_label->show();
+ } else if (!edited_layer->is_enabled() || !edited_layer->is_visible_in_tree()) {
+ cant_edit_label->set_text(TTR("The edited layer is disabled or invisible"));
+ cant_edit_label->show();
+ } else if (tile_set.is_null()) {
+ cant_edit_label->set_text(TTR("The edited TileMap or TileMapLayer node has no TileSet resource.\nCreate or load a TileSet resource in the Tile Set property in the inspector."));
+ cant_edit_label->show();
+ } else {
+ cant_edit_label->hide();
+ }
- // Update the visibility of controls.
- missing_tileset_label->set_visible(tile_set.is_null());
+ // Update tabs visibility.
for (TileMapLayerSubEditorPlugin::TabData &tab_data : tabs_data) {
tab_data.panel->hide();
}
- if (tile_set.is_valid()) {
- tabs_data[tabs_bar->get_current_tab()].panel->show();
- }
+ tabs_data[tabs_bar->get_current_tab()].panel->set_visible(!cant_edit_label->is_visible());
}
Vector TileMapLayerEditor::get_line(const TileMapLayer *p_tile_map_layer, Vector2i p_from_cell, Vector2i p_to_cell) {
ERR_FAIL_NULL_V(p_tile_map_layer, Vector());
- Ref tile_set = p_tile_map_layer->get_effective_tile_set();
+ Ref tile_set = p_tile_map_layer->get_tile_set();
ERR_FAIL_COND_V(tile_set.is_null(), Vector());
if (tile_set->get_tile_shape() == TileSet::TILE_SHAPE_SQUARE) {
@@ -3805,7 +4054,7 @@ Vector TileMapLayerEditor::get_line(const TileMapLayer *p_tile_map_lay
}
void TileMapLayerEditor::_tile_map_layer_changed() {
- tileset_changed_needs_update = true;
+ tile_map_layer_changed_needs_update = true;
}
void TileMapLayerEditor::_tab_changed(int p_tab_id) {
@@ -3825,7 +4074,7 @@ void TileMapLayerEditor::_tab_changed(int p_tab_id) {
TileMapLayer *tile_map_layer = _get_edited_layer();
if (tile_map_layer) {
- if (tile_map_layer->get_effective_tile_set().is_valid()) {
+ if (tile_map_layer->get_tile_set().is_valid()) {
tabs_data[tabs_bar->get_current_tab()].panel->show();
}
}
@@ -3841,36 +4090,38 @@ void TileMapLayerEditor::_layers_select_next_or_previous(bool p_next) {
return;
}
- TileMapLayerGroup *tile_map_layer_group = Object::cast_to(edited_layer->get_parent());
- if (!tile_map_layer_group) {
- return;
- }
+ EditorNode *en = EditorNode::get_singleton();
+ Node *edited_scene_root = en->get_edited_scene();
+ ERR_FAIL_NULL(edited_scene_root);
+ TileMapLayer *new_selected_layer = nullptr;
int inc = p_next ? 1 : -1;
- int index = Math::posmod(edited_layer->get_index() + inc, tile_map_layer_group->get_child_count());
- const TileMapLayer *new_selected_layer = Object::cast_to(tile_map_layer_group->get_child(index));
- while (new_selected_layer != edited_layer) {
- if (new_selected_layer && new_selected_layer->is_enabled()) {
- break;
+ if (edited_layer->get_index_in_tile_map() >= 0) {
+ // Part of a TileMap.
+ TileMap *tile_map = Object::cast_to(edited_layer->get_parent());
+ new_selected_layer = Object::cast_to(tile_map->get_child(Math::posmod(edited_layer->get_index_in_tile_map() + inc, tile_map->get_layers_count())));
+ } else {
+ // Individual layer.
+ _update_tile_map_layers_in_scene_list_cache();
+ int edited_index = -1;
+ for (int i = 0; i < tile_map_layers_in_scene_cache.size(); i++) {
+ if (tile_map_layers_in_scene_cache[i] == edited_layer) {
+ edited_index = i;
+ break;
+ }
}
- index = Math::posmod((index + inc), tile_map_layer_group->get_child_count());
- new_selected_layer = Object::cast_to(tile_map_layer_group->get_child(index));
+ new_selected_layer = tile_map_layers_in_scene_cache[Math::posmod(edited_index + inc, tile_map_layers_in_scene_cache.size())];
}
- if (new_selected_layer != edited_layer) {
- emit_signal("change_selected_layer_request", new_selected_layer->get_name());
- }
-}
+ ERR_FAIL_NULL(new_selected_layer);
-void TileMapLayerEditor::_update_highlighting_toggle() {
- const TileMapLayer *edited_layer = _get_edited_layer();
- if (!edited_layer) {
- return;
- }
-
- TileMapLayerGroup *tile_map_layer_group = Object::cast_to(edited_layer->get_parent());
- if (tile_map_layer_group) {
- toggle_highlight_selected_layer_button->set_pressed(tile_map_layer_group->is_highlighting_selected_layer());
+ if (edited_layer->get_index_in_tile_map() < 0) {
+ // Only if not part of a TileMap.
+ en->edit_node(new_selected_layer);
+ en->get_editor_selection()->clear();
+ en->get_editor_selection()->add_node(new_selected_layer);
+ } else {
+ edit(new_selected_layer);
}
}
@@ -3966,7 +4217,7 @@ void TileMapLayerEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
return;
}
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_null()) {
return;
}
@@ -3994,29 +4245,25 @@ void TileMapLayerEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
}
if (!source || !source->has_tile(tile_atlas_coords) || !source->has_alternative_tile(tile_atlas_coords, tile_alternative_tile)) {
- // Generate a random color from the hashed values of the tiles.
- Array a = tile_set->map_tile_proxy(tile_source_id, tile_atlas_coords, tile_alternative_tile);
- if (int(a[0]) == tile_source_id && Vector2i(a[1]) == tile_atlas_coords && int(a[2]) == tile_alternative_tile) {
- // Only display the pattern if we have no proxy tile.
- Array to_hash;
- to_hash.push_back(tile_source_id);
- to_hash.push_back(tile_atlas_coords);
- to_hash.push_back(tile_alternative_tile);
- uint32_t hash = RandomPCG(to_hash.hash()).rand();
+ // Generate a random color from the hashed identifier of the tiles.
+ Array to_hash;
+ to_hash.push_back(tile_source_id);
+ to_hash.push_back(tile_atlas_coords);
+ to_hash.push_back(tile_alternative_tile);
+ uint32_t hash = RandomPCG(to_hash.hash()).rand();
- Color color;
- color = color.from_hsv(
- (float)((hash >> 24) & 0xFF) / 256.0,
- Math::lerp(0.5, 1.0, (float)((hash >> 16) & 0xFF) / 256.0),
- Math::lerp(0.5, 1.0, (float)((hash >> 8) & 0xFF) / 256.0),
- 0.8);
+ Color color;
+ color = color.from_hsv(
+ (float)((hash >> 24) & 0xFF) / 256.0,
+ Math::lerp(0.5, 1.0, (float)((hash >> 16) & 0xFF) / 256.0),
+ Math::lerp(0.5, 1.0, (float)((hash >> 8) & 0xFF) / 256.0),
+ 0.8);
- // Draw the scaled tile.
- Transform2D tile_xform;
- tile_xform.set_origin(tile_set->map_to_local(coords));
- tile_xform.set_scale(tile_shape_size);
- tile_set->draw_tile_shape(p_overlay, xform * tile_xform, color, true, warning_pattern_texture);
- }
+ // Display the warning pattern.
+ Transform2D tile_xform;
+ tile_xform.set_origin(tile_set->map_to_local(coords));
+ tile_xform.set_scale(tile_shape_size);
+ tile_set->draw_tile_shape(p_overlay, xform * tile_xform, color, true, warning_pattern_texture);
// Draw the warning icon.
Vector2::Axis min_axis = missing_tile_texture->get_size().min_axis_index();
@@ -4092,75 +4339,50 @@ void TileMapLayerEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
tabs_plugins[tabs_bar->get_current_tab()]->forward_canvas_draw_over_viewport(p_overlay);
}
-void TileMapLayerEditor::edit(TileMapLayer *p_tile_map_layer) {
- if (p_tile_map_layer && p_tile_map_layer->get_instance_id() == edited_tile_map_layer_id) {
+void TileMapLayerEditor::edit(Object *p_edited) {
+ if (p_edited && p_edited->get_instance_id() == edited_tile_map_layer_id) {
return;
}
+ _clear_all_layers_highlighting();
+
// Disconnect to changes.
TileMapLayer *tile_map_layer = _get_edited_layer();
if (tile_map_layer) {
tile_map_layer->disconnect("changed", callable_mp(this, &TileMapLayerEditor::_tile_map_layer_changed));
+ tile_map_layer->disconnect("visibility_changed", callable_mp(this, &TileMapLayerEditor::_tile_map_layer_changed));
}
// Update the edited layer.
- if (p_tile_map_layer) {
+ TileMapLayer *new_layer = Object::cast_to(p_edited);
+ if (new_layer) {
// Change the edited object.
- edited_tile_map_layer_id = p_tile_map_layer->get_instance_id();
+ edited_tile_map_layer_id = new_layer->get_instance_id();
tile_map_layer = _get_edited_layer();
// Connect to changes.
if (!tile_map_layer->is_connected("changed", callable_mp(this, &TileMapLayerEditor::_tile_map_layer_changed))) {
tile_map_layer->connect("changed", callable_mp(this, &TileMapLayerEditor::_tile_map_layer_changed));
+ tile_map_layer->connect("visibility_changed", callable_mp(this, &TileMapLayerEditor::_tile_map_layer_changed));
}
} else {
edited_tile_map_layer_id = ObjectID();
}
- update_layers_selector();
- _update_highlighting_toggle();
+ // Check if we are trying to use a MultiNodeEdit.
+ is_multi_node_edit = Object::cast_to(p_edited);
- // Call the plugins.
+ // Call the plugins and update everything.
tabs_plugins[tabs_bar->get_current_tab()]->edit(edited_tile_map_layer_id);
+ _update_layers_selector();
+ _update_all_layers_highlighting();
_tile_map_layer_changed();
}
-void TileMapLayerEditor::update_layers_selector() {
- const TileMapLayer *edited_layer = _get_edited_layer();
- if (!edited_layer) {
- return;
- }
-
- TileMapLayerGroup *tile_map_layer_group = Object::cast_to(edited_layer->get_parent());
- if (tile_map_layer_group) {
- // Update the selector
- layers_selection_button->show();
- layers_selection_button->clear();
-
- // Build the list of layers.
- for (int i = 0; i < tile_map_layer_group->get_child_count(); i++) {
- const TileMapLayer *layer = Object::cast_to(tile_map_layer_group->get_child(i));
- if (layer) {
- int index = layers_selection_button->get_item_count();
- layers_selection_button->add_item(layer->get_name());
- layers_selection_button->set_item_disabled(index, !layer->is_enabled());
- layers_selection_button->set_item_metadata(index, layer->get_name());
- if (edited_layer == layer) {
- layers_selection_button->select(index);
- }
- }
- }
-
- // Disable the button if there's no layer to select.
- layers_selection_button->set_disabled(false);
- if (layers_selection_button->get_item_count() == 0) {
- layers_selection_button->set_disabled(true);
- layers_selection_button->set_text(TTR("No Layers"));
- }
- } else {
- layers_selection_button->hide();
- }
+void TileMapLayerEditor::set_show_layer_selector(bool p_show_layer_selector) {
+ show_layers_selector = p_show_layer_selector;
+ _update_layers_selector();
}
TileMapLayerEditor::TileMapLayerEditor() {
@@ -4210,13 +4432,36 @@ TileMapLayerEditor::TileMapLayerEditor() {
tile_map_toolbar->add_child(c);
// Layer selector.
+ layer_selection_hbox = memnew(HBoxContainer);
+ tile_map_toolbar->add_child(layer_selection_hbox);
+
layers_selection_button = memnew(OptionButton);
layers_selection_button->set_custom_minimum_size(Size2(200, 0));
layers_selection_button->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
layers_selection_button->set_tooltip_text(TTR("TileMap Layers"));
layers_selection_button->connect("item_selected", callable_mp(this, &TileMapLayerEditor::_layers_selection_item_selected));
- tile_map_toolbar->add_child(layers_selection_button);
+ layer_selection_hbox->add_child(layers_selection_button);
+ select_previous_layer = memnew(Button);
+ select_previous_layer->set_theme_type_variation("FlatButton");
+ select_previous_layer->set_tooltip_text(TTR("Select previous layer"));
+ select_previous_layer->connect("pressed", callable_mp(this, &TileMapLayerEditor::_select_previous_layer_pressed));
+ layer_selection_hbox->add_child(select_previous_layer);
+
+ select_next_layer = memnew(Button);
+ select_next_layer->set_theme_type_variation("FlatButton");
+ select_next_layer->set_tooltip_text(TTR("Select next layer"));
+ select_next_layer->connect("pressed", callable_mp(this, &TileMapLayerEditor::_select_next_layer_pressed));
+ layer_selection_hbox->add_child(select_next_layer);
+
+ select_all_layers = memnew(Button);
+ select_all_layers->set_theme_type_variation("FlatButton");
+ select_all_layers->set_text(TTR("Select all layers"));
+ select_all_layers->connect("pressed", callable_mp(this, &TileMapLayerEditor::_select_all_layers_pressed));
+ select_all_layers->set_tooltip_text(TTR("Select all TileMapLayers in scene"));
+ layer_selection_hbox->add_child(select_all_layers);
+
+ // Highlighting selected layer.
toggle_highlight_selected_layer_button = memnew(Button);
toggle_highlight_selected_layer_button->set_theme_type_variation("FlatButton");
toggle_highlight_selected_layer_button->set_toggle_mode(true);
@@ -4239,18 +4484,19 @@ TileMapLayerEditor::TileMapLayerEditor() {
advanced_menu_button = memnew(MenuButton);
advanced_menu_button->set_flat(false);
advanced_menu_button->set_theme_type_variation("FlatButton");
- advanced_menu_button->get_popup()->add_item(TTR("Automatically Replace Tiles with Proxies"));
+ advanced_menu_button->get_popup()->add_item(TTR("Automatically Replace Tiles with Proxies"), ADVANCED_MENU_REPLACE_WITH_PROXIES);
+ advanced_menu_button->get_popup()->add_item(TTR("Extract TileMap layers as individual TileMapLayer nodes"), ADVANCED_MENU_EXTRACT_TILE_MAP_LAYERS);
advanced_menu_button->get_popup()->connect("id_pressed", callable_mp(this, &TileMapLayerEditor::_advanced_menu_button_id_pressed));
tile_map_toolbar->add_child(advanced_menu_button);
- missing_tileset_label = memnew(Label);
- missing_tileset_label->set_text(TTR("The edited TileMap node has no TileSet resource.\nCreate or load a TileSet resource in the Tile Set property in the inspector."));
- missing_tileset_label->set_h_size_flags(SIZE_EXPAND_FILL);
- missing_tileset_label->set_v_size_flags(SIZE_EXPAND_FILL);
- missing_tileset_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
- missing_tileset_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
- missing_tileset_label->hide();
- add_child(missing_tileset_label);
+ // A label for editing errors.
+ cant_edit_label = memnew(Label);
+ cant_edit_label->set_h_size_flags(SIZE_EXPAND_FILL);
+ cant_edit_label->set_v_size_flags(SIZE_EXPAND_FILL);
+ cant_edit_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
+ cant_edit_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
+ cant_edit_label->hide();
+ add_child(cant_edit_label);
for (unsigned int tab_index = 0; tab_index < tabs_data.size(); tab_index++) {
add_child(tabs_data[tab_index].panel);
diff --git a/editor/plugins/tiles/tile_map_layer_editor.h b/editor/plugins/tiles/tile_map_layer_editor.h
index a7fea2abcfe..26032614495 100644
--- a/editor/plugins/tiles/tile_map_layer_editor.h
+++ b/editor/plugins/tiles/tile_map_layer_editor.h
@@ -339,10 +339,16 @@ class TileMapLayerEditor : public VBoxContainer {
GDCLASS(TileMapLayerEditor, VBoxContainer);
private:
- bool tileset_changed_needs_update = false;
+ bool tile_map_layer_changed_needs_update = false;
ObjectID edited_tile_map_layer_id;
+ bool is_multi_node_edit = false;
+ Vector tile_map_layers_in_scene_cache;
+ bool layers_in_scene_list_cache_needs_update = false;
TileMapLayer *_get_edited_layer() const;
+ void _find_tile_map_layers_in_scene(Node *p_current, const Node *p_owner, Vector &r_list) const;
+ void _update_tile_map_layers_in_scene_list_cache();
+ void _node_change(Node *p_node);
// Vector to keep plugins.
Vector tile_map_editor_plugins;
@@ -350,20 +356,36 @@ private:
// Toolbar.
HFlowContainer *tile_map_toolbar = nullptr;
+ bool show_layers_selector = false;
+
+ HBoxContainer *layer_selection_hbox = nullptr;
+ Button *select_previous_layer = nullptr;
+ void _select_previous_layer_pressed();
+ Button *select_next_layer = nullptr;
+ void _select_next_layer_pressed();
+ Button *select_all_layers = nullptr;
+ void _select_all_layers_pressed();
OptionButton *layers_selection_button = nullptr;
void _layers_selection_item_selected(int p_index);
+ void _update_layers_selector();
Button *toggle_highlight_selected_layer_button = nullptr;
+ void _clear_all_layers_highlighting();
+ void _update_all_layers_highlighting();
void _highlight_selected_layer_button_toggled(bool p_pressed);
Button *toggle_grid_button = nullptr;
void _on_grid_toggled(bool p_pressed);
+ enum {
+ ADVANCED_MENU_REPLACE_WITH_PROXIES,
+ ADVANCED_MENU_EXTRACT_TILE_MAP_LAYERS,
+ };
MenuButton *advanced_menu_button = nullptr;
void _advanced_menu_button_id_pressed(int p_id);
// Bottom panel.
- Label *missing_tileset_label = nullptr;
+ Label *cant_edit_label = nullptr;
TabBar *tabs_bar = nullptr;
LocalVector tabs_data;
LocalVector tabs_plugins;
@@ -379,22 +401,20 @@ private:
// Updates.
void _layers_select_next_or_previous(bool p_next);
- void _update_highlighting_toggle();
// Inspector undo/redo callback.
void _move_tile_map_array_element(Object *p_undo_redo, Object *p_edited, const String &p_array_prefix, int p_from_index, int p_to_pos);
protected:
void _notification(int p_what);
- static void _bind_methods();
void _draw_shape(Control *p_control, Rect2 p_region, TileSet::TileShape p_shape, TileSet::TileOffsetAxis p_offset_axis, Color p_color);
public:
bool forward_canvas_gui_input(const Ref &p_event);
void forward_canvas_draw_over_viewport(Control *p_overlay);
- void edit(TileMapLayer *p_tile_map_layer);
- void update_layers_selector();
+ void edit(Object *p_tile_map_layer);
+ void set_show_layer_selector(bool p_show_layer_selector);
TileMapLayerEditor();
~TileMapLayerEditor();
diff --git a/editor/plugins/tiles/tiles_editor_plugin.cpp b/editor/plugins/tiles/tiles_editor_plugin.cpp
index ed21a294879..c3141beb1a3 100644
--- a/editor/plugins/tiles/tiles_editor_plugin.cpp
+++ b/editor/plugins/tiles/tiles_editor_plugin.cpp
@@ -40,6 +40,7 @@
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
#include "editor/gui/editor_bottom_panel.h"
+#include "editor/multi_node_edit.h"
#include "editor/plugins/canvas_item_editor_plugin.h"
#include "editor/themes/editor_scale.h"
#include "scene/2d/tile_map.h"
@@ -336,7 +337,7 @@ void TileMapEditorPlugin::_tile_map_layer_removed() {
void TileMapEditorPlugin::_update_tile_map() {
TileMapLayer *edited_layer = Object::cast_to(ObjectDB::get_instance(tile_map_layer_id));
if (edited_layer) {
- Ref tile_set = edited_layer->get_effective_tile_set();
+ Ref tile_set = edited_layer->get_tile_set();
if (tile_set.is_valid() && tile_set_id != tile_set->get_instance_id()) {
tile_set_plugin_singleton->edit(tile_set.ptr());
tile_set_plugin_singleton->make_visible(true);
@@ -355,38 +356,25 @@ void TileMapEditorPlugin::_select_layer(const StringName &p_name) {
ERR_FAIL_NULL(edited_layer);
Node *parent = edited_layer->get_parent();
- ERR_FAIL_NULL(parent);
-
- TileMapLayer *new_layer = Object::cast_to(parent->get_node_or_null(String(p_name)));
- edit(new_layer);
+ if (parent) {
+ TileMapLayer *new_layer = Object::cast_to(parent->get_node_or_null(String(p_name)));
+ edit(new_layer);
+ }
}
-void TileMapEditorPlugin::_edit_tile_map_layer(TileMapLayer *p_tile_map_layer) {
+void TileMapEditorPlugin::_edit_tile_map_layer(TileMapLayer *p_tile_map_layer, bool p_show_layer_selector) {
ERR_FAIL_NULL(p_tile_map_layer);
editor->edit(p_tile_map_layer);
-
- // Update the selected layers in the TileMapLayerGroup parent node.
- TileMapLayerGroup *tile_map_layer_group = Object::cast_to(p_tile_map_layer->get_parent());
- if (tile_map_layer_group) {
- Vector selected;
- selected.push_back(p_tile_map_layer->get_name());
- tile_map_layer_group->set_selected_layers(selected);
- }
+ editor->set_show_layer_selector(p_show_layer_selector);
// Update the object IDs.
tile_map_layer_id = p_tile_map_layer->get_instance_id();
p_tile_map_layer->connect("changed", callable_mp(this, &TileMapEditorPlugin::_tile_map_layer_changed));
p_tile_map_layer->connect("tree_exited", callable_mp(this, &TileMapEditorPlugin::_tile_map_layer_removed));
- if (tile_map_layer_group) {
- tile_map_group_id = tile_map_layer_group->get_instance_id();
- tile_map_layer_group->connect("child_entered_tree", callable_mp(editor, &TileMapLayerEditor::update_layers_selector).unbind(1));
- tile_map_layer_group->connect("child_exiting_tree", callable_mp(editor, &TileMapLayerEditor::update_layers_selector).unbind(1));
- tile_map_layer_group->connect("child_order_changed", callable_mp(editor, &TileMapLayerEditor::update_layers_selector));
- }
// Update the edited tileset.
- Ref tile_set = p_tile_map_layer->get_effective_tile_set();
+ Ref tile_set = p_tile_map_layer->get_tile_set();
if (tile_set.is_valid()) {
tile_set_plugin_singleton->edit(tile_set.ptr());
tile_set_plugin_singleton->make_visible(true);
@@ -397,30 +385,15 @@ void TileMapEditorPlugin::_edit_tile_map_layer(TileMapLayer *p_tile_map_layer) {
}
}
-void TileMapEditorPlugin::_edit_tile_map_layer_group(TileMapLayerGroup *p_tile_map_layer_group) {
- ERR_FAIL_NULL(p_tile_map_layer_group);
+void TileMapEditorPlugin::_edit_tile_map(TileMap *p_tile_map) {
+ ERR_FAIL_NULL(p_tile_map);
- Vector selected_layers = p_tile_map_layer_group->get_selected_layers();
-
- TileMapLayer *selected_layer = nullptr;
- if (selected_layers.size() > 0) {
- // Edit the selected layer.
- selected_layer = Object::cast_to(p_tile_map_layer_group->get_node_or_null(String(selected_layers[0])));
- }
- if (!selected_layer) {
- // Edit the first layer found.
- for (int i = 0; i < p_tile_map_layer_group->get_child_count(); i++) {
- selected_layer = Object::cast_to(p_tile_map_layer_group->get_child(i));
- if (selected_layer) {
- break;
- }
- }
- }
-
- if (selected_layer) {
- _edit_tile_map_layer(selected_layer);
+ if (p_tile_map->get_layers_count() > 0) {
+ TileMapLayer *selected_layer = Object::cast_to(p_tile_map->get_child(0));
+ _edit_tile_map_layer(selected_layer, true);
} else {
editor->edit(nullptr);
+ editor->set_show_layer_selector(false);
}
}
@@ -437,36 +410,38 @@ void TileMapEditorPlugin::edit(Object *p_object) {
edited_layer->disconnect("tree_exited", callable_mp(this, &TileMapEditorPlugin::_tile_map_layer_removed));
}
- TileMapLayerGroup *tile_map_group = Object::cast_to(ObjectDB::get_instance(tile_map_group_id));
- if (tile_map_group) {
- tile_map_group->disconnect("child_entered_tree", callable_mp(editor, &TileMapLayerEditor::update_layers_selector).unbind(1));
- tile_map_group->disconnect("child_exiting_tree", callable_mp(editor, &TileMapLayerEditor::update_layers_selector).unbind(1));
- tile_map_group->disconnect("child_order_changed", callable_mp(editor, &TileMapLayerEditor::update_layers_selector));
- }
-
tile_map_group_id = ObjectID();
tile_map_layer_id = ObjectID();
tile_set_id = ObjectID();
- TileMapLayerGroup *tile_map_layer_group = Object::cast_to(p_object);
+ TileMap *tile_map = Object::cast_to(p_object);
TileMapLayer *tile_map_layer = Object::cast_to(p_object);
- if (tile_map_layer_group) {
- _edit_tile_map_layer_group(tile_map_layer_group);
+ MultiNodeEdit *multi_node_edit = Object::cast_to(p_object);
+ if (tile_map) {
+ _edit_tile_map(tile_map);
} else if (tile_map_layer) {
- _edit_tile_map_layer(tile_map_layer);
+ _edit_tile_map_layer(tile_map_layer, false);
+ } else if (multi_node_edit) {
+ editor->edit(multi_node_edit);
} else {
- // Deselect the layer in the group.
- if (edited_layer) {
- tile_map_layer_group = Object::cast_to(edited_layer->get_parent());
- if (tile_map_layer_group) {
- tile_map_layer_group->set_selected_layers(Vector());
- }
- }
+ editor->edit(nullptr);
}
}
bool TileMapEditorPlugin::handles(Object *p_object) const {
- return Object::cast_to(p_object) != nullptr || Object::cast_to(p_object) != nullptr;
+ MultiNodeEdit *multi_node_edit = Object::cast_to(p_object);
+ Node *edited_scene = EditorNode::get_singleton()->get_edited_scene();
+ if (multi_node_edit && edited_scene) {
+ bool only_tile_map_layers = true;
+ for (int i = 0; i < multi_node_edit->get_node_count(); i++) {
+ if (!Object::cast_to(edited_scene->get_node(multi_node_edit->get_node(i)))) {
+ only_tile_map_layers = false;
+ break;
+ }
+ }
+ return only_tile_map_layers;
+ }
+ return Object::cast_to(p_object) != nullptr || Object::cast_to(p_object) != nullptr;
}
void TileMapEditorPlugin::make_visible(bool p_visible) {
@@ -509,7 +484,6 @@ TileMapEditorPlugin::TileMapEditorPlugin() {
editor->set_h_size_flags(Control::SIZE_EXPAND_FILL);
editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
editor->set_custom_minimum_size(Size2(0, 200) * EDSCALE);
- editor->connect("change_selected_layer_request", callable_mp(this, &TileMapEditorPlugin::_select_layer));
editor->hide();
button = EditorNode::get_bottom_panel()->add_item(TTR("TileMap"), editor, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_tile_map_bottom_panel", TTR("Toggle TileMap Bottom Panel")));
diff --git a/editor/plugins/tiles/tiles_editor_plugin.h b/editor/plugins/tiles/tiles_editor_plugin.h
index ac3e8986d6e..23a6a52a5c7 100644
--- a/editor/plugins/tiles/tiles_editor_plugin.h
+++ b/editor/plugins/tiles/tiles_editor_plugin.h
@@ -126,8 +126,8 @@ class TileMapEditorPlugin : public EditorPlugin {
void _update_tile_map();
void _select_layer(const StringName &p_name);
- void _edit_tile_map_layer(TileMapLayer *p_tile_map_layer);
- void _edit_tile_map_layer_group(TileMapLayerGroup *p_tile_map_layer_group);
+ void _edit_tile_map_layer(TileMapLayer *p_tile_map_layer, bool p_show_layer_selector);
+ void _edit_tile_map(TileMap *p_tile_map);
protected:
void _notification(int p_notification);
diff --git a/misc/extension_api_validation/4.2-stable.expected b/misc/extension_api_validation/4.2-stable.expected
index 3df19bb83ae..53a29fa6605 100644
--- a/misc/extension_api_validation/4.2-stable.expected
+++ b/misc/extension_api_validation/4.2-stable.expected
@@ -99,15 +99,6 @@ Validate extension JSON: Error: Field 'classes/GLTFBufferView/methods/get_indice
Change AudioStreamPlayer* is_autoplay_enabled and GLTFBufferView getters to be const.
-GH-87379
---------
-Validate extension JSON: API was removed: classes/TileMap/methods/get_tileset
-Validate extension JSON: API was removed: classes/TileMap/methods/set_tileset
-Validate extension JSON: API was removed: classes/TileMap/properties/tile_set
-
-Moved to the parent TileMapLayerGroup class. No change should be necessary.
-
-
GH-87340
--------
Validate extension JSON: JSON file: Field was added in a way that breaks compatibility 'classes/RenderingDevice/methods/screen_get_framebuffer_format': arguments
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index f8737730ba9..bbf1d09bbc8 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -32,7 +32,7 @@
#include "tile_map.compat.inc"
#include "core/core_string_names.h"
-#include "scene/2d/tile_map_layer.h"
+#include "core/io/marshalls.h"
#include "scene/gui/control.h"
#define TILEMAP_CALL_FOR_LAYER(layer, function, ...) \
@@ -49,10 +49,118 @@
ERR_FAIL_INDEX_V(layer, (int)layers.size(), err_value); \
return layers[layer]->function(__VA_ARGS__);
+void TileMap::_tile_set_changed() {
+ update_configuration_warnings();
+}
+
void TileMap::_emit_changed() {
emit_signal(CoreStringNames::get_singleton()->changed);
}
+void TileMap::_set_tile_map_data_using_compatibility_format(int p_layer, TileMapDataFormat p_format, const Vector &p_data) {
+ ERR_FAIL_INDEX(p_layer, (int)layers.size());
+ ERR_FAIL_COND(p_format >= TileMapDataFormat::TILE_MAP_DATA_FORMAT_MAX);
+#ifndef DISABLE_DEPRECATED
+ ERR_FAIL_COND_MSG(p_format != (TileMapDataFormat)(TILE_MAP_DATA_FORMAT_MAX - 1), "Old TileMap data format detected despite DISABLE_DEPRECATED being set compilation time.");
+#endif // DISABLE_DEPRECATED
+
+ // Set data for a given tile from raw data.
+ int c = p_data.size();
+ const int *r = p_data.ptr();
+
+ int offset = (p_format >= TileMapDataFormat::TILE_MAP_DATA_FORMAT_2) ? 3 : 2;
+ ERR_FAIL_COND_MSG(c % offset != 0, vformat("Corrupted tile data. Got size: %d. Expected modulo: %d", c, offset));
+
+ layers[p_layer]->clear();
+
+ for (int i = 0; i < c; i += offset) {
+ const uint8_t *ptr = (const uint8_t *)&r[i];
+ uint8_t local[12];
+ for (int j = 0; j < ((p_format >= TileMapDataFormat::TILE_MAP_DATA_FORMAT_2) ? 12 : 8); j++) {
+ local[j] = ptr[j];
+ }
+
+#ifdef BIG_ENDIAN_ENABLED
+ SWAP(local[0], local[3]);
+ SWAP(local[1], local[2]);
+ SWAP(local[4], local[7]);
+ SWAP(local[5], local[6]);
+ //TODO: ask someone to check this...
+ if (FORMAT >= FORMAT_2) {
+ SWAP(local[8], local[11]);
+ SWAP(local[9], local[10]);
+ }
+#endif
+ // Extracts position in TileMap.
+ int16_t x = decode_uint16(&local[0]);
+ int16_t y = decode_uint16(&local[2]);
+
+ if (p_format == TileMapDataFormat::TILE_MAP_DATA_FORMAT_3) {
+ uint16_t source_id = decode_uint16(&local[4]);
+ uint16_t atlas_coords_x = decode_uint16(&local[6]);
+ uint16_t atlas_coords_y = decode_uint16(&local[8]);
+ uint16_t alternative_tile = decode_uint16(&local[10]);
+ layers[p_layer]->set_cell(Vector2i(x, y), source_id, Vector2i(atlas_coords_x, atlas_coords_y), alternative_tile);
+ } else {
+#ifndef DISABLE_DEPRECATED
+ // Previous decated format.
+ uint32_t v = decode_uint32(&local[4]);
+ // Extract the transform flags that used to be in the tilemap.
+ bool flip_h = v & (1UL << 29);
+ bool flip_v = v & (1UL << 30);
+ bool transpose = v & (1UL << 31);
+ v &= (1UL << 29) - 1;
+
+ // Extract autotile/atlas coords.
+ int16_t coord_x = 0;
+ int16_t coord_y = 0;
+ if (p_format == TileMapDataFormat::TILE_MAP_DATA_FORMAT_2) {
+ coord_x = decode_uint16(&local[8]);
+ coord_y = decode_uint16(&local[10]);
+ }
+
+ if (tile_set.is_valid()) {
+ Array a = tile_set->compatibility_tilemap_map(v, Vector2i(coord_x, coord_y), flip_h, flip_v, transpose);
+ if (a.size() == 3) {
+ layers[p_layer]->set_cell(Vector2i(x, y), a[0], a[1], a[2]);
+ } else {
+ ERR_PRINT(vformat("No valid tile in Tileset for: tile:%s coords:%s flip_h:%s flip_v:%s transpose:%s", v, Vector2i(coord_x, coord_y), flip_h, flip_v, transpose));
+ }
+ } else {
+ int compatibility_alternative_tile = ((int)flip_h) + ((int)flip_v << 1) + ((int)transpose << 2);
+ layers[p_layer]->set_cell(Vector2i(x, y), v, Vector2i(coord_x, coord_y), compatibility_alternative_tile);
+ }
+#endif // DISABLE_DEPRECATED
+ }
+ }
+}
+
+Vector TileMap::_get_tile_map_data_using_compatibility_format(int p_layer) const {
+ ERR_FAIL_INDEX_V(p_layer, (int)layers.size(), Vector());
+
+ // Export tile data to raw format.
+ const HashMap tile_map_layer_data = layers[p_layer]->get_tile_map_layer_data();
+ Vector tile_data;
+ tile_data.resize(tile_map_layer_data.size() * 3);
+ int *w = tile_data.ptrw();
+
+ // Save in highest format.
+
+ int idx = 0;
+ for (const KeyValue &E : tile_map_layer_data) {
+ uint8_t *ptr = (uint8_t *)&w[idx];
+ encode_uint16((int16_t)(E.key.x), &ptr[0]);
+ encode_uint16((int16_t)(E.key.y), &ptr[2]);
+ encode_uint16(E.value.cell.source_id, &ptr[4]);
+ encode_uint16(E.value.cell.coord_x, &ptr[6]);
+ encode_uint16(E.value.cell.coord_y, &ptr[8]);
+ encode_uint16(E.value.cell.alternative_tile, &ptr[10]);
+ idx += 3;
+ }
+
+ return tile_data;
+}
+
void TileMap::_notification(int p_what) {
switch (p_what) {
case TileMap::NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
@@ -199,6 +307,34 @@ void TileMap::draw_tile(RID p_canvas_item, const Vector2 &p_position, const Ref<
}
}
+void TileMap::set_tileset(const Ref &p_tileset) {
+ if (p_tileset == tile_set) {
+ return;
+ }
+
+ // Set the tileset, registering to its changes.
+ if (tile_set.is_valid()) {
+ tile_set->disconnect_changed(callable_mp(this, &TileMap::_tile_set_changed));
+ }
+
+ tile_set = p_tileset;
+
+ if (tile_set.is_valid()) {
+ tile_set->connect_changed(callable_mp(this, &TileMap::_tile_set_changed));
+ }
+
+ for (int i = 0; i < get_child_count(); i++) {
+ TileMapLayer *layer = Object::cast_to(get_child(i));
+ if (layer) {
+ layer->set_tile_set(tile_set);
+ }
+ }
+}
+
+Ref TileMap::get_tileset() const {
+ return tile_set;
+}
+
int TileMap::get_layers_count() const {
return layers.size();
}
@@ -215,6 +351,7 @@ void TileMap::add_layer(int p_to_pos) {
layers.insert(p_to_pos, new_layer);
add_child(new_layer, false, INTERNAL_MODE_FRONT);
new_layer->set_name(vformat("Layer%d", p_to_pos));
+ new_layer->set_tile_set(tile_set);
move_child(new_layer, p_to_pos);
for (uint32_t i = 0; i < layers.size(); i++) {
layers[i]->set_as_tile_map_internal_node(i);
@@ -251,8 +388,11 @@ void TileMap::remove_layer(int p_layer) {
ERR_FAIL_INDEX(p_layer, (int)layers.size());
// Clear before removing the layer.
- layers[p_layer]->queue_free();
+ TileMapLayer *removed = layers[p_layer];
layers.remove_at(p_layer);
+ remove_child(removed);
+ removed->queue_free();
+
for (uint32_t i = 0; i < layers.size(); i++) {
layers[i]->set_as_tile_map_internal_node(i);
}
@@ -349,7 +489,7 @@ void TileMap::set_collision_visibility_mode(TileMap::VisibilityMode p_show_colli
}
collision_visibility_mode = p_show_collision;
for (TileMapLayer *layer : layers) {
- layer->set_collision_visibility_mode(TileMapLayer::VisibilityMode(p_show_collision));
+ layer->set_collision_visibility_mode(TileMapLayer::DebugVisibilityMode(p_show_collision));
}
_emit_changed();
}
@@ -364,7 +504,7 @@ void TileMap::set_navigation_visibility_mode(TileMap::VisibilityMode p_show_navi
}
navigation_visibility_mode = p_show_navigation;
for (TileMapLayer *layer : layers) {
- layer->set_navigation_visibility_mode(TileMapLayer::VisibilityMode(p_show_navigation));
+ layer->set_navigation_visibility_mode(TileMapLayer::DebugVisibilityMode(p_show_navigation));
}
_emit_changed();
}
@@ -394,19 +534,85 @@ void TileMap::erase_cell(int p_layer, const Vector2i &p_coords) {
}
int TileMap::get_cell_source_id(int p_layer, const Vector2i &p_coords, bool p_use_proxies) const {
- TILEMAP_CALL_FOR_LAYER_V(p_layer, TileSet::INVALID_SOURCE, get_cell_source_id, p_coords, p_use_proxies);
+ if (p_use_proxies && tile_set.is_valid()) {
+ if (p_layer < 0) {
+ p_layer = layers.size() + p_layer;
+ }
+ ERR_FAIL_INDEX_V(p_layer, (int)layers.size(), TileSet::INVALID_SOURCE);
+
+ int source_id = layers[p_layer]->get_cell_source_id(p_coords);
+ Vector2i atlas_coords = layers[p_layer]->get_cell_atlas_coords(p_coords);
+ int alternative_id = layers[p_layer]->get_cell_alternative_tile(p_coords);
+
+ Array arr = tile_set->map_tile_proxy(source_id, atlas_coords, alternative_id);
+ ERR_FAIL_COND_V(arr.size() != 3, TileSet::INVALID_SOURCE);
+ return arr[0];
+ } else {
+ TILEMAP_CALL_FOR_LAYER_V(p_layer, TileSet::INVALID_SOURCE, get_cell_source_id, p_coords);
+ }
}
Vector2i TileMap::get_cell_atlas_coords(int p_layer, const Vector2i &p_coords, bool p_use_proxies) const {
- TILEMAP_CALL_FOR_LAYER_V(p_layer, TileSetSource::INVALID_ATLAS_COORDS, get_cell_atlas_coords, p_coords, p_use_proxies);
+ if (p_use_proxies && tile_set.is_valid()) {
+ if (p_layer < 0) {
+ p_layer = layers.size() + p_layer;
+ }
+ ERR_FAIL_INDEX_V(p_layer, (int)layers.size(), TileSetAtlasSource::INVALID_ATLAS_COORDS);
+
+ int source_id = layers[p_layer]->get_cell_source_id(p_coords);
+ Vector2i atlas_coords = layers[p_layer]->get_cell_atlas_coords(p_coords);
+ int alternative_id = layers[p_layer]->get_cell_alternative_tile(p_coords);
+
+ Array arr = tile_set->map_tile_proxy(source_id, atlas_coords, alternative_id);
+ ERR_FAIL_COND_V(arr.size() != 3, TileSetSource::INVALID_ATLAS_COORDS);
+ return arr[1];
+ } else {
+ TILEMAP_CALL_FOR_LAYER_V(p_layer, TileSetSource::INVALID_ATLAS_COORDS, get_cell_atlas_coords, p_coords);
+ }
}
int TileMap::get_cell_alternative_tile(int p_layer, const Vector2i &p_coords, bool p_use_proxies) const {
- TILEMAP_CALL_FOR_LAYER_V(p_layer, TileSetSource::INVALID_TILE_ALTERNATIVE, get_cell_alternative_tile, p_coords, p_use_proxies);
+ if (p_use_proxies && tile_set.is_valid()) {
+ if (p_layer < 0) {
+ p_layer = layers.size() + p_layer;
+ }
+ ERR_FAIL_INDEX_V(p_layer, (int)layers.size(), TileSetSource::INVALID_TILE_ALTERNATIVE);
+
+ int source_id = layers[p_layer]->get_cell_source_id(p_coords);
+ Vector2i atlas_coords = layers[p_layer]->get_cell_atlas_coords(p_coords);
+ int alternative_id = layers[p_layer]->get_cell_alternative_tile(p_coords);
+
+ Array arr = tile_set->map_tile_proxy(source_id, atlas_coords, alternative_id);
+ ERR_FAIL_COND_V(arr.size() != 3, TileSetSource::INVALID_TILE_ALTERNATIVE);
+ return arr[2];
+ } else {
+ TILEMAP_CALL_FOR_LAYER_V(p_layer, TileSetSource::INVALID_TILE_ALTERNATIVE, get_cell_alternative_tile, p_coords);
+ }
}
TileData *TileMap::get_cell_tile_data(int p_layer, const Vector2i &p_coords, bool p_use_proxies) const {
- TILEMAP_CALL_FOR_LAYER_V(p_layer, nullptr, get_cell_tile_data, p_coords, p_use_proxies);
+ if (p_use_proxies && tile_set.is_valid()) {
+ if (p_layer < 0) {
+ p_layer = layers.size() + p_layer;
+ }
+ ERR_FAIL_INDEX_V(p_layer, (int)layers.size(), nullptr);
+
+ int source_id = layers[p_layer]->get_cell_source_id(p_coords);
+ Vector2i atlas_coords = layers[p_layer]->get_cell_atlas_coords(p_coords);
+ int alternative_id = layers[p_layer]->get_cell_alternative_tile(p_coords);
+
+ Array arr = tile_set->map_tile_proxy(source_id, atlas_coords, alternative_id);
+ ERR_FAIL_COND_V(arr.size() != 3, nullptr);
+
+ Ref atlas_source = tile_set->get_source(arr[0]);
+ if (atlas_source.is_valid()) {
+ return atlas_source->get_tile_data(arr[1], arr[2]);
+ } else {
+ return nullptr;
+ }
+ } else {
+ TILEMAP_CALL_FOR_LAYER_V(p_layer, nullptr, get_cell_tile_data, p_coords);
+ }
}
Ref TileMap::get_pattern(int p_layer, TypedArray p_coords_array) {
@@ -451,7 +657,10 @@ void TileMap::set_cells_terrain_path(int p_layer, TypedArray p_path, i
}
TileMapCell TileMap::get_cell(int p_layer, const Vector2i &p_coords, bool p_use_proxies) const {
- TILEMAP_CALL_FOR_LAYER_V(p_layer, TileMapCell(), get_cell, p_coords, p_use_proxies);
+ if (p_use_proxies) {
+ WARN_DEPRECATED_MSG("use_proxies is deprecated.");
+ }
+ TILEMAP_CALL_FOR_LAYER_V(p_layer, TileMapCell(), get_cell, p_coords);
}
Vector2i TileMap::get_coords_for_body_rid(RID p_physics_body) {
@@ -478,6 +687,13 @@ void TileMap::fix_invalid_tiles() {
}
}
+#ifdef TOOLS_ENABLED
+TileMapLayer *TileMap::duplicate_layer_from_internal(int p_layer) {
+ ERR_FAIL_INDEX_V(p_layer, (int)layers.size(), nullptr);
+ return Object::cast_to(layers[p_layer]->duplicate(DUPLICATE_USE_INSTANTIATION | DUPLICATE_FROM_EDITOR));
+}
+#endif // TOOLS_ENABLED
+
void TileMap::clear_layer(int p_layer) {
TILEMAP_CALL_FOR_LAYER(p_layer, clear)
}
@@ -540,10 +756,11 @@ bool TileMap::_set(const StringName &p_name, const Variant &p_value) {
add_child(new_layer, false, INTERNAL_MODE_FRONT);
new_layer->set_as_tile_map_internal_node(0);
new_layer->set_name("Layer0");
+ new_layer->set_tile_set(tile_set);
new_layer->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &TileMap::_emit_changed));
layers.push_back(new_layer);
}
- layers[0]->set_tile_data(format, p_value);
+ _set_tile_map_data_using_compatibility_format(0, format, p_value);
_emit_changed();
return true;
}
@@ -565,6 +782,7 @@ bool TileMap::_set(const StringName &p_name, const Variant &p_value) {
add_child(new_layer, false, INTERNAL_MODE_FRONT);
new_layer->set_as_tile_map_internal_node(index);
new_layer->set_name(vformat("Layer%d", index));
+ new_layer->set_tile_set(tile_set);
new_layer->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &TileMap::_emit_changed));
layers.push_back(new_layer);
}
@@ -596,7 +814,7 @@ bool TileMap::_set(const StringName &p_name, const Variant &p_value) {
set_layer_navigation_enabled(index, p_value);
return true;
} else if (components[1] == "tile_data") {
- layers[index]->set_tile_data(format, p_value);
+ _set_tile_map_data_using_compatibility_format(index, format, p_value);
_emit_changed();
return true;
} else {
@@ -609,7 +827,7 @@ bool TileMap::_set(const StringName &p_name, const Variant &p_value) {
bool TileMap::_get(const StringName &p_name, Variant &r_ret) const {
Vector components = String(p_name).split("/", true, 2);
if (p_name == "format") {
- r_ret = TileMapDataFormat::FORMAT_MAX - 1; // When saving, always save highest format.
+ r_ret = TileMapDataFormat::TILE_MAP_DATA_FORMAT_MAX - 1; // When saving, always save highest format.
return true;
}
#ifndef DISABLE_DEPRECATED
@@ -646,7 +864,7 @@ bool TileMap::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = is_layer_navigation_enabled(index);
return true;
} else if (components[1] == "tile_data") {
- r_ret = layers[index]->get_tile_data();
+ r_ret = _get_tile_map_data_using_compatibility_format(index);
return true;
} else {
return false;
@@ -899,6 +1117,9 @@ void TileMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("force_update", "layer"), &TileMap::force_update, DEFVAL(-1));
#endif // DISABLE_DEPRECATED
+ ClassDB::bind_method(D_METHOD("set_tileset", "tileset"), &TileMap::set_tileset);
+ ClassDB::bind_method(D_METHOD("get_tileset"), &TileMap::get_tileset);
+
ClassDB::bind_method(D_METHOD("set_rendering_quadrant_size", "size"), &TileMap::set_rendering_quadrant_size);
ClassDB::bind_method(D_METHOD("get_rendering_quadrant_size"), &TileMap::get_rendering_quadrant_size);
@@ -969,6 +1190,7 @@ void TileMap::_bind_methods() {
GDVIRTUAL_BIND(_use_tile_data_runtime_update, "layer", "coords");
GDVIRTUAL_BIND(_tile_data_runtime_update, "layer", "coords", "tile_data");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tile_set", PROPERTY_HINT_RESOURCE_TYPE, "TileSet"), "set_tileset", "get_tileset");
ADD_PROPERTY(PropertyInfo(Variant::INT, "rendering_quadrant_size", PROPERTY_HINT_RANGE, "1,128,1"), "set_rendering_quadrant_size", "get_rendering_quadrant_size");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision_animatable"), "set_collision_animatable", "is_collision_animatable");
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_visibility_mode", PROPERTY_HINT_ENUM, "Default,Force Show,Force Hide"), "set_collision_visibility_mode", "get_collision_visibility_mode");
@@ -976,7 +1198,7 @@ void TileMap::_bind_methods() {
ADD_ARRAY("layers", "layer_");
- ADD_PROPERTY_DEFAULT("format", TileMapDataFormat::FORMAT_1);
+ ADD_PROPERTY_DEFAULT("format", TileMapDataFormat::TILE_MAP_DATA_FORMAT_1);
ADD_SIGNAL(MethodInfo(CoreStringNames::get_singleton()->changed));
@@ -990,6 +1212,7 @@ TileMap::TileMap() {
add_child(new_layer, false, INTERNAL_MODE_FRONT);
new_layer->set_as_tile_map_internal_node(0);
new_layer->set_name("Layer0");
+ new_layer->set_tile_set(tile_set);
new_layer->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &TileMap::_emit_changed));
layers.push_back(new_layer);
default_layer = memnew(TileMapLayer);
diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h
index edea90fa95f..41068ea9783 100644
--- a/scene/2d/tile_map.h
+++ b/scene/2d/tile_map.h
@@ -31,7 +31,7 @@
#ifndef TILE_MAP_H
#define TILE_MAP_H
-#include "scene/2d/tile_map_layer_group.h"
+#include "scene/2d/tile_map_layer.h"
#include "scene/resources/2d/tile_set.h"
class Control;
@@ -39,14 +39,14 @@ class TileMapLayer;
class TerrainConstraint;
enum TileMapDataFormat {
- FORMAT_1 = 0,
- FORMAT_2,
- FORMAT_3,
- FORMAT_MAX,
+ TILE_MAP_DATA_FORMAT_1 = 0,
+ TILE_MAP_DATA_FORMAT_2,
+ TILE_MAP_DATA_FORMAT_3,
+ TILE_MAP_DATA_FORMAT_MAX,
};
-class TileMap : public TileMapLayerGroup {
- GDCLASS(TileMap, TileMapLayerGroup)
+class TileMap : public Node2D {
+ GDCLASS(TileMap, Node2D)
public:
// Kept for compatibility, but should use TileMapLayer::VisibilityMode instead.
@@ -60,11 +60,12 @@ private:
friend class TileSetPlugin;
// A compatibility enum to specify how is the data if formatted.
- mutable TileMapDataFormat format = TileMapDataFormat::FORMAT_3;
+ mutable TileMapDataFormat format = TileMapDataFormat::TILE_MAP_DATA_FORMAT_3;
static constexpr float FP_ADJUST = 0.00001;
// Properties.
+ Ref tile_set;
int rendering_quadrant_size = 16;
bool collision_animatable = false;
VisibilityMode collision_visibility_mode = VISIBILITY_MODE_DEFAULT;
@@ -78,8 +79,14 @@ private:
Transform2D last_valid_transform;
Transform2D new_transform;
+ void _tile_set_changed();
+
void _emit_changed();
+ // Kept for compatibility with TileMap. With TileMapLayers as individual nodes, the format is stored directly in the array.
+ void _set_tile_map_data_using_compatibility_format(int p_layer, TileMapDataFormat p_format, const Vector &p_data);
+ Vector _get_tile_map_data_using_compatibility_format(int p_layer) const;
+
protected:
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
@@ -114,6 +121,10 @@ public:
static void draw_tile(RID p_canvas_item, const Vector2 &p_position, const Ref p_tile_set, int p_atlas_source_id, const Vector2i &p_atlas_coords, int p_alternative_tile, int p_frame = -1, Color p_modulation = Color(1.0, 1.0, 1.0, 1.0), const TileData *p_tile_data_override = nullptr, real_t p_normalized_animation_offset = 0.0);
+ // Accessors.
+ void set_tileset(const Ref &p_tileset);
+ Ref get_tileset() const;
+
// Layers management.
int get_layers_count() const;
void add_layer(int p_to_pos);
@@ -200,6 +211,11 @@ public:
// Fixing and clearing methods.
void fix_invalid_tiles();
+#ifdef TOOLS_ENABLED
+ // Moving layers outside of TileMap.
+ TileMapLayer *duplicate_layer_from_internal(int p_layer);
+#endif // TOOLS_ENABLED
+
// Clears tiles from a given layer.
void clear_layer(int p_layer);
void clear();
diff --git a/scene/2d/tile_map_layer.cpp b/scene/2d/tile_map_layer.cpp
index 84c4c43a5ad..3f10eb76610 100644
--- a/scene/2d/tile_map_layer.cpp
+++ b/scene/2d/tile_map_layer.cpp
@@ -32,6 +32,7 @@
#include "core/core_string_names.h"
#include "core/io/marshalls.h"
+#include "scene/2d/tile_map.h"
#include "scene/gui/control.h"
#include "scene/resources/world_2d.h"
#include "servers/navigation_server_2d.h"
@@ -51,11 +52,10 @@ Vector2i TileMapLayer::_coords_to_debug_quadrant_coords(const Vector2i &p_coords
}
void TileMapLayer::_debug_update() {
- const Ref &tile_set = get_effective_tile_set();
RenderingServer *rs = RenderingServer::get_singleton();
// Check if we should cleanup everything.
- bool forced_cleanup = in_destructor || !enabled || !tile_set.is_valid() || !is_visible_in_tree();
+ bool forced_cleanup = in_destructor || !enabled || tile_set.is_null() || !is_visible_in_tree();
if (forced_cleanup) {
for (KeyValue> &kv : debug_quadrant_map) {
@@ -84,7 +84,7 @@ void TileMapLayer::_debug_update() {
if (_debug_was_cleaned_up || anything_changed) {
// Update all cells.
- for (KeyValue &kv : tile_map) {
+ for (KeyValue &kv : tile_map_layer_data) {
CellData &cell_data = kv.value;
_debug_quadrants_update_cell(cell_data, dirty_debug_quadrant_list);
}
@@ -179,33 +179,21 @@ void TileMapLayer::_debug_quadrants_update_cell(CellData &r_cell_data, SelfList<
/////////////////////////////// Rendering //////////////////////////////////////
void TileMapLayer::_rendering_update() {
- const Ref &tile_set = get_effective_tile_set();
RenderingServer *rs = RenderingServer::get_singleton();
// Check if we should cleanup everything.
- bool forced_cleanup = in_destructor || !enabled || !tile_set.is_valid() || !is_visible_in_tree();
+ bool forced_cleanup = in_destructor || !enabled || tile_set.is_null() || !is_visible_in_tree();
// ----------- Layer level processing -----------
if (!forced_cleanup) {
// Modulate the layer.
Color layer_modulate = get_modulate();
#ifdef TOOLS_ENABLED
- const TileMapLayerGroup *tile_map_layer_group = Object::cast_to(get_parent());
- if (tile_map_layer_group) {
- const Vector selected_layers = tile_map_layer_group->get_selected_layers();
- if (tile_map_layer_group->is_highlighting_selected_layer() && selected_layers.size() == 1 && get_name() != selected_layers[0]) {
- TileMapLayer *selected_layer = Object::cast_to(tile_map_layer_group->get_node_or_null(String(selected_layers[0])));
- if (selected_layer) {
- int z_selected = selected_layer->get_z_index();
- int layer_z_index = get_z_index();
- if (layer_z_index < z_selected || (layer_z_index == z_selected && get_index() < selected_layer->get_index())) {
- layer_modulate = layer_modulate.darkened(0.5);
- } else if (layer_z_index > z_selected || (layer_z_index == z_selected && get_index() > selected_layer->get_index())) {
- layer_modulate = layer_modulate.darkened(0.5);
- layer_modulate.a *= 0.3;
- }
- }
- }
+ if (highlight_mode == HIGHLIGHT_MODE_BELOW) {
+ layer_modulate = layer_modulate.darkened(0.5);
+ } else if (highlight_mode == HIGHLIGHT_MODE_ABOVE) {
+ layer_modulate = layer_modulate.darkened(0.5);
+ layer_modulate.a *= 0.3;
}
#endif // TOOLS_ENABLED
rs->canvas_item_set_modulate(get_canvas_item(), layer_modulate);
@@ -219,7 +207,7 @@ void TileMapLayer::_rendering_update() {
// Check if anything changed that might change the quadrant shape.
// If so, recreate everything.
bool quandrant_shape_changed = dirty.flags[DIRTY_FLAGS_LAYER_RENDERING_QUADRANT_SIZE] ||
- (is_y_sort_enabled() && (dirty.flags[DIRTY_FLAGS_LAYER_Y_SORT_ENABLED] || dirty.flags[DIRTY_FLAGS_LAYER_Y_SORT_ORIGIN] || dirty.flags[DIRTY_FLAGS_LAYER_LOCAL_TRANSFORM] || dirty.flags[DIRTY_FLAGS_LAYER_GROUP_TILE_SET]));
+ (is_y_sort_enabled() && (dirty.flags[DIRTY_FLAGS_LAYER_Y_SORT_ENABLED] || dirty.flags[DIRTY_FLAGS_LAYER_Y_SORT_ORIGIN] || dirty.flags[DIRTY_FLAGS_LAYER_LOCAL_TRANSFORM] || dirty.flags[DIRTY_FLAGS_TILE_SET]));
// Free all quadrants.
if (forced_cleanup || quandrant_shape_changed) {
@@ -238,9 +226,9 @@ void TileMapLayer::_rendering_update() {
if (!forced_cleanup) {
// List all quadrants to update, recreating them if needed.
- if (dirty.flags[DIRTY_FLAGS_LAYER_GROUP_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE] || _rendering_was_cleaned_up) {
+ if (dirty.flags[DIRTY_FLAGS_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE] || _rendering_was_cleaned_up) {
// Update all cells.
- for (KeyValue &kv : tile_map) {
+ for (KeyValue &kv : tile_map_layer_data) {
CellData &cell_data = kv.value;
_rendering_quadrants_update_cell(cell_data, dirty_rendering_quadrant_list);
}
@@ -420,13 +408,13 @@ void TileMapLayer::_rendering_update() {
// ----------- Occluders processing -----------
if (forced_cleanup) {
// Clean everything.
- for (KeyValue &kv : tile_map) {
+ for (KeyValue &kv : tile_map_layer_data) {
_rendering_occluders_clear_cell(kv.value);
}
} else {
- if (_rendering_was_cleaned_up || dirty.flags[DIRTY_FLAGS_LAYER_GROUP_TILE_SET]) {
+ if (_rendering_was_cleaned_up || dirty.flags[DIRTY_FLAGS_TILE_SET]) {
// Update all cells.
- for (KeyValue &kv : tile_map) {
+ for (KeyValue &kv : tile_map_layer_data) {
_rendering_occluders_update_cell(kv.value);
}
} else {
@@ -445,11 +433,10 @@ void TileMapLayer::_rendering_update() {
void TileMapLayer::_rendering_notification(int p_what) {
RenderingServer *rs = RenderingServer::get_singleton();
- const Ref &tile_set = get_effective_tile_set();
if (p_what == NOTIFICATION_TRANSFORM_CHANGED || p_what == NOTIFICATION_ENTER_CANVAS || p_what == NOTIFICATION_VISIBILITY_CHANGED) {
if (tile_set.is_valid()) {
Transform2D tilemap_xform = get_global_transform();
- for (KeyValue &kv : tile_map) {
+ for (KeyValue &kv : tile_map_layer_data) {
const CellData &cell_data = kv.value;
for (const RID &occluder : cell_data.occluders) {
if (occluder.is_null()) {
@@ -474,8 +461,6 @@ void TileMapLayer::_rendering_notification(int p_what) {
}
void TileMapLayer::_rendering_quadrants_update_cell(CellData &r_cell_data, SelfList::List &r_dirty_rendering_quadrant_list) {
- const Ref &tile_set = get_effective_tile_set();
-
// Check if the cell is valid and retrieve its y_sort_origin.
bool is_valid = false;
int tile_y_sort_origin = 0;
@@ -573,7 +558,6 @@ void TileMapLayer::_rendering_occluders_clear_cell(CellData &r_cell_data) {
}
void TileMapLayer::_rendering_occluders_update_cell(CellData &r_cell_data) {
- const Ref &tile_set = get_effective_tile_set();
RenderingServer *rs = RenderingServer::get_singleton();
// Free unused occluders then resize the occluders array.
@@ -642,8 +626,7 @@ void TileMapLayer::_rendering_occluders_update_cell(CellData &r_cell_data) {
#ifdef DEBUG_ENABLED
void TileMapLayer::_rendering_draw_cell_debug(const RID &p_canvas_item, const Vector2 &p_quadrant_pos, const CellData &r_cell_data) {
- const Ref &tile_set = get_effective_tile_set();
- ERR_FAIL_COND(!tile_set.is_valid());
+ ERR_FAIL_COND(tile_set.is_null());
if (!Engine::get_singleton()->is_editor_hint()) {
return;
@@ -691,19 +674,17 @@ void TileMapLayer::_rendering_draw_cell_debug(const RID &p_canvas_item, const Ve
/////////////////////////////// Physics //////////////////////////////////////
void TileMapLayer::_physics_update() {
- const Ref &tile_set = get_effective_tile_set();
-
// Check if we should cleanup everything.
- bool forced_cleanup = in_destructor || !enabled || !is_inside_tree() || !tile_set.is_valid();
+ bool forced_cleanup = in_destructor || !enabled || !collision_enabled || !is_inside_tree() || tile_set.is_null();
if (forced_cleanup) {
// Clean everything.
- for (KeyValue &kv : tile_map) {
+ for (KeyValue &kv : tile_map_layer_data) {
_physics_clear_cell(kv.value);
}
} else {
- if (_physics_was_cleaned_up || dirty.flags[DIRTY_FLAGS_LAYER_GROUP_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_USE_KINEMATIC_BODIES] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE]) {
+ if (_physics_was_cleaned_up || dirty.flags[DIRTY_FLAGS_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_USE_KINEMATIC_BODIES] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE]) {
// Update all cells.
- for (KeyValue &kv : tile_map) {
+ for (KeyValue &kv : tile_map_layer_data) {
_physics_update_cell(kv.value);
}
} else {
@@ -721,7 +702,6 @@ void TileMapLayer::_physics_update() {
}
void TileMapLayer::_physics_notification(int p_what) {
- const Ref &tile_set = get_effective_tile_set();
Transform2D gl_transform = get_global_transform();
PhysicsServer2D *ps = PhysicsServer2D::get_singleton();
@@ -729,7 +709,7 @@ void TileMapLayer::_physics_notification(int p_what) {
case NOTIFICATION_TRANSFORM_CHANGED:
// Move the collisison shapes along with the TileMap.
if (is_inside_tree() && tile_set.is_valid()) {
- for (KeyValue &kv : tile_map) {
+ for (KeyValue &kv : tile_map_layer_data) {
const CellData &cell_data = kv.value;
for (RID body : cell_data.bodies) {
@@ -747,7 +727,7 @@ void TileMapLayer::_physics_notification(int p_what) {
if (is_inside_tree()) {
RID space = get_world_2d()->get_space();
- for (KeyValue &kv : tile_map) {
+ for (KeyValue &kv : tile_map_layer_data) {
const CellData &cell_data = kv.value;
for (RID body : cell_data.bodies) {
@@ -774,7 +754,6 @@ void TileMapLayer::_physics_clear_cell(CellData &r_cell_data) {
}
void TileMapLayer::_physics_update_cell(CellData &r_cell_data) {
- const Ref &tile_set = get_effective_tile_set();
Transform2D gl_transform = get_global_transform();
RID space = get_world_2d()->get_space();
PhysicsServer2D *ps = PhysicsServer2D::get_singleton();
@@ -891,8 +870,7 @@ void TileMapLayer::_physics_update_cell(CellData &r_cell_data) {
#ifdef DEBUG_ENABLED
void TileMapLayer::_physics_draw_cell_debug(const RID &p_canvas_item, const Vector2 &p_quadrant_pos, const CellData &r_cell_data) {
// Draw the debug collision shapes.
- const Ref &tile_set = get_effective_tile_set();
- ERR_FAIL_COND(!tile_set.is_valid());
+ ERR_FAIL_COND(tile_set.is_null());
if (!get_tree()) {
return;
@@ -900,13 +878,13 @@ void TileMapLayer::_physics_draw_cell_debug(const RID &p_canvas_item, const Vect
bool show_collision = false;
switch (collision_visibility_mode) {
- case TileMapLayer::VISIBILITY_MODE_DEFAULT:
+ case TileMapLayer::DEBUG_VISIBILITY_MODE_DEFAULT:
show_collision = !Engine::get_singleton()->is_editor_hint() && get_tree()->is_debugging_collisions_hint();
break;
- case TileMapLayer::VISIBILITY_MODE_FORCE_HIDE:
+ case TileMapLayer::DEBUG_VISIBILITY_MODE_FORCE_HIDE:
show_collision = false;
break;
- case TileMapLayer::VISIBILITY_MODE_FORCE_SHOW:
+ case TileMapLayer::DEBUG_VISIBILITY_MODE_FORCE_SHOW:
show_collision = true;
break;
}
@@ -948,10 +926,9 @@ void TileMapLayer::_physics_draw_cell_debug(const RID &p_canvas_item, const Vect
void TileMapLayer::_navigation_update() {
ERR_FAIL_NULL(NavigationServer2D::get_singleton());
NavigationServer2D *ns = NavigationServer2D::get_singleton();
- const Ref &tile_set = get_effective_tile_set();
// Check if we should cleanup everything.
- bool forced_cleanup = in_destructor || !enabled || !navigation_enabled || !is_inside_tree() || !tile_set.is_valid();
+ bool forced_cleanup = in_destructor || !enabled || !navigation_enabled || !is_inside_tree() || tile_set.is_null();
// ----------- Layer level processing -----------
// All this processing is kept for compatibility with the TileMap node.
@@ -980,13 +957,13 @@ void TileMapLayer::_navigation_update() {
// ----------- Navigation regions processing -----------
if (forced_cleanup) {
// Clean everything.
- for (KeyValue &kv : tile_map) {
+ for (KeyValue &kv : tile_map_layer_data) {
_navigation_clear_cell(kv.value);
}
} else {
- if (_navigation_was_cleaned_up || dirty.flags[DIRTY_FLAGS_LAYER_GROUP_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE] || dirty.flags[DIRTY_FLAGS_LAYER_NAVIGATION_MAP]) {
+ if (_navigation_was_cleaned_up || dirty.flags[DIRTY_FLAGS_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE] || dirty.flags[DIRTY_FLAGS_LAYER_NAVIGATION_MAP]) {
// Update all cells.
- for (KeyValue &kv : tile_map) {
+ for (KeyValue &kv : tile_map_layer_data) {
_navigation_update_cell(kv.value);
}
} else {
@@ -1004,11 +981,10 @@ void TileMapLayer::_navigation_update() {
}
void TileMapLayer::_navigation_notification(int p_what) {
- const Ref &tile_set = get_effective_tile_set();
if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
if (tile_set.is_valid()) {
Transform2D tilemap_xform = get_global_transform();
- for (KeyValue &kv : tile_map) {
+ for (KeyValue &kv : tile_map_layer_data) {
const CellData &cell_data = kv.value;
// Update navigation regions transform.
for (const RID ®ion : cell_data.navigation_regions) {
@@ -1038,7 +1014,6 @@ void TileMapLayer::_navigation_clear_cell(CellData &r_cell_data) {
}
void TileMapLayer::_navigation_update_cell(CellData &r_cell_data) {
- const Ref &tile_set = get_effective_tile_set();
NavigationServer2D *ns = NavigationServer2D::get_singleton();
Transform2D gl_xform = get_global_transform();
RID navigation_map = navigation_map_override.is_valid() ? navigation_map_override : get_world_2d()->get_navigation_map();
@@ -1119,13 +1094,13 @@ void TileMapLayer::_navigation_draw_cell_debug(const RID &p_canvas_item, const V
// Draw the debug collision shapes.
bool show_navigation = false;
switch (navigation_visibility_mode) {
- case TileMapLayer::VISIBILITY_MODE_DEFAULT:
+ case TileMapLayer::DEBUG_VISIBILITY_MODE_DEFAULT:
show_navigation = !Engine::get_singleton()->is_editor_hint() && get_tree()->is_debugging_navigation_hint();
break;
- case TileMapLayer::VISIBILITY_MODE_FORCE_HIDE:
+ case TileMapLayer::DEBUG_VISIBILITY_MODE_FORCE_HIDE:
show_navigation = false;
break;
- case TileMapLayer::VISIBILITY_MODE_FORCE_SHOW:
+ case TileMapLayer::DEBUG_VISIBILITY_MODE_FORCE_SHOW:
show_navigation = true;
break;
}
@@ -1138,8 +1113,6 @@ void TileMapLayer::_navigation_draw_cell_debug(const RID &p_canvas_item, const V
return;
}
- const Ref &tile_set = get_effective_tile_set();
-
RenderingServer *rs = RenderingServer::get_singleton();
const NavigationServer2D *ns2d = NavigationServer2D::get_singleton();
@@ -1224,20 +1197,18 @@ void TileMapLayer::_navigation_draw_cell_debug(const RID &p_canvas_item, const V
/////////////////////////////// Scenes //////////////////////////////////////
void TileMapLayer::_scenes_update() {
- const Ref &tile_set = get_effective_tile_set();
-
// Check if we should cleanup everything.
- bool forced_cleanup = in_destructor || !enabled || !is_inside_tree() || !tile_set.is_valid();
+ bool forced_cleanup = in_destructor || !enabled || !is_inside_tree() || tile_set.is_null();
if (forced_cleanup) {
// Clean everything.
- for (KeyValue &kv : tile_map) {
+ for (KeyValue &kv : tile_map_layer_data) {
_scenes_clear_cell(kv.value);
}
} else {
- if (_scenes_was_cleaned_up || dirty.flags[DIRTY_FLAGS_LAYER_GROUP_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE]) {
+ if (_scenes_was_cleaned_up || dirty.flags[DIRTY_FLAGS_TILE_SET] || dirty.flags[DIRTY_FLAGS_LAYER_IN_TREE]) {
// Update all cells.
- for (KeyValue &kv : tile_map) {
+ for (KeyValue &kv : tile_map_layer_data) {
_scenes_update_cell(kv.value);
}
} else {
@@ -1270,8 +1241,6 @@ void TileMapLayer::_scenes_clear_cell(CellData &r_cell_data) {
}
void TileMapLayer::_scenes_update_cell(CellData &r_cell_data) {
- const Ref &tile_set = get_effective_tile_set();
-
// Clear the scene in any case.
_scenes_clear_cell(r_cell_data);
@@ -1312,8 +1281,7 @@ void TileMapLayer::_scenes_update_cell(CellData &r_cell_data) {
#ifdef DEBUG_ENABLED
void TileMapLayer::_scenes_draw_cell_debug(const RID &p_canvas_item, const Vector2 &p_quadrant_pos, const CellData &r_cell_data) {
- const Ref &tile_set = get_effective_tile_set();
- ERR_FAIL_COND(!tile_set.is_valid());
+ ERR_FAIL_COND(tile_set.is_null());
if (!Engine::get_singleton()->is_editor_hint()) {
return;
@@ -1362,22 +1330,20 @@ void TileMapLayer::_scenes_draw_cell_debug(const RID &p_canvas_item, const Vecto
/////////////////////////////////////////////////////////////////////
void TileMapLayer::_build_runtime_update_tile_data() {
- const Ref &tile_set = get_effective_tile_set();
-
// Check if we should cleanup everything.
- bool forced_cleanup = in_destructor || !enabled || !tile_set.is_valid() || !is_visible_in_tree();
+ bool forced_cleanup = in_destructor || !enabled || tile_set.is_null() || !is_visible_in_tree();
if (!forced_cleanup) {
bool valid_runtime_update = GDVIRTUAL_IS_OVERRIDDEN(_use_tile_data_runtime_update) && GDVIRTUAL_IS_OVERRIDDEN(_tile_data_runtime_update);
bool valid_runtime_update_for_tilemap = tile_map_node && tile_map_node->GDVIRTUAL_IS_OVERRIDDEN(_use_tile_data_runtime_update) && tile_map_node->GDVIRTUAL_IS_OVERRIDDEN(_tile_data_runtime_update); // For keeping compatibility.
if (valid_runtime_update || valid_runtime_update_for_tilemap) {
bool use_tilemap_for_runtime = valid_runtime_update_for_tilemap && !valid_runtime_update;
- if (_runtime_update_tile_data_was_cleaned_up || dirty.flags[DIRTY_FLAGS_LAYER_GROUP_TILE_SET]) {
+ if (_runtime_update_tile_data_was_cleaned_up || dirty.flags[DIRTY_FLAGS_TILE_SET]) {
_runtime_update_needs_all_cells_cleaned_up = true;
- for (KeyValue &E : tile_map) {
+ for (KeyValue