Skip to content

Commit

Permalink
Implement requested changes for PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
sjbmcg committed Apr 20, 2024
1 parent a1db30f commit 966e411
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
46 changes: 26 additions & 20 deletions EndlessClient/Controllers/InventoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using EndlessClient.HUD.Panels;
using EndlessClient.Rendering.Character;
using EndlessClient.Rendering.Map;
using EndlessClient.Audio;
using EOLib;
using EOLib.Domain.Chat;
using EOLib.Domain.Character;
Expand Down Expand Up @@ -51,6 +52,7 @@ public class InventoryController : IInventoryController
private readonly IEOMessageBoxFactory _eoMessageBoxFactory;
private readonly IChatRepository _chatRepository;
private readonly ILocalizedStringFinder _localizedStringFinder;
private readonly ISfxPlayer _sfxPlayer;
private bool _goldWarningShown = false;

public InventoryController(IItemActions itemActions,
Expand All @@ -73,7 +75,8 @@ public InventoryController(IItemActions itemActions,
IItemTransferDialogFactory itemTransferDialogFactory,
IEOMessageBoxFactory eoMessageBoxFactory,
IChatRepository chatRepository,
ILocalizedStringFinder localizedStringFinder)
ILocalizedStringFinder localizedStringFinder,
ISfxPlayer sfxPlayer)
{
_itemActions = itemActions;
_inGameDialogActions = inGameDialogActions;
Expand All @@ -96,6 +99,7 @@ public InventoryController(IItemActions itemActions,
_eoMessageBoxFactory = eoMessageBoxFactory;
_chatRepository = chatRepository;
_localizedStringFinder = localizedStringFinder;
_sfxPlayer = sfxPlayer;
}

public void ShowPaperdollDialog()
Expand Down Expand Up @@ -352,40 +356,42 @@ public void TradeItem(EIFRecord itemData, InventoryItem inventoryItem)
}

private void DoItemDrop(EIFRecord itemData, InventoryItem inventoryItem, Action<int> dropAction,
ItemTransferDialog.TransferType transferType = ItemTransferDialog.TransferType.DropItems,
EOResourceID message = EOResourceID.DIALOG_TRANSFER_DROP)
ItemTransferDialog.TransferType transferType = ItemTransferDialog.TransferType.DropItems,
EOResourceID message = EOResourceID.DIALOG_TRANSFER_DROP)
{
bool playDefaultSound = true;

if (inventoryItem.Amount > 1)
{
if (inventoryItem.ItemID == 1 && inventoryItem.Amount > 10000 && transferType == ItemTransferDialog.TransferType.DropItems)
{
playDefaultSound = false;
}

var transferDialog = _itemTransferDialogFactory.CreateItemTransferDialog(
itemData.Name,
transferType,
inventoryItem.Amount,
message);
message,
playDefaultSound);

transferDialog.DialogClosing += (sender, e) =>
{
if (e.Result == XNADialogResult.OK)
{
if (inventoryItem.ItemID == 1 && transferDialog.SelectedAmount > 10000 && transferType == ItemTransferDialog.TransferType.DropItems)
if (!playDefaultSound && !_goldWarningShown)
{
if (!_goldWarningShown)
var warningMsg = _eoMessageBoxFactory.CreateMessageBox(DialogResourceID.DROP_MANY_GOLD_ON_GROUND, EODialogButtons.OkCancel);
warningMsg.DialogClosing += (_, warningArgs) =>
{
var warningMsg = _eoMessageBoxFactory.CreateMessageBox(DialogResourceID.DROP_MANY_GOLD_ON_GROUND, EODialogButtons.OkCancel);
warningMsg.DialogClosing += (_, warningArgs) =>
if (warningArgs.Result == XNADialogResult.OK)
{
if (warningArgs.Result == XNADialogResult.OK)
{
dropAction(transferDialog.SelectedAmount);
}
};
warningMsg.ShowDialog();
_goldWarningShown = true;
}
else
{
dropAction(transferDialog.SelectedAmount);
}
dropAction(transferDialog.SelectedAmount);
_sfxPlayer.PlaySfx(SoundEffectID.Login);
_goldWarningShown = true;
}
};
warningMsg.ShowDialog();
}
else
{
Expand Down
20 changes: 7 additions & 13 deletions EndlessClient/Dialogs/Factories/ItemTransferDialogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using EndlessClient.HUD.Chat;
using EOLib.Graphics;
using EOLib.Localization;
using System;

namespace EndlessClient.Dialogs.Factories
{
Expand All @@ -18,7 +17,6 @@ public class ItemTransferDialogFactory : IItemTransferDialogFactory
private readonly ILocalizedStringFinder _localizedStringFinder;
private readonly IContentProvider _contentProvider;
private readonly ISfxPlayer _sfxPlayer;
private bool _goldSoundPlayed = false;

public ItemTransferDialogFactory(INativeGraphicsManager nativeGraphicsManager,
IChatTextBoxActions chatTextBoxActions,
Expand All @@ -35,7 +33,7 @@ public ItemTransferDialogFactory(INativeGraphicsManager nativeGraphicsManager,
_sfxPlayer = sfxPlayer;
}

public ItemTransferDialog CreateItemTransferDialog(string itemName, ItemTransferDialog.TransferType transferType, int totalAmount, EOResourceID message)
public ItemTransferDialog CreateItemTransferDialog(string itemName, ItemTransferDialog.TransferType transferType, int totalAmount, EOResourceID message, bool playDefaultSound = true)
{
var dlg = new ItemTransferDialog(_nativeGraphicsManager,
_chatTextBoxActions,
Expand All @@ -47,24 +45,20 @@ public ItemTransferDialog CreateItemTransferDialog(string itemName, ItemTransfer
totalAmount,
message);

dlg.DialogClosing += (_, _) =>
if (playDefaultSound)
{
if (itemName == "Gold" && !_goldSoundPlayed)
{
_sfxPlayer.PlaySfx(SoundEffectID.Login);
_goldSoundPlayed = true;
}
else if (itemName != "Gold")
dlg.DialogClosing += (_, _) =>
{
_sfxPlayer.PlaySfx(SoundEffectID.DialogButtonClick);
}
};
};
}

return dlg;
}
}

public interface IItemTransferDialogFactory
{
ItemTransferDialog CreateItemTransferDialog(string itemName, ItemTransferDialog.TransferType transferType, int totalAmount, EOResourceID message);
ItemTransferDialog CreateItemTransferDialog(string itemName, ItemTransferDialog.TransferType transferType, int totalAmount, EOResourceID message, bool playDefaultSound = true);
}
}

0 comments on commit 966e411

Please sign in to comment.