summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-06-02 12:14:15 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-06-02 12:14:15 -0400
commit90f55a6921ac798e03d6f81240d3a9899544c031 (patch)
treed19e551679c69d436028e30115740242d8a90104 /src
parent74971f532822b44fbffc99810afd2c0d8a0d424d (diff)
downloadSMAPI-90f55a6921ac798e03d6f81240d3a9899544c031.tar.gz
SMAPI-90f55a6921ac798e03d6f81240d3a9899544c031.tar.bz2
SMAPI-90f55a6921ac798e03d6f81240d3a9899544c031.zip
add mouse scroll event (#310)
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI/Events/IInputEvents.cs3
-rw-r--r--src/SMAPI/Events/InputMouseWheelScrolledEventArgs.cs38
-rw-r--r--src/SMAPI/Framework/Events/EventManager.cs4
-rw-r--r--src/SMAPI/Framework/Events/ModInputEvents.cs7
-rw-r--r--src/SMAPI/Framework/SGame.cs15
-rw-r--r--src/SMAPI/StardewModdingAPI.csproj1
6 files changed, 68 insertions, 0 deletions
diff --git a/src/SMAPI/Events/IInputEvents.cs b/src/SMAPI/Events/IInputEvents.cs
index 938c772b..64d82c57 100644
--- a/src/SMAPI/Events/IInputEvents.cs
+++ b/src/SMAPI/Events/IInputEvents.cs
@@ -13,5 +13,8 @@ namespace StardewModdingAPI.Events
/// <summary>Raised after the player moves the in-game cursor.</summary>
event EventHandler<InputCursorMovedArgsInput> CursorMoved;
+
+ /// <summary>Raised after the player scrolls the mouse wheel.</summary>
+ event EventHandler<InputMouseWheelScrolledEventArgs> MouseWheelScrolled;
}
}
diff --git a/src/SMAPI/Events/InputMouseWheelScrolledEventArgs.cs b/src/SMAPI/Events/InputMouseWheelScrolledEventArgs.cs
new file mode 100644
index 00000000..9afab9cc
--- /dev/null
+++ b/src/SMAPI/Events/InputMouseWheelScrolledEventArgs.cs
@@ -0,0 +1,38 @@
+using System;
+
+namespace StardewModdingAPI.Events
+{
+ /// <summary>Event arguments when the player scrolls the mouse wheel.</summary>
+ public class InputMouseWheelScrolledEventArgs : EventArgs
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The cursor position.</summary>
+ public ICursorPosition Position { get; }
+
+ /// <summary>The old scroll value.</summary>
+ public int OldValue { get; }
+
+ /// <summary>The new scroll value.</summary>
+ public int NewValue { get; }
+
+ /// <summary>The amount by which the scroll value changed.</summary>
+ public int Delta => this.NewValue - this.OldValue;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="position">The cursor position.</param>
+ /// <param name="oldValue">The old scroll value.</param>
+ /// <param name="newValue">The new scroll value.</param>
+ public InputMouseWheelScrolledEventArgs(ICursorPosition position, int oldValue, int newValue)
+ {
+ this.Position = position;
+ this.OldValue = oldValue;
+ this.NewValue = newValue;
+ }
+ }
+}
diff --git a/src/SMAPI/Framework/Events/EventManager.cs b/src/SMAPI/Framework/Events/EventManager.cs
index eea74587..9f67244a 100644
--- a/src/SMAPI/Framework/Events/EventManager.cs
+++ b/src/SMAPI/Framework/Events/EventManager.cs
@@ -44,6 +44,9 @@ namespace StardewModdingAPI.Framework.Events
/// <summary>Raised after the player moves the in-game cursor.</summary>
public readonly ManagedEvent<InputCursorMovedArgsInput> Input_CursorMoved;
+ /// <summary>Raised after the player scrolls the mouse wheel.</summary>
+ public readonly ManagedEvent<InputMouseWheelScrolledEventArgs> Input_MouseWheelScrolled;
+
/*********
** Events (old)
@@ -249,6 +252,7 @@ namespace StardewModdingAPI.Framework.Events
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.Input_MouseWheelScrolled = ManageEventOf<InputMouseWheelScrolledEventArgs>(nameof(IModEvents.Input), nameof(IInputEvents.MouseWheelScrolled));
this.World_BuildingListChanged = ManageEventOf<WorldBuildingListChangedEventArgs>(nameof(IModEvents.World), nameof(IWorldEvents.LocationListChanged));
this.World_LargeTerrainFeatureListChanged = ManageEventOf<WorldLargeTerrainFeatureListChangedEventArgs>(nameof(IModEvents.World), nameof(IWorldEvents.LargeTerrainFeatureListChanged));
diff --git a/src/SMAPI/Framework/Events/ModInputEvents.cs b/src/SMAPI/Framework/Events/ModInputEvents.cs
index 48dd0369..387ea87a 100644
--- a/src/SMAPI/Framework/Events/ModInputEvents.cs
+++ b/src/SMAPI/Framework/Events/ModInputEvents.cs
@@ -30,6 +30,13 @@ namespace StardewModdingAPI.Framework.Events
remove => this.EventManager.Input_CursorMoved.Remove(value);
}
+ /// <summary>Raised after the player scrolls the mouse wheel.</summary>
+ public event EventHandler<InputMouseWheelScrolledEventArgs> MouseWheelScrolled
+ {
+ add => this.EventManager.Input_MouseWheelScrolled.Add(value);
+ remove => this.EventManager.Input_MouseWheelScrolled.Remove(value);
+ }
+
/*********
** Public methods
diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs
index 894a771f..18529728 100644
--- a/src/SMAPI/Framework/SGame.cs
+++ b/src/SMAPI/Framework/SGame.cs
@@ -103,6 +103,9 @@ namespace StardewModdingAPI.Framework
/// <summary>Tracks changes to the cursor position.</summary>
private readonly IValueWatcher<Point> CursorWatcher;
+ /// <summary>Tracks changes to the mouse wheel scroll.</summary>
+ private readonly IValueWatcher<int> MouseWheelScrollWatcher;
+
/// <summary>The previous content locale.</summary>
private LocalizedContentManager.LanguageCode? PreviousLocale;
@@ -172,6 +175,7 @@ namespace StardewModdingAPI.Framework
// init watchers
Game1.locations = new ObservableCollection<GameLocation>();
this.CursorWatcher = WatcherFactory.ForEquatable(() => this.Input.MousePosition);
+ this.MouseWheelScrollWatcher = WatcherFactory.ForEquatable(() => this.Input.RealMouse.ScrollWheelValue);
this.SaveIdWatcher = WatcherFactory.ForEquatable(() => Game1.hasLoadedGame ? Game1.uniqueIDForThisGame : 0);
this.WindowSizeWatcher = WatcherFactory.ForEquatable(() => new Point(Game1.viewport.Width, Game1.viewport.Height));
this.TimeWatcher = WatcherFactory.ForEquatable(() => Game1.timeOfDay);
@@ -180,6 +184,7 @@ namespace StardewModdingAPI.Framework
this.Watchers.AddRange(new IWatcher[]
{
this.CursorWatcher,
+ this.MouseWheelScrollWatcher,
this.SaveIdWatcher,
this.WindowSizeWatcher,
this.TimeWatcher,
@@ -468,6 +473,16 @@ namespace StardewModdingAPI.Framework
}
this.PreviousCursorPosition = cursor;
+ // raise mouse wheel scrolled
+ if (this.MouseWheelScrollWatcher.IsChanged)
+ {
+ int oldValue = this.MouseWheelScrollWatcher.PreviousValue;
+ int newValue = this.MouseWheelScrollWatcher.CurrentValue;
+ this.MouseWheelScrollWatcher.Reset();
+
+ this.Events.Input_MouseWheelScrolled.Raise(new InputMouseWheelScrolledEventArgs(cursor, oldValue, newValue));
+ }
+
// raise input button events
foreach (var pair in inputState.ActiveButtons)
{
diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj
index 604ad64f..b81f1359 100644
--- a/src/SMAPI/StardewModdingAPI.csproj
+++ b/src/SMAPI/StardewModdingAPI.csproj
@@ -85,6 +85,7 @@
<Compile Include="..\..\build\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
+ <Compile Include="Events\InputMouseWheelScrolledEventArgs.cs" />
<Compile Include="Events\InputCursorMovedEventArgs.cs" />
<Compile Include="Events\InputButtonReleasedEventArgs.cs" />
<Compile Include="Events\InputButtonPressedEventArgs.cs" />