summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-06-02 02:35:26 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-06-02 02:35:26 -0400
commit6f931aa576b2b2f6a64e7e0522e01f6a37c92c8a (patch)
tree403b30a28e19f5b4936ab85920a5678c562ff766 /src/SMAPI/Framework
parent0df7a967a6980db7f4da8d393feae97c968e3375 (diff)
downloadSMAPI-6f931aa576b2b2f6a64e7e0522e01f6a37c92c8a.tar.gz
SMAPI-6f931aa576b2b2f6a64e7e0522e01f6a37c92c8a.tar.bz2
SMAPI-6f931aa576b2b2f6a64e7e0522e01f6a37c92c8a.zip
add Input.CursorMoved event (#310)
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r--src/SMAPI/Framework/Events/EventManager.cs20
-rw-r--r--src/SMAPI/Framework/Events/ModInputEvents.cs11
-rw-r--r--src/SMAPI/Framework/SGame.cs27
3 files changed, 41 insertions, 17 deletions
diff --git a/src/SMAPI/Framework/Events/EventManager.cs b/src/SMAPI/Framework/Events/EventManager.cs
index 62d9582e..eea74587 100644
--- a/src/SMAPI/Framework/Events/EventManager.cs
+++ b/src/SMAPI/Framework/Events/EventManager.cs
@@ -35,12 +35,15 @@ namespace StardewModdingAPI.Framework.Events
/****
** Input
****/
- /// <summary>Raised when the player presses a button on the keyboard, controller, or mouse.</summary>
+ /// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
public readonly ManagedEvent<InputButtonPressedArgsInput> Input_ButtonPressed;
- /// <summary>Raised when the player released a button on the keyboard, controller, or mouse.</summary>
+ /// <summary>Raised after the player released a button on the keyboard, controller, or mouse.</summary>
public readonly ManagedEvent<InputButtonReleasedArgsInput> Input_ButtonReleased;
+ /// <summary>Raised after the player moves the in-game cursor.</summary>
+ public readonly ManagedEvent<InputCursorMovedArgsInput> Input_CursorMoved;
+
/*********
** Events (old)
@@ -57,14 +60,14 @@ namespace StardewModdingAPI.Framework.Events
/// <summary>Raised when the <see cref="KeyboardState"/> changes. That happens when the player presses or releases a key.</summary>
public readonly ManagedEvent<EventArgsKeyboardStateChanged> Legacy_Control_KeyboardChanged;
- /// <summary>Raised when the player presses a keyboard key.</summary>
+ /// <summary>Raised after the player presses a keyboard key.</summary>
public readonly ManagedEvent<EventArgsKeyPressed> Legacy_Control_KeyPressed;
- /// <summary>Raised when the player releases a keyboard key.</summary>
+ /// <summary>Raised after the player releases a keyboard key.</summary>
public readonly ManagedEvent<EventArgsKeyPressed> Legacy_Control_KeyReleased;
/// <summary>Raised when the <see cref="MouseState"/> changes. That happens when the player moves the mouse, scrolls the mouse wheel, or presses/releases a button.</summary>
- public readonly ManagedEvent<EventArgsMouseStateChanged> Control_MouseChanged;
+ public readonly ManagedEvent<EventArgsMouseStateChanged> Legacy_Control_MouseChanged;
/// <summary>The player pressed a controller button. This event isn't raised for trigger buttons.</summary>
public readonly ManagedEvent<EventArgsControllerButtonPressed> Legacy_Control_ControllerButtonPressed;
@@ -132,10 +135,10 @@ namespace StardewModdingAPI.Framework.Events
/****
** InputEvents
****/
- /// <summary>Raised when the player presses a button on the keyboard, controller, or mouse.</summary>
+ /// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
public readonly ManagedEvent<EventArgsInput> Legacy_Input_ButtonPressed;
- /// <summary>Raised when the player releases a keyboard key on the keyboard, controller, or mouse.</summary>
+ /// <summary>Raised after the player releases a keyboard key on the keyboard, controller, or mouse.</summary>
public readonly ManagedEvent<EventArgsInput> Legacy_Input_ButtonReleased;
/****
@@ -245,6 +248,7 @@ namespace StardewModdingAPI.Framework.Events
// init events (new)
this.Input_ButtonPressed = ManageEventOf<InputButtonPressedArgsInput>(nameof(IModEvents.Input), nameof(IInputEvents.ButtonPressed));
this.Input_ButtonReleased = ManageEventOf<InputButtonReleasedArgsInput>(nameof(IModEvents.Input), nameof(IInputEvents.ButtonReleased));
+ this.Input_CursorMoved = ManageEventOf<InputCursorMovedArgsInput>(nameof(IModEvents.Input), nameof(IInputEvents.CursorMoved));
this.World_BuildingListChanged = ManageEventOf<WorldBuildingListChangedEventArgs>(nameof(IModEvents.World), nameof(IWorldEvents.LocationListChanged));
this.World_LargeTerrainFeatureListChanged = ManageEventOf<WorldLargeTerrainFeatureListChangedEventArgs>(nameof(IModEvents.World), nameof(IWorldEvents.LargeTerrainFeatureListChanged));
@@ -263,7 +267,7 @@ namespace StardewModdingAPI.Framework.Events
this.Legacy_Control_KeyboardChanged = ManageEventOf<EventArgsKeyboardStateChanged>(nameof(ControlEvents), nameof(ControlEvents.KeyboardChanged));
this.Legacy_Control_KeyPressed = ManageEventOf<EventArgsKeyPressed>(nameof(ControlEvents), nameof(ControlEvents.KeyPressed));
this.Legacy_Control_KeyReleased = ManageEventOf<EventArgsKeyPressed>(nameof(ControlEvents), nameof(ControlEvents.KeyReleased));
- this.Control_MouseChanged = ManageEventOf<EventArgsMouseStateChanged>(nameof(ControlEvents), nameof(ControlEvents.MouseChanged));
+ this.Legacy_Control_MouseChanged = ManageEventOf<EventArgsMouseStateChanged>(nameof(ControlEvents), nameof(ControlEvents.MouseChanged));
this.Game_FirstUpdateTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.FirstUpdateTick));
this.Game_UpdateTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.UpdateTick));
diff --git a/src/SMAPI/Framework/Events/ModInputEvents.cs b/src/SMAPI/Framework/Events/ModInputEvents.cs
index 18baec16..48dd0369 100644
--- a/src/SMAPI/Framework/Events/ModInputEvents.cs
+++ b/src/SMAPI/Framework/Events/ModInputEvents.cs
@@ -9,20 +9,27 @@ namespace StardewModdingAPI.Framework.Events
/*********
** Accessors
*********/
- /// <summary>Raised when the player presses a button on the keyboard, controller, or mouse.</summary>
+ /// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
public event EventHandler<InputButtonPressedArgsInput> ButtonPressed
{
add => this.EventManager.Input_ButtonPressed.Add(value);
remove => this.EventManager.Input_ButtonPressed.Remove(value);
}
- /// <summary>Raised when the player releases a button on the keyboard, controller, or mouse.</summary>
+ /// <summary>Raised after the player releases a button on the keyboard, controller, or mouse.</summary>
public event EventHandler<InputButtonReleasedArgsInput> ButtonReleased
{
add => this.EventManager.Input_ButtonReleased.Add(value);
remove => this.EventManager.Input_ButtonReleased.Remove(value);
}
+ /// <summary>Raised after the player moves the in-game cursor.</summary>
+ public event EventHandler<InputCursorMovedArgsInput> CursorMoved
+ {
+ add => this.EventManager.Input_CursorMoved.Add(value);
+ remove => this.EventManager.Input_CursorMoved.Remove(value);
+ }
+
/*********
** Public methods
diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs
index f87293c2..f4e0d3c5 100644
--- a/src/SMAPI/Framework/SGame.cs
+++ b/src/SMAPI/Framework/SGame.cs
@@ -103,6 +103,9 @@ namespace StardewModdingAPI.Framework
/// <summary>The previous content locale.</summary>
private LocalizedContentManager.LanguageCode? PreviousLocale;
+ /// <summary>The previous cursor position.</summary>
+ private ICursorPosition PreviousCursorPosition;
+
/// <summary>An index incremented on every tick and reset every 60th tick (0–59).</summary>
private int CurrentUpdateTick;
@@ -444,14 +447,24 @@ namespace StardewModdingAPI.Framework
{
// cursor position
Vector2 screenPixels = new Vector2(Game1.getMouseX(), Game1.getMouseY());
- 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();
- cursor = new CursorPosition(screenPixels, tile, grabTile);
+ if (this.PreviousCursorPosition == null || screenPixels != this.PreviousCursorPosition.ScreenPixels)
+ {
+ 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();
+ cursor = new CursorPosition(screenPixels, tile, grabTile);
+ }
+ else
+ cursor = this.PreviousCursorPosition;
}
- // raise input events
+ // raise cursor moved event
+ if (this.PreviousCursorPosition != null && cursor.ScreenPixels != this.PreviousCursorPosition.ScreenPixels)
+ this.Events.Input_CursorMoved.Raise(new InputCursorMovedArgsInput(this.PreviousCursorPosition, cursor));
+ this.PreviousCursorPosition = cursor;
+
+ // raise input button events
foreach (var pair in inputState.ActiveButtons)
{
SButton button = pair.Key;
@@ -501,7 +514,7 @@ namespace StardewModdingAPI.Framework
if (inputState.RealKeyboard != previousInputState.RealKeyboard)
this.Events.Legacy_Control_KeyboardChanged.Raise(new EventArgsKeyboardStateChanged(previousInputState.RealKeyboard, inputState.RealKeyboard));
if (inputState.RealMouse != previousInputState.RealMouse)
- this.Events.Control_MouseChanged.Raise(new EventArgsMouseStateChanged(previousInputState.RealMouse, inputState.RealMouse, previousInputState.MousePosition, inputState.MousePosition));
+ this.Events.Legacy_Control_MouseChanged.Raise(new EventArgsMouseStateChanged(previousInputState.RealMouse, inputState.RealMouse, previousInputState.MousePosition, inputState.MousePosition));
}
}