mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +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:
parent
e04f2fbdd2
commit
7eeecc19d1
2 changed files with 11 additions and 19 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ 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);
|
||||
|
@ -60,10 +61,15 @@ namespace MLEM.Ui {
|
|||
foreach (var root in this.rootElements)
|
||||
root.Element.ForceUpdateArea();
|
||||
};
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue