mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 22:18:34 +01:00
drop .NET Framework support for TextInputWrapper.DesktopGl
This commit is contained in:
parent
e0263dc943
commit
1e485a103c
1 changed files with 5 additions and 24 deletions
|
@ -64,8 +64,8 @@ namespace MLEM.Misc {
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
public class DesktopGl<T> : TextInputWrapper {
|
public class DesktopGl<T> : TextInputWrapper {
|
||||||
|
|
||||||
private MemberInfo key;
|
private FieldInfo key;
|
||||||
private MemberInfo character;
|
private FieldInfo character;
|
||||||
private readonly Action<GameWindow, EventHandler<T>> addListener;
|
private readonly Action<GameWindow, EventHandler<T>> addListener;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -84,33 +84,14 @@ namespace MLEM.Misc {
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void AddListener(GameWindow window, TextInputCallback callback) {
|
public override void AddListener(GameWindow window, TextInputCallback callback) {
|
||||||
this.addListener(window, (sender, args) => {
|
this.addListener(window, (sender, args) => {
|
||||||
// the old versions of DesktopGL use a property here, while the
|
|
||||||
// core version uses a field. So much for "no breaking changes"
|
|
||||||
if (this.key == null)
|
if (this.key == null)
|
||||||
this.key = GetMember(args, "Key");
|
this.key = args.GetType().GetField("Key");
|
||||||
if (this.character == null)
|
if (this.character == null)
|
||||||
this.character = GetMember(args, "Character");
|
this.character = args.GetType().GetField("Character");
|
||||||
callback.Invoke(sender, GetValue<Keys>(this.key, args), GetValue<char>(this.character, args));
|
callback.Invoke(sender, (Keys) this.key.GetValue(args), (char) this.character.GetValue(args));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MemberInfo GetMember(object args, string name) {
|
|
||||||
var ret = args.GetType().GetProperty(name);
|
|
||||||
if (ret != null)
|
|
||||||
return ret;
|
|
||||||
return args.GetType().GetField(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static U GetValue<U>(MemberInfo member, object args) {
|
|
||||||
switch (member) {
|
|
||||||
case PropertyInfo p:
|
|
||||||
return (U) p.GetValue(args);
|
|
||||||
case FieldInfo f:
|
|
||||||
return (U) f.GetValue(args);
|
|
||||||
}
|
|
||||||
throw new ArgumentException();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in a new issue