From 7dc7f010a64ef0cf057a67bbee85196ce1d695c0 Mon Sep 17 00:00:00 2001 From: YonKuma Date: Wed, 8 Nov 2017 22:51:25 -0500 Subject: Added code to suppress mouse clicks issue Pathoschild/SMAPI#384 --- src/SMAPI/Events/EventArgsInput.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/SMAPI/Events') diff --git a/src/SMAPI/Events/EventArgsInput.cs b/src/SMAPI/Events/EventArgsInput.cs index ff904675..0df5275b 100644 --- a/src/SMAPI/Events/EventArgsInput.cs +++ b/src/SMAPI/Events/EventArgsInput.cs @@ -127,6 +127,37 @@ namespace StardewModdingAPI.Events Game1.oldPadState = new GamePadState(thumbsticks, triggers, buttons, dpad); } + + // mouse + else if (button.TryGetStardewInput(out InputButton inputButton)) + { + if (inputButton.mouseLeft) + { + Game1.oldMouseState = new MouseState( + Game1.oldMouseState.X, + Game1.oldMouseState.Y, + Game1.oldMouseState.ScrollWheelValue, + ButtonState.Pressed, + Game1.oldMouseState.MiddleButton, + Game1.oldMouseState.RightButton, + Game1.oldMouseState.XButton1, + Game1.oldMouseState.XButton2 + ); + } + else if (inputButton.mouseRight) + { + Game1.oldMouseState = new MouseState( + Game1.oldMouseState.X, + Game1.oldMouseState.Y, + Game1.oldMouseState.ScrollWheelValue, + Game1.oldMouseState.LeftButton, + Game1.oldMouseState.MiddleButton, + ButtonState.Pressed, + Game1.oldMouseState.XButton1, + Game1.oldMouseState.XButton2 + ); + } + } } } } -- cgit From b9ba645ce0cb8fe924e0c8e880ebba3d065558ef Mon Sep 17 00:00:00 2001 From: YonKuma Date: Wed, 8 Nov 2017 22:59:51 -0500 Subject: Fixing code to match SMAPI idiom --- src/SMAPI/Events/EventArgsInput.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI/Events') diff --git a/src/SMAPI/Events/EventArgsInput.cs b/src/SMAPI/Events/EventArgsInput.cs index 0df5275b..bb06430a 100644 --- a/src/SMAPI/Events/EventArgsInput.cs +++ b/src/SMAPI/Events/EventArgsInput.cs @@ -129,7 +129,7 @@ namespace StardewModdingAPI.Events } // mouse - else if (button.TryGetStardewInput(out InputButton inputButton)) + else if (this.Button.TryGetStardewInput(out InputButton inputButton)) { if (inputButton.mouseLeft) { -- cgit From 0330d84e990883a5bd5f98a70570bde007713414 Mon Sep 17 00:00:00 2001 From: YonKuma Date: Fri, 10 Nov 2017 16:20:25 -0500 Subject: Simplified mouse checks SuppressButton now uses the passed button rather than the object button --- src/SMAPI/Events/EventArgsInput.cs | 55 ++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 29 deletions(-) (limited to 'src/SMAPI/Events') diff --git a/src/SMAPI/Events/EventArgsInput.cs b/src/SMAPI/Events/EventArgsInput.cs index bb06430a..276bfef6 100644 --- a/src/SMAPI/Events/EventArgsInput.cs +++ b/src/SMAPI/Events/EventArgsInput.cs @@ -56,11 +56,11 @@ namespace StardewModdingAPI.Events public void SuppressButton(SButton button) { // keyboard - if (this.Button.TryGetKeyboard(out Keys key)) + if (button.TryGetKeyboard(out Keys key)) Game1.oldKBState = new KeyboardState(Game1.oldKBState.GetPressedKeys().Union(new[] { key }).ToArray()); // controller - else if (this.Button.TryGetController(out Buttons controllerButton)) + else if (button.TryGetController(out Buttons controllerButton)) { var newState = GamePad.GetState(PlayerIndex.One); var thumbsticks = Game1.oldPadState.ThumbSticks; @@ -129,34 +129,31 @@ namespace StardewModdingAPI.Events } // mouse - else if (this.Button.TryGetStardewInput(out InputButton inputButton)) + else if (button == SButton.MouseLeft) { - if (inputButton.mouseLeft) - { - Game1.oldMouseState = new MouseState( - Game1.oldMouseState.X, - Game1.oldMouseState.Y, - Game1.oldMouseState.ScrollWheelValue, - ButtonState.Pressed, - Game1.oldMouseState.MiddleButton, - Game1.oldMouseState.RightButton, - Game1.oldMouseState.XButton1, - Game1.oldMouseState.XButton2 - ); - } - else if (inputButton.mouseRight) - { - Game1.oldMouseState = new MouseState( - Game1.oldMouseState.X, - Game1.oldMouseState.Y, - Game1.oldMouseState.ScrollWheelValue, - Game1.oldMouseState.LeftButton, - Game1.oldMouseState.MiddleButton, - ButtonState.Pressed, - Game1.oldMouseState.XButton1, - Game1.oldMouseState.XButton2 - ); - } + Game1.oldMouseState = new MouseState( + Game1.oldMouseState.X, + Game1.oldMouseState.Y, + Game1.oldMouseState.ScrollWheelValue, + ButtonState.Pressed, + Game1.oldMouseState.MiddleButton, + Game1.oldMouseState.RightButton, + Game1.oldMouseState.XButton1, + Game1.oldMouseState.XButton2 + ); + } + else if (button == SButton.MouseRight) + { + Game1.oldMouseState = new MouseState( + Game1.oldMouseState.X, + Game1.oldMouseState.Y, + Game1.oldMouseState.ScrollWheelValue, + Game1.oldMouseState.LeftButton, + Game1.oldMouseState.MiddleButton, + ButtonState.Pressed, + Game1.oldMouseState.XButton1, + Game1.oldMouseState.XButton2 + ); } } } -- cgit From ca13b2834c3d34be94c4d46a59cba945e62cce33 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 26 Nov 2017 15:39:41 -0500 Subject: fix e.SuppressButton() not working with some mouse buttons, update release notes (#389) --- docs/release-notes.md | 2 ++ src/SMAPI/Events/EventArgsInput.cs | 31 +++++++++---------------------- 2 files changed, 11 insertions(+), 22 deletions(-) (limited to 'src/SMAPI/Events') diff --git a/docs/release-notes.md b/docs/release-notes.md index a74b1927..433050fb 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -5,6 +5,8 @@ * For modders: * Added `DaysSinceStart` property to `SDate` dates. + * Fixed input `e.SuppressButton(button)` method ignoring input. + * Fixed input `e.SuppressButton()` method not working with mouse buttons. ## 2.1 * For players: diff --git a/src/SMAPI/Events/EventArgsInput.cs b/src/SMAPI/Events/EventArgsInput.cs index 276bfef6..54ce9b53 100644 --- a/src/SMAPI/Events/EventArgsInput.cs +++ b/src/SMAPI/Events/EventArgsInput.cs @@ -129,30 +129,17 @@ namespace StardewModdingAPI.Events } // mouse - else if (button == SButton.MouseLeft) + else if (button == SButton.MouseLeft || button == SButton.MouseMiddle || button == SButton.MouseRight || button == SButton.MouseX1 || button == SButton.MouseX2) { Game1.oldMouseState = new MouseState( - Game1.oldMouseState.X, - Game1.oldMouseState.Y, - Game1.oldMouseState.ScrollWheelValue, - ButtonState.Pressed, - Game1.oldMouseState.MiddleButton, - Game1.oldMouseState.RightButton, - Game1.oldMouseState.XButton1, - Game1.oldMouseState.XButton2 - ); - } - else if (button == SButton.MouseRight) - { - Game1.oldMouseState = new MouseState( - Game1.oldMouseState.X, - Game1.oldMouseState.Y, - Game1.oldMouseState.ScrollWheelValue, - Game1.oldMouseState.LeftButton, - Game1.oldMouseState.MiddleButton, - ButtonState.Pressed, - Game1.oldMouseState.XButton1, - Game1.oldMouseState.XButton2 + x: Game1.oldMouseState.X, + y: Game1.oldMouseState.Y, + scrollWheel: Game1.oldMouseState.ScrollWheelValue, + leftButton: button == SButton.MouseLeft ? ButtonState.Pressed : Game1.oldMouseState.LeftButton, + middleButton: button == SButton.MouseMiddle ? ButtonState.Pressed : Game1.oldMouseState.MiddleButton, + rightButton: button == SButton.MouseRight ? ButtonState.Pressed : Game1.oldMouseState.RightButton, + xButton1: button == SButton.MouseX1 ? ButtonState.Pressed : Game1.oldMouseState.XButton1, + xButton2: button == SButton.MouseX2 ? ButtonState.Pressed : Game1.oldMouseState.XButton2 ); } } -- cgit