diff --git a/MLEM.Startup/MlemGame.cs b/MLEM.Startup/MlemGame.cs index 4e75435..9a87547 100644 --- a/MLEM.Startup/MlemGame.cs +++ b/MLEM.Startup/MlemGame.cs @@ -36,14 +36,14 @@ namespace MLEM.Startup { protected override void LoadContent() { this.SpriteBatch = new SpriteBatch(this.GraphicsDevice); this.InputHandler = new InputHandler(); + this.Components.Add(this.InputHandler); this.UiSystem = new UiSystem(this.Window, this.GraphicsDevice, new UntexturedStyle(this.SpriteBatch), this.InputHandler); + this.Components.Add(this.UiSystem); this.OnLoadContent?.Invoke(this); } protected sealed override void Update(GameTime gameTime) { - this.InputHandler.Update(); this.DoUpdate(gameTime); - this.UiSystem.Update(gameTime); this.OnUpdate?.Invoke(this, gameTime); CoroutineHandler.Tick(gameTime.GetElapsedSeconds()); CoroutineHandler.RaiseEvent(CoroutineEvents.Update); diff --git a/MLEM.Ui/UiControls.cs b/MLEM.Ui/UiControls.cs index dbba32f..2cb87ce 100644 --- a/MLEM.Ui/UiControls.cs +++ b/MLEM.Ui/UiControls.cs @@ -76,7 +76,6 @@ namespace MLEM.Ui { // KEYBOARD INPUT if (this.HandleKeyboard) { if (this.KeyboardButtons.Any(this.Input.IsKeyPressed)) { - this.IsAutoNavMode = true; if (this.SelectedElement?.Root != null) { if (this.Input.IsModifierKeyDown(ModifierKey.Shift)) { // secondary action on element using space or enter @@ -117,11 +116,9 @@ namespace MLEM.Ui { // GAMEPAD INPUT if (this.HandleGamepad) { if (this.GamepadButtons.Any(b => this.IsGamepadPressed(b))) { - this.IsAutoNavMode = true; if (this.SelectedElement?.Root != null) this.System.OnElementPressed?.Invoke(this.SelectedElement); } else if (this.SecondaryGamepadButtons.Any(b => this.IsGamepadPressed(b))) { - this.IsAutoNavMode = true; if (this.SelectedElement?.Root != null) this.System.OnElementSecondaryPressed?.Invoke(this.SelectedElement); } else if (this.DownButtons.Any(this.IsGamepadPressed)) { diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs index a69b417..3386d12 100644 --- a/MLEM.Ui/UiSystem.cs +++ b/MLEM.Ui/UiSystem.cs @@ -13,7 +13,7 @@ using MLEM.Ui.Elements; using MLEM.Ui.Style; namespace MLEM.Ui { - public class UiSystem { + public class UiSystem : GameComponent { public readonly GraphicsDevice GraphicsDevice; public readonly GameWindow Window; @@ -67,7 +67,7 @@ namespace MLEM.Ui { public RootCallback OnRootAdded; public RootCallback OnRootRemoved; - public UiSystem(GameWindow window, GraphicsDevice device, UiStyle style, InputHandler inputHandler = null) { + public UiSystem(GameWindow window, GraphicsDevice device, UiStyle style, InputHandler inputHandler = null) : base(null) { this.Controls = new UiControls(this, inputHandler); this.GraphicsDevice = device; this.Window = window; @@ -95,7 +95,7 @@ namespace MLEM.Ui { }; } - public void Update(GameTime time) { + public override void Update(GameTime time) { this.Controls.Update(); for (var i = this.rootElements.Count - 1; i >= 0; i--) { diff --git a/MLEM/Input/InputHandler.cs b/MLEM/Input/InputHandler.cs index 62c27c3..8ffbed1 100644 --- a/MLEM/Input/InputHandler.cs +++ b/MLEM/Input/InputHandler.cs @@ -9,7 +9,7 @@ using MLEM.Extensions; using MLEM.Misc; namespace MLEM.Input { - public class InputHandler { + public class InputHandler : GameComponent { public KeyboardState LastKeyboardState { get; private set; } public KeyboardState KeyboardState { get; private set; } @@ -50,7 +50,7 @@ namespace MLEM.Input { private readonly bool[] triggerGamepadButtonRepeat = new bool[GamePad.MaximumGamePadCount]; private readonly Buttons?[] heldGamepadButtons = new Buttons?[GamePad.MaximumGamePadCount]; - public InputHandler(bool handleKeyboard = true, bool handleMouse = true, bool handleGamepads = true, bool handleTouch = true) { + public InputHandler(bool handleKeyboard = true, bool handleMouse = true, bool handleGamepads = true, bool handleTouch = true) : base(null) { this.HandleKeyboard = handleKeyboard; this.HandleMouse = handleMouse; this.HandleGamepads = handleGamepads; @@ -113,7 +113,7 @@ namespace MLEM.Input { if (this.HandleGamepadRepeats) { for (var i = 0; i < this.ConnectedGamepads; i++) { this.triggerGamepadButtonRepeat[i] = false; - + if (!this.heldGamepadButtons[i].HasValue) { foreach (var b in EnumHelper.Buttons) { if (this.IsGamepadButtonDown(b, i)) { @@ -151,6 +151,10 @@ namespace MLEM.Input { } } + public override void Update(GameTime gameTime) { + this.Update(); + } + public GamePadState GetLastGamepadState(int index) { return this.lastGamepads[index]; }