public void AddInput(ControllerInputId button, float value) { InputSummary inputSummary; if (!_stats.TryGetValue(button, out inputSummary)) { inputSummary = new InputSummary(); _stats.Add(button, inputSummary); } inputSummary.AddInput(value); }
private bool IsPressed(GamePadState gpState, ControllerInputId button) { switch (button) { case ControllerInputId.A: return(gpState.Buttons.A == ButtonState.Pressed); case ControllerInputId.B: return(gpState.Buttons.B == ButtonState.Pressed); case ControllerInputId.X: return(gpState.Buttons.X == ButtonState.Pressed); case ControllerInputId.Y: return(gpState.Buttons.Y == ButtonState.Pressed); case ControllerInputId.LStick: return(gpState.Buttons.LeftStick == ButtonState.Pressed); case ControllerInputId.RStick: return(gpState.Buttons.RightStick == ButtonState.Pressed); case ControllerInputId.LShoulder: return(gpState.Buttons.LeftShoulder == ButtonState.Pressed); case ControllerInputId.RShoulder: return(gpState.Buttons.RightShoulder == ButtonState.Pressed); case ControllerInputId.DPadUp: return(gpState.DPad.Up == ButtonState.Pressed); case ControllerInputId.DPadDown: return(gpState.DPad.Down == ButtonState.Pressed); case ControllerInputId.DPadLeft: return(gpState.DPad.Left == ButtonState.Pressed); case ControllerInputId.DPadRight: return(gpState.DPad.Right == ButtonState.Pressed); case ControllerInputId.Start: return(gpState.Buttons.Start == ButtonState.Pressed); case ControllerInputId.Back: return(gpState.Buttons.Back == ButtonState.Pressed); case ControllerInputId.LTrigger: return(gpState.Triggers.Left >= TriggerThreshold); case ControllerInputId.RTrigger: return(gpState.Triggers.Right >= TriggerThreshold); //Using thumbsticks as buttons is not common, but it would be nice not to ignore them case ControllerInputId.LJoystick: return(gpState.ThumbSticks.Left.X >= Deadzone || gpState.ThumbSticks.Left.Y >= Deadzone); case ControllerInputId.RJoystick: return(gpState.ThumbSticks.Right.X >= Deadzone || gpState.ThumbSticks.Right.Y >= Deadzone); default: return(false); } }
private (short, short) GetStick(ControllerInputId stickInputId) { if (stickInputId < ControllerInputId.Axis0 || stickInputId > ControllerInputId.Axis5) { return(0, 0); } JoystickState jsState = Joystick.GetState(Index); int xAxis = stickInputId - ControllerInputId.Axis0; float xValue = jsState.GetAxis(xAxis); float yValue = 0 - jsState.GetAxis(xAxis + 1); // Invert Y-axis return(ApplyDeadzone(new Vector2(xValue, yValue))); }
private (short, short) GetStick(ControllerInputId joystick) { GamePadState gpState = GamePad.GetState(Index); switch (joystick) { case ControllerInputId.LJoystick: return(ApplyDeadzone(gpState.ThumbSticks.Left)); case ControllerInputId.RJoystick: return(ApplyDeadzone(gpState.ThumbSticks.Right)); default: return(0, 0); } }
private (short, short) GetStick(ControllerInputId stickXInputId, ControllerInputId stickYInputId, float deadzone) { if (stickXInputId < ControllerInputId.Axis0 || stickXInputId > ControllerInputId.Axis5 || stickYInputId < ControllerInputId.Axis0 || stickYInputId > ControllerInputId.Axis5) { return(0, 0); } JoystickState jsState = Joystick.GetState(_config.Index); int xAxis = stickXInputId - ControllerInputId.Axis0; int yAxis = stickYInputId - ControllerInputId.Axis0; float xValue = jsState.GetAxis(xAxis); float yValue = -jsState.GetAxis(yAxis); // Invert Y-axis return(ApplyDeadzone(new Vector2(xValue, yValue), deadzone)); }
private bool IsActivated(JoystickState joystickState, ControllerInputId controllerInputId) { if (controllerInputId <= ControllerInputId.Button20) { return(joystickState.IsButtonDown((int)controllerInputId)); } else if (controllerInputId <= ControllerInputId.Axis5) { int axis = controllerInputId - ControllerInputId.Axis0; return(joystickState.GetAxis(axis) > TriggerThreshold); } else if (controllerInputId <= ControllerInputId.Hat2Right) { int hat = (controllerInputId - ControllerInputId.Hat0Up) / 4; int baseHatId = (int)ControllerInputId.Hat0Up + (hat * 4); JoystickHatState hatState = joystickState.GetHat((JoystickHat)hat); if (hatState.IsUp && ((int)controllerInputId % baseHatId == 0)) { return(true); } if (hatState.IsDown && ((int)controllerInputId % baseHatId == 1)) { return(true); } if (hatState.IsLeft && ((int)controllerInputId % baseHatId == 2)) { return(true); } if (hatState.IsRight && ((int)controllerInputId % baseHatId == 3)) { return(true); } } return(false); }
private static bool IsAnyButtonPressed(out ControllerInputId pressedButton, int index, double triggerThreshold) { JoystickState joystickState = Joystick.GetState(index); JoystickCapabilities joystickCapabilities = Joystick.GetCapabilities(index); //Buttons for (int i = 0; i != joystickCapabilities.ButtonCount; i++) { if (joystickState.IsButtonDown(i)) { Enum.TryParse($"Button{i}", out pressedButton); return(true); } } //Axis for (int i = 0; i != joystickCapabilities.AxisCount; i++) { if (joystickState.GetAxis(i) > 0.5f && joystickState.GetAxis(i) > triggerThreshold) { Enum.TryParse($"Axis{i}", out pressedButton); return(true); } } //Hats for (int i = 0; i != joystickCapabilities.HatCount; i++) { JoystickHatState hatState = joystickState.GetHat((JoystickHat)i); string pos = null; if (hatState.IsUp) { pos = "Up"; } if (hatState.IsDown) { pos = "Down"; } if (hatState.IsLeft) { pos = "Left"; } if (hatState.IsRight) { pos = "Right"; } if (pos == null) { continue; } Enum.TryParse($"Hat{i}{pos}", out pressedButton); return(true); } pressedButton = ControllerInputId.Unbound; return(false); }