mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
improved Keybind constructors
This commit is contained in:
parent
2118837062
commit
a5a73af01c
2 changed files with 27 additions and 6 deletions
|
@ -57,11 +57,11 @@ namespace MLEM.Ui {
|
|||
/// <summary>
|
||||
/// AA <see cref="Keybind"/> that acts as the buttons on a gamepad that perform the <see cref="Element.OnPressed"/> action.
|
||||
/// </summary>
|
||||
public readonly Keybind GamepadButtons = new Keybind().Add(Buttons.A);
|
||||
public readonly Keybind GamepadButtons = new Keybind(Buttons.A);
|
||||
/// <summary>
|
||||
/// A <see cref="Keybind"/> that acts as the buttons on a gamepad that perform the <see cref="Element.OnSecondaryPressed"/> action.
|
||||
/// </summary>
|
||||
public readonly Keybind SecondaryGamepadButtons = new Keybind().Add(Buttons.X);
|
||||
public readonly Keybind SecondaryGamepadButtons = new Keybind(Buttons.X);
|
||||
/// <summary>
|
||||
/// A <see cref="Keybind"/> that acts as the buttons that select a <see cref="Element"/> that is above the currently selected element.
|
||||
/// </summary>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
|
@ -12,7 +13,27 @@ namespace MLEM.Input {
|
|||
public class Keybind {
|
||||
|
||||
[DataMember]
|
||||
private readonly List<Combination> combinations = new List<Combination>();
|
||||
private Combination[] combinations = Array.Empty<Combination>();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new keybind and adds the given key and modifiers using <see cref="Add(MLEM.Input.GenericInput,MLEM.Input.GenericInput[])"/>
|
||||
/// </summary>
|
||||
/// <param name="key">The key to be pressed.</param>
|
||||
/// <param name="modifiers">The modifier keys that have to be held down.</param>
|
||||
public Keybind(GenericInput key, params GenericInput[] modifiers) {
|
||||
this.Add(key, modifiers);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Keybind(GenericInput, GenericInput[])"/>
|
||||
public Keybind(GenericInput key, ModifierKey modifier) {
|
||||
this.Add(key, modifier);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new keybind with no default combinations
|
||||
/// </summary>
|
||||
public Keybind() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new key combination to this keybind that can optionally be pressed for the keybind to trigger.
|
||||
|
@ -21,7 +42,7 @@ namespace MLEM.Input {
|
|||
/// <param name="modifiers">The modifier keys that have to be held down.</param>
|
||||
/// <returns>This keybind, for chaining</returns>
|
||||
public Keybind Add(GenericInput key, params GenericInput[] modifiers) {
|
||||
this.combinations.Add(new Combination(key, modifiers));
|
||||
this.combinations = this.combinations.Append(new Combination(key, modifiers)).ToArray();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -35,7 +56,7 @@ namespace MLEM.Input {
|
|||
/// </summary>
|
||||
/// <returns>This keybind, for chaining</returns>
|
||||
public Keybind Clear() {
|
||||
this.combinations.Clear();
|
||||
this.combinations = Array.Empty<Combination>();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -46,7 +67,7 @@ namespace MLEM.Input {
|
|||
/// <param name="other">The keybind to copy from</param>
|
||||
/// <returns>This keybind, for chaining</returns>
|
||||
public Keybind CopyFrom(Keybind other) {
|
||||
this.combinations.AddRange(other.combinations);
|
||||
this.combinations = this.combinations.Concat(other.combinations).ToArray();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue