mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-12-26 02:09:24 +01:00
7eeecc19d1
also make the uisystem know if it doesn't support text input natively
64 lines
No EOL
2.3 KiB
C#
64 lines
No EOL
2.3 KiB
C#
using Coroutine;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using Microsoft.Xna.Framework.Input;
|
|
using MLEM.Input;
|
|
using MLEM.Ui;
|
|
using MLEM.Ui.Style;
|
|
using MonoGame.Extended;
|
|
|
|
namespace MLEM.Startup {
|
|
public class MlemGame : Game {
|
|
|
|
private static MlemGame instance;
|
|
public static InputHandler Input => instance.InputHandler;
|
|
|
|
public readonly GraphicsDeviceManager GraphicsDeviceManager;
|
|
public SpriteBatch SpriteBatch { get; protected set; }
|
|
public InputHandler InputHandler { get; protected set; }
|
|
public UiSystem UiSystem { get; protected set; }
|
|
|
|
public MlemGame(int windowWidth = 1280, int windowHeight = 720, bool vsync = false, bool allowResizing = true, string contentDir = "Content") {
|
|
instance = this;
|
|
this.GraphicsDeviceManager = new GraphicsDeviceManager(this) {
|
|
PreferredBackBufferWidth = windowWidth,
|
|
PreferredBackBufferHeight = windowHeight,
|
|
SynchronizeWithVerticalRetrace = vsync
|
|
};
|
|
this.Content.RootDirectory = contentDir;
|
|
this.Window.AllowUserResizing = allowResizing;
|
|
}
|
|
|
|
protected override void LoadContent() {
|
|
this.SpriteBatch = new SpriteBatch(this.GraphicsDevice);
|
|
this.InputHandler = new InputHandler();
|
|
this.UiSystem = new UiSystem(this.Window, this.GraphicsDevice, new UntexturedStyle(this.SpriteBatch), this.InputHandler);
|
|
}
|
|
|
|
protected override void Update(GameTime gameTime) {
|
|
base.Update(gameTime);
|
|
|
|
this.InputHandler.Update();
|
|
this.UiSystem.Update(gameTime);
|
|
|
|
CoroutineHandler.Tick(gameTime.GetElapsedSeconds());
|
|
CoroutineHandler.RaiseEvent(CoroutineEvents.Update);
|
|
}
|
|
|
|
protected override void Draw(GameTime gameTime) {
|
|
this.UiSystem.DrawEarly(gameTime, this.SpriteBatch);
|
|
this.DoDraw(gameTime);
|
|
this.UiSystem.Draw(gameTime, this.SpriteBatch);
|
|
CoroutineHandler.RaiseEvent(CoroutineEvents.Draw);
|
|
}
|
|
|
|
protected virtual void DoDraw(GameTime gameTime) {
|
|
base.Draw(gameTime);
|
|
}
|
|
|
|
public static T LoadContent<T>(string name) {
|
|
return instance.Content.Load<T>(name);
|
|
}
|
|
|
|
}
|
|
} |