mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 06:28:35 +01:00
added some events to MlemGame to allow for mouse handling to be disabled easily in the android version
This commit is contained in:
parent
12a2e92c09
commit
b812bbe677
2 changed files with 13 additions and 0 deletions
|
@ -18,6 +18,8 @@ namespace AndroidDemos {
|
||||||
protected override void OnCreate(Bundle bundle) {
|
protected override void OnCreate(Bundle bundle) {
|
||||||
base.OnCreate(bundle);
|
base.OnCreate(bundle);
|
||||||
var g = new GameImpl();
|
var g = new GameImpl();
|
||||||
|
// disable mouse handling for android to make emulator behavior more coherent
|
||||||
|
g.OnLoadContent += game => game.InputHandler.HandleMouse = false;
|
||||||
this.SetContentView((View) g.Services.GetService(typeof(View)));
|
this.SetContentView((View) g.Services.GetService(typeof(View)));
|
||||||
g.Run();
|
g.Run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,10 @@ namespace MLEM.Startup {
|
||||||
public InputHandler InputHandler { get; protected set; }
|
public InputHandler InputHandler { get; protected set; }
|
||||||
public UiSystem UiSystem { get; protected set; }
|
public UiSystem UiSystem { get; protected set; }
|
||||||
|
|
||||||
|
public GenericCallback OnLoadContent;
|
||||||
|
public TimeCallback OnUpdate;
|
||||||
|
public TimeCallback OnDraw;
|
||||||
|
|
||||||
public MlemGame(int windowWidth = 1280, int windowHeight = 720, bool vsync = false, bool allowResizing = true, string contentDir = "Content") {
|
public MlemGame(int windowWidth = 1280, int windowHeight = 720, bool vsync = false, bool allowResizing = true, string contentDir = "Content") {
|
||||||
instance = this;
|
instance = this;
|
||||||
this.GraphicsDeviceManager = new GraphicsDeviceManager(this) {
|
this.GraphicsDeviceManager = new GraphicsDeviceManager(this) {
|
||||||
|
@ -33,6 +37,7 @@ namespace MLEM.Startup {
|
||||||
this.SpriteBatch = new SpriteBatch(this.GraphicsDevice);
|
this.SpriteBatch = new SpriteBatch(this.GraphicsDevice);
|
||||||
this.InputHandler = new InputHandler();
|
this.InputHandler = new InputHandler();
|
||||||
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);
|
||||||
|
this.OnLoadContent?.Invoke(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update(GameTime gameTime) {
|
protected override void Update(GameTime gameTime) {
|
||||||
|
@ -41,6 +46,7 @@ namespace MLEM.Startup {
|
||||||
this.InputHandler.Update();
|
this.InputHandler.Update();
|
||||||
this.UiSystem.Update(gameTime);
|
this.UiSystem.Update(gameTime);
|
||||||
|
|
||||||
|
this.OnUpdate?.Invoke(this, gameTime);
|
||||||
CoroutineHandler.Tick(gameTime.GetElapsedSeconds());
|
CoroutineHandler.Tick(gameTime.GetElapsedSeconds());
|
||||||
CoroutineHandler.RaiseEvent(CoroutineEvents.Update);
|
CoroutineHandler.RaiseEvent(CoroutineEvents.Update);
|
||||||
}
|
}
|
||||||
|
@ -49,6 +55,7 @@ namespace MLEM.Startup {
|
||||||
this.UiSystem.DrawEarly(gameTime, this.SpriteBatch);
|
this.UiSystem.DrawEarly(gameTime, this.SpriteBatch);
|
||||||
this.DoDraw(gameTime);
|
this.DoDraw(gameTime);
|
||||||
this.UiSystem.Draw(gameTime, this.SpriteBatch);
|
this.UiSystem.Draw(gameTime, this.SpriteBatch);
|
||||||
|
this.OnDraw?.Invoke(this, gameTime);
|
||||||
CoroutineHandler.RaiseEvent(CoroutineEvents.Draw);
|
CoroutineHandler.RaiseEvent(CoroutineEvents.Draw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,5 +67,9 @@ namespace MLEM.Startup {
|
||||||
return instance.Content.Load<T>(name);
|
return instance.Content.Load<T>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public delegate void GenericCallback(MlemGame game);
|
||||||
|
|
||||||
|
public delegate void TimeCallback(MlemGame game, GameTime time);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue