/// <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); }
internal AxisInput(AxisControl axis, ButtonInputSet modifier) { Axis = axis ?? throw new ArgumentNullException(nameof(axis)); if (modifier != null) { Modifier = modifier; } }
internal ButtonInput(ButtonControl button, ButtonInputSet modifier) { Button = button ?? throw new ArgumentNullException(nameof(button)); if (modifier != null) { Modifier = modifier; } }
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); }
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); }
/// <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); }
/// <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); }
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);
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);
public static ButtonInput FromKeyboard(Keys key, ButtonInputSet modifier) => new ButtonInput(new KeyButtonControl(key), modifier);
public static ButtonInput FromGamepad(GamepadButtons button, ButtonInputSet modifier) => new ButtonInput(new GamepadButtonControl(button), modifier);