mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-24 13:38:34 +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
|
||||
- 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
|
||||
- Improved NinePatch memory performance
|
||||
- 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
|
||||
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) {
|
||||
string GetCurrentName() {
|
||||
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());
|
||||
|
|
|
@ -18,15 +18,6 @@ namespace MLEM.Extensions {
|
|||
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>
|
||||
|
@ -34,10 +25,13 @@ namespace MLEM.Extensions {
|
|||
/// </summary>
|
||||
public static class ColorHelper {
|
||||
|
||||
/// <inheritdoc cref="ColorExtensions.Invert"/>
|
||||
[Obsolete("This method has been moved to ColorExtensions.Invert in 5.1.0")]
|
||||
/// <summary>
|
||||
/// 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) {
|
||||
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>
|
||||
|
|
|
@ -27,16 +27,19 @@ namespace MLEM.Input {
|
|||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() {
|
||||
var ret = this.Type.ToString();
|
||||
switch (this.Type) {
|
||||
case InputType.Mouse:
|
||||
return $"Mouse{(MouseButton) this}";
|
||||
ret += ((MouseButton) this).ToString();
|
||||
break;
|
||||
case InputType.Keyboard:
|
||||
return ((Keys) this).ToString();
|
||||
ret += ((Keys) this).ToString();
|
||||
break;
|
||||
case InputType.Gamepad:
|
||||
return $"Gamepad{(Buttons) this}";
|
||||
default:
|
||||
return this.Type.ToString();
|
||||
ret += ((Buttons) this).ToString();
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
@ -123,23 +123,6 @@ namespace MLEM.Input {
|
|||
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>
|
||||
/// 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.
|
||||
|
@ -201,22 +184,6 @@ namespace MLEM.Input {
|
|||
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