Support nesting AtlasTextures inside other AtlasTextures

Connects AtlasTexture to its `atlas`'s "changed" signal, allowing it to detect property changes to `atlas` and update accordingly, when the project is running and in the editor, as well.
This commit is contained in:
Micky
2022-09-27 18:53:14 +02:00
parent 0056acf46f
commit 1518d813be
2 changed files with 10 additions and 2 deletions

View File

@ -6,13 +6,13 @@
<description> <description>
[Texture2D] resource that draws only part of its [member atlas] texture, as defined by the [member region]. An additional [member margin] can also be set, which is useful for small adjustments. [Texture2D] resource that draws only part of its [member atlas] texture, as defined by the [member region]. An additional [member margin] can also be set, which is useful for small adjustments.
Multiple [AtlasTexture] resources can be cropped from the same [member atlas]. Packing many smaller textures into a singular large texture helps to optimize video memory costs and render calls. Multiple [AtlasTexture] resources can be cropped from the same [member atlas]. Packing many smaller textures into a singular large texture helps to optimize video memory costs and render calls.
[b]Note:[/b] [AtlasTexture] cannot be used in an [AnimatedTexture], and does not work properly if used inside of other [AtlasTexture] resources. [b]Note:[/b] [AtlasTexture] cannot be used in an [AnimatedTexture], and may not tile properly in nodes such as [TextureRect], when inside other [AtlasTexture] resources.
</description> </description>
<tutorials> <tutorials>
</tutorials> </tutorials>
<members> <members>
<member name="atlas" type="Texture2D" setter="set_atlas" getter="get_atlas"> <member name="atlas" type="Texture2D" setter="set_atlas" getter="get_atlas">
The texture that contains the atlas. Can be any type inheriting from [Texture2D]. Nesting [AtlasTexture] resources is not supported. The texture that contains the atlas. Can be any type inheriting from [Texture2D], including another [AtlasTexture].
</member> </member>
<member name="filter_clip" type="bool" setter="set_filter_clip" getter="has_filter_clip" default="false"> <member name="filter_clip" type="bool" setter="set_filter_clip" getter="has_filter_clip" default="false">
If [code]true[/code], the area outside of the [member region] is clipped to avoid bleeding of the surrounding texture pixels. If [code]true[/code], the area outside of the [member region] is clipped to avoid bleeding of the surrounding texture pixels.

View File

@ -1489,7 +1489,15 @@ void AtlasTexture::set_atlas(const Ref<Texture2D> &p_atlas) {
if (atlas == p_atlas) { if (atlas == p_atlas) {
return; return;
} }
// Support recursive AtlasTextures.
if (Ref<AtlasTexture>(atlas).is_valid()) {
atlas->disconnect(CoreStringNames::get_singleton()->changed, callable_mp((Resource *)this, &AtlasTexture::emit_changed));
}
atlas = p_atlas; atlas = p_atlas;
if (Ref<AtlasTexture>(atlas).is_valid()) {
atlas->connect(CoreStringNames::get_singleton()->changed, callable_mp((Resource *)this, &AtlasTexture::emit_changed));
}
emit_changed(); emit_changed();
} }