1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 14:38:34 +01:00

make MLEM.Ui not crash on DesktopGL.Core

This commit is contained in:
Ellpeck 2020-02-24 00:42:01 +01:00
parent 88b467725c
commit 719bdc7176

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
@ -13,7 +14,15 @@ namespace MLEM.Extensions {
} }
public static bool SupportsTextInput() { public static bool SupportsTextInput() {
return TextInput != null; if (TextInput == null)
return false;
// The newest version of DesktopGL.Core made a change where TextInputEventArgs doesn't extend EventArgs
// anymore, making this reflection system incompatible with it. For now, this just disables text input
// meaning that MLEM.Ui text boxes won't work, but at least it won't crash either.
// Let's hope there'll be one last update to DesktopGL that also introduces this change so we can fix this.
if (!typeof(EventArgs).IsAssignableFrom(TextInput.EventHandlerType.GenericTypeArguments.FirstOrDefault()))
return false;
return true;
} }
public delegate void TextInputCallback(object sender, Keys key, char character); public delegate void TextInputCallback(object sender, Keys key, char character);
@ -30,7 +39,7 @@ namespace MLEM.Extensions {
} }
public bool AddToWindow(GameWindow window) { public bool AddToWindow(GameWindow window) {
if (TextInput == null) if (!SupportsTextInput())
return false; return false;
TextInput.AddEventHandler(window, Delegate.CreateDelegate(TextInput.EventHandlerType, this, Callback)); TextInput.AddEventHandler(window, Delegate.CreateDelegate(TextInput.EventHandlerType, this, Callback));
return true; return true;