summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Utilities/SButton.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-09-08 14:02:08 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-09-08 14:02:08 -0400
commitaf1a2bde8219c5d4b8660b13702725626a4a5647 (patch)
treea18bf2227299276604124b6a243ccda84d0413a2 /src/StardewModdingAPI/Utilities/SButton.cs
parent8df1ab7e1102dedf744e799af2cede560893c92a (diff)
parent23951220ae84f3132832c942b61a8e81aee1fbfe (diff)
downloadSMAPI-af1a2bde8219c5d4b8660b13702725626a4a5647.tar.gz
SMAPI-af1a2bde8219c5d4b8660b13702725626a4a5647.tar.bz2
SMAPI-af1a2bde8219c5d4b8660b13702725626a4a5647.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/StardewModdingAPI/Utilities/SButton.cs')
-rw-r--r--src/StardewModdingAPI/Utilities/SButton.cs28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/StardewModdingAPI/Utilities/SButton.cs b/src/StardewModdingAPI/Utilities/SButton.cs
index c4833b0b..33058a64 100644
--- a/src/StardewModdingAPI/Utilities/SButton.cs
+++ b/src/StardewModdingAPI/Utilities/SButton.cs
@@ -1,5 +1,6 @@
-using System;
+using System;
using Microsoft.Xna.Framework.Input;
+using StardewValley;
namespace StardewModdingAPI.Utilities
{
@@ -655,5 +656,30 @@ namespace StardewModdingAPI.Utilities
button = 0;
return false;
}
+
+ /// <summary>Get the <see cref="InputButton"/> equivalent for the given button.</summary>
+ /// <param name="input">The button to convert.</param>
+ /// <param name="button">The Stardew Valley input button equivalent.</param>
+ /// <returns>Returns whether the value was converted successfully.</returns>
+ public static bool TryGetStardewInput(this SButton input, out InputButton button)
+ {
+ // keyboard
+ if (input.TryGetKeyboard(out Keys key))
+ {
+ button = new InputButton(key);
+ return true;
+ }
+
+ // mouse
+ if (input == SButton.MouseLeft || input == SButton.MouseRight)
+ {
+ button = new InputButton(mouseLeft: input == SButton.MouseLeft);
+ return true;
+ }
+
+ // not valid
+ button = default(InputButton);
+ return false;
+ }
}
}