コード例 #1
0
 private Input()
 {
     Keyboard   = new KeyboardManager();
     Mouse      = new MouseManager();
     Joystick   = new JoystickManager();
     Actions    = new ActionSet();
     LastDevice = InputDevice.Mouse;
 }
コード例 #2
0
        /// <summary>
        ///   The value of the axis.
        /// </summary>
        /// <param name="axis">
        ///   The axis to check.
        /// </param>
        /// <returns>
        ///   The value of the axis if it is valid, otherwise 0.0.
        /// </returns>
        public float GetAxis(string axis)
        {
            if (!JoystickManager.IsAxis(axis))
            {
                return(0.0f);
            }

            return(GetAxis((uint)JoystickManager.ToAxis(axis)));
        }
コード例 #3
0
        /// <summary>
        ///   If the button is pressed.
        /// </summary>
        /// <param name="but">
        ///   The button to check.
        /// </param>
        /// <returns>
        ///   True if the button is valid and is pressed, otherwise false.
        /// </returns>
        public bool IsPressed(string but)
        {
            if (!JoystickManager.IsButton(but))
            {
                return(false);
            }

            return(IsPressed((uint)JoystickManager.ToButton(but)));
        }
コード例 #4
0
        /// <summary>
        ///   Checks if the given string represents a valid axis for the given input device.
        /// </summary>
        /// <param name="dev">
        ///   The input device.
        /// </param>
        /// <param name="axis">
        ///   The axis string.
        /// </param>
        /// <returns>
        ///   True if the given string represents a valid axis for the given input device, otherwise false.
        /// </returns>
        public static bool IsAxis(InputDevice dev, string axis)
        {
            if (dev is InputDevice.Mouse)
            {
                return(MouseManager.IsAxis(axis));
            }
            else if (dev is InputDevice.Joystick)
            {
                return(JoystickManager.IsAxis(axis));
            }

            return(false);
        }
コード例 #5
0
        /// <summary>
        ///   Checks if the given string represents a valid buttton/key for the given input device.
        /// </summary>
        /// <param name="dev">
        ///   The input device.
        /// </param>
        /// <param name="but">
        ///   The button/key string.
        /// </param>
        /// <returns>
        ///   True if the given string represents a valid button/key for the given input device, otherwise false.
        /// </returns>
        public static bool IsButton(InputDevice dev, string but)
        {
            if (dev is InputDevice.Keyboard)
            {
                return(KeyboardManager.IsKey(but));
            }
            else if (dev is InputDevice.Mouse)
            {
                return(MouseManager.IsButton(but));
            }
            else if (dev is InputDevice.Joystick)
            {
                return(JoystickManager.IsButton(but));
            }

            return(false);
        }
コード例 #6
0
ファイル: InputMap.cs プロジェクト: BrokenShards/MiInput
        /// <summary>
        ///   Loads data from an xml element.
        /// </summary>
        /// <param name="ele">
        ///   The element to load data from.
        /// </param>
        /// <returns>
        ///   True if loaded successfully and false otherwise.
        /// </returns>
        public override bool LoadFromXml(XmlElement ele)
        {
            if (ele is null)
            {
                return(Logger.LogReturn("Failed loading InputMap: Null xml element.", false, LogType.Error));
            }

            // Type
            {
                string loname = ele.Name.ToLower();
                Type = loname == "button" ? InputType.Button : (loname == "axis" ? InputType.Axis : (InputType)(-1));

                if (Type < 0)
                {
                    return(Logger.LogReturn("Failed loading InputMap: Invalid input type.", false, LogType.Error));
                }
            }

            // Device
            {
                if (!ele.HasAttribute(nameof(Device)))
                {
                    return(Logger.LogReturn("Failed loading InputMap: No Device attribute.", false, LogType.Error));
                }
                if (!Enum.TryParse(ele.GetAttribute(nameof(Device)), true, out InputDevice dev))
                {
                    return(Logger.LogReturn("Failed loading InputMap: Invalid Device attribute.", false, LogType.Error));
                }

                Device = dev;
            }

            // Value
            {
                if (!ele.HasAttribute(nameof(Value)) && !ele.HasAttribute("Positive") &&
                    !ele.HasAttribute(nameof(Negative)))
                {
                    return(Logger.LogReturn("Failed loading InputMap: No Positive and Negative or Value attributes.", false, LogType.Error));
                }

                string val = ele.GetAttribute(nameof(Value)),
                       neg = ele.GetAttribute(nameof(Negative));

                if (string.IsNullOrWhiteSpace(val))
                {
                    val = ele.GetAttribute("Positive");
                }

                if (string.IsNullOrWhiteSpace(val))
                {
                    val = null;
                }
                if (string.IsNullOrWhiteSpace(neg))
                {
                    neg = null;
                }

                if (val is null && neg is null)
                {
                    return(Logger.LogReturn("Failed loading InputMap: Invalid Positive, Negative and/or Value attributes.", false, LogType.Error));
                }

                if (Device is InputDevice.Keyboard)
                {
                    if (val is not null && !KeyboardManager.IsKey(val))
                    {
                        return(Logger.LogReturn("Failed loading InputMap: Invalid Positive or Value attribute.", false, LogType.Error));
                    }
                    if (neg is not null && !KeyboardManager.IsKey(neg))
                    {
                        return(Logger.LogReturn("Failed loading InputMap: Invalid Negative attribute.", false, LogType.Error));
                    }
                }
                else if (Device is InputDevice.Mouse)
                {
                    if (Type is InputType.Axis)
                    {
                        if (!MouseManager.IsAxis(val))
                        {
                            return(Logger.LogReturn("Failed loading InputMap: Unable to parse mouse axis.", false, LogType.Error));
                        }
                    }
                    else if (Type is InputType.Button)
                    {
                        if (val is not null && !MouseManager.IsButton(val))
                        {
                            return(Logger.LogReturn("Failed loading InputMap: Invalid Positive or Value attribute.", false, LogType.Error));
                        }
                        if (neg is not null && !MouseManager.IsButton(neg))
                        {
                            return(Logger.LogReturn("Failed loading InputMap: Invalid Negative attribute.", false, LogType.Error));
                        }
                    }
                }
                else if (Device is InputDevice.Joystick)
                {
                    if (Type is InputType.Axis)
                    {
                        if (!JoystickManager.IsAxis(val))
                        {
                            return(Logger.LogReturn("Failed loading InputMap: Unable to parse joystick axis.", false, LogType.Error));
                        }
                    }
                    else if (Type is InputType.Button)
                    {
                        if (val is not null && !JoystickManager.IsButton(val))
                        {
                            return(Logger.LogReturn("Failed loading InputMap: Invalid Positive or Value attribute.", false, LogType.Error));
                        }
                        if (neg is not null && !JoystickManager.IsButton(neg))
                        {
                            return(Logger.LogReturn("Failed loading InputMap: Invalid Negative attribute.", false, LogType.Error));
                        }
                    }
                }

                Value    = val ?? string.Empty;
                Negative = neg ?? string.Empty;
            }

            // Invert
            {
                if (ele.HasAttribute(nameof(Invert)))
                {
                    string invert = ele.GetAttribute(nameof(Invert));

                    if (string.IsNullOrWhiteSpace(invert))
                    {
                        return(Logger.LogReturn("Failed loading InputMap: Invalid Invert attribute.", false, LogType.Error));
                    }
                    if (!bool.TryParse(invert, out bool i))
                    {
                        return(Logger.LogReturn("Failed loading InputMap: Unable to parse Invert attribute.", false, LogType.Error));
                    }

                    Invert = i;
                }
            }

            return(true);
        }
コード例 #7
0
 /// <summary>
 ///   Copy constructor.
 /// </summary>
 /// <param name="man">
 ///   The manager to copy.
 /// </param>
 public JoystickManager(JoystickManager man)
 {
     m_last    = new JoystickState(man.m_last);
     m_current = new JoystickState(man.m_current);
 }