mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 05:58:35 +01:00
Compare commits
4 commits
c6fe72bdc9
...
3ad024b95a
Author | SHA1 | Date | |
---|---|---|---|
3ad024b95a | |||
ae6ce6e7d5 | |||
54ca580dd3 | |||
4e122175b2 |
4 changed files with 66 additions and 21 deletions
|
@ -26,6 +26,7 @@ Improvements
|
||||||
- Allow better control over the order and layout of a Keybind's combinations
|
- Allow better control over the order and layout of a Keybind's combinations
|
||||||
- Allow setting a gamepad button deadzone in InputHandler
|
- Allow setting a gamepad button deadzone in InputHandler
|
||||||
- Trigger InputHandler key and gamepad repeats for the most recently pressed input
|
- Trigger InputHandler key and gamepad repeats for the most recently pressed input
|
||||||
|
- Added properties and constructors for existing operator overloads to GenericInput
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
- **Fixed a formatting Code only knowing about the last Token that it is applied in**
|
- **Fixed a formatting Code only knowing about the last Token that it is applied in**
|
||||||
|
@ -53,6 +54,7 @@ Improvements
|
||||||
- Automatically update all elements when changing a ui system's viewport
|
- Automatically update all elements when changing a ui system's viewport
|
||||||
- Allow setting a default color for clickable links in UiStyle
|
- Allow setting a default color for clickable links in UiStyle
|
||||||
- Allow ElementHelper's KeybindButton to query a combination at a given index
|
- Allow ElementHelper's KeybindButton to query a combination at a given index
|
||||||
|
- Allow ElementHelper's KeybindButton to accept a Keybind for clearing a combination
|
||||||
- Automatically select the first element when a dropdown is opened in auto nav mode
|
- Automatically select the first element when a dropdown is opened in auto nav mode
|
||||||
- Improved gamepad navigation by employing angles between elements
|
- Improved gamepad navigation by employing angles between elements
|
||||||
- Prefer elements that have the same parent as the currently selected element when using gamepad navigation
|
- Prefer elements that have the same parent as the currently selected element when using gamepad navigation
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>portable</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>false</Optimize>
|
||||||
<OutputPath>bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\</OutputPath>
|
<OutputPath>bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\</OutputPath>
|
||||||
<DefineConstants>DEBUG;TRACE;ANDROID</DefineConstants>
|
<DefineConstants>DEBUG;TRACE;ANDROID</DefineConstants>
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
<AndroidLinkMode>None</AndroidLinkMode>
|
<AndroidLinkMode>None</AndroidLinkMode>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>portable</DebugType>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<OutputPath>bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\</OutputPath>
|
<OutputPath>bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\</OutputPath>
|
||||||
<DefineConstants>TRACE;ANDROID</DefineConstants>
|
<DefineConstants>TRACE;ANDROID</DefineConstants>
|
||||||
|
|
|
@ -115,6 +115,11 @@ namespace MLEM.Ui.Elements {
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="KeybindButton(MLEM.Ui.Anchor,Microsoft.Xna.Framework.Vector2,MLEM.Input.Keybind,MLEM.Input.InputHandler,string,MLEM.Input.Keybind,string,System.Func{MLEM.Input.GenericInput,string},int)"/>
|
||||||
|
public static Button KeybindButton(Anchor anchor, Vector2 size, Keybind keybind, InputHandler inputHandler, string activePlaceholder, GenericInput unbindKey = default, string unboundPlaceholder = "", Func<GenericInput, string> inputName = null, int index = 0) {
|
||||||
|
return KeybindButton(anchor, size, keybind, inputHandler, activePlaceholder, new Keybind(unbindKey), unboundPlaceholder, inputName, index);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a <see cref="Button"/> that acts as a way to input a custom value for a <see cref="Keybind"/>.
|
/// Creates a <see cref="Button"/> that acts as a way to input a custom value for a <see cref="Keybind"/>.
|
||||||
/// Note that only the <see cref="Keybind.Combination"/> at index <paramref name="index"/> of the given keybind is displayed and edited, all others are ignored.
|
/// Note that only the <see cref="Keybind.Combination"/> at index <paramref name="index"/> of the given keybind is displayed and edited, all others are ignored.
|
||||||
|
@ -126,12 +131,12 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <param name="keybind">The keybind that this button should represent</param>
|
/// <param name="keybind">The keybind that this button should represent</param>
|
||||||
/// <param name="inputHandler">The input handler to query inputs with</param>
|
/// <param name="inputHandler">The input handler to query inputs with</param>
|
||||||
/// <param name="activePlaceholder">A placeholder text that is displayed while the keybind is being edited</param>
|
/// <param name="activePlaceholder">A placeholder text that is displayed while the keybind is being edited</param>
|
||||||
/// <param name="unbindKey">An optional generic input that allows the keybind value to be unbound, clearing all combinations</param>
|
/// <param name="unbind">An optional keybind to press that allows the keybind value to be unbound, clearing the combination</param>
|
||||||
/// <param name="unboundPlaceholder">A placeholder text that is displayed if the keybind is unbound</param>
|
/// <param name="unboundPlaceholder">A placeholder text that is displayed if the keybind is unbound</param>
|
||||||
/// <param name="inputName">An optional function to give each input a display name that is easier to read. If this is null, <see cref="GenericInput.ToString"/> is used.</param>
|
/// <param name="inputName">An optional function to give each input a display name that is easier to read. If this is null, <see cref="GenericInput.ToString"/> is used.</param>
|
||||||
/// <param name="index">The index in the <paramref name="keybind"/> that the button should display. Note that, if the index is greater than the amount of combinations, combinations entered using this button will be stored at an earlier index.</param>
|
/// <param name="index">The index in the <paramref name="keybind"/> that the button should display. Note that, if the index is greater than the amount of combinations, combinations entered using this button will be stored at an earlier index.</param>
|
||||||
/// <returns>A keybind button with the given settings</returns>
|
/// <returns>A keybind button with the given settings</returns>
|
||||||
public static Button KeybindButton(Anchor anchor, Vector2 size, Keybind keybind, InputHandler inputHandler, string activePlaceholder, GenericInput unbindKey = default, string unboundPlaceholder = "", Func<GenericInput, string> inputName = null, int index = 0) {
|
public static Button KeybindButton(Anchor anchor, Vector2 size, Keybind keybind, InputHandler inputHandler, string activePlaceholder, Keybind unbind = default, string unboundPlaceholder = "", Func<GenericInput, string> inputName = null, int index = 0) {
|
||||||
string GetCurrentName() => keybind.TryGetCombination(index, out var combination) ? combination.ToString(" + ", inputName) : unboundPlaceholder;
|
string GetCurrentName() => keybind.TryGetCombination(index, out var combination) ? combination.ToString(" + ", inputName) : unboundPlaceholder;
|
||||||
|
|
||||||
var button = new Button(anchor, size, GetCurrentName());
|
var button = new Button(anchor, size, GetCurrentName());
|
||||||
|
@ -145,7 +150,7 @@ namespace MLEM.Ui.Elements {
|
||||||
button.SetData("Active", true);
|
button.SetData("Active", true);
|
||||||
activeNext = false;
|
activeNext = false;
|
||||||
} else if (button.GetData<bool>("Active")) {
|
} else if (button.GetData<bool>("Active")) {
|
||||||
if (unbindKey != default && inputHandler.IsPressed(unbindKey)) {
|
if (unbind != null && unbind.IsPressed(inputHandler)) {
|
||||||
keybind.Remove((c, i) => i == index);
|
keybind.Remove((c, i) => i == index);
|
||||||
button.Text.Text = unboundPlaceholder;
|
button.Text.Text = unboundPlaceholder;
|
||||||
button.SetData("Active", false);
|
button.SetData("Active", false);
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespace MLEM.Input {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A generic input represents any kind of input key.
|
/// A generic input represents any kind of input key.
|
||||||
/// This includes <see cref="Keys"/> for keyboard keys, <see cref="MouseButton"/> for mouse buttons and <see cref="Buttons"/> for gamepad buttons.
|
/// This includes <see cref="Keys"/> for keyboard keys, <see cref="MouseButton"/> for mouse buttons and <see cref="Buttons"/> for gamepad buttons.
|
||||||
/// For creating and extracting inputs from a generic input, the implicit operators and <see cref="Type"/> can be used.
|
/// For creating and extracting inputs from a generic input, the implicit operators and <see cref="Type"/> can additionally be used.
|
||||||
/// Note that this type is serializable using <see cref="DataContractAttribute"/>.
|
/// Note that this type is serializable using <see cref="DataContractAttribute"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataContract]
|
[DataContract]
|
||||||
|
@ -20,6 +20,46 @@ namespace MLEM.Input {
|
||||||
[DataMember]
|
[DataMember]
|
||||||
private readonly int value;
|
private readonly int value;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns this generic input's <see cref="Keys"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="InvalidOperationException">If this generic input's <see cref="Type"/> is not <see cref="InputType.Keyboard"/> or <see cref="InputType.None"/>.</exception>
|
||||||
|
public Keys Key {
|
||||||
|
get {
|
||||||
|
if (this.Type == InputType.None)
|
||||||
|
return Keys.None;
|
||||||
|
return this.Type == InputType.Keyboard ? (Keys) this.value : throw new InvalidOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Returns this generic input's <see cref="MouseButton"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="InvalidOperationException">If this generic input's <see cref="Type"/> is not <see cref="InputType.Mouse"/>.</exception>
|
||||||
|
public MouseButton MouseButton => this.Type == InputType.Mouse ? (MouseButton) this.value : throw new InvalidOperationException();
|
||||||
|
/// <summary>
|
||||||
|
/// Returns this generic input's <see cref="Buttons"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="InvalidOperationException">If this generic input's <see cref="Type"/> is not <see cref="InputType.Gamepad"/>.</exception>
|
||||||
|
public Buttons Button => this.Type == InputType.Gamepad ? (Buttons) this.value : throw new InvalidOperationException();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new generic input from the given keyboard <see cref="Keys"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">The key to convert.</param>
|
||||||
|
public GenericInput(Keys key) : this(InputType.Keyboard, (int) key) {}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new generic input from the given <see cref="MouseButton"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="button">The button to convert.</param>
|
||||||
|
public GenericInput(MouseButton button) : this(InputType.Mouse, (int) button) {}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new generic input from the given gamepad <see cref="Buttons"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="button">The button to convert.</param>
|
||||||
|
public GenericInput(Buttons button) : this(InputType.Gamepad, (int) button) {}
|
||||||
|
|
||||||
private GenericInput(InputType type, int value) {
|
private GenericInput(InputType type, int value) {
|
||||||
this.Type = type;
|
this.Type = type;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
@ -83,10 +123,10 @@ namespace MLEM.Input {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts a <see cref="Keys"/> to a generic input.
|
/// Converts a <see cref="Keys"/> to a generic input.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="keys">The keys to convert</param>
|
/// <param name="key">The keys to convert</param>
|
||||||
/// <returns>The resulting generic input</returns>
|
/// <returns>The resulting generic input</returns>
|
||||||
public static implicit operator GenericInput(Keys keys) {
|
public static implicit operator GenericInput(Keys key) {
|
||||||
return new GenericInput(InputType.Keyboard, (int) keys);
|
return new GenericInput(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -95,16 +135,16 @@ namespace MLEM.Input {
|
||||||
/// <param name="button">The button to convert</param>
|
/// <param name="button">The button to convert</param>
|
||||||
/// <returns>The resulting generic input</returns>
|
/// <returns>The resulting generic input</returns>
|
||||||
public static implicit operator GenericInput(MouseButton button) {
|
public static implicit operator GenericInput(MouseButton button) {
|
||||||
return new GenericInput(InputType.Mouse, (int) button);
|
return new GenericInput(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts a <see cref="Buttons"/> to a generic input.
|
/// Converts a <see cref="Buttons"/> to a generic input.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="buttons">The buttons to convert</param>
|
/// <param name="button">The buttons to convert</param>
|
||||||
/// <returns>The resulting generic input</returns>
|
/// <returns>The resulting generic input</returns>
|
||||||
public static implicit operator GenericInput(Buttons buttons) {
|
public static implicit operator GenericInput(Buttons button) {
|
||||||
return new GenericInput(InputType.Gamepad, (int) buttons);
|
return new GenericInput(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -112,11 +152,9 @@ namespace MLEM.Input {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">The input to convert</param>
|
/// <param name="input">The input to convert</param>
|
||||||
/// <returns>The resulting keys</returns>
|
/// <returns>The resulting keys</returns>
|
||||||
/// <exception cref="ArgumentException">If the given generic input's <see cref="Type"/> is not <see cref="InputType.Keyboard"/> or <see cref="InputType.None"/></exception>
|
/// <exception cref="InvalidOperationException">If the given generic input's <see cref="Type"/> is not <see cref="InputType.Keyboard"/> or <see cref="InputType.None"/></exception>
|
||||||
public static implicit operator Keys(GenericInput input) {
|
public static implicit operator Keys(GenericInput input) {
|
||||||
if (input.Type == InputType.None)
|
return input.Key;
|
||||||
return Keys.None;
|
|
||||||
return input.Type == InputType.Keyboard ? (Keys) input.value : throw new ArgumentException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -124,9 +162,9 @@ namespace MLEM.Input {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">The input to convert</param>
|
/// <param name="input">The input to convert</param>
|
||||||
/// <returns>The resulting button</returns>
|
/// <returns>The resulting button</returns>
|
||||||
/// <exception cref="ArgumentException">If the given generic input's <see cref="Type"/> is not <see cref="InputType.Mouse"/></exception>
|
/// <exception cref="InvalidOperationException">If the given generic input's <see cref="Type"/> is not <see cref="InputType.Mouse"/></exception>
|
||||||
public static implicit operator MouseButton(GenericInput input) {
|
public static implicit operator MouseButton(GenericInput input) {
|
||||||
return input.Type == InputType.Mouse ? (MouseButton) input.value : throw new ArgumentException();
|
return input.MouseButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -134,9 +172,9 @@ namespace MLEM.Input {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input">The input to convert</param>
|
/// <param name="input">The input to convert</param>
|
||||||
/// <returns>The resulting buttons</returns>
|
/// <returns>The resulting buttons</returns>
|
||||||
/// <exception cref="ArgumentException">If the given generic input's <see cref="Type"/> is not <see cref="InputType.Gamepad"/></exception>
|
/// <exception cref="InvalidOperationException">If the given generic input's <see cref="Type"/> is not <see cref="InputType.Gamepad"/></exception>
|
||||||
public static implicit operator Buttons(GenericInput input) {
|
public static implicit operator Buttons(GenericInput input) {
|
||||||
return input.Type == InputType.Gamepad ? (Buttons) input.value : throw new ArgumentException();
|
return input.Button;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in a new issue