Browse Source

Merge pull request #46623 from Janglee123/tilemap-collision-show

Added `show_collision` property for tilemap node.
Rémi Verschelde 4 years ago
parent
commit
cad3771ce7
3 changed files with 22 additions and 1 deletions
  1. 3 0
      doc/classes/TileMap.xml
  2. 15 1
      scene/2d/tile_map.cpp
  3. 4 0
      scene/2d/tile_map.h

+ 3 - 0
doc/classes/TileMap.xml

@@ -326,6 +326,9 @@
 		<member name="occluder_light_mask" type="int" setter="set_occluder_light_mask" getter="get_occluder_light_mask" default="1">
 		<member name="occluder_light_mask" type="int" setter="set_occluder_light_mask" getter="get_occluder_light_mask" default="1">
 			The light mask assigned to all light occluders in the TileMap. The TileSet's light occluders will cast shadows only from Light2D(s) that have the same light mask(s).
 			The light mask assigned to all light occluders in the TileMap. The TileSet's light occluders will cast shadows only from Light2D(s) that have the same light mask(s).
 		</member>
 		</member>
+		<member name="show_collision" type="bool" setter="set_show_collision" getter="is_show_collision_enabled" default="true">
+			If [code]true[/code], collision shapes are shown in the editor and at run-time. Requires [b]Visible Collision Shapes[/b] to be enabled in the [b]Debug[/b] menu for collision shapes to be visible at run-time.
+		</member>
 		<member name="tile_set" type="TileSet" setter="set_tileset" getter="get_tileset">
 		<member name="tile_set" type="TileSet" setter="set_tileset" getter="get_tileset">
 			The assigned [TileSet].
 			The assigned [TileSet].
 		</member>
 		</member>

+ 15 - 1
scene/2d/tile_map.cpp

@@ -346,7 +346,8 @@ void TileMap::update_dirty_quadrants() {
 	Color debug_collision_color;
 	Color debug_collision_color;
 	Color debug_navigation_color;
 	Color debug_navigation_color;
 
 
-	bool debug_shapes = st && st->is_debugging_collisions_hint();
+	bool debug_shapes = show_collision && (Engine::get_singleton()->is_editor_hint() || (st && st->is_debugging_collisions_hint()));
+
 	if (debug_shapes) {
 	if (debug_shapes) {
 		debug_collision_color = st->get_debug_collisions_color();
 		debug_collision_color = st->get_debug_collisions_color();
 	}
 	}
@@ -1792,6 +1793,15 @@ String TileMap::get_configuration_warning() const {
 	return warning;
 	return warning;
 }
 }
 
 
+void TileMap::set_show_collision(bool p_value) {
+	show_collision = p_value;
+	_recreate_quadrants();
+}
+
+bool TileMap::is_show_collision_enabled() const {
+	return show_collision;
+}
+
 void TileMap::_bind_methods() {
 void TileMap::_bind_methods() {
 
 
 	ClassDB::bind_method(D_METHOD("set_tileset", "tileset"), &TileMap::set_tileset);
 	ClassDB::bind_method(D_METHOD("set_tileset", "tileset"), &TileMap::set_tileset);
@@ -1827,6 +1837,9 @@ void TileMap::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("set_compatibility_mode", "enable"), &TileMap::set_compatibility_mode);
 	ClassDB::bind_method(D_METHOD("set_compatibility_mode", "enable"), &TileMap::set_compatibility_mode);
 	ClassDB::bind_method(D_METHOD("is_compatibility_mode_enabled"), &TileMap::is_compatibility_mode_enabled);
 	ClassDB::bind_method(D_METHOD("is_compatibility_mode_enabled"), &TileMap::is_compatibility_mode_enabled);
 
 
+	ClassDB::bind_method(D_METHOD("set_show_collision", "enable"), &TileMap::set_show_collision);
+	ClassDB::bind_method(D_METHOD("is_show_collision_enabled"), &TileMap::is_show_collision_enabled);
+
 	ClassDB::bind_method(D_METHOD("set_centered_textures", "enable"), &TileMap::set_centered_textures);
 	ClassDB::bind_method(D_METHOD("set_centered_textures", "enable"), &TileMap::set_centered_textures);
 	ClassDB::bind_method(D_METHOD("is_centered_textures_enabled"), &TileMap::is_centered_textures_enabled);
 	ClassDB::bind_method(D_METHOD("is_centered_textures_enabled"), &TileMap::is_centered_textures_enabled);
 
 
@@ -1898,6 +1911,7 @@ void TileMap::_bind_methods() {
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_half_offset", PROPERTY_HINT_ENUM, "Offset X,Offset Y,Disabled,Offset Negative X,Offset Negative Y"), "set_half_offset", "get_half_offset");
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_half_offset", PROPERTY_HINT_ENUM, "Offset X,Offset Y,Disabled,Offset Negative X,Offset Negative Y"), "set_half_offset", "get_half_offset");
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_tile_origin", PROPERTY_HINT_ENUM, "Top Left,Center,Bottom Left"), "set_tile_origin", "get_tile_origin");
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_tile_origin", PROPERTY_HINT_ENUM, "Top Left,Center,Bottom Left"), "set_tile_origin", "get_tile_origin");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_y_sort"), "set_y_sort_mode", "is_y_sort_mode_enabled");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_y_sort"), "set_y_sort_mode", "is_y_sort_mode_enabled");
+	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_collision"), "set_show_collision", "is_show_collision_enabled");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "compatibility_mode"), "set_compatibility_mode", "is_compatibility_mode_enabled");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "compatibility_mode"), "set_compatibility_mode", "is_compatibility_mode_enabled");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "centered_textures"), "set_centered_textures", "is_centered_textures_enabled");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "centered_textures"), "set_centered_textures", "is_centered_textures_enabled");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_clip_uv"), "set_clip_uv", "get_clip_uv");
 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_clip_uv"), "set_clip_uv", "get_clip_uv");

+ 4 - 0
scene/2d/tile_map.h

@@ -80,6 +80,7 @@ private:
 	CollisionObject2D *collision_parent;
 	CollisionObject2D *collision_parent;
 	bool use_kinematic;
 	bool use_kinematic;
 	Navigation2D *navigation;
 	Navigation2D *navigation;
+	bool show_collision = true;
 
 
 	union PosKey {
 	union PosKey {
 
 
@@ -277,6 +278,9 @@ public:
 
 
 	void update_dirty_quadrants();
 	void update_dirty_quadrants();
 
 
+	void set_show_collision(bool p_value);
+	bool is_show_collision_enabled() const;
+
 	void set_collision_layer(uint32_t p_layer);
 	void set_collision_layer(uint32_t p_layer);
 	uint32_t get_collision_layer() const;
 	uint32_t get_collision_layer() const;