diff --git a/EndlessClient/Dialogs/Actions/InGameDialogActions.cs b/EndlessClient/Dialogs/Actions/InGameDialogActions.cs index 37521c394..957eba9d4 100644 --- a/EndlessClient/Dialogs/Actions/InGameDialogActions.cs +++ b/EndlessClient/Dialogs/Actions/InGameDialogActions.cs @@ -29,6 +29,7 @@ public class InGameDialogActions : IInGameDialogActions private readonly ISkillmasterDialogFactory _skillmasterDialogFactory; private readonly IBardDialogFactory _bardDialogFactory; private readonly IScrollingListDialogFactory _scrollingListDialogFactory; + private readonly ITradeDialogFactory _tradeDialogFactory; private readonly ISfxPlayer _sfxPlayer; private readonly IShopDialogFactory _shopDialogFactory; private readonly IQuestDialogFactory _questDialogFactory; @@ -49,6 +50,7 @@ public InGameDialogActions(IFriendIgnoreListDialogFactory friendIgnoreListDialog ISkillmasterDialogFactory skillmasterDialogFactory, IBardDialogFactory bardDialogFactory, IScrollingListDialogFactory scrollingListDialogFactory, + ITradeDialogFactory tradeDialogFactory, ISfxPlayer sfxPlayer) { _friendIgnoreListDialogFactory = friendIgnoreListDialogFactory; @@ -65,6 +67,7 @@ public InGameDialogActions(IFriendIgnoreListDialogFactory friendIgnoreListDialog _skillmasterDialogFactory = skillmasterDialogFactory; _bardDialogFactory = bardDialogFactory; _scrollingListDialogFactory = scrollingListDialogFactory; + _tradeDialogFactory = tradeDialogFactory; _sfxPlayer = sfxPlayer; _shopDialogFactory = shopDialogFactory; _questDialogFactory = questDialogFactory; @@ -281,6 +284,25 @@ public void ShowMessageDialog(string title, IReadOnlyList messages) }); } + public void ShowTradeDialog() + { + _activeDialogRepository.TradeDialog.MatchNone(() => + { + var dlg = _tradeDialogFactory.Create(); + dlg.DialogClosed += (_, _) => _activeDialogRepository.TradeDialog = Option.None(); + _activeDialogRepository.TradeDialog = Option.Some(dlg); + + UseDefaultDialogSounds(dlg); + + dlg.Show(); + }); + } + + public void CloseTradeDialog() + { + _activeDialogRepository.TradeDialog.MatchSome(dlg => dlg.Close()); + } + private void UseDefaultDialogSounds(ScrollingListDialog dialog) { UseDefaultDialogSounds((BaseEODialog)dialog); @@ -334,5 +356,9 @@ public interface IInGameDialogActions void ShowBardDialog(); void ShowMessageDialog(string title, IReadOnlyList messages); + + void ShowTradeDialog(); + + void CloseTradeDialog(); } } diff --git a/EndlessClient/Dialogs/Actions/TradeDialogActions.cs b/EndlessClient/Dialogs/Actions/TradeDialogActions.cs index 7dd69ecb4..5d0da0b4e 100644 --- a/EndlessClient/Dialogs/Actions/TradeDialogActions.cs +++ b/EndlessClient/Dialogs/Actions/TradeDialogActions.cs @@ -1,7 +1,8 @@ using AutomaticTypeMapper; using EndlessClient.Dialogs.Factories; +using EndlessClient.HUD; using EOLib.Config; -using EOLib.Domain.Map; +using EOLib.Domain.Character; using EOLib.Domain.Notifiers; using EOLib.Domain.Trade; using EOLib.Localization; @@ -13,15 +14,30 @@ namespace EndlessClient.Dialogs.Actions public class TradeDialogActions : ITradeEventNotifier { private readonly ITradeActions _tradeActions; + private readonly IInGameDialogActions _inGameDialogActions; private readonly IEOMessageBoxFactory _messageBoxFactory; + private readonly IStatusLabelSetter _statusLabelSetter; + private readonly ILocalizedStringFinder _localizedStringFinder; + private readonly ITradeProvider _tradeProvider; + private readonly ICharacterProvider _characterProvider; private readonly IConfigurationProvider _configurationProvider; public TradeDialogActions(ITradeActions tradeActions, + IInGameDialogActions inGameDialogActions, IEOMessageBoxFactory messageBoxFactory, + IStatusLabelSetter statusLabelSetter, + ILocalizedStringFinder localizedStringFinder, + ITradeProvider tradeProvider, + ICharacterProvider characterProvider, IConfigurationProvider configurationProvider) { _tradeActions = tradeActions; + _inGameDialogActions = inGameDialogActions; _messageBoxFactory = messageBoxFactory; + _statusLabelSetter = statusLabelSetter; + _localizedStringFinder = localizedStringFinder; + _tradeProvider = tradeProvider; + _characterProvider = characterProvider; _configurationProvider = configurationProvider; } @@ -44,24 +60,28 @@ public void NotifyTradeRequest(short playerId, string name) public void NotifyTradeAccepted() { - // todo: show trade dialog + _inGameDialogActions.ShowTradeDialog(); - // todo: status label - //m_game.Hud.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_ACTION, EOResourceID.STATUS_LABEL_TRADE_YOU_ARE_TRADING_WITH, - // otherName + " " + OldWorld.GetString(EOResourceID.STATUS_LABEL_DRAG_AND_DROP_ITEMS)); + var otherName = _tradeProvider.PlayerOneOffer.PlayerID == _characterProvider.MainCharacter.ID + ? _tradeProvider.PlayerOneOffer.PlayerName + : _tradeProvider.PlayerTwoOffer.PlayerName; + _statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_ACTION, + EOResourceID.STATUS_LABEL_TRADE_YOU_ARE_TRADING_WITH, + $"{otherName} {_localizedStringFinder.GetString(EOResourceID.STATUS_LABEL_DRAG_AND_DROP_ITEMS)}"); } public void NotifyTradeClose(bool cancel) { - // todo: close trade dialog + _inGameDialogActions.CloseTradeDialog(); if (cancel) { - //m_game.Hud.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_ACTION, EOResourceID.STATUS_LABEL_TRADE_ABORTED); + _statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_ACTION, EOResourceID.STATUS_LABEL_TRADE_ABORTED); } else { - //EOMessageBox.Show(DialogResourceID.TRADE_SUCCESS, EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader); + var dlg = _messageBoxFactory.CreateMessageBox(DialogResourceID.TRADE_SUCCESS); + dlg.ShowDialog(); } } } diff --git a/EndlessClient/Dialogs/BaseEODialog.cs b/EndlessClient/Dialogs/BaseEODialog.cs index 8a64c10c3..4ee98c542 100644 --- a/EndlessClient/Dialogs/BaseEODialog.cs +++ b/EndlessClient/Dialogs/BaseEODialog.cs @@ -34,5 +34,12 @@ public override void CenterInGameView() if (_isInGame()) DrawPosition = new Vector2(DrawPosition.X, (330 - DrawArea.Height)/2f); } + + protected override void OnUpdateControl(GameTime gameTime) + { + ChildControlClickHandled = false; + + base.OnUpdateControl(gameTime); + } } } diff --git a/EndlessClient/Dialogs/Factories/TradeDialogFactory.cs b/EndlessClient/Dialogs/Factories/TradeDialogFactory.cs new file mode 100644 index 000000000..ebaeaa872 --- /dev/null +++ b/EndlessClient/Dialogs/Factories/TradeDialogFactory.cs @@ -0,0 +1,80 @@ +using AutomaticTypeMapper; +using EndlessClient.Dialogs.Services; +using EndlessClient.HUD.Inventory; +using EndlessClient.HUD; +using EndlessClient.Rendering.Map; +using EOLib.Domain.Character; +using EOLib.Domain.Trade; +using EOLib.Graphics; +using EOLib.IO.Repositories; +using EOLib.Localization; +using EndlessClient.ControlSets; +using EndlessClient.HUD.Panels; + +namespace EndlessClient.Dialogs.Factories +{ + [AutoMappedType] + public class TradeDialogFactory : ITradeDialogFactory + { + private readonly INativeGraphicsManager _nativeGraphicsManager; + private readonly ITradeActions _tradeActions; + private readonly ILocalizedStringFinder _localizedStringFinder; + private readonly IEODialogButtonService _dialogButtonService; + private readonly IEOMessageBoxFactory _messageBoxFactory; + private readonly IStatusLabelSetter _statusLabelSetter; + private readonly IInventorySpaceValidator _inventorySpaceValidator; + private readonly ITradeProvider _tradeProvider; + private readonly ICharacterProvider _characterProvider; + private readonly IEIFFileProvider _eifFileProvider; + private readonly IMapItemGraphicProvider _mapItemGraphicProvider; + private readonly IHudControlProvider _hudControlProvider; + + public TradeDialogFactory(INativeGraphicsManager nativeGraphicsManager, + ITradeActions tradeActions, + ILocalizedStringFinder localizedStringFinder, + IEODialogButtonService dialogButtonService, + IEOMessageBoxFactory messageBoxFactory, + IStatusLabelSetter statusLabelSetter, + IInventorySpaceValidator inventorySpaceValidator, + ITradeProvider tradeProvider, + ICharacterProvider characterProvider, + IEIFFileProvider eifFileProvider, + IMapItemGraphicProvider mapItemGraphicProvider, + IHudControlProvider hudControlProvider) + { + _nativeGraphicsManager = nativeGraphicsManager; + _tradeActions = tradeActions; + _localizedStringFinder = localizedStringFinder; + _dialogButtonService = dialogButtonService; + _messageBoxFactory = messageBoxFactory; + _statusLabelSetter = statusLabelSetter; + _inventorySpaceValidator = inventorySpaceValidator; + _tradeProvider = tradeProvider; + _characterProvider = characterProvider; + _eifFileProvider = eifFileProvider; + _mapItemGraphicProvider = mapItemGraphicProvider; + _hudControlProvider = hudControlProvider; + } + + public TradeDialog Create() + { + return new TradeDialog(_nativeGraphicsManager, + _tradeActions, + _localizedStringFinder, + _dialogButtonService, + _messageBoxFactory, + _statusLabelSetter, + _inventorySpaceValidator, + _tradeProvider, + _characterProvider, + _eifFileProvider, + _mapItemGraphicProvider, + _hudControlProvider.GetComponent(HUD.Controls.HudControlIdentifier.InventoryPanel)); + } + } + + public interface ITradeDialogFactory + { + TradeDialog Create(); + } +} diff --git a/EndlessClient/Dialogs/ScrollingListDialog.cs b/EndlessClient/Dialogs/ScrollingListDialog.cs index 4d0aea02d..ef6f6e2ae 100644 --- a/EndlessClient/Dialogs/ScrollingListDialog.cs +++ b/EndlessClient/Dialogs/ScrollingListDialog.cs @@ -364,8 +364,6 @@ public override void Initialize() protected override void OnUpdateControl(GameTime gameTime) { - ChildControlClickHandled = false; - if (_listItems.Count > _scrollBar.LinesToRender) { for (int i = 0; i < _listItems.Count; ++i) diff --git a/EndlessClient/Dialogs/TradeDialog.cs b/EndlessClient/Dialogs/TradeDialog.cs index c47c969b8..aba0b07e9 100644 --- a/EndlessClient/Dialogs/TradeDialog.cs +++ b/EndlessClient/Dialogs/TradeDialog.cs @@ -156,7 +156,8 @@ public override void Initialize() _cancel.Initialize(); } - protected override void OnUpdateControl(GameTime gameTime) + public void Close() => Close(XNADialogResult.NO_BUTTON_PRESSED); + { var updateItemVisibility = false; diff --git a/EndlessClient/Rendering/ContextMenuRenderer.cs b/EndlessClient/Rendering/ContextMenuRenderer.cs index fea00f08f..4fa4cc071 100644 --- a/EndlessClient/Rendering/ContextMenuRenderer.cs +++ b/EndlessClient/Rendering/ContextMenuRenderer.cs @@ -13,6 +13,7 @@ using EOLib.Domain.Chat; using EOLib.Domain.Interact; using EOLib.Domain.Party; +using EOLib.Domain.Trade; using EOLib.Graphics; using EOLib.Localization; using Microsoft.Xna.Framework; @@ -46,6 +47,7 @@ private enum MenuAction private readonly IInGameDialogActions _inGameDialogActions; private readonly IPaperdollActions _paperdollActions; private readonly IPartyActions _partyActions; + private readonly ITradeActions _tradeActions; private readonly IStatusLabelSetter _statusLabelSetter; private readonly IFriendIgnoreListService _friendIgnoreListService; private readonly IHudControlProvider _hudControlProvider; @@ -54,13 +56,14 @@ private enum MenuAction private readonly IPartyDataProvider _partyDataProvider; private readonly ICharacterRenderer _characterRenderer; - //private DateTime? m_lastTradeRequestedTime; + private static DateTime? _lastTradeRequestedTime; private static DateTime? _lastPartyRequestTime; public ContextMenuRenderer(INativeGraphicsManager nativeGraphicsManager, IInGameDialogActions inGameDialogActions, IPaperdollActions paperdollActions, IPartyActions partyActions, + ITradeActions tradeActions, IStatusLabelSetter statusLabelSetter, IFriendIgnoreListService friendIgnoreListService, IHudControlProvider hudControlProvider, @@ -73,6 +76,7 @@ public ContextMenuRenderer(INativeGraphicsManager nativeGraphicsManager, _inGameDialogActions = inGameDialogActions; _paperdollActions = paperdollActions; _partyActions = partyActions; + _tradeActions = tradeActions; _statusLabelSetter = statusLabelSetter; _friendIgnoreListService = friendIgnoreListService; _hudControlProvider = hudControlProvider; @@ -222,10 +226,10 @@ private Action GetActionFromMenuAction(MenuAction menuAction) switch (menuAction) { case MenuAction.Paperdoll: return ShowPaperdollAction; - case MenuAction.Book: return () => { };//return _eventShowBook; + case MenuAction.Book: return ShowBook; case MenuAction.Join: return JoinParty; case MenuAction.Invite: return InviteToParty; - case MenuAction.Trade: return () => { }; //return _eventTrade; + case MenuAction.Trade: return Trade; case MenuAction.Whisper: return PrivateMessage; case MenuAction.Friend: return AddFriend; case MenuAction.Ignore: return AddIgnore; @@ -239,10 +243,9 @@ private void ShowPaperdollAction() _inGameDialogActions.ShowPaperdollDialog(_characterRenderer.Character, isMainCharacter: false); } - //private void _eventShowBook(object arg1, EventArgs arg2) - //{ - // EOMessageBox.Show("TODO: Show quest info", "TODO ITEM", EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader); - //} + private void ShowBook() + { + } private void JoinParty() { @@ -282,26 +285,26 @@ private void InviteToParty() _statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_ACTION, _characterRenderer.Character.Name, EOResourceID.STATUS_LABEL_PARTY_IS_INVITED); } - //private void _eventTrade(object arg1, EventArgs arg2) - //{ - // if (OldWorld.Instance.MainPlayer.ActiveCharacter.CurrentMap == OldWorld.Instance.JailMap) - // EOMessageBox.Show(OldWorld.GetString(EOResourceID.JAIL_WARNING_CANNOT_TRADE), - // OldWorld.GetString(EOResourceID.STATUS_LABEL_TYPE_WARNING), - // EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader); - // else - // { - // if(m_lastTradeRequestedTime != null && (DateTime.Now - m_lastTradeRequestedTime.Value).TotalSeconds < Constants.TradeRequestTimeoutSeconds) - // { - // ((EOGame)Game).Hud.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.STATUS_LABEL_TRADE_RECENTLY_REQUESTED); - // return; - // } - // m_lastTradeRequestedTime = DateTime.Now; - // if (!m_api.TradeRequest((short)m_rend.Character.ID)) - // ((EOGame)Game).DoShowLostConnectionDialogAndReturnToMainMenu(); - // //todo: is this correct text? - // ((EOGame)Game).Hud.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_ACTION, EOResourceID.STATUS_LABEL_TRADE_REQUESTED_TO_TRADE); - // } - //} + private void Trade() + { + // see: https://github.com/ethanmoffat/EndlessClient/issues/193 + //if (OldWorld.Instance.MainPlayer.ActiveCharacter.CurrentMap == OldWorld.Instance.JailMap) + // EOMessageBox.Show(OldWorld.GetString(EOResourceID.JAIL_WARNING_CANNOT_TRADE), + // OldWorld.GetString(EOResourceID.STATUS_LABEL_TYPE_WARNING), + // EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader); + + if (_lastTradeRequestedTime != null && (DateTime.Now - _lastTradeRequestedTime.Value).TotalSeconds < Constants.TradeRequestTimeoutSeconds) + { + _statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.STATUS_LABEL_TRADE_RECENTLY_REQUESTED); + return; + } + + _lastTradeRequestedTime = DateTime.Now; + + _tradeActions.RequestTrade((short)_characterRenderer.Character.ID); + + _statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_ACTION, EOResourceID.STATUS_LABEL_TRADE_REQUESTED_TO_TRADE); + } private void PrivateMessage() { diff --git a/EndlessClient/Rendering/Factories/ContextMenuRendererFactory.cs b/EndlessClient/Rendering/Factories/ContextMenuRendererFactory.cs index 71af096e9..429d2d3fc 100644 --- a/EndlessClient/Rendering/Factories/ContextMenuRendererFactory.cs +++ b/EndlessClient/Rendering/Factories/ContextMenuRendererFactory.cs @@ -7,6 +7,7 @@ using EndlessClient.Services; using EOLib.Domain.Interact; using EOLib.Domain.Party; +using EOLib.Domain.Trade; using EOLib.Graphics; namespace EndlessClient.Rendering.Factories @@ -18,6 +19,7 @@ public class ContextMenuRendererFactory : IContextMenuRendererFactory private readonly IInGameDialogActions _inGameDialogActions; private readonly IPaperdollActions _paperdollActions; private readonly IPartyActions _partyActions; + private readonly ITradeActions _tradeActions; private readonly IStatusLabelSetter _statusLabelSetter; private readonly IFriendIgnoreListService _friendIgnoreListService; private readonly IHudControlProvider _hudControlProvider; @@ -29,6 +31,7 @@ public ContextMenuRendererFactory(INativeGraphicsManager nativeGraphicsManager, IInGameDialogActions inGameDialogActions, IPaperdollActions paperdollActions, IPartyActions partyActions, + ITradeActions tradeActions, IStatusLabelSetter statusLabelSetter, IFriendIgnoreListService friendIgnoreListService, IHudControlProvider hudControlProvider, @@ -40,6 +43,7 @@ public ContextMenuRendererFactory(INativeGraphicsManager nativeGraphicsManager, _inGameDialogActions = inGameDialogActions; _paperdollActions = paperdollActions; _partyActions = partyActions; + _tradeActions = tradeActions; _statusLabelSetter = statusLabelSetter; _friendIgnoreListService = friendIgnoreListService; _hudControlProvider = hudControlProvider; @@ -54,6 +58,7 @@ public IContextMenuRenderer CreateContextMenuRenderer(ICharacterRenderer charact _inGameDialogActions, _paperdollActions, _partyActions, + _tradeActions, _statusLabelSetter, _friendIgnoreListService, _hudControlProvider,