Exemple #1
0
        private void UpdateInput()
        {
            InputTwinState state = Game.InputState;

            Menu.Update(this);
            Menu.HandleInput(this);
        }
Exemple #2
0
        public IEnumerator <InputTwinState> InputIterator()
        {
            InputState     previous   = new InputState();
            InputTwinState twinState  = null;
            StringBuilder  textBuffer = new StringBuilder();

            Window.TextInput += (sender, e) =>
            {
                textBuffer.Append(e.Character);
            };

            while (true)
            {
                var keyboard = Keyboard.GetState();
                var mouse    = Mouse.GetState();
                var gamepad  = GamePad.GetState(0);

                InputState next = new InputState(keyboard, mouse, gamepad, textBuffer.ToString());
                twinState = new InputTwinState(previous, next, twinState);
                twinState.HandleRepeats();
                textBuffer.Clear();
                yield return(twinState);

                previous = next;
            }
        }
Exemple #3
0
 public static Point?GetDirectionPressed(this IDictionary <Keys, Point> map, InputTwinState state, int repeatStart, int repeatStep)
 {
     if (map.Any(x => state.IsKeyPressed(x.Key, repeatStart, repeatStep)))
     {
         return(GetDirectionDown(map, state));
     }
     return(null);
 }
Exemple #4
0
        public static Point?GetDirectionNumpadPressed(InputTwinState state, int repeatStart, int repeatStep)
        {
            var result = NumpadKeys.Where(x => state.IsKeyPressed(x.Key, repeatStart, repeatStep)).Select(x => x.Value);

            if (result.Count() == 1)
            {
                return(result.Single());
            }
            return(null);
        }
Exemple #5
0
        public static Point?GetDirectionNumpadDown(InputTwinState state)
        {
            var result = NumpadKeys.Where(x => state.IsKeyDown(x.Key)).Select(x => x.Value);

            if (result.Count() == 1)
            {
                return(result.Single());
            }
            return(null);
        }
Exemple #6
0
        public static int?GetNumberPressed(this IDictionary <Keys, int> map, InputTwinState state, int repeatStart, int repeatStep)
        {
            var result = map.Where(x => state.IsKeyPressed(x.Key, repeatStart, repeatStep)).Select(x => x.Value);

            if (result.Count() == 1)
            {
                return(result.Single());
            }
            return(null);
        }
Exemple #7
0
        public static int?GetNumberDown(this IDictionary <Keys, int> map, InputTwinState state)
        {
            var result = map.Where(x => state.IsKeyDown(x.Key)).Select(x => x.Value);

            if (result.Count() == 1)
            {
                return(result.Single());
            }
            return(null);
        }
Exemple #8
0
 public InputTwinState(InputState previous, InputState next, InputTwinState old)
 {
     Previous = previous;
     Next     = next;
     if (old != null)
     {
         KeyRepeats    = old.KeyRepeats;
         ButtonRepeats = old.ButtonRepeats;
     }
     else
     {
         KeyRepeats    = new Dictionary <Keys, KeyRepeat>();
         ButtonRepeats = new Dictionary <Buttons, KeyRepeat>();
     }
 }
Exemple #9
0
        public static Point?GetDirectionDown(this IDictionary <Keys, Point> map, InputTwinState state)
        {
            var shift  = state.IsKeyDown(Keys.LeftShift);
            var result = map.Where(x => state.IsKeyDown(x.Key)).Select(x => x.Value);

            if (result.Count() < 2 && shift)
            {
                return(null);
            }
            var direction = result.Aggregate(Point.Zero, (a, b) => a + b);

            if (direction == Point.Zero)
            {
                return(null);
            }
            return(direction);
        }