From f78502a3a4a133b93cf9bf01eb426867e7798045 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 21 Mar 2019 23:14:31 -0400 Subject: fix incorrect input check, update release notes --- src/SMAPI/Framework/Input/SInputState.cs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/SMAPI/Framework/Input') diff --git a/src/SMAPI/Framework/Input/SInputState.cs b/src/SMAPI/Framework/Input/SInputState.cs index 96a7003a..a15272d5 100644 --- a/src/SMAPI/Framework/Input/SInputState.cs +++ b/src/SMAPI/Framework/Input/SInputState.cs @@ -94,7 +94,10 @@ namespace StardewModdingAPI.Framework.Input this.RealKeyboard = realKeyboard; this.RealMouse = realMouse; if (cursorAbsolutePos != this.CursorPositionImpl?.AbsolutePixels || playerTilePos != this.LastPlayerTile) + { + this.LastPlayerTile = playerTilePos; this.CursorPositionImpl = this.GetCursorPosition(realMouse, cursorAbsolutePos); + } // update suppressed states this.SuppressButtons.RemoveWhere(p => !this.GetStatus(activeButtons, p).IsDown()); -- cgit From 3cf3df8ffb21afc7698427e51787324c5d237800 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 14 Sep 2019 23:18:03 -0400 Subject: fix ICursorPosition.AbsolutePixels not adjusted for zoom --- docs/release-notes.md | 1 + src/SMAPI/Framework/CursorPosition.cs | 8 ++++---- src/SMAPI/Framework/Input/SInputState.cs | 14 ++++++++------ 3 files changed, 13 insertions(+), 10 deletions(-) (limited to 'src/SMAPI/Framework/Input') diff --git a/docs/release-notes.md b/docs/release-notes.md index 45d65f7d..af8b1d5b 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -86,6 +86,7 @@ For modders: * Mods are now loaded much earlier in the game launch. This lets mods intercept any content asset, but the game is not fully initialized when `Entry` is called (use the `GameLaunched` event if you need to run code when the game is initialized). * Removed all deprecated APIs. * Removed `Monitor.ExitGameImmediately`. + * Fixed `ICursorPosition.AbsolutePixels` not adjusted for zoom. * Changes: * Added support for content pack translations. * Added `IContentPack.HasFile`, `Context.IsGameLaunched`, and `SemanticVersion.TryParse`. diff --git a/src/SMAPI/Framework/CursorPosition.cs b/src/SMAPI/Framework/CursorPosition.cs index 079917f2..2008ccce 100644 --- a/src/SMAPI/Framework/CursorPosition.cs +++ b/src/SMAPI/Framework/CursorPosition.cs @@ -8,10 +8,10 @@ namespace StardewModdingAPI.Framework /********* ** Accessors *********/ - /// The pixel position relative to the top-left corner of the in-game map. + /// The pixel position relative to the top-left corner of the in-game map, adjusted for pixel zoom. public Vector2 AbsolutePixels { get; } - /// The pixel position relative to the top-left corner of the visible screen. + /// The pixel position relative to the top-left corner of the visible screen, adjusted for pixel zoom. public Vector2 ScreenPixels { get; } /// The tile position under the cursor relative to the top-left corner of the map. @@ -25,8 +25,8 @@ namespace StardewModdingAPI.Framework ** Public methods *********/ /// Construct an instance. - /// The pixel position relative to the top-left corner of the in-game map. - /// The pixel position relative to the top-left corner of the visible screen. + /// The pixel position relative to the top-left corner of the in-game map, adjusted for pixel zoom. + /// The pixel position relative to the top-left corner of the visible screen, adjusted for pixel zoom. /// The tile position relative to the top-left corner of the map. /// The tile position that the game considers under the cursor for purposes of clicking actions. public CursorPosition(Vector2 absolutePixels, Vector2 screenPixels, Vector2 tile, Vector2 grabTile) diff --git a/src/SMAPI/Framework/Input/SInputState.cs b/src/SMAPI/Framework/Input/SInputState.cs index a15272d5..d69e5604 100644 --- a/src/SMAPI/Framework/Input/SInputState.cs +++ b/src/SMAPI/Framework/Input/SInputState.cs @@ -80,12 +80,14 @@ namespace StardewModdingAPI.Framework.Input { try { + float zoomMultiplier = (1f / Game1.options.zoomLevel); + // get new states GamePadState realController = GamePad.GetState(PlayerIndex.One); KeyboardState realKeyboard = Keyboard.GetState(); MouseState realMouse = Mouse.GetState(); var activeButtons = this.DeriveStatuses(this.ActiveButtons, realKeyboard, realMouse, realController); - Vector2 cursorAbsolutePos = new Vector2(realMouse.X + Game1.viewport.X, realMouse.Y + Game1.viewport.Y); + Vector2 cursorAbsolutePos = new Vector2((realMouse.X * zoomMultiplier) + Game1.viewport.X, (realMouse.Y * zoomMultiplier) + Game1.viewport.Y); Vector2? playerTilePos = Context.IsPlayerFree ? Game1.player.getTileLocation() : (Vector2?)null; // update real states @@ -96,7 +98,7 @@ namespace StardewModdingAPI.Framework.Input if (cursorAbsolutePos != this.CursorPositionImpl?.AbsolutePixels || playerTilePos != this.LastPlayerTile) { this.LastPlayerTile = playerTilePos; - this.CursorPositionImpl = this.GetCursorPosition(realMouse, cursorAbsolutePos); + this.CursorPositionImpl = this.GetCursorPosition(realMouse, cursorAbsolutePos, zoomMultiplier); } // update suppressed states @@ -170,11 +172,11 @@ namespace StardewModdingAPI.Framework.Input *********/ /// Get the current cursor position. /// The current mouse state. - /// The absolute pixel position relative to the map. - private CursorPosition GetCursorPosition(MouseState mouseState, Vector2 absolutePixels) + /// The absolute pixel position relative to the map, adjusted for pixel zoom. + /// The multiplier applied to pixel coordinates to adjust them for pixel zoom. + private CursorPosition GetCursorPosition(MouseState mouseState, Vector2 absolutePixels, float zoomMultiplier) { - Vector2 rawPixels = new Vector2(mouseState.X, mouseState.Y); - Vector2 screenPixels = rawPixels * new Vector2((float)1.0 / Game1.options.zoomLevel); // derived from Game1::getMouseX + Vector2 screenPixels = new Vector2(mouseState.X * zoomMultiplier, mouseState.Y * zoomMultiplier); Vector2 tile = new Vector2((int)((Game1.viewport.X + screenPixels.X) / Game1.tileSize), (int)((Game1.viewport.Y + screenPixels.Y) / Game1.tileSize)); Vector2 grabTile = (Game1.mouseCursorTransparency > 0 && Utility.tileWithinRadiusOfPlayer((int)tile.X, (int)tile.Y, 1, Game1.player)) // derived from Game1.pressActionButton ? tile -- cgit