mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-12-25 01:39:23 +01:00
make MLEM.Ui not crash on DesktopGL.Core
This commit is contained in:
parent
88b467725c
commit
719bdc7176
1 changed files with 11 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
@ -13,7 +14,15 @@ namespace MLEM.Extensions {
|
|||
}
|
||||
|
||||
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);
|
||||
|
@ -30,7 +39,7 @@ namespace MLEM.Extensions {
|
|||
}
|
||||
|
||||
public bool AddToWindow(GameWindow window) {
|
||||
if (TextInput == null)
|
||||
if (!SupportsTextInput())
|
||||
return false;
|
||||
TextInput.AddEventHandler(window, Delegate.CreateDelegate(TextInput.EventHandlerType, this, Callback));
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue