Skip to content

Commit

Permalink
Skeleton for opening/showing Jukebox
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed May 18, 2023
1 parent 13a9322 commit 56f2144
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 15 deletions.
@@ -1,13 +1,14 @@
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Map;
using EOLib.IO;
using EOLib.IO.Repositories;
using EOLib.Net;
using EOLib.Net.Communication;
using Optional.Collections;
using System;

namespace EOLib.Domain.Jukebox
namespace EOLib.Domain.Interact.Jukebox
{
[AutoMappedType]
public class JukeboxActions : IJukeboxActions
Expand Down
@@ -1,10 +1,10 @@
using Amadevus.RecordGenerator;
using EOLib.IO.Map;

namespace EOLib.Domain.Interact.Board
namespace EOLib.Domain.Interact
{
[Record]
public sealed partial class BoardMapEntity : IMapEntity
public sealed partial class TileSpecMapEntity : IMapEntity
{
public int X { get; }

Expand Down
12 changes: 12 additions & 0 deletions EOLib/Domain/Map/MapActions.cs
Expand Up @@ -91,6 +91,16 @@ public void OpenBoard(TileSpec boardSpec)

_packetSendService.SendPacket(packet);
}

public void OpenJukebox(MapCoordinate location)
{
var packet = new PacketBuilder(PacketFamily.JukeBox, PacketAction.Open)
.AddChar(location.X)
.AddChar(location.Y)
.Build();

_packetSendService.SendPacket(packet);
}
}

public interface IMapActions
Expand All @@ -106,5 +116,7 @@ public interface IMapActions
void OpenLocker(MapCoordinate location);

void OpenBoard(TileSpec boardSpec);

void OpenJukebox(MapCoordinate location);
}
}
2 changes: 1 addition & 1 deletion EndlessClient/Controllers/BardController.cs
Expand Up @@ -2,7 +2,7 @@
using EndlessClient.Rendering.Character;
using EOLib.Domain.Character;
using EOLib.Domain.Extensions;
using EOLib.Domain.Jukebox;
using EOLib.Domain.Interact.Jukebox;

namespace EndlessClient.Controllers
{
Expand Down
6 changes: 5 additions & 1 deletion EndlessClient/Controllers/MapInteractionController.cs
Expand Up @@ -160,7 +160,11 @@ public void LeftClick(IMapCellState cellState)
}
break;
case TileSpec.Jukebox:
// todo
if (unwalkableAction == UnwalkableTileAction.Jukebox)
{
_mapActions.OpenJukebox(cellState.Coordinate);
_inGameDialogActions.ShowJukeboxDialog();
}
break;
}
}
Expand Down
22 changes: 22 additions & 0 deletions EndlessClient/Dialogs/Actions/InGameDialogActions.cs
Expand Up @@ -34,6 +34,7 @@ public class InGameDialogActions : IInGameDialogActions
private readonly IScrollingListDialogFactory _scrollingListDialogFactory;
private readonly ITradeDialogFactory _tradeDialogFactory;
private readonly IBoardDialogFactory _boardDialogFactory;
private readonly IJukeboxDialogFactory _jukeboxDialogFactory;
private readonly ISfxPlayer _sfxPlayer;
private readonly IStatusLabelSetter _statusLabelSetter;
private readonly IShopDialogFactory _shopDialogFactory;
Expand All @@ -57,6 +58,7 @@ public class InGameDialogActions : IInGameDialogActions
IScrollingListDialogFactory scrollingListDialogFactory,
ITradeDialogFactory tradeDialogFactory,
IBoardDialogFactory boardDialogFactory,
IJukeboxDialogFactory jukeboxDialogFactory,
ISfxPlayer sfxPlayer,
IStatusLabelSetter statusLabelSetter)
{
Expand All @@ -76,6 +78,7 @@ public class InGameDialogActions : IInGameDialogActions
_scrollingListDialogFactory = scrollingListDialogFactory;
_tradeDialogFactory = tradeDialogFactory;
_boardDialogFactory = boardDialogFactory;
_jukeboxDialogFactory = jukeboxDialogFactory;
_sfxPlayer = sfxPlayer;
_statusLabelSetter = statusLabelSetter;
_shopDialogFactory = shopDialogFactory;
Expand Down Expand Up @@ -329,6 +332,23 @@ public void ShowBoardDialog()
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_ACTION, EOResourceID.BOARD_TOWN_BOARD_NOW_VIEWED);
}

public void ShowJukeboxDialog()
{
_activeDialogRepository.JukeboxDialog.MatchNone(() =>
{
var dlg = _jukeboxDialogFactory.Create();
dlg.DialogClosed += (_, _) => _activeDialogRepository.JukeboxDialog = Option.None<JukeboxDialog>();
_activeDialogRepository.JukeboxDialog = Option.Some(dlg);
dlg.Show();
UseDefaultDialogSounds(dlg);
});

// the vanilla client shows the status label any time the server sends the BOARD_OPEN packet
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_ACTION, EOResourceID.JUKEBOX_NOW_VIEWED);
}

private void UseDefaultDialogSounds(ScrollingListDialog dialog)
{
UseDefaultDialogSounds((BaseEODialog)dialog);
Expand Down Expand Up @@ -389,5 +409,7 @@ public interface IInGameDialogActions
void CloseTradeDialog();

void ShowBoardDialog();

void ShowJukeboxDialog();
}
}
8 changes: 8 additions & 0 deletions EndlessClient/Dialogs/ActiveDialogRepository.cs
Expand Up @@ -39,6 +39,8 @@ public interface IActiveDialogProvider : IDisposable

Option<BoardDialog> BoardDialog { get; }

Option<JukeboxDialog> JukeboxDialog { get; }

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

Expand Down Expand Up @@ -74,6 +76,8 @@ public interface IActiveDialogRepository : IDisposable

Option<BoardDialog> BoardDialog { get; set; }

Option<JukeboxDialog> JukeboxDialog { get; set; }

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

Expand Down Expand Up @@ -110,6 +114,8 @@ public class ActiveDialogRepository : IActiveDialogRepository, IActiveDialogProv

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

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

IReadOnlyList<Option<IXNADialog>> ActiveDialogs
{
get
Expand All @@ -131,6 +137,7 @@ IReadOnlyList<Option<IXNADialog>> ActiveDialogs
TradeDialog.Map(Map),
MessageBox.Map(Map),
BoardDialog.Map(Map),
JukeboxDialog.Map(Map),
}.ToList();

static IXNADialog Map(object d)
Expand Down Expand Up @@ -164,6 +171,7 @@ public void Dispose()
TradeDialog = Option.None<TradeDialog>();
MessageBox = Option.None<EOMessageBox>();
BoardDialog = Option.None<BoardDialog>();
JukeboxDialog = Option.None<JukeboxDialog>();
}
}
}
35 changes: 35 additions & 0 deletions EndlessClient/Dialogs/Factories/JukeboxDialogFactory.cs
@@ -0,0 +1,35 @@
using AutomaticTypeMapper;
using EndlessClient.Dialogs.Services;
using EOLib.Graphics;

namespace EndlessClient.Dialogs.Factories
{
[AutoMappedType]
public class JukeboxDialogFactory : IJukeboxDialogFactory
{
private readonly INativeGraphicsManager _nativeGraphicsManager;
private readonly IEODialogButtonService _dialogButtonService;
private readonly IEODialogIconService _dialogIconService;

public JukeboxDialogFactory(INativeGraphicsManager nativeGraphicsManager,
IEODialogButtonService dialogButtonService,
IEODialogIconService dialogIconService)
{
_nativeGraphicsManager = nativeGraphicsManager;
_dialogButtonService = dialogButtonService;
_dialogIconService = dialogIconService;
}

public JukeboxDialog Create()
{
return new JukeboxDialog(_nativeGraphicsManager,
_dialogButtonService,
_dialogIconService);
}
}

public interface IJukeboxDialogFactory
{
JukeboxDialog Create();
}
}
15 changes: 15 additions & 0 deletions EndlessClient/Dialogs/JukeboxDialog.cs
@@ -0,0 +1,15 @@
using EndlessClient.Dialogs.Services;
using EOLib.Graphics;

namespace EndlessClient.Dialogs
{
public class JukeboxDialog : ScrollingListDialog
{
public JukeboxDialog(INativeGraphicsManager nativeGraphicsManager,
IEODialogButtonService dialogButtonService,
IEODialogIconService dialogIconService)
: base(nativeGraphicsManager, dialogButtonService, DialogType.Jukebox)
{
}
}
}
6 changes: 6 additions & 0 deletions EndlessClient/Dialogs/ScrollingListDialog.cs
Expand Up @@ -50,6 +50,9 @@ public enum DialogType
FriendIgnore = Shop,
Locker = Shop,
Message = Shop,
Guild = Shop,
Inn = Shop,
LawBob = Shop,

// large no scroll
Chest,
Expand All @@ -63,6 +66,9 @@ public enum DialogType

// small no scroll
BankAccountDialog,

Jukebox,
Barber,
}

public class ScrollingListDialog : BaseEODialog
Expand Down
3 changes: 3 additions & 0 deletions EndlessClient/Dialogs/Services/EODialogIconService.cs
Expand Up @@ -9,11 +9,14 @@ public enum DialogIcon
{
Buy = 0,
Sell,
JukeboxBrowse = Sell,
BankDeposit,
BankWithdraw,
Craft,
BankLockerUpgrade,

JukeboxPlay = 8,

Learn = 20,
Forget = 21,
}
Expand Down
Expand Up @@ -23,6 +23,7 @@ public void NotifyPacketDialog(PacketFamily packetFamily)
case PacketFamily.Locker: _inGameDialogActions.ShowLockerDialog(); break;
case PacketFamily.Chest: _inGameDialogActions.ShowChestDialog(); break;
case PacketFamily.Board: _inGameDialogActions.ShowBoardDialog(); break;
case PacketFamily.JukeBox: _inGameDialogActions.ShowJukeboxDialog(); break;
}
}

Expand Down
5 changes: 3 additions & 2 deletions EndlessClient/Input/UnwalkableTileActions.cs
Expand Up @@ -20,6 +20,7 @@ public enum UnwalkableTileAction
Locker,
Character,
Board,
Jukebox,
}

[AutoMappedType]
Expand Down Expand Up @@ -177,8 +178,8 @@ private UnwalkableTileAction HandleWalkToTileSpec(IMapCellState cellState)
case TileSpec.Board7:
case TileSpec.Board8:
return UnwalkableTileAction.Board;
case TileSpec.Jukebox: //todo: jukebox
break;
case TileSpec.Jukebox:
return UnwalkableTileAction.Jukebox;
}

return UnwalkableTileAction.None;
Expand Down
1 change: 1 addition & 0 deletions EndlessClient/Input/UnwalkableTileActionsHandler.cs
Expand Up @@ -39,6 +39,7 @@ public void HandleUnwalkableTileActions(IReadOnlyList<UnwalkableTileAction> unwa
case UnwalkableTileAction.Chair: _characterActions.SitInChair(); break;
case UnwalkableTileAction.Door: cellState.Warp.MatchSome(w => _mapActions.OpenDoor(w)); break;
case UnwalkableTileAction.Board: _mapActions.OpenBoard(cellState.TileSpec); break;
case UnwalkableTileAction.Jukebox: _mapActions.OpenJukebox(cellState.Coordinate); break;
}
}
}
Expand Down
17 changes: 9 additions & 8 deletions EndlessClient/Rendering/Map/ClickDispatcher.cs
Expand Up @@ -6,7 +6,7 @@
using EndlessClient.Rendering.NPC;
using EOLib.Domain.Character;
using EOLib.Domain.Extensions;
using EOLib.Domain.Interact.Board;
using EOLib.Domain.Interact;
using EOLib.Domain.Map;
using EOLib.IO.Map;
using Microsoft.Xna.Framework;
Expand Down Expand Up @@ -111,8 +111,9 @@ private bool CheckForEntityClicks(MouseEventArgs eventArgs)
entities.AddRange(_currentMapProvider.CurrentMap.Signs);
entities.AddRange(_currentMapProvider.CurrentMap
.GetTileSpecs(TileSpec.Board1, TileSpec.Board2, TileSpec.Board3, TileSpec.Board4,
TileSpec.Board5, TileSpec.Board6, TileSpec.Board7, TileSpec.Board8)
.Select(x => new BoardMapEntity(x.X, x.Y)));
TileSpec.Board5, TileSpec.Board6, TileSpec.Board7, TileSpec.Board8,
TileSpec.Jukebox)
.Select(x => new TileSpecMapEntity(x.X, x.Y)));

entities.Sort((a, b) =>
{
Expand Down Expand Up @@ -156,7 +157,7 @@ private bool DispatchClickToEntity(IMapEntity entity, MouseEventArgs eventArgs)
DomainCharacter c => HandleCharacterClick(c, eventArgs.Button),
DomainNPC n => eventArgs.Button == MouseButton.Left && HandleNPCClick(n, eventArgs.Position),
SignMapEntity s => eventArgs.Button == MouseButton.Left && HandleSignClick(s),
BoardMapEntity b => eventArgs.Button == MouseButton.Left && HandleBoardClick(b),
TileSpecMapEntity ts => eventArgs.Button == MouseButton.Left && HandleTileSpecClick(ts),
_ => throw new ArgumentException()
};
}
Expand All @@ -167,7 +168,7 @@ private Rectangle GetEntityBounds(IMapEntity entity)
{
DomainCharacter c => GetCharacterRendererArea(c.ID),
DomainNPC n => GetNPCRendererArea(n.Index),
SignMapEntity or BoardMapEntity => GetObjectBounds(entity),
SignMapEntity or TileSpecMapEntity => GetObjectBounds(entity),
_ => throw new ArgumentException()
};
}
Expand Down Expand Up @@ -242,12 +243,12 @@ private bool HandleSignClick(SignMapEntity s)
return true;
}

private bool HandleBoardClick(BoardMapEntity b)
private bool HandleTileSpecClick(TileSpecMapEntity ts)
{
var cellState = new MapCellState
{
Coordinate = new MapCoordinate(b.X, b.Y),
TileSpec = _currentMapProvider.CurrentMap.Tiles[b.Y, b.X]
Coordinate = new MapCoordinate(ts.X, ts.Y),
TileSpec = _currentMapProvider.CurrentMap.Tiles[ts.Y, ts.X]
};

_mapInteractionController.LeftClick(cellState);
Expand Down

0 comments on commit 56f2144

Please sign in to comment.