public void Update() { if (GameServices.GetService<ShroomGame>().IsActive) { this._lastState = this._state; this._state = Mouse.GetState(); this._lastPosition = new Vector2(GameServices.GetService<GraphicsDevice>().Viewport.Width / 2, GameServices.GetService<GraphicsDevice>().Viewport.Height / 2); this._currentPosition = new Vector2(this._state.X, this._state.Y); if(ShroomGame.actualGameState != GameState.Dead && ShroomGame.actualGameState != GameState.MainMenu && ShroomGame.actualGameState != GameState.Options && ShroomGame.actualGameState != GameState.Credits) { Mouse.SetPosition(GameServices.GetService<GraphicsDevice>().Viewport.Width / 2, GameServices.GetService<GraphicsDevice>().Viewport.Height / 2); } this.ScrollTotal = this._state.ScrollWheelValue; this.ScrollValue = this._state.ScrollWheelValue - this._lastState.ScrollWheelValue; if (this.ScrollValue != 0) //To podobnie jak wyżej { Scroll?.Invoke(this.ScrollValue); } foreach (var key in this._keys.Keys) { switch (key) { case SupportedMouseButtons.Left: this[key].Update(this._state.LeftButton == ButtonState.Pressed); break; case SupportedMouseButtons.Right: this[key].Update(this._state.RightButton == ButtonState.Pressed); break; case SupportedMouseButtons.Middle: this[key].Update(this._state.MiddleButton == ButtonState.Pressed); break; default: break; } if (this[key].WasPressed) { WasPressed?.Invoke(this[key]); } else if (this[key].WasReleased) { WasReleased?.Invoke(this[key]); } } } }
public void Update(Vector2 containerPos) { _tile.Update(); if (SlotRectangle == new Rectangle(0, 0, 0, 0)) { SlotRectangle = DrawRectangle; } _containerPosition = containerPos; if (!_isBeingMoved && !_isReturningToDefaultPos && !_isSteppingAside) { SetPosition(DefaultPosition); } if (_isReturningToDefaultPos) { if (!IsMovingToNewPosition) { _isReturningToDefaultPos = false; } } if (_isBeingMoved) { Inventory.IsMovingTile = true; Rectangle mouse = InputSystem.GetMouseInUi(); SetPosition(mouse.X - (int)_mouseDifferential.X, mouse.Y - (int)_mouseDifferential.Y); if (InputSystem.IsLeftMousePressed() && _wasMouseReleased) { _wasMouseReleased = false; ReturnToDefaultPosition(); _isBeingMoved = false; Inventory.IsMovingTile = false; HotBar.ReplaceHotBar(this); WasReleased?.Invoke(this); } } if (InputSystem.IsLeftMouseReleased()) { _wasMouseReleased = true; } }
public void Update() { this._state = Keyboard.GetState(); foreach (var key in this._keys.Keys) { this[key].Update(this._state.IsKeyDown(key)); if (this[key].WasPressed) { WasPressed?.Invoke(this[key]); } else if (this[key].WasReleased) { WasReleased?.Invoke(this[key]); } } }