1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-25 22:18:34 +01:00

remove some stuff from MlemGame so that you don't crash :^)

also make the uisystem know if it doesn't support text input natively
This commit is contained in:
Ellpeck 2019-08-29 18:46:48 +02:00
parent e04f2fbdd2
commit 7eeecc19d1
2 changed files with 11 additions and 19 deletions

View file

@ -26,16 +26,7 @@ namespace MLEM.Startup {
SynchronizeWithVerticalRetrace = vsync SynchronizeWithVerticalRetrace = vsync
}; };
this.Content.RootDirectory = contentDir; this.Content.RootDirectory = contentDir;
this.Window.AllowUserResizing = allowResizing; 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() { 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); 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) { protected override void Update(GameTime gameTime) {
base.Update(gameTime); base.Update(gameTime);

View file

@ -47,7 +47,8 @@ namespace MLEM.Ui {
public BlendState BlendState; public BlendState BlendState;
public SamplerState SamplerState = SamplerState.PointClamp; public SamplerState SamplerState = SamplerState.PointClamp;
public UiControls Controls; public UiControls Controls;
public readonly bool SupportsTextInput;
public UiSystem(GameWindow window, GraphicsDevice device, UiStyle style, InputHandler inputHandler = null) { public UiSystem(GameWindow window, GraphicsDevice device, UiStyle style, InputHandler inputHandler = null) {
this.Controls = new UiControls(this, inputHandler); this.Controls = new UiControls(this, inputHandler);
this.GraphicsDevice = device; this.GraphicsDevice = device;
@ -60,10 +61,15 @@ namespace MLEM.Ui {
foreach (var root in this.rootElements) foreach (var root in this.rootElements)
root.Element.ForceUpdateArea(); root.Element.ForceUpdateArea();
}; };
window.TextInput += (sender, args) => { try {
foreach (var root in this.rootElements) window.TextInput += (sender, args) => {
root.Element.Propagate(e => e.OnTextInput?.Invoke(e, args.Key, args.Character)); 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) { public void Update(GameTime time) {