using UnityEngine;
using System.Collections;

public class UITurnLoopParameters : MonoBehaviour {

    public UnityEngine.UI.Text SpeedLabel;
    public UnityEngine.UI.Text ProjectileSpeedLabel;

    public Transform SpawnRatPrefab;
    public Transform SpawnBatPrefab;
    public Transform SpawnWizardPrefab;

    public Transform PlayerWavePrefab;


    public void SetInputCancelsRender(bool val)
    {
        TurnBasedGameLoop.instance.InputCancelsRender = val;
    }

    public void SetSimultaneousTurns(bool val)
    {
        TurnBasedGameLoop.instance.SimultaneousTurns = val;
    }

    public void SetAIWaitsForPlayerRender(bool val)
    {
        TurnBasedGameLoop.instance.AIWaitsForPlayerRender = val;
    }

    public void SetMovementRenderTime(float val)
    {
        TurnBasedGameLoop.instance.MovementRenderTime = val;
        SpeedLabel.text = "Animation Time\n" + Mathf.Round(val*1000) + "ms";
    }

    public void SetProjectileSpeed(float val)
    {
        float TILESIZE = 0.3f;
        float speed = val * TILESIZE;

        TurnBasedGameLoop.instance.ProjectileSpeed = speed;
        ProjectileSpeedLabel.text = "Projectile Speed\n" + Mathf.RoundToInt(val) + " tiles/sec";
    }

    public void SpawnRat()
    {
        GameObject.Instantiate(SpawnRatPrefab);
    }

    public void SpawnBat()
    {
        GameObject.Instantiate(SpawnBatPrefab);
    }
    public void SpawnWizard()
    {
        GameObject.Instantiate(SpawnWizardPrefab);
    }

    public void SetPlayerAlive(bool val)
    {
        if (!val)
            DestroyPlayer();
        else
            SpawnPlayer();
    }

    public void LaunchDiscuss()
    {
        if( Application.isWebPlayer || Application.platform == RuntimePlatform.WebGLPlayer)
            Application.ExternalEval("window.open(\"https://twitter.com/intent/user?screen_name=pkenneydev\")");
        else
            Application.OpenURL("https://twitter.com/intent/user?screen_name=pkenneydev");
    }

    private void SpawnPlayer()
    {
        GameObject.Instantiate(PlayerWavePrefab);        
    }

    private void DestroyPlayer()
    {
        GameObject player = GameObject.Find("Player(Clone)");
        if (player == null)
            return;

        player.GetComponent<Actor>().Die();
    }
}
