Skip to content

Commit c76c8e5

Browse files
committed
update: hotkeys and bags handling for DragAndDrop_HandleDrop
- Required logic update after fixes for item's icon handling. - (bags seriously need a big refactor): replaced direct packet store (buggy) and slider (never been coded properly) for at least, a simple and functional YesNo Prompt that stores whole item stacks from inventory. - HotbarItem case returns false (required so items don't go invisible when placing them to hotbars). - SpellItem to Hotbar case returns false (required so spells don't go invisible when placing them to hotbars). - fixes quantityLabels logic - visually functional bags and bank items when moving them around
1 parent 44c1a0a commit c76c8e5

10 files changed

Lines changed: 57 additions & 54 deletions

File tree

Intersect.Client.Core/Entities/Player.cs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,41 +1121,32 @@ public void TryStoreItemInBag(int inventorySlotIndex, int bagSlotIndex)
11211121
}
11221122

11231123
var quantity = inventorySlot.Quantity;
1124-
var maxQuantity = quantity;
1125-
1126-
if (maxQuantity < 2)
1127-
{
1128-
PacketSender.SendStoreBagItem(inventorySlotIndex, 1, bagSlotIndex);
1129-
return;
1130-
}
11311124

11321125
_ = new InputBox(
11331126
title: Strings.Bags.StoreItem,
11341127
prompt: Strings.Bags.StoreItemPrompt.ToString(itemDescriptor.Name),
1135-
inputType: InputType.NumericSliderInput,
1128+
inputType: InputType.YesNo,
11361129
quantity: quantity,
1137-
maximumQuantity: maxQuantity,
1138-
userData: new Tuple<int, int>(inventorySlotIndex, bagSlotIndex),
1130+
userData: new Tuple<int, int, int>(inventorySlotIndex, bagSlotIndex, quantity),
11391131
onSubmit: TryStoreItemInBagOnSubmit
11401132
);
11411133
}
11421134

11431135
private static void TryStoreItemInBagOnSubmit(Base sender, InputSubmissionEventArgs args)
11441136
{
1145-
if (sender is not InputBox { UserData: (int inventorySlotIndex, int bagSlotIndex) })
1137+
if (sender is not InputBox { UserData: (int inventorySlotIndex, int bagSlotIndex, int quantity) })
11461138
{
11471139
return;
11481140
}
11491141

1150-
if (args.Value is not NumericalSubmissionValue submissionValue)
1142+
if (args.Value is not BooleanSubmissionValue submissionValue)
11511143
{
11521144
return;
11531145
}
11541146

1155-
var value = (int)Math.Round(submissionValue.Value);
1156-
if (value > 0)
1147+
if (submissionValue.Value)
11571148
{
1158-
PacketSender.SendStoreBagItem(inventorySlotIndex, value, bagSlotIndex);
1149+
PacketSender.SendStoreBagItem(inventorySlotIndex, quantity, bagSlotIndex);
11591150
}
11601151
}
11611152

@@ -1445,12 +1436,17 @@ public void AddToHotbar(int hotbarSlot, sbyte itemType, int itemSlot)
14451436
PacketSender.SendHotbarUpdate(hotbarSlot, itemType, itemSlot);
14461437
}
14471438

1448-
public void HotbarSwap(int index, int swapIndex)
1439+
public bool HotbarSwap(int index, int swapIndex)
14491440
{
14501441
var itemId = Hotbar[index].ItemOrSpellId;
14511442
var bagId = Hotbar[index].BagId;
14521443
var stats = Hotbar[index].PreferredStatBuffs;
14531444

1445+
if (Hotbar[swapIndex].ItemOrSpellId == itemId)
1446+
{
1447+
return false;
1448+
}
1449+
14541450
Hotbar[index].ItemOrSpellId = Hotbar[swapIndex].ItemOrSpellId;
14551451
Hotbar[index].BagId = Hotbar[swapIndex].BagId;
14561452
Hotbar[index].PreferredStatBuffs = Hotbar[swapIndex].PreferredStatBuffs;
@@ -1460,6 +1456,7 @@ public void HotbarSwap(int index, int swapIndex)
14601456
Hotbar[swapIndex].PreferredStatBuffs = stats;
14611457

14621458
PacketSender.SendHotbarSwap(index, swapIndex);
1459+
return true;
14631460
}
14641461

14651462
// Change the dimension if the player is on a gateway

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ public partial class BagItem : SlotItem
1919
{
2020
// Controls
2121
private readonly Label _quantityLabel;
22-
private readonly BagWindow _bagWindow;
2322

2423
// Context Menu Handling
2524
private readonly MenuItem _withdrawContextItem;
2625

27-
public BagItem(BagWindow bagWindow, Base parent, int index, ContextMenu contextMenu)
26+
public BagItem(Base parent, int index, ContextMenu contextMenu)
2827
: base(parent, nameof(BagItem), index, contextMenu)
2928
{
30-
_bagWindow = bagWindow;
3129
TextureFilename = "bagitem.png";
3230

3331
Icon.HoverEnter += Icon_HoverEnter;
@@ -145,6 +143,16 @@ private void Icon_DoubleClicked(Base sender, MouseButtonState arguments)
145143

146144
public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
147145
{
146+
if (Globals.Me is not { } player)
147+
{
148+
return false;
149+
}
150+
151+
if (Globals.BagSlots is not { Length: > 0 } bagSlots)
152+
{
153+
return false;
154+
}
155+
148156
var targetNode = Interface.FindComponentUnderCursor();
149157

150158
// Find the first parent acceptable in that tree that can accept the package
@@ -154,11 +162,11 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
154162
{
155163
case BagItem bagItem:
156164
PacketSender.SendMoveBagItems(SlotIndex, bagItem.SlotIndex);
157-
return true;
165+
return bagSlots[bagItem.SlotIndex] is not { Quantity: > 0 };
158166

159167
case InventoryItem inventoryItem:
160-
Globals.Me?.TryRetrieveItemFromBag(SlotIndex, inventoryItem.SlotIndex);
161-
return true;
168+
player.TryRetrieveItemFromBag(SlotIndex, inventoryItem.SlotIndex);
169+
return bagSlots[inventoryItem.SlotIndex] is not { Quantity: > 0 };
162170

163171
default:
164172
targetNode = targetNode.Parent;
@@ -194,7 +202,7 @@ public override void Update()
194202
var bagSlot = bagSlots[SlotIndex];
195203
var descriptor = bagSlot.Descriptor;
196204

197-
_quantityLabel.IsVisibleInParent = !Icon.IsDragging && descriptor.IsStackable && bagSlot.Quantity > 1;
205+
_quantityLabel.IsVisibleInParent = !Icon.IsHidden && descriptor.IsStackable && bagSlot.Quantity > 1;
198206
if (_quantityLabel.IsVisibleInParent)
199207
{
200208
_quantityLabel.Text = Strings.FormatQuantityAbbreviated(bagSlot.Quantity);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private void InitItemContainer()
5858

5959
for (var slotIndex = 0; slotIndex < bagSlots.Length; slotIndex++)
6060
{
61-
Items.Add(new BagItem(this, _slotContainer, slotIndex, _contextMenu));
61+
Items.Add(new BagItem(_slotContainer, slotIndex, _contextMenu));
6262
}
6363

6464
PopulateSlotContainer.Populate(_slotContainer, Items);

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@ public partial class BankItem : SlotItem
2222
{
2323
// Controls
2424
private readonly Label _quantityLabel;
25-
private BankWindow _bankWindow;
2625

2726
// Context Menu Handling
2827
private MenuItem _withdrawContextItem;
2928

30-
public BankItem(BankWindow bankWindow, Base parent, int index, ContextMenu contextMenu) :
31-
base(parent, nameof(BankItem), index, contextMenu)
29+
public BankItem(Base parent, int index, ContextMenu contextMenu) : base(parent, nameof(BankItem), index, contextMenu)
3230
{
33-
_bankWindow = bankWindow;
3431
TextureFilename = "bankitem.png";
3532

3633
Icon.HoverEnter += Icon_HoverEnter;
@@ -105,6 +102,7 @@ private void Icon_HoverEnter(Base? sender, EventArgs? arguments)
105102

106103
if (bankSlots[SlotIndex] is not { Descriptor: not null } or { Quantity: <= 0 })
107104
{
105+
_quantityLabel.IsVisibleInParent = false;
108106
return;
109107
}
110108

@@ -194,29 +192,28 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
194192
}
195193
}
196194

195+
if (Globals.BankSlots is not { Length: > 0 } bankSlots)
196+
{
197+
return false;
198+
}
199+
197200
var targetNode = Interface.FindComponentUnderCursor();
198201

199202
// Find the first parent acceptable in that tree that can accept the package
200203
while (targetNode != default)
201204
{
205+
if (bankSlots[SlotIndex] is not { Quantity: > 0 } slot)
206+
{
207+
return false;
208+
}
209+
202210
switch (targetNode)
203211
{
204212
case BankItem bankItem:
205213
PacketSender.SendMoveBankItems(SlotIndex, bankItem.SlotIndex);
206-
return true;
214+
return bankSlots[bankItem.SlotIndex] is not { Quantity: > 0 };
207215

208216
case InventoryItem inventoryItem:
209-
210-
if (Globals.BankSlots is not { Length: > 0 } bankSlots)
211-
{
212-
return false;
213-
}
214-
215-
if (bankSlots[SlotIndex] is not { Quantity: > 0 } slot)
216-
{
217-
return false;
218-
}
219-
220217
player.TryRetrieveItemFromBank(
221218
SlotIndex,
222219
inventorySlotIndex: inventoryItem.SlotIndex,
@@ -259,7 +256,7 @@ public override void Update()
259256
var bankSlot = bankSlots[SlotIndex];
260257
var descriptor = bankSlot.Descriptor;
261258

262-
_quantityLabel.IsVisibleInParent = !Icon.IsDragging && descriptor.IsStackable && bankSlot.Quantity > 1;
259+
_quantityLabel.IsVisibleInParent = descriptor.IsStackable && bankSlot.Quantity > 1 && !Icon.IsHidden;
263260
if (_quantityLabel.IsVisibleInParent)
264261
{
265262
_quantityLabel.Text = Strings.FormatQuantityAbbreviated(bankSlot.Quantity);
@@ -283,6 +280,7 @@ public override void Update()
283280
{
284281
Icon.Texture = default;
285282
Icon.IsVisibleInParent = false;
283+
_quantityLabel.IsVisibleInParent = false;
286284
}
287285
}
288286
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private void InitItemContainer()
6767
{
6868
for (var slotIndex = 0; slotIndex < Globals.BankSlotCount; slotIndex++)
6969
{
70-
Items.Add(new BankItem(this, _slotContainer, slotIndex, _contextMenu));
70+
Items.Add(new BankItem(_slotContainer, slotIndex, _contextMenu));
7171
}
7272

7373
PopulateSlotContainer.Populate(_slotContainer, Items);

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,9 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
217217
if (targetNode is HotbarItem hotbarItem)
218218
{
219219
player.HotbarSwap(SlotIndex, hotbarItem.SlotIndex);
220-
return true;
221-
}
222-
else
223-
{
224-
targetNode = targetNode.Parent;
225220
}
221+
222+
targetNode = targetNode.Parent;
226223
}
227224

228225
// If we've reached the top of the tree, we can't drop here, so cancel drop

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
421421

422422
case BagItem bagItem:
423423
player.TryStoreItemInBag(SlotIndex, bagItem.SlotIndex);
424-
return true;
424+
return false;
425425

426426
case BankItem bankItem:
427427
return player.TryStoreItemInBank(
@@ -433,11 +433,11 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
433433

434434
case HotbarItem hotbarItem:
435435
player.AddToHotbar(hotbarItem.SlotIndex, 0, SlotIndex);
436-
return true;
436+
return false;
437437

438438
case ShopWindow:
439439
player.TrySellItem(SlotIndex);
440-
return true;
440+
return false;
441441

442442
default:
443443
targetNode = targetNode.Parent;
@@ -500,7 +500,7 @@ public override void Update()
500500
_equipImageBackground.IsVisibleInParent = !isDragging && equipped;
501501
_equipLabel.IsVisibleInParent = !isDragging && equipped;
502502

503-
_quantityLabel.IsVisibleInParent = !isDragging && descriptor.IsStackable && inventorySlot.Quantity > 1;
503+
_quantityLabel.IsVisibleInParent = !Icon.IsHidden && descriptor.IsStackable && inventorySlot.Quantity > 1;
504504
if (_quantityLabel.IsVisibleInParent)
505505
{
506506
_quantityLabel.Text = Strings.FormatQuantityAbbreviated(inventorySlot.Quantity);

Intersect.Client.Core/Interface/Game/Spells/SpellItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
173173

174174
case HotbarItem hotbarItem:
175175
player.AddToHotbar(hotbarItem.SlotIndex, 1, SlotIndex);
176-
return true;
176+
return false;
177177

178178
default:
179179
targetNode = targetNode.Parent;

Intersect.Client.Core/Localization/Strings.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,10 @@ public partial struct Bags
541541
public static LocalizedString StoreItem = @"Store Item";
542542

543543
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
544-
public static LocalizedString StoreItemPrompt = @"How many/much {00} would you like to store?";
544+
public static LocalizedString StoreMultipleItemPrompt = @"How many/much {00} would you like to store?";
545+
546+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
547+
public static LocalizedString StoreItemPrompt = @"Do you wish to store the item: {00} ?";
545548

546549
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
547550
public static LocalizedString Title = @"Bag";

Intersect.Client.Framework/Entities/IPlayer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public interface IPlayer : IEntity
3434
void AddToHotbar(int hotbarSlot, sbyte itemType, int itemSlot);
3535
int FindHotbarItem(IHotbarInstance hotbarInstance);
3636
int FindHotbarSpell(IHotbarInstance hotbarInstance);
37-
void HotbarSwap(int index, int swapIndex);
37+
bool HotbarSwap(int index, int swapIndex);
3838
int FindItem(Guid itemId, int itemVal = 1);
3939
void SwapItems(int item1, int item2);
4040
long GetItemCooldown(Guid id);

0 commit comments

Comments
 (0)