/// <summary> /// Links an analog button to the axis /// </summary> /// <param name="button">Analog button</param> /// <param name="priority">Priority of the button</param> public void AddAnalogButton(AbstractButton button, short priority) { if (button.Type != ButtonType.Analog) throw new ArgumentException("Provided button is not analog"); AxisBinding binding = new AxisBinding(button, priority); _hardwareButtons.Add(binding); _hardwareButtons.Sort(AxisBinding.Comparison); }
/// <summary> /// Updates one gamepad state /// </summary> internal void Update() { _previousState = _currentState; _currentState = XnaGamePad.GetState(_gamePadIndex); if (!_previousState.IsConnected) { if (_currentState.IsConnected) { if (Connected != null) Connected(this, new GamePadEventArgs(this)); } } else { if (!_currentState.IsConnected) { if (Disconnected != null) Disconnected(this, new GamePadEventArgs(this)); } } if (!_currentState.IsConnected) return; GamePadThumbSticks prevThumb = _previousState.ThumbSticks; GamePadThumbSticks currThumb = _currentState.ThumbSticks; _thumbRightDelta = Vector2.Subtract(currThumb.Right, prevThumb.Right); _thumbLeftDelta = Vector2.Subtract(currThumb.Left, prevThumb.Left); GamePadTriggers prevTrigger = _previousState.Triggers; GamePadTriggers currTrigger = _currentState.Triggers; _triggerRightDelta = currTrigger.Right - prevTrigger.Right; _triggerLeftDelta = currTrigger.Left - prevTrigger.Left; InternalButtonPressed.Clear(); for (short i = 0; i < AllDigital.Length; i++) { if(_currentState.IsButtonUp(AllDigital[i])) continue; AbstractButton btn = new AbstractButton(AllDigital[i]); InternalButtonPressed.Add(new ButtonEvent(btn, (short)_gamePadIndex)); } }
/// <summary> /// Links two digital button to the axis /// </summary> /// <param name="negative">Button used to go in negative range</param> /// <param name="positive">Button used to go in positive range</param> /// <param name="priority">Priority of the button</param> public void AddDigitalButton(AbstractButton negative, AbstractButton positive, short priority) { if((negative.Type != ButtonType.Digital)) throw new ArgumentException("Negative button is not digital"); if ((positive.Type != ButtonType.Digital)) throw new ArgumentException("Positive button is not digital"); AxisBinding binding = new AxisBinding(negative, positive, priority); _hardwareButtons.Add(binding); _hardwareButtons.Sort(AxisBinding.Comparison); }
/// <summary> /// Constructor of AxisBinding class /// </summary> /// <param name="negative">Button used to go in negative range</param> /// <param name="positive">Button used to go in positive range</param> /// <param name="priority">Priority of the button</param> internal AxisBinding(AbstractButton negative, AbstractButton positive, short priority) { Negative = negative; Positive = positive; _priority = priority; }
/// <summary> /// Links a real button to the virtual button /// </summary> /// <param name="btn">Button instance</param> /// <param name="priority">Priority of the button</param> public void AddButton(AbstractButton btn, short priority) { ButtonBinding binding = new ButtonBinding(btn, priority); _hardwareButtons.Add(binding); _hardwareButtons.Sort(ButtonBinding.Comparison); }
/// <summary> /// Constructor of ButtonBinding class /// </summary> /// <param name="btn">Button instance</param> /// <param name="priority">Priority of the button</param> internal ButtonBinding(AbstractButton btn, short priority) { Button = btn; _priority = priority; }
/// <summary> /// Update mouse states /// </summary> internal static void Update() { _previousState = _currentState; _currentState = XnaMouse.GetState(); _previousPosition = new Vector2(_previousState.X, _previousState.Y); _currentPosition = new Vector2(_currentState.X, _currentState.Y); Vector2.Subtract(ref _currentPosition, ref _previousPosition, out _positionDelta); WheelDelta = _currentState.ScrollWheelValue - _previousState.ScrollWheelValue; InternalButtonPressed.Clear(); for (int i = 0; i < AllDigital.Length; i++) { if(IsUp(AllDigital[i])) continue; AbstractButton btn = new AbstractButton(AllDigital[i]); InternalButtonPressed.Add(new ButtonEvent(btn)); } }
/// <summary> /// Updates keyboard states /// </summary> internal static void Update() { _previousState = _currentState; _currentState = XnaKeyboard.GetState(); InternalButtonPressed.Clear(); for (int i = 0; i < AllDigital.Length; i++) { if (_currentState.IsKeyUp(AllDigital[i])) continue; AbstractButton btn = new AbstractButton(AllDigital[i]); InternalButtonPressed.Add(new ButtonEvent(btn)); } }