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

namespace TFramework
{
    public class DefaultInputDevice : InputDeviceBase
    {
        /// <summary>
        /// UpperLower轴线值
        /// </summary>
        private float _upperLowerValue = 0;

        public override void OnRun()
        {
            if (Input.GetMouseButtonDown(0)) InputManager.SetV_KeyDown(InputKeyType.MouseLeft);
            else if (Input.GetMouseButtonUp(0)) InputManager.SetV_KeyUp(InputKeyType.MouseLeft);

            if (Input.GetMouseButtonDown(1)) InputManager.SetV_KeyDown(InputKeyType.MouseRight);
            else if (Input.GetMouseButtonUp(1)) InputManager.SetV_KeyUp(InputKeyType.MouseRight);

            if (Input.GetMouseButtonDown(2)) InputManager.SetV_KeyDown(InputKeyType.MouseMiddle);
            else if (Input.GetMouseButtonUp(2)) InputManager.SetV_KeyUp(InputKeyType.MouseMiddle);


            InputManager.SetV_Axis(InputAxisType.MouseX, Input.GetAxis("Mouse X"));
            InputManager.SetV_Axis(InputAxisType.MouseY, Input.GetAxis("Mouse Y"));
            InputManager.SetV_Axis(InputAxisType.MouseScrollWheel, Input.GetAxis("Mouse ScrollWheel"));

            InputManager.SetV_Axis(InputAxisType.Horizontal, Input.GetAxis("Horizontal"));
            InputManager.SetV_Axis(InputAxisType.Vertical, Input.GetAxis("Vertical"));

            if (Input.GetKey(KeyCode.Q)) _upperLowerValue -= Time.deltaTime;
            else if (Input.GetKey(KeyCode.E)) _upperLowerValue += Time.deltaTime;
            else _upperLowerValue = 0;
            InputManager.SetV_Axis(InputAxisType.UpperLower, Mathf.Clamp(_upperLowerValue, -1, 1));

            InputManager.SetVirtualMousePosition(Input.mousePosition);
        }

        public override void OnShutdown()
        {
            InputManager.RemoveV_Key(InputKeyType.MouseLeft);
            InputManager.RemoveV_Key(InputKeyType.MouseRight);
            InputManager.RemoveV_Key(InputKeyType.MouseMiddle);

            InputManager.RemoveV_Axis(InputAxisType.MouseX);
            InputManager.RemoveV_Axis(InputAxisType.MouseY);
            InputManager.RemoveV_Axis(InputAxisType.MouseScrollWheel);
            InputManager.RemoveV_Axis(InputAxisType.Horizontal);
            InputManager.RemoveV_Axis(InputAxisType.Vertical);
            InputManager.RemoveV_Axis(InputAxisType.UpperLower);
        }

        public override void OnStartUp()
        {

            InputManager.AddV_Key(InputKeyType.MouseLeft);
            InputManager.AddV_Key(InputKeyType.MouseRight);
            InputManager.AddV_Key(InputKeyType.MouseMiddle);

            InputManager.AddV_Axis(InputAxisType.MouseX);
            InputManager.AddV_Axis(InputAxisType.MouseY);
            InputManager.AddV_Axis(InputAxisType.MouseScrollWheel);
            InputManager.AddV_Axis(InputAxisType.Horizontal);
            InputManager.AddV_Axis(InputAxisType.Vertical);
            InputManager.AddV_Axis(InputAxisType.UpperLower);
        }
    }

    /// <summary>
    /// 输入轴线类型
    /// </summary>
    public static class InputAxisType
    {
        /// <summary>
        /// 鼠标X轴移动
        /// </summary>
        public static string MouseX = "MouseX";
        /// <summary>
        /// 鼠标Y轴移动
        /// </summary>
        public static string MouseY = "MouseY";
        /// <summary>
        /// 鼠标滚轮滚动
        /// </summary>
        public static string MouseScrollWheel = "MouseScrollWheel";
        /// <summary>
        /// 键盘水平输入
        /// </summary>
        public static string Horizontal = "Horizontal";
        /// <summary>
        /// 键盘垂直输入
        /// </summary>
        public static string Vertical = "Vertical";
        /// <summary>
        /// 键盘上下输入
        /// </summary>
        public static string UpperLower = "UpperLower";
    }

    /// <summary>
    /// 输入按键类型
    /// </summary>
    public static class InputKeyType
    {
        /// <summary>
        /// 鼠标左键
        /// </summary>
        public static string MouseLeft = "MouseLeft";
        /// <summary>
        /// 鼠标右键
        /// </summary>
        public static string MouseRight = "MouseRight";
        /// <summary>
        /// 鼠标中键
        /// </summary>
        public static string MouseMiddle = "MouseMiddle";
    }
}
