bool HandleClicks(GamePadState now, GamePadState before) { if (GamePadHelper.IsShoulderPressed(now)) { return(false); } // Left click if (GamePadHelper.IsPressDown(now.Buttons.A, before.Buttons.A)) { _Input.Mouse.LeftButtonDown(); } else if (GamePadHelper.IsPressUp(now.Buttons.A, before.Buttons.A)) { _Input.Mouse.LeftButtonUp(); } // Right click if (GamePadHelper.IsPressDown(now.Buttons.B, before.Buttons.B)) { _Input.Mouse.RightButtonDown(); } else if (GamePadHelper.IsPressUp(now.Buttons.B, before.Buttons.B)) { _Input.Mouse.RightButtonUp(); } return(false); }
private int ComputeInput(GamePadHelper pad) { if (!pad.isSet || !pad.state.IsConnected) { return(0); } var state = pad.state; int i = 0; if (IsXInputUp(state)) { i |= 1 << (int)PadMenuInputState.Up; } if (IsXInputDown(state)) { i |= 1 << (int)PadMenuInputState.Down; } if (state.Buttons.A == ButtonState.Pressed) { i |= 1 << (int)PadMenuInputState.Confirm; } return(i); }
bool HandleGUI(GamePadState now, GamePadState before) { if (GamePadHelper.IsPressUp(now.Buttons.Back, before.Buttons.Back)) { _GC.IsHideUI = !_GC.IsHideUI; } return(false); }
private void Awake() { DontDestroyOnLoad(this.gameObject); for (int i = 0; i < gamePads.Length; i++) { gamePads[i] = new GamePadHelper(); } }
/// <summary> /// Inicializa uma nova instância da classe InputManager. /// </summary> public InputManager() { One = new GamePadHelper(PlayerIndex.One, null); Two = new GamePadHelper(PlayerIndex.Two, null); Three = new GamePadHelper(PlayerIndex.Three, null); Four = new GamePadHelper(PlayerIndex.Four, null); Keyboard = new KeyboardHelper(); Mouse = new MouseHelper(); }
/// <summary>Gets the input induced camera offset, based on mouse position or game pad state.</summary> /// <returns>The offset based on player input.</returns> private Vector2 GetInputInducedOffset() { Vector2 offset; offset.X = 0; offset.Y = 0; // Get viewport, for mouse position scaling and offset scaling. var viewport = _graphics.Viewport; var offsetScale = new Vector2(viewport.Width, viewport.Height).Length() / 6f; var inputManager = (InputManager)_services.GetService(typeof(InputManager)); var mouse = inputManager.GetMouse(); // If we have a game pad attached, get the stick tilt. if (Settings.Instance.EnableGamepad) { foreach (var gamepad in inputManager.GamePads) { if (gamepad.IsAttached) { offset = GamePadHelper.GetLook(gamepad); // Only use the first gamepad we can find. break; } } } else if (mouse != null) { // Otherwise use the mouse. var state = mouse.GetState(); // Get the relative position of the mouse to the ship and // apply some factoring to it (so that the maximum distance // of cursor to ship is not half the screen size). if (state.X >= 0 && state.X < viewport.Width) { offset.X = ((state.X / (float)viewport.Width) - 0.5f) * 2; } if (state.Y >= 0 && state.Y < viewport.Height) { offset.Y = ((state.Y / (float)viewport.Height) - 0.5f) * 2; } } // Normalize the vector. This way we get some 'dead area' when controlling with the mouse // in the corners of the screen (where the offset length won't change), but we get the same // effect as we'd get it with the game pad, keeping it fair in how far players can look. if (offset.LengthSquared() > 1) { offset.Normalize(); } return(XnaUnitConversion.ToSimulationUnits(offset * offsetScale)); }
bool HandleInput(GamePadState now, GamePadState before) { if (GamePadHelper.IsShoulderPressed(now)) { return(false); } if (_GC && _Scene && now.Buttons.LeftShoulder == ButtonState.Released && now.Buttons.RightShoulder == ButtonState.Released) { return(HandleGUI(now, before) || HandleSekkusu(now, before)); } return(false); }
bool HandleInput(GamePadState nowState, GamePadState prevState) { if (GamePadHelper.IsPressUp(nowState.Buttons.Start, prevState.Buttons.Start)) { Recenter(); } if (nowState.Buttons.LeftShoulder == ButtonState.Pressed) { Vector2 rightStick = new Vector2(nowState.ThumbSticks.Right.X, nowState.ThumbSticks.Right.Y); Vector2 leftStick = new Vector2(nowState.ThumbSticks.Left.X, nowState.ThumbSticks.Left.Y); if (rightStick.magnitude > 0.1f) { VR.Settings.Rotation += rightStick.x * Time.deltaTime * 50f; VR.Settings.OffsetY += rightStick.y * Time.deltaTime * 0.1f; } if (leftStick.magnitude > 0.1f) { VR.Settings.Distance += leftStick.x * Time.deltaTime * 0.1f; VR.Settings.Angle += leftStick.y * Time.deltaTime * 50f; } if (nowState.DPad.Up == ButtonState.Pressed) { VR.Settings.IPDScale += Time.deltaTime * 0.1f; } else if (nowState.DPad.Down == ButtonState.Pressed) { VR.Settings.IPDScale -= Time.deltaTime * 0.1f; } // Impersonate if (GamePadHelper.IsPressUp(nowState.Buttons.Y, prevState.Buttons.Y)) { if (LockTarget == null || !LockTarget.IsValid) { Impersonate(VR.Interpreter.Actors.FirstOrDefault()); } else { Impersonate(null); } } } return(false); }
bool HandleSekkusu(GamePadState now, GamePadState before) { // Speed if (GamePadHelper.IsPressUp(now.DPad.Up, before.DPad.Up)) { _Scene.Pad.ChangeSpeed(Mathf.Clamp(_Scene.Pad.speed + 0.6f, _Scene.Pad.SpeedMin, _Scene.Pad.SpeedMax)); } else if (GamePadHelper.IsPressUp(now.DPad.Down, before.DPad.Down)) { _Scene.Pad.ChangeSpeed(Mathf.Clamp(_Scene.Pad.speed - 0.6f, _Scene.Pad.SpeedMin, _Scene.Pad.SpeedMax)); } // Pose if (GamePadHelper.IsPressUp(now.DPad.Left, before.DPad.Left)) { ChangePose(-1); } else if (GamePadHelper.IsPressUp(now.DPad.Right, before.DPad.Right)) { ChangePose(1); } // Mode if (GamePadHelper.IsPressUp(now.Buttons.X, before.Buttons.X)) { ToggleGrind(); } if (GamePadHelper.IsPressUp(now.Buttons.Y, before.Buttons.Y)) { TogglePiston(); } // E*********n if (GamePadHelper.IsPressDown(now.Buttons.RightStick, before.Buttons.RightStick)) { E*******e(false); } if (GamePadHelper.IsPressDown(now.Buttons.LeftStick, before.Buttons.LeftStick)) { E*******e(true); } return(false); }
bool MoveCamera(GamePadState state, GamePadState prevState) { if (GamePadHelper.IsShoulderPressed(state)) { return(false); } if (_Camera) { var leftThumb = new Vector2(state.ThumbSticks.Left.X, state.ThumbSticks.Left.Y); var rightThumb = new Vector2(state.ThumbSticks.Right.X, state.ThumbSticks.Right.Y); bool leftTrigger = state.Triggers.Left > TRIGGER_THRESHOLD; bool rightTrigger = state.Triggers.Right > TRIGGER_THRESHOLD; if (leftTrigger || rightTrigger) { // Zoom _DistanceField.SetValue(_Camera, Mathf.Max(0.1f, _Camera.Distance - rightThumb.y * Time.deltaTime * 2)); _Messages.Enqueue(() => { _Camera.Rotate(new Vector3(0, -rightThumb.x, 0) * Time.deltaTime * 100); }); } if (leftTrigger) { // Pan 1 _Camera.Translate(leftThumb * Time.deltaTime * 100, false); } else if (rightTrigger) { // Pan 2 _Camera.Translate(new Vector3(leftThumb.x, 0, leftThumb.y) * Time.deltaTime * 100, false); } else { // Move _Messages.Enqueue(() => { _Camera.Rotate(new Vector3(rightThumb.y, -rightThumb.x, 0) * Time.deltaTime * 100); }); } } return(false); }
public override void Update(GameTime gameTime) { base.Update(gameTime); // Rescan input devices periodically, e.g. to accept newly connected gamepads. if ((DateTime.UtcNow - _lastInputDeviceScan).TotalSeconds > InputDeviceScanInterval) { AttachListeners(); _lastInputDeviceScan = DateTime.UtcNow; } // Disregard the rest if we're not connected. if (!IsConnected) { // Reset periodic update values. _accelerationDirection = Directions.None; _accelerationVector = Vector2.Zero; _accelerationChanged = DateTime.MinValue; _targetRotation = 0; _rotationChanged = DateTime.MinValue; _lastUpdate = DateTime.MinValue; return; } // Handle game pad input that we can't properly handle via events. if (Settings.Instance.EnableGamepad && _gamePad != null && _gamePad.IsAttached) { // Handle movement of the left stick, which controls our movement. var gamepadAcceleration = GamePadHelper.GetAcceleration(_gamePad); if (gamepadAcceleration != _previousGamepadAcceleration) { _accelerationVector = gamepadAcceleration; _accelerationChanged = DateTime.UtcNow; } _previousGamepadAcceleration = gamepadAcceleration; // Handle movement of the right stick, which controls our direction. var gamepadLook = GamePadHelper.GetLook(_gamePad); if (gamepadLook != _previousGamepadLook && gamepadLook != Vector2.Zero) { _targetRotation = (float)Math.Atan2(gamepadLook.Y, gamepadLook.X); _rotationChanged = DateTime.UtcNow; } _previousGamepadLook = gamepadLook; } // See if we want to re-orientate the ship and whether the acceleration // changed. Only check every so often, as slight delays here will not be // as noticeable, due to the ship's slow turn/acceleration speed. if ((DateTime.UtcNow - _lastUpdate).TotalMilliseconds > AnalogPollInterval) { // Has the mouse moved since the last update? if (_rotationChanged >= _lastUpdate) { // Yes, push command. BeginCommand(GameCommand.Rotate); } // Has the acceleration changed since the last update? if (_accelerationChanged >= _lastUpdate) { // Yes, push command. BeginCommand(GameCommand.Accelerate); } _lastUpdate = DateTime.UtcNow; } }
bool MoveMouse(GamePadState now, GamePadState before) { if (now.Triggers.Left < TRIGGER_THRESHOLD && now.Triggers.Right < TRIGGER_THRESHOLD && !GamePadHelper.IsShoulderPressed(now)) { // Move cursor _Input.Mouse.MoveMouseBy((int)(now.ThumbSticks.Left.X * Time.deltaTime * 700), (int)(-now.ThumbSticks.Left.Y * Time.deltaTime * 700)); } return(false); }