using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIValue : MonoBehaviour {

    public float realValue = 0;
    public UIType type;
    public bool realToggle = false;

    public enum UIType 
    {
        Slider,
        Press,
        Hold,
        Switch,
        Switch2,
        Dial,
        Wire
    }

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        if (type == UIType.Hold)

        {
            if (realToggle)
            {
                realValue += Time.deltaTime;
            }
        }
	}

    public float GetValue()
    {
        switch (type)
        {
            case UIType.Slider:
                return GetComponent<Slider>().value;
                break;
            case UIType.Press:
                if (realToggle)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
                break;
            case UIType.Hold:
                return realValue;
                break;
            case UIType.Switch:
                if (GetComponent<RockerToggle>().Up)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
                break;
            case UIType.Switch2:
                if (GetComponent<ToggleBigLever>().Right)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
                break;
            case UIType.Dial:
                return GetComponent<SpinDial>().rounded;
                break;
            case UIType.Wire:
                return GetComponent<DragablePin>().current;
                break;
        }
        return 0;
    }

    public void SetState(bool state)
    {
        realToggle = state;
    }

    public bool checkValue(int test)
    {
        Debug.Log(type.ToString() + " :i " + GetValue());
        if (test == (int)GetValue())
        {
            return true;
        }
        return false;
    }

    public bool checkValue(float test)
    {
        Debug.Log(type.ToString() + " :f " + GetValue());
        if (test >= (int)GetValue())
        {
            return true;
        }
        return false;
    }

}
