using UnityEngine;
using System.Collections;

public class WaveInfoManager : MonoBehaviour
{
    public Sprite[] WaveInfoSprites;
    protected MasterControllerScript mcs;
    PlayerController playerScript;

    void Start()
    {
        mcs = GameObject.Find("MasterController").GetComponent<MasterControllerScript>();
        playerScript = GameObject.Find("TestMans").GetComponent<PlayerController>();
    }
    void OnGUI()
    {
        GUIStyle myStyle = playerScript.fontStyle;
        int oldsize = myStyle.fontSize;
        TextAnchor oldAlingment = myStyle.alignment;
        myStyle.alignment = TextAnchor.UpperCenter;

        if (mcs.bPlayerDead && mcs.fTimeSincePlayerDied > 4.0f)
        {
            SpriteRenderer sr = GetComponent<SpriteRenderer>();
            sr.enabled = false;

            float fYeller = 0.9f + 0.1f * Mathf.Sin(Time.realtimeSinceStartup * 4.0f);
            myStyle.fontSize = 48;
            myStyle.normal.textColor = Color.white;
            GUI.Label(new Rect(0, 90, Screen.width, 60), "GAME OVER", myStyle);
            GUI.Label(new Rect(0, 150, Screen.width, 60), "A WINNER IS U.N.", myStyle);
            myStyle.fontSize = 36;
            GUI.Label(new Rect(0, 300, Screen.width, 40), "Final Score", myStyle);
            myStyle.normal.textColor = new Color(fYeller,fYeller, 0.2f, 1);
            GUI.Label(new Rect(0, 350, Screen.width, 40), mcs.iScore.ToString(), myStyle);
            myStyle.normal.textColor = Color.white;
            GUI.Label(new Rect(0, 400, Screen.width, 40), "You Crushed Your Way To", myStyle);
            myStyle.normal.textColor = new Color(fYeller, fYeller, 0.2f, 1);
            GUI.Label(new Rect(0, 450, Screen.width, 40), "Wave " + mcs.iWhatWaveIsIt.ToString(), myStyle);

            myStyle.fontSize = 36;
            GUI.Label(new Rect(0, 520, Screen.width, 40), "Press Space to", myStyle);
            GUI.Label(new Rect(0, 570, Screen.width, 40), "Try Again!", myStyle);
            myStyle.normal.textColor = Color.white;

            if (Input.GetKey(KeyCode.Space))
                Application.LoadLevel(Application.loadedLevel);
        }
        else
        {
            if (mcs.bIsBonusStage)
            {
                myStyle.fontSize = 36;
                myStyle.normal.textColor = new Color(Random.value, Random.value, Random.value, 1);
                GUI.Label(new Rect(0, 100, Screen.width, 40), "BONUS STAGE!", myStyle);

            }
            else if (mcs.bIsBossStage && mcs.iBlockCountThisWave < 80)
            {
                myStyle.fontSize = 48;
                myStyle.normal.textColor = new Color(0.9f + 0.1f * Mathf.Sin(Time.realtimeSinceStartup * 4.0f), 0.2f, 0.2f, 1);
                GUI.Label(new Rect(0, 90, Screen.width, 60), "WARNING!", myStyle);

                myStyle.fontSize = 24;
                myStyle.normal.textColor = Color.white;
                GUI.Label(new Rect(0, 150, Screen.width, 40), "The UN Peacekeeping", myStyle);
                GUI.Label(new Rect(0, 180, Screen.width, 40), "Medical Delivery Dreadnaught", myStyle);
                if (mcs.ActiveBoss != null)
                {
                    BossNose bn = mcs.ActiveBoss.GetComponent<BossNose>();
                    myStyle.normal.textColor = Color.yellow;
                    GUI.Label(new Rect(0, 210, Screen.width, 40), bn.strShipName, myStyle);
                }
                myStyle.normal.textColor = Color.white;
                GUI.Label(new Rect(0, 240, Screen.width, 40), "is approaching!", myStyle);

            }
            else if (mcs.bAttractScreen )
            {
                float fYeller = 0.9f + 0.1f * Mathf.Sin(Time.realtimeSinceStartup * 4.0f);
                myStyle.fontSize = 48;
                myStyle.normal.textColor = Color.white;
                GUI.Label(new Rect(0, 90, Screen.width, 60), "Blue Helmet Beatdown!", myStyle);
                myStyle.fontSize = 24;
                GUI.Label(new Rect(0, 250, Screen.width, 40), "Spawned in a secret unethical experiment", myStyle);
                GUI.Label(new Rect(0, 300, Screen.width, 40), "(funded by FIFA and the IMF)", myStyle);
                GUI.Label(new Rect(0, 350, Screen.width, 40), "You yearn for freedom and are fleeing", myStyle);
                GUI.Label(new Rect(0, 400, Screen.width, 40), "the Peacekeeping forces of the UN!", myStyle);
                myStyle.normal.textColor = new Color(fYeller, fYeller, 0.2f, 1);
                myStyle.fontSize = 36;
                GUI.Label(new Rect(0, 500, Screen.width, 40), "Press Space to", myStyle);
                GUI.Label(new Rect(0, 550, Screen.width, 40), "BE THE MONSTER!", myStyle);
                myStyle.normal.textColor = Color.white;

                myStyle.fontSize = 12;
                GUI.Label(new Rect(0, 620, Screen.width, 16), "Jim Shepard | @madjackmcmad", myStyle);
                GUI.Label(new Rect(0, 636, Screen.width, 16), "Created in 48 hours for", myStyle);
                GUI.Label(new Rect(0, 652, Screen.width, 16), "Ludum Dare 33 21-23 August 2015", myStyle);
                
            }
            else if (mcs.iBlockCountThisWave < 10)
            {
                myStyle.fontSize = 36;
                GUI.Label(new Rect(0, 100, Screen.width, 40), "WAVE " + mcs.iWhatWaveIsIt, myStyle);
            }
        }

        playerScript.fontStyle.fontSize = oldsize;
        playerScript.fontStyle.normal.textColor = Color.white;
        playerScript.fontStyle.alignment = oldAlingment;
    }
}
