1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-25 05:58:35 +01:00

Compare commits

..

No commits in common. "3ad024b95a8dd2e6d495ec2f1f7f30eabfb8da17" and "c6fe72bdc9a439d1f20d95acd6c3623d021e61c6" have entirely different histories.

4 changed files with 21 additions and 66 deletions

View file

@ -26,7 +26,6 @@ Improvements
- Allow better control over the order and layout of a Keybind's combinations
- Allow setting a gamepad button deadzone in InputHandler
- Trigger InputHandler key and gamepad repeats for the most recently pressed input
- Added properties and constructors for existing operator overloads to GenericInput
Fixes
- **Fixed a formatting Code only knowing about the last Token that it is applied in**
@ -54,7 +53,6 @@ Improvements
- Automatically update all elements when changing a ui system's viewport
- 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 accept a Keybind for clearing a combination
- Automatically select the first element when a dropdown is opened in auto nav mode
- Improved gamepad navigation by employing angles between elements
- Prefer elements that have the same parent as the currently selected element when using gamepad navigation

View file

@ -27,7 +27,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\</OutputPath>
<DefineConstants>DEBUG;TRACE;ANDROID</DefineConstants>
@ -37,7 +37,7 @@
<AndroidLinkMode>None</AndroidLinkMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>portable</DebugType>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\</OutputPath>
<DefineConstants>TRACE;ANDROID</DefineConstants>

View file

@ -115,11 +115,6 @@ namespace MLEM.Ui.Elements {
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>
/// 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.
@ -131,12 +126,12 @@ namespace MLEM.Ui.Elements {
/// <param name="keybind">The keybind that this button should represent</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="unbind">An optional keybind to press that allows the keybind value to be unbound, clearing the combination</param>
/// <param name="unbindKey">An optional generic input that allows the keybind value to be unbound, clearing all combinations</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="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>
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) {
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) {
string GetCurrentName() => keybind.TryGetCombination(index, out var combination) ? combination.ToString(" + ", inputName) : unboundPlaceholder;
var button = new Button(anchor, size, GetCurrentName());
@ -150,7 +145,7 @@ namespace MLEM.Ui.Elements {
button.SetData("Active", true);
activeNext = false;
} else if (button.GetData<bool>("Active")) {
if (unbind != null && unbind.IsPressed(inputHandler)) {
if (unbindKey != default && inputHandler.IsPressed(unbindKey)) {
keybind.Remove((c, i) => i == index);
button.Text.Text = unboundPlaceholder;
button.SetData("Active", false);

View file

@ -6,7 +6,7 @@ namespace MLEM.Input {
/// <summary>
/// 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.
/// For creating and extracting inputs from a generic input, the implicit operators and <see cref="Type"/> can additionally be used.
/// For creating and extracting inputs from a generic input, the implicit operators and <see cref="Type"/> can be used.
/// Note that this type is serializable using <see cref="DataContractAttribute"/>.
/// </summary>
[DataContract]
@ -20,46 +20,6 @@ namespace MLEM.Input {
[DataMember]
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) {
this.Type = type;
this.value = value;
@ -123,10 +83,10 @@ namespace MLEM.Input {
/// <summary>
/// Converts a <see cref="Keys"/> to a generic input.
/// </summary>
/// <param name="key">The keys to convert</param>
/// <param name="keys">The keys to convert</param>
/// <returns>The resulting generic input</returns>
public static implicit operator GenericInput(Keys key) {
return new GenericInput(key);
public static implicit operator GenericInput(Keys keys) {
return new GenericInput(InputType.Keyboard, (int) keys);
}
/// <summary>
@ -135,16 +95,16 @@ namespace MLEM.Input {
/// <param name="button">The button to convert</param>
/// <returns>The resulting generic input</returns>
public static implicit operator GenericInput(MouseButton button) {
return new GenericInput(button);
return new GenericInput(InputType.Mouse, (int) button);
}
/// <summary>
/// Converts a <see cref="Buttons"/> to a generic input.
/// </summary>
/// <param name="button">The buttons to convert</param>
/// <param name="buttons">The buttons to convert</param>
/// <returns>The resulting generic input</returns>
public static implicit operator GenericInput(Buttons button) {
return new GenericInput(button);
public static implicit operator GenericInput(Buttons buttons) {
return new GenericInput(InputType.Gamepad, (int) buttons);
}
/// <summary>
@ -152,9 +112,11 @@ namespace MLEM.Input {
/// </summary>
/// <param name="input">The input to convert</param>
/// <returns>The resulting keys</returns>
/// <exception cref="InvalidOperationException">If the given generic input's <see cref="Type"/> is not <see cref="InputType.Keyboard"/> or <see cref="InputType.None"/></exception>
/// <exception cref="ArgumentException">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) {
return input.Key;
if (input.Type == InputType.None)
return Keys.None;
return input.Type == InputType.Keyboard ? (Keys) input.value : throw new ArgumentException();
}
/// <summary>
@ -162,9 +124,9 @@ namespace MLEM.Input {
/// </summary>
/// <param name="input">The input to convert</param>
/// <returns>The resulting button</returns>
/// <exception cref="InvalidOperationException">If the given generic input's <see cref="Type"/> is not <see cref="InputType.Mouse"/></exception>
/// <exception cref="ArgumentException">If the given generic input's <see cref="Type"/> is not <see cref="InputType.Mouse"/></exception>
public static implicit operator MouseButton(GenericInput input) {
return input.MouseButton;
return input.Type == InputType.Mouse ? (MouseButton) input.value : throw new ArgumentException();
}
/// <summary>
@ -172,9 +134,9 @@ namespace MLEM.Input {
/// </summary>
/// <param name="input">The input to convert</param>
/// <returns>The resulting buttons</returns>
/// <exception cref="InvalidOperationException">If the given generic input's <see cref="Type"/> is not <see cref="InputType.Gamepad"/></exception>
/// <exception cref="ArgumentException">If the given generic input's <see cref="Type"/> is not <see cref="InputType.Gamepad"/></exception>
public static implicit operator Buttons(GenericInput input) {
return input.Button;
return input.Type == InputType.Gamepad ? (Buttons) input.value : throw new ArgumentException();
}
/// <summary>