mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 22:18:34 +01:00
Improved EnumHelper.GetValues signature to return an array
This commit is contained in:
parent
7a0464e8d6
commit
8044cb59cb
7 changed files with 15 additions and 23 deletions
|
@ -10,6 +10,10 @@ Jump to version:
|
||||||
- [5.0.0](#500)
|
- [5.0.0](#500)
|
||||||
|
|
||||||
## 6.1.0
|
## 6.1.0
|
||||||
|
### MLEM
|
||||||
|
Improvements
|
||||||
|
- Improved EnumHelper.GetValues signature to return an array
|
||||||
|
|
||||||
### MLEM.Ui
|
### MLEM.Ui
|
||||||
Additions
|
Additions
|
||||||
- Added some extension methods for querying Anchor types
|
- Added some extension methods for querying Anchor types
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
|
@ -28,7 +27,7 @@ namespace MLEM.Ui.Parsers {
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class UiMarkdownParser {
|
public class UiMarkdownParser {
|
||||||
|
|
||||||
private static readonly ElementType[] ElementTypes = EnumHelper.GetValues<ElementType>().ToArray();
|
private static readonly ElementType[] ElementTypes = EnumHelper.GetValues<ElementType>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The base path for markdown images, which is prepended to the image link.
|
/// The base path for markdown images, which is prepended to the image link.
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace MLEM.Input {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All enum values of <see cref="ModifierKey"/>
|
/// All enum values of <see cref="ModifierKey"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly ModifierKey[] ModifierKeys = EnumHelper.GetValues<ModifierKey>().ToArray();
|
public static readonly ModifierKey[] ModifierKeys = EnumHelper.GetValues<ModifierKey>();
|
||||||
private static readonly Dictionary<ModifierKey, Keys[]> KeysLookup = new Dictionary<ModifierKey, Keys[]> {
|
private static readonly Dictionary<ModifierKey, Keys[]> KeysLookup = new Dictionary<ModifierKey, Keys[]> {
|
||||||
{ModifierKey.Shift, new[] {Keys.LeftShift, Keys.RightShift}},
|
{ModifierKey.Shift, new[] {Keys.LeftShift, Keys.RightShift}},
|
||||||
{ModifierKey.Control, new[] {Keys.LeftControl, Keys.RightControl}},
|
{ModifierKey.Control, new[] {Keys.LeftControl, Keys.RightControl}},
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using MLEM.Misc;
|
using MLEM.Misc;
|
||||||
|
|
||||||
|
@ -12,7 +11,7 @@ namespace MLEM.Input {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All enum values of <see cref="MouseButton"/>
|
/// All enum values of <see cref="MouseButton"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly MouseButton[] MouseButtons = EnumHelper.GetValues<MouseButton>().ToArray();
|
public static readonly MouseButton[] MouseButtons = EnumHelper.GetValues<MouseButton>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the <see cref="ButtonState"/> of the given mouse button.
|
/// Returns the <see cref="ButtonState"/> of the given mouse button.
|
||||||
|
|
|
@ -71,7 +71,7 @@ namespace MLEM.Misc {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All <see cref="Direction2"/> enum values
|
/// All <see cref="Direction2"/> enum values
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly Direction2[] All = EnumHelper.GetValues<Direction2>().ToArray();
|
public static readonly Direction2[] All = EnumHelper.GetValues<Direction2>();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The <see cref="Direction2.Up"/> through <see cref="Direction2.Left"/> directions
|
/// The <see cref="Direction2.Up"/> through <see cref="Direction2.Left"/> directions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
|
||||||
namespace MLEM.Misc {
|
namespace MLEM.Misc {
|
||||||
|
@ -12,19 +10,20 @@ namespace MLEM.Misc {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All values of the <see cref="Buttons"/> enum.
|
/// All values of the <see cref="Buttons"/> enum.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly Buttons[] Buttons = EnumHelper.GetValues<Buttons>().ToArray();
|
public static readonly Buttons[] Buttons = EnumHelper.GetValues<Buttons>();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All values of the <see cref="Keys"/> enum.
|
/// All values of the <see cref="Keys"/> enum.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly Keys[] Keys = EnumHelper.GetValues<Keys>().ToArray();
|
public static readonly Keys[] Keys = EnumHelper.GetValues<Keys>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns all of the values of the given enum type.
|
/// Returns an array containing all of the values of the given enum type.
|
||||||
|
/// Note that this method is a version-independent equivalent of .NET 5's <c>Enum.GetValues<TEnum></c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">The type whose enum to get</typeparam>
|
/// <typeparam name="T">The type whose enum to get</typeparam>
|
||||||
/// <returns>An enumerable of the values of the enum, in declaration order.</returns>
|
/// <returns>An enumerable of the values of the enum, in declaration order.</returns>
|
||||||
public static IEnumerable<T> GetValues<T>() {
|
public static T[] GetValues<T>() {
|
||||||
return Enum.GetValues(typeof(T)).Cast<T>();
|
return (T[]) Enum.GetValues(typeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using FontStashSharp;
|
using FontStashSharp;
|
||||||
using Microsoft.Xna.Framework;
|
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
|
||||||
using Microsoft.Xna.Framework.Input;
|
|
||||||
using MLEM.Cameras;
|
using MLEM.Cameras;
|
||||||
using MLEM.Data;
|
using MLEM.Data;
|
||||||
using MLEM.Data.Content;
|
using MLEM.Data.Content;
|
||||||
using MLEM.Extended.Font;
|
using MLEM.Extended.Font;
|
||||||
using MLEM.Extended.Tiled;
|
|
||||||
using MLEM.Extensions;
|
using MLEM.Extensions;
|
||||||
using MLEM.Font;
|
using MLEM.Font;
|
||||||
using MLEM.Formatting;
|
using MLEM.Formatting;
|
||||||
|
@ -23,9 +17,6 @@ using MLEM.Textures;
|
||||||
using MLEM.Ui;
|
using MLEM.Ui;
|
||||||
using MLEM.Ui.Elements;
|
using MLEM.Ui.Elements;
|
||||||
using MLEM.Ui.Style;
|
using MLEM.Ui.Style;
|
||||||
using MonoGame.Extended;
|
|
||||||
using MonoGame.Extended.Tiled;
|
|
||||||
using MonoGame.Extended.ViewportAdapters;
|
|
||||||
|
|
||||||
namespace Sandbox;
|
namespace Sandbox;
|
||||||
|
|
||||||
|
@ -348,7 +339,7 @@ public class GameImpl : MlemGame {
|
||||||
widthPanel.AddChild(new Paragraph(Anchor.AutoCenter, 100000, "Test String " + Math.Pow(10, i), true) {
|
widthPanel.AddChild(new Paragraph(Anchor.AutoCenter, 100000, "Test String " + Math.Pow(10, i), true) {
|
||||||
OnUpdated = (e, time) => {
|
OnUpdated = (e, time) => {
|
||||||
if (Input.IsPressed(Keys.A)) {
|
if (Input.IsPressed(Keys.A)) {
|
||||||
e.Anchor = (Anchor) (((int) e.Anchor + 1) % EnumHelper.GetValues<Anchor>().Count());
|
e.Anchor = (Anchor) (((int) e.Anchor + 1) % EnumHelper.GetValues<Anchor>().Length);
|
||||||
Console.WriteLine(e.Anchor);
|
Console.WriteLine(e.Anchor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue