第30行: |
第30行: |
| | up | | | up |
| | up | | | up |
− | | <samp> 无</samp> | + | | <samp>None</samp> |
| |- | | |- |
| | up | | | up |
| | down | | | down |
− | | <samp> 按下</samp> | + | | <samp>Pressed</samp> |
| |- | | |- |
| | down | | | down |
| | down | | | down |
− | | <samp> 按住</samp> | + | | <samp>Held</samp> |
| |- | | |- |
| | down | | | down |
| | up | | | up |
− | | <samp> 松开</samp> | + | | <samp>Released</samp> |
| |} | | |} |
| </dd> | | </dd> |
第89行: |
第89行: |
| 副作用: | | 副作用: |
| <ul> | | <ul> |
− | <li>The [[Modding:Modder Guide/APIs/Events#Input.ButtonReleased|<samp>ButtonReleased</samp> event]] will be raised on the next tick for the suppressed input.</li> | + | <li>[[Modding:Modder Guide/APIs/Events#Input.ButtonReleased|<samp>ButtonReleased</samp> 事件]] 会在输入被抑制后的下一个 tick 触发。</li> |
− | <li>Methods like <samp>helper.Input.IsDown(button)</samp> and <samp>helper.Input.GetState(button)</samp> will show the button as released for the duration of the suppression, even if it's physically still pressed. You can use <samp>helper.Input.IsSuppressed(button)</samp> to check if that's the case (it will only be true until the button is physically released): | + | <li> 在按键被抑制期间,类似 <samp>helper.Input.IsDown(button)</samp> 和 <samp>helper.Input.GetState(button)</samp> 的方法会表明按键的状态是 released ,即使该按键在现实中处于被按下的状态。你可以使用 <samp>helper.Input.IsSuppressed(button)</samp> 来检查按键是否处于这种情况(它会一直返回 true 直到按键在现实中被松开): |
| <syntaxhighlight lang="c#"> | | <syntaxhighlight lang="c#"> |
| bool isPhysicallyDown = helper.Input.IsDown(button) || helper.Input.IsSuppressed(button); | | bool isPhysicallyDown = helper.Input.IsDown(button) || helper.Input.IsSuppressed(button); |
第96行: |
第96行: |
| </ul> | | </ul> |
| | | |
− | ==Data structures== | + | == 数据结构== |
| ===SButton=== | | ===SButton=== |
− | SMAPI's <samp>SButton</samp> is a constant which includes every [https://docs.microsoft.com/en-us/previous-versions/windows/xna/bb975202(v%3dxnagamestudio.40) controller], [https://docs.microsoft.com/en-us/previous-versions/windows/xna/bb197781(v%3dxnagamestudio.40) keyboard], and [https://docs.microsoft.com/en-us/previous-versions/windows/xna/bb198097(v%3dxnagamestudio.40) mouse] button. SMAPI events use this to let you handle button presses without needing separate code for each. See [[Modding:Player Guide/Key Bindings]] for a list of values. | + | SMAPI 的 <samp>SButton</samp> 是一个涵盖了每种[https://docs.microsoft.com/en-us/previous-versions/windows/xna/bb975202(v%3dxnagamestudio.40) 控制器], [https://docs.microsoft.com/en-us/previous-versions/windows/xna/bb197781(v%3dxnagamestudio.40) 键盘] 和[https://docs.microsoft.com/en-us/previous-versions/windows/xna/bb198097(v%3dxnagamestudio.40) 鼠标] 的按键的常量。SMAPI 事件使用此常量,这允许你处理按键按下时不需要区分每种按键的代码。阅读 [[Modding:Player Guide/Key Bindings]] 来获取值列表。 |
| | | |
− | SMAPI provides extensions to convert any of the other constants to <samp>SButton</samp>: | + | SMAPI 提供了把任意其他常量转换为 <samp>SButton</samp> 的扩展: |
| <syntaxhighlight lang="c#"> | | <syntaxhighlight lang="c#"> |
| SButton key = Keys.A.ToSButton(); // SButton.A | | SButton key = Keys.A.ToSButton(); // SButton.A |
第107行: |
第107行: |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | You can also convert <samp>SButton</samp> to the other constants. This uses a <samp>TryGet</samp> approach since <samp>SButton</samp> is a superset of the others (''e.g.,'' you can't convert <samp>SButton.ControllerA</samp> to a keyboard value):
| + | 你也可以将 <samp>SButton</samp> 转换为其他常量。这将使用到 <samp>TryGet</samp> 的途径,因为 <samp>SButton</samp> 是其他常量的一个超集(比方说,你不能把 <samp>SButton.ControllerA</samp> 转换成一个 keyboard 值): |
| <syntaxhighlight lang="c#"> | | <syntaxhighlight lang="c#"> |
| SButton value = SButton.A; | | SButton value = SButton.A; |
第118行: |
第118行: |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | Two last extensions let you check how the button is mapped in the game:
| + | 最后两个扩展帮助你检查按键在游戏中如何布局: |
| <syntaxhighlight lang="c#"> | | <syntaxhighlight lang="c#"> |
| SButton button = SButton.MouseLeft; | | SButton button = SButton.MouseLeft; |
| if (button.IsUseToolButton()) | | if (button.IsUseToolButton()) |
− | // use tool | + | // 使用工具 |
| else if (button.IsActionButton()) | | else if (button.IsActionButton()) |
− | // perform action | + | // 执行动作 |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | You can use <samp>SButton</samp> values directly in your [[../Config|config model]], but <samp>[[#KeybindList|KeybindList]]</samp> is recommended instead in most cases.
| + | 你可以在[[../Config|config model]] 中直接使用 <samp>SButton</samp> 的值,但是大部分情况下推荐使用 <samp>[[#KeybindList|KeybindList]]</samp> 。 |
| | | |
| ===KeybindList=== | | ===KeybindList=== |
第212行: |
第212行: |
| '''The pixel positions are ''not'' adjusted for [[Modding:Modder Guide/Game Fundamentals#UI scaling|UI scaling]]''' (''i.e.,'' they're non-UI mode). Whether you need UI or non-UI positions depends how you're using them, so you can use <samp>cursorPos.GetScaledAbsolutePixels()</samp> or <samp>cursorPos.GetScaledScreenPixels()</samp> to adjust them automatically for the current mode or <samp>Utility.ModifyCoordinatesForUIScale</samp> to always get UI mode coordinates. | | '''The pixel positions are ''not'' adjusted for [[Modding:Modder Guide/Game Fundamentals#UI scaling|UI scaling]]''' (''i.e.,'' they're non-UI mode). Whether you need UI or non-UI positions depends how you're using them, so you can use <samp>cursorPos.GetScaledAbsolutePixels()</samp> or <samp>cursorPos.GetScaledScreenPixels()</samp> to adjust them automatically for the current mode or <samp>Utility.ModifyCoordinatesForUIScale</samp> to always get UI mode coordinates. |
| | | |
− | ==See also== | + | == 另见== |
| * [[../Events#Input|Input events]] | | * [[../Events#Input|Input events]] |
− | * [[Modding:Player Guide/Key Bindings]] for a list of valid <samp>SButton</samp> values | + | * [[Modding:Player Guide/Key Bindings]] 中有一个可用的 <samp>SButton</samp> 值列表 |
| | | |
| [[en:Modding:Modder Guide/APIs/Input]] | | [[en:Modding:Modder Guide/APIs/Input]] |