Pathoschild / SMAPI

The modding API for Stardew Valley.
https://smapi.io/
GNU Lesser General Public License v3.0
1.71k stars 258 forks source link

Allow mods to suppress scroll wheel changes #941

Closed MercuriusXeno closed 1 day ago

MercuriusXeno commented 3 months ago

Exposes a new method in IInputHandler named SuppressScrollWheel, which causes SInputState to update Game1.oldMouseState to a copy of itself with ScrollWheelValue synced to the latest value, each tick, so that changes are ignored, for the duration of the suppression.

Mods must proactively reset the suppression state to false to restore scrolling when they're done doing whatever they need to do with scrolling.

Note that this preserves MouseWheelChangedEvent firing by design. I didn't consider the use cases or ramification too deeply beyond the initial assumption that mods would still need the event to fire, so this may need further discussion.

Feel free to issue any corrections if there's style issues, I do not mind the cleanup work.

MercuriusXeno commented 3 months ago

Hindsight - i'm not a huge fan of the pattern differences between overridden buttons (set it and forget it, it clears the override on release organically) and this new flag (you have to put it back when you're done).

I experimented a bit with trying to make something more temporary but it's a broad departure from what this PR does.

Open to ideas.

Pathoschild commented 3 months ago

Thanks for the pull request! We could maybe update the old state once when the method is called though, so it'd only be suppressed until the scroll wheel changes again (just like button suppression only applies until it changes again).

MercuriusXeno commented 3 months ago

Changed the style per your suggestion, wound up being a much cleaner impl

Pathoschild commented 1 day ago

Merged into develop for the upcoming SMAPI 4.1.0. Thanks for the help!