mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-24 21:48:35 +01:00
Compare commits
No commits in common. "374d936be24c141528881b334a49207d3d2d4007" and "9a0b8ef846abbba4a8d87b22f4e06e098f38833c" have entirely different histories.
374d936be2
...
9a0b8ef846
5 changed files with 22 additions and 56 deletions
|
@ -10,14 +10,12 @@ 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,7 +131,11 @@ 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();
|
||||||
return combination?.ToString(" + ", inputName) ?? unboundPlaceholder;
|
if (combination == null)
|
||||||
|
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,15 +18,6 @@ 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>
|
||||||
|
@ -34,10 +25,13 @@ namespace MLEM.Extensions {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ColorHelper {
|
public static class ColorHelper {
|
||||||
|
|
||||||
/// <inheritdoc cref="ColorExtensions.Invert"/>
|
/// <summary>
|
||||||
[Obsolete("This method has been moved to ColorExtensions.Invert in 5.1.0")]
|
/// Returns an inverted version of the color.
|
||||||
|
/// </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 ColorExtensions.Invert(color);
|
return new Color(Math.Abs(255 - color.R), Math.Abs(255 - color.G), Math.Abs(255 - color.B), color.A);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -27,16 +27,19 @@ 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:
|
||||||
return $"Mouse{(MouseButton) this}";
|
ret += ((MouseButton) this).ToString();
|
||||||
|
break;
|
||||||
case InputType.Keyboard:
|
case InputType.Keyboard:
|
||||||
return ((Keys) this).ToString();
|
ret += ((Keys) this).ToString();
|
||||||
|
break;
|
||||||
case InputType.Gamepad:
|
case InputType.Gamepad:
|
||||||
return $"Gamepad{(Buttons) this}";
|
ret += ((Buttons) this).ToString();
|
||||||
default:
|
break;
|
||||||
return this.Type.ToString();
|
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
|
@ -123,23 +123,6 @@ 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.
|
||||||
|
@ -201,22 +184,6 @@ 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