mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-24 13:38:34 +01:00
Compare commits
3 commits
9a0b8ef846
...
374d936be2
Author | SHA1 | Date | |
---|---|---|---|
374d936be2 | |||
a52b46dce9 | |||
6aa9ec03d4 |
5 changed files with 56 additions and 22 deletions
|
@ -10,12 +10,14 @@ Jump to version:
|
||||||
Additions
|
Additions
|
||||||
- Added RotateBy to Direction2Helper
|
- Added RotateBy to Direction2Helper
|
||||||
|
|
||||||
Fixes
|
|
||||||
- Set default values for InputHandler held and pressed keys to avoid an exception if buttons are held in the very first frame
|
|
||||||
|
|
||||||
Improvements
|
Improvements
|
||||||
- Improved NinePatch memory performance
|
- Improved NinePatch memory performance
|
||||||
- Moved sound-related classes into Sound namespace
|
- Moved sound-related classes into Sound namespace
|
||||||
|
- Added customizable overloads for Keybind, Combination and GenericInput ToString methods
|
||||||
|
- Added ColorExtensions.Invert and made ColorHelper.Invert obsolete
|
||||||
|
|
||||||
|
Fixes
|
||||||
|
- Set default values for InputHandler held and pressed keys to avoid an exception if buttons are held in the very first frame
|
||||||
|
|
||||||
### MLEM.Ui
|
### MLEM.Ui
|
||||||
Additions
|
Additions
|
||||||
|
|
|
@ -131,11 +131,7 @@ namespace MLEM.Ui.Elements {
|
||||||
public static Button KeybindButton(Anchor anchor, Vector2 size, Keybind keybind, InputHandler inputHandler, string activePlaceholder, GenericInput unbindKey = default, string unboundPlaceholder = "", Func<GenericInput, string> inputName = null) {
|
public static Button KeybindButton(Anchor anchor, Vector2 size, Keybind keybind, InputHandler inputHandler, string activePlaceholder, GenericInput unbindKey = default, string unboundPlaceholder = "", Func<GenericInput, string> inputName = null) {
|
||||||
string GetCurrentName() {
|
string GetCurrentName() {
|
||||||
var combination = keybind.GetCombinations().FirstOrDefault();
|
var combination = keybind.GetCombinations().FirstOrDefault();
|
||||||
if (combination == null)
|
return combination?.ToString(" + ", inputName) ?? unboundPlaceholder;
|
||||||
return unboundPlaceholder;
|
|
||||||
return string.Join(" + ", combination.Modifiers
|
|
||||||
.Append(combination.Key)
|
|
||||||
.Select(i => inputName?.Invoke(i) ?? i.ToString()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var button = new Button(anchor, size, GetCurrentName());
|
var button = new Button(anchor, size, GetCurrentName());
|
||||||
|
|
|
@ -18,6 +18,15 @@ namespace MLEM.Extensions {
|
||||||
return color * (other.A / 255F);
|
return color * (other.A / 255F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns an inverted version of this color.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">The color to invert</param>
|
||||||
|
/// <returns>The inverted color</returns>
|
||||||
|
public static Color Invert(this Color color) {
|
||||||
|
return new Color(Math.Abs(255 - color.R), Math.Abs(255 - color.G), Math.Abs(255 - color.B), color.A);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -25,13 +34,10 @@ namespace MLEM.Extensions {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ColorHelper {
|
public static class ColorHelper {
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="ColorExtensions.Invert"/>
|
||||||
/// Returns an inverted version of the color.
|
[Obsolete("This method has been moved to ColorExtensions.Invert in 5.1.0")]
|
||||||
/// </summary>
|
|
||||||
/// <param name="color">The color to invert</param>
|
|
||||||
/// <returns>The inverted color</returns>
|
|
||||||
public static Color Invert(this Color color) {
|
public static Color Invert(this Color color) {
|
||||||
return new Color(Math.Abs(255 - color.R), Math.Abs(255 - color.G), Math.Abs(255 - color.B), color.A);
|
return ColorExtensions.Invert(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -27,19 +27,16 @@ namespace MLEM.Input {
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
var ret = this.Type.ToString();
|
|
||||||
switch (this.Type) {
|
switch (this.Type) {
|
||||||
case InputType.Mouse:
|
case InputType.Mouse:
|
||||||
ret += ((MouseButton) this).ToString();
|
return $"Mouse{(MouseButton) this}";
|
||||||
break;
|
|
||||||
case InputType.Keyboard:
|
case InputType.Keyboard:
|
||||||
ret += ((Keys) this).ToString();
|
return ((Keys) this).ToString();
|
||||||
break;
|
|
||||||
case InputType.Gamepad:
|
case InputType.Gamepad:
|
||||||
ret += ((Buttons) this).ToString();
|
return $"Gamepad{(Buttons) this}";
|
||||||
break;
|
default:
|
||||||
|
return this.Type.ToString();
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
|
@ -123,6 +123,23 @@ namespace MLEM.Input {
|
||||||
yield return combination;
|
yield return combination;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts this keybind into an easily human-readable string.
|
||||||
|
/// When using <see cref="ToString()"/>, this method is used with <paramref name="joiner"/> set to ", ".
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="joiner">The string to use to join combinations</param>
|
||||||
|
/// <param name="combinationJoiner">The string to use for combination-internal joining, see <see cref="Combination.ToString(string,System.Func{MLEM.Input.GenericInput,string})"/></param>
|
||||||
|
/// <param name="inputName">The function to use for determining the display name of generic inputs, see <see cref="Combination.ToString(string,System.Func{MLEM.Input.GenericInput,string})"/></param>
|
||||||
|
/// <returns>A human-readable string representing this keybind</returns>
|
||||||
|
public string ToString(string joiner, string combinationJoiner = " + ", Func<GenericInput, string> inputName = null) {
|
||||||
|
return string.Join(joiner, this.combinations.Select(c => c.ToString(combinationJoiner, inputName)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string ToString() {
|
||||||
|
return this.ToString(", ");
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A key combination is a combination of a set of modifier keys and a key.
|
/// A key combination is a combination of a set of modifier keys and a key.
|
||||||
/// All of the keys are <see cref="GenericInput"/> instances, so they can be keyboard-, mouse- or gamepad-based.
|
/// All of the keys are <see cref="GenericInput"/> instances, so they can be keyboard-, mouse- or gamepad-based.
|
||||||
|
@ -184,6 +201,22 @@ namespace MLEM.Input {
|
||||||
return this.Modifiers.Length <= 0 || this.Modifiers.Any(m => handler.IsDown(m, gamepadIndex));
|
return this.Modifiers.Length <= 0 || this.Modifiers.Any(m => handler.IsDown(m, gamepadIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts this combination into an easily human-readable string.
|
||||||
|
/// When using <see cref="ToString()"/>, this method is used with <paramref name="joiner"/> set to " + ".
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="joiner">The string to use to join this combination's <see cref="Modifiers"/> and <see cref="Key"/> together</param>
|
||||||
|
/// <param name="inputName">The function to use for determining the display name of a <see cref="GenericInput"/>. If this is null, the generic input's default <see cref="GenericInput.ToString"/> method is used.</param>
|
||||||
|
/// <returns>A human-readable string representing this combination</returns>
|
||||||
|
public string ToString(string joiner, Func<GenericInput, string> inputName = null) {
|
||||||
|
return string.Join(joiner, this.Modifiers.Append(this.Key).Select(i => inputName?.Invoke(i) ?? i.ToString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string ToString() {
|
||||||
|
return this.ToString(" + ");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue