Skip to content
Snippets Groups Projects
Commit 621e9b1e authored by Robin Halseth Sandvik's avatar Robin Halseth Sandvik
Browse files

Added new method to update the icon of abilities on the screen.

- Doesn't fully work yet.
parent 6363d046
No related branches found
No related tags found
1 merge request!84Merge, ability cluster
...@@ -73,15 +73,17 @@ namespace BigSock { ...@@ -73,15 +73,17 @@ namespace BigSock {
Updates the list of the user's abilities. Updates the list of the user's abilities.
*/ */
protected void SetAbilities(List<IAbility> neo) { protected void SetAbilities(List<IAbility> neo) {
var res = new List<AbilityEntity>(); var res = new List<AbilityEntity>();
for(int i = 0; i < neo.Count; ++i) for(int i = 0; i < neo.Count; ++i)
res.Add(new AbilityEntity(neo[i], i, _keyMapping[i])); res.Add(new AbilityEntity(neo[i], i, _keyMapping[i]));
_abilities = res; _abilities = res;
//!! Put in updating he ui here. // Update the UI to reflect the new abilities.
foreach(var ability in _abilities) { AbilityUI?.SetElements(_abilities.Count);
// AbilityUI.SetAbility(ability.Index, ability); ??? foreach (var ability in _abilities) {
AbilityUI.SetAbility(ability.Index, ability);
} }
} }
...@@ -119,7 +121,6 @@ namespace BigSock { ...@@ -119,7 +121,6 @@ namespace BigSock {
aService.Get(101), aService.Get(101),
aService.Get(201), aService.Get(201),
}; };
AbilityUI?.SetElements(ABILITY_COUNT);
SetAbilities(abilities); SetAbilities(abilities);
//_testAttack = (IAttack)AbilityService.SINGLETON.Get(104); //_testAttack = (IAttack)AbilityService.SINGLETON.Get(104);
......
...@@ -29,7 +29,9 @@ namespace BigSock.UI ...@@ -29,7 +29,9 @@ namespace BigSock.UI
{ {
abilityList[index].WithCharge(amount); abilityList[index].WithCharge(amount);
} }
public void SetAbility(int index, AbilityEntity ability) {
abilityList[index].WithAbility(ability);
}
} }
} }
...@@ -6,39 +6,46 @@ using UnityEngine.UI; ...@@ -6,39 +6,46 @@ using UnityEngine.UI;
namespace BigSock.UI namespace BigSock.UI
{ {
public class AbilityElement : MonoBehaviour public class AbilityElement : MonoBehaviour
{ {
private Slider chargeSlider, cooldownSlider; private Slider chargeSlider, cooldownSlider;
private Image _sprite;
public AbilityElement WithCharge(float? value = null, float? maxValue = null) public AbilityElement WithCharge(float? value = null, float? maxValue = null)
{ {
if (value != null) chargeSlider.value = value.Value; if (value != null) chargeSlider.value = value.Value;
if (maxValue != null) chargeSlider.maxValue = maxValue.Value; if (maxValue != null) chargeSlider.maxValue = maxValue.Value;
return this; return this;
} }
public AbilityElement WithCooldown(float? value = null, float? maxValue = null) public AbilityElement WithCooldown(float? value = null, float? maxValue = null)
{ {
if (value != null) cooldownSlider.value = value.Value; 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 // Start is called before the first frame update
void Start() void Start() {
{ chargeSlider = transform.Find("ChargeSlider").GetComponent<Slider>();
chargeSlider = transform.Find("ChargeSlider").GetComponent<Slider>(); cooldownSlider = transform.Find("ReloadSlider").GetComponent<Slider>();
cooldownSlider = transform.Find("ReloadSlider").GetComponent<Slider>(); _sprite = transform.Find("Sprite").GetComponent<UnityEngine.UI.Image>();
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment