private void UpdateInput() { InputTwinState state = Game.InputState; Menu.Update(this); Menu.HandleInput(this); }
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; } }
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); }
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); }
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); }
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); }
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); }
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>(); } }
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); }