From 7eeecc19d1a36bafce1c44eb47a5d8b09ba345c4 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 29 Aug 2019 18:46:48 +0200 Subject: [PATCH] remove some stuff from MlemGame so that you don't crash :^) also make the uisystem know if it doesn't support text input natively --- MLEM.Startup/MlemGame.cs | 14 -------------- MLEM.Ui/UiSystem.cs | 16 +++++++++++----- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/MLEM.Startup/MlemGame.cs b/MLEM.Startup/MlemGame.cs index 95861c9..6acfea0 100644 --- a/MLEM.Startup/MlemGame.cs +++ b/MLEM.Startup/MlemGame.cs @@ -26,16 +26,7 @@ namespace MLEM.Startup { SynchronizeWithVerticalRetrace = vsync }; this.Content.RootDirectory = contentDir; - this.Window.AllowUserResizing = allowResizing; - this.Window.ClientSizeChanged += (win, args) => this.OnWindowSizeChange(this.GraphicsDevice.Viewport); - this.Window.TextInput += (win, args) => this.OnTextInput(args.Key, args.Character); - } - - public virtual void OnWindowSizeChange(Viewport viewport) { - } - - public virtual void OnTextInput(Keys key, char character) { } protected override void LoadContent() { @@ -44,11 +35,6 @@ namespace MLEM.Startup { this.UiSystem = new UiSystem(this.Window, this.GraphicsDevice, new UntexturedStyle(this.SpriteBatch), this.InputHandler); } - protected override void Initialize() { - base.Initialize(); - this.OnWindowSizeChange(this.GraphicsDevice.Viewport); - } - protected override void Update(GameTime gameTime) { base.Update(gameTime); diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs index 637e14c..1cd6ec7 100644 --- a/MLEM.Ui/UiSystem.cs +++ b/MLEM.Ui/UiSystem.cs @@ -47,7 +47,8 @@ namespace MLEM.Ui { public BlendState BlendState; public SamplerState SamplerState = SamplerState.PointClamp; public UiControls Controls; - + public readonly bool SupportsTextInput; + public UiSystem(GameWindow window, GraphicsDevice device, UiStyle style, InputHandler inputHandler = null) { this.Controls = new UiControls(this, inputHandler); this.GraphicsDevice = device; @@ -60,10 +61,15 @@ namespace MLEM.Ui { foreach (var root in this.rootElements) root.Element.ForceUpdateArea(); }; - window.TextInput += (sender, args) => { - foreach (var root in this.rootElements) - root.Element.Propagate(e => e.OnTextInput?.Invoke(e, args.Key, args.Character)); - }; + try { + window.TextInput += (sender, args) => { + foreach (var root in this.rootElements) + root.Element.Propagate(e => e.OnTextInput?.Invoke(e, args.Key, args.Character)); + }; + this.SupportsTextInput = true; + } catch (TypeLoadException) { + this.SupportsTextInput = false; + } } public void Update(GameTime time) {