From c42f4a18d90e751ef47fe245f47a7cb2eb65161c Mon Sep 17 00:00:00 2001
From: Julius <juliusfe@stud.ntnu.no>
Date: Fri, 9 Dec 2022 19:14:21 +0100
Subject: [PATCH] Added clear function to ability cluster

---
 MrBigsock/Assets/Code/PlayerController.cs     |  9 +++
 MrBigsock/Assets/Code/UI/AbilityCluster.cs    | 58 +++++++++++--------
 .../Prefabs/MapObjects/ClosedChest.prefab     |  2 +-
 3 files changed, 45 insertions(+), 24 deletions(-)

diff --git a/MrBigsock/Assets/Code/PlayerController.cs b/MrBigsock/Assets/Code/PlayerController.cs
index 1d26c4c8..7b2540a0 100644
--- a/MrBigsock/Assets/Code/PlayerController.cs
+++ b/MrBigsock/Assets/Code/PlayerController.cs
@@ -320,6 +320,15 @@ namespace BigSock {
 					var controlScheme = PrefabService.SINGLETON.Instance("UI/ControlScheme", canvas.transform);
 				}
 			}
+
+			/* for testing ui
+			if (Input.GetKeyDown(KeyCode.P))
+			{
+				GameObject abil = GameObject.Find("AbilityCluster");
+				var abilScript = abil.GetComponent<AbilityCluster>();
+				abilScript.ResetElements();
+			}
+			*/
 		}
 
 		/*
diff --git a/MrBigsock/Assets/Code/UI/AbilityCluster.cs b/MrBigsock/Assets/Code/UI/AbilityCluster.cs
index c34be524..bda6f286 100644
--- a/MrBigsock/Assets/Code/UI/AbilityCluster.cs
+++ b/MrBigsock/Assets/Code/UI/AbilityCluster.cs
@@ -6,32 +6,44 @@ using BigSock.Service;
 
 namespace BigSock.UI
 {
-  public class AbilityCluster : MonoBehaviour
-  {
-    private const string ABILITYELEMENT = "UI/Ability";        
-    private List<AbilityElement> abilityList;
+    public class AbilityCluster : MonoBehaviour
+    {
+        private const string ABILITYELEMENT = "UI/Ability";        
+        private List<AbilityElement> abilityList;
+
+        public void SetElements(int elementAmount)
+		{           
+            abilityList = new List<AbilityElement>();
+            ResetElements();
+            for (int i = 0; i < elementAmount; ++i)
+            {               
+                abilityList.Add(PrefabService.SINGLETON.Instance(ABILITYELEMENT, transform).GetComponent<AbilityElement>());
+            }
+        }
 
-    public void SetElements(int elementAmount)
+        //Clears all elements in ability cluster.
+		public void ResetElements()
 		{
-      abilityList = new List<AbilityElement>();
-      for (int i = 0; i < elementAmount; ++i)
-			{                
-        abilityList.Add(PrefabService.SINGLETON.Instance(ABILITYELEMENT, transform).GetComponent<AbilityElement>());
-      }
-    }
+            abilityList.Clear();
+            var layout = this.GetComponent<HorizontalLayoutGroup>();
+            for (int i = 0; i < layout.transform.childCount; i++)
+			{
+                Destroy(layout.transform.GetChild(i).gameObject);
+            }                
+        }
 
-    public void SetCooldown(int index, float amount) 
-    {
-      abilityList[index].WithCooldown(amount);
-    }
+		public void SetCooldown(int index, float amount) 
+        {
+            abilityList[index].WithCooldown(amount);
+        }
 
-      public void SetCharge(int index, float amount)
-      {
-          abilityList[index].WithCharge(amount);
-      }
-    public void SetAbility(int index, AbilityEntity ability) {
-      abilityList[index].WithAbility(ability);
-    }
+        public void SetCharge(int index, float amount)
+        {
+            abilityList[index].WithCharge(amount);
+        }
+        public void SetAbility(int index, AbilityEntity ability) {
+            abilityList[index].WithAbility(ability);
+        }
 
-  }
+    }
 }
diff --git a/MrBigsock/Assets/Prefabs/MapObjects/ClosedChest.prefab b/MrBigsock/Assets/Prefabs/MapObjects/ClosedChest.prefab
index 273c687c..29f16ead 100644
--- a/MrBigsock/Assets/Prefabs/MapObjects/ClosedChest.prefab
+++ b/MrBigsock/Assets/Prefabs/MapObjects/ClosedChest.prefab
@@ -15,7 +15,7 @@ GameObject:
   - component: {fileID: 532417261}
   m_Layer: 11
   m_Name: ClosedChest
-  m_TagString: Untagged
+  m_TagString: Chest
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
-- 
GitLab