using UnityEngine;
using System.Collections;

public class GlyphUI : MonoBehaviour {

    public GameObject GlyphSelector;

    private Animator _myAnimator;
    private bool LateInit = false;

    private bool SummoningOpen = false;

	// Use this for initialization
	void Start () {
        _myAnimator = GetComponent<Animator>();
        GameStateController.Instance.GameStateChanged += Instance_GameStateChanged;
	}

    void Instance_GameStateChanged(EGameState oldState, EGameState newState)
    {
        if (newState == EGameState.Summoming)
        {
			audio.Play ();
            _myAnimator.SetBool("Summoning", true);
            SummoningOpen = true;
            if (CharacterManager.instance.PlayerCharacter.GlyphStack.Count > 0)
            {
                GlyphSelector.SetActive(true);
            }
        }
        else
        {
            _myAnimator.SetBool("Summoning", false);
            SummoningOpen = false;
            GlyphSelector.SetActive(false);
        }
    }

    void PlayerCharacter_GlyphStackChanged(System.Collections.Generic.Stack<DamageType> stack)
    {
        if (SummoningOpen && stack.Count > 0)
        {
            GlyphSelector.SetActive(true);
        }
        else
        {
            GlyphSelector.SetActive(false);
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (!LateInit)
        {
            // der playercharacter hat sich nicht unbedingt schon angemeldet, wenn man das hier in
            // der Start() methode macht...
            CharacterManager.instance.PlayerCharacter.GlyphStackChanged += PlayerCharacter_GlyphStackChanged;
            LateInit = true;
        }
    }
}
