public void Update(GameTime gameTime, PlayerIndex playerIndex) { if (Count == 0) { return; } foreach (Control c in this) { if (c.Enabled) { c.Update(gameTime); } if (c.HasFocus) { c.HandleInput(playerIndex); } } if (InputHandler.ButtonPressed(Buttons.LeftThumbstickUp, playerIndex) || InputHandler.ButtonPressed(Buttons.DPadUp, playerIndex) || InputHandler.KeyPressed(Keys.Up)) { PreviousControl(); } if (InputHandler.ButtonPressed(Buttons.LeftThumbstickDown, playerIndex) || InputHandler.ButtonPressed(Buttons.DPadDown, playerIndex) || InputHandler.KeyPressed(Keys.Down)) { NextControl(); } }
protected override void Update(GameTime gameTime) { if (InputHandler.KeyPressed(Keys.Escape) || InputHandler.ButtonPressed(Buttons.Back, PlayerIndex.One)) { Exit(); } base.Update(gameTime); }
public override void HandleInput(PlayerIndex playerIndex) { if (!HasFocus) { return; } if (InputHandler.KeyReleased(Keys.Enter) || InputHandler.ButtonPressed(Buttons.A, playerIndex)) { OnSelected(EventArgs.Empty); } }
protected override void Update(GameTime gameTime) { if (InputHandler.KeyPressed(Keys.F1) || InputHandler.ButtonPressed(Buttons.Start, PlayerIndex.One)) { Config.FullScreen = !Config.FullScreen; Graphics.IsFullScreen = Config.FullScreen; Graphics.ApplyChanges(); } base.Update(gameTime); }
public void Update(GameTime gameTime, PlayerIndex playerIndex) { if (Count == 0) { return; } foreach (Control c in this) { if (c.Enabled) { c.Update(gameTime); } if (c.HasFocus) { c.HandleInput(playerIndex); } else if ( InputHandler.CurrentMouseState.Y > c.Position.Y && InputHandler.CurrentMouseState.Y < c.Position.Y + c.SpriteFont.MeasureString(c.Text).Y&& InputHandler.CurrentMouseState.X > c.Position.X && InputHandler.CurrentMouseState.X < c.Position.X + c.SpriteFont.MeasureString(c.Text).X || InputHandler.CurrentGesture.Position.X > c.Position.X && InputHandler.CurrentGesture.Position.X < c.Position.X + SpriteFont.MeasureString(c.Text).X&& InputHandler.CurrentGesture.Position.Y > c.Position.Y && InputHandler.CurrentGesture.Position.Y < c.Position.Y + SpriteFont.MeasureString(c.Text).Y ) { SelectControl(c); } } if (InputHandler.ButtonPressed(Buttons.LeftThumbstickUp, playerIndex) || InputHandler.ButtonPressed(Buttons.DPadUp, playerIndex) || InputHandler.KeyPressed(Keys.Up) || InputHandler.TouchPressed() && InputHandler.CurrentGesture.GestureType == GestureType.Flick && InputHandler.CurrentGesture.Position.Y < InputHandler.LastGesture.Position.Y) { PreviousControl(); } if (InputHandler.ButtonPressed(Buttons.LeftThumbstickDown, playerIndex) || InputHandler.ButtonPressed(Buttons.DPadDown, playerIndex) || InputHandler.TouchPressed() && InputHandler.CurrentGesture.GestureType == GestureType.Flick && InputHandler.CurrentGesture.Position.Y > InputHandler.LastGesture.Position.Y || InputHandler.KeyPressed(Keys.Down)) { NextControl(); } }
/* The job of the Control Manager is to update and draw every control in the parent List<Control>. */ public void Update(GameTime gameTime, PlayerIndex playerIndex) { /* Obviously if there are no controls, no updating needs to be done, so the function returns. */ if (Count == 0) { return; } /* Every control with Enabled set to true will be updated. * Every control with HasFocus set to true will have input handled. */ foreach (Control c in this) { if (c.Enabled) { c.Update(gameTime); } if (c.HasFocus) { c.HandleInput(playerIndex); } } /* If the ControlManager is not currently accepting input, the function needs to stop now before it checks input. */ if (!acceptsInput) { return; } /* Otherwise, the CntrolManager checks the up and down arrow keys will switch between controls in the list. * To do this, it uses NextControl() and PreviousControl(), which are defined further down in the class. */ if (InputHandler.ButtonPressed(Buttons.LeftThumbstickUp, playerIndex) || InputHandler.ButtonPressed(Buttons.DPadUp, playerIndex) || InputHandler.KeyPressed(Keys.Up)) { PreviousControl(); } if (InputHandler.ButtonPressed(Buttons.LeftThumbstickDown, playerIndex) || InputHandler.ButtonPressed(Buttons.DPadDown, playerIndex) || InputHandler.KeyPressed(Keys.Down)) { NextControl(); } }
public override void Update(GameTime gameTime) { if (Bounds.Contains(InputHandler.MousePos)) { if (OnMouseIn != null) { OnMouseIn(this, null); } if (InputHandler.MouseButtonPressed(MouseButton.LeftButton)) { OnSelected(null); } } if (hasFocus) { if (InputHandler.ButtonPressed(Buttons.A, PlayerIndex.One) || InputHandler.ButtonPressed(Buttons.Start, PlayerIndex.One)) { OnSelected(null); } } }
//This is where we'll check for inputs for all players void Update() { #if !UNITY_EDITOR_OSX GamePadState testState; for (int i = 0; i < 4; i++) { PlayerIndex getIndex = (PlayerIndex)i; testState = GamePad.GetState (getIndex); if(testState.IsConnected){ prevState [i] = states [i]; states [i] = GamePad.GetState (getIndex); } } #endif //Only check if a button is actually being pressed or released if(ButtonPressed!=null) for (int i = 0; i < 4; i++) { //xInput section #if !UNITY_EDITOR_OSX PlayerIndex getIndex = (PlayerIndex)i; testState = GamePad.GetState (getIndex); if (testState.IsConnected) { if (prevState [i].Buttons.A == ButtonState.Released && states [i].Buttons.A == ButtonState.Pressed) { InputHandler.ButtonPressed (i, InputHandler.Buttons.a); } if (prevState [i].Buttons.B == ButtonState.Released && states [i].Buttons.B == ButtonState.Pressed) { InputHandler.ButtonPressed (i, InputHandler.Buttons.b); } if (prevState [i].Buttons.X == ButtonState.Released && states [i].Buttons.X == ButtonState.Pressed) { InputHandler.ButtonPressed (i, InputHandler.Buttons.x); } if (prevState [i].Buttons.Y == ButtonState.Released && states [i].Buttons.Y == ButtonState.Pressed) { InputHandler.ButtonPressed (i, InputHandler.Buttons.y); } } else { #else //Normal joystick support (only 1 player currently) if(i==0){ if(Input.GetKeyDown(KeyCode.JoystickButton16)){ InputHandler.ButtonPressed (i, InputHandler.Buttons.a); } if(Input.GetKeyDown(KeyCode.JoystickButton17)){ InputHandler.ButtonPressed (i, InputHandler.Buttons.b); } if(Input.GetKeyDown(KeyCode.JoystickButton18)){ InputHandler.ButtonPressed (i, InputHandler.Buttons.x); } if(Input.GetKeyDown(KeyCode.JoystickButton19)){ InputHandler.ButtonPressed (i, InputHandler.Buttons.y); } } #endif if (i == 0) { //Keyboard support if (Input.GetKeyDown ("a")) { InputHandler.ButtonPressed (i, InputHandler.Buttons.x); } if (Input.GetKeyDown ("s")) { InputHandler.ButtonPressed (i, InputHandler.Buttons.a); } if (Input.GetKeyDown ("d")) { InputHandler.ButtonPressed (i, InputHandler.Buttons.b); } if (Input.GetKeyDown ("w")) { InputHandler.ButtonPressed (i, InputHandler.Buttons.y); } } else if (i == 1) { if (Input.GetKeyDown ("f")) { InputHandler.ButtonPressed (i, InputHandler.Buttons.x); } if (Input.GetKeyDown ("g")) { InputHandler.ButtonPressed (i, InputHandler.Buttons.a); } if (Input.GetKeyDown ("h")) { InputHandler.ButtonPressed (i, InputHandler.Buttons.b); } if (Input.GetKeyDown ("t")) { InputHandler.ButtonPressed (i, InputHandler.Buttons.y); } } else if (i == 2) { if (Input.GetKeyDown ("j")) { InputHandler.ButtonPressed (i, InputHandler.Buttons.x); } if (Input.GetKeyDown ("k")) { InputHandler.ButtonPressed (i, InputHandler.Buttons.a); } if (Input.GetKeyDown ("l")) { InputHandler.ButtonPressed (i, InputHandler.Buttons.b); } if (Input.GetKeyDown ("i")) { InputHandler.ButtonPressed (i, InputHandler.Buttons.y); } } else { if (Input.GetKeyDown (KeyCode.Keypad4)) { InputHandler.ButtonPressed (i, InputHandler.Buttons.x); } if (Input.GetKeyDown (KeyCode.Keypad5)) { InputHandler.ButtonPressed (i, InputHandler.Buttons.a); } if (Input.GetKeyDown (KeyCode.Keypad6)) { InputHandler.ButtonPressed (i, InputHandler.Buttons.b); } if (Input.GetKeyDown (KeyCode.Keypad8)) { InputHandler.ButtonPressed (i, InputHandler.Buttons.y); } } #if !UNITY_EDITOR_OSX } #endif } if(ButtonReleased!=null) for (int i = 0; i < 4; i++) { //xInput section #if !UNITY_EDITOR_OSX PlayerIndex getIndex = (PlayerIndex)i; testState = GamePad.GetState (getIndex); if (testState.IsConnected) { if(prevState [i].Buttons.A == ButtonState.Pressed && states [i].Buttons.A == ButtonState.Released) { InputHandler.ButtonReleased (i, InputHandler.Buttons.a); } if(prevState [i].Buttons.B == ButtonState.Pressed && states [i].Buttons.B == ButtonState.Released) { InputHandler.ButtonReleased (i, InputHandler.Buttons.b); } if(prevState [i].Buttons.X == ButtonState.Pressed && states [i].Buttons.X == ButtonState.Released) { InputHandler.ButtonReleased (i, InputHandler.Buttons.x); } if(prevState [i].Buttons.Y == ButtonState.Pressed && states [i].Buttons.Y == ButtonState.Released) { InputHandler.ButtonReleased (i, InputHandler.Buttons.y); } } else { #else //Normal joystick support (only 1 player currently) if(i==0){ if(Input.GetKeyUp(KeyCode.JoystickButton16)){ InputHandler.ButtonReleased (i, InputHandler.Buttons.a); } if(Input.GetKeyUp(KeyCode.JoystickButton17)){ InputHandler.ButtonReleased (i, InputHandler.Buttons.b); } if(Input.GetKeyUp(KeyCode.JoystickButton18)){ InputHandler.ButtonReleased (i, InputHandler.Buttons.x); } if(Input.GetKeyUp(KeyCode.JoystickButton19)){ InputHandler.ButtonReleased (i, InputHandler.Buttons.y); } } #endif if (i == 0) { //Keyboard support if (Input.GetKeyUp ("a")) { InputHandler.ButtonReleased (i, InputHandler.Buttons.x); } if (Input.GetKeyUp ("s")) { InputHandler.ButtonReleased (i, InputHandler.Buttons.a); } if (Input.GetKeyUp ("d")) { InputHandler.ButtonReleased (i, InputHandler.Buttons.b); } if (Input.GetKeyUp ("w")) { InputHandler.ButtonReleased (i, InputHandler.Buttons.y); } } else if (i == 1) { if (Input.GetKeyUp ("f")) { InputHandler.ButtonReleased (i, InputHandler.Buttons.x); } if (Input.GetKeyUp ("g")) { InputHandler.ButtonReleased (i, InputHandler.Buttons.a); } if (Input.GetKeyUp ("h")) { InputHandler.ButtonReleased (i, InputHandler.Buttons.b); } if (Input.GetKeyUp ("t")) { InputHandler.ButtonReleased (i, InputHandler.Buttons.y); } } else if (i == 2) { if (Input.GetKeyUp ("j")) { InputHandler.ButtonReleased (i, InputHandler.Buttons.x); } if (Input.GetKeyUp ("k")) { InputHandler.ButtonReleased (i, InputHandler.Buttons.a); } if (Input.GetKeyUp ("l")) { InputHandler.ButtonReleased (i, InputHandler.Buttons.b); } if (Input.GetKeyUp ("i")) { InputHandler.ButtonReleased (i, InputHandler.Buttons.y); } } else { if (Input.GetKeyUp (KeyCode.Keypad4)) { InputHandler.ButtonReleased (i, InputHandler.Buttons.x); } if (Input.GetKeyUp (KeyCode.Keypad5)) { InputHandler.ButtonReleased (i, InputHandler.Buttons.a); } if (Input.GetKeyUp (KeyCode.Keypad6)) { InputHandler.ButtonReleased (i, InputHandler.Buttons.b); } if (Input.GetKeyUp (KeyCode.Keypad8)) { InputHandler.ButtonReleased (i, InputHandler.Buttons.y); } } #if !UNITY_EDITOR_OSX } #endif } }