From c619c080e0f32271658559f4ed8f9dbca35a7c37 Mon Sep 17 00:00:00 2001 From: Atilla Lonny Date: Mon, 26 Sep 2022 14:46:01 -0400 Subject: [PATCH] InventoryItemPanel refactoring --- .../HUD/Inventory/InventoryPanelItem.cs | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/EndlessClient/HUD/Inventory/InventoryPanelItem.cs b/EndlessClient/HUD/Inventory/InventoryPanelItem.cs index 06ba3e9c1..9a50e9449 100644 --- a/EndlessClient/HUD/Inventory/InventoryPanelItem.cs +++ b/EndlessClient/HUD/Inventory/InventoryPanelItem.cs @@ -48,7 +48,7 @@ public class ItemDragCompletedEventArgs // Ru Paul's drag properties private bool _beingDragged; private Vector2 _oldOffset; - private bool dragItemPositioned; + private bool _dragPositioned; private bool MousePressed => CurrentMouseState.LeftButton == ButtonState.Pressed && PreviousMouseState.LeftButton == ButtonState.Released; @@ -217,7 +217,7 @@ protected override void OnUpdateControl(GameTime gameTime) else DrawPosition = GetPosition(Slot); - dragItemPositioned = false; + _dragPositioned = false; _beingDragged = false; _nameLabel.Visible = false; } @@ -241,9 +241,7 @@ 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); - } } } @@ -251,29 +249,17 @@ protected override void OnDrawControl(GameTime gameTime) { // slot based on current mouse position if being dragged var currentSlot = GetCurrentSlotBasedOnPosition(); - var drawPosition = GetPosition(currentSlot) + (_beingDragged ? _oldOffset : ImmediateParent.DrawPositionWithParentOffset); - - if (!dragItemPositioned) - { - if (InventoryGridArea.Contains(DrawArea.WithPosition(drawPosition))) - { - dragItemPositioned = true; - } - } + var drawPosition = GetPosition(currentSlot) + _oldOffset; - if (dragItemPositioned) - { - _spriteBatch.Draw(_itemGraphic, DrawPositionWithParentOffset, Color.FromNonPremultiplied(255, 255, 255, _beingDragged ? 128 : 255)); - } + if (!_dragPositioned) + _dragPositioned = InventoryGridArea.Contains(DrawArea.WithPosition(drawPosition)); - if (InventoryGridArea.Contains(DrawArea.WithPosition(drawPosition))) - { - _spriteBatch.Draw(_itemGraphic, _beingDragged ? (DrawPositionWithParentOffset) : DrawPositionWithParentOffset, Color.FromNonPremultiplied(255, 255, 255, _beingDragged ? 128 : 255)); - } + if (_dragPositioned || InventoryGridArea.Contains(DrawArea.WithPosition(drawPosition))) + _spriteBatch.Draw(_itemGraphic, DrawPositionWithParentOffset, Color.FromNonPremultiplied(255, 255, 255, 128)); } else { - _spriteBatch.Draw(_itemGraphic, _beingDragged ? (DrawPositionWithParentOffset) : DrawPositionWithParentOffset, Color.FromNonPremultiplied(255, 255, 255, _beingDragged ? 128 : 255)); + _spriteBatch.Draw(_itemGraphic, DrawPositionWithParentOffset, Color.FromNonPremultiplied(255, 255, 255, 255)); } _spriteBatch.End();