diff --git a/MrBigsock/Assets/Code/PlayerController.cs b/MrBigsock/Assets/Code/PlayerController.cs index 35a1d4d707606203db1dba7969eaf55a7aac10e6..1d26c4c885e87adfa699c556bcb948ae57bd59b4 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 659c3d05fc99bfb099648228c91644ad6c718827..c34be5240385018a250325951385b45222398dd2 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 21307ed2c9ed44d88bc3c5a4d486a6e68af46b3d..5e44700af0bff81cf051fe5f0e5263a1ae48b612 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() + { - } + } } }