Skip to content

Commit e33fad4

Browse files
committed
added drag and drop logic on slot items
1 parent 8d9b65a commit e33fad4

File tree

9 files changed

+281
-2
lines changed

9 files changed

+281
-2
lines changed

Intersect.Client.Core/Interface/Game/Bag/BagItem.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
using Intersect.Client.Framework.Gwen;
44
using Intersect.Client.Framework.Gwen.Control;
55
using Intersect.Client.Framework.Gwen.Control.EventArguments;
6+
using Intersect.Client.Framework.Gwen.DragDrop;
67
using Intersect.Client.Framework.Gwen.Input;
78
using Intersect.Client.Framework.Input;
89
using Intersect.Client.General;
910
using Intersect.Client.Interface.Game.DescriptionWindows;
11+
using Intersect.Client.Interface.Game.Inventory;
1012
using Intersect.Client.Localization;
13+
using Intersect.Client.Networking;
1114
using Intersect.Configuration;
1215
using Intersect.Framework.Core.GameObjects.Items;
1316

@@ -150,6 +153,42 @@ private void _iconImage_DoubleClicked(Base sender, MouseButtonState arguments)
150153

151154
#endregion
152155

156+
#region Drag and Drop
157+
158+
public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
159+
{
160+
var targetNode = Interface.FindComponentUnderCursor(NodeFilter.None);
161+
162+
// Find the first parent acceptable in that tree that can accept the package
163+
while (targetNode != default)
164+
{
165+
switch (targetNode)
166+
{
167+
case BagItem bagItem:
168+
PacketSender.SendMoveBagItems(SlotIndex, bagItem.SlotIndex);
169+
return true;
170+
171+
case InventoryItem inventoryItem:
172+
Globals.Me?.TryRetrieveItemFromBag(SlotIndex, inventoryItem.SlotIndex);
173+
return true;
174+
175+
default:
176+
targetNode = targetNode.Parent;
177+
break;
178+
}
179+
180+
// If we've reached the top of the tree, we can't drop here, so cancel drop
181+
if (targetNode == null)
182+
{
183+
return false;
184+
}
185+
}
186+
187+
return false;
188+
}
189+
190+
#endregion
191+
153192
public override void Update()
154193
{
155194
if (Globals.Me == default)

Intersect.Client.Core/Interface/Game/Bank/BankItem.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
using Intersect.Client.Framework.Gwen;
55
using Intersect.Client.Framework.Gwen.Control;
66
using Intersect.Client.Framework.Gwen.Control.EventArguments;
7+
using Intersect.Client.Framework.Gwen.DragDrop;
78
using Intersect.Client.Framework.Gwen.Input;
89
using Intersect.Client.Framework.Input;
910
using Intersect.Client.General;
11+
using Intersect.Client.Interface.Game.Chat;
1012
using Intersect.Client.Interface.Game.DescriptionWindows;
13+
using Intersect.Client.Interface.Game.Inventory;
1114
using Intersect.Client.Localization;
15+
using Intersect.Client.Networking;
1216
using Intersect.Configuration;
17+
using Intersect.Enums;
1318
using Intersect.Framework.Core.GameObjects.Items;
1419

1520
namespace Intersect.Client.Interface.Game.Bank;
@@ -52,6 +57,8 @@ public BankItem(BankWindow bankWindow, Base parent, int index, ContextMenu conte
5257
contextMenu.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
5358
}
5459

60+
#region Context Menu
61+
5562
protected override void OnContextMenuOpening(ContextMenu contextMenu)
5663
{
5764
if (Globals.BankSlots is not { Length: > 0 } bankSlots)
@@ -77,6 +84,8 @@ private void _withdrawMenuItem_Clicked(Base sender, MouseButtonState arguments)
7784
Globals.Me?.TryRetrieveItemFromBank(SlotIndex);
7885
}
7986

87+
#endregion
88+
8089
#region Mouse Events
8190

8291
private void _iconImage_HoverEnter(Base? sender, EventArgs? arguments)
@@ -170,6 +179,81 @@ private void _iconImage_DoubleClicked(Base sender, MouseButtonState arguments)
170179

171180
#endregion
172181

182+
#region Drag and Drop
183+
184+
public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
185+
{
186+
var targetNode = Interface.FindComponentUnderCursor(NodeFilter.None);
187+
188+
// Find the first parent acceptable in that tree that can accept the package
189+
while (targetNode != default)
190+
{
191+
switch (targetNode)
192+
{
193+
case BankItem bankItem:
194+
if (Globals.IsGuildBank)
195+
{
196+
if (Globals.Me is not { } player)
197+
{
198+
return false;
199+
}
200+
201+
var rank = player.GuildRank;
202+
var isInGuild = !string.IsNullOrWhiteSpace(player.Guild);
203+
if (!isInGuild || (player.Rank != 0 && rank?.Permissions.BankDeposit == false))
204+
{
205+
ChatboxMsg.AddMessage(
206+
new ChatboxMsg(
207+
Strings.Guilds.NotAllowedSwap.ToString(player.Guild),
208+
CustomColors.Alerts.Error,
209+
ChatMessageType.Bank
210+
)
211+
);
212+
213+
return false;
214+
}
215+
}
216+
217+
PacketSender.SendMoveBankItems(SlotIndex, bankItem.SlotIndex);
218+
return true;
219+
220+
case InventoryItem inventoryItem:
221+
222+
if (Globals.BankSlots is not { Length: > 0 } bankSlots)
223+
{
224+
return false;
225+
}
226+
227+
if (bankSlots[SlotIndex] is not { Quantity: > 0 } slot)
228+
{
229+
return false;
230+
}
231+
232+
Globals.Me?.TryRetrieveItemFromBank(
233+
SlotIndex,
234+
inventorySlotIndex: inventoryItem.SlotIndex,
235+
quantityHint: slot.Quantity,
236+
skipPrompt: true
237+
);
238+
return true;
239+
240+
default:
241+
targetNode = targetNode.Parent;
242+
break;
243+
}
244+
245+
// If we've reached the top of the tree, we can't drop here, so cancel drop
246+
if (targetNode == null)
247+
{
248+
return false;
249+
}
250+
}
251+
252+
return false;
253+
}
254+
255+
#endregion
256+
173257
public new void Update()
174258
{
175259
if (Globals.Me == default)

Intersect.Client.Core/Interface/Game/Draggable.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ namespace Intersect.Client.Interface.Game;
66

77
public partial class Draggable(Base parent, string name) : ImagePanel(parent, name)
88
{
9+
public bool DisableDragAndDrop { get; set; } = false;
10+
911
public override bool DragAndDrop_Draggable()
1012
{
1113
return true;
1214
}
1315

1416
public override Package DragAndDrop_GetPackage(int x, int y)
1517
{
18+
if (DisableDragAndDrop)
19+
{
20+
return null;
21+
}
22+
1623
return new Package()
1724
{
1825
IsDraggable = true,

Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
using Intersect.Client.Framework.Gwen;
55
using Intersect.Client.Framework.Gwen.Control;
66
using Intersect.Client.Framework.Gwen.Control.EventArguments;
7+
using Intersect.Client.Framework.Gwen.DragDrop;
78
using Intersect.Client.Framework.Gwen.Input;
89
using Intersect.Client.Framework.Input;
910
using Intersect.Client.General;
1011
using Intersect.Client.Interface.Game.DescriptionWindows;
12+
using Intersect.Client.Interface.Game.Inventory;
13+
using Intersect.Client.Interface.Game.Spells;
1114
using Intersect.Client.Items;
1215
using Intersect.Client.Localization;
1316
using Intersect.Client.Spells;
@@ -206,6 +209,33 @@ private void _iconImage_HoverEnter(Base sender, EventArgs arguments)
206209
}
207210
}
208211

212+
public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
213+
{
214+
var targetNode = Interface.FindComponentUnderCursor(NodeFilter.None);
215+
216+
// Find the first parent acceptable in that tree that can accept the package
217+
while (targetNode != default)
218+
{
219+
if (targetNode is HotbarItem hotbarItem)
220+
{
221+
Globals.Me?.HotbarSwap(SlotIndex, hotbarItem.SlotIndex);
222+
return true;
223+
}
224+
else
225+
{
226+
targetNode = targetNode.Parent;
227+
}
228+
229+
// If we've reached the top of the tree, we can't drop here, so cancel drop
230+
if (targetNode == null)
231+
{
232+
return false;
233+
}
234+
}
235+
236+
return false;
237+
}
238+
209239
public void Update()
210240
{
211241
if (Globals.Me == null || Controls.ActiveControls == null)

Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
using Intersect.Client.Framework.Gwen;
66
using Intersect.Client.Framework.Gwen.Control;
77
using Intersect.Client.Framework.Gwen.Control.EventArguments;
8+
using Intersect.Client.Framework.Gwen.DragDrop;
89
using Intersect.Client.Framework.Gwen.Input;
910
using Intersect.Client.Framework.Input;
1011
using Intersect.Client.General;
12+
using Intersect.Client.Interface.Game.Bag;
13+
using Intersect.Client.Interface.Game.Bank;
1114
using Intersect.Client.Interface.Game.DescriptionWindows;
15+
using Intersect.Client.Interface.Game.Hotbar;
16+
using Intersect.Client.Interface.Game.Shop;
1217
using Intersect.Client.Localization;
18+
using Intersect.Client.Networking;
1319
using Intersect.Configuration;
1420
using Intersect.Framework.Core.GameObjects.Items;
1521
using Intersect.GameObjects;
@@ -395,6 +401,80 @@ void _iconImage_HoverEnter(Base? sender, EventArgs? arguments)
395401

396402
#endregion
397403

404+
#region Drag and Drop
405+
406+
public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
407+
{
408+
if (Globals.Me?.Inventory is not { } inventory)
409+
{
410+
return false;
411+
}
412+
413+
if (inventory[SlotIndex] is not { } inventorySlot)
414+
{
415+
return false;
416+
}
417+
418+
if (!Interface.DoesMouseHitInterface() && !Globals.Me.IsBusy)
419+
{
420+
PacketSender.SendDropItem(SlotIndex, inventorySlot.Quantity);
421+
return true;
422+
}
423+
424+
var targetNode = Interface.FindComponentUnderCursor(NodeFilter.None);
425+
426+
// Find the first parent acceptable in that tree that can accept the package
427+
while (targetNode != default)
428+
{
429+
switch (targetNode)
430+
{
431+
case InventoryItem inventoryItem:
432+
if (inventoryItem.SlotIndex == SlotIndex)
433+
{
434+
return false;
435+
}
436+
437+
Globals.Me?.SwapItems(SlotIndex, inventoryItem.SlotIndex);
438+
return true;
439+
440+
case BagItem bagItem:
441+
Globals.Me?.TryStoreItemInBag(SlotIndex, bagItem.SlotIndex);
442+
return true;
443+
444+
case BankItem bankItem:
445+
Globals.Me?.TryStoreItemInBank(
446+
SlotIndex,
447+
bankSlotIndex: bankItem.SlotIndex,
448+
quantityHint: inventorySlot.Quantity,
449+
skipPrompt: true
450+
);
451+
return true;
452+
453+
case HotbarItem hotbarItem:
454+
Globals.Me?.AddToHotbar(hotbarItem.SlotIndex, 0, SlotIndex);
455+
return true;
456+
457+
case ShopWindow:
458+
Globals.Me?.TrySellItem(SlotIndex);
459+
return true;
460+
461+
default:
462+
targetNode = targetNode.Parent;
463+
break;
464+
}
465+
466+
// If we've reached the top of the tree, we can't drop here, so return false
467+
if (targetNode == null)
468+
{
469+
return false;
470+
}
471+
}
472+
473+
return false;
474+
}
475+
476+
#endregion
477+
398478
private void PlayerOnInventoryUpdated(Player player, int slotIndex)
399479
{
400480
if (player != Globals.Me)

Intersect.Client.Core/Interface/Game/Shop/ShopItem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public ShopItem(ShopWindow shopWindow, Base parent, int index, ContextMenu conte
3030
_iconImage.HoverLeave += _iconImage_HoverLeave;
3131
_iconImage.Clicked += _iconImage_RightClicked;
3232
_iconImage.DoubleClicked += _iconImage_DoubleClicked;
33+
_iconImage.DisableDragAndDrop = true;
3334

3435
LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
3536

Intersect.Client.Core/Interface/Game/SlotItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Intersect.Client.Interface.Game;
66
public partial class SlotItem : ImagePanel
77
{
88
public readonly int SlotIndex;
9-
protected readonly ImagePanel _iconImage;
9+
protected readonly Draggable _iconImage;
1010
protected readonly ContextMenu? _contextMenu;
1111

1212
public SlotItem(Base parent, string name, int index, ContextMenu? contextMenu) : base(parent, name)

0 commit comments

Comments
 (0)