Skip to content

Commit

Permalink
First pass of opening/rendering shop dialog. Todo: action for buy/sel…
Browse files Browse the repository at this point in the history
…l/trade items
  • Loading branch information
ethanmoffat committed Apr 5, 2022
1 parent 499c27d commit 4bf92a6
Show file tree
Hide file tree
Showing 16 changed files with 561 additions and 408 deletions.
4 changes: 3 additions & 1 deletion EOLib/Domain/Interact/MapNPCActions.cs
@@ -1,8 +1,10 @@
using EOLib.Net;
using AutomaticTypeMapper;
using EOLib.Net;
using EOLib.Net.Communication;

namespace EOLib.Domain.Interact
{
[AutoMappedType]
public class MapNPCActions : IMapNPCActions
{
private readonly IPacketSendService _packetSendService;
Expand Down
6 changes: 3 additions & 3 deletions EndlessClient/Controllers/MapInteractionController.cs
Expand Up @@ -72,7 +72,7 @@ public class MapInteractionController : IMapInteractionController

public void LeftClick(IMapCellState cellState, IMouseCursorRenderer mouseRenderer)
{
if (!InventoryPanel.NoItemsDragging())
if (!InventoryPanel.NoItemsDragging() || cellState.Character.HasValue || cellState.NPC.HasValue)
{
return;
}
Expand All @@ -91,25 +91,25 @@ public void LeftClick(IMapCellState cellState, IMouseCursorRenderer mouseRendere
else
HandlePickupResult(_mapActions.PickUpItem(item), item);
}
else if (cellState.NPC.HasValue) { /* TODO: spell cast */ }
else if (cellState.Sign.HasValue)
{
var sign = cellState.Sign.ValueOr(Sign.None);
var messageBox = _eoMessageBoxFactory.CreateMessageBox(sign.Message, sign.Title);
messageBox.ShowDialog();
}
else if (cellState.Chest.HasValue) { /* TODO: chest interaction */ }
else if (cellState.Character.HasValue) { /* TODO: character spell cast */ }
else if (cellState.InBounds)
{
mouseRenderer.AnimateClick();
_hudControlProvider.GetComponent<ICharacterAnimator>(HudControlIdentifier.CharacterAnimator)
.StartMainCharacterWalkAnimation(Option.Some(cellState.Coordinate));
}
// todo: board, jukebox

_userInputTimeRepository.LastInputTime = DateTime.Now;
}

// todo: move to new controller for character interaction
public void RightClick(IMapCellState cellState)
{
if (!cellState.Character.HasValue)
Expand Down
43 changes: 43 additions & 0 deletions EndlessClient/Controllers/NPCInteractionController.cs
@@ -0,0 +1,43 @@
using AutomaticTypeMapper;
using EndlessClient.Dialogs.Actions;
using EOLib.Domain.Interact;
using EOLib.Domain.NPC;
using EOLib.IO.Repositories;

namespace EndlessClient.Controllers
{
[AutoMappedType]
public class NPCInteractionController : INPCInteractionController
{
private readonly IMapNPCActions _mapNpcActions;
private readonly IInGameDialogActions _inGameDialogActions;
private readonly IENFFileProvider _enfFileProvider;

public NPCInteractionController(IMapNPCActions mapNpcActions,
IInGameDialogActions inGameDialogActions,
IENFFileProvider enfFileProvider)
{
_mapNpcActions = mapNpcActions;
_inGameDialogActions = inGameDialogActions;
_enfFileProvider = enfFileProvider;
}

public void ShowNPCDialog(INPC npc)
{
var data = _enfFileProvider.ENFFile[npc.ID];

switch(data.Type)
{
case EOLib.IO.NPCType.Shop:
_mapNpcActions.RequestShop(npc.Index);
_inGameDialogActions.ShowShopDialog();
break;
}
}
}

public interface INPCInteractionController
{
void ShowNPCDialog(INPC npc);
}
}
19 changes: 18 additions & 1 deletion EndlessClient/Dialogs/Actions/InGameDialogActions.cs
Expand Up @@ -11,14 +11,17 @@ public class InGameDialogActions : IInGameDialogActions
private readonly IFriendIgnoreListDialogFactory _friendIgnoreListDialogFactory;
private readonly IPaperdollDialogFactory _paperdollDialogFactory;
private readonly IActiveDialogRepository _activeDialogRepository;
private readonly IShopDialogFactory _shopDialogFactory;

public InGameDialogActions(IFriendIgnoreListDialogFactory friendIgnoreListDialogFactory,
IPaperdollDialogFactory paperdollDialogFactory,
IActiveDialogRepository activeDialogRepository)
IActiveDialogRepository activeDialogRepository,
IShopDialogFactory shopDialogFactory)
{
_friendIgnoreListDialogFactory = friendIgnoreListDialogFactory;
_paperdollDialogFactory = paperdollDialogFactory;
_activeDialogRepository = activeDialogRepository;
_shopDialogFactory = shopDialogFactory;
}

public void ShowFriendListDialog()
Expand Down Expand Up @@ -56,6 +59,18 @@ public void ShowPaperdollDialog(ICharacter character, bool isMainCharacter)
dlg.Show();
});
}

public void ShowShopDialog()
{
_activeDialogRepository.ShopDialog.MatchNone(() =>
{
var dlg = _shopDialogFactory.Create();
dlg.DialogClosed += (_, _) => _activeDialogRepository.ShopDialog = Option.None<ShopDialog>();
_activeDialogRepository.ShopDialog = Option.Some(dlg);
dlg.Show();
});
}
}

public interface IInGameDialogActions
Expand All @@ -65,5 +80,7 @@ public interface IInGameDialogActions
void ShowIgnoreListDialog();

void ShowPaperdollDialog(ICharacter character, bool isMainCharacter);

void ShowShopDialog();
}
}
10 changes: 9 additions & 1 deletion EndlessClient/Dialogs/ActiveDialogRepository.cs
Expand Up @@ -13,14 +13,18 @@ public interface IActiveDialogProvider : IDisposable

Option<PaperdollDialog> PaperdollDialog { get; }

Option<ShopDialog> ShopDialog { get; }

IReadOnlyList<Option<IXNADialog>> ActiveDialogs { get; }
}

public interface IActiveDialogRepository : IDisposable
{
Option<ScrollingListDialog> FriendIgnoreDialog { get; set; }

Option<PaperdollDialog> PaperdollDialog { get; set; }
Option<PaperdollDialog> PaperdollDialog { get; set; }

Option<ShopDialog> ShopDialog { get; set; }

IReadOnlyList<Option<IXNADialog>> ActiveDialogs { get; }
}
Expand All @@ -32,6 +36,8 @@ public class ActiveDialogRepository : IActiveDialogRepository, IActiveDialogProv

public Option<PaperdollDialog> PaperdollDialog { get; set; }

public Option<ShopDialog> ShopDialog { get; set; }

IReadOnlyList<Option<IXNADialog>> ActiveDialogs
{
get
Expand All @@ -40,6 +46,7 @@ IReadOnlyList<Option<IXNADialog>> ActiveDialogs
{
FriendIgnoreDialog.Map(d => (IXNADialog)d),
PaperdollDialog.Map(d => (IXNADialog)d),
ShopDialog.Map(d => (IXNADialog)d),
}.ToList();
}
}
Expand All @@ -55,6 +62,7 @@ public void Dispose()

FriendIgnoreDialog = Option.None<ScrollingListDialog>();
PaperdollDialog = Option.None<PaperdollDialog>();
ShopDialog = Option.None<ShopDialog>();
}
}
}
Expand Up @@ -53,7 +53,7 @@ public ScrollingListDialog Create(bool isFriendList)
{
var textFileLines = _friendIgnoreListService.LoadList(isFriendList ? Constants.FriendListFile : Constants.IgnoreListFile);

var dialog = new ScrollingListDialog(_gameStateProvider, _nativeGraphicsManager, _dialogButtonService)
var dialog = new ScrollingListDialog(_nativeGraphicsManager, _dialogButtonService)
{
Buttons = ScrollingListDialogButtons.AddCancel,
ListItemType = ListDialogItem.ListItemStyle.Small,
Expand Down
69 changes: 69 additions & 0 deletions EndlessClient/Dialogs/Factories/ShopDialogFactory.cs
@@ -0,0 +1,69 @@
using AutomaticTypeMapper;
using EndlessClient.Dialogs.Services;
using EndlessClient.GameExecution;
using EndlessClient.HUD.Inventory;
using EOLib.Domain.Character;
using EOLib.Domain.Interact.Shop;
using EOLib.Graphics;
using EOLib.IO.Repositories;
using EOLib.Localization;

namespace EndlessClient.Dialogs.Factories
{
[AutoMappedType]
public class ShopDialogFactory : IShopDialogFactory
{
private readonly INativeGraphicsManager _nativeGraphicsManager;
private readonly IEOMessageBoxFactory _messageBoxFactory;
private readonly IItemTransferDialogFactory _itemTransferDialogFactory;
private readonly IEODialogButtonService _dialogButtonService;
private readonly IEODialogIconService _dialogIconService;
private readonly ILocalizedStringFinder _localizedStringFinder;
private readonly IShopDataProvider _shopDataProvider;
private readonly ICharacterInventoryProvider _characterInventoryProvider;
private readonly IEIFFileProvider _eifFileProvider;
private readonly IInventorySpaceValidator _inventorySpaceValidator;

public ShopDialogFactory(INativeGraphicsManager nativeGraphicsManager,
IEOMessageBoxFactory messageBoxFactory,
IItemTransferDialogFactory itemTransferDialogFactory,
IEODialogButtonService dialogButtonService,
IEODialogIconService dialogIconService,
ILocalizedStringFinder localizedStringFinder,
IShopDataProvider shopDataProvider,
ICharacterInventoryProvider characterInventoryProvider,
IEIFFileProvider eifFileProvider,
IInventorySpaceValidator inventorySpaceValidator)
{
_nativeGraphicsManager = nativeGraphicsManager;
_messageBoxFactory = messageBoxFactory;
_itemTransferDialogFactory = itemTransferDialogFactory;
_dialogButtonService = dialogButtonService;
_dialogIconService = dialogIconService;
_localizedStringFinder = localizedStringFinder;
_shopDataProvider = shopDataProvider;
_characterInventoryProvider = characterInventoryProvider;
_eifFileProvider = eifFileProvider;
_inventorySpaceValidator = inventorySpaceValidator;
}

public ShopDialog Create()
{
return new ShopDialog(_nativeGraphicsManager,
_messageBoxFactory,
_itemTransferDialogFactory,
_dialogButtonService,
_dialogIconService,
_localizedStringFinder,
_shopDataProvider,
_characterInventoryProvider,
_eifFileProvider,
_inventorySpaceValidator);
}
}

public interface IShopDialogFactory
{
ShopDialog Create();
}
}
25 changes: 13 additions & 12 deletions EndlessClient/Dialogs/ListDialogItem.cs
Expand Up @@ -10,6 +10,12 @@ namespace EndlessClient.Dialogs
{
public class ListDialogItem : XNAControl
{
public enum ListItemStyle
{
Small,
Large
}

private int _index;
private int _xOffset, _yOffset;

Expand Down Expand Up @@ -85,17 +91,13 @@ public string SubText

public Texture2D IconGraphic { get; set; }

public Rectangle? IconGraphicSource { get; set; }

public bool ShowIconBackGround { get; set; }

public event EventHandler RightClick;
public event EventHandler LeftClick;

public enum ListItemStyle
{
Small,
Large
}

public ListDialogItem(ScrollingListDialog parent, ListItemStyle style, int listIndex = -1)
{
_parentList = parent;
Expand Down Expand Up @@ -248,25 +250,24 @@ protected override void OnDrawControl(GameTime gameTime)

if (Style == ListItemStyle.Large)
{
var offset = new Vector2(OffsetX + 14, OffsetY + 36 * Index);

if (ShowIconBackGround)
{
_spriteBatch.Draw(_gfxPadThing, DrawPositionWithParentOffset + offset + GetCoordsFromGraphic(_gfxPadThing), Color.White);
_spriteBatch.Draw(_gfxPadThing, DrawPositionWithParentOffset + GetCoordsFromGraphic(_gfxPadThing.Bounds), Color.White);
}

if (IconGraphic != null)
{
_spriteBatch.Draw(IconGraphic, DrawPositionWithParentOffset + offset + GetCoordsFromGraphic(IconGraphic), Color.White);
var graphicOffset = IconGraphicSource.HasValue ? GetCoordsFromGraphic(IconGraphicSource.Value) : GetCoordsFromGraphic(IconGraphic.Bounds);
_spriteBatch.Draw(IconGraphic, DrawPositionWithParentOffset + graphicOffset, IconGraphicSource, Color.White);
}
}

_spriteBatch.End();
}

private static Vector2 GetCoordsFromGraphic(Texture2D sourceTexture)
private static Vector2 GetCoordsFromGraphic(Rectangle sourceTextureArea)
{
return new Vector2((float)Math.Round((64 - sourceTexture.Width) / 2f), (float)Math.Round((36 - sourceTexture.Height) / 2f));
return new Vector2((float)Math.Round((56 - sourceTextureArea.Width) / 2f), (float)Math.Round((36 - sourceTextureArea.Height) / 2f));
}

protected override void Dispose(bool disposing)
Expand Down

0 comments on commit 4bf92a6

Please sign in to comment.