Encounter / Assets / Scripts / GUIHandlers / AbilityGUI.cs
AbilityGUI.cs
Raw
using System.Threading.Tasks;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// Visual GUI system that handles specifically Abilities of entities
/// </summary>
public class AbilityGUI : MonoBehaviour
{
    [Header("Ability GUI Elements")]
    [SerializeField] private TextMeshProUGUI abilityName;           // Reference to the text field where the name of the ability will be injected
    [SerializeField] private Image abilityImageField;               // Reference to the image field for the ability sprite
    [SerializeField] private Transform helperList;                  // Reference to the tranform where each of the helper effects will be instantiated
    [SerializeField] private TextMeshProUGUI descriptionField;      // Reference to the field where the description will be injected
    [SerializeField] private AutoScroller autoScroller;             // Reference to the auto scroller for the effect list

    [Header("Prefabs")]
    [SerializeField] private GameObject textField;                  // Prefab of the text instance for the helper effects

    private Ability abilityInjected;                                // Reference to the ability that was injected into this GUI

    /// <summary>
    /// Injects the ability into this GUI, registering it and putting all of the necessary characteristics into the UI elements
    /// </summary>
    /// <param name="ability">The ability to which information will be taken</param>
    public void InjectAbilityInformation(Ability ability)
    {
        abilityInjected             = ability;

        abilityName.text            = abilityInjected.AbilityName;
        abilityImageField.sprite    = abilityInjected.AbilitySprite;
        descriptionField.text       = abilityInjected.AbilityDescription;

        int helperCount = abilityInjected.HelperEffects.Count;

        for (int i = 0; i < helperCount; ++i)
        {
            GameObject textObject = Instantiate(textField, helperList);
            textObject.GetComponent<TextMeshProUGUI>().text = $"- {abilityInjected.HelperEffects[i]}";
        }

        autoScroller.InjectEffectCount(helperCount);
    }
    /// <summary>
    /// Retrieves the count of the helper effects for the auto scroller
    /// </summary>
    /// <returns>Number of Helper Effects in the ability</returns>
    public int GetHelperCount()
    {
        return abilityInjected.HelperEffects.Count;
    }
        
}