From 621e9b1e4f5ca7ac0a858c5d4d35631b9346f66e Mon Sep 17 00:00:00 2001 From: Ny Bruker <robinhs@stud.ntnu.no> Date: Fri, 9 Dec 2022 18:39:46 +0100 Subject: [PATCH] Added new method to update the icon of abilities on the screen. - Doesn't fully work yet. --- MrBigsock/Assets/Code/PlayerController.cs | 9 ++-- MrBigsock/Assets/Code/UI/AbilityCluster.cs | 4 +- MrBigsock/Assets/Code/UI/AbilityElement.cs | 57 ++++++++++++---------- 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/MrBigsock/Assets/Code/PlayerController.cs b/MrBigsock/Assets/Code/PlayerController.cs index 35a1d4d7..1d26c4c8 100644 --- a/MrBigsock/Assets/Code/PlayerController.cs +++ b/MrBigsock/Assets/Code/PlayerController.cs @@ -73,15 +73,17 @@ namespace BigSock { Updates the list of the user's abilities. */ protected void SetAbilities(List<IAbility> neo) { + var res = new List<AbilityEntity>(); for(int i = 0; i < neo.Count; ++i) res.Add(new AbilityEntity(neo[i], i, _keyMapping[i])); _abilities = res; - //!! Put in updating he ui here. - foreach(var ability in _abilities) { - // AbilityUI.SetAbility(ability.Index, ability); ??? + // Update the UI to reflect the new abilities. + AbilityUI?.SetElements(_abilities.Count); + foreach (var ability in _abilities) { + AbilityUI.SetAbility(ability.Index, ability); } } @@ -119,7 +121,6 @@ namespace BigSock { aService.Get(101), aService.Get(201), }; - AbilityUI?.SetElements(ABILITY_COUNT); SetAbilities(abilities); //_testAttack = (IAttack)AbilityService.SINGLETON.Get(104); diff --git a/MrBigsock/Assets/Code/UI/AbilityCluster.cs b/MrBigsock/Assets/Code/UI/AbilityCluster.cs index 659c3d05..c34be524 100644 --- a/MrBigsock/Assets/Code/UI/AbilityCluster.cs +++ b/MrBigsock/Assets/Code/UI/AbilityCluster.cs @@ -29,7 +29,9 @@ namespace BigSock.UI { abilityList[index].WithCharge(amount); } - + public void SetAbility(int index, AbilityEntity ability) { + abilityList[index].WithAbility(ability); + } } } diff --git a/MrBigsock/Assets/Code/UI/AbilityElement.cs b/MrBigsock/Assets/Code/UI/AbilityElement.cs index 21307ed2..5e44700a 100644 --- a/MrBigsock/Assets/Code/UI/AbilityElement.cs +++ b/MrBigsock/Assets/Code/UI/AbilityElement.cs @@ -6,39 +6,46 @@ using UnityEngine.UI; namespace BigSock.UI { - public class AbilityElement : MonoBehaviour - { - private Slider chargeSlider, cooldownSlider; + public class AbilityElement : MonoBehaviour + { + private Slider chargeSlider, cooldownSlider; + private Image _sprite; - public AbilityElement WithCharge(float? value = null, float? maxValue = null) - { - if (value != null) chargeSlider.value = value.Value; + public AbilityElement WithCharge(float? value = null, float? maxValue = null) + { + if (value != null) chargeSlider.value = value.Value; - if (maxValue != null) chargeSlider.maxValue = maxValue.Value; - return this; - } + if (maxValue != null) chargeSlider.maxValue = maxValue.Value; + return this; + } - public AbilityElement WithCooldown(float? value = null, float? maxValue = null) - { - if (value != null) cooldownSlider.value = value.Value; + public AbilityElement WithCooldown(float? value = null, float? maxValue = null) + { + if (value != null) cooldownSlider.value = value.Value; + + if (maxValue != null) cooldownSlider.maxValue = maxValue.Value; + return this; + } - if (maxValue != null) cooldownSlider.maxValue = maxValue.Value; - return this; - } + public AbilityElement WithAbility(AbilityEntity ability) { + if (_sprite != null) + _sprite.overrideSprite = ability.Ability.Icon ?? _sprite.overrideSprite; + return this; + } - // Start is called before the first frame update - void Start() - { - chargeSlider = transform.Find("ChargeSlider").GetComponent<Slider>(); - cooldownSlider = transform.Find("ReloadSlider").GetComponent<Slider>(); - } + // Start is called before the first frame update + void Start() { + chargeSlider = transform.Find("ChargeSlider").GetComponent<Slider>(); + cooldownSlider = transform.Find("ReloadSlider").GetComponent<Slider>(); + _sprite = transform.Find("Sprite").GetComponent<UnityEngine.UI.Image>(); + } - // Update is called once per frame - void Update() - { + // Update is called once per frame + void Update() + { - } + } } } -- GitLab