コード例 #1
0
        public static bool RebindKey(bool gamepad, RebindableKeys key)
        {
            Buttons newbutton = Buttons.A;
            Keys    newkey;

            // Wait for key input
            if (gamepad)
            {
                throw new NotImplementedException("Gamepad support not implemented!");
            }
            else
            {
                Keys[] pressedKeys = CurrentKeyboardState.GetPressedKeys();
                if (pressedKeys.Length <= 0 ||
                    PreviousKeyboardState.IsKeyDown(pressedKeys[0]))
                {
                    return(false);
                }

                newkey = CurrentKeyboardState.GetPressedKeys()[0];

                if (IsKeyBound(newkey, key))
                {
                    return(false);
                }
            }

            switch (key)
            {
            case RebindableKeys.Action1:
                if (gamepad)
                {
                    GamepadAction = (Buttons)newbutton;
                }
                else
                {
                    KeyboardAction = (Keys)newkey;
                }
                break;

            case RebindableKeys.Action2:
                if (gamepad)
                {
                    GamepadAction2 = (Buttons)newbutton;
                }
                else
                {
                    KeyboardAction2 = (Keys)newkey;
                }
                break;

            case RebindableKeys.Action3:
                if (gamepad)
                {
                    GamepadAction3 = (Buttons)newbutton;
                }
                else
                {
                    KeyboardAction3 = (Keys)newkey;
                }
                break;

            case RebindableKeys.Up:
                if (gamepad)
                {
                    GamepadUp = (Buttons)newbutton;
                }
                else
                {
                    KeyboardUp = (Keys)newkey;
                }
                break;

            case RebindableKeys.Down:
                if (gamepad)
                {
                    GamepadDown = (Buttons)newbutton;
                }
                else
                {
                    KeyboardDown = (Keys)newkey;
                }
                break;

            case RebindableKeys.Left:
                if (gamepad)
                {
                    GamepadLeft = (Buttons)newbutton;
                }
                else
                {
                    KeyboardLeft = (Keys)newkey;
                }
                break;

            case RebindableKeys.Right:
                if (gamepad)
                {
                    GamepadRight = (Buttons)newbutton;
                }
                else
                {
                    KeyboardRight = (Keys)newkey;
                }
                break;

            case RebindableKeys.Pause:
                if (gamepad)
                {
                    GamepadPause = (Buttons)newbutton;
                }
                else
                {
                    KeyboardPause = (Keys)newkey;
                }
                break;

            case RebindableKeys.Inventory:
                if (gamepad)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    KeyboardInventory = (Keys)newkey;
                }
                break;

            case RebindableKeys.Map:
                if (gamepad)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    KeyboardMap = (Keys)newkey;
                }
                break;

            case RebindableKeys.Missions:
                if (gamepad)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    KeyboardMissions = (Keys)newkey;
                }
                break;

            case RebindableKeys.Help:
                if (gamepad)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    KeyboardHelp = (Keys)newkey;
                }
                break;
            }

            return(true);
        }
コード例 #2
0
        public static bool CheckHold(RebindableKeys key)
        {
            switch (key)
            {
            case RebindableKeys.Action1:
                if (GamepadReady)
                {
                    return(CurrentGamepadState.IsButtonDown(GamepadAction));
                }
                else
                {
                    return(CurrentKeyboardState.IsKeyDown(KeyboardAction));
                }

            case RebindableKeys.Action2:
                if (GamepadReady)
                {
                    return(CurrentGamepadState.IsButtonDown(GamepadAction2));
                }
                else
                {
                    return(CurrentKeyboardState.IsKeyDown(KeyboardAction2));
                }

            case RebindableKeys.Action3:
                if (GamepadReady)
                {
                    return(CurrentGamepadState.IsButtonDown(GamepadAction3));
                }
                else
                {
                    return(CurrentKeyboardState.IsKeyDown(KeyboardAction3));
                }

            case RebindableKeys.Up:
                if (GamepadReady)
                {
                    if (CurrentGamepadState.IsButtonDown(GamepadUp))
                    {
                        return(true);
                    }
                    else
                    {
                        return(CurrentGamepadState.IsButtonDown(Buttons.DPadUp));
                    }
                }
                else
                {
                    return(CurrentKeyboardState.IsKeyDown(KeyboardUp));
                }

            case RebindableKeys.Down:
                if (GamepadReady)
                {
                    if (CurrentGamepadState.IsButtonDown(GamepadDown))
                    {
                        return(true);
                    }
                    else
                    {
                        return(CurrentGamepadState.IsButtonDown(Buttons.DPadDown));
                    }
                }
                else
                {
                    return(CurrentKeyboardState.IsKeyDown(KeyboardDown));
                }

            case RebindableKeys.Left:
                if (GamepadReady)
                {
                    if (CurrentGamepadState.IsButtonDown(GamepadLeft))
                    {
                        return(true);
                    }
                    else
                    {
                        return(CurrentGamepadState.IsButtonDown(Buttons.DPadLeft));
                    }
                }
                else
                {
                    return(CurrentKeyboardState.IsKeyDown(KeyboardLeft));
                }

            case RebindableKeys.Right:
                if (GamepadReady)
                {
                    if (CurrentGamepadState.IsButtonDown(GamepadRight))
                    {
                        return(true);
                    }
                    else
                    {
                        return(CurrentGamepadState.IsButtonDown(Buttons.DPadRight));
                    }
                }
                else
                {
                    return(CurrentKeyboardState.IsKeyDown(KeyboardRight));
                }

            case RebindableKeys.Pause:
                if (GamepadReady)
                {
                    return(CurrentGamepadState.IsButtonDown(GamepadPause));
                }
                else
                {
                    return(CurrentKeyboardState.IsKeyDown(KeyboardPause));
                }

            case RebindableKeys.Inventory:
                if (GamepadReady)
                {
                    return(false);
                }
                else
                {
                    return(CurrentKeyboardState.IsKeyDown(KeyboardInventory));
                }

            case RebindableKeys.Map:
                if (GamepadReady)
                {
                    return(false);
                }
                else
                {
                    return(CurrentKeyboardState.IsKeyDown(KeyboardMap));
                }

            case RebindableKeys.Missions:
                if (GamepadReady)
                {
                    return(false);
                }
                else
                {
                    return(CurrentKeyboardState.IsKeyDown(KeyboardMissions));
                }

            case RebindableKeys.Help:
                if (GamepadReady)
                {
                    return(false);
                }
                else
                {
                    return(CurrentKeyboardState.IsKeyDown(KeyboardHelp));
                }

            default:
                return(false);
            }
        }
コード例 #3
0
        public static string GetKeyName(RebindableKeys key)
        {
            switch (key)
            {
            case RebindableKeys.Action1:
                if (GamepadReady)
                {
                    return(GamepadAction.ToString());
                }
                else
                {
                    return(KeyboardAction.ToString());
                }

            case RebindableKeys.Action2:
                if (GamepadReady)
                {
                    return(GamepadAction2.ToString());
                }
                else
                {
                    return(KeyboardAction2.ToString());
                }

            case RebindableKeys.Action3:
                if (GamepadReady)
                {
                    return(GamepadAction3.ToString());
                }
                else
                {
                    return(KeyboardAction3.ToString());
                }

            case RebindableKeys.Up:
                if (GamepadReady)
                {
                    return(GamepadUp.ToString());
                }
                else
                {
                    return(KeyboardUp.ToString());
                }

            case RebindableKeys.Down:
                if (GamepadReady)
                {
                    return(GamepadDown.ToString());
                }
                else
                {
                    return(KeyboardDown.ToString());
                }

            case RebindableKeys.Left:
                if (GamepadReady)
                {
                    return(GamepadLeft.ToString());
                }
                else
                {
                    return(KeyboardLeft.ToString());
                }

            case RebindableKeys.Right:
                if (GamepadReady)
                {
                    return(GamepadRight.ToString());
                }
                else
                {
                    return(KeyboardRight.ToString());
                }

            case RebindableKeys.Pause:
                if (GamepadReady)
                {
                    return(GamepadPause.ToString());
                }
                else
                {
                    return(KeyboardPause.ToString());
                }

            case RebindableKeys.Inventory:
                if (GamepadReady)
                {
                    return("I AM ERROR. GAMEPAD CONTROLS NOT IMPLEMENTED");
                }
                else
                {
                    return(KeyboardInventory.ToString());
                }

            case RebindableKeys.Map:
                if (GamepadReady)
                {
                    return("I AM ERROR. GAMEPAD CONTROLS NOT IMPLEMENTED");
                }
                else
                {
                    return(KeyboardMap.ToString());
                }

            case RebindableKeys.Missions:
                if (GamepadReady)
                {
                    return("I AM ERROR. GAMEPAD CONTROLS NOT IMPLEMENTED");
                }
                else
                {
                    return(KeyboardMissions.ToString());
                }

            case RebindableKeys.Help:
                if (GamepadReady)
                {
                    return("I AM ERROR. GAMEPAD CONTROLS NOT IMPLEMENTED");
                }
                else
                {
                    return(KeyboardHelp.ToString());
                }

            default:
                return("I AM ERROR");
            }
        }