/// <summary> /// Get the value as a boolean /// </summary> public bool GetValue(KeyboardMouseState inputState) { if (!inputState.WindowFocused) { return(false); } if (usemouse) { switch (mouse) { case MouseInput.LeftButton: return(inputState.MouseState.LeftButton == ButtonState.Pressed); case MouseInput.MiddleButton: return(inputState.MouseState.MiddleButton == ButtonState.Pressed); case MouseInput.RightButton: return(inputState.MouseState.RightButton == ButtonState.Pressed); case MouseInput.XButton1: return(inputState.MouseState.XButton1 == ButtonState.Pressed); case MouseInput.XButton2: return(inputState.MouseState.XButton2 == ButtonState.Pressed); } throw new ArgumentException(); } else { return(inputState.KeyboardState.IsKeyDown(key)); } }
/// <summary> /// Get the value as a float /// </summary> public float GetValue(KeyboardMouseState inputState, bool invert) { KeyboardState ks = inputState.KeyboardState; if (ks.IsKeyDown(key)) { if (invert) { return(-1); } return(1); } return(0); }
/// <summary> /// Override this method to change how raw keyboard and mouse input values are translated to a <see cref="InputState"/> object /// </summary> /// <param name="gameState"></param> /// <param name="state">structure to write input state values</param> /// <param name="inputState">stores raw keyboard state</param> /// <param name="mapping">stores the current mapped input values</param> protected virtual void UpdateState(UpdateState gameState, InputState state, KeyboardMouseState inputState, KeyboardMouseControlMapping mapping) { long tick = gameState.TotalTimeTicks; state.buttons.a.SetState(mapping.A.GetValue(inputState), tick); state.buttons.b.SetState(mapping.B.GetValue(inputState), tick); state.buttons.x.SetState(mapping.X.GetValue(inputState), tick); state.buttons.y.SetState(mapping.Y.GetValue(inputState), tick); state.buttons.dpadD.SetState(mapping.DpadDown.GetValue(inputState), tick); state.buttons.dpadU.SetState(mapping.DpadUp.GetValue(inputState), tick); state.buttons.dpadL.SetState(mapping.DpadLeft.GetValue(inputState), tick); state.buttons.dpadR.SetState(mapping.DpadRight.GetValue(inputState), tick); state.buttons.shoulderL.SetState(mapping.LeftShoulder.GetValue(inputState), tick); state.buttons.shoulderR.SetState(mapping.RightShoulder.GetValue(inputState), tick); state.buttons.back.SetState(mapping.Back.GetValue(inputState), tick); state.buttons.start.SetState(mapping.Start.GetValue(inputState), tick); state.buttons.leftStickClick.SetState(mapping.LeftStickClick.GetValue(inputState), tick); state.buttons.rightStickClick.SetState(mapping.RightStickClick.GetValue(inputState), tick); state.triggers.leftTrigger = mapping.LeftTrigger.GetValue(inputState, false); state.triggers.rightTrigger = mapping.RightTrigger.GetValue(inputState, false); Vector2 v = new Vector2(); v.Y = mapping.LeftStickForward.GetValue(inputState, false) + mapping.LeftStickBackward.GetValue(inputState, true); v.X = mapping.LeftStickLeft.GetValue(inputState, true) + mapping.LeftStickRight.GetValue(inputState, false); state.sticks.leftStick = v; v.Y = mapping.RightStickForward.GetValue(inputState, false) + mapping.RightStickBackward.GetValue(inputState, true); v.X = mapping.RightStickLeft.GetValue(inputState, true) + mapping.RightStickRight.GetValue(inputState, false); state.sticks.rightStick = v; }
/// <summary> /// Get the value as a boolean /// </summary> public bool GetValue(KeyboardMouseState inputState) { return(inputState.KeyboardState.IsKeyDown(key)); }
/// <summary> /// Get the value as a float /// </summary> public float GetValue(KeyboardMouseState inputState, bool invert) { if (!inputState.WindowFocused) { return(0); } KeyboardState ks = inputState.KeyboardState; MouseState ms = inputState.MouseState; if (usemouse) { float val = 0; switch (mouse) { case MouseInput.LeftButton: val = ms.LeftButton == ButtonState.Pressed ? 1 : 0; break; case MouseInput.MiddleButton: val = ms.MiddleButton == ButtonState.Pressed ? 1 : 0; break; case MouseInput.RightButton: val = ms.RightButton == ButtonState.Pressed ? 1 : 0; break; case MouseInput.ScrollWheel: if (invert) { return(0); } val = ms.ScrollWheelValue / 640.0f; break; case MouseInput.XButton1: val = ms.XButton1 == ButtonState.Pressed ? 1 : 0; break; case MouseInput.XButton2: val = ms.XButton2 == ButtonState.Pressed ? 1 : 0; break; case MouseInput.XAxis: if (invert) { return(0); } val = (ms.X - inputState.MousePositionPrevious.X) / 8.0f; break; case MouseInput.YAxis: if (invert) { return(0); } val = (ms.Y - inputState.MousePositionPrevious.Y) / -8.0f; break; } if (invert) { return(-val); } return(val); } else { if (ks.IsKeyDown(key)) { if (invert) { return(-1); } return(1); } return(0); } }