From e7c3f9251e45eb44facd448237a6152f39adaa6d Mon Sep 17 00:00:00 2001 From: Royce551 Date: Thu, 4 Aug 2022 16:50:25 -0500 Subject: [PATCH] Input fixes --- Water/Graphics/GameObjectManager.cs | 4 +++- Water/Input/InputManager.cs | 8 ++++---- Water/WaterGame.cs | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Water/Graphics/GameObjectManager.cs b/Water/Graphics/GameObjectManager.cs index 0607c88..7d6f089 100644 --- a/Water/Graphics/GameObjectManager.cs +++ b/Water/Graphics/GameObjectManager.cs @@ -12,6 +12,7 @@ namespace Water.Graphics public class GameObjectManager : IDrawableThing { public List AllObjects { get; private set; } = new(); + public WaterGame MainGame { get; } public GraphicsDevice GraphicsDevice { get; } public TextureCache Textures { get; private set; } public FontCache Fonts { get; private set; } @@ -22,9 +23,10 @@ namespace Water.Graphics private readonly List objectsToAdd = new(); private readonly List objectsToRemove = new(); - public GameObjectManager(GraphicsDevice graphicsDevice) + public GameObjectManager(GraphicsDevice graphicsDevice, WaterGame waterGame) { GraphicsDevice = graphicsDevice; + MainGame = waterGame; Textures = new TextureCache(graphicsDevice); Fonts = new FontCache(); Input = new InputManager(this); diff --git a/Water/Input/InputManager.cs b/Water/Input/InputManager.cs index 3e8ff4a..b6eea79 100644 --- a/Water/Input/InputManager.cs +++ b/Water/Input/InputManager.cs @@ -51,11 +51,11 @@ namespace Water.Input KeyUp?.Invoke(this, new(key)); } - if (currentMouseState.LeftButton == ButtonState.Pressed) PrimaryMouseButtonDown?.Invoke(this, new()); - if (currentMouseState.LeftButton == ButtonState.Released) PrimaryMouseButtonUp?.Invoke(this, new()); + if (currentMouseState.LeftButton == ButtonState.Pressed && previousMouseState.LeftButton != ButtonState.Pressed && game.MainGame.IsActive) PrimaryMouseButtonDown?.Invoke(this, new()); + if (currentMouseState.LeftButton == ButtonState.Released && previousMouseState.LeftButton != ButtonState.Released && game.MainGame.IsActive) PrimaryMouseButtonUp?.Invoke(this, new()); - if (currentMouseState.RightButton == ButtonState.Pressed) SecondaryMouseButtonDown?.Invoke(this, new()); - if (currentMouseState.RightButton == ButtonState.Released) SecondaryMouseButtonUp?.Invoke(this, new()); + if (currentMouseState.RightButton == ButtonState.Pressed && previousMouseState.RightButton != ButtonState.Pressed && game.MainGame.IsActive) SecondaryMouseButtonDown?.Invoke(this, new()); + if (currentMouseState.RightButton == ButtonState.Released && previousMouseState.RightButton != ButtonState.Released && game.MainGame.IsActive) SecondaryMouseButtonUp?.Invoke(this, new()); previousKbState = currentKbState; previousMouseState = currentMouseState; diff --git a/Water/WaterGame.cs b/Water/WaterGame.cs index f821d9c..e45e693 100644 --- a/Water/WaterGame.cs +++ b/Water/WaterGame.cs @@ -31,7 +31,7 @@ namespace Water TargetElapsedTime = TimeSpan.FromMilliseconds(1); Graphics.ApplyChanges(); - gameObjectManager = new(GraphicsDevice); + gameObjectManager = new(GraphicsDevice, this); Screen = new(gameObjectManager, Window); Screen.RelativePosition = GraphicsDevice.Viewport.Bounds;