Skip to content

Commit

Permalink
Update inventory drag+drop to work with bank deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Sep 15, 2022
1 parent cc295d6 commit 716f636
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
25 changes: 24 additions & 1 deletion EndlessClient/Controllers/InventoryController.cs
Expand Up @@ -10,6 +10,7 @@
using EOLib;
using EOLib.Domain.Character;
using EOLib.Domain.Interact;
using EOLib.Domain.Interact.Bank;
using EOLib.Domain.Item;
using EOLib.Domain.Map;
using EOLib.IO;
Expand All @@ -30,6 +31,7 @@ public class InventoryController : IInventoryController
private readonly IPaperdollActions _paperdollActions;
private readonly IChestActions _chestActions;
private readonly ILockerActions _lockerActions;
private readonly IBankActions _bankActions;
private readonly IItemEquipValidator _itemEquipValidator;
private readonly IItemDropValidator _itemDropValidator;
private readonly ICharacterProvider _characterProvider;
Expand All @@ -47,6 +49,7 @@ public class InventoryController : IInventoryController
IPaperdollActions paperdollActions,
IChestActions chestActions,
ILockerActions lockerActions,
IBankActions bankActions,
IItemEquipValidator itemEquipValidator,
IItemDropValidator itemDropValidator,
ICharacterProvider characterProvider,
Expand All @@ -64,6 +67,7 @@ public class InventoryController : IInventoryController
_paperdollActions = paperdollActions;
_chestActions = chestActions;
_lockerActions = lockerActions;
_bankActions = bankActions;
_itemEquipValidator = itemEquipValidator;
_itemDropValidator = itemDropValidator;
_characterProvider = characterProvider;
Expand Down Expand Up @@ -262,6 +266,23 @@ public void DropItemInLocker(EIFRecord itemData, InventoryItem inventoryItem)
}
}

public void DropItemInBank(EIFRecord itemData, InventoryItem inventoryItem)
{
if (inventoryItem.Amount == 0)
{
var dlg = _eoMessageBoxFactory.CreateMessageBox(DialogResourceID.BANK_ACCOUNT_UNABLE_TO_DEPOSIT);
dlg.ShowDialog();
}
else
{
DoItemDrop(itemData,
inventoryItem,
a => _bankActions.Deposit(a),
ItemTransferDialog.TransferType.BankTransfer,
EOResourceID.DIALOG_TRANSFER_DEPOSIT);
}
}

public void JunkItem(EIFRecord itemData, InventoryItem inventoryItem)
{
if (inventoryItem.Amount > 1)
Expand Down Expand Up @@ -301,7 +322,7 @@ public void JunkItem(EIFRecord itemData, InventoryItem inventoryItem)
{
if (e.Result == XNADialogResult.OK)
{
if (inventoryItem.ItemID == 1 && transferDialog.SelectedAmount > 10000)
if (inventoryItem.ItemID == 1 && transferDialog.SelectedAmount > 10000 && transferType == ItemTransferDialog.TransferType.DropItems)
{
var warningMsg = _eoMessageBoxFactory.CreateMessageBox(DialogResourceID.DROP_MANY_GOLD_ON_GROUND, EODialogButtons.OkCancel);
warningMsg.DialogClosing += (_, warningArgs) =>
Expand Down Expand Up @@ -342,6 +363,8 @@ public interface IInventoryController

void DropItemInLocker(EIFRecord itemData, InventoryItem inventoryItem);

void DropItemInBank(EIFRecord itemData, InventoryItem inventoryItem);

void JunkItem(EIFRecord itemData, InventoryItem inventoryItem);
}
}
9 changes: 9 additions & 0 deletions EndlessClient/Dialogs/BankAccountDialog.cs
Expand Up @@ -139,6 +139,9 @@ protected override void OnUpdateControl(GameTime gameTime)

private void Deposit(object sender, EventArgs e)
{
if (!_inventoryPanel.NoItemsDragging())
return;

_characterInventoryProvider.ItemInventory.SingleOrNone(x => x.ItemID == 1)
.Match(
some: characterGold =>
Expand Down Expand Up @@ -176,6 +179,9 @@ private void Deposit(object sender, EventArgs e)

private void Withdraw(object sender, EventArgs e)
{
if (!_inventoryPanel.NoItemsDragging())
return;

if (_bankDataProvider.AccountValue == 0)
{
var dlg = _messageBoxFactory.CreateMessageBox(DialogResourceID.BANK_ACCOUNT_UNABLE_TO_WITHDRAW);
Expand All @@ -201,6 +207,9 @@ private void Withdraw(object sender, EventArgs e)

private void Upgrade(object sender, EventArgs e)
{
if (!_inventoryPanel.NoItemsDragging())
return;

_bankDataProvider.LockerUpgrades.MatchSome(lockerUpgrades =>
{
if (lockerUpgrades == Constants.MaxLockerUpgrades)
Expand Down
35 changes: 9 additions & 26 deletions EndlessClient/HUD/Panels/InventoryPanel.cs
Expand Up @@ -416,6 +416,14 @@ private void HandleItemDoneDragging(object sender, InventoryPanelItem.ItemDragCo
_inventoryController.DropItemInLocker(item.Data, item.InventoryItem);
}
});
_activeDialogProvider.BankAccountDialog.MatchSome(x =>
{
if (x.MouseOver && x.MouseOverPreviously && item.Data.ID == 1)
{
dialogDrop = true;
_inventoryController.DropItemInBank(item.Data, item.InventoryItem);
}
});

if (dialogDrop)
{
Expand Down Expand Up @@ -479,32 +487,7 @@ private void HandleItemDoneDragging(object sender, InventoryPanelItem.ItemDragCo

#region Unimplemented drag action
/*
if (BankAccountDialog.Instance != null && BankAccountDialog.Instance.MouseOver && BankAccountDialog.Instance.MouseOverPreviously && m_inventory.ItemID == 1)
{
if (m_inventory.Amount == 0)
{
EOMessageBox.Show(DialogResourceID.BANK_ACCOUNT_UNABLE_TO_DEPOSIT, EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
}
else if (m_inventory.Amount > 1)
{
ItemTransferDialog dlg = new ItemTransferDialog(m_itemData.Name, ItemTransferDialog.TransferType.BankTransfer,
m_inventory.Amount, EOResourceID.DIALOG_TRANSFER_DEPOSIT);
dlg.DialogClosing += (o, e) =>
{
if (e.Result == XNADialogResult.Cancel)
return;
if (!m_api.BankDeposit(dlg.SelectedAmount))
EOGame.Instance.DoShowLostConnectionDialogAndReturnToMainMenu();
};
}
else
{
if (!m_api.BankDeposit(1))
EOGame.Instance.DoShowLostConnectionDialogAndReturnToMainMenu();
}
}
else if (TradeDialog.Instance != null && TradeDialog.Instance.MouseOver && TradeDialog.Instance.MouseOverPreviously
if (TradeDialog.Instance != null && TradeDialog.Instance.MouseOver && TradeDialog.Instance.MouseOverPreviously
&& !TradeDialog.Instance.MainPlayerAgrees)
{
if (m_itemData.Special == ItemSpecial.Lore)
Expand Down

0 comments on commit 716f636

Please sign in to comment.