From 8d9b65a87e7f2088fb5e5d9e6bb2e4b4caf72e38 Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Wed, 12 Mar 2025 22:54:15 -0300 Subject: [PATCH 01/16] deactivating old drag and drop and starting to using native wg --- .../Interface/Game/Bag/BagItem.cs | 242 ++--------- .../Interface/Game/Bag/BagWindow.cs | 13 - .../Interface/Game/Bank/BankItem.cs | 278 ++----------- .../Interface/Game/Bank/BankWindow.cs | 13 - .../Interface/Game/Draggable.cs | 68 +-- .../Interface/Game/Hotbar/HotBarWindow.cs | 13 - .../Interface/Game/Hotbar/HotbarItem.cs | 185 +-------- .../Interface/Game/Inventory/InventoryItem.cs | 386 +++--------------- .../Game/Inventory/InventoryWindow.cs | 15 - .../Interface/Game/SlotItem.cs | 2 +- .../Interface/Game/Spells/SpellItem.cs | 206 +--------- .../Interface/Game/Spells/SpellsWindow.cs | 15 - .../Gwen/DragDrop/DragAndDrop.cs | 3 +- 13 files changed, 156 insertions(+), 1283 deletions(-) diff --git a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs index 487a705fd2..887977770b 100644 --- a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs @@ -1,6 +1,5 @@ using Intersect.Client.Core; using Intersect.Client.Framework.File_Management; -using Intersect.Client.Framework.GenericClasses; using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; @@ -8,11 +7,8 @@ using Intersect.Client.Framework.Input; using Intersect.Client.General; using Intersect.Client.Interface.Game.DescriptionWindows; -using Intersect.Client.Interface.Game.Inventory; using Intersect.Client.Localization; -using Intersect.Client.Networking; using Intersect.Configuration; -using Intersect.Framework.Core; using Intersect.Framework.Core.GameObjects.Items; namespace Intersect.Client.Interface.Game.Bag; @@ -22,20 +18,8 @@ public partial class BagItem : SlotItem // Controls private readonly Label _quantityLabel; private readonly BagWindow _bagWindow; - private Draggable? _dragIcon; private ItemDescriptionWindow? _descWindow; - // Drag Handling - public bool IsDragging; - private bool _canDrag; - private long _clickTime; - private bool _mouseOver; - private int _mouseX = -1; - private int _mouseY = -1; - - // Data control - private string? _textureLoaded; - // Context Menu Handling private readonly MenuItem _withdrawContextItem; @@ -107,19 +91,13 @@ private void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) return; } - _mouseOver = true; - _canDrag = true; if (Globals.InputManager.IsMouseButtonDown(MouseButton.Left)) { - _canDrag = false; return; } - if (_descWindow != default) - { - _descWindow.Dispose(); - _descWindow = default; - } + _descWindow?.Dispose(); + _descWindow = default; if (Globals.BagSlots is not { Length: > 0 } bagSlots) { @@ -143,36 +121,22 @@ private void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) private void _iconImage_HoverLeave(Base sender, EventArgs arguments) { - _mouseOver = false; - _mouseX = -1; - _mouseY = -1; - - if (_descWindow != default) - { - _descWindow.Dispose(); - _descWindow = default; - } + _descWindow?.Dispose(); + _descWindow = default; } private void _iconImage_Clicked(Base sender, MouseButtonState arguments) { - // ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault - switch (arguments.MouseButton) + if (arguments.MouseButton is MouseButton.Right) { - case MouseButton.Right: - if (ClientConfiguration.Instance.EnableContextMenus) - { - OpenContextMenu(); - } - else - { - _iconImage_DoubleClicked(sender, arguments); - } - break; - - case MouseButton.Left: - _clickTime = Timing.Global.MillisecondsUtc + 500; - break; + if (ClientConfiguration.Instance.EnableContextMenus) + { + OpenContextMenu(); + } + else + { + _iconImage_DoubleClicked(sender, arguments); + } } } @@ -202,193 +166,41 @@ public override void Update() { _quantityLabel.IsVisibleInParent = false; _iconImage.Texture = default; - _textureLoaded = default; return; } var bagSlot = bagSlots[SlotIndex]; var descriptor = bagSlot.Descriptor; - _quantityLabel.IsVisibleInParent = !IsDragging && descriptor.IsStackable && bagSlot.Quantity > 1; + //TODO: dont show when is dragging + _quantityLabel.IsVisibleInParent = descriptor.IsStackable && bagSlot.Quantity > 1; if (_quantityLabel.IsVisibleInParent) { _quantityLabel.Text = Strings.FormatQuantityAbbreviated(bagSlot.Quantity); } - if (_textureLoaded != descriptor.Icon) + if (_iconImage.TextureFilename == descriptor.Icon) { - var itemTex = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); - if (itemTex != default) - { - _iconImage.Texture = itemTex; - _iconImage.RenderColor = descriptor.Color; - _iconImage.IsVisibleInParent = true; - } - else - { - if (_iconImage.Texture != default) - { - _iconImage.Texture = default; - _iconImage.IsVisibleInParent = false; - } - } - - _textureLoaded = descriptor.Icon; - - if (_descWindow != default) - { - _descWindow.Dispose(); - _descWindow = default; - _iconImage_HoverEnter(default, default); - } + return; } - if (!IsDragging) + var itemTexture = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); + if (itemTexture != default) { - if (_mouseOver) - { - if (!Globals.InputManager.IsMouseButtonDown(MouseButton.Left)) - { - _canDrag = true; - _mouseX = -1; - _mouseY = -1; - if (Timing.Global.MillisecondsUtc < _clickTime) - { - _clickTime = 0; - } - } - else - { - if (_canDrag && Draggable.Active == default) - { - if (_mouseX == -1 || _mouseY == -1) - { - _mouseX = InputHandler.MousePosition.X - _iconImage.ToCanvas(new Point(0, 0)).X; - _mouseY = InputHandler.MousePosition.Y - _iconImage.ToCanvas(new Point(0, 0)).Y; - } - else - { - var xdiff = _mouseX - - (InputHandler.MousePosition.X - _iconImage.ToCanvas(new Point(0, 0)).X); - - var ydiff = _mouseY - - (InputHandler.MousePosition.Y - _iconImage.ToCanvas(new Point(0, 0)).Y); - - if (Math.Sqrt(Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2)) > 5) - { - IsDragging = true; - _dragIcon = new Draggable( - _iconImage.ToCanvas(new Point(0, 0)).X + _mouseX, - _iconImage.ToCanvas(new Point(0, 0)).X + _mouseY, _iconImage.Texture, _iconImage.RenderColor - ); - } - } - } - } - } + _iconImage.Texture = itemTexture; + _iconImage.RenderColor = descriptor.Color; + _iconImage.IsVisibleInParent = true; } else { - if (_dragIcon?.Update() == true) + if (_iconImage.Texture != default) { - //Drug the item and now we stopped - IsDragging = false; - var dragRect = new FloatRect( - _dragIcon.X - (Padding.Left + Padding.Right) / 2f, - _dragIcon.Y - (Padding.Top + Padding.Bottom) / 2f, - (Padding.Left + Padding.Right) / 2f + _iconImage.Width, - (Padding.Top + Padding.Bottom) / 2f + _iconImage.Height - ); - - float bestIntersect = 0; - var bestIntersectIndex = -1; - - //So we picked up an item and then dropped it. Lets see where we dropped it to. - //Check inventory first. - if (_bagWindow.RenderBounds().IntersectsWith(dragRect)) - { - for (var i = 0; i < Globals.BagSlots.Length; i++) - { - var slot = _bagWindow.Items[i]; - if (slot is not BagItem bagItem) - { - continue; - } - - if (bagItem.RenderBounds().IntersectsWith(dragRect)) - { - if (FloatRect.Intersect(bagItem.RenderBounds(), dragRect).Width * - FloatRect.Intersect(bagItem.RenderBounds(), dragRect).Height > - bestIntersect) - { - bestIntersect = - FloatRect.Intersect(bagItem.RenderBounds(), dragRect).Width * - FloatRect.Intersect(bagItem.RenderBounds(), dragRect).Height; - - bestIntersectIndex = i; - } - } - } - - if (bestIntersectIndex > -1) - { - if (SlotIndex != bestIntersectIndex) - { - //Try to swap.... - PacketSender.SendMoveBagItems(SlotIndex, bestIntersectIndex); - } - } - } - else - { - var invWindow = Interface.GameUi.GameMenu.GetInventoryWindow(); - - if (invWindow.RenderBounds().IntersectsWith(dragRect)) - { - for (var i = 0; i < Options.Instance.Player.MaxInventory; i++) - { - if(invWindow.Items[i] is not InventoryItem inventoryItem) - { - continue; - } - - if (inventoryItem.RenderBounds().IntersectsWith(dragRect)) - { - if (FloatRect.Intersect(inventoryItem.RenderBounds(), dragRect).Width * - FloatRect.Intersect(inventoryItem.RenderBounds(), dragRect).Height > - bestIntersect) - { - bestIntersect = - FloatRect.Intersect(inventoryItem.RenderBounds(), dragRect).Width * - FloatRect.Intersect(inventoryItem.RenderBounds(), dragRect).Height; - - bestIntersectIndex = i; - } - } - } - - if (bestIntersectIndex > -1) - { - Globals.Me.TryRetrieveItemFromBag(SlotIndex, bestIntersectIndex); - } - } - } - - _dragIcon.Dispose(); + _iconImage.Texture = default; + _iconImage.IsVisibleInParent = false; } } - } - - public FloatRect RenderBounds() - { - var rect = new FloatRect() - { - X = _iconImage.ToCanvas(new Point(0, 0)).X, - Y = _iconImage.ToCanvas(new Point(0, 0)).Y, - Width = _iconImage.Width, - Height = _iconImage.Height - }; - return rect; + _descWindow?.Dispose(); + _descWindow = default; } } diff --git a/Intersect.Client.Core/Interface/Game/Bag/BagWindow.cs b/Intersect.Client.Core/Interface/Game/Bag/BagWindow.cs index 35f95e6a85..b9797994ec 100644 --- a/Intersect.Client.Core/Interface/Game/Bag/BagWindow.cs +++ b/Intersect.Client.Core/Interface/Game/Bag/BagWindow.cs @@ -86,17 +86,4 @@ public void Update() } } } - - public FloatRect RenderBounds() - { - var rect = new FloatRect() - { - X = ToCanvas(new Point(0, 0)).X - 4 / 2, - Y = ToCanvas(new Point(0, 0)).Y - 4 / 2, - Width = Width + 4, - Height = Height + 4 - }; - - return rect; - } } diff --git a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs index 954403f6db..7790bc9fee 100644 --- a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs @@ -7,14 +7,9 @@ using Intersect.Client.Framework.Gwen.Input; using Intersect.Client.Framework.Input; using Intersect.Client.General; -using Intersect.Client.Interface.Game.Chat; using Intersect.Client.Interface.Game.DescriptionWindows; -using Intersect.Client.Interface.Game.Inventory; using Intersect.Client.Localization; -using Intersect.Client.Networking; using Intersect.Configuration; -using Intersect.Enums; -using Intersect.Framework.Core; using Intersect.Framework.Core.GameObjects.Items; namespace Intersect.Client.Interface.Game.Bank; @@ -24,20 +19,8 @@ public partial class BankItem : SlotItem // Controls private readonly Label _quantityLabel; private BankWindow _bankWindow; - private Draggable? _dragIcon; private ItemDescriptionWindow? _descWindow; - // Drag Handling - public bool IsDragging; - private bool _canDrag; - private long _clickTime; - private bool _mouseOver; - private int _mouseX = -1; - private int _mouseY = -1; - - // Data control - private string? _textureLoaded; - // Context Menu Handling private MenuItem _withdrawContextItem; @@ -103,20 +86,14 @@ private void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) return; } - _mouseOver = true; - _canDrag = true; - if (Globals.InputManager.IsMouseButtonDown(MouseButton.Left)) { - _canDrag = false; return; } - if (_descWindow != null) - { - _descWindow.Dispose(); - _descWindow = null; - } + + _descWindow?.Dispose(); + _descWindow = null; if (Globals.BankSlots is not { Length: > 0 } bankSlots) { @@ -140,35 +117,22 @@ private void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) private void _iconImage_HoverLeave(Base sender, EventArgs arguments) { - _mouseOver = false; - _mouseX = -1; - _mouseY = -1; - - if (_descWindow != null) - { - _descWindow.Dispose(); - _descWindow = null; - } + _descWindow?.Dispose(); + _descWindow = default; } private void _iconImage_Clicked(Base sender, MouseButtonState arguments) { - switch (arguments.MouseButton) + if (arguments.MouseButton is MouseButton.Right) { - case MouseButton.Left: - _clickTime = Timing.Global.MillisecondsUtc + 500; - break; - - case MouseButton.Right: - if (ClientConfiguration.Instance.EnableContextMenus) - { - OpenContextMenu(); - } - else - { - _iconImage_DoubleClicked(sender, arguments); - } - break; + if (ClientConfiguration.Instance.EnableContextMenus) + { + OpenContextMenu(); + } + else + { + _iconImage_DoubleClicked(sender, arguments); + } } } @@ -222,225 +186,41 @@ private void _iconImage_DoubleClicked(Base sender, MouseButtonState arguments) { _quantityLabel.IsVisibleInParent = false; _iconImage.Texture = default; - _textureLoaded = default; return; } var bankSlot = bankSlots[SlotIndex]; var descriptor = bankSlot.Descriptor; - _quantityLabel.IsVisibleInParent = !IsDragging && descriptor.IsStackable && bankSlot.Quantity > 1; + //TODO: dont show when is dragging + _quantityLabel.IsVisibleInParent = descriptor.IsStackable && bankSlot.Quantity > 1; if (_quantityLabel.IsVisibleInParent) { _quantityLabel.Text = Strings.FormatQuantityAbbreviated(bankSlot.Quantity); } - if (_textureLoaded != descriptor.Icon) + if (_iconImage.TextureFilename == descriptor.Icon) { - var itemTex = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); - if (itemTex != default) - { - _iconImage.Texture = itemTex; - _iconImage.RenderColor = descriptor.Color; - _iconImage.IsVisibleInParent = true; - } - else - { - if (_iconImage.Texture != default) - { - _iconImage.Texture = default; - _iconImage.IsVisibleInParent = false; - } - } - - _textureLoaded = descriptor.Icon; - - if (_descWindow != default) - { - _descWindow.Dispose(); - _descWindow = default; - _iconImage_HoverEnter(default, default); - } + return; } - if (!IsDragging) + var itemTexture = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); + if (itemTexture != default) { - if (_mouseOver) - { - if (!Globals.InputManager.IsMouseButtonDown(MouseButton.Left)) - { - _canDrag = true; - _mouseX = -1; - _mouseY = -1; - if (Timing.Global.MillisecondsUtc < _clickTime) - { - //Globals.Me.TryUseItem(_mySlot); - _clickTime = 0; - } - } - else - { - if (_canDrag && Draggable.Active == null) - { - if (_mouseX == -1 || _mouseY == -1) - { - _mouseX = InputHandler.MousePosition.X - _iconImage.ToCanvas(new Point(0, 0)).X; - _mouseY = InputHandler.MousePosition.Y - _iconImage.ToCanvas(new Point(0, 0)).Y; - } - else - { - var xdiff = _mouseX - - (InputHandler.MousePosition.X - _iconImage.ToCanvas(new Point(0, 0)).X); - - var ydiff = _mouseY - - (InputHandler.MousePosition.Y - _iconImage.ToCanvas(new Point(0, 0)).Y); - - if (Math.Sqrt(Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2)) > 5) - { - IsDragging = true; - _dragIcon = new Draggable( - _iconImage.ToCanvas(new Point(0, 0)).X + _mouseX, - _iconImage.ToCanvas(new Point(0, 0)).X + _mouseY, _iconImage.Texture, _iconImage.RenderColor - ); - } - } - } - } - } + _iconImage.Texture = itemTexture; + _iconImage.RenderColor = descriptor.Color; + _iconImage.IsVisibleInParent = true; } - else if (_dragIcon?.Update() == true) + else { - //Drug the item and now we stopped - IsDragging = false; - var dragRect = new FloatRect( - _dragIcon.X - (Padding.Left + Padding.Right) / 2f, - _dragIcon.Y - (Padding.Top + Padding.Bottom) / 2f, - (Padding.Left + Padding.Right) / 2f + _iconImage.Width, - (Padding.Top + Padding.Bottom) / 2f + _iconImage.Height - ); - - float bestIntersect = 0; - var bestIntersectIndex = -1; - - // So we picked up an item and then dropped it. Lets see where we dropped it to. - if (_bankWindow.RenderBounds().IntersectsWith(dragRect)) + if (_iconImage.Texture != default) { - var bankSlotComponents = _bankWindow.Items.ToArray(); - var bankSlotLimit = Math.Min(Globals.BankSlotCount, bankSlotComponents.Length); - for (var bankSlotIndex = 0; bankSlotIndex < bankSlotLimit; bankSlotIndex++) - { - if (bankSlotComponents[bankSlotIndex] is not BankItem bankSlotComponent) - { - continue; - } - - var bankSlotRenderBounds = bankSlotComponent.RenderBounds(); - if (!bankSlotRenderBounds.IntersectsWith(dragRect)) - { - continue; - } - - var intersection = FloatRect.Intersect(bankSlotRenderBounds, dragRect); - if (intersection.Width * intersection.Height <= bestIntersect) - { - continue; - } - - bestIntersect = intersection.Width * intersection.Height; - bestIntersectIndex = bankSlotIndex; - } - - if (bestIntersectIndex > -1) - { - if (SlotIndex != bestIntersectIndex) - { - var allowed = true; - - //Permission Check - if (Globals.IsGuildBank) - { - var rank = Globals.Me.GuildRank; - if (string.IsNullOrWhiteSpace(Globals.Me.Guild) || - (rank?.Permissions.BankDeposit == false && Globals.Me.Rank != 0)) - { - ChatboxMsg.AddMessage( - new ChatboxMsg( - Strings.Guilds.NotAllowedSwap.ToString(Globals.Me.Guild), - CustomColors.Alerts.Error, - ChatMessageType.Bank - ) - ); - allowed = false; - } - } - - if (allowed) - { - PacketSender.SendMoveBankItems(SlotIndex, bestIntersectIndex); - } - } - } + _iconImage.Texture = default; + _iconImage.IsVisibleInParent = false; } - else - { - var invWindow = Interface.GameUi.GameMenu.GetInventoryWindow(); - if (invWindow.RenderBounds().IntersectsWith(dragRect)) - { - var inventorySlots = invWindow.Items.ToArray(); - var inventorySlotLimit = Math.Min( - Globals.Me?.Inventory.Length ?? inventorySlots.Length, - inventorySlots.Length - ); - for (var inventoryIndex = 0; inventoryIndex < inventorySlotLimit; inventoryIndex++) - { - if (inventorySlots[inventoryIndex] is not InventoryItem inventorySlotComponent) - { - continue; - } - - var inventorySlotRenderBounds = inventorySlotComponent.RenderBounds(); - if (!inventorySlotRenderBounds.IntersectsWith(dragRect)) - { - continue; - } - - var intersection = FloatRect.Intersect(inventorySlotRenderBounds, dragRect); - if (intersection.Width * intersection.Height <= bestIntersect) - { - continue; - } - - bestIntersect = intersection.Width * intersection.Height; - bestIntersectIndex = inventoryIndex; - } - - if (bestIntersectIndex > -1) - { - var slot = Globals.BankSlots[SlotIndex]; - Globals.Me?.TryRetrieveItemFromBank( - SlotIndex, - inventorySlotIndex: bestIntersectIndex, - quantityHint: slot.Quantity, - skipPrompt: true - ); - } - } - } - - _dragIcon.Dispose(); } - } - - public FloatRect RenderBounds() - { - var rect = new FloatRect() - { - X = _iconImage.ToCanvas(new Point(0, 0)).X, - Y = _iconImage.ToCanvas(new Point(0, 0)).Y, - Width = _iconImage.Width, - Height = _iconImage.Height - }; - return rect; + _descWindow?.Dispose(); + _descWindow = default; } } diff --git a/Intersect.Client.Core/Interface/Game/Bank/BankWindow.cs b/Intersect.Client.Core/Interface/Game/Bank/BankWindow.cs index 8b77f1add4..7323a9337d 100644 --- a/Intersect.Client.Core/Interface/Game/Bank/BankWindow.cs +++ b/Intersect.Client.Core/Interface/Game/Bank/BankWindow.cs @@ -89,17 +89,4 @@ public void Update() } } } - - public FloatRect RenderBounds() - { - var rect = new FloatRect() - { - X = ToCanvas(new Point(0, 0)).X - 4 / 2, - Y = ToCanvas(new Point(0, 0)).Y - 4 / 2, - Width = Width + 4, - Height = Height + 4 - }; - - return rect; - } } diff --git a/Intersect.Client.Core/Interface/Game/Draggable.cs b/Intersect.Client.Core/Interface/Game/Draggable.cs index 04d7b64810..2a2b8a5540 100644 --- a/Intersect.Client.Core/Interface/Game/Draggable.cs +++ b/Intersect.Client.Core/Interface/Game/Draggable.cs @@ -1,68 +1,34 @@ -using Intersect.Client.Core; -using Intersect.Client.Framework.File_Management; -using Intersect.Client.Framework.Graphics; using Intersect.Client.Framework.Gwen.Control; +using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.Framework.Gwen.Input; -using Intersect.Client.Framework.Input; -using Intersect.Client.General; namespace Intersect.Client.Interface.Game; - -partial class Draggable +public partial class Draggable(Base parent, string name) : ImagePanel(parent, name) { - - public static Draggable Active = null; - - ImagePanel mPnl; - - public Draggable(int x, int y, IGameTexture tex, Color color) - { - mPnl = new ImagePanel(Interface.GameUi.GameCanvas, "Draggable"); - mPnl.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString()); - mPnl.SetPosition( - InputHandler.MousePosition.X - mPnl.Width / 2, InputHandler.MousePosition.Y - mPnl.Height / 2 - ); - - mPnl.Texture = tex; - mPnl.RenderColor = color; - Active = this; - } - - public int X + public override bool DragAndDrop_Draggable() { - get => mPnl.X; - set => mPnl.X = value; + return true; } - public int Y + public override Package DragAndDrop_GetPackage(int x, int y) { - get => mPnl.Y; - set => mPnl.Y = value; + return new Package() + { + IsDraggable = true, + DrawControl = this, + Name = Name, + HoldOffset = ToLocal(InputHandler.MousePosition.X, InputHandler.MousePosition.Y), + }; } - public bool Update() + public override void DragAndDrop_StartDragging(Package package, int x, int y) { - mPnl.SetPosition( - InputHandler.MousePosition.X - mPnl.Width / 2, InputHandler.MousePosition.Y - mPnl.Height / 2 - ); - - if (!Globals.InputManager.IsMouseButtonDown(MouseButton.Left)) - { - return true; - } - - return false; + IsVisibleInParent = false; } - public void Dispose() + public override void DragAndDrop_EndDragging(bool success, int x, int y) { - if (Active == this) - { - Active = null; - } - - Interface.GameUi.GameCanvas.RemoveChild(mPnl, false); + IsVisibleInParent = true; } - -} +} \ No newline at end of file diff --git a/Intersect.Client.Core/Interface/Game/Hotbar/HotBarWindow.cs b/Intersect.Client.Core/Interface/Game/Hotbar/HotBarWindow.cs index a528821e29..53611d8dbd 100644 --- a/Intersect.Client.Core/Interface/Game/Hotbar/HotBarWindow.cs +++ b/Intersect.Client.Core/Interface/Game/Hotbar/HotBarWindow.cs @@ -49,17 +49,4 @@ public void Update() slot.Update(); } } - - public FloatRect RenderBounds() - { - var rect = new FloatRect - { - X = ToCanvas(default).X, - Y = ToCanvas(default).Y, - Width = Width, - Height = Height, - }; - - return rect; - } } diff --git a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs index e19115505f..4588068262 100644 --- a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs +++ b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs @@ -20,20 +20,13 @@ namespace Intersect.Client.Interface.Game.Hotbar; public partial class HotbarItem : SlotItem { - private const int ItemXPadding = 4; - private const int ItemYPadding = 4; - private readonly Label _cooldownLabel; private readonly Label _equipLabel; private readonly Label _keyLabel; - private bool _canDrag; - private long _clickTime; private Guid _currentId = Guid.Empty; private ItemDescriptor? _currentItem = null; private SpellDescriptor? _currentSpell = null; - private Draggable _dragIcon; - private bool _isDragging; private bool _isEquipped; private bool _isFaded; private readonly Base _hotbarWindow; @@ -41,9 +34,6 @@ public partial class HotbarItem : SlotItem private Item? _inventoryItem = null; private int _inventoryItemIndex = -1; private ItemDescriptionWindow? _itemDescWindow; - private bool _mouseOver; - private int _mouseX = -1; - private int _mouseY = -1; private Label _quantityLabel; private Spell? _spellBookItem = null; private SpellDescriptionWindow? _spellDescWindow; @@ -161,34 +151,19 @@ public void Activate() private void _iconImage_Clicked(Base sender, MouseButtonState arguments) { - switch (arguments.MouseButton) + if (arguments.MouseButton is MouseButton.Right) { - case MouseButton.Left: - _clickTime = Timing.Global.MillisecondsUtc + 500; - break; - - case MouseButton.Right: - Globals.Me?.AddToHotbar(SlotIndex, -1, -1); - break; + Globals.Me?.AddToHotbar(SlotIndex, -1, -1); } } private void _iconImage_HoverLeave(Base sender, EventArgs arguments) { - _mouseOver = false; - _mouseX = -1; - _mouseY = -1; - if (_itemDescWindow != null) - { - _itemDescWindow.Dispose(); - _itemDescWindow = null; - } + _itemDescWindow?.Dispose(); + _itemDescWindow = null; - if (_spellDescWindow != null) - { - _spellDescWindow.Dispose(); - _spellDescWindow = null; - } + _spellDescWindow?.Dispose(); + _spellDescWindow = null; } private void _iconImage_HoverEnter(Base sender, EventArgs arguments) @@ -198,22 +173,15 @@ private void _iconImage_HoverEnter(Base sender, EventArgs arguments) return; } - _mouseOver = true; - _canDrag = true; if (Globals.InputManager.IsMouseButtonDown(MouseButton.Left)) { - _canDrag = false; - return; } if (_currentItem != null && _inventoryItem != null) { - if (_itemDescWindow != null) - { - _itemDescWindow.Dispose(); - _itemDescWindow = null; - } + _itemDescWindow?.Dispose(); + _itemDescWindow = null; var quantityOfItem = 1; @@ -229,11 +197,8 @@ private void _iconImage_HoverEnter(Base sender, EventArgs arguments) } else if (_currentSpell != null) { - if (_spellDescWindow != null) - { - _spellDescWindow.Dispose(); - _spellDescWindow = null; - } + _spellDescWindow?.Dispose(); + _spellDescWindow = null; _spellDescWindow = new SpellDescriptionWindow( _currentSpell.Id, _hotbarWindow.X + (_hotbarWindow.Width / 2), _hotbarWindow.Y + _hotbarWindow.Height + 2 @@ -241,19 +206,6 @@ private void _iconImage_HoverEnter(Base sender, EventArgs arguments) } } - public FloatRect RenderBounds() - { - var rect = new FloatRect() - { - X = ToCanvas(new Point(0, 0)).X, - Y = ToCanvas(new Point(0, 0)).Y, - Width = Width, - Height = Height - }; - - return rect; - } - public void Update() { if (Globals.Me == null || Controls.ActiveControls == null) @@ -510,122 +462,5 @@ public void Update() } } } - - if (_currentItem != null || _currentSpell != null) - { - if (!_isDragging) - { - _iconImage.IsHidden = false; - - var equipLabelIsHidden = _currentItem == null || !Globals.Me.IsEquipped(_inventoryItemIndex) || _inventoryItemIndex < 0; - _equipLabel.IsHidden = equipLabelIsHidden; - - var quantityLabelIsHidden = _currentItem is not { Stackable: true } || _inventoryItemIndex < 0; - _quantityLabel.IsHidden = quantityLabelIsHidden; - - if (_mouseOver) - { - if (!Globals.InputManager.IsMouseButtonDown(MouseButton.Left)) - { - _canDrag = true; - _mouseX = -1; - _mouseY = -1; - if (Timing.Global.MillisecondsUtc < _clickTime) - { - Activate(); - _clickTime = 0; - } - } - else - { - if (_canDrag && Draggable.Active == null) - { - if (_mouseX == -1 || _mouseY == -1) - { - _mouseX = InputHandler.MousePosition.X - ToCanvas(new Point(0, 0)).X; - _mouseY = InputHandler.MousePosition.Y - ToCanvas(new Point(0, 0)).Y; - } - else - { - var xdiff = _mouseX - - (InputHandler.MousePosition.X - - ToCanvas(new Point(0, 0)).X); - - var ydiff = _mouseY - - (InputHandler.MousePosition.Y - - ToCanvas(new Point(0, 0)).Y); - - if (Math.Sqrt(Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2)) > 5) - { - _isDragging = true; - _dragIcon = new Draggable( - ToCanvas(new Point(0, 0)).X + _mouseX, - ToCanvas(new Point(0, 0)).X + _mouseY, _iconImage.Texture, _iconImage.RenderColor - ); - - //SOMETHING SHOULD BE RENDERED HERE, RIGHT? - } - } - } - } - } - } - else if (_dragIcon.Update()) - { - //Drug the item and now we stopped - _isDragging = false; - FloatRect dragRect = new( - _dragIcon.X - ItemXPadding / 2f, - _dragIcon.Y - ItemYPadding / 2f, - ItemXPadding / 2f + 32, - ItemYPadding / 2f + 32 - ); - - float bestIntersect = 0; - var bestIntersectIndex = -1; - - if (Interface.GameUi.Hotbar.RenderBounds().IntersectsWith(dragRect)) - { - var hotbarSlotComponents = Interface.GameUi.Hotbar.Items.ToArray(); - var hotbarSlotLimit = Math.Min( - Options.Instance.Player.HotbarSlotCount, - hotbarSlotComponents.Length - ); - for (var hotbarSlotIndex = 0; hotbarSlotIndex < hotbarSlotLimit; hotbarSlotIndex++) - { - var hotbarSlotComponent = hotbarSlotComponents[hotbarSlotIndex]; - var hotbarSlotRenderBounds = hotbarSlotComponent.RenderBounds(); - if (!hotbarSlotRenderBounds.IntersectsWith(dragRect)) - { - continue; - } - - var intersection = FloatRect.Intersect(hotbarSlotRenderBounds, dragRect); - if (intersection.Width * intersection.Height <= bestIntersect) - { - continue; - } - - bestIntersect = intersection.Width * intersection.Height; - - bestIntersectIndex = hotbarSlotIndex; - } - - if (bestIntersectIndex > -1 && bestIntersectIndex != SlotIndex) - { - Globals.Me.HotbarSwap(SlotIndex, (byte)bestIntersectIndex); - } - } - - _dragIcon.Dispose(); - } - else - { - _iconImage.IsHidden = true; - _equipLabel.IsHidden = true; - _quantityLabel.IsHidden = true; - _cooldownLabel.IsHidden = true; - } - } } } diff --git a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs index 966f3e776f..e526d8f61e 100644 --- a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs +++ b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs @@ -8,13 +8,9 @@ using Intersect.Client.Framework.Gwen.Input; using Intersect.Client.Framework.Input; using Intersect.Client.General; -using Intersect.Client.Interface.Game.Bag; -using Intersect.Client.Interface.Game.Bank; using Intersect.Client.Interface.Game.DescriptionWindows; using Intersect.Client.Localization; -using Intersect.Client.Networking; using Intersect.Configuration; -using Intersect.Framework.Core; using Intersect.Framework.Core.GameObjects.Items; using Intersect.GameObjects; using Intersect.Utilities; @@ -29,20 +25,8 @@ public partial class InventoryItem : SlotItem private readonly Label _cooldownLabel; private readonly ImagePanel _equipImageBackground; private readonly InventoryWindow _inventoryWindow; - private Draggable? _dragIcon; private ItemDescriptionWindow? _descWindow; - // Drag Handling - public bool IsDragging; - private bool _canDrag; - private long _clickTime; - private bool _mouseOver; - private int _mouseX = -1; - private int _mouseY = -1; - - // Data control - private string _textureLoaded = string.Empty; - // Context Menu Handling private readonly MenuItem _useItemMenuItem; private readonly MenuItem _actionItemMenuItem; @@ -271,55 +255,42 @@ private void _iconImage_DoubleClicked(Base sender, MouseButtonState arguments) private void _iconImage_Clicked(Base sender, MouseButtonState arguments) { - switch (arguments.MouseButton) + if (arguments.MouseButton is MouseButton.Right) { - case MouseButton.Left: - _clickTime = Timing.Global.MillisecondsUtc + 500; - break; - - case MouseButton.Right: - if (ClientConfiguration.Instance.EnableContextMenus) + if (ClientConfiguration.Instance.EnableContextMenus) + { + OpenContextMenu(); + } + else + { + if (Globals.GameShop != null) + { + Globals.Me?.TrySellItem(SlotIndex); + } + else if (Globals.InBank) + { + Globals.Me?.TryStoreItemInBank(SlotIndex); + } + else if (Globals.InBag) { - OpenContextMenu(); + Globals.Me?.TryStoreItemInBag(SlotIndex, -1); + } + else if (Globals.InTrade) + { + Globals.Me?.TryOfferItemToTrade(SlotIndex); } else { - if (Globals.GameShop != null) - { - Globals.Me?.TrySellItem(SlotIndex); - } - else if (Globals.InBank) - { - Globals.Me?.TryStoreItemInBank(SlotIndex); - } - else if (Globals.InBag) - { - Globals.Me?.TryStoreItemInBag(SlotIndex, -1); - } - else if (Globals.InTrade) - { - Globals.Me?.TryOfferItemToTrade(SlotIndex); - } - else - { - Globals.Me?.TryDropItem(SlotIndex); - } + Globals.Me?.TryDropItem(SlotIndex); } - break; + } } } private void _iconImage_HoverLeave(Base sender, EventArgs arguments) { - _mouseOver = false; - _mouseX = -1; - _mouseY = -1; - - if (_descWindow != null) - { - _descWindow.Dispose(); - _descWindow = null; - } + _descWindow?.Dispose(); + _descWindow = null; } void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) @@ -329,12 +300,8 @@ void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) return; } - _mouseOver = true; - _canDrag = true; - if (Globals.InputManager.IsMouseButtonDown(MouseButton.Left)) { - _canDrag = false; return; } @@ -446,20 +413,7 @@ private void PlayerOnInventoryUpdated(Player player, int slotIndex) } // empty texture to reload on update - _textureLoaded = string.Empty; - } - - public FloatRect RenderBounds() - { - var rect = new FloatRect() - { - X = _iconImage.ToCanvas(new Point(0, 0)).X, - Y = _iconImage.ToCanvas(new Point(0, 0)).Y, - Width = _iconImage.Width, - Height = _iconImage.Height - }; - - return rect; + _iconImage.Texture = default; } public override void Update() @@ -481,16 +435,20 @@ public override void Update() } var equipped = Globals.Me.MyEquipment.Any(s => s == SlotIndex); - _equipImageBackground.IsVisibleInParent = !IsDragging && equipped; - _equipLabel.IsVisibleInParent = !IsDragging && equipped; + //Todo: hide when dragging + _equipImageBackground.IsVisibleInParent = equipped; + //Todo: hide when dragging + _equipLabel.IsVisibleInParent = equipped; - _quantityLabel.IsVisibleInParent = !IsDragging && descriptor.IsStackable && inventorySlot.Quantity > 1; + //Todo: hide when dragging + _quantityLabel.IsVisibleInParent = descriptor.IsStackable && inventorySlot.Quantity > 1; if (_quantityLabel.IsVisibleInParent) { _quantityLabel.Text = Strings.FormatQuantityAbbreviated(inventorySlot.Quantity); } - _cooldownLabel.IsVisibleInParent = !IsDragging && Globals.Me.IsItemOnCooldown(SlotIndex); + //Todo: hide when dragging + _cooldownLabel.IsVisibleInParent = Globals.Me.IsItemOnCooldown(SlotIndex); if (_cooldownLabel.IsVisibleInParent) { var itemCooldownRemaining = Globals.Me.GetItemRemainingCooldown(SlotIndex); @@ -502,278 +460,46 @@ public override void Update() _iconImage.RenderColor.A = descriptor.Color.A; } - if (_textureLoaded != descriptor.Icon) + if (_iconImage.TextureFilename == descriptor.Icon) { - var itemTex = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); - if (itemTex != null) - { - _iconImage.Texture = itemTex; - _iconImage.RenderColor = Globals.Me.IsItemOnCooldown(SlotIndex) - ? new Color(100, descriptor.Color.R, descriptor.Color.G, descriptor.Color.B) - : descriptor.Color; - _iconImage.IsVisibleInParent = true; - } - else - { - if (_iconImage.Texture != null) - { - _iconImage.Texture = null; - _iconImage.IsVisibleInParent = false; - } - } - - _textureLoaded = descriptor.Icon; - - if (_descWindow != null) - { - _descWindow.Dispose(); - _descWindow = null; - _iconImage_HoverEnter(null, null); - } + return; } - if (!IsDragging) + var itemTexture = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); + if (itemTexture != null) { - if (_mouseOver) - { - if (!Globals.InputManager.IsMouseButtonDown(MouseButton.Left)) - { - _canDrag = true; - _mouseX = -1; - _mouseY = -1; - - if (Timing.Global.MillisecondsUtc < _clickTime) - { - _clickTime = 0; - } - } - else - { - if (_canDrag && Draggable.Active == null) - { - if (_mouseX == -1 || _mouseY == -1) - { - _mouseX = InputHandler.MousePosition.X - _iconImage.ToCanvas(new Point(0, 0)).X; - _mouseY = InputHandler.MousePosition.Y - _iconImage.ToCanvas(new Point(0, 0)).Y; - } - else - { - var xdiff = _mouseX - - (InputHandler.MousePosition.X - _iconImage.ToCanvas(new Point(0, 0)).X); - - var ydiff = _mouseY - - (InputHandler.MousePosition.Y - _iconImage.ToCanvas(new Point(0, 0)).Y); - - if (Math.Sqrt(Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2)) > 5) - { - IsDragging = true; - _iconImage.IsVisibleInParent = false; - - _dragIcon = new Draggable( - _iconImage.ToCanvas(new Point(0, 0)).X + _mouseX, - _iconImage.ToCanvas(new Point(0, 0)).X + _mouseY, _iconImage.Texture, _iconImage.RenderColor - ); - } - } - } - } - } + _iconImage.Texture = itemTexture; + _iconImage.RenderColor = Globals.Me.IsItemOnCooldown(SlotIndex) + ? new Color(100, descriptor.Color.R, descriptor.Color.G, descriptor.Color.B) + : descriptor.Color; + _iconImage.IsVisibleInParent = true; } - else if (_dragIcon?.Update() == true) + else { - //Drug the item and now we stopped - IsDragging = false; - _iconImage.IsVisibleInParent = true; - - var dragRect = new FloatRect( - _dragIcon.X - (Padding.Left + Padding.Right) / 2f, - _dragIcon.Y - (Padding.Top + Padding.Bottom) / 2f, - (Padding.Left + Padding.Right) / 2f + _iconImage.Width, - (Padding.Top + Padding.Bottom) / 2f + _iconImage.Height - ); - - float bestIntersect = 0; - var bestIntersectIndex = -1; - - //So we picked up an item and then dropped it. Lets see where we dropped it to. - //Check inventory first. - if (_inventoryWindow.RenderBounds().IntersectsWith(dragRect)) - { - var inventorySlotComponents = _inventoryWindow.Items.ToArray(); - var inventorySlotLimit = Math.Min(Options.Instance.Player.MaxInventory, inventorySlotComponents.Length); - for (var inventoryIndex = 0; inventoryIndex < inventorySlotLimit; inventoryIndex++) - { - var inventorySlotComponent = inventorySlotComponents[inventoryIndex]; - var inventoryRenderBounds = ((InventoryItem)inventorySlotComponent).RenderBounds(); - - if (!inventoryRenderBounds.IntersectsWith(dragRect)) - { - continue; - } - - var intersection = FloatRect.Intersect(inventoryRenderBounds, dragRect); - if (!(intersection.Width * intersection.Height > bestIntersect)) - { - continue; - } - - bestIntersect = intersection.Width * intersection.Height; - bestIntersectIndex = inventoryIndex; - } - - if (bestIntersectIndex > -1) - { - if (SlotIndex != bestIntersectIndex) - { - Globals.Me.SwapItems(SlotIndex, bestIntersectIndex); - } - } - } - else if (Interface.GameUi.Hotbar.RenderBounds().IntersectsWith(dragRect)) - { - var hotbarSlotComponents = Interface.GameUi.Hotbar.Items.ToArray(); - var hotbarSlotLimit = Math.Min( - Options.Instance.Player.HotbarSlotCount, - hotbarSlotComponents.Length - ); - for (var hotbarSlotIndex = 0; hotbarSlotIndex < hotbarSlotLimit; hotbarSlotIndex++) - { - var hotbarSlotComponent = hotbarSlotComponents[hotbarSlotIndex]; - var hotbarSlotRenderBounds = hotbarSlotComponent.RenderBounds(); - if (!hotbarSlotRenderBounds.IntersectsWith(dragRect)) - { - continue; - } - - var intersection = FloatRect.Intersect(hotbarSlotRenderBounds, dragRect); - if (intersection.Width * intersection.Height <= bestIntersect) - { - continue; - } - - bestIntersect = intersection.Width * intersection.Height; - bestIntersectIndex = hotbarSlotIndex; - } - - if (bestIntersectIndex > -1) - { - Globals.Me.AddToHotbar((byte)bestIntersectIndex, 0, SlotIndex); - } - } - else if (Globals.InBag && Globals.BagSlots != default) - { - var bagWindow = Interface.GameUi.GetBagWindow(); - if (bagWindow.RenderBounds().IntersectsWith(dragRect)) - { - var bagSlotComponents = bagWindow.Items.ToArray(); - var bagSlotLimit = Math.Min(Globals.BagSlots.Length, bagSlotComponents.Length); - for (var bagSlotIndex = 0; bagSlotIndex < bagSlotLimit; bagSlotIndex++) - { - if (bagSlotComponents[bagSlotIndex] is not BagItem bagSlotComponent) - { - continue; - } - - var bagSlotRenderBounds = bagSlotComponent.RenderBounds(); - if (!bagSlotRenderBounds.IntersectsWith(dragRect)) - { - continue; - } - - var intersection = FloatRect.Intersect(bagSlotRenderBounds, dragRect); - if (intersection.Width * intersection.Height <= bestIntersect) - { - continue; - } - - bestIntersect = intersection.Width * intersection.Height; - bestIntersectIndex = bagSlotIndex; - } - - if (bestIntersectIndex > -1) - { - Globals.Me.TryStoreItemInBag(SlotIndex, bestIntersectIndex); - } - } - } - else if (Globals.InBank && Globals.BankSlots != default) - { - if (Interface.GameUi.GetBankWindow() is not BankWindow bankWindow) - { - return; - } - - if (bankWindow.RenderBounds().IntersectsWith(dragRect)) - { - var bankSlotComponents = bankWindow.Items.ToArray(); - var bankSlotLimit = Math.Min( - Math.Min(Globals.BankSlots.Length, Globals.BankSlotCount), - bankSlotComponents.Length - ); - - for (var bankSlotIndex = 0; bankSlotIndex < bankSlotLimit; bankSlotIndex++) - { - if (bankSlotComponents[bankSlotIndex] is not BankItem bankSlotComponent) - { - continue; - } - - var bankSlotRenderBounds = bankSlotComponent.RenderBounds(); - if (!bankSlotRenderBounds.IntersectsWith(dragRect)) - { - continue; - } - - var intersection = FloatRect.Intersect(bankSlotRenderBounds, dragRect); - if (!(intersection.Width * intersection.Height > bestIntersect)) - { - continue; - } - - bestIntersect = intersection.Width * intersection.Height; - bestIntersectIndex = bankSlotIndex; - } - - if (bestIntersectIndex > -1) - { - var slot = Globals.Me.Inventory[SlotIndex]; - Globals.Me.TryStoreItemInBank( - SlotIndex, - bankSlotIndex: bestIntersectIndex, - quantityHint: slot.Quantity, - skipPrompt: true - ); - } - } - } - else if (!Globals.Me.IsBusy) + if (_iconImage.Texture != null) { - PacketSender.SendDropItem(SlotIndex, Globals.Me.Inventory[SlotIndex].Quantity); + _iconImage.Texture = null; + _iconImage.IsVisibleInParent = false; } + } - _dragIcon.Dispose(); + if (_descWindow != null) + { + _descWindow.Dispose(); + _descWindow = null; + _iconImage_HoverEnter(null, null); } } private void _reset() { _iconImage.IsVisibleInParent = false; + _iconImage.Texture = default; _equipImageBackground.IsVisibleInParent = false; _quantityLabel.IsVisibleInParent = false; _equipLabel.IsVisibleInParent = false; _cooldownLabel.IsVisibleInParent = false; - _textureLoaded = string.Empty; - - if (_dragIcon != default) - { - _dragIcon.Dispose(); - _dragIcon = default; - } - - if (_descWindow != default) - { - _descWindow.Dispose(); - _descWindow = default; - } + _descWindow?.Dispose(); + _descWindow = default; } } diff --git a/Intersect.Client.Core/Interface/Game/Inventory/InventoryWindow.cs b/Intersect.Client.Core/Interface/Game/Inventory/InventoryWindow.cs index 8075650794..9d57c11b69 100644 --- a/Intersect.Client.Core/Interface/Game/Inventory/InventoryWindow.cs +++ b/Intersect.Client.Core/Interface/Game/Inventory/InventoryWindow.cs @@ -99,19 +99,4 @@ public override void Hide() _contextMenu?.Close(); base.Hide(); } - - // TODO: Window has RenderBounds as property, but InventoryWindow has it as a method. This should be consistent. - public FloatRect RenderBounds() - { - var tempSlot = Items[0]; - var rect = new FloatRect() - { - X = ToCanvas(new Point(0, 0)).X - (tempSlot.Padding.Left + tempSlot.Padding.Right) / 2, - Y = ToCanvas(new Point(0, 0)).Y - (tempSlot.Padding.Top + tempSlot.Padding.Bottom) / 2, - Width = Width + tempSlot.Padding.Left + tempSlot.Padding.Right, - Height = Height + tempSlot.Padding.Top + tempSlot.Padding.Bottom - }; - - return rect; - } } diff --git a/Intersect.Client.Core/Interface/Game/SlotItem.cs b/Intersect.Client.Core/Interface/Game/SlotItem.cs index fd47cfa32f..2d66abd3e4 100644 --- a/Intersect.Client.Core/Interface/Game/SlotItem.cs +++ b/Intersect.Client.Core/Interface/Game/SlotItem.cs @@ -17,7 +17,7 @@ public SlotItem(Base parent, string name, int index, ContextMenu? contextMenu) : Margin = new Margin(4); MouseInputEnabled = true; - _iconImage = new ImagePanel(this, "Icon") + _iconImage = new Draggable(this, "Icon") { MinimumSize = new Point(32, 32), MouseInputEnabled = true, diff --git a/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs b/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs index 67a1c75c87..207a09735d 100644 --- a/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs +++ b/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs @@ -1,7 +1,6 @@ using Intersect.Client.Core; using Intersect.Client.Framework.Content; using Intersect.Client.Framework.File_Management; -using Intersect.Client.Framework.GenericClasses; using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; @@ -11,7 +10,6 @@ using Intersect.Client.Interface.Game.DescriptionWindows; using Intersect.Client.Localization; using Intersect.Configuration; -using Intersect.Framework.Core; using Intersect.GameObjects; using Intersect.Utilities; @@ -22,17 +20,8 @@ public partial class SpellItem : SlotItem // Controls private readonly Label _cooldownLabel; private readonly SpellsWindow _spellWindow; - private Draggable? _dragIcon; private SpellDescriptionWindow? _descriptionWindow; - // Drag Handling - public bool IsDragging; - private bool _canDrag; - private long _clickTime; - private bool _mouseOver; - private int _mouseX = -1; - private int _mouseY = -1; - // Context Menu Handling private readonly MenuItem _useSpellMenuItem; private readonly MenuItem _forgetSpellMenuItem; @@ -122,20 +111,13 @@ private void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) return; } - _mouseOver = true; - _canDrag = true; - if (Globals.InputManager.IsMouseButtonDown(MouseButton.Left)) { - _canDrag = false; return; } - if (_descriptionWindow != null) - { - _descriptionWindow.Dispose(); - _descriptionWindow = null; - } + _descriptionWindow?.Dispose(); + _descriptionWindow = null; if (Globals.Me?.Spells is not { Length: > 0 } spellSlots) { @@ -147,35 +129,22 @@ private void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) private void _iconImage_HoverLeave(Base sender, EventArgs arguments) { - _mouseOver = false; - _mouseX = -1; - _mouseY = -1; - - if (_descriptionWindow != null) - { - _descriptionWindow.Dispose(); - _descriptionWindow = null; - } + _descriptionWindow?.Dispose(); + _descriptionWindow = null; } private void _iconImage_Clicked(Base sender, MouseButtonState arguments) { - switch (arguments.MouseButton) + if (arguments.MouseButton is MouseButton.Right) { - case MouseButton.Left: - _clickTime = Timing.Global.MillisecondsUtc + 500; - break; - - case MouseButton.Right: - if (ClientConfiguration.Instance.EnableContextMenus) - { - OpenContextMenu(); - } - else - { - Globals.Me?.TryForgetSpell(SlotIndex); - } - break; + if (ClientConfiguration.Instance.EnableContextMenus) + { + OpenContextMenu(); + } + else + { + Globals.Me?.TryForgetSpell(SlotIndex); + } } } @@ -206,7 +175,8 @@ public override void Update() return; } - _cooldownLabel.IsVisibleInParent = !IsDragging && Globals.Me.IsSpellOnCooldown(SlotIndex); + //TODO: dont show when is dragging + _cooldownLabel.IsVisibleInParent = Globals.Me.IsSpellOnCooldown(SlotIndex); if (_cooldownLabel.IsVisibleInParent) { var itemCooldownRemaining = Globals.Me.GetSpellRemainingCooldown(SlotIndex); @@ -239,151 +209,5 @@ public override void Update() _descriptionWindow?.Dispose(); _descriptionWindow = null; } - - if (!IsDragging) - { - if (_mouseOver) - { - if (!Globals.InputManager.IsMouseButtonDown(MouseButton.Left)) - { - _canDrag = true; - _mouseX = -1; - _mouseY = -1; - if (Timing.Global.MillisecondsUtc < _clickTime) - { - _clickTime = 0; - } - } - else - { - if (_canDrag && Draggable.Active == null) - { - if (_mouseX == -1 || _mouseY == -1) - { - _mouseX = InputHandler.MousePosition.X - _iconImage.ToCanvas(new Point(0, 0)).X; - _mouseY = InputHandler.MousePosition.Y - _iconImage.ToCanvas(new Point(0, 0)).Y; - } - else - { - var xdiff = _mouseX - - (InputHandler.MousePosition.X - _iconImage.ToCanvas(new Point(0, 0)).X); - - var ydiff = _mouseY - - (InputHandler.MousePosition.Y - _iconImage.ToCanvas(new Point(0, 0)).Y); - - if (Math.Sqrt(Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2)) > 5) - { - IsDragging = true; - _iconImage.IsVisibleInParent = false; - _dragIcon = new Draggable( - _iconImage.ToCanvas(new Point(0, 0)).X + _mouseX, - _iconImage.ToCanvas(new Point(0, 0)).X + _mouseY, _iconImage.Texture, _iconImage.RenderColor - ); - } - } - } - } - } - } - else - { - if (_dragIcon?.Update() == true) - { - //Drug the item and now we stopped - IsDragging = false; - _iconImage.IsVisibleInParent = true; - - var dragRect = new FloatRect( - _dragIcon.X - (Padding.Left + Padding.Right) / 2f, - _dragIcon.Y - (Padding.Top + Padding.Bottom) / 2f, - (Padding.Left + Padding.Right) / 2f + _iconImage.Width, - (Padding.Top + Padding.Bottom) / 2f + _iconImage.Height - ); - - float bestIntersect = 0; - var bestIntersectIndex = -1; - - //So we picked up an item and then dropped it. Lets see where we dropped it to. - //Check spell first. - if (_spellWindow.RenderBounds().IntersectsWith(dragRect)) - { - for (var i = 0; i < Options.Instance.Player.MaxSpells; i++) - { - if (_spellWindow.Items[i] is not SpellItem spellSlot) - { - continue; - } - - if (i < _spellWindow.Items.Count && - spellSlot.RenderBounds().IntersectsWith(dragRect)) - { - if (FloatRect.Intersect(spellSlot.RenderBounds(), dragRect).Width * - FloatRect.Intersect(spellSlot.RenderBounds(), dragRect).Height > - bestIntersect) - { - bestIntersect = - FloatRect.Intersect(spellSlot.RenderBounds(), dragRect).Width * - FloatRect.Intersect(spellSlot.RenderBounds(), dragRect).Height; - - bestIntersectIndex = i; - } - } - } - - if (bestIntersectIndex > -1) - { - if (SlotIndex != bestIntersectIndex && !Globals.Me.IsCasting) - { - Globals.Me.SwapSpells(bestIntersectIndex, SlotIndex); - } - } - } - else if (Interface.GameUi.Hotbar.RenderBounds().IntersectsWith(dragRect)) - { - for (var i = 0; i < Options.Instance.Player.HotbarSlotCount; i++) - { - if (Interface.GameUi.Hotbar.Items[i].RenderBounds().IntersectsWith(dragRect)) - { - if (FloatRect.Intersect( - Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect - ) - .Width * - FloatRect.Intersect(Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect) - .Height > - bestIntersect) - { - bestIntersect = - FloatRect.Intersect(Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect) - .Width * - FloatRect.Intersect(Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect) - .Height; - - bestIntersectIndex = i; - } - } - } - - if (bestIntersectIndex > -1) - { - Globals.Me.AddToHotbar((byte) bestIntersectIndex, 1, SlotIndex); - } - } - - _dragIcon.Dispose(); - } - } - } - - public FloatRect RenderBounds() - { - var rect = new FloatRect() - { - X = _iconImage.ToCanvas(new Point(0, 0)).X, - Y = _iconImage.ToCanvas(new Point(0, 0)).Y, - Width = _iconImage.Width, - Height = _iconImage.Height - }; - - return rect; } } diff --git a/Intersect.Client.Core/Interface/Game/Spells/SpellsWindow.cs b/Intersect.Client.Core/Interface/Game/Spells/SpellsWindow.cs index a0c9500dcb..e6cef096cc 100644 --- a/Intersect.Client.Core/Interface/Game/Spells/SpellsWindow.cs +++ b/Intersect.Client.Core/Interface/Game/Spells/SpellsWindow.cs @@ -76,19 +76,4 @@ public override void Hide() _contextMenu?.Close(); base.Hide(); } - - public FloatRect RenderBounds() - { - var rect = new FloatRect() - { - X = ToCanvas(new Point(0, 0)).X - - (Items[0].Padding.Left + Items[0].Padding.Right) / 2, - Y = ToCanvas(new Point(0, 0)).Y - - (Items[0].Padding.Top + Items[0].Padding.Bottom) / 2, - Width = Width + Items[0].Padding.Left + Items[0].Padding.Right, - Height = Height + Items[0].Padding.Top + Items[0].Padding.Bottom - }; - - return rect; - } } diff --git a/Intersect.Client.Framework/Gwen/DragDrop/DragAndDrop.cs b/Intersect.Client.Framework/Gwen/DragDrop/DragAndDrop.cs index e978fccd1e..270e63e38a 100644 --- a/Intersect.Client.Framework/Gwen/DragDrop/DragAndDrop.cs +++ b/Intersect.Client.Framework/Gwen/DragDrop/DragAndDrop.cs @@ -1,4 +1,4 @@ -using Intersect.Client.Framework.GenericClasses; +using Intersect.Client.Framework.GenericClasses; using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Input; @@ -78,7 +78,6 @@ private static bool ShouldStartDraggingControl(int x, int y) SourceControl = sLastPressedControl; InputHandler.MouseFocus = null; sLastPressedControl = null; - CurrentPackage.DrawControl = null; // Some controls will want to decide whether they should be dragged at that moment. // This function is for them (it defaults to true) From e33fad4a9aafebde08c7ef1cb2e5f786bd027d32 Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Thu, 13 Mar 2025 11:06:49 -0300 Subject: [PATCH 02/16] added drag and drop logic on slot items --- .../Interface/Game/Bag/BagItem.cs | 39 +++++++++ .../Interface/Game/Bank/BankItem.cs | 84 +++++++++++++++++++ .../Interface/Game/Draggable.cs | 7 ++ .../Interface/Game/Hotbar/HotbarItem.cs | 30 +++++++ .../Interface/Game/Inventory/InventoryItem.cs | 80 ++++++++++++++++++ .../Interface/Game/Shop/ShopItem.cs | 1 + .../Interface/Game/SlotItem.cs | 2 +- .../Interface/Game/Spells/SpellItem.cs | 38 +++++++++ .../Gwen/Control/Base.cs | 2 +- 9 files changed, 281 insertions(+), 2 deletions(-) diff --git a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs index 887977770b..a01ae1ffa3 100644 --- a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs @@ -3,11 +3,14 @@ using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; +using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.Framework.Gwen.Input; using Intersect.Client.Framework.Input; using Intersect.Client.General; using Intersect.Client.Interface.Game.DescriptionWindows; +using Intersect.Client.Interface.Game.Inventory; using Intersect.Client.Localization; +using Intersect.Client.Networking; using Intersect.Configuration; using Intersect.Framework.Core.GameObjects.Items; @@ -150,6 +153,42 @@ private void _iconImage_DoubleClicked(Base sender, MouseButtonState arguments) #endregion + #region Drag and Drop + + public override bool DragAndDrop_HandleDrop(Package package, int x, int y) + { + var targetNode = Interface.FindComponentUnderCursor(NodeFilter.None); + + // Find the first parent acceptable in that tree that can accept the package + while (targetNode != default) + { + switch (targetNode) + { + case BagItem bagItem: + PacketSender.SendMoveBagItems(SlotIndex, bagItem.SlotIndex); + return true; + + case InventoryItem inventoryItem: + Globals.Me?.TryRetrieveItemFromBag(SlotIndex, inventoryItem.SlotIndex); + return true; + + default: + targetNode = targetNode.Parent; + break; + } + + // If we've reached the top of the tree, we can't drop here, so cancel drop + if (targetNode == null) + { + return false; + } + } + + return false; + } + + #endregion + public override void Update() { if (Globals.Me == default) diff --git a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs index 7790bc9fee..c818696340 100644 --- a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs @@ -4,12 +4,17 @@ using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; +using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.Framework.Gwen.Input; using Intersect.Client.Framework.Input; using Intersect.Client.General; +using Intersect.Client.Interface.Game.Chat; using Intersect.Client.Interface.Game.DescriptionWindows; +using Intersect.Client.Interface.Game.Inventory; using Intersect.Client.Localization; +using Intersect.Client.Networking; using Intersect.Configuration; +using Intersect.Enums; using Intersect.Framework.Core.GameObjects.Items; namespace Intersect.Client.Interface.Game.Bank; @@ -52,6 +57,8 @@ public BankItem(BankWindow bankWindow, Base parent, int index, ContextMenu conte contextMenu.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString()); } + #region Context Menu + protected override void OnContextMenuOpening(ContextMenu contextMenu) { if (Globals.BankSlots is not { Length: > 0 } bankSlots) @@ -77,6 +84,8 @@ private void _withdrawMenuItem_Clicked(Base sender, MouseButtonState arguments) Globals.Me?.TryRetrieveItemFromBank(SlotIndex); } + #endregion + #region Mouse Events private void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) @@ -170,6 +179,81 @@ private void _iconImage_DoubleClicked(Base sender, MouseButtonState arguments) #endregion + #region Drag and Drop + + public override bool DragAndDrop_HandleDrop(Package package, int x, int y) + { + var targetNode = Interface.FindComponentUnderCursor(NodeFilter.None); + + // Find the first parent acceptable in that tree that can accept the package + while (targetNode != default) + { + switch (targetNode) + { + case BankItem bankItem: + if (Globals.IsGuildBank) + { + if (Globals.Me is not { } player) + { + return false; + } + + var rank = player.GuildRank; + var isInGuild = !string.IsNullOrWhiteSpace(player.Guild); + if (!isInGuild || (player.Rank != 0 && rank?.Permissions.BankDeposit == false)) + { + ChatboxMsg.AddMessage( + new ChatboxMsg( + Strings.Guilds.NotAllowedSwap.ToString(player.Guild), + CustomColors.Alerts.Error, + ChatMessageType.Bank + ) + ); + + return false; + } + } + + PacketSender.SendMoveBankItems(SlotIndex, bankItem.SlotIndex); + return true; + + case InventoryItem inventoryItem: + + if (Globals.BankSlots is not { Length: > 0 } bankSlots) + { + return false; + } + + if (bankSlots[SlotIndex] is not { Quantity: > 0 } slot) + { + return false; + } + + Globals.Me?.TryRetrieveItemFromBank( + SlotIndex, + inventorySlotIndex: inventoryItem.SlotIndex, + quantityHint: slot.Quantity, + skipPrompt: true + ); + return true; + + default: + targetNode = targetNode.Parent; + break; + } + + // If we've reached the top of the tree, we can't drop here, so cancel drop + if (targetNode == null) + { + return false; + } + } + + return false; + } + + #endregion + public new void Update() { if (Globals.Me == default) diff --git a/Intersect.Client.Core/Interface/Game/Draggable.cs b/Intersect.Client.Core/Interface/Game/Draggable.cs index 2a2b8a5540..69bff13620 100644 --- a/Intersect.Client.Core/Interface/Game/Draggable.cs +++ b/Intersect.Client.Core/Interface/Game/Draggable.cs @@ -6,6 +6,8 @@ namespace Intersect.Client.Interface.Game; public partial class Draggable(Base parent, string name) : ImagePanel(parent, name) { + public bool DisableDragAndDrop { get; set; } = false; + public override bool DragAndDrop_Draggable() { return true; @@ -13,6 +15,11 @@ public override bool DragAndDrop_Draggable() public override Package DragAndDrop_GetPackage(int x, int y) { + if (DisableDragAndDrop) + { + return null; + } + return new Package() { IsDraggable = true, diff --git a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs index 4588068262..e4c07b1847 100644 --- a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs +++ b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs @@ -4,10 +4,13 @@ using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; +using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.Framework.Gwen.Input; using Intersect.Client.Framework.Input; using Intersect.Client.General; using Intersect.Client.Interface.Game.DescriptionWindows; +using Intersect.Client.Interface.Game.Inventory; +using Intersect.Client.Interface.Game.Spells; using Intersect.Client.Items; using Intersect.Client.Localization; using Intersect.Client.Spells; @@ -206,6 +209,33 @@ private void _iconImage_HoverEnter(Base sender, EventArgs arguments) } } + public override bool DragAndDrop_HandleDrop(Package package, int x, int y) + { + var targetNode = Interface.FindComponentUnderCursor(NodeFilter.None); + + // Find the first parent acceptable in that tree that can accept the package + while (targetNode != default) + { + if (targetNode is HotbarItem hotbarItem) + { + Globals.Me?.HotbarSwap(SlotIndex, hotbarItem.SlotIndex); + return true; + } + else + { + targetNode = targetNode.Parent; + } + + // If we've reached the top of the tree, we can't drop here, so cancel drop + if (targetNode == null) + { + return false; + } + } + + return false; + } + public void Update() { if (Globals.Me == null || Controls.ActiveControls == null) diff --git a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs index e526d8f61e..279bf8b47a 100644 --- a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs +++ b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs @@ -5,11 +5,17 @@ using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; +using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.Framework.Gwen.Input; using Intersect.Client.Framework.Input; using Intersect.Client.General; +using Intersect.Client.Interface.Game.Bag; +using Intersect.Client.Interface.Game.Bank; using Intersect.Client.Interface.Game.DescriptionWindows; +using Intersect.Client.Interface.Game.Hotbar; +using Intersect.Client.Interface.Game.Shop; using Intersect.Client.Localization; +using Intersect.Client.Networking; using Intersect.Configuration; using Intersect.Framework.Core.GameObjects.Items; using Intersect.GameObjects; @@ -395,6 +401,80 @@ void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) #endregion + #region Drag and Drop + + public override bool DragAndDrop_HandleDrop(Package package, int x, int y) + { + if (Globals.Me?.Inventory is not { } inventory) + { + return false; + } + + if (inventory[SlotIndex] is not { } inventorySlot) + { + return false; + } + + if (!Interface.DoesMouseHitInterface() && !Globals.Me.IsBusy) + { + PacketSender.SendDropItem(SlotIndex, inventorySlot.Quantity); + return true; + } + + var targetNode = Interface.FindComponentUnderCursor(NodeFilter.None); + + // Find the first parent acceptable in that tree that can accept the package + while (targetNode != default) + { + switch (targetNode) + { + case InventoryItem inventoryItem: + if (inventoryItem.SlotIndex == SlotIndex) + { + return false; + } + + Globals.Me?.SwapItems(SlotIndex, inventoryItem.SlotIndex); + return true; + + case BagItem bagItem: + Globals.Me?.TryStoreItemInBag(SlotIndex, bagItem.SlotIndex); + return true; + + case BankItem bankItem: + Globals.Me?.TryStoreItemInBank( + SlotIndex, + bankSlotIndex: bankItem.SlotIndex, + quantityHint: inventorySlot.Quantity, + skipPrompt: true + ); + return true; + + case HotbarItem hotbarItem: + Globals.Me?.AddToHotbar(hotbarItem.SlotIndex, 0, SlotIndex); + return true; + + case ShopWindow: + Globals.Me?.TrySellItem(SlotIndex); + return true; + + default: + targetNode = targetNode.Parent; + break; + } + + // If we've reached the top of the tree, we can't drop here, so return false + if (targetNode == null) + { + return false; + } + } + + return false; + } + + #endregion + private void PlayerOnInventoryUpdated(Player player, int slotIndex) { if (player != Globals.Me) diff --git a/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs b/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs index 235eedf673..be89f11228 100644 --- a/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs +++ b/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs @@ -30,6 +30,7 @@ public ShopItem(ShopWindow shopWindow, Base parent, int index, ContextMenu conte _iconImage.HoverLeave += _iconImage_HoverLeave; _iconImage.Clicked += _iconImage_RightClicked; _iconImage.DoubleClicked += _iconImage_DoubleClicked; + _iconImage.DisableDragAndDrop = true; LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString()); diff --git a/Intersect.Client.Core/Interface/Game/SlotItem.cs b/Intersect.Client.Core/Interface/Game/SlotItem.cs index 2d66abd3e4..8404d5399f 100644 --- a/Intersect.Client.Core/Interface/Game/SlotItem.cs +++ b/Intersect.Client.Core/Interface/Game/SlotItem.cs @@ -6,7 +6,7 @@ namespace Intersect.Client.Interface.Game; public partial class SlotItem : ImagePanel { public readonly int SlotIndex; - protected readonly ImagePanel _iconImage; + protected readonly Draggable _iconImage; protected readonly ContextMenu? _contextMenu; public SlotItem(Base parent, string name, int index, ContextMenu? contextMenu) : base(parent, name) diff --git a/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs b/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs index 207a09735d..323cc95b9d 100644 --- a/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs +++ b/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs @@ -4,10 +4,12 @@ using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; +using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.Framework.Gwen.Input; using Intersect.Client.Framework.Input; using Intersect.Client.General; using Intersect.Client.Interface.Game.DescriptionWindows; +using Intersect.Client.Interface.Game.Hotbar; using Intersect.Client.Localization; using Intersect.Configuration; using Intersect.GameObjects; @@ -155,6 +157,42 @@ private void _iconImage_DoubleClicked(Base sender, MouseButtonState arguments) #endregion + #region Drag and Drop + + public override bool DragAndDrop_HandleDrop(Package package, int x, int y) + { + var targetNode = Interface.FindComponentUnderCursor(NodeFilter.None); + + // Find the first parent acceptable in that tree that can accept the package + while (targetNode != default) + { + switch (targetNode) + { + case SpellItem spellItem: + Globals.Me?.SwapSpells(SlotIndex, spellItem.SlotIndex); + return true; + + case HotbarItem hotbarItem: + Globals.Me?.AddToHotbar(hotbarItem.SlotIndex, 1, SlotIndex); + return true; + + default: + targetNode = targetNode.Parent; + break; + } + + // If we've reached the top of the tree, we can't drop here, so cancel drop + if (targetNode == null) + { + return false; + } + } + + return false; + } + + #endregion + public override void Update() { if (Globals.Me == default) diff --git a/Intersect.Client.Framework/Gwen/Control/Base.cs b/Intersect.Client.Framework/Gwen/Control/Base.cs index 963cab2af3..ac17834f23 100644 --- a/Intersect.Client.Framework/Gwen/Control/Base.cs +++ b/Intersect.Client.Framework/Gwen/Control/Base.cs @@ -4330,7 +4330,7 @@ public virtual void DragAndDrop_Hover(Package p, int x, int y) // receiver public virtual bool DragAndDrop_CanAcceptPackage(Package p) { - return false; + return true; } public record struct SizeToChildrenArgs( From b5a4cd3dc722ebf5d3934f44935c58716643909f Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Thu, 13 Mar 2025 11:46:53 -0300 Subject: [PATCH 03/16] dont interact when is dragging --- Intersect.Client.Core/Entities/Entity.cs | 3 ++- Intersect.Client.Core/Entities/Player.cs | 6 ++++++ Intersect.Client.Framework/Gwen/DragDrop/DragAndDrop.cs | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Intersect.Client.Core/Entities/Entity.cs b/Intersect.Client.Core/Entities/Entity.cs index e77882db54..84aebf7365 100644 --- a/Intersect.Client.Core/Entities/Entity.cs +++ b/Intersect.Client.Core/Entities/Entity.cs @@ -7,6 +7,7 @@ using Intersect.Client.Framework.Entities; using Intersect.Client.Framework.GenericClasses; using Intersect.Client.Framework.Graphics; +using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.Framework.Items; using Intersect.Client.Framework.Maps; using Intersect.Client.General; @@ -1368,7 +1369,7 @@ private int NormalSpriteAnimationFrame // Checks if the entity is attacking or not. // Note: the calculation differs with IsAttacking because // frames are intended to behave differently with normal sprite-sheets. - else if (AttackTimer - (CalculateAttackTime() / 2) > Timing.Global.Milliseconds) + else if (AttackTimer - (CalculateAttackTime() / 2) > Timing.Global.Milliseconds && !DragAndDrop.IsDragging) { frame = Options.Instance.Sprites.NormalAttackFrame; } diff --git a/Intersect.Client.Core/Entities/Player.cs b/Intersect.Client.Core/Entities/Player.cs index 3ec3afaf2b..f2961ab817 100644 --- a/Intersect.Client.Core/Entities/Player.cs +++ b/Intersect.Client.Core/Entities/Player.cs @@ -7,6 +7,7 @@ using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; using Intersect.Client.Framework.Gwen.Control.EventArguments.InputSubmissionEvent; +using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.Framework.Input; using Intersect.Client.Framework.Items; using Intersect.Client.General; @@ -1960,6 +1961,11 @@ public bool TryAttack() return false; } + if (DragAndDrop.IsDragging) + { + return false; + } + int x = Globals.Me.X; int y = Globals.Me.Y; var map = Globals.Me.MapId; diff --git a/Intersect.Client.Framework/Gwen/DragDrop/DragAndDrop.cs b/Intersect.Client.Framework/Gwen/DragDrop/DragAndDrop.cs index 270e63e38a..97f634e58b 100644 --- a/Intersect.Client.Framework/Gwen/DragDrop/DragAndDrop.cs +++ b/Intersect.Client.Framework/Gwen/DragDrop/DragAndDrop.cs @@ -27,6 +27,8 @@ public static partial class DragAndDrop public static Base SourceControl; + public static bool IsDragging => CurrentPackage != default; + private static bool OnDrop(int x, int y) { var success = false; From 01a76a2491aeae7056be1e2edbfe4efc78f95b81 Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Thu, 13 Mar 2025 12:15:08 -0300 Subject: [PATCH 04/16] expose icon image --- .../Interface/Game/Bag/BagItem.cs | 34 +++++++------- .../Interface/Game/Bank/BankItem.cs | 34 +++++++------- .../Interface/Game/Hotbar/HotbarItem.cs | 44 +++++++++++-------- .../Interface/Game/Inventory/InventoryItem.cs | 42 +++++++++--------- .../Interface/Game/Shop/ShopItem.cs | 24 +++++----- .../Interface/Game/SlotItem.cs | 4 +- .../Interface/Game/Spells/SpellItem.cs | 38 ++++++++-------- 7 files changed, 114 insertions(+), 106 deletions(-) diff --git a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs index a01ae1ffa3..6569f6172b 100644 --- a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs @@ -32,10 +32,10 @@ public BagItem(BagWindow bagWindow, Base parent, int index, ContextMenu contextM _bagWindow = bagWindow; TextureFilename = "bagitem.png"; - _iconImage.HoverEnter += _iconImage_HoverEnter; - _iconImage.HoverLeave += _iconImage_HoverLeave; - _iconImage.Clicked += _iconImage_Clicked; - _iconImage.DoubleClicked += _iconImage_DoubleClicked; + IconImage.HoverEnter += IconImage_HoverEnter; + IconImage.HoverLeave += IconImage_HoverLeave; + IconImage.Clicked += IconImage_Clicked; + IconImage.DoubleClicked += IconImage_DoubleClicked; _quantityLabel = new Label(this, "Quantity") { @@ -87,7 +87,7 @@ private void _withdrawMenuItem_Clicked(Base sender, MouseButtonState arguments) #region Mouse Events - private void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) + private void IconImage_HoverEnter(Base? sender, EventArgs? arguments) { if (InputHandler.MouseFocus != default) { @@ -122,13 +122,13 @@ private void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) ); } - private void _iconImage_HoverLeave(Base sender, EventArgs arguments) + private void IconImage_HoverLeave(Base sender, EventArgs arguments) { _descWindow?.Dispose(); _descWindow = default; } - private void _iconImage_Clicked(Base sender, MouseButtonState arguments) + private void IconImage_Clicked(Base sender, MouseButtonState arguments) { if (arguments.MouseButton is MouseButton.Right) { @@ -138,12 +138,12 @@ private void _iconImage_Clicked(Base sender, MouseButtonState arguments) } else { - _iconImage_DoubleClicked(sender, arguments); + IconImage_DoubleClicked(sender, arguments); } } } - private void _iconImage_DoubleClicked(Base sender, MouseButtonState arguments) + private void IconImage_DoubleClicked(Base sender, MouseButtonState arguments) { if (Globals.InBag) { @@ -204,7 +204,7 @@ public override void Update() if (bagSlots[SlotIndex] is not { Descriptor: not null } or { Quantity: <= 0 }) { _quantityLabel.IsVisibleInParent = false; - _iconImage.Texture = default; + IconImage.Texture = default; return; } @@ -218,7 +218,7 @@ public override void Update() _quantityLabel.Text = Strings.FormatQuantityAbbreviated(bagSlot.Quantity); } - if (_iconImage.TextureFilename == descriptor.Icon) + if (IconImage.TextureFilename == descriptor.Icon) { return; } @@ -226,16 +226,16 @@ public override void Update() var itemTexture = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); if (itemTexture != default) { - _iconImage.Texture = itemTexture; - _iconImage.RenderColor = descriptor.Color; - _iconImage.IsVisibleInParent = true; + IconImage.Texture = itemTexture; + IconImage.RenderColor = descriptor.Color; + IconImage.IsVisibleInParent = true; } else { - if (_iconImage.Texture != default) + if (IconImage.Texture != default) { - _iconImage.Texture = default; - _iconImage.IsVisibleInParent = false; + IconImage.Texture = default; + IconImage.IsVisibleInParent = false; } } diff --git a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs index c818696340..b336722a8c 100644 --- a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs @@ -35,10 +35,10 @@ public BankItem(BankWindow bankWindow, Base parent, int index, ContextMenu conte _bankWindow = bankWindow; TextureFilename = "bankitem.png"; - _iconImage.HoverEnter += _iconImage_HoverEnter; - _iconImage.HoverLeave += _iconImage_HoverLeave; - _iconImage.Clicked += _iconImage_Clicked; - _iconImage.DoubleClicked += _iconImage_DoubleClicked; + IconImage.HoverEnter += IconImage_HoverEnter; + IconImage.HoverLeave += IconImage_HoverLeave; + IconImage.Clicked += IconImage_Clicked; + IconImage.DoubleClicked += IconImage_DoubleClicked; _quantityLabel = new Label(this, "Quantity") { @@ -88,7 +88,7 @@ private void _withdrawMenuItem_Clicked(Base sender, MouseButtonState arguments) #region Mouse Events - private void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) + private void IconImage_HoverEnter(Base? sender, EventArgs? arguments) { if (InputHandler.MouseFocus != null) { @@ -124,13 +124,13 @@ private void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) ); } - private void _iconImage_HoverLeave(Base sender, EventArgs arguments) + private void IconImage_HoverLeave(Base sender, EventArgs arguments) { _descWindow?.Dispose(); _descWindow = default; } - private void _iconImage_Clicked(Base sender, MouseButtonState arguments) + private void IconImage_Clicked(Base sender, MouseButtonState arguments) { if (arguments.MouseButton is MouseButton.Right) { @@ -140,12 +140,12 @@ private void _iconImage_Clicked(Base sender, MouseButtonState arguments) } else { - _iconImage_DoubleClicked(sender, arguments); + IconImage_DoubleClicked(sender, arguments); } } } - private void _iconImage_DoubleClicked(Base sender, MouseButtonState arguments) + private void IconImage_DoubleClicked(Base sender, MouseButtonState arguments) { if (!Globals.InBank) { @@ -269,7 +269,7 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) if (bankSlots[SlotIndex] is not { Descriptor: not null } or { Quantity: <= 0 }) { _quantityLabel.IsVisibleInParent = false; - _iconImage.Texture = default; + IconImage.Texture = default; return; } @@ -283,7 +283,7 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) _quantityLabel.Text = Strings.FormatQuantityAbbreviated(bankSlot.Quantity); } - if (_iconImage.TextureFilename == descriptor.Icon) + if (IconImage.TextureFilename == descriptor.Icon) { return; } @@ -291,16 +291,16 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) var itemTexture = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); if (itemTexture != default) { - _iconImage.Texture = itemTexture; - _iconImage.RenderColor = descriptor.Color; - _iconImage.IsVisibleInParent = true; + IconImage.Texture = itemTexture; + IconImage.RenderColor = descriptor.Color; + IconImage.IsVisibleInParent = true; } else { - if (_iconImage.Texture != default) + if (IconImage.Texture != default) { - _iconImage.Texture = default; - _iconImage.IsVisibleInParent = false; + IconImage.Texture = default; + IconImage.IsVisibleInParent = false; } } diff --git a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs index e4c07b1847..8edd9b60d1 100644 --- a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs +++ b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs @@ -58,12 +58,12 @@ public HotbarItem(int hotbarSlotIndex, Base hotbarWindow) RestrictToParent = true; TextureFilename = "hotbaritem.png"; - // _iconImage is layered on top of the container (shows the Item or Spell Icon). - _iconImage.Name = $"{nameof(HotbarItem)}{SlotIndex}"; - _iconImage.SetPosition(1, 1); - _iconImage.HoverEnter += _iconImage_HoverEnter; - _iconImage.HoverLeave += _iconImage_HoverLeave; - _iconImage.Clicked += _iconImage_Clicked; + IconImage.Name = $"{nameof(HotbarItem)}{SlotIndex}"; + IconImage.SetPosition(1, 1); + IconImage.HoverEnter += IconImage_HoverEnter; + IconImage.HoverLeave += IconImage_HoverLeave; + IconImage.Clicked += IconImage_Clicked; + IconImage.DoubleClicked += IconImage_DoubleClicked; var font = GameContentManager.Current.GetFont("sourcesansproblack"); @@ -152,7 +152,7 @@ public void Activate() } } - private void _iconImage_Clicked(Base sender, MouseButtonState arguments) + private void IconImage_Clicked(Base sender, MouseButtonState arguments) { if (arguments.MouseButton is MouseButton.Right) { @@ -160,7 +160,15 @@ private void _iconImage_Clicked(Base sender, MouseButtonState arguments) } } - private void _iconImage_HoverLeave(Base sender, EventArgs arguments) + private void IconImage_DoubleClicked(Base sender, MouseButtonState arguments) + { + if (arguments.MouseButton is MouseButton.Left) + { + Activate(); + } + } + + private void IconImage_HoverLeave(Base sender, EventArgs arguments) { _itemDescWindow?.Dispose(); _itemDescWindow = null; @@ -169,7 +177,7 @@ private void _iconImage_HoverLeave(Base sender, EventArgs arguments) _spellDescWindow = null; } - private void _iconImage_HoverEnter(Base sender, EventArgs arguments) + private void IconImage_HoverEnter(Base sender, EventArgs arguments) { if (InputHandler.MouseFocus != null || Globals.Me == null) { @@ -391,8 +399,8 @@ public void Update() { if (_currentItem != null) { - _iconImage.Show(); - _iconImage.Texture = Globals.ContentManager.GetTexture( + IconImage.Show(); + IconImage.Texture = Globals.ContentManager.GetTexture( Framework.Content.TextureType.Item, _currentItem.Icon ); @@ -430,8 +438,8 @@ public void Update() } else if (_currentSpell != null) { - _iconImage.Show(); - _iconImage.Texture = Globals.ContentManager.GetTexture( + IconImage.Show(); + IconImage.Texture = Globals.ContentManager.GetTexture( Framework.Content.TextureType.Spell, _currentSpell.Icon ); @@ -459,7 +467,7 @@ public void Update() } else { - _iconImage.Hide(); + IconImage.Hide(); _textureLoaded = true; _isEquipped = false; _equipLabel.IsHidden = true; @@ -471,24 +479,24 @@ public void Update() { if (_currentSpell != null) { - _iconImage.RenderColor = new Color(60, 255, 255, 255); + IconImage.RenderColor = new Color(60, 255, 255, 255); } if (_currentItem != null) { - _iconImage.RenderColor = new Color(60, _currentItem.Color.R, _currentItem.Color.G, _currentItem.Color.B); + IconImage.RenderColor = new Color(60, _currentItem.Color.R, _currentItem.Color.G, _currentItem.Color.B); } } else { if (_currentSpell != null) { - _iconImage.RenderColor = Color.White; + IconImage.RenderColor = Color.White; } if (_currentItem != null) { - _iconImage.RenderColor = _currentItem.Color; + IconImage.RenderColor = _currentItem.Color; } } } diff --git a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs index 279bf8b47a..be4b479e93 100644 --- a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs +++ b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs @@ -44,10 +44,10 @@ public InventoryItem(InventoryWindow inventoryWindow, Base parent, int index, Co _inventoryWindow = inventoryWindow; TextureFilename = "inventoryitem.png"; - _iconImage.HoverEnter += _iconImage_HoverEnter; - _iconImage.HoverLeave += _iconImage_HoverLeave; - _iconImage.Clicked += _iconImage_Clicked; - _iconImage.DoubleClicked += _iconImage_DoubleClicked; + IconImage.HoverEnter += IconImage_HoverEnter; + IconImage.HoverLeave += IconImage_HoverLeave; + IconImage.Clicked += IconImage_Clicked; + IconImage.DoubleClicked += IconImage_DoubleClicked; _equipImageBackground = new ImagePanel(this, "EquippedIcon") { @@ -214,7 +214,7 @@ private void _dropItemContextItem_Clicked(Base sender, Framework.Gwen.Control.Ev #region Mouse Events - private void _iconImage_DoubleClicked(Base sender, MouseButtonState arguments) + private void IconImage_DoubleClicked(Base sender, MouseButtonState arguments) { if (Globals.Me == default) { @@ -259,7 +259,7 @@ private void _iconImage_DoubleClicked(Base sender, MouseButtonState arguments) } } - private void _iconImage_Clicked(Base sender, MouseButtonState arguments) + private void IconImage_Clicked(Base sender, MouseButtonState arguments) { if (arguments.MouseButton is MouseButton.Right) { @@ -293,13 +293,13 @@ private void _iconImage_Clicked(Base sender, MouseButtonState arguments) } } - private void _iconImage_HoverLeave(Base sender, EventArgs arguments) + private void IconImage_HoverLeave(Base sender, EventArgs arguments) { _descWindow?.Dispose(); _descWindow = null; } - void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) + void IconImage_HoverEnter(Base? sender, EventArgs? arguments) { if (InputHandler.MouseFocus != null) { @@ -493,7 +493,7 @@ private void PlayerOnInventoryUpdated(Player player, int slotIndex) } // empty texture to reload on update - _iconImage.Texture = default; + IconImage.Texture = default; } public override void Update() @@ -533,14 +533,14 @@ public override void Update() { var itemCooldownRemaining = Globals.Me.GetItemRemainingCooldown(SlotIndex); _cooldownLabel.Text = TimeSpan.FromMilliseconds(itemCooldownRemaining).WithSuffix("0.0"); - _iconImage.RenderColor.A = 100; + IconImage.RenderColor.A = 100; } else { - _iconImage.RenderColor.A = descriptor.Color.A; + IconImage.RenderColor.A = descriptor.Color.A; } - if (_iconImage.TextureFilename == descriptor.Icon) + if (IconImage.TextureFilename == descriptor.Icon) { return; } @@ -548,18 +548,18 @@ public override void Update() var itemTexture = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); if (itemTexture != null) { - _iconImage.Texture = itemTexture; - _iconImage.RenderColor = Globals.Me.IsItemOnCooldown(SlotIndex) + IconImage.Texture = itemTexture; + IconImage.RenderColor = Globals.Me.IsItemOnCooldown(SlotIndex) ? new Color(100, descriptor.Color.R, descriptor.Color.G, descriptor.Color.B) : descriptor.Color; - _iconImage.IsVisibleInParent = true; + IconImage.IsVisibleInParent = true; } else { - if (_iconImage.Texture != null) + if (IconImage.Texture != null) { - _iconImage.Texture = null; - _iconImage.IsVisibleInParent = false; + IconImage.Texture = null; + IconImage.IsVisibleInParent = false; } } @@ -567,14 +567,14 @@ public override void Update() { _descWindow.Dispose(); _descWindow = null; - _iconImage_HoverEnter(null, null); + IconImage_HoverEnter(null, null); } } private void _reset() { - _iconImage.IsVisibleInParent = false; - _iconImage.Texture = default; + IconImage.IsVisibleInParent = false; + IconImage.Texture = default; _equipImageBackground.IsVisibleInParent = false; _quantityLabel.IsVisibleInParent = false; _equipLabel.IsVisibleInParent = false; diff --git a/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs b/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs index be89f11228..ccfd16cdeb 100644 --- a/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs +++ b/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs @@ -26,11 +26,11 @@ public ShopItem(ShopWindow shopWindow, Base parent, int index, ContextMenu conte _mySlot = index; TextureFilename = "shopitem.png"; - _iconImage.HoverEnter += _iconImage_HoverEnter; - _iconImage.HoverLeave += _iconImage_HoverLeave; - _iconImage.Clicked += _iconImage_RightClicked; - _iconImage.DoubleClicked += _iconImage_DoubleClicked; - _iconImage.DisableDragAndDrop = true; + IconImage.HoverEnter += IconImage_HoverEnter; + IconImage.HoverLeave += IconImage_HoverLeave; + IconImage.Clicked += IconImage_RightClicked; + IconImage.DoubleClicked += IconImage_DoubleClicked; + IconImage.DisableDragAndDrop = true; LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString()); @@ -42,7 +42,7 @@ public ShopItem(ShopWindow shopWindow, Base parent, int index, ContextMenu conte LoadItem(); } - private void _iconImage_HoverEnter(Base sender, EventArgs arguments) + private void IconImage_HoverEnter(Base sender, EventArgs arguments) { if (InputHandler.MouseFocus != null) { @@ -88,7 +88,7 @@ private void _iconImage_HoverEnter(Base sender, EventArgs arguments) } } - private void _iconImage_HoverLeave(Base sender, EventArgs arguments) + private void IconImage_HoverLeave(Base sender, EventArgs arguments) { if (_itemDescWindow != null) { @@ -97,7 +97,7 @@ private void _iconImage_HoverLeave(Base sender, EventArgs arguments) } } - private void _iconImage_RightClicked(Base sender, MouseButtonState arguments) + private void IconImage_RightClicked(Base sender, MouseButtonState arguments) { if (arguments.MouseButton != MouseButton.Right) { @@ -110,11 +110,11 @@ private void _iconImage_RightClicked(Base sender, MouseButtonState arguments) } else { - _iconImage_DoubleClicked(sender, arguments); + IconImage_DoubleClicked(sender, arguments); } } - private void _iconImage_DoubleClicked(Base sender, MouseButtonState arguments) + private void IconImage_DoubleClicked(Base sender, MouseButtonState arguments) { Globals.Me?.TryBuyItem(_mySlot); } @@ -157,8 +157,8 @@ public void LoadItem() var itemTex = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, itemDescriptor.Icon); if (itemTex != null) { - _iconImage.Texture = itemTex; - _iconImage.RenderColor = itemDescriptor.Color; + IconImage.Texture = itemTex; + IconImage.RenderColor = itemDescriptor.Color; } } } diff --git a/Intersect.Client.Core/Interface/Game/SlotItem.cs b/Intersect.Client.Core/Interface/Game/SlotItem.cs index 8404d5399f..570aee85ab 100644 --- a/Intersect.Client.Core/Interface/Game/SlotItem.cs +++ b/Intersect.Client.Core/Interface/Game/SlotItem.cs @@ -6,7 +6,7 @@ namespace Intersect.Client.Interface.Game; public partial class SlotItem : ImagePanel { public readonly int SlotIndex; - protected readonly Draggable _iconImage; + public readonly Draggable IconImage; protected readonly ContextMenu? _contextMenu; public SlotItem(Base parent, string name, int index, ContextMenu? contextMenu) : base(parent, name) @@ -17,7 +17,7 @@ public SlotItem(Base parent, string name, int index, ContextMenu? contextMenu) : Margin = new Margin(4); MouseInputEnabled = true; - _iconImage = new Draggable(this, "Icon") + IconImage = new Draggable(this, "Icon") { MinimumSize = new Point(32, 32), MouseInputEnabled = true, diff --git a/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs b/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs index 323cc95b9d..1bf6b0b7b2 100644 --- a/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs +++ b/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs @@ -34,10 +34,10 @@ public SpellItem(SpellsWindow spellWindow, Base parent, int index, ContextMenu c _spellWindow = spellWindow; TextureFilename = "spellitem.png"; - _iconImage.HoverEnter += _iconImage_HoverEnter; - _iconImage.HoverLeave += _iconImage_HoverLeave; - _iconImage.Clicked += _iconImage_Clicked; - _iconImage.DoubleClicked += _iconImage_DoubleClicked; + IconImage.HoverEnter += IconImage_HoverEnter; + IconImage.HoverLeave += IconImage_HoverLeave; + IconImage.Clicked += IconImage_Clicked; + IconImage.DoubleClicked += IconImage_DoubleClicked; _cooldownLabel = new Label(this, "CooldownLabel") { @@ -106,7 +106,7 @@ private void _forgetSpellMenuItem_Clicked(Base sender, MouseButtonState argument #region Mouse Events - private void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) + private void IconImage_HoverEnter(Base? sender, EventArgs? arguments) { if (InputHandler.MouseFocus != null) { @@ -129,13 +129,13 @@ private void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) _descriptionWindow = new SpellDescriptionWindow(spellSlots[SlotIndex].Id, _spellWindow.X, _spellWindow.Y); } - private void _iconImage_HoverLeave(Base sender, EventArgs arguments) + private void IconImage_HoverLeave(Base sender, EventArgs arguments) { _descriptionWindow?.Dispose(); _descriptionWindow = null; } - private void _iconImage_Clicked(Base sender, MouseButtonState arguments) + private void IconImage_Clicked(Base sender, MouseButtonState arguments) { if (arguments.MouseButton is MouseButton.Right) { @@ -150,7 +150,7 @@ private void _iconImage_Clicked(Base sender, MouseButtonState arguments) } } - private void _iconImage_DoubleClicked(Base sender, MouseButtonState arguments) + private void IconImage_DoubleClicked(Base sender, MouseButtonState arguments) { Globals.Me?.TryUseSpell(SlotIndex); } @@ -207,8 +207,8 @@ public override void Update() if (!SpellDescriptor.TryGet(spellSlots[SlotIndex].Id, out var spell)) { - _iconImage.Hide(); - _iconImage.Texture = null; + IconImage.Hide(); + IconImage.Texture = null; _cooldownLabel.Hide(); return; } @@ -219,28 +219,28 @@ public override void Update() { var itemCooldownRemaining = Globals.Me.GetSpellRemainingCooldown(SlotIndex); _cooldownLabel.Text = TimeSpan.FromMilliseconds(itemCooldownRemaining).WithSuffix("0.0"); - _iconImage.RenderColor.A = 100; + IconImage.RenderColor.A = 100; } else { - _iconImage.RenderColor.A = 255; + IconImage.RenderColor.A = 255; } - if (Path.GetFileName(_iconImage.Texture?.Name) != spell.Icon) + if (Path.GetFileName(IconImage.Texture?.Name) != spell.Icon) { var spellIconTexture = Globals.ContentManager?.GetTexture(TextureType.Spell, spell.Icon); if (spellIconTexture != null) { - _iconImage.Texture = spellIconTexture; - _iconImage.RenderColor.A = (byte)(_cooldownLabel.IsVisibleInParent ? 100 : 255); - _iconImage.IsVisibleInParent = true; + IconImage.Texture = spellIconTexture; + IconImage.RenderColor.A = (byte)(_cooldownLabel.IsVisibleInParent ? 100 : 255); + IconImage.IsVisibleInParent = true; } else { - if (_iconImage.Texture != null) + if (IconImage.Texture != null) { - _iconImage.Texture = null; - _iconImage.IsVisibleInParent = false; + IconImage.Texture = null; + IconImage.IsVisibleInParent = false; } } From 6dc060cde5138bfa00837986a5504ed1d896c1bd Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Thu, 13 Mar 2025 13:45:45 -0300 Subject: [PATCH 05/16] dont let player do some actions when is dragging --- Intersect.Client.Core/Core/Input.cs | 8 +++++++- .../Interface/Game/Bag/BagWindow.cs | 20 +++++++++++++------ .../Interface/Game/Bank/BankWindow.cs | 15 +++++++++++++- .../Interface/Game/Hotbar/HotBarWindow.cs | 12 +++++++++++ .../Game/Inventory/InventoryWindow.cs | 9 ++++++++- .../Interface/Game/Spells/SpellsWindow.cs | 9 ++++++++- 6 files changed, 63 insertions(+), 10 deletions(-) diff --git a/Intersect.Client.Core/Core/Input.cs b/Intersect.Client.Core/Core/Input.cs index 6920bea7b8..2fd9e0c37a 100644 --- a/Intersect.Client.Core/Core/Input.cs +++ b/Intersect.Client.Core/Core/Input.cs @@ -2,6 +2,7 @@ using Intersect.Client.Entities; using Intersect.Client.Framework.GenericClasses; using Intersect.Client.Framework.Graphics; +using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.Framework.Gwen.Input; using Intersect.Client.Framework.Input; using Intersect.Client.General; @@ -138,6 +139,11 @@ public static void OnKeyPressed(Keys modifier, Keys key) return; } + if (DragAndDrop.IsDragging) + { + return; + } + var gameUi = Interface.Interface.GameUi; // First try and unfocus chat then close all UI elements, then untarget our target.. and THEN open the escape menu. @@ -196,7 +202,7 @@ public static void OnKeyPressed(Keys modifier, Keys key) break; case Control.ToggleGui: - if (currentGameState == GameStates.InGame) + if (currentGameState == GameStates.InGame && !DragAndDrop.IsDragging) { Interface.Interface.HideUi = !Interface.Interface.HideUi; } diff --git a/Intersect.Client.Core/Interface/Game/Bag/BagWindow.cs b/Intersect.Client.Core/Interface/Game/Bag/BagWindow.cs index b9797994ec..b6439fbbd8 100644 --- a/Intersect.Client.Core/Interface/Game/Bag/BagWindow.cs +++ b/Intersect.Client.Core/Interface/Game/Bag/BagWindow.cs @@ -3,6 +3,7 @@ using Intersect.Client.Framework.GenericClasses; using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; +using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.General; using Intersect.Client.Localization; using Intersect.Client.Utilities; @@ -65,12 +66,6 @@ private void InitItemContainer() PopulateSlotContainer.Populate(_slotContainer, Items); } - public override void Hide() - { - _contextMenu?.Close(); - base.Hide(); - } - public void Update() { if (IsVisibleInTree == false) @@ -86,4 +81,17 @@ public void Update() } } } + + public override void Hide() + { + _contextMenu?.Close(); + + // dont hide window if we are dragging something + if (Items.Any(c => c.IconImage == DragAndDrop.CurrentPackage?.DrawControl)) + { + return; + } + + base.Hide(); + } } diff --git a/Intersect.Client.Core/Interface/Game/Bank/BankWindow.cs b/Intersect.Client.Core/Interface/Game/Bank/BankWindow.cs index 7323a9337d..3347c3061b 100644 --- a/Intersect.Client.Core/Interface/Game/Bank/BankWindow.cs +++ b/Intersect.Client.Core/Interface/Game/Bank/BankWindow.cs @@ -1,8 +1,8 @@ using Intersect.Client.Core; using Intersect.Client.Framework.File_Management; -using Intersect.Client.Framework.GenericClasses; using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; +using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.General; using Intersect.Client.Localization; using Intersect.Client.Utilities; @@ -89,4 +89,17 @@ public void Update() } } } + + public override void Hide() + { + _contextMenu?.Close(); + + // dont hide window if we are dragging something + if (Items.Any(c => c.IconImage == DragAndDrop.CurrentPackage?.DrawControl)) + { + return; + } + + base.Hide(); + } } diff --git a/Intersect.Client.Core/Interface/Game/Hotbar/HotBarWindow.cs b/Intersect.Client.Core/Interface/Game/Hotbar/HotBarWindow.cs index 53611d8dbd..63933038a8 100644 --- a/Intersect.Client.Core/Interface/Game/Hotbar/HotBarWindow.cs +++ b/Intersect.Client.Core/Interface/Game/Hotbar/HotBarWindow.cs @@ -3,6 +3,7 @@ using Intersect.Client.Framework.GenericClasses; using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; +using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.General; namespace Intersect.Client.Interface.Game.Hotbar; @@ -49,4 +50,15 @@ public void Update() slot.Update(); } } + + public override void Hide() + { + // dont hide window if we are dragging something + if (Items.Any(c => c.IconImage == DragAndDrop.CurrentPackage?.DrawControl)) + { + return; + } + + base.Hide(); + } } diff --git a/Intersect.Client.Core/Interface/Game/Inventory/InventoryWindow.cs b/Intersect.Client.Core/Interface/Game/Inventory/InventoryWindow.cs index 9d57c11b69..8b78dbd244 100644 --- a/Intersect.Client.Core/Interface/Game/Inventory/InventoryWindow.cs +++ b/Intersect.Client.Core/Interface/Game/Inventory/InventoryWindow.cs @@ -1,8 +1,8 @@ using Intersect.Client.Core; using Intersect.Client.Framework.File_Management; -using Intersect.Client.Framework.GenericClasses; using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; +using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.General; using Intersect.Client.Localization; using Intersect.Client.Utilities; @@ -97,6 +97,13 @@ public override void Hide() } _contextMenu?.Close(); + + // dont hide window if we are dragging something + if (Items.Any(c => c.IconImage == DragAndDrop.CurrentPackage?.DrawControl)) + { + return; + } + base.Hide(); } } diff --git a/Intersect.Client.Core/Interface/Game/Spells/SpellsWindow.cs b/Intersect.Client.Core/Interface/Game/Spells/SpellsWindow.cs index e6cef096cc..75e3626f1a 100644 --- a/Intersect.Client.Core/Interface/Game/Spells/SpellsWindow.cs +++ b/Intersect.Client.Core/Interface/Game/Spells/SpellsWindow.cs @@ -1,8 +1,8 @@ using Intersect.Client.Core; using Intersect.Client.Framework.File_Management; -using Intersect.Client.Framework.GenericClasses; using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; +using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.Localization; using Intersect.Client.Utilities; @@ -74,6 +74,13 @@ private void InitItemContainer() public override void Hide() { _contextMenu?.Close(); + + // dont hide window if we are dragging something + if (Items.Any(c => c.IconImage == DragAndDrop.CurrentPackage?.DrawControl)) + { + return; + } + base.Hide(); } } From aba53d55c89ecf6ef307c222df501628d91b513d Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Thu, 13 Mar 2025 15:34:33 -0300 Subject: [PATCH 06/16] hide details when dragging slot items --- .../Interface/Game/Bag/BagItem.cs | 3 +- .../Interface/Game/Bank/BankItem.cs | 3 +- .../Interface/Game/Draggable.cs | 2 ++ .../Interface/Game/Hotbar/HotbarItem.cs | 28 ++++++++++++------- .../Interface/Game/Inventory/InventoryItem.cs | 14 ++++------ .../Interface/Game/Spells/SpellItem.cs | 3 +- 6 files changed, 28 insertions(+), 25 deletions(-) diff --git a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs index 6569f6172b..b8cf2fc2c1 100644 --- a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs @@ -211,8 +211,7 @@ public override void Update() var bagSlot = bagSlots[SlotIndex]; var descriptor = bagSlot.Descriptor; - //TODO: dont show when is dragging - _quantityLabel.IsVisibleInParent = descriptor.IsStackable && bagSlot.Quantity > 1; + _quantityLabel.IsVisibleInParent = !IconImage.IsDragging && descriptor.IsStackable && bagSlot.Quantity > 1; if (_quantityLabel.IsVisibleInParent) { _quantityLabel.Text = Strings.FormatQuantityAbbreviated(bagSlot.Quantity); diff --git a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs index b336722a8c..30e258db8b 100644 --- a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs @@ -276,8 +276,7 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) var bankSlot = bankSlots[SlotIndex]; var descriptor = bankSlot.Descriptor; - //TODO: dont show when is dragging - _quantityLabel.IsVisibleInParent = descriptor.IsStackable && bankSlot.Quantity > 1; + _quantityLabel.IsVisibleInParent = !IconImage.IsDragging && descriptor.IsStackable && bankSlot.Quantity > 1; if (_quantityLabel.IsVisibleInParent) { _quantityLabel.Text = Strings.FormatQuantityAbbreviated(bankSlot.Quantity); diff --git a/Intersect.Client.Core/Interface/Game/Draggable.cs b/Intersect.Client.Core/Interface/Game/Draggable.cs index 69bff13620..0a50d73650 100644 --- a/Intersect.Client.Core/Interface/Game/Draggable.cs +++ b/Intersect.Client.Core/Interface/Game/Draggable.cs @@ -8,6 +8,8 @@ public partial class Draggable(Base parent, string name) : ImagePanel(parent, na { public bool DisableDragAndDrop { get; set; } = false; + public bool IsDragging => DragAndDrop.CurrentPackage?.DrawControl == this; + public override bool DragAndDrop_Draggable() { return true; diff --git a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs index 8edd9b60d1..f00c9945e2 100644 --- a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs +++ b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs @@ -9,8 +9,6 @@ using Intersect.Client.Framework.Input; using Intersect.Client.General; using Intersect.Client.Interface.Game.DescriptionWindows; -using Intersect.Client.Interface.Game.Inventory; -using Intersect.Client.Interface.Game.Spells; using Intersect.Client.Items; using Intersect.Client.Localization; using Intersect.Client.Spells; @@ -395,11 +393,25 @@ public void Update() } } + var isDragging = IconImage.IsDragging; + if (isDragging) + { + _equipLabel.IsHidden = true; + _quantityLabel.IsHidden = true; + _cooldownLabel.IsHidden = true; + } + else + { + _equipLabel.IsHidden = !_isEquipped || _inventoryItemIndex < 0; + _quantityLabel.IsHidden = _currentItem?.Stackable == false || _inventoryItemIndex < 0; + _cooldownLabel.IsHidden = !_isFaded || _inventoryItemIndex < 0; + } + if (updateDisplay) //Item on cd and fade is incorrect { if (_currentItem != null) { - IconImage.Show(); + IconImage.IsVisibleInTree = !isDragging; IconImage.Texture = Globals.ContentManager.GetTexture( Framework.Content.TextureType.Item, _currentItem.Icon ); @@ -413,7 +425,7 @@ public void Update() _isFaded = Globals.Me.IsItemOnCooldown(_inventoryItemIndex); _isEquipped = Globals.Me.IsEquipped(_inventoryItemIndex); - if (_isFaded) + if (_isFaded && !isDragging) { _cooldownLabel.IsHidden = false; _cooldownLabel.Text = TimeSpan @@ -430,15 +442,11 @@ public void Update() _isFaded = true; } - _equipLabel.IsHidden = !_isEquipped || _inventoryItemIndex < 0; - _quantityLabel.IsHidden = !_currentItem.Stackable || _inventoryItemIndex < 0; - _cooldownLabel.IsHidden = !_isFaded || _inventoryItemIndex < 0; - _textureLoaded = true; } else if (_currentSpell != null) { - IconImage.Show(); + IconImage.IsVisibleInTree = !isDragging; IconImage.Texture = Globals.ContentManager.GetTexture( Framework.Content.TextureType.Spell, _currentSpell.Icon ); @@ -450,7 +458,7 @@ public void Update() { var spellSlot = Globals.Me.FindHotbarSpell(slot); _isFaded = Globals.Me.IsSpellOnCooldown(spellSlot); - if (_isFaded) + if (_isFaded && !isDragging) { _cooldownLabel.IsHidden = false; var remaining = Globals.Me.GetSpellRemainingCooldown(spellSlot); diff --git a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs index be4b479e93..58a18c98be 100644 --- a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs +++ b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs @@ -1,7 +1,6 @@ using Intersect.Client.Core; using Intersect.Client.Entities; using Intersect.Client.Framework.File_Management; -using Intersect.Client.Framework.GenericClasses; using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; @@ -515,20 +514,17 @@ public override void Update() } var equipped = Globals.Me.MyEquipment.Any(s => s == SlotIndex); - //Todo: hide when dragging - _equipImageBackground.IsVisibleInParent = equipped; - //Todo: hide when dragging - _equipLabel.IsVisibleInParent = equipped; + var isDragging = IconImage.IsDragging; + _equipImageBackground.IsVisibleInParent = !isDragging && equipped; + _equipLabel.IsVisibleInParent = !isDragging && equipped; - //Todo: hide when dragging - _quantityLabel.IsVisibleInParent = descriptor.IsStackable && inventorySlot.Quantity > 1; + _quantityLabel.IsVisibleInParent = !isDragging && descriptor.IsStackable && inventorySlot.Quantity > 1; if (_quantityLabel.IsVisibleInParent) { _quantityLabel.Text = Strings.FormatQuantityAbbreviated(inventorySlot.Quantity); } - //Todo: hide when dragging - _cooldownLabel.IsVisibleInParent = Globals.Me.IsItemOnCooldown(SlotIndex); + _cooldownLabel.IsVisibleInParent = !isDragging && Globals.Me.IsItemOnCooldown(SlotIndex); if (_cooldownLabel.IsVisibleInParent) { var itemCooldownRemaining = Globals.Me.GetItemRemainingCooldown(SlotIndex); diff --git a/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs b/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs index 1bf6b0b7b2..13b24417f8 100644 --- a/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs +++ b/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs @@ -213,8 +213,7 @@ public override void Update() return; } - //TODO: dont show when is dragging - _cooldownLabel.IsVisibleInParent = Globals.Me.IsSpellOnCooldown(SlotIndex); + _cooldownLabel.IsVisibleInParent = !IconImage.IsDragging && Globals.Me.IsSpellOnCooldown(SlotIndex); if (_cooldownLabel.IsVisibleInParent) { var itemCooldownRemaining = Globals.Me.GetSpellRemainingCooldown(SlotIndex); From 5cdbf96d6d8b0fa59fe0364d9f290f0b2c80dbdb Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Fri, 14 Mar 2025 21:52:57 -0300 Subject: [PATCH 07/16] trying to block user input on root --- Intersect.Client.Core/Core/Input.cs | 5 +++++ Intersect.Client.Core/Entities/Entity.cs | 3 +-- Intersect.Client.Core/Entities/Player.cs | 6 ------ .../Interface/Game/Bag/BagWindow.cs | 9 --------- .../Interface/Game/Bank/BankWindow.cs | 8 -------- .../Interface/Game/Hotbar/HotBarWindow.cs | 13 ------------- .../Interface/Game/Hotbar/HotbarItem.cs | 5 +++++ .../Interface/Game/Inventory/InventoryWindow.cs | 8 -------- .../Interface/Game/Spells/SpellsWindow.cs | 8 -------- Intersect.Client.Framework/Input/ControlBinding.cs | 3 ++- 10 files changed, 13 insertions(+), 55 deletions(-) diff --git a/Intersect.Client.Core/Core/Input.cs b/Intersect.Client.Core/Core/Input.cs index 2fd9e0c37a..9371c1c192 100644 --- a/Intersect.Client.Core/Core/Input.cs +++ b/Intersect.Client.Core/Core/Input.cs @@ -255,6 +255,11 @@ public static void OnKeyPressed(Keys modifier, Keys key) break; } + if (DragAndDrop.IsDragging) + { + break; + } + switch (control) { case Control.Block: diff --git a/Intersect.Client.Core/Entities/Entity.cs b/Intersect.Client.Core/Entities/Entity.cs index 84aebf7365..e77882db54 100644 --- a/Intersect.Client.Core/Entities/Entity.cs +++ b/Intersect.Client.Core/Entities/Entity.cs @@ -7,7 +7,6 @@ using Intersect.Client.Framework.Entities; using Intersect.Client.Framework.GenericClasses; using Intersect.Client.Framework.Graphics; -using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.Framework.Items; using Intersect.Client.Framework.Maps; using Intersect.Client.General; @@ -1369,7 +1368,7 @@ private int NormalSpriteAnimationFrame // Checks if the entity is attacking or not. // Note: the calculation differs with IsAttacking because // frames are intended to behave differently with normal sprite-sheets. - else if (AttackTimer - (CalculateAttackTime() / 2) > Timing.Global.Milliseconds && !DragAndDrop.IsDragging) + else if (AttackTimer - (CalculateAttackTime() / 2) > Timing.Global.Milliseconds) { frame = Options.Instance.Sprites.NormalAttackFrame; } diff --git a/Intersect.Client.Core/Entities/Player.cs b/Intersect.Client.Core/Entities/Player.cs index f2961ab817..3ec3afaf2b 100644 --- a/Intersect.Client.Core/Entities/Player.cs +++ b/Intersect.Client.Core/Entities/Player.cs @@ -7,7 +7,6 @@ using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; using Intersect.Client.Framework.Gwen.Control.EventArguments.InputSubmissionEvent; -using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.Framework.Input; using Intersect.Client.Framework.Items; using Intersect.Client.General; @@ -1961,11 +1960,6 @@ public bool TryAttack() return false; } - if (DragAndDrop.IsDragging) - { - return false; - } - int x = Globals.Me.X; int y = Globals.Me.Y; var map = Globals.Me.MapId; diff --git a/Intersect.Client.Core/Interface/Game/Bag/BagWindow.cs b/Intersect.Client.Core/Interface/Game/Bag/BagWindow.cs index b6439fbbd8..7c88c48f93 100644 --- a/Intersect.Client.Core/Interface/Game/Bag/BagWindow.cs +++ b/Intersect.Client.Core/Interface/Game/Bag/BagWindow.cs @@ -1,9 +1,7 @@ using Intersect.Client.Core; using Intersect.Client.Framework.File_Management; -using Intersect.Client.Framework.GenericClasses; using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; -using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.General; using Intersect.Client.Localization; using Intersect.Client.Utilities; @@ -85,13 +83,6 @@ public void Update() public override void Hide() { _contextMenu?.Close(); - - // dont hide window if we are dragging something - if (Items.Any(c => c.IconImage == DragAndDrop.CurrentPackage?.DrawControl)) - { - return; - } - base.Hide(); } } diff --git a/Intersect.Client.Core/Interface/Game/Bank/BankWindow.cs b/Intersect.Client.Core/Interface/Game/Bank/BankWindow.cs index 3347c3061b..a618f1e7a7 100644 --- a/Intersect.Client.Core/Interface/Game/Bank/BankWindow.cs +++ b/Intersect.Client.Core/Interface/Game/Bank/BankWindow.cs @@ -2,7 +2,6 @@ using Intersect.Client.Framework.File_Management; using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; -using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.General; using Intersect.Client.Localization; using Intersect.Client.Utilities; @@ -93,13 +92,6 @@ public void Update() public override void Hide() { _contextMenu?.Close(); - - // dont hide window if we are dragging something - if (Items.Any(c => c.IconImage == DragAndDrop.CurrentPackage?.DrawControl)) - { - return; - } - base.Hide(); } } diff --git a/Intersect.Client.Core/Interface/Game/Hotbar/HotBarWindow.cs b/Intersect.Client.Core/Interface/Game/Hotbar/HotBarWindow.cs index 63933038a8..a5a8fc6059 100644 --- a/Intersect.Client.Core/Interface/Game/Hotbar/HotBarWindow.cs +++ b/Intersect.Client.Core/Interface/Game/Hotbar/HotBarWindow.cs @@ -1,9 +1,7 @@ using Intersect.Client.Core; using Intersect.Client.Framework.File_Management; -using Intersect.Client.Framework.GenericClasses; using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; -using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.General; namespace Intersect.Client.Interface.Game.Hotbar; @@ -50,15 +48,4 @@ public void Update() slot.Update(); } } - - public override void Hide() - { - // dont hide window if we are dragging something - if (Items.Any(c => c.IconImage == DragAndDrop.CurrentPackage?.DrawControl)) - { - return; - } - - base.Hide(); - } } diff --git a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs index f00c9945e2..8f0a9b0eb8 100644 --- a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs +++ b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs @@ -134,6 +134,11 @@ public void Activate() return; } + if (DragAndDrop.IsDragging) + { + return; + } + if (_currentId != Guid.Empty && Globals.Me != null) { if (_currentItem != null) diff --git a/Intersect.Client.Core/Interface/Game/Inventory/InventoryWindow.cs b/Intersect.Client.Core/Interface/Game/Inventory/InventoryWindow.cs index 8b78dbd244..10a7a8725b 100644 --- a/Intersect.Client.Core/Interface/Game/Inventory/InventoryWindow.cs +++ b/Intersect.Client.Core/Interface/Game/Inventory/InventoryWindow.cs @@ -2,7 +2,6 @@ using Intersect.Client.Framework.File_Management; using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; -using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.General; using Intersect.Client.Localization; using Intersect.Client.Utilities; @@ -97,13 +96,6 @@ public override void Hide() } _contextMenu?.Close(); - - // dont hide window if we are dragging something - if (Items.Any(c => c.IconImage == DragAndDrop.CurrentPackage?.DrawControl)) - { - return; - } - base.Hide(); } } diff --git a/Intersect.Client.Core/Interface/Game/Spells/SpellsWindow.cs b/Intersect.Client.Core/Interface/Game/Spells/SpellsWindow.cs index 75e3626f1a..5aa172d8fb 100644 --- a/Intersect.Client.Core/Interface/Game/Spells/SpellsWindow.cs +++ b/Intersect.Client.Core/Interface/Game/Spells/SpellsWindow.cs @@ -2,7 +2,6 @@ using Intersect.Client.Framework.File_Management; using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; -using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.Localization; using Intersect.Client.Utilities; @@ -74,13 +73,6 @@ private void InitItemContainer() public override void Hide() { _contextMenu?.Close(); - - // dont hide window if we are dragging something - if (Items.Any(c => c.IconImage == DragAndDrop.CurrentPackage?.DrawControl)) - { - return; - } - base.Hide(); } } diff --git a/Intersect.Client.Framework/Input/ControlBinding.cs b/Intersect.Client.Framework/Input/ControlBinding.cs index 1c4f05ab21..84243c3e89 100644 --- a/Intersect.Client.Framework/Input/ControlBinding.cs +++ b/Intersect.Client.Framework/Input/ControlBinding.cs @@ -1,4 +1,5 @@ using Intersect.Client.Framework.GenericClasses; +using Intersect.Client.Framework.Gwen.DragDrop; using Newtonsoft.Json; namespace Intersect.Client.Framework.Input; @@ -34,7 +35,7 @@ public bool IsDown() if (IsMouseKey && Key.TryGetMouseButton(out var mouseButton)) { - return gameInput.IsMouseButtonDown(mouseButton); + return gameInput.IsMouseButtonDown(mouseButton) && !DragAndDrop.IsDragging; } return gameInput.IsKeyDown(Key); From a673a7f277297512006927b34c848ff6b0a218eb Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Fri, 14 Mar 2025 22:08:44 -0300 Subject: [PATCH 08/16] IconImage => Icon --- .../Interface/Game/Bag/BagItem.cs | 36 +++++++-------- .../Interface/Game/Bank/BankItem.cs | 36 +++++++-------- .../Interface/Game/Hotbar/HotbarItem.cs | 40 ++++++++--------- .../Interface/Game/Inventory/InventoryItem.cs | 44 +++++++++---------- .../Interface/Game/Shop/ShopItem.cs | 24 +++++----- .../Interface/Game/SlotItem.cs | 4 +- .../Interface/Game/Spells/SpellItem.cs | 40 ++++++++--------- 7 files changed, 112 insertions(+), 112 deletions(-) diff --git a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs index b8cf2fc2c1..38fd3f0738 100644 --- a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs @@ -32,10 +32,10 @@ public BagItem(BagWindow bagWindow, Base parent, int index, ContextMenu contextM _bagWindow = bagWindow; TextureFilename = "bagitem.png"; - IconImage.HoverEnter += IconImage_HoverEnter; - IconImage.HoverLeave += IconImage_HoverLeave; - IconImage.Clicked += IconImage_Clicked; - IconImage.DoubleClicked += IconImage_DoubleClicked; + Icon.HoverEnter += Icon_HoverEnter; + Icon.HoverLeave += Icon_HoverLeave; + Icon.Clicked += Icon_Clicked; + Icon.DoubleClicked += Icon_DoubleClicked; _quantityLabel = new Label(this, "Quantity") { @@ -87,7 +87,7 @@ private void _withdrawMenuItem_Clicked(Base sender, MouseButtonState arguments) #region Mouse Events - private void IconImage_HoverEnter(Base? sender, EventArgs? arguments) + private void Icon_HoverEnter(Base? sender, EventArgs? arguments) { if (InputHandler.MouseFocus != default) { @@ -122,13 +122,13 @@ private void IconImage_HoverEnter(Base? sender, EventArgs? arguments) ); } - private void IconImage_HoverLeave(Base sender, EventArgs arguments) + private void Icon_HoverLeave(Base sender, EventArgs arguments) { _descWindow?.Dispose(); _descWindow = default; } - private void IconImage_Clicked(Base sender, MouseButtonState arguments) + private void Icon_Clicked(Base sender, MouseButtonState arguments) { if (arguments.MouseButton is MouseButton.Right) { @@ -138,12 +138,12 @@ private void IconImage_Clicked(Base sender, MouseButtonState arguments) } else { - IconImage_DoubleClicked(sender, arguments); + Icon_DoubleClicked(sender, arguments); } } } - private void IconImage_DoubleClicked(Base sender, MouseButtonState arguments) + private void Icon_DoubleClicked(Base sender, MouseButtonState arguments) { if (Globals.InBag) { @@ -204,20 +204,20 @@ public override void Update() if (bagSlots[SlotIndex] is not { Descriptor: not null } or { Quantity: <= 0 }) { _quantityLabel.IsVisibleInParent = false; - IconImage.Texture = default; + Icon.Texture = default; return; } var bagSlot = bagSlots[SlotIndex]; var descriptor = bagSlot.Descriptor; - _quantityLabel.IsVisibleInParent = !IconImage.IsDragging && descriptor.IsStackable && bagSlot.Quantity > 1; + _quantityLabel.IsVisibleInParent = !Icon.IsDragging && descriptor.IsStackable && bagSlot.Quantity > 1; if (_quantityLabel.IsVisibleInParent) { _quantityLabel.Text = Strings.FormatQuantityAbbreviated(bagSlot.Quantity); } - if (IconImage.TextureFilename == descriptor.Icon) + if (Icon.TextureFilename == descriptor.Icon) { return; } @@ -225,16 +225,16 @@ public override void Update() var itemTexture = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); if (itemTexture != default) { - IconImage.Texture = itemTexture; - IconImage.RenderColor = descriptor.Color; - IconImage.IsVisibleInParent = true; + Icon.Texture = itemTexture; + Icon.RenderColor = descriptor.Color; + Icon.IsVisibleInParent = true; } else { - if (IconImage.Texture != default) + if (Icon.Texture != default) { - IconImage.Texture = default; - IconImage.IsVisibleInParent = false; + Icon.Texture = default; + Icon.IsVisibleInParent = false; } } diff --git a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs index 30e258db8b..dbf754dcd4 100644 --- a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs @@ -35,10 +35,10 @@ public BankItem(BankWindow bankWindow, Base parent, int index, ContextMenu conte _bankWindow = bankWindow; TextureFilename = "bankitem.png"; - IconImage.HoverEnter += IconImage_HoverEnter; - IconImage.HoverLeave += IconImage_HoverLeave; - IconImage.Clicked += IconImage_Clicked; - IconImage.DoubleClicked += IconImage_DoubleClicked; + Icon.HoverEnter += Icon_HoverEnter; + Icon.HoverLeave += Icon_HoverLeave; + Icon.Clicked += Icon_Clicked; + Icon.DoubleClicked += Icon_DoubleClicked; _quantityLabel = new Label(this, "Quantity") { @@ -88,7 +88,7 @@ private void _withdrawMenuItem_Clicked(Base sender, MouseButtonState arguments) #region Mouse Events - private void IconImage_HoverEnter(Base? sender, EventArgs? arguments) + private void Icon_HoverEnter(Base? sender, EventArgs? arguments) { if (InputHandler.MouseFocus != null) { @@ -124,13 +124,13 @@ private void IconImage_HoverEnter(Base? sender, EventArgs? arguments) ); } - private void IconImage_HoverLeave(Base sender, EventArgs arguments) + private void Icon_HoverLeave(Base sender, EventArgs arguments) { _descWindow?.Dispose(); _descWindow = default; } - private void IconImage_Clicked(Base sender, MouseButtonState arguments) + private void Icon_Clicked(Base sender, MouseButtonState arguments) { if (arguments.MouseButton is MouseButton.Right) { @@ -140,12 +140,12 @@ private void IconImage_Clicked(Base sender, MouseButtonState arguments) } else { - IconImage_DoubleClicked(sender, arguments); + Icon_DoubleClicked(sender, arguments); } } } - private void IconImage_DoubleClicked(Base sender, MouseButtonState arguments) + private void Icon_DoubleClicked(Base sender, MouseButtonState arguments) { if (!Globals.InBank) { @@ -269,20 +269,20 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) if (bankSlots[SlotIndex] is not { Descriptor: not null } or { Quantity: <= 0 }) { _quantityLabel.IsVisibleInParent = false; - IconImage.Texture = default; + Icon.Texture = default; return; } var bankSlot = bankSlots[SlotIndex]; var descriptor = bankSlot.Descriptor; - _quantityLabel.IsVisibleInParent = !IconImage.IsDragging && descriptor.IsStackable && bankSlot.Quantity > 1; + _quantityLabel.IsVisibleInParent = !Icon.IsDragging && descriptor.IsStackable && bankSlot.Quantity > 1; if (_quantityLabel.IsVisibleInParent) { _quantityLabel.Text = Strings.FormatQuantityAbbreviated(bankSlot.Quantity); } - if (IconImage.TextureFilename == descriptor.Icon) + if (Icon.TextureFilename == descriptor.Icon) { return; } @@ -290,16 +290,16 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) var itemTexture = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); if (itemTexture != default) { - IconImage.Texture = itemTexture; - IconImage.RenderColor = descriptor.Color; - IconImage.IsVisibleInParent = true; + Icon.Texture = itemTexture; + Icon.RenderColor = descriptor.Color; + Icon.IsVisibleInParent = true; } else { - if (IconImage.Texture != default) + if (Icon.Texture != default) { - IconImage.Texture = default; - IconImage.IsVisibleInParent = false; + Icon.Texture = default; + Icon.IsVisibleInParent = false; } } diff --git a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs index 8f0a9b0eb8..2299454447 100644 --- a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs +++ b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs @@ -56,12 +56,12 @@ public HotbarItem(int hotbarSlotIndex, Base hotbarWindow) RestrictToParent = true; TextureFilename = "hotbaritem.png"; - IconImage.Name = $"{nameof(HotbarItem)}{SlotIndex}"; - IconImage.SetPosition(1, 1); - IconImage.HoverEnter += IconImage_HoverEnter; - IconImage.HoverLeave += IconImage_HoverLeave; - IconImage.Clicked += IconImage_Clicked; - IconImage.DoubleClicked += IconImage_DoubleClicked; + Icon.Name = $"{nameof(HotbarItem)}{SlotIndex}"; + Icon.SetPosition(1, 1); + Icon.HoverEnter += Icon_HoverEnter; + Icon.HoverLeave += Icon_HoverLeave; + Icon.Clicked += Icon_Clicked; + Icon.DoubleClicked += Icon_DoubleClicked; var font = GameContentManager.Current.GetFont("sourcesansproblack"); @@ -155,7 +155,7 @@ public void Activate() } } - private void IconImage_Clicked(Base sender, MouseButtonState arguments) + private void Icon_Clicked(Base sender, MouseButtonState arguments) { if (arguments.MouseButton is MouseButton.Right) { @@ -163,7 +163,7 @@ private void IconImage_Clicked(Base sender, MouseButtonState arguments) } } - private void IconImage_DoubleClicked(Base sender, MouseButtonState arguments) + private void Icon_DoubleClicked(Base sender, MouseButtonState arguments) { if (arguments.MouseButton is MouseButton.Left) { @@ -171,7 +171,7 @@ private void IconImage_DoubleClicked(Base sender, MouseButtonState arguments) } } - private void IconImage_HoverLeave(Base sender, EventArgs arguments) + private void Icon_HoverLeave(Base sender, EventArgs arguments) { _itemDescWindow?.Dispose(); _itemDescWindow = null; @@ -180,7 +180,7 @@ private void IconImage_HoverLeave(Base sender, EventArgs arguments) _spellDescWindow = null; } - private void IconImage_HoverEnter(Base sender, EventArgs arguments) + private void Icon_HoverEnter(Base sender, EventArgs arguments) { if (InputHandler.MouseFocus != null || Globals.Me == null) { @@ -398,7 +398,7 @@ public void Update() } } - var isDragging = IconImage.IsDragging; + var isDragging = Icon.IsDragging; if (isDragging) { _equipLabel.IsHidden = true; @@ -416,8 +416,8 @@ public void Update() { if (_currentItem != null) { - IconImage.IsVisibleInTree = !isDragging; - IconImage.Texture = Globals.ContentManager.GetTexture( + Icon.IsVisibleInTree = !isDragging; + Icon.Texture = Globals.ContentManager.GetTexture( Framework.Content.TextureType.Item, _currentItem.Icon ); @@ -451,8 +451,8 @@ public void Update() } else if (_currentSpell != null) { - IconImage.IsVisibleInTree = !isDragging; - IconImage.Texture = Globals.ContentManager.GetTexture( + Icon.IsVisibleInTree = !isDragging; + Icon.Texture = Globals.ContentManager.GetTexture( Framework.Content.TextureType.Spell, _currentSpell.Icon ); @@ -480,7 +480,7 @@ public void Update() } else { - IconImage.Hide(); + Icon.Hide(); _textureLoaded = true; _isEquipped = false; _equipLabel.IsHidden = true; @@ -492,24 +492,24 @@ public void Update() { if (_currentSpell != null) { - IconImage.RenderColor = new Color(60, 255, 255, 255); + Icon.RenderColor = new Color(60, 255, 255, 255); } if (_currentItem != null) { - IconImage.RenderColor = new Color(60, _currentItem.Color.R, _currentItem.Color.G, _currentItem.Color.B); + Icon.RenderColor = new Color(60, _currentItem.Color.R, _currentItem.Color.G, _currentItem.Color.B); } } else { if (_currentSpell != null) { - IconImage.RenderColor = Color.White; + Icon.RenderColor = Color.White; } if (_currentItem != null) { - IconImage.RenderColor = _currentItem.Color; + Icon.RenderColor = _currentItem.Color; } } } diff --git a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs index 58a18c98be..0d1fd5fa8c 100644 --- a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs +++ b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs @@ -43,10 +43,10 @@ public InventoryItem(InventoryWindow inventoryWindow, Base parent, int index, Co _inventoryWindow = inventoryWindow; TextureFilename = "inventoryitem.png"; - IconImage.HoverEnter += IconImage_HoverEnter; - IconImage.HoverLeave += IconImage_HoverLeave; - IconImage.Clicked += IconImage_Clicked; - IconImage.DoubleClicked += IconImage_DoubleClicked; + Icon.HoverEnter += Icon_HoverEnter; + Icon.HoverLeave += Icon_HoverLeave; + Icon.Clicked += Icon_Clicked; + Icon.DoubleClicked += Icon_DoubleClicked; _equipImageBackground = new ImagePanel(this, "EquippedIcon") { @@ -213,7 +213,7 @@ private void _dropItemContextItem_Clicked(Base sender, Framework.Gwen.Control.Ev #region Mouse Events - private void IconImage_DoubleClicked(Base sender, MouseButtonState arguments) + private void Icon_DoubleClicked(Base sender, MouseButtonState arguments) { if (Globals.Me == default) { @@ -258,7 +258,7 @@ private void IconImage_DoubleClicked(Base sender, MouseButtonState arguments) } } - private void IconImage_Clicked(Base sender, MouseButtonState arguments) + private void Icon_Clicked(Base sender, MouseButtonState arguments) { if (arguments.MouseButton is MouseButton.Right) { @@ -292,13 +292,13 @@ private void IconImage_Clicked(Base sender, MouseButtonState arguments) } } - private void IconImage_HoverLeave(Base sender, EventArgs arguments) + private void Icon_HoverLeave(Base sender, EventArgs arguments) { _descWindow?.Dispose(); _descWindow = null; } - void IconImage_HoverEnter(Base? sender, EventArgs? arguments) + void Icon_HoverEnter(Base? sender, EventArgs? arguments) { if (InputHandler.MouseFocus != null) { @@ -492,7 +492,7 @@ private void PlayerOnInventoryUpdated(Player player, int slotIndex) } // empty texture to reload on update - IconImage.Texture = default; + Icon.Texture = default; } public override void Update() @@ -514,7 +514,7 @@ public override void Update() } var equipped = Globals.Me.MyEquipment.Any(s => s == SlotIndex); - var isDragging = IconImage.IsDragging; + var isDragging = Icon.IsDragging; _equipImageBackground.IsVisibleInParent = !isDragging && equipped; _equipLabel.IsVisibleInParent = !isDragging && equipped; @@ -529,14 +529,14 @@ public override void Update() { var itemCooldownRemaining = Globals.Me.GetItemRemainingCooldown(SlotIndex); _cooldownLabel.Text = TimeSpan.FromMilliseconds(itemCooldownRemaining).WithSuffix("0.0"); - IconImage.RenderColor.A = 100; + Icon.RenderColor.A = 100; } else { - IconImage.RenderColor.A = descriptor.Color.A; + Icon.RenderColor.A = descriptor.Color.A; } - if (IconImage.TextureFilename == descriptor.Icon) + if (Icon.TextureFilename == descriptor.Icon) { return; } @@ -544,18 +544,18 @@ public override void Update() var itemTexture = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); if (itemTexture != null) { - IconImage.Texture = itemTexture; - IconImage.RenderColor = Globals.Me.IsItemOnCooldown(SlotIndex) + Icon.Texture = itemTexture; + Icon.RenderColor = Globals.Me.IsItemOnCooldown(SlotIndex) ? new Color(100, descriptor.Color.R, descriptor.Color.G, descriptor.Color.B) : descriptor.Color; - IconImage.IsVisibleInParent = true; + Icon.IsVisibleInParent = true; } else { - if (IconImage.Texture != null) + if (Icon.Texture != null) { - IconImage.Texture = null; - IconImage.IsVisibleInParent = false; + Icon.Texture = null; + Icon.IsVisibleInParent = false; } } @@ -563,14 +563,14 @@ public override void Update() { _descWindow.Dispose(); _descWindow = null; - IconImage_HoverEnter(null, null); + Icon_HoverEnter(null, null); } } private void _reset() { - IconImage.IsVisibleInParent = false; - IconImage.Texture = default; + Icon.IsVisibleInParent = false; + Icon.Texture = default; _equipImageBackground.IsVisibleInParent = false; _quantityLabel.IsVisibleInParent = false; _equipLabel.IsVisibleInParent = false; diff --git a/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs b/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs index ccfd16cdeb..a3c1c5407c 100644 --- a/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs +++ b/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs @@ -26,11 +26,11 @@ public ShopItem(ShopWindow shopWindow, Base parent, int index, ContextMenu conte _mySlot = index; TextureFilename = "shopitem.png"; - IconImage.HoverEnter += IconImage_HoverEnter; - IconImage.HoverLeave += IconImage_HoverLeave; - IconImage.Clicked += IconImage_RightClicked; - IconImage.DoubleClicked += IconImage_DoubleClicked; - IconImage.DisableDragAndDrop = true; + Icon.HoverEnter += Icon_HoverEnter; + Icon.HoverLeave += Icon_HoverLeave; + Icon.Clicked += Icon_RightClicked; + Icon.DoubleClicked += Icon_DoubleClicked; + Icon.DisableDragAndDrop = true; LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString()); @@ -42,7 +42,7 @@ public ShopItem(ShopWindow shopWindow, Base parent, int index, ContextMenu conte LoadItem(); } - private void IconImage_HoverEnter(Base sender, EventArgs arguments) + private void Icon_HoverEnter(Base sender, EventArgs arguments) { if (InputHandler.MouseFocus != null) { @@ -88,7 +88,7 @@ private void IconImage_HoverEnter(Base sender, EventArgs arguments) } } - private void IconImage_HoverLeave(Base sender, EventArgs arguments) + private void Icon_HoverLeave(Base sender, EventArgs arguments) { if (_itemDescWindow != null) { @@ -97,7 +97,7 @@ private void IconImage_HoverLeave(Base sender, EventArgs arguments) } } - private void IconImage_RightClicked(Base sender, MouseButtonState arguments) + private void Icon_RightClicked(Base sender, MouseButtonState arguments) { if (arguments.MouseButton != MouseButton.Right) { @@ -110,11 +110,11 @@ private void IconImage_RightClicked(Base sender, MouseButtonState arguments) } else { - IconImage_DoubleClicked(sender, arguments); + Icon_DoubleClicked(sender, arguments); } } - private void IconImage_DoubleClicked(Base sender, MouseButtonState arguments) + private void Icon_DoubleClicked(Base sender, MouseButtonState arguments) { Globals.Me?.TryBuyItem(_mySlot); } @@ -157,8 +157,8 @@ public void LoadItem() var itemTex = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, itemDescriptor.Icon); if (itemTex != null) { - IconImage.Texture = itemTex; - IconImage.RenderColor = itemDescriptor.Color; + Icon.Texture = itemTex; + Icon.RenderColor = itemDescriptor.Color; } } } diff --git a/Intersect.Client.Core/Interface/Game/SlotItem.cs b/Intersect.Client.Core/Interface/Game/SlotItem.cs index 570aee85ab..8b88fa8264 100644 --- a/Intersect.Client.Core/Interface/Game/SlotItem.cs +++ b/Intersect.Client.Core/Interface/Game/SlotItem.cs @@ -6,7 +6,7 @@ namespace Intersect.Client.Interface.Game; public partial class SlotItem : ImagePanel { public readonly int SlotIndex; - public readonly Draggable IconImage; + public readonly Draggable Icon; protected readonly ContextMenu? _contextMenu; public SlotItem(Base parent, string name, int index, ContextMenu? contextMenu) : base(parent, name) @@ -17,7 +17,7 @@ public SlotItem(Base parent, string name, int index, ContextMenu? contextMenu) : Margin = new Margin(4); MouseInputEnabled = true; - IconImage = new Draggable(this, "Icon") + Icon = new Draggable(this, nameof(Icon)) { MinimumSize = new Point(32, 32), MouseInputEnabled = true, diff --git a/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs b/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs index 13b24417f8..4be9beefad 100644 --- a/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs +++ b/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs @@ -34,10 +34,10 @@ public SpellItem(SpellsWindow spellWindow, Base parent, int index, ContextMenu c _spellWindow = spellWindow; TextureFilename = "spellitem.png"; - IconImage.HoverEnter += IconImage_HoverEnter; - IconImage.HoverLeave += IconImage_HoverLeave; - IconImage.Clicked += IconImage_Clicked; - IconImage.DoubleClicked += IconImage_DoubleClicked; + Icon.HoverEnter += Icon_HoverEnter; + Icon.HoverLeave += Icon_HoverLeave; + Icon.Clicked += Icon_Clicked; + Icon.DoubleClicked += Icon_DoubleClicked; _cooldownLabel = new Label(this, "CooldownLabel") { @@ -106,7 +106,7 @@ private void _forgetSpellMenuItem_Clicked(Base sender, MouseButtonState argument #region Mouse Events - private void IconImage_HoverEnter(Base? sender, EventArgs? arguments) + private void Icon_HoverEnter(Base? sender, EventArgs? arguments) { if (InputHandler.MouseFocus != null) { @@ -129,13 +129,13 @@ private void IconImage_HoverEnter(Base? sender, EventArgs? arguments) _descriptionWindow = new SpellDescriptionWindow(spellSlots[SlotIndex].Id, _spellWindow.X, _spellWindow.Y); } - private void IconImage_HoverLeave(Base sender, EventArgs arguments) + private void Icon_HoverLeave(Base sender, EventArgs arguments) { _descriptionWindow?.Dispose(); _descriptionWindow = null; } - private void IconImage_Clicked(Base sender, MouseButtonState arguments) + private void Icon_Clicked(Base sender, MouseButtonState arguments) { if (arguments.MouseButton is MouseButton.Right) { @@ -150,7 +150,7 @@ private void IconImage_Clicked(Base sender, MouseButtonState arguments) } } - private void IconImage_DoubleClicked(Base sender, MouseButtonState arguments) + private void Icon_DoubleClicked(Base sender, MouseButtonState arguments) { Globals.Me?.TryUseSpell(SlotIndex); } @@ -207,39 +207,39 @@ public override void Update() if (!SpellDescriptor.TryGet(spellSlots[SlotIndex].Id, out var spell)) { - IconImage.Hide(); - IconImage.Texture = null; + Icon.Hide(); + Icon.Texture = null; _cooldownLabel.Hide(); return; } - _cooldownLabel.IsVisibleInParent = !IconImage.IsDragging && Globals.Me.IsSpellOnCooldown(SlotIndex); + _cooldownLabel.IsVisibleInParent = !Icon.IsDragging && Globals.Me.IsSpellOnCooldown(SlotIndex); if (_cooldownLabel.IsVisibleInParent) { var itemCooldownRemaining = Globals.Me.GetSpellRemainingCooldown(SlotIndex); _cooldownLabel.Text = TimeSpan.FromMilliseconds(itemCooldownRemaining).WithSuffix("0.0"); - IconImage.RenderColor.A = 100; + Icon.RenderColor.A = 100; } else { - IconImage.RenderColor.A = 255; + Icon.RenderColor.A = 255; } - if (Path.GetFileName(IconImage.Texture?.Name) != spell.Icon) + if (Path.GetFileName(Icon.Texture?.Name) != spell.Icon) { var spellIconTexture = Globals.ContentManager?.GetTexture(TextureType.Spell, spell.Icon); if (spellIconTexture != null) { - IconImage.Texture = spellIconTexture; - IconImage.RenderColor.A = (byte)(_cooldownLabel.IsVisibleInParent ? 100 : 255); - IconImage.IsVisibleInParent = true; + Icon.Texture = spellIconTexture; + Icon.RenderColor.A = (byte)(_cooldownLabel.IsVisibleInParent ? 100 : 255); + Icon.IsVisibleInParent = true; } else { - if (IconImage.Texture != null) + if (Icon.Texture != null) { - IconImage.Texture = null; - IconImage.IsVisibleInParent = false; + Icon.Texture = null; + Icon.IsVisibleInParent = false; } } From c76198758c54b05a87a8f0e580bb50801da2cfcd Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Fri, 14 Mar 2025 22:10:51 -0300 Subject: [PATCH 09/16] _descWindow => _descriptionWindow --- .../Interface/Game/Bag/BagItem.cs | 16 +++++----- .../Interface/Game/Bank/BankItem.cs | 16 +++++----- .../Interface/Game/Hotbar/HotbarItem.cs | 24 +++++++-------- .../Interface/Game/Inventory/InventoryItem.cs | 30 +++++++++---------- .../Interface/Game/Shop/ShopItem.cs | 16 +++++----- 5 files changed, 51 insertions(+), 51 deletions(-) diff --git a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs index 38fd3f0738..f414dae0de 100644 --- a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs @@ -21,7 +21,7 @@ public partial class BagItem : SlotItem // Controls private readonly Label _quantityLabel; private readonly BagWindow _bagWindow; - private ItemDescriptionWindow? _descWindow; + private ItemDescriptionWindow? _descriptionWindow; // Context Menu Handling private readonly MenuItem _withdrawContextItem; @@ -99,8 +99,8 @@ private void Icon_HoverEnter(Base? sender, EventArgs? arguments) return; } - _descWindow?.Dispose(); - _descWindow = default; + _descriptionWindow?.Dispose(); + _descriptionWindow = default; if (Globals.BagSlots is not { Length: > 0 } bagSlots) { @@ -113,7 +113,7 @@ private void Icon_HoverEnter(Base? sender, EventArgs? arguments) } var item = bagSlots[SlotIndex]; - _descWindow = new ItemDescriptionWindow( + _descriptionWindow = new ItemDescriptionWindow( item.Descriptor, item.Quantity, _bagWindow.X, @@ -124,8 +124,8 @@ private void Icon_HoverEnter(Base? sender, EventArgs? arguments) private void Icon_HoverLeave(Base sender, EventArgs arguments) { - _descWindow?.Dispose(); - _descWindow = default; + _descriptionWindow?.Dispose(); + _descriptionWindow = default; } private void Icon_Clicked(Base sender, MouseButtonState arguments) @@ -238,7 +238,7 @@ public override void Update() } } - _descWindow?.Dispose(); - _descWindow = default; + _descriptionWindow?.Dispose(); + _descriptionWindow = default; } } diff --git a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs index dbf754dcd4..315369d05c 100644 --- a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs @@ -24,7 +24,7 @@ public partial class BankItem : SlotItem // Controls private readonly Label _quantityLabel; private BankWindow _bankWindow; - private ItemDescriptionWindow? _descWindow; + private ItemDescriptionWindow? _descriptionWindow; // Context Menu Handling private MenuItem _withdrawContextItem; @@ -101,8 +101,8 @@ private void Icon_HoverEnter(Base? sender, EventArgs? arguments) } - _descWindow?.Dispose(); - _descWindow = null; + _descriptionWindow?.Dispose(); + _descriptionWindow = null; if (Globals.BankSlots is not { Length: > 0 } bankSlots) { @@ -115,7 +115,7 @@ private void Icon_HoverEnter(Base? sender, EventArgs? arguments) } var item = bankSlots[SlotIndex]; - _descWindow = new ItemDescriptionWindow( + _descriptionWindow = new ItemDescriptionWindow( item.Descriptor, item.Quantity, _bankWindow.X, @@ -126,8 +126,8 @@ private void Icon_HoverEnter(Base? sender, EventArgs? arguments) private void Icon_HoverLeave(Base sender, EventArgs arguments) { - _descWindow?.Dispose(); - _descWindow = default; + _descriptionWindow?.Dispose(); + _descriptionWindow = default; } private void Icon_Clicked(Base sender, MouseButtonState arguments) @@ -303,7 +303,7 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) } } - _descWindow?.Dispose(); - _descWindow = default; + _descriptionWindow?.Dispose(); + _descriptionWindow = default; } } diff --git a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs index 2299454447..d7be497924 100644 --- a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs +++ b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs @@ -34,10 +34,10 @@ public partial class HotbarItem : SlotItem private ControlBinding? _hotKey; private Item? _inventoryItem = null; private int _inventoryItemIndex = -1; - private ItemDescriptionWindow? _itemDescWindow; + private ItemDescriptionWindow? _itemDescriptionWindow; private Label _quantityLabel; private Spell? _spellBookItem = null; - private SpellDescriptionWindow? _spellDescWindow; + private SpellDescriptionWindow? _spellDescriptionWindow; private bool _textureLoaded; public HotbarItem(int hotbarSlotIndex, Base hotbarWindow) @@ -173,11 +173,11 @@ private void Icon_DoubleClicked(Base sender, MouseButtonState arguments) private void Icon_HoverLeave(Base sender, EventArgs arguments) { - _itemDescWindow?.Dispose(); - _itemDescWindow = null; + _itemDescriptionWindow?.Dispose(); + _itemDescriptionWindow = null; - _spellDescWindow?.Dispose(); - _spellDescWindow = null; + _spellDescriptionWindow?.Dispose(); + _spellDescriptionWindow = null; } private void Icon_HoverEnter(Base sender, EventArgs arguments) @@ -194,8 +194,8 @@ private void Icon_HoverEnter(Base sender, EventArgs arguments) if (_currentItem != null && _inventoryItem != null) { - _itemDescWindow?.Dispose(); - _itemDescWindow = null; + _itemDescriptionWindow?.Dispose(); + _itemDescriptionWindow = null; var quantityOfItem = 1; @@ -204,17 +204,17 @@ private void Icon_HoverEnter(Base sender, EventArgs arguments) quantityOfItem = Globals.Me.GetQuantityOfItemInInventory(_currentItem.Id); } - _itemDescWindow = new ItemDescriptionWindow( + _itemDescriptionWindow = new ItemDescriptionWindow( _currentItem, quantityOfItem, _hotbarWindow.X + (_hotbarWindow.Width / 2), _hotbarWindow.Y + _hotbarWindow.Height + 2, _inventoryItem.ItemProperties, _currentItem.Name, "" ); } else if (_currentSpell != null) { - _spellDescWindow?.Dispose(); - _spellDescWindow = null; + _spellDescriptionWindow?.Dispose(); + _spellDescriptionWindow = null; - _spellDescWindow = new SpellDescriptionWindow( + _spellDescriptionWindow = new SpellDescriptionWindow( _currentSpell.Id, _hotbarWindow.X + (_hotbarWindow.Width / 2), _hotbarWindow.Y + _hotbarWindow.Height + 2 ); } diff --git a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs index 0d1fd5fa8c..9187b1d29b 100644 --- a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs +++ b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs @@ -30,7 +30,7 @@ public partial class InventoryItem : SlotItem private readonly Label _cooldownLabel; private readonly ImagePanel _equipImageBackground; private readonly InventoryWindow _inventoryWindow; - private ItemDescriptionWindow? _descWindow; + private ItemDescriptionWindow? _descriptionWindow; // Context Menu Handling private readonly MenuItem _useItemMenuItem; @@ -294,8 +294,8 @@ private void Icon_Clicked(Base sender, MouseButtonState arguments) private void Icon_HoverLeave(Base sender, EventArgs arguments) { - _descWindow?.Dispose(); - _descWindow = null; + _descriptionWindow?.Dispose(); + _descriptionWindow = null; } void Icon_HoverEnter(Base? sender, EventArgs? arguments) @@ -310,10 +310,10 @@ void Icon_HoverEnter(Base? sender, EventArgs? arguments) return; } - if (_descWindow != null) + if (_descriptionWindow != null) { - _descWindow.Dispose(); - _descWindow = null; + _descriptionWindow.Dispose(); + _descriptionWindow = null; } if (Globals.Me?.Inventory[SlotIndex] is not { } inventorySlot) @@ -329,7 +329,7 @@ void Icon_HoverEnter(Base? sender, EventArgs? arguments) if (Globals.GameShop == null) { - _descWindow = new ItemDescriptionWindow( + _descriptionWindow = new ItemDescriptionWindow( inventorySlotDescriptor, inventorySlot.Quantity, _inventoryWindow.X, @@ -357,7 +357,7 @@ void Icon_HoverEnter(Base? sender, EventArgs? arguments) return; } - _descWindow = new ItemDescriptionWindow( + _descriptionWindow = new ItemDescriptionWindow( inventorySlotDescriptor, inventorySlot.Quantity, _inventoryWindow.X, @@ -372,7 +372,7 @@ void Icon_HoverEnter(Base? sender, EventArgs? arguments) var costItem = Globals.GameShop.DefaultCurrency; if (inventorySlotDescriptor != null && costItem != null) { - _descWindow = new ItemDescriptionWindow( + _descriptionWindow = new ItemDescriptionWindow( inventorySlotDescriptor, inventorySlot.Quantity, _inventoryWindow.X, @@ -385,7 +385,7 @@ void Icon_HoverEnter(Base? sender, EventArgs? arguments) } else { - _descWindow = new ItemDescriptionWindow( + _descriptionWindow = new ItemDescriptionWindow( inventorySlotDescriptor, inventorySlot.Quantity, _inventoryWindow.X, @@ -559,10 +559,10 @@ public override void Update() } } - if (_descWindow != null) + if (_descriptionWindow != null) { - _descWindow.Dispose(); - _descWindow = null; + _descriptionWindow.Dispose(); + _descriptionWindow = null; Icon_HoverEnter(null, null); } } @@ -575,7 +575,7 @@ private void _reset() _quantityLabel.IsVisibleInParent = false; _equipLabel.IsVisibleInParent = false; _cooldownLabel.IsVisibleInParent = false; - _descWindow?.Dispose(); - _descWindow = default; + _descriptionWindow?.Dispose(); + _descriptionWindow = default; } } diff --git a/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs b/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs index a3c1c5407c..f71e2cae10 100644 --- a/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs +++ b/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs @@ -17,7 +17,7 @@ public partial class ShopItem : SlotItem private readonly int _mySlot; private readonly ShopWindow _shopWindow; private readonly MenuItem _buyMenuItem; - private ItemDescriptionWindow? _itemDescWindow; + private ItemDescriptionWindow? _descriptionWindow; public ShopItem(ShopWindow shopWindow, Base parent, int index, ContextMenu contextMenu) : base(parent, nameof(ShopItem), index, contextMenu) @@ -54,10 +54,10 @@ private void Icon_HoverEnter(Base sender, EventArgs arguments) return; } - if (_itemDescWindow != default) + if (_descriptionWindow != default) { - _itemDescWindow.Dispose(); - _itemDescWindow = default; + _descriptionWindow.Dispose(); + _descriptionWindow = default; } if (Globals.GameShop is not { SellingItems.Count: > 0 } gameShop) @@ -77,7 +77,7 @@ private void Icon_HoverEnter(Base sender, EventArgs arguments) StatModifiers = item.StatsGiven, }; - _itemDescWindow = new ItemDescriptionWindow( + _descriptionWindow = new ItemDescriptionWindow( item: gameShop.SellingItems[_mySlot].Item, amount: 1, x: _shopWindow.X, @@ -90,10 +90,10 @@ private void Icon_HoverEnter(Base sender, EventArgs arguments) private void Icon_HoverLeave(Base sender, EventArgs arguments) { - if (_itemDescWindow != null) + if (_descriptionWindow != null) { - _itemDescWindow.Dispose(); - _itemDescWindow = null; + _descriptionWindow.Dispose(); + _descriptionWindow = null; } } From 63ffb04a3c4f0a5d2e4c709c7d55cfe67d554392 Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Fri, 14 Mar 2025 22:19:06 -0300 Subject: [PATCH 10/16] cleanup drag and drop handle drop --- Intersect.Client.Core/Interface/Game/Bag/BagItem.cs | 11 +++-------- Intersect.Client.Core/Interface/Game/Bank/BankItem.cs | 9 ++------- .../Interface/Game/Hotbar/HotbarItem.cs | 9 ++------- .../Interface/Game/Inventory/InventoryItem.cs | 9 ++------- .../Interface/Game/Spells/SpellItem.cs | 9 ++------- 5 files changed, 11 insertions(+), 36 deletions(-) diff --git a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs index f414dae0de..85e57afbbe 100644 --- a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs @@ -145,7 +145,7 @@ private void Icon_Clicked(Base sender, MouseButtonState arguments) private void Icon_DoubleClicked(Base sender, MouseButtonState arguments) { - if (Globals.InBag) + if (arguments.MouseButton is MouseButton.Left) { Globals.Me?.TryRetrieveItemFromBag(SlotIndex, -1); } @@ -157,7 +157,7 @@ private void Icon_DoubleClicked(Base sender, MouseButtonState arguments) public override bool DragAndDrop_HandleDrop(Package package, int x, int y) { - var targetNode = Interface.FindComponentUnderCursor(NodeFilter.None); + var targetNode = Interface.FindComponentUnderCursor(); // Find the first parent acceptable in that tree that can accept the package while (targetNode != default) @@ -176,14 +176,9 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) targetNode = targetNode.Parent; break; } - - // If we've reached the top of the tree, we can't drop here, so cancel drop - if (targetNode == null) - { - return false; - } } + // If we've reached the top of the tree, we can't drop here, so cancel drop return false; } diff --git a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs index 315369d05c..0c5e7939cd 100644 --- a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs @@ -183,7 +183,7 @@ private void Icon_DoubleClicked(Base sender, MouseButtonState arguments) public override bool DragAndDrop_HandleDrop(Package package, int x, int y) { - var targetNode = Interface.FindComponentUnderCursor(NodeFilter.None); + var targetNode = Interface.FindComponentUnderCursor(); // Find the first parent acceptable in that tree that can accept the package while (targetNode != default) @@ -241,14 +241,9 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) targetNode = targetNode.Parent; break; } - - // If we've reached the top of the tree, we can't drop here, so cancel drop - if (targetNode == null) - { - return false; - } } + // If we've reached the top of the tree, we can't drop here, so cancel drop return false; } diff --git a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs index d7be497924..57a098ccf0 100644 --- a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs +++ b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs @@ -222,7 +222,7 @@ private void Icon_HoverEnter(Base sender, EventArgs arguments) public override bool DragAndDrop_HandleDrop(Package package, int x, int y) { - var targetNode = Interface.FindComponentUnderCursor(NodeFilter.None); + var targetNode = Interface.FindComponentUnderCursor(); // Find the first parent acceptable in that tree that can accept the package while (targetNode != default) @@ -236,14 +236,9 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) { targetNode = targetNode.Parent; } - - // If we've reached the top of the tree, we can't drop here, so cancel drop - if (targetNode == null) - { - return false; - } } + // If we've reached the top of the tree, we can't drop here, so cancel drop return false; } diff --git a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs index 9187b1d29b..334a1cc155 100644 --- a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs +++ b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs @@ -420,7 +420,7 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) return true; } - var targetNode = Interface.FindComponentUnderCursor(NodeFilter.None); + var targetNode = Interface.FindComponentUnderCursor(); // Find the first parent acceptable in that tree that can accept the package while (targetNode != default) @@ -461,14 +461,9 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) targetNode = targetNode.Parent; break; } - - // If we've reached the top of the tree, we can't drop here, so return false - if (targetNode == null) - { - return false; - } } + // If we've reached the top of the tree, we can't drop here, so cancel drop return false; } diff --git a/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs b/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs index 4be9beefad..54c9d0d259 100644 --- a/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs +++ b/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs @@ -161,7 +161,7 @@ private void Icon_DoubleClicked(Base sender, MouseButtonState arguments) public override bool DragAndDrop_HandleDrop(Package package, int x, int y) { - var targetNode = Interface.FindComponentUnderCursor(NodeFilter.None); + var targetNode = Interface.FindComponentUnderCursor(); // Find the first parent acceptable in that tree that can accept the package while (targetNode != default) @@ -180,14 +180,9 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) targetNode = targetNode.Parent; break; } - - // If we've reached the top of the tree, we can't drop here, so cancel drop - if (targetNode == null) - { - return false; - } } + // If we've reached the top of the tree, we can't drop here, so cancel drop return false; } From f54e409235d4c989ec8b8c83de044f1e91b68267 Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Fri, 14 Mar 2025 22:30:16 -0300 Subject: [PATCH 11/16] Globals.ContentManager? => GameContentManager.Current --- Intersect.Client.Core/Interface/Game/Bag/BagItem.cs | 2 +- Intersect.Client.Core/Interface/Game/Bank/BankItem.cs | 4 ++-- Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs | 4 ++-- .../Interface/Game/Inventory/InventoryItem.cs | 2 +- Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs index 85e57afbbe..35bd1a943e 100644 --- a/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bag/BagItem.cs @@ -217,7 +217,7 @@ public override void Update() return; } - var itemTexture = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); + var itemTexture = GameContentManager.Current.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); if (itemTexture != default) { Icon.Texture = itemTexture; diff --git a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs index 0c5e7939cd..4b80b71ea3 100644 --- a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs @@ -249,7 +249,7 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) #endregion - public new void Update() + public override void Update() { if (Globals.Me == default) { @@ -282,7 +282,7 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) return; } - var itemTexture = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); + var itemTexture = GameContentManager.Current.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); if (itemTexture != default) { Icon.Texture = itemTexture; diff --git a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs index 57a098ccf0..3e38d9a764 100644 --- a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs +++ b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs @@ -242,7 +242,7 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) return false; } - public void Update() + public override void Update() { if (Globals.Me == null || Controls.ActiveControls == null) { @@ -412,7 +412,7 @@ public void Update() if (_currentItem != null) { Icon.IsVisibleInTree = !isDragging; - Icon.Texture = Globals.ContentManager.GetTexture( + Icon.Texture = GameContentManager.Current.GetTexture( Framework.Content.TextureType.Item, _currentItem.Icon ); diff --git a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs index 334a1cc155..6c9be54bfa 100644 --- a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs +++ b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs @@ -536,7 +536,7 @@ public override void Update() return; } - var itemTexture = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); + var itemTexture = GameContentManager.Current.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); if (itemTexture != null) { Icon.Texture = itemTexture; diff --git a/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs b/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs index 54c9d0d259..ef00dbb236 100644 --- a/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs +++ b/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs @@ -222,7 +222,7 @@ public override void Update() if (Path.GetFileName(Icon.Texture?.Name) != spell.Icon) { - var spellIconTexture = Globals.ContentManager?.GetTexture(TextureType.Spell, spell.Icon); + var spellIconTexture = GameContentManager.Current.GetTexture(TextureType.Spell, spell.Icon); if (spellIconTexture != null) { Icon.Texture = spellIconTexture; From e8857196646cbdddddc1a7878844a49f24bc2b03 Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Fri, 14 Mar 2025 22:41:02 -0300 Subject: [PATCH 12/16] add buy item when dragging from shop to inventory --- .../Interface/Game/Draggable.cs | 7 ------ .../Interface/Game/Shop/ShopItem.cs | 24 ++++++++++++++++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Intersect.Client.Core/Interface/Game/Draggable.cs b/Intersect.Client.Core/Interface/Game/Draggable.cs index 0a50d73650..9afd863410 100644 --- a/Intersect.Client.Core/Interface/Game/Draggable.cs +++ b/Intersect.Client.Core/Interface/Game/Draggable.cs @@ -6,8 +6,6 @@ namespace Intersect.Client.Interface.Game; public partial class Draggable(Base parent, string name) : ImagePanel(parent, name) { - public bool DisableDragAndDrop { get; set; } = false; - public bool IsDragging => DragAndDrop.CurrentPackage?.DrawControl == this; public override bool DragAndDrop_Draggable() @@ -17,11 +15,6 @@ public override bool DragAndDrop_Draggable() public override Package DragAndDrop_GetPackage(int x, int y) { - if (DisableDragAndDrop) - { - return null; - } - return new Package() { IsDraggable = true, diff --git a/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs b/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs index f71e2cae10..24b7f18a41 100644 --- a/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs +++ b/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs @@ -2,10 +2,12 @@ using Intersect.Client.Framework.File_Management; using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; +using Intersect.Client.Framework.Gwen.DragDrop; using Intersect.Client.Framework.Gwen.Input; using Intersect.Client.Framework.Input; using Intersect.Client.General; using Intersect.Client.Interface.Game.DescriptionWindows; +using Intersect.Client.Interface.Game.Inventory; using Intersect.Client.Localization; using Intersect.Configuration; using Intersect.Framework.Core.GameObjects.Items; @@ -30,7 +32,6 @@ public ShopItem(ShopWindow shopWindow, Base parent, int index, ContextMenu conte Icon.HoverLeave += Icon_HoverLeave; Icon.Clicked += Icon_RightClicked; Icon.DoubleClicked += Icon_DoubleClicked; - Icon.DisableDragAndDrop = true; LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString()); @@ -161,4 +162,25 @@ public void LoadItem() Icon.RenderColor = itemDescriptor.Color; } } + + public override bool DragAndDrop_HandleDrop(Package p, int x, int y) + { + var targetNode = Interface.FindComponentUnderCursor(); + + // Find the first parent acceptable in that tree that can accept the package + while (targetNode != default) + { + if (targetNode is not InventoryWindow) + { + targetNode = targetNode.Parent; + continue; + } + + Globals.Me?.TryBuyItem(_mySlot); + return true; + } + + // If we've reached the top of the tree, we can't drop here, so cancel drop + return false; + } } From 62e3ebb9e9e6674b1a729a84c9d2542463007cbe Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Fri, 14 Mar 2025 22:54:39 -0300 Subject: [PATCH 13/16] refactor the core of system with correct data/type --- Intersect.Client.Core/Interface/Game/Draggable.cs | 8 +++++++- Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs | 2 +- Intersect.Client.Core/Interface/Game/SlotItem.cs | 6 ++++++ Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs | 9 +++++++-- Intersect.Client.Framework/Gwen/Control/Base.cs | 4 ++-- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Intersect.Client.Core/Interface/Game/Draggable.cs b/Intersect.Client.Core/Interface/Game/Draggable.cs index 9afd863410..1205e3a1c5 100644 --- a/Intersect.Client.Core/Interface/Game/Draggable.cs +++ b/Intersect.Client.Core/Interface/Game/Draggable.cs @@ -8,12 +8,18 @@ public partial class Draggable(Base parent, string name) : ImagePanel(parent, na { public bool IsDragging => DragAndDrop.CurrentPackage?.DrawControl == this; + // TODO: Fix drag and drop names public override bool DragAndDrop_Draggable() { return true; } - public override Package DragAndDrop_GetPackage(int x, int y) + public override bool DragAndDrop_CanAcceptPackage(Package package) + { + return true; + } + + public override Package? DragAndDrop_GetPackage(int x, int y) { return new Package() { diff --git a/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs b/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs index 24b7f18a41..18332db7fe 100644 --- a/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs +++ b/Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs @@ -163,7 +163,7 @@ public void LoadItem() } } - public override bool DragAndDrop_HandleDrop(Package p, int x, int y) + public override bool DragAndDrop_HandleDrop(Package package, int x, int y) { var targetNode = Interface.FindComponentUnderCursor(); diff --git a/Intersect.Client.Core/Interface/Game/SlotItem.cs b/Intersect.Client.Core/Interface/Game/SlotItem.cs index 8b88fa8264..f0ddb79f30 100644 --- a/Intersect.Client.Core/Interface/Game/SlotItem.cs +++ b/Intersect.Client.Core/Interface/Game/SlotItem.cs @@ -1,5 +1,6 @@ using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; +using Intersect.Client.Framework.Gwen.DragDrop; namespace Intersect.Client.Interface.Game; @@ -42,6 +43,11 @@ public void OpenContextMenu() OnContextMenuOpening(contextMenu); } + public override bool DragAndDrop_CanAcceptPackage(Package package) + { + return true; + } + protected virtual void OnContextMenuOpening(ContextMenu contextMenu) { // Display our menu... If we have anything to display. diff --git a/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs b/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs index ef00dbb236..65bb84869a 100644 --- a/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs +++ b/Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs @@ -161,6 +161,11 @@ private void Icon_DoubleClicked(Base sender, MouseButtonState arguments) public override bool DragAndDrop_HandleDrop(Package package, int x, int y) { + if (Globals.Me is not { } player) + { + return false; + } + var targetNode = Interface.FindComponentUnderCursor(); // Find the first parent acceptable in that tree that can accept the package @@ -169,11 +174,11 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) switch (targetNode) { case SpellItem spellItem: - Globals.Me?.SwapSpells(SlotIndex, spellItem.SlotIndex); + player.SwapSpells(SlotIndex, spellItem.SlotIndex); return true; case HotbarItem hotbarItem: - Globals.Me?.AddToHotbar(hotbarItem.SlotIndex, 1, SlotIndex); + player.AddToHotbar(hotbarItem.SlotIndex, 1, SlotIndex); return true; default: diff --git a/Intersect.Client.Framework/Gwen/Control/Base.cs b/Intersect.Client.Framework/Gwen/Control/Base.cs index ac17834f23..acd903b296 100644 --- a/Intersect.Client.Framework/Gwen/Control/Base.cs +++ b/Intersect.Client.Framework/Gwen/Control/Base.cs @@ -4258,7 +4258,7 @@ public virtual void UpdateCursor() } // giver - public virtual Package DragAndDrop_GetPackage(int x, int y) + public virtual Package? DragAndDrop_GetPackage(int x, int y) { return _dragPayload; } @@ -4330,7 +4330,7 @@ public virtual void DragAndDrop_Hover(Package p, int x, int y) // receiver public virtual bool DragAndDrop_CanAcceptPackage(Package p) { - return true; + return false; } public record struct SizeToChildrenArgs( From 46fdea8139662a450e7a455aad81a5f236b8ae61 Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Fri, 14 Mar 2025 23:04:57 -0300 Subject: [PATCH 14/16] more cleaning and refactor --- .../Interface/Game/Bank/BankItem.cs | 48 +++++------ .../Interface/Game/Hotbar/HotbarItem.cs | 16 ++-- .../Interface/Game/Inventory/InventoryItem.cs | 83 +++++++++++-------- 3 files changed, 81 insertions(+), 66 deletions(-) diff --git a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs index 4b80b71ea3..ecb26c9f01 100644 --- a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs @@ -147,7 +147,7 @@ private void Icon_Clicked(Base sender, MouseButtonState arguments) private void Icon_DoubleClicked(Base sender, MouseButtonState arguments) { - if (!Globals.InBank) + if (arguments.MouseButton is not MouseButton.Left) { return; } @@ -183,6 +183,27 @@ private void Icon_DoubleClicked(Base sender, MouseButtonState arguments) public override bool DragAndDrop_HandleDrop(Package package, int x, int y) { + if (Globals.Me is not { } player) + { + return false; + } + + var rank = player.GuildRank; + var isInGuild = !string.IsNullOrWhiteSpace(player.Guild); + + if (!isInGuild || (player.Rank != 0 && rank?.Permissions.BankDeposit == false)) + { + ChatboxMsg.AddMessage( + new ChatboxMsg( + Strings.Guilds.NotAllowedSwap.ToString(player.Guild), + CustomColors.Alerts.Error, + ChatMessageType.Bank + ) + ); + + return false; + } + var targetNode = Interface.FindComponentUnderCursor(); // Find the first parent acceptable in that tree that can accept the package @@ -191,29 +212,6 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) switch (targetNode) { case BankItem bankItem: - if (Globals.IsGuildBank) - { - if (Globals.Me is not { } player) - { - return false; - } - - var rank = player.GuildRank; - var isInGuild = !string.IsNullOrWhiteSpace(player.Guild); - if (!isInGuild || (player.Rank != 0 && rank?.Permissions.BankDeposit == false)) - { - ChatboxMsg.AddMessage( - new ChatboxMsg( - Strings.Guilds.NotAllowedSwap.ToString(player.Guild), - CustomColors.Alerts.Error, - ChatMessageType.Bank - ) - ); - - return false; - } - } - PacketSender.SendMoveBankItems(SlotIndex, bankItem.SlotIndex); return true; @@ -229,7 +227,7 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) return false; } - Globals.Me?.TryRetrieveItemFromBank( + player.TryRetrieveItemFromBank( SlotIndex, inventorySlotIndex: inventoryItem.SlotIndex, quantityHint: slot.Quantity, diff --git a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs index 3e38d9a764..8a934f611d 100644 --- a/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs +++ b/Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs @@ -222,6 +222,11 @@ private void Icon_HoverEnter(Base sender, EventArgs arguments) public override bool DragAndDrop_HandleDrop(Package package, int x, int y) { + if (Globals.Me is not { } player) + { + return false; + } + var targetNode = Interface.FindComponentUnderCursor(); // Find the first parent acceptable in that tree that can accept the package @@ -229,7 +234,7 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) { if (targetNode is HotbarItem hotbarItem) { - Globals.Me?.HotbarSwap(SlotIndex, hotbarItem.SlotIndex); + player.HotbarSwap(SlotIndex, hotbarItem.SlotIndex); return true; } else @@ -394,6 +399,7 @@ public override void Update() } var isDragging = Icon.IsDragging; + var invalidInventoryIndex = _inventoryItemIndex < 0; if (isDragging) { _equipLabel.IsHidden = true; @@ -402,9 +408,9 @@ public override void Update() } else { - _equipLabel.IsHidden = !_isEquipped || _inventoryItemIndex < 0; - _quantityLabel.IsHidden = _currentItem?.Stackable == false || _inventoryItemIndex < 0; - _cooldownLabel.IsHidden = !_isFaded || _inventoryItemIndex < 0; + _equipLabel.IsHidden = !_isEquipped || invalidInventoryIndex; + _quantityLabel.IsHidden = _currentItem?.Stackable == false || invalidInventoryIndex; + _cooldownLabel.IsHidden = !_isFaded || invalidInventoryIndex; } if (updateDisplay) //Item on cd and fade is incorrect @@ -420,7 +426,7 @@ public override void Update() _quantityLabel.IsHidden = true; _cooldownLabel.IsHidden = true; - if (_inventoryItemIndex > -1) + if (!invalidInventoryIndex) { _isFaded = Globals.Me.IsItemOnCooldown(_inventoryItemIndex); _isEquipped = Globals.Me.IsEquipped(_inventoryItemIndex); diff --git a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs index 6c9be54bfa..61e39b21a2 100644 --- a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs +++ b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs @@ -204,7 +204,7 @@ private void _actionItemContextItem_Clicked(Base sender, MouseButtonState argume } } - private void _dropItemContextItem_Clicked(Base sender, Framework.Gwen.Control.EventArguments.MouseButtonState arguments) + private void _dropItemContextItem_Clicked(Base sender, MouseButtonState arguments) { Globals.Me?.TryDropItem(SlotIndex); } @@ -260,35 +260,41 @@ private void Icon_DoubleClicked(Base sender, MouseButtonState arguments) private void Icon_Clicked(Base sender, MouseButtonState arguments) { - if (arguments.MouseButton is MouseButton.Right) + if (arguments.MouseButton is not MouseButton.Right) { - if (ClientConfiguration.Instance.EnableContextMenus) - { - OpenContextMenu(); - } - else - { - if (Globals.GameShop != null) - { - Globals.Me?.TrySellItem(SlotIndex); - } - else if (Globals.InBank) - { - Globals.Me?.TryStoreItemInBank(SlotIndex); - } - else if (Globals.InBag) - { - Globals.Me?.TryStoreItemInBag(SlotIndex, -1); - } - else if (Globals.InTrade) - { - Globals.Me?.TryOfferItemToTrade(SlotIndex); - } - else - { - Globals.Me?.TryDropItem(SlotIndex); - } - } + return; + } + + if (ClientConfiguration.Instance.EnableContextMenus) + { + OpenContextMenu(); + return; + } + + if (Globals.Me is not { } player) + { + return; + } + + if (Globals.GameShop != null) + { + player.TrySellItem(SlotIndex); + } + else if (Globals.InBank) + { + player.TryStoreItemInBank(SlotIndex); + } + else if (Globals.InBag) + { + player.TryStoreItemInBag(SlotIndex, -1); + } + else if (Globals.InTrade) + { + player.TryOfferItemToTrade(SlotIndex); + } + else + { + player.TryDropItem(SlotIndex); } } @@ -404,7 +410,12 @@ void Icon_HoverEnter(Base? sender, EventArgs? arguments) public override bool DragAndDrop_HandleDrop(Package package, int x, int y) { - if (Globals.Me?.Inventory is not { } inventory) + if (Globals.Me is not { } player) + { + return false; + } + + if (player.Inventory is not { } inventory) { return false; } @@ -414,7 +425,7 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) return false; } - if (!Interface.DoesMouseHitInterface() && !Globals.Me.IsBusy) + if (!Interface.DoesMouseHitInterface() && !player.IsBusy) { PacketSender.SendDropItem(SlotIndex, inventorySlot.Quantity); return true; @@ -433,15 +444,15 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) return false; } - Globals.Me?.SwapItems(SlotIndex, inventoryItem.SlotIndex); + player.SwapItems(SlotIndex, inventoryItem.SlotIndex); return true; case BagItem bagItem: - Globals.Me?.TryStoreItemInBag(SlotIndex, bagItem.SlotIndex); + player.TryStoreItemInBag(SlotIndex, bagItem.SlotIndex); return true; case BankItem bankItem: - Globals.Me?.TryStoreItemInBank( + player.TryStoreItemInBank( SlotIndex, bankSlotIndex: bankItem.SlotIndex, quantityHint: inventorySlot.Quantity, @@ -450,11 +461,11 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) return true; case HotbarItem hotbarItem: - Globals.Me?.AddToHotbar(hotbarItem.SlotIndex, 0, SlotIndex); + player.AddToHotbar(hotbarItem.SlotIndex, 0, SlotIndex); return true; case ShopWindow: - Globals.Me?.TrySellItem(SlotIndex); + player.TrySellItem(SlotIndex); return true; default: From 1d31084bf329a7eeeab30f7645e2cfbb14a14ed9 Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Sat, 15 Mar 2025 15:53:00 -0300 Subject: [PATCH 15/16] small tweaks --- Intersect.Client.Core/Interface/Game/Bank/BankItem.cs | 2 +- Intersect.Client.Framework/Gwen/Control/Base.cs | 1 + Intersect.Client.Framework/Input/ControlBinding.cs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs index ecb26c9f01..b4f97a3bb0 100644 --- a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs @@ -191,7 +191,7 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) var rank = player.GuildRank; var isInGuild = !string.IsNullOrWhiteSpace(player.Guild); - if (!isInGuild || (player.Rank != 0 && rank?.Permissions.BankDeposit == false)) + if (!isInGuild || (Globals.IsGuildBank && player.Rank != 0 && rank?.Permissions.BankDeposit == false)) { ChatboxMsg.AddMessage( new ChatboxMsg( diff --git a/Intersect.Client.Framework/Gwen/Control/Base.cs b/Intersect.Client.Framework/Gwen/Control/Base.cs index acd903b296..1ac4e9d4c7 100644 --- a/Intersect.Client.Framework/Gwen/Control/Base.cs +++ b/Intersect.Client.Framework/Gwen/Control/Base.cs @@ -4264,6 +4264,7 @@ public virtual void UpdateCursor() } // giver + // TODO: Fix drag and drop names public virtual bool DragAndDrop_Draggable() { if (_dragPayload == null) diff --git a/Intersect.Client.Framework/Input/ControlBinding.cs b/Intersect.Client.Framework/Input/ControlBinding.cs index 84243c3e89..3914ab59e4 100644 --- a/Intersect.Client.Framework/Input/ControlBinding.cs +++ b/Intersect.Client.Framework/Input/ControlBinding.cs @@ -53,7 +53,7 @@ public bool WasDown() if (IsMouseKey && Key.TryGetMouseButton(out var mouseButton)) { - return gameInput.WasMouseButtonDown(mouseButton); + return gameInput.WasMouseButtonDown(mouseButton) && !DragAndDrop.IsDragging; } return gameInput.WasKeyDown(Key); From 5cba8270f7bb0767774acd36a248f12ef2fe59f2 Mon Sep 17 00:00:00 2001 From: WeylonSantana Date: Sat, 15 Mar 2025 15:57:05 -0300 Subject: [PATCH 16/16] fix guild bank not swapping for guildless user --- .../Interface/Game/Bank/BankItem.cs | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs index b4f97a3bb0..5bd52ab8bb 100644 --- a/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs +++ b/Intersect.Client.Core/Interface/Game/Bank/BankItem.cs @@ -191,17 +191,20 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y) var rank = player.GuildRank; var isInGuild = !string.IsNullOrWhiteSpace(player.Guild); - if (!isInGuild || (Globals.IsGuildBank && player.Rank != 0 && rank?.Permissions.BankDeposit == false)) + if (Globals.IsGuildBank) { - ChatboxMsg.AddMessage( - new ChatboxMsg( - Strings.Guilds.NotAllowedSwap.ToString(player.Guild), - CustomColors.Alerts.Error, - ChatMessageType.Bank - ) - ); - - return false; + if (!isInGuild || (player.Rank != 0 && rank?.Permissions.BankDeposit == false)) + { + ChatboxMsg.AddMessage( + new ChatboxMsg( + Strings.Guilds.NotAllowedSwap.ToString(player.Guild), + CustomColors.Alerts.Error, + ChatMessageType.Bank + ) + ); + + return false; + } } var targetNode = Interface.FindComponentUnderCursor();