Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions Intersect.Client.Core/Entities/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,16 @@ public void TryDropItem(int inventorySlotIndex)
}

var quantity = inventorySlot.Quantity;
var canDropMultiple = quantity > 1;
var maxQuantity = GetQuantityOfItemInInventory(itemDescriptor.Id);
var canDropMultiple = maxQuantity > 1;
var inputType = canDropMultiple ? InputType.NumericSliderInput : InputType.YesNo;
var prompt = canDropMultiple ? Strings.Inventory.DropItemPrompt : Strings.Inventory.DropPrompt;
_ = new InputBox(
title: Strings.Inventory.DropItemTitle,
prompt: prompt.ToString(itemDescriptor.Name),
inputType: inputType,
quantity: quantity,
maximumQuantity: GetQuantityOfItemInInventory(itemDescriptor.Id),
maximumQuantity: maxQuantity,
userData: inventorySlotIndex,
onSubmit: (sender, args) =>
{
Expand Down Expand Up @@ -1120,41 +1121,32 @@ public void TryStoreItemInBag(int inventorySlotIndex, int bagSlotIndex)
}

var quantity = inventorySlot.Quantity;
var maxQuantity = quantity;

if (maxQuantity < 2)
{
PacketSender.SendStoreBagItem(inventorySlotIndex, 1, bagSlotIndex);
return;
}

_ = new InputBox(
title: Strings.Bags.StoreItem,
prompt: Strings.Bags.StoreItemPrompt.ToString(itemDescriptor.Name),
inputType: InputType.NumericSliderInput,
inputType: InputType.YesNo,
quantity: quantity,
maximumQuantity: maxQuantity,
userData: new Tuple<int, int>(inventorySlotIndex, bagSlotIndex),
userData: new Tuple<int, int, int>(inventorySlotIndex, bagSlotIndex, quantity),
onSubmit: TryStoreItemInBagOnSubmit
);
}

private static void TryStoreItemInBagOnSubmit(Base sender, InputSubmissionEventArgs args)
{
if (sender is not InputBox { UserData: (int inventorySlotIndex, int bagSlotIndex) })
if (sender is not InputBox { UserData: (int inventorySlotIndex, int bagSlotIndex, int quantity) })
{
return;
}

if (args.Value is not NumericalSubmissionValue submissionValue)
if (args.Value is not BooleanSubmissionValue submissionValue)
{
return;
}

var value = (int)Math.Round(submissionValue.Value);
if (value > 0)
if (submissionValue.Value)
{
PacketSender.SendStoreBagItem(inventorySlotIndex, value, bagSlotIndex);
PacketSender.SendStoreBagItem(inventorySlotIndex, quantity, bagSlotIndex);
}
}

Expand Down Expand Up @@ -1444,12 +1436,17 @@ public void AddToHotbar(int hotbarSlot, sbyte itemType, int itemSlot)
PacketSender.SendHotbarUpdate(hotbarSlot, itemType, itemSlot);
}

public void HotbarSwap(int index, int swapIndex)
public bool HotbarSwap(int index, int swapIndex)
{
var itemId = Hotbar[index].ItemOrSpellId;
var bagId = Hotbar[index].BagId;
var stats = Hotbar[index].PreferredStatBuffs;

if (Hotbar[swapIndex].ItemOrSpellId == itemId)
{
return false;
}

Hotbar[index].ItemOrSpellId = Hotbar[swapIndex].ItemOrSpellId;
Hotbar[index].BagId = Hotbar[swapIndex].BagId;
Hotbar[index].PreferredStatBuffs = Hotbar[swapIndex].PreferredStatBuffs;
Expand All @@ -1459,6 +1456,7 @@ public void HotbarSwap(int index, int swapIndex)
Hotbar[swapIndex].PreferredStatBuffs = stats;

PacketSender.SendHotbarSwap(index, swapIndex);
return true;
}

// Change the dimension if the player is on a gateway
Expand Down
22 changes: 15 additions & 7 deletions Intersect.Client.Core/Interface/Game/Bag/BagItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ public partial class BagItem : SlotItem
{
// Controls
private readonly Label _quantityLabel;
private readonly BagWindow _bagWindow;

// Context Menu Handling
private readonly MenuItem _withdrawContextItem;

public BagItem(BagWindow bagWindow, Base parent, int index, ContextMenu contextMenu)
public BagItem(Base parent, int index, ContextMenu contextMenu)
: base(parent, nameof(BagItem), index, contextMenu)
{
_bagWindow = bagWindow;
TextureFilename = "bagitem.png";

Icon.HoverEnter += Icon_HoverEnter;
Expand Down Expand Up @@ -145,6 +143,16 @@ 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;
}

if (Globals.BagSlots is not { Length: > 0 } bagSlots)
{
return false;
}

var targetNode = Interface.FindComponentUnderCursor();

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

case InventoryItem inventoryItem:
Globals.Me?.TryRetrieveItemFromBag(SlotIndex, inventoryItem.SlotIndex);
return true;
player.TryRetrieveItemFromBag(SlotIndex, inventoryItem.SlotIndex);
return bagSlots[inventoryItem.SlotIndex] is not { Quantity: > 0 };

default:
targetNode = targetNode.Parent;
Expand Down Expand Up @@ -194,7 +202,7 @@ public override void Update()
var bagSlot = bagSlots[SlotIndex];
var descriptor = bagSlot.Descriptor;

_quantityLabel.IsVisibleInParent = !Icon.IsDragging && descriptor.IsStackable && bagSlot.Quantity > 1;
_quantityLabel.IsVisibleInParent = !Icon.IsHidden && descriptor.IsStackable && bagSlot.Quantity > 1;
if (_quantityLabel.IsVisibleInParent)
{
_quantityLabel.Text = Strings.FormatQuantityAbbreviated(bagSlot.Quantity);
Expand Down
2 changes: 1 addition & 1 deletion Intersect.Client.Core/Interface/Game/Bag/BagWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void InitItemContainer()

for (var slotIndex = 0; slotIndex < bagSlots.Length; slotIndex++)
{
Items.Add(new BagItem(this, _slotContainer, slotIndex, _contextMenu));
Items.Add(new BagItem(_slotContainer, slotIndex, _contextMenu));
}

PopulateSlotContainer.Populate(_slotContainer, Items);
Expand Down
32 changes: 15 additions & 17 deletions Intersect.Client.Core/Interface/Game/Bank/BankItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@ public partial class BankItem : SlotItem
{
// Controls
private readonly Label _quantityLabel;
private BankWindow _bankWindow;

// Context Menu Handling
private MenuItem _withdrawContextItem;

public BankItem(BankWindow bankWindow, Base parent, int index, ContextMenu contextMenu) :
base(parent, nameof(BankItem), index, contextMenu)
public BankItem(Base parent, int index, ContextMenu contextMenu) : base(parent, nameof(BankItem), index, contextMenu)
{
_bankWindow = bankWindow;
TextureFilename = "bankitem.png";

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

if (bankSlots[SlotIndex] is not { Descriptor: not null } or { Quantity: <= 0 })
{
_quantityLabel.IsVisibleInParent = false;
return;
}

Expand Down Expand Up @@ -194,29 +192,28 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
}
}

if (Globals.BankSlots is not { Length: > 0 } bankSlots)
{
return false;
}

var targetNode = Interface.FindComponentUnderCursor();

// Find the first parent acceptable in that tree that can accept the package
while (targetNode != default)
{
if (bankSlots[SlotIndex] is not { Quantity: > 0 } slot)
{
return false;
}

switch (targetNode)
{
case BankItem bankItem:
PacketSender.SendMoveBankItems(SlotIndex, bankItem.SlotIndex);
return true;
return bankSlots[bankItem.SlotIndex] is not { Quantity: > 0 };

case InventoryItem inventoryItem:

if (Globals.BankSlots is not { Length: > 0 } bankSlots)
{
return false;
}

if (bankSlots[SlotIndex] is not { Quantity: > 0 } slot)
{
return false;
}

player.TryRetrieveItemFromBank(
SlotIndex,
inventorySlotIndex: inventoryItem.SlotIndex,
Expand Down Expand Up @@ -259,7 +256,7 @@ public override void Update()
var bankSlot = bankSlots[SlotIndex];
var descriptor = bankSlot.Descriptor;

_quantityLabel.IsVisibleInParent = !Icon.IsDragging && descriptor.IsStackable && bankSlot.Quantity > 1;
_quantityLabel.IsVisibleInParent = descriptor.IsStackable && bankSlot.Quantity > 1 && !Icon.IsHidden;
if (_quantityLabel.IsVisibleInParent)
{
_quantityLabel.Text = Strings.FormatQuantityAbbreviated(bankSlot.Quantity);
Expand All @@ -283,6 +280,7 @@ public override void Update()
{
Icon.Texture = default;
Icon.IsVisibleInParent = false;
_quantityLabel.IsVisibleInParent = false;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Intersect.Client.Core/Interface/Game/Bank/BankWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void InitItemContainer()
{
for (var slotIndex = 0; slotIndex < Globals.BankSlotCount; slotIndex++)
{
Items.Add(new BankItem(this, _slotContainer, slotIndex, _contextMenu));
Items.Add(new BankItem(_slotContainer, slotIndex, _contextMenu));
}

PopulateSlotContainer.Populate(_slotContainer, Items);
Expand Down
3 changes: 0 additions & 3 deletions Intersect.Client.Core/Interface/Game/Crafting/RecipeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Intersect.Client.General;
using Intersect.Framework.Core.GameObjects.Crafting;
using Intersect.Framework.Core.GameObjects.Items;
using Intersect.GameObjects;

namespace Intersect.Client.Interface.Game.Crafting;

Expand All @@ -14,8 +13,6 @@ public partial class RecipeItem

public ImagePanel? Container;

public bool IsDragging;

//Dragging
private bool mCanDrag;

Expand Down
22 changes: 21 additions & 1 deletion Intersect.Client.Core/Interface/Game/Draggable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public override bool DragAndDrop_Draggable()

public override bool DragAndDrop_CanAcceptPackage(Package package)
{
// Important: Icon is the topmost hovered control, so it must be allowed to "receive" the drop, BUT: we forward handling to SlotItem.
return true;
}

Expand All @@ -27,6 +28,7 @@ public override bool DragAndDrop_CanAcceptPackage(Package package)
DrawControl = this,
Name = Name,
HoldOffset = ToLocal(InputHandler.MousePosition.X, InputHandler.MousePosition.Y),
UserData = Parent, // Expected to be SlotItem (InventoryItem/BankItem/etc)
};
}

Expand All @@ -37,6 +39,24 @@ public override void DragAndDrop_StartDragging(Package package, int x, int y)

public override void DragAndDrop_EndDragging(bool success, int x, int y)
{
IsVisibleInParent = true;
IsVisibleInParent = !success;
}

public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
{
// Never allow Base.DragAndDrop_HandleDrop() to run on the icon because it reparents SourceControl (Base.cs)
// Forward drop handling to the slot (or nearest SlotItem ancestor).
var node = Parent;
while (node != null)
{
if (node is SlotItem)
{
return node.DragAndDrop_HandleDrop(package, x, y);
}

node = node.Parent;
}

return false;
}
}
7 changes: 2 additions & 5 deletions Intersect.Client.Core/Interface/Game/Hotbar/HotbarItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,9 @@ public override bool DragAndDrop_HandleDrop(Package package, int x, int y)
if (targetNode is HotbarItem hotbarItem)
{
player.HotbarSwap(SlotIndex, hotbarItem.SlotIndex);
return true;
}
else
{
targetNode = targetNode.Parent;
}

targetNode = targetNode.Parent;
}

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