Skip to content

Commit 46fdea8

Browse files
committed
more cleaning and refactor
1 parent 62e3ebb commit 46fdea8

File tree

3 files changed

+81
-66
lines changed

3 files changed

+81
-66
lines changed

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

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private void Icon_Clicked(Base sender, MouseButtonState arguments)
147147

148148
private void Icon_DoubleClicked(Base sender, MouseButtonState arguments)
149149
{
150-
if (!Globals.InBank)
150+
if (arguments.MouseButton is not MouseButton.Left)
151151
{
152152
return;
153153
}
@@ -183,6 +183,27 @@ private void Icon_DoubleClicked(Base sender, MouseButtonState arguments)
183183

184184
public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
185185
{
186+
if (Globals.Me is not { } player)
187+
{
188+
return false;
189+
}
190+
191+
var rank = player.GuildRank;
192+
var isInGuild = !string.IsNullOrWhiteSpace(player.Guild);
193+
194+
if (!isInGuild || (player.Rank != 0 && rank?.Permissions.BankDeposit == false))
195+
{
196+
ChatboxMsg.AddMessage(
197+
new ChatboxMsg(
198+
Strings.Guilds.NotAllowedSwap.ToString(player.Guild),
199+
CustomColors.Alerts.Error,
200+
ChatMessageType.Bank
201+
)
202+
);
203+
204+
return false;
205+
}
206+
186207
var targetNode = Interface.FindComponentUnderCursor();
187208

188209
// 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)
191212
switch (targetNode)
192213
{
193214
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-
217215
PacketSender.SendMoveBankItems(SlotIndex, bankItem.SlotIndex);
218216
return true;
219217

@@ -229,7 +227,7 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
229227
return false;
230228
}
231229

232-
Globals.Me?.TryRetrieveItemFromBank(
230+
player.TryRetrieveItemFromBank(
233231
SlotIndex,
234232
inventorySlotIndex: inventoryItem.SlotIndex,
235233
quantityHint: slot.Quantity,

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,19 @@ private void Icon_HoverEnter(Base sender, EventArgs arguments)
222222

223223
public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
224224
{
225+
if (Globals.Me is not { } player)
226+
{
227+
return false;
228+
}
229+
225230
var targetNode = Interface.FindComponentUnderCursor();
226231

227232
// Find the first parent acceptable in that tree that can accept the package
228233
while (targetNode != default)
229234
{
230235
if (targetNode is HotbarItem hotbarItem)
231236
{
232-
Globals.Me?.HotbarSwap(SlotIndex, hotbarItem.SlotIndex);
237+
player.HotbarSwap(SlotIndex, hotbarItem.SlotIndex);
233238
return true;
234239
}
235240
else
@@ -394,6 +399,7 @@ public override void Update()
394399
}
395400

396401
var isDragging = Icon.IsDragging;
402+
var invalidInventoryIndex = _inventoryItemIndex < 0;
397403
if (isDragging)
398404
{
399405
_equipLabel.IsHidden = true;
@@ -402,9 +408,9 @@ public override void Update()
402408
}
403409
else
404410
{
405-
_equipLabel.IsHidden = !_isEquipped || _inventoryItemIndex < 0;
406-
_quantityLabel.IsHidden = _currentItem?.Stackable == false || _inventoryItemIndex < 0;
407-
_cooldownLabel.IsHidden = !_isFaded || _inventoryItemIndex < 0;
411+
_equipLabel.IsHidden = !_isEquipped || invalidInventoryIndex;
412+
_quantityLabel.IsHidden = _currentItem?.Stackable == false || invalidInventoryIndex;
413+
_cooldownLabel.IsHidden = !_isFaded || invalidInventoryIndex;
408414
}
409415

410416
if (updateDisplay) //Item on cd and fade is incorrect
@@ -420,7 +426,7 @@ public override void Update()
420426
_quantityLabel.IsHidden = true;
421427
_cooldownLabel.IsHidden = true;
422428

423-
if (_inventoryItemIndex > -1)
429+
if (!invalidInventoryIndex)
424430
{
425431
_isFaded = Globals.Me.IsItemOnCooldown(_inventoryItemIndex);
426432
_isEquipped = Globals.Me.IsEquipped(_inventoryItemIndex);

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

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ private void _actionItemContextItem_Clicked(Base sender, MouseButtonState argume
204204
}
205205
}
206206

207-
private void _dropItemContextItem_Clicked(Base sender, Framework.Gwen.Control.EventArguments.MouseButtonState arguments)
207+
private void _dropItemContextItem_Clicked(Base sender, MouseButtonState arguments)
208208
{
209209
Globals.Me?.TryDropItem(SlotIndex);
210210
}
@@ -260,35 +260,41 @@ private void Icon_DoubleClicked(Base sender, MouseButtonState arguments)
260260

261261
private void Icon_Clicked(Base sender, MouseButtonState arguments)
262262
{
263-
if (arguments.MouseButton is MouseButton.Right)
263+
if (arguments.MouseButton is not MouseButton.Right)
264264
{
265-
if (ClientConfiguration.Instance.EnableContextMenus)
266-
{
267-
OpenContextMenu();
268-
}
269-
else
270-
{
271-
if (Globals.GameShop != null)
272-
{
273-
Globals.Me?.TrySellItem(SlotIndex);
274-
}
275-
else if (Globals.InBank)
276-
{
277-
Globals.Me?.TryStoreItemInBank(SlotIndex);
278-
}
279-
else if (Globals.InBag)
280-
{
281-
Globals.Me?.TryStoreItemInBag(SlotIndex, -1);
282-
}
283-
else if (Globals.InTrade)
284-
{
285-
Globals.Me?.TryOfferItemToTrade(SlotIndex);
286-
}
287-
else
288-
{
289-
Globals.Me?.TryDropItem(SlotIndex);
290-
}
291-
}
265+
return;
266+
}
267+
268+
if (ClientConfiguration.Instance.EnableContextMenus)
269+
{
270+
OpenContextMenu();
271+
return;
272+
}
273+
274+
if (Globals.Me is not { } player)
275+
{
276+
return;
277+
}
278+
279+
if (Globals.GameShop != null)
280+
{
281+
player.TrySellItem(SlotIndex);
282+
}
283+
else if (Globals.InBank)
284+
{
285+
player.TryStoreItemInBank(SlotIndex);
286+
}
287+
else if (Globals.InBag)
288+
{
289+
player.TryStoreItemInBag(SlotIndex, -1);
290+
}
291+
else if (Globals.InTrade)
292+
{
293+
player.TryOfferItemToTrade(SlotIndex);
294+
}
295+
else
296+
{
297+
player.TryDropItem(SlotIndex);
292298
}
293299
}
294300

@@ -404,7 +410,12 @@ void Icon_HoverEnter(Base? sender, EventArgs? arguments)
404410

405411
public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
406412
{
407-
if (Globals.Me?.Inventory is not { } inventory)
413+
if (Globals.Me is not { } player)
414+
{
415+
return false;
416+
}
417+
418+
if (player.Inventory is not { } inventory)
408419
{
409420
return false;
410421
}
@@ -414,7 +425,7 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
414425
return false;
415426
}
416427

417-
if (!Interface.DoesMouseHitInterface() && !Globals.Me.IsBusy)
428+
if (!Interface.DoesMouseHitInterface() && !player.IsBusy)
418429
{
419430
PacketSender.SendDropItem(SlotIndex, inventorySlot.Quantity);
420431
return true;
@@ -433,15 +444,15 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
433444
return false;
434445
}
435446

436-
Globals.Me?.SwapItems(SlotIndex, inventoryItem.SlotIndex);
447+
player.SwapItems(SlotIndex, inventoryItem.SlotIndex);
437448
return true;
438449

439450
case BagItem bagItem:
440-
Globals.Me?.TryStoreItemInBag(SlotIndex, bagItem.SlotIndex);
451+
player.TryStoreItemInBag(SlotIndex, bagItem.SlotIndex);
441452
return true;
442453

443454
case BankItem bankItem:
444-
Globals.Me?.TryStoreItemInBank(
455+
player.TryStoreItemInBank(
445456
SlotIndex,
446457
bankSlotIndex: bankItem.SlotIndex,
447458
quantityHint: inventorySlot.Quantity,
@@ -450,11 +461,11 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
450461
return true;
451462

452463
case HotbarItem hotbarItem:
453-
Globals.Me?.AddToHotbar(hotbarItem.SlotIndex, 0, SlotIndex);
464+
player.AddToHotbar(hotbarItem.SlotIndex, 0, SlotIndex);
454465
return true;
455466

456467
case ShopWindow:
457-
Globals.Me?.TrySellItem(SlotIndex);
468+
player.TrySellItem(SlotIndex);
458469
return true;
459470

460471
default:

0 commit comments

Comments
 (0)