This wiki is a read-only version of the Stardew Valley Wiki. The official editable wiki maintained by ConcernedApe can be found at stardewvalleywiki.com

Changes

Jump to: navigation, search

Modding:Modder Guide/APIs/Utilities

1,743 bytes removed, 20:59, 10 June 2018
move SButton info to Modding:Modder Guide/APIs/Input
==Input==
SMAPI's <tt>SButton</tt> constants unify the [https://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.buttons.aspx <tt>Buttons</tt>], [https://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.keys.aspx <tt>Keys</tt>], [https://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.mousestate.aspx <tt>MouseState</tt>], and <tt>InputButton</tt> constants. SMAPI events use this to let you handle uniquely represent controller, keyboard, and mouse input without needing separate code for eachbutton presses or clicks. See [[Modding:Key bindings]] for a list of values. SMAPI provides extensions to convert any of the other constants to <tt>SButton</tt>:<source lang="c#">SButton key = Keys.A.ToSButton(); // SButton.ASButton button = Buttons.A.ToSButton(); // SButton.ControllerASButton input = new InputButton(true).ToSButton(); // SButton.MouseLeft</source> You can also convert <tt>SButton</tt> to the other constants. This uses a <tt>TryGet</tt> approach since <tt>SButton</tt> is a superset of the others (e.g. you can't convert <tt>SButton.ControllerA</tt> to a keyboard value):<source lang="c#">SButton value = SButton.A;if (value.TryGetKeyboard(out Keys key)) ...;if (value.TryGetController(out Buttons button)) ...;if (value.TryGetStardewInput(out InputButton input)) ...;</source> Two last extensions let you check how the button is mapped in the game:<source lang="c#">SButton button = SButton.MouseLeft;if (button.IsUseToolButton()) // use toolelse if (button.IsActionButton()) // perform action</source> You can use <tt>SButton</tt> values directly in your [[../ConfigInput|config modelInput]], and they'll be represented by their names:{| class="wikitable"| <source lang="c#">internal class ModConfig{ public SButton DoThingButton { get; set; } = SButtonpage for more info.LeftControl;}</source>| &rarr;| <source lang="json">{ "DoThingButton": "LeftControl"}</source>|}
==Semantic versions==
Protected, translators
5,421
edits

Navigation menu