示例#1
0
        /// <summary>
        /// Registers a button input to the controller.
        /// </summary>
        /// <param name="inputName">Name used for identification.</param>
        /// <param name="button">ButtonInput to add.</param>
        /// <param name="replace">Whether or not to replace existing inputs with the same inputName.</param>
        /// <returns>A ButtonInputSet created from the provided ButtonInput.</returns>
        public ButtonInputSet AddButtonInput(string inputName, ButtonInput button, bool replace = false)
        {
            ButtonInputSet set;

            if (buttons.ContainsKey(inputName))
            {
                if (replace)
                {
                    buttons.Remove(inputName);
                    set = new ButtonInputSet(button);
                    buttons.Add(inputName, set);
                }
                else
                {
                    set = buttons[inputName];
                    set.Inputs.Add(button);
                }
            }
            else
            {
                set = new ButtonInputSet(button);
                buttons.Add(inputName, set);
            }
            set.Key         = inputName;
            set.PlayerIndex = PlayerIndex;
            return(set);
        }
示例#2
0
 internal AxisInput(AxisControl axis, ButtonInputSet modifier)
 {
     Axis = axis ?? throw new ArgumentNullException(nameof(axis));
     if (modifier != null)
     {
         Modifier = modifier;
     }
 }
示例#3
0
 internal ButtonInput(ButtonControl button, ButtonInputSet modifier)
 {
     Button = button ?? throw new ArgumentNullException(nameof(button));
     if (modifier != null)
     {
         Modifier = modifier;
     }
 }
示例#4
0
        public ButtonInputSet DeepCopy()
        {
            List <ButtonInput> copyInputs = new List <ButtonInput>();

            foreach (ButtonInput existing in Inputs)
            {
                copyInputs.Add(existing.DeepCopy());
            }

            ButtonInputSet copy = new ButtonInputSet(copyInputs);

            return(copy);
        }
示例#5
0
        public bool RemoveButtonInput(string inputName, ButtonInput button)
        {
            if (!buttons.ContainsKey(inputName))
            {
                return(false);
            }

            ButtonInputSet buttonInput = buttons[inputName];

            buttonInput.Inputs.Remove(button);
            if (buttonInput.Inputs.Count == 0)
            {
                buttons.Remove(inputName);
            }
            return(true);
        }
示例#6
0
        /// <summary>
        /// Removes a ButtonInputSet from the controller.
        /// </summary>
        /// <param name="input">ButtonInputSet to remove.</param>
        /// <returns>True if the ButtonInputSet was found and removed.</returns>
        public bool RemoveButtonInput(ButtonInputSet input)
        {
            if (input == null)
            {
                return(false);
            }

            foreach (KeyValuePair <string, ButtonInputSet> btn in buttons)
            {
                if (btn.Value == input)
                {
                    buttons.Remove(btn.Key);
                    return(true);
                }
            }
            return(false);
        }
示例#7
0
        /// <summary>
        /// Registers multiple button inputs to the controller, under the same ID.
        /// </summary>
        /// <param name="inputName">Name used for identification.</param>
        /// <param name="replace">Whether or not to replace existing inputs with the same inputName.</param>
        /// <param name="buttons">One or more buttons to add.</param>
        /// <returns>A ButtonInputSet created from the provided ButtonInputs.</returns>
        public ButtonInputSet AddButtonInput(string inputName, bool replace = false, params ButtonInput[] buttons)
        {
            ButtonInputSet set = null;

            if (replace)
            {
                this.buttons.Remove(inputName);
            }
            for (int i = 0; i < buttons.Length; i++)
            {
                set = AddButtonInput(inputName, buttons[i]);
            }
            if (set == null)
            {
                return(null);
            }

            set.Key         = inputName;
            set.PlayerIndex = PlayerIndex;
            return(set);
        }
示例#8
0
 public static AxisInput FromKeyboard(Keys positiveKey, Keys negativeKey, ButtonInputSet modifier, float?sensitivity = null, float?gravity = null, float deadzone = 0.05f, bool reverse = false)
 => new AxisInput(new KeyAxisControl(positiveKey, negativeKey, sensitivity, gravity, deadzone, reverse), modifier);
示例#9
0
 public static AxisInput FromThumbStick(ThumbSticks thumbStick, ThumbSticksAxis thumbSticksAxis, ButtonInputSet modifier, float deadzone = 0.05f, bool reverse = false)
 => new AxisInput(new GamepadAxisControl(thumbStick, thumbSticksAxis, deadzone, reverse), modifier);
示例#10
0
 public static ButtonInput FromKeyboard(Keys key, ButtonInputSet modifier)
 => new ButtonInput(new KeyButtonControl(key), modifier);
示例#11
0
 public static ButtonInput FromGamepad(GamepadButtons button, ButtonInputSet modifier)
 => new ButtonInput(new GamepadButtonControl(button), modifier);