Exemple #1
0
        public bool HandleKeyboard(Keys key, ModifierState modifierState)
        {
            switch (key)
            {
            case Keys.Escape:
                GrimDank.Instance.Exit();
                return(true);
            }

            return(false);
        }
Exemple #2
0
        public bool HandleKeyboard(Keys key, ModifierState modifierState)
        {
            Direction dirToMove = Controls.Move(key);
            bool      handled   = true;

            if (dirToMove == Direction.NONE)
            {
                switch (key)
                {
                case Keys.Enter:
                    if (_targetValidator(TargetPos))     // CurrentPos is valid
                    {
                        InputStack.Remove(this);
                        GrimDank.Instance.TestLevel.Targeter = null;
                        _onTargetSelected(TargetPos);
                    }
                    else
                    {
                        MessageLog.Write("Invalid target.");
                    }

                    break;

                case Keys.Add:
                    // This works even if we started at -1.
                    if (_validTargets.Count != 0)
                    {
                        _currentTargetIndex = MathHelpers.WrapAround(_currentTargetIndex + 1, _validTargets.Count);
                        TargetPos           = _validTargets[_currentTargetIndex];
                    }
                    break;

                case Keys.Escape:
                    InputStack.Remove(this);
                    GrimDank.Instance.TestLevel.Targeter = null;
                    break;

                default:
                    handled = false;
                    break;
                }
            }
            // Here we purposely do NOT reset the _currentTargetIndex to -1, to preserve the starting point in case the user presses + sometime again
            // in the future (we pick up where we left off)
            else
            {
                TargetPos += dirToMove;
            }

            return(handled);
        }