mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58: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:
parent
e04f2fbdd2
commit
7eeecc19d1
2 changed files with 11 additions and 19 deletions
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ 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);
|
||||||
|
@ -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();
|
||||||
};
|
};
|
||||||
|
try {
|
||||||
window.TextInput += (sender, args) => {
|
window.TextInput += (sender, args) => {
|
||||||
foreach (var root in this.rootElements)
|
foreach (var root in this.rootElements)
|
||||||
root.Element.Propagate(e => e.OnTextInput?.Invoke(e, args.Key, args.Character));
|
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) {
|
||||||
|
|
Loading…
Reference in a new issue