Changes

Jump to navigation Jump to search
→‎Keybind settings: rewrite for SMAPI 3.9 and new best practices
Line 85: Line 85:  
: {{main article|Modding:Modder Guide/APIs/Input}}
 
: {{main article|Modding:Modder Guide/APIs/Input}}
   −
You can use SMAPI's [[Modding:Modder Guide/APIs/Input#SButton|<tt>SButton</tt>]] type directly in your config model to configure keybindings:
+
You can use SMAPI's [[Modding:Modder Guide/APIs/Input#KeybindList|<tt>KeybindList</tt>]] in your model to let users configure keybinds. This automatically supports multi-key or alternative bindings (e.g. to support split-screen mode):
 +
 
 
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
 
class ModConfig
 
class ModConfig
 
{
 
{
   public SButton ToggleKey { get; set; } = SButton.F2;
+
   public KeybindList ToggleKey { get; set; } = KeybindList.Parse("LeftShift + F2, LeftTrigger");
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 96: Line 97:  
<syntaxhighlight lang="json">
 
<syntaxhighlight lang="json">
 
{
 
{
   "ToggleKey": "F2"
+
   "ToggleKey": "LeftShift + F2, LeftTrigger"
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  −
{{SMAPI upcoming|3.9|
  −
For compatibility with split-screen (when you may have players on both keyboard and controller), you should use [[Modding:Modder Guide/APIs/Input#KeybindList|<tt>KeybindList</tt>]] instead:
  −
  −
<syntaxhighlight lang="c#">
  −
class ModConfig
  −
{
  −
  public KeybindList ToggleKey { get; set; } = KeybindList.ForSingle(SButton.F2);
  −
}
  −
</syntaxhighlight>
  −
  −
This is written/parsed the same way, but lets players specify multi-key or alternative bindings like <code>"LeftShift + F2, LeftTrigger"</code>.
  −
}}
 
translators
8,403

edits

Navigation menu