Exemplo n.º 1
0
 public bool RemoveReleasedInputCommand(int input)
 {
     if (ReleasedInputToCommandMap.ContainsKey(input))
     {
         ReleasedInputToCommandMap.Remove(input);
         return(true);
     }
     return(false);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Executes the commands associated with all keyboard inputs received
        /// since this method was last called.
        /// </summary>
        public override void UpdateAndExecuteInputs()
        {
            KeyboardState currentState = Keyboard.GetState();

            foreach (Keys key in lastState.GetPressedKeys())
            {
                ICommand command = null;
                if (currentState.IsKeyUp(key))
                {
                    if ((command == null) && ReleasedInputToCommandMap.TryGetValue((int)key, out command))
                    {
                        command.InvokeCommand();
                    }
                }
            }

            foreach (Keys key in currentState.GetPressedKeys())
            {
                ICommand command = null;
                if (lastState.IsKeyUp(key))
                {
                    foreach (Modifier mod in Enum.GetValues(typeof(Modifier)))
                    {
                        if (currentState.IsKeyDown((Keys)mod))
                        {
                            //if a modifier is being held, it should block other kinds of commands
                            //this guarantees that the null check fails when it tries to run a regular command
                            command = new DummyCommand(new DummyClass());
                            if (inputChordToCommandMap.TryGetValue((int)mod, out Dictionary <int, ICommand> temp))
                            {
                                if (temp.TryGetValue((int)key, out command))
                                {
                                    command.InvokeCommand();
                                    break;
                                }
                                else
                                {
                                    //needs to be set here too, if it makes it in here but trygetvalue fails, because
                                    //trygetvalue will set it back to null;
                                    command = new DummyCommand(new DummyClass());
                                }
                            }
                        }
                    }
                    if ((command == null) && InputToCommandMap.TryGetValue((int)key, out command))
                    {
                        command.InvokeCommand();
                    }
                }
                if ((command == null) && HeldInputToCommandMap.TryGetValue((int)key, out command))
                {
                    command.InvokeCommand();
                }
            }

            lastState = currentState;
        }
Exemplo n.º 3
0
 public bool AddReleasedInputCommand(int input, ICommand command)
 {
     if (!ReleasedInputToCommandMap.ContainsKey(input))
     {
         ReleasedInputToCommandMap.Add(input, command);
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Executes the commands associated with all gamepad inputs received
        /// since this method was last called, if the gamepad is connected.
        /// </summary>
        public override void UpdateAndExecuteInputs()
        {
            GamePadState currentState = GamePad.GetState(player);

            Buttons[] buttonList = (Buttons[])Enum.GetValues(typeof(Buttons));

            foreach (Buttons button in buttonList)
            {
                if (lastState.IsButtonDown(button))
                {
                    ICommand command = null;
                    if (currentState.IsButtonUp(button))
                    {
                        if ((command == null) && ReleasedInputToCommandMap.TryGetValue((int)button, out command))
                        {
                            command.InvokeCommand();
                        }
                    }
                }
            }

            if (currentState.IsConnected)
            {
                foreach (Buttons button in buttonList)
                {
                    if (lastState.IsButtonUp(button) && currentState.IsButtonDown(button))
                    {
                        if (InputToCommandMap.TryGetValue((int)(button), out ICommand command))
                        {
                            command.InvokeCommand();
                        }
                    }
                }
            }
            lastState = currentState;
        }