Skip to content

Commit

Permalink
Merge pull request #229 from miou-gh/fix-inventory-drag-item
Browse files Browse the repository at this point in the history
Fix dragged inventory item from being rendered prematurely
  • Loading branch information
ethanmoffat committed Sep 28, 2022
2 parents b21ab37 + 3c7d3c9 commit c8223d4
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions EndlessClient/HUD/Inventory/InventoryPanelItem.cs
Expand Up @@ -48,9 +48,10 @@ public class ItemDragCompletedEventArgs
// Ru Paul's drag properties
private bool _beingDragged;
private Vector2 _oldOffset;
private bool _dragPositioned;

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;
Expand Down Expand Up @@ -216,6 +217,7 @@ protected override void OnUpdateControl(GameTime gameTime)
else
DrawPosition = GetPosition(Slot);

_dragPositioned = false;
_beingDragged = false;
_nameLabel.Visible = false;
}
Expand All @@ -229,6 +231,7 @@ protected override void OnDrawControl(GameTime gameTime)
{
_spriteBatch.Begin();

// draw highlighted area
if (MouseOver)
{
if (!_beingDragged || InventoryGridArea.Contains(CurrentMouseState.Position))
Expand All @@ -238,16 +241,28 @@ protected override void OnDrawControl(GameTime gameTime)
var drawPosition = GetPosition(currentSlot) + (_beingDragged ? _oldOffset : ImmediateParent.DrawPositionWithParentOffset);

if (InventoryGridArea.Contains(DrawArea.WithPosition(drawPosition)))
{
_spriteBatch.Draw(_highlightBackground, DrawArea.WithPosition(drawPosition), Color.White);
}
}
}

_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) + _oldOffset;

_spriteBatch.End();
if (!_dragPositioned)
_dragPositioned = InventoryGridArea.Contains(DrawArea.WithPosition(drawPosition));

if (_dragPositioned || InventoryGridArea.Contains(DrawArea.WithPosition(drawPosition)))
_spriteBatch.Draw(_itemGraphic, DrawPositionWithParentOffset, Color.FromNonPremultiplied(255, 255, 255, 128));
}
else
{
_spriteBatch.Draw(_itemGraphic, DrawPositionWithParentOffset, Color.FromNonPremultiplied(255, 255, 255, 255));
}

_spriteBatch.End();
base.OnDrawControl(gameTime);
}

Expand All @@ -273,7 +288,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
{
Expand Down

0 comments on commit c8223d4

Please sign in to comment.