using System; using Microsoft.Xna.Framework.Input; using StardewValley; namespace StardewModdingAPI.Utilities { /// A unified button constant which includes all controller, keyboard, and mouse buttons. /// Derived from , , and . #if SMAPI_1_x internal #else public #endif enum SButton { /// No valid key. None = 0, /********* ** Mouse *********/ /// The left mouse button. MouseLeft = 1000, /// The right mouse button. MouseRight = 1001, /// The middle mouse button. MouseMiddle = 1002, /// The first mouse XButton. MouseX1 = 1003, /// The second mouse XButton. MouseX2 = 1004, /********* ** Controller *********/ /// The 'A' button on a controller. ControllerA = SButtonExtensions.ControllerOffset + Buttons.A, /// The 'B' button on a controller. ControllerB = SButtonExtensions.ControllerOffset + Buttons.B, /// The 'X' button on a controller. ControllerX = SButtonExtensions.ControllerOffset + Buttons.X, /// The 'Y' button on a controller. ControllerY = SButtonExtensions.ControllerOffset + Buttons.Y, /// The back button on a controller. ControllerBack = SButtonExtensions.ControllerOffset + Buttons.Back, /// The start button on a controller. ControllerStart = SButtonExtensions.ControllerOffset + Buttons.Start, /// The up button on the directional pad of a controller. DPadUp = SButtonExtensions.ControllerOffset + Buttons.DPadUp, /// The down button on the directional pad of a controller. DPadDown = SButtonExtensions.ControllerOffset + Buttons.DPadDown, /// The left button on the directional pad of a controller. DPadLeft = SButtonExtensions.ControllerOffset + Buttons.DPadLeft, /// The right button on the directional pad of a controller. DPadRight = SButtonExtensions.ControllerOffset + Buttons.DPadRight, /// The left bumper (shoulder) button on a controller. LeftShoulder = SButtonExtensions.ControllerOffset + Buttons.LeftShoulder, /// The right bumper (shoulder) button on a controller. RightShoulder = SButtonExtensions.ControllerOffset + Buttons.RightShoulder, /// The left trigger on a controller. LeftTrigger = SButtonExtensions.ControllerOffset + Buttons.LeftTrigger, /// The right trigger on a controller. RightTrigger = SButtonExtensions.ControllerOffset + Buttons.RightTrigger, /// The left analog stick on a controller (when pressed). LeftStick = SButtonExtensions.ControllerOffset + Buttons.LeftStick, /// The right analog stick on a controller (when pressed). RightStick = SButtonExtensions.ControllerOffset + Buttons.RightStick, /// The 'big button' on a controller. BigButton = SButtonExtensions.ControllerOffset + Buttons.BigButton, /// The left analog stick on a controller (when pushed left). LeftThumbstickLeft = SButtonExtensions.ControllerOffset + Buttons.LeftThumbstickLeft, /// The left analog stick on a controller (when pushed right). LeftThumbstickRight = SButtonExtensions.ControllerOffset + Buttons.LeftThumbstickRight, /// The left analog stick on a controller (when pushed down). LeftThumbstickDown = SButtonExtensions.ControllerOffset + Buttons.LeftThumbstickDown, /// The left analog stick on a controller (when pushed up). LeftThumbstickUp = SButtonExtensions.ControllerOffset + Buttons.LeftThumbstickUp, /// The right analog stick on a controller (when pushed left). RightThumbstickLeft = SButtonExtensions.ControllerOffset + Buttons.RightThumbstickLeft, /// The right analog stick on a controller (when pushed right). RightThumbstickRight = SButtonExtensions.ControllerOffset + Buttons.RightThumbstickRight, /// The right analog stick on a controller (when pushed down). RightThumbstickDown = SButtonExtensions.ControllerOffset + Buttons.RightThumbstickDown, /// The right analog stick on a controller (when pushed up). RightThumbstickUp = SButtonExtensions.ControllerOffset + Buttons.RightThumbstickUp, /********* ** Keyboard *********/ /// The A button on a keyboard. A = Keys.A, /// The Add button on a keyboard. Add = Keys.Add, /// The Applications button on a keyboard. Apps = Keys.Apps, /// The Attn button on a keyboard. Attn = Keys.Attn, /// The B button on a keyboard. B = Keys.B, /// The Backspace button on a keyboard. Back = Keys.Back, /// The Browser Back button on a keyboard in Windows 2000/XP. BrowserBack = Keys.BrowserBack, /// The Browser Favorites button on a keyboard in Windows 2000/XP. BrowserFavorites = Keys.BrowserFavorites, /// The Browser Favorites button on a keyboard in Windows 2000/XP. BrowserForward = Keys.BrowserForward, /// The Browser Home button on a keyboard in Windows 2000/XP. BrowserHome = Keys.BrowserHome, /// The Browser Refresh button on a keyboard in Windows 2000/XP. BrowserRefresh = Keys.BrowserRefresh, /// The Browser Search button on a keyboard in Windows 2000/XP. BrowserSearch = Keys.BrowserSearch, /// The Browser Stop button on a keyboard in Windows 2000/XP. BrowserStop = Keys.BrowserStop, /// The C button on a keyboard. C = Keys.C, /// The Caps Lock button on a keyboard. CapsLock = Keys.CapsLock, /// The Green ChatPad button on a keyboard. ChatPadGreen = Keys.ChatPadGreen, /// The Orange ChatPad button on a keyboard. ChatPadOrange = Keys.ChatPadOrange, /// The CrSel button on a keyboard. Crsel = Keys.Crsel, /// The D button on a keyboard. D = Keys.D, /// A miscellaneous button on a keyboard; can vary by keyboard. D0 = Keys.D0, /// A miscellaneous button on a keyboard; can vary by keyboard. D1 = Keys.D1, /// A miscellaneous button on a keyboard; can vary by keyboard. D2 = Keys.D2, /// A miscellaneous button on a keyboard; can vary by keyboard. D3 = Keys.D3, /// A miscellaneous button on a keyboard; can vary by keyboard. D4 = Keys.D4, /// A miscellaneous button on a keyboard; can vary by keyboard. D5 = Keys.D5, /// A miscellaneous button on a keyboard; can vary by keyboard. D6 = Keys.D6, /// A miscellaneous button on a keyboard; can vary by keyboard. D7 = Keys.D7, /// A miscellaneous button on a keyboard; can vary by keyboard. D8 = Keys.D8, /// A miscellaneous button on a keyboard; can vary by keyboard. D9 = Keys.D9, /// The Decimal button on a keyboard. Decimal = Keys.Decimal, /// The Delete button on a keyboard. Delete = Keys.Delete, /// The Divide button on a keyboard. Divide = Keys.Divide, /// The Down arrow button on a keyboard. Down = Keys.Down, /// The E button on a keyboard. E = Keys.E, /// The End button on a keyboard. End = Keys.End, /// The Enter button on a keyboard. Enter = Keys.Enter, /// The Erase EOF button on a keyboard. EraseEof = Keys.EraseEof, /// The Escape button on a keyboard. Escape = Keys.Escape, /// The Execute button on a keyboard. Execute = Keys.Execute, /// The ExSel button on a keyboard. Exsel = Keys.Exsel, /// The F button on a keyboard. F = Keys.F, /// The F1 button on a keyboard. F1 = Keys.F1, /// The F10 button on a keyboard. F10 = Keys.F10, /// The F11 button on a keyboard. F11 = Keys.F11, /// The F12 button on a keyboard. F12 = Keys.F12, /// The F13 button on a keyboard. F13 = Keys.F13, /// The F14 button on a keyboard. F14 = Keys.F14, /// The F15 button on a keyboard. F15 = Keys.F15, /// The F16 button on a keyboard. F16 = Keys.F16, /// The F17 button on a keyboard. F17 = Keys.F17, /// The F18 button on a keyboard. F18 = Keys.F18, /// The F19 button on a keyboard. F19 = Keys.F19, /// The F2 button on a keyboard. F2 = Keys.F2, /// The F20 button on a keyboard. F20 = Keys.F20, /// The F21 button on a keyboard. F21 = Keys.F21, /// The F22 button on a keyboard. F22 = Keys.F22, /// The F23 button on a keyboard. F23 = Keys.F23, /// The F24 button on a keyboard. F24 = Keys.F24, /// The F3 button on a keyboard. F3 = Keys.F3, /// The F4 button on a keyboard. F4 = Keys.F4, /// The F5 button on a keyboard. F5 = Keys.F5, /// The F6 button on a keyboard. F6 = Keys.F6, /// The F7 button on a keyboard. F7 = Keys.F7, /// The F8 button on a keyboard. F8 = Keys.F8, /// The F9 button on a keyboard. F9 = Keys.F9, /// The G button on a keyboard. G = Keys.G, /// The H button on a keyboard. H = Keys.H, /// The Help button on a keyboard. Help = Keys.Help, /// The Home button on a keyboard. Home = Keys.Home, /// The I button on a keyboard. I = Keys.I, /// The IME Convert button on a keyboard. ImeConvert = Keys.ImeConvert, /// The IME NoConvert button on a keyboard. ImeNoConvert = Keys.ImeNoConvert, /// The INS button on a keyboard. Insert = Keys.Insert, /// The J button on a keyboard. J = Keys.J, /// The K button on a keyboard. K = Keys.K, /// The Kana button on a Japanese keyboard. Kana = Keys.Kana, /// The Kanji button on a Japanese keyboard. Kanji = Keys.Kanji, /// The L button on a keyboard. L = Keys.L, /// The Start Applications 1 button on a keyboard in Windows 2000/XP. LaunchApplication1 = Keys.LaunchApplication1, /// The Start Applications 2 button on a keyboard in Windows 2000/XP. LaunchApplication2 = Keys.LaunchApplication2, /// The Start Mail button on a keyboard in Windows 2000/XP. LaunchMail = Keys.LaunchMail, /// The Left arrow button on a keyboard. Left = Keys.Left, /// The Left Alt button on a keyboard. LeftAlt = Keys.LeftAlt, /// The Left Control button on a keyboard. LeftControl = Keys.LeftControl, /// The Left Shift button on a keyboard. LeftShift = Keys.LeftShift, /// The Left Windows button on a keyboard. LeftWindows = Keys.LeftWindows, /// The M button on a keyboard. M = Keys.M, /// The MediaNextTrack button on a keyboard in Windows 2000/XP. MediaNextTrack = Keys.MediaNextTrack, /// The MediaPlayPause button on a keyboard in Windows 2000/XP. MediaPlayPause = Keys.MediaPlayPause, /// The MediaPreviousTrack button on a keyboard in Windows 2000/XP. MediaPreviousTrack = Keys.MediaPreviousTrack, /// The MediaStop button on a keyboard in Windows 2000/XP. MediaStop = Keys.MediaStop, /// The Multiply button on a keyboard. Multiply = Keys.Multiply, /// The N button on a keyboard. N = Keys.N, /// The Num Lock button on a keyboard. NumLock = Keys.NumLock, /// The Numeric keypad 0 button on a keyboard. NumPad0 = Keys.NumPad0, /// The Numeric keypad 1 button on a keyboard. NumPad1 = Keys.NumPad1, /// The Numeric keypad 2 button on a keyboard. NumPad2 = Keys.NumPad2, /// The Numeric keypad 3 button on a keyboard. NumPad3 = Keys.NumPad3, /// The Numeric keypad 4 button on a keyboard. NumPad4 = Keys.NumPad4, /// The Numeric keypad 5 button on a keyboard. NumPad5 = Keys.NumPad5, /// The Numeric keypad 6 button on a keyboard. NumPad6 = Keys.NumPad6, /// The Numeric keypad 7 button on a keyboard. NumPad7 = Keys.NumPad7, /// The Numeric keypad 8 button on a keyboard. NumPad8 = Keys.NumPad8, /// The Numeric keypad 9 button on a keyboard. NumPad9 = Keys.NumPad9, /// The O button on a keyboard. O = Keys.O, /// A miscellaneous button on a keyboard; can vary by keyboard. Oem8 = Keys.Oem8, /// The OEM Auto button on a keyboard. OemAuto = Keys.OemAuto, /// The OEM Angle Bracket or Backslash button on the RT 102 keyboard in Windows 2000/XP. OemBackslash = Keys.OemBackslash, /// The Clear button on a keyboard. OemClear = Keys.OemClear, /// The OEM Close Bracket button on a US standard keyboard in Windows 2000/XP. OemCloseBrackets = Keys.OemCloseBrackets, /// The ',' button on a keyboard in any country/region in Windows 2000/XP. OemComma = Keys.OemComma, /// The OEM Copy button on a keyboard. OemCopy = Keys.OemCopy, /// The OEM Enlarge Window button on a keyboard. OemEnlW = Keys.OemEnlW, /// The '-' button on a keyboard in any country/region in Windows 2000/XP. OemMinus = Keys.OemMinus, /// The OEM Open Bracket button on a US standard keyboard in Windows 2000/XP. OemOpenBrackets = Keys.OemOpenBrackets, /// The '.' button on a keyboard in any country/region. OemPeriod = Keys.OemPeriod, /// The OEM Pipe button on a US standard keyboard. OemPipe = Keys.OemPipe, /// The '+' button on a keyboard in Windows 2000/XP. OemPlus = Keys.OemPlus, /// The OEM Question Mark button on a US standard keyboard. OemQuestion = Keys.OemQuestion, /// The OEM Single/Double Quote button on a US standard keyboard. OemQuotes = Keys.OemQuotes, /// The OEM Semicolon button on a US standard keyboard. OemSemicolon = Keys.OemSemicolon, /// The OEM Tilde button on a US standard keyboard. OemTilde = Keys.OemTilde, /// The P button on a keyboard. P = Keys.P, /// The PA1 button on a keyboard. Pa1 = Keys.Pa1, /// The Page Down button on a keyboard. PageDown = Keys.PageDown, /// The Page Up button on a keyboard. PageUp = Keys.PageUp, /// The Pause button on a keyboard. Pause = Keys.Pause, /// The Play button on a keyboard. Play = Keys.Play, /// The Print button on a keyboard. Print = Keys.Print, /// The Print Screen button on a keyboard. PrintScreen = Keys.PrintScreen, /// The IME Process button on a keyboard in Windows 95/98/ME/NT 4.0/2000/XP. ProcessKey = Keys.ProcessKey, /// The Q button on a keyboard. Q = Keys.Q, /// The R button on a keyboard. R = Keys.R, /// The Right Arrow button on a keyboard. Right = Keys.Right, /// The Right Alt button on a keyboard. RightAlt = Keys.RightAlt, /// The Right Control button on a keyboard. RightControl = Keys.RightControl, /// The Right Shift button on a keyboard. RightShift = Keys.RightShift, /// The Right Windows button on a keyboard. RightWindows = Keys.RightWindows, /// The S button on a keyboard. S = Keys.S, /// The Scroll Lock button on a keyboard. Scroll = Keys.Scroll, /// The Select button on a keyboard. Select = Keys.Select, /// The Select Media button on a keyboard in Windows 2000/XP. SelectMedia = Keys.SelectMedia, /// The Separator button on a keyboard. Separator = Keys.Separator, /// The Computer Sleep button on a keyboard. Sleep = Keys.Sleep, /// The Space bar on a keyboard. Space = Keys.Space, /// The Subtract button on a keyboard. Subtract = Keys.Subtract, /// The T button on a keyboard. T = Keys.T, /// The Tab button on a keyboard. Tab = Keys.Tab, /// The U button on a keyboard. U = Keys.U, /// The Up Arrow button on a keyboard. Up = Keys.Up, /// The V button on a keyboard. V = Keys.V, /// The Volume Down button on a keyboard in Windows 2000/XP. VolumeDown = Keys.VolumeDown, /// The Volume Mute button on a keyboard in Windows 2000/XP. VolumeMute = Keys.VolumeMute, /// The Volume Up button on a keyboard in Windows 2000/XP. VolumeUp = Keys.VolumeUp, /// The W button on a keyboard. W = Keys.W, /// The X button on a keyboard. X = Keys.X, /// The Y button on a keyboard. Y = Keys.Y, /// The Z button on a keyboard. Z = Keys.Z, /// The Zoom button on a keyboard. Zoom = Keys.Zoom } /// Provides extension methods for . #if SMAPI_1_x internal #else public #endif static class SButtonExtensions { /********* ** Accessors *********/ /// The offset added to values when converting them to to avoid collisions with values. internal const int ControllerOffset = 2000; /********* ** Public methods *********/ /// Get the equivalent for the given button. /// The keyboard button to convert. internal static SButton ToSButton(this Keys key) { return (SButton)key; } /// Get the equivalent for the given button. /// The controller button to convert. internal static SButton ToSButton(this Buttons key) { return (SButton)(SButtonExtensions.ControllerOffset + key); } /// Get the equivalent for the given button. /// The button to convert. /// The keyboard equivalent. /// Returns whether the value was converted successfully. public static bool TryGetKeyboard(this SButton input, out Keys key) { if (Enum.IsDefined(typeof(Keys), (int)input)) { key = (Keys)input; return true; } key = Keys.None; return false; } /// Get the equivalent for the given button. /// The button to convert. /// The controller equivalent. /// Returns whether the value was converted successfully. public static bool TryGetController(this SButton input, out Buttons button) { if (Enum.IsDefined(typeof(Buttons), (int)input - SButtonExtensions.ControllerOffset)) { button = (Buttons)(input - SButtonExtensions.ControllerOffset); return true; } button = 0; return false; } /// Get the equivalent for the given button. /// The button to convert. /// The Stardew Valley input button equivalent. /// Returns whether the value was converted successfully. 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; } } }