summaryrefslogtreecommitdiff
path: root/src/SMAPI/SModHooks.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-04-22 19:59:03 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-04-22 19:59:03 -0400
commit5e7eaf9f75d72d8cbb338c35b43f2974440b3456 (patch)
tree4cc95e003f4434941e22d2588b9dea11dfae9469 /src/SMAPI/SModHooks.cs
parent902814d308289f169750a615ae573edc348893d3 (diff)
downloadSMAPI-5e7eaf9f75d72d8cbb338c35b43f2974440b3456.tar.gz
SMAPI-5e7eaf9f75d72d8cbb338c35b43f2974440b3456.tar.bz2
SMAPI-5e7eaf9f75d72d8cbb338c35b43f2974440b3456.zip
rewrite input suppression (#453)
This lets SMAPI intercept all input using the new Game1.hooks in SDV 1.3.0.32. However, intercepting mouse clicks needs a few more changes in the game code.
Diffstat (limited to 'src/SMAPI/SModHooks.cs')
-rw-r--r--src/SMAPI/SModHooks.cs48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/SMAPI/SModHooks.cs b/src/SMAPI/SModHooks.cs
new file mode 100644
index 00000000..1b88d606
--- /dev/null
+++ b/src/SMAPI/SModHooks.cs
@@ -0,0 +1,48 @@
+using System;
+using Microsoft.Xna.Framework.Input;
+using StardewValley;
+
+namespace StardewModdingAPI
+{
+ /// <summary>Intercepts predefined Stardew Valley mod hooks.</summary>
+ internal class SModHooks : ModHooks
+ {
+ /*********
+ ** Delegates
+ *********/
+ /// <summary>A delegate invoked by the <see cref="SModHooks.OnGame1_UpdateControlInput"/> hook.</summary>
+ /// <param name="keyboardState">The game's keyboard state for the current tick.</param>
+ /// <param name="mouseState">The game's mouse state for the current tick.</param>
+ /// <param name="gamePadState">The game's controller state for the current tick.</param>
+ /// <param name="action">The game's default logic.</param>
+ public delegate void UpdateControlInputDelegate(ref KeyboardState keyboardState, ref MouseState mouseState, ref GamePadState gamePadState, Action action);
+
+
+ /*********
+ ** Properties
+ *********/
+ /// <summary>The callback for <see cref="OnGame1_UpdateControlInput"/>.</summary>
+ private readonly UpdateControlInputDelegate UpdateControlInputHandler;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="updateControlInputHandler">The callback for <see cref="OnGame1_UpdateControlInput"/>.</param>
+ public SModHooks(UpdateControlInputDelegate updateControlInputHandler)
+ {
+ this.UpdateControlInputHandler = updateControlInputHandler;
+ }
+
+ /// <summary>A hook invoked before the game processes player input.</summary>
+ /// <param name="keyboardState">The game's keyboard state for the current tick.</param>
+ /// <param name="mouseState">The game's mouse state for the current tick.</param>
+ /// <param name="gamePadState">The game's controller state for the current tick.</param>
+ /// <param name="action">The game's default logic.</param>
+ public override void OnGame1_UpdateControlInput(ref KeyboardState keyboardState, ref MouseState mouseState, ref GamePadState gamePadState, Action action)
+ {
+ this.UpdateControlInputHandler(ref keyboardState, ref mouseState, ref gamePadState, action);
+ }
+ }
+}