From 7b44075ac89f85e447a088180878b5d7414a5c82 Mon Sep 17 00:00:00 2001 From: Wiktor Kocielski Date: Fri, 4 Aug 2023 09:59:45 +0300 Subject: [PATCH 1/2] Add recursive methods for layers --- Source/Engine/Level/Actor.cpp | 24 ++++++++++++++++++++++++ Source/Engine/Level/Actor.h | 11 +++++++++++ 2 files changed, 35 insertions(+) diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp index 8185f3b9d..a0aa01cba 100644 --- a/Source/Engine/Level/Actor.cpp +++ b/Source/Engine/Level/Actor.cpp @@ -456,6 +456,19 @@ void Actor::SetLayerName(const StringView& value) LOG(Warning, "Unknown layer name '{0}'", value); } +void Actor::SetLayerNameRecursive(const StringView& value) +{ + for (int32 i = 0; i < 32; i++) + { + if (Level::Layers[i] == value) + { + SetLayerRecursive(i); + return; + } + } + LOG(Warning, "Unknown layer name '{0}'", value); +} + bool Actor::HasTag() const { return Tags.Count() != 0; @@ -500,6 +513,17 @@ void Actor::SetLayer(int32 layerIndex) OnLayerChanged(); } +void Actor::SetLayerRecursive(int32 layerIndex) +{ + layerIndex = Math::Clamp(layerIndex, 0, 31); + for (const auto& child : Children) + child->SetLayerRecursive(layerIndex); + if (layerIndex == _layer) + return; + _layer = layerIndex; + OnLayerChanged(); +} + void Actor::SetName(const StringView& value) { if (_name == value) diff --git a/Source/Engine/Level/Actor.h b/Source/Engine/Level/Actor.h index 510bc9eb8..7a75b12f7 100644 --- a/Source/Engine/Level/Actor.h +++ b/Source/Engine/Level/Actor.h @@ -102,6 +102,12 @@ public: /// The index of the layer. API_PROPERTY() void SetLayer(int32 layerIndex); + /// + /// Sets the layer recursively for all underlying children. + /// + /// The index of the layer. + API_FUNCTION() void SetLayerRecursive(int32 layerIndex); + /// /// Gets the name of the layer. /// @@ -113,6 +119,11 @@ public: /// API_PROPERTY() void SetLayerName(const StringView& value); + /// + /// Sets the name of the layer recursively for all underlying children. + /// + API_FUNCTION() void SetLayerNameRecursive(const StringView& value); + /// /// Determines whether this actor has any tag assigned. /// From d9a1eb349df0a0c5ae8ac7c9b38e0d24bdfdeb53 Mon Sep 17 00:00:00 2001 From: Wiktor Kocielski Date: Wed, 6 Sep 2023 05:43:27 +0300 Subject: [PATCH 2/2] Implement tags recursive addition --- Source/Engine/Level/Actor.cpp | 7 +++++++ Source/Engine/Level/Actor.h | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp index a0aa01cba..388379237 100644 --- a/Source/Engine/Level/Actor.cpp +++ b/Source/Engine/Level/Actor.cpp @@ -489,6 +489,13 @@ void Actor::AddTag(const Tag& tag) Tags.AddUnique(tag); } +void Actor::AddTagRecursive(const Tag& tag) +{ + for (const auto& child : Children) + child->AddTagRecursive(tag); + Tags.AddUnique(tag); +} + PRAGMA_DISABLE_DEPRECATION_WARNINGS const String& Actor::GetTag() const diff --git a/Source/Engine/Level/Actor.h b/Source/Engine/Level/Actor.h index 7a75b12f7..31cfe2473 100644 --- a/Source/Engine/Level/Actor.h +++ b/Source/Engine/Level/Actor.h @@ -120,7 +120,7 @@ public: API_PROPERTY() void SetLayerName(const StringView& value); /// - /// Sets the name of the layer recursively for all underlying children. + /// Sets the name of the layer recursively for actor and for all underlying child actors. /// API_FUNCTION() void SetLayerNameRecursive(const StringView& value); @@ -147,6 +147,12 @@ public: /// The tag to add. API_FUNCTION() void AddTag(const Tag& tag); + /// + /// Adds a tag to the actor and for all underlying child actors. + /// + /// The tag to add. + API_FUNCTION() void AddTagRecursive(const Tag& tag); + /// /// Gets the name of the tag. /// [Deprecated in v1.5]