Skip to content

Commit

Permalink
Fix dragged inventory item from being rendered prematurely
Browse files Browse the repository at this point in the history
  • Loading branch information
miou-gh committed Sep 25, 2022
1 parent 86880ba commit a1b59c9
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 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 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;
Expand Down Expand Up @@ -216,6 +217,7 @@ protected override void OnUpdateControl(GameTime gameTime)
else
DrawPosition = GetPosition(Slot);

dragItemPositioned = 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 @@ -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);
}

Expand All @@ -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
{
Expand Down

0 comments on commit a1b59c9

Please sign in to comment.