From a1b59c9843e54f84d6ce69e41242bf752902ba2b Mon Sep 17 00:00:00 2001 From: Atilla Lonny Date: Sun, 25 Sep 2022 19:15:57 -0400 Subject: [PATCH] Fix dragged inventory item from being rendered prematurely --- .../HUD/Inventory/InventoryPanelItem.cs | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/EndlessClient/HUD/Inventory/InventoryPanelItem.cs b/EndlessClient/HUD/Inventory/InventoryPanelItem.cs index 667c7a50f..06ba3e9c1 100644 --- a/EndlessClient/HUD/Inventory/InventoryPanelItem.cs +++ b/EndlessClient/HUD/Inventory/InventoryPanelItem.cs @@ -48,9 +48,10 @@ public class ItemDragCompletedEventArgs // Ru Paul's drag properties private bool _beingDragged; private Vector2 _oldOffset; + private bool dragItemPositioned; private bool MousePressed => CurrentMouseState.LeftButton == ButtonState.Pressed && PreviousMouseState.LeftButton == ButtonState.Released; - + private bool MouseReleased => CurrentMouseState.LeftButton == ButtonState.Released && PreviousMouseState.LeftButton == ButtonState.Pressed; private bool MouseHeld => CurrentMouseState.LeftButton == ButtonState.Pressed && PreviousMouseState.LeftButton == ButtonState.Pressed; @@ -216,6 +217,7 @@ protected override void OnUpdateControl(GameTime gameTime) else DrawPosition = GetPosition(Slot); + dragItemPositioned = false; _beingDragged = false; _nameLabel.Visible = false; } @@ -229,6 +231,7 @@ protected override void OnDrawControl(GameTime gameTime) { _spriteBatch.Begin(); + // draw highlighted area if (MouseOver) { if (!_beingDragged || InventoryGridArea.Contains(CurrentMouseState.Position)) @@ -244,10 +247,36 @@ protected override void OnDrawControl(GameTime gameTime) } } - _spriteBatch.Draw(_itemGraphic, DrawPositionWithParentOffset, Color.FromNonPremultiplied(255, 255, 255, _beingDragged ? 128 : 255)); + if (_beingDragged) + { + // slot based on current mouse position if being dragged + var currentSlot = GetCurrentSlotBasedOnPosition(); + var drawPosition = GetPosition(currentSlot) + (_beingDragged ? _oldOffset : ImmediateParent.DrawPositionWithParentOffset); - _spriteBatch.End(); + if (!dragItemPositioned) + { + if (InventoryGridArea.Contains(DrawArea.WithPosition(drawPosition))) + { + dragItemPositioned = true; + } + } + if (dragItemPositioned) + { + _spriteBatch.Draw(_itemGraphic, DrawPositionWithParentOffset, Color.FromNonPremultiplied(255, 255, 255, _beingDragged ? 128 : 255)); + } + + if (InventoryGridArea.Contains(DrawArea.WithPosition(drawPosition))) + { + _spriteBatch.Draw(_itemGraphic, _beingDragged ? (DrawPositionWithParentOffset) : DrawPositionWithParentOffset, Color.FromNonPremultiplied(255, 255, 255, _beingDragged ? 128 : 255)); + } + } + else + { + _spriteBatch.Draw(_itemGraphic, _beingDragged ? (DrawPositionWithParentOffset) : DrawPositionWithParentOffset, Color.FromNonPremultiplied(255, 255, 255, _beingDragged ? 128 : 255)); + } + + _spriteBatch.End(); base.OnDrawControl(gameTime); } @@ -273,7 +302,7 @@ private void UpdateNameLabelPosition() if (actualPosition.X + _nameLabel.DrawAreaWithParentOffset.Width + DrawArea.Width > InventoryGridArea.Width) { - _nameLabel.DrawPosition = new Vector2(actualPosition.X -_nameLabel.DrawArea.Width, actualPosition.Y); + _nameLabel.DrawPosition = new Vector2(actualPosition.X - _nameLabel.DrawArea.Width, actualPosition.Y); } else {