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 {
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);
......
......@@ -29,7 +29,9 @@ namespace BigSock.UI
{
abilityList[index].WithCharge(amount);
}
public void SetAbility(int index, AbilityEntity ability) {
abilityList[index].WithAbility(ability);
}
}
}
......@@ -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()
{
}
}
}
}
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