add absolute pixels to ICursorPosition, fix tile not updated if screen-relative pos didn't change (#546)
This commit is contained in:
parent
d401aff330
commit
08e9c7e7d3
|
@ -42,6 +42,7 @@
|
|||
* Added support for custom seasonal tilesheets when loading an unpacked `.tbin` map.
|
||||
* Added Harmony DLL for internal use by SMAPI. (Mods should still include their own copy for backwards compatibility, and in case it's removed later. SMAPI will always load its own version though.)
|
||||
* Added option to suppress update checks for a specific mod in `StardewModdingAPI.config.json`.
|
||||
* Added absolute pixels to `ICursorPosition`.
|
||||
* Update checks now use the update key order when deciding which to link to.
|
||||
* Fixed error if a mod loads a PNG while the game is loading (e.g. custom map tilesheets via `IAssetLoader`).
|
||||
* Fixed assets loaded by temporary content managers not being editable by mods.
|
||||
|
|
|
@ -8,8 +8,8 @@ namespace StardewModdingAPI.Framework
|
|||
/*********
|
||||
** Accessors
|
||||
*********/
|
||||
/// <summary>The raw pixel position, not adjusted for the game zoom.</summary>
|
||||
public Vector2 RawPixels { get; }
|
||||
/// <summary>The pixel position relative to the top-left corner of the in-game map.</summary>
|
||||
public Vector2 AbsolutePixels { get; }
|
||||
|
||||
/// <summary>The pixel position relative to the top-left corner of the visible screen.</summary>
|
||||
public Vector2 ScreenPixels { get; }
|
||||
|
@ -25,13 +25,13 @@ namespace StardewModdingAPI.Framework
|
|||
** Public methods
|
||||
*********/
|
||||
/// <summary>Construct an instance.</summary>
|
||||
/// <param name="rawPixels">The raw pixel position, not adjusted for the game zoom.</param>
|
||||
/// <param name="absolutePixels">The pixel position relative to the top-left corner of the in-game map.</param>
|
||||
/// <param name="screenPixels">The pixel position relative to the top-left corner of the visible screen.</param>
|
||||
/// <param name="tile">The tile position relative to the top-left corner of the map.</param>
|
||||
/// <param name="grabTile">The tile position that the game considers under the cursor for purposes of clicking actions.</param>
|
||||
public CursorPosition(Vector2 rawPixels, Vector2 screenPixels, Vector2 tile, Vector2 grabTile)
|
||||
public CursorPosition(Vector2 absolutePixels, Vector2 screenPixels, Vector2 tile, Vector2 grabTile)
|
||||
{
|
||||
this.RawPixels = rawPixels;
|
||||
this.AbsolutePixels = absolutePixels;
|
||||
this.ScreenPixels = screenPixels;
|
||||
this.Tile = tile;
|
||||
this.GrabTile = grabTile;
|
||||
|
@ -41,7 +41,7 @@ namespace StardewModdingAPI.Framework
|
|||
/// <param name="other">An object to compare with this object.</param>
|
||||
public bool Equals(ICursorPosition other)
|
||||
{
|
||||
return other != null && this.ScreenPixels == other.ScreenPixels;
|
||||
return other != null && this.AbsolutePixels == other.AbsolutePixels;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,15 +82,15 @@ namespace StardewModdingAPI.Framework.Input
|
|||
KeyboardState realKeyboard = Keyboard.GetState();
|
||||
MouseState realMouse = Mouse.GetState();
|
||||
var activeButtons = this.DeriveStatuses(this.ActiveButtons, realKeyboard, realMouse, realController);
|
||||
Vector2 cursorRawPixelPos = new Vector2(this.RealMouse.X, this.RealMouse.Y);
|
||||
Vector2 cursorAbsolutePos = new Vector2(realMouse.X + Game1.viewport.X, realMouse.Y + Game1.viewport.Y);
|
||||
|
||||
// update real states
|
||||
this.ActiveButtons = activeButtons;
|
||||
this.RealController = realController;
|
||||
this.RealKeyboard = realKeyboard;
|
||||
this.RealMouse = realMouse;
|
||||
if (this.CursorPositionImpl?.RawPixels != cursorRawPixelPos)
|
||||
this.CursorPositionImpl = this.GetCursorPosition(cursorRawPixelPos);
|
||||
if (this.CursorPositionImpl?.AbsolutePixels != cursorAbsolutePos)
|
||||
this.CursorPositionImpl = this.GetCursorPosition(realMouse, cursorAbsolutePos);
|
||||
|
||||
// update suppressed states
|
||||
this.SuppressButtons.RemoveWhere(p => !this.GetStatus(activeButtons, p).IsDown());
|
||||
|
@ -162,15 +162,17 @@ namespace StardewModdingAPI.Framework.Input
|
|||
** Private methods
|
||||
*********/
|
||||
/// <summary>Get the current cursor position.</summary>
|
||||
/// <remarks>The raw pixel position from the mouse state.</remarks>
|
||||
private CursorPosition GetCursorPosition(Vector2 rawPixelPos)
|
||||
/// <param name="mouseState">The current mouse state.</param>
|
||||
/// <param name="absolutePixels">The absolute pixel position relative to the map.</param>
|
||||
private CursorPosition GetCursorPosition(MouseState mouseState, Vector2 absolutePixels)
|
||||
{
|
||||
Vector2 screenPixels = new Vector2((int)(rawPixelPos.X * (1.0 / Game1.options.zoomLevel)), (int)(rawPixelPos.Y * (1.0 / Game1.options.zoomLevel))); // derived from Game1::getMouseX
|
||||
Vector2 rawPixels = new Vector2(mouseState.X, mouseState.Y);
|
||||
Vector2 screenPixels = rawPixels * new Vector2((float)1.0 / Game1.options.zoomLevel); // derived from Game1::getMouseX
|
||||
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
|
||||
: Game1.player.GetGrabTile();
|
||||
return new CursorPosition(rawPixelPos, screenPixels, tile, grabTile);
|
||||
return new CursorPosition(absolutePixels, screenPixels, tile, grabTile);
|
||||
}
|
||||
|
||||
/// <summary>Whether input should be suppressed in the current context.</summary>
|
||||
|
|
|
@ -6,6 +6,9 @@ namespace StardewModdingAPI
|
|||
/// <summary>Represents a cursor position in the different coordinate systems.</summary>
|
||||
public interface ICursorPosition : IEquatable<ICursorPosition>
|
||||
{
|
||||
/// <summary>The pixel position relative to the top-left corner of the in-game map.</summary>
|
||||
Vector2 AbsolutePixels { get; }
|
||||
|
||||
/// <summary>The pixel position relative to the top-left corner of the visible screen.</summary>
|
||||
Vector2 ScreenPixels { get; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue