Skip to content

Commit

Permalink
Implement speak to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Apr 14, 2024
1 parent 5d02996 commit b0bc1f9
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 16 deletions.
40 changes: 40 additions & 0 deletions EOLib/Domain/Report/ReportActions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using EOLib.Net;
using EOLib.Net.Communication;

namespace EOLib.Domain.Report
{
public class ReportActions : IReportActions
{
private readonly IPacketSendService _packetSendService;

public ReportActions(IPacketSendService packetSendService)
{
_packetSendService = packetSendService;
}

public void ReportPlayer(string player, string message)
{
var packet = new PacketBuilder(PacketFamily.AdminInteract, PacketAction.Report)
.AddString(player)
.AddByte(255)
.AddString(message)
.Build();
_packetSendService.SendPacket(packet);
}

public void SpeakToAdmin(string message)
{
var packet = new PacketBuilder(PacketFamily.AdminInteract, PacketAction.Tell)
.AddString(message)
.Build();
_packetSendService.SendPacket(packet);
}
}

public interface IReportActions
{
void ReportPlayer(string player, string message);

void SpeakToAdmin(string message);
}
}
55 changes: 55 additions & 0 deletions EndlessClient/Dialogs/Actions/HelpActions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using AutomaticTypeMapper;
using EndlessClient.Dialogs.Factories;
using EOLib.Domain.Report;
using XNAControls;

namespace EndlessClient.Dialogs.Actions
{
[AutoMappedType]
public class HelpActions : IHelpActions
{
private readonly IReportActions _reportActions;
private readonly ITextInputDialogFactory _textInputDialogFactory;

public HelpActions(IReportActions reportActions,
ITextInputDialogFactory textInputDialogFactory)
{
_reportActions = reportActions;
_textInputDialogFactory = textInputDialogFactory;
}

public void ResetPassword()
{
// todo
}

public void ReportSomeone()
{
// gfx002 / 157
}

public void SpeakToAdmin()
{
const string Prompt = "Please enter your question, and we will try to get back to you.";

var dlg = _textInputDialogFactory.Create(Prompt, maxInputChars: 48);
dlg.DialogClosing += (_, e) =>
{
if (e.Result == XNADialogResult.OK)
{
_reportActions.SpeakToAdmin(dlg.ResponseText);
}
};
dlg.ShowDialog();
}
}

public interface IHelpActions
{
void ResetPassword();

void ReportSomeone();

void SpeakToAdmin();
}
}
19 changes: 19 additions & 0 deletions EndlessClient/Dialogs/Actions/InGameDialogActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class InGameDialogActions : IInGameDialogActions
private readonly IJukeboxDialogFactory _jukeboxDialogFactory;
private readonly IInnkeeperDialogFactory _innkeeperDialogFactory;
private readonly ILawDialogFactory _lawDialogFactory;
private readonly IHelpDialogFactory _helpDialogFactory;
private readonly ISfxPlayer _sfxPlayer;
private readonly IStatusLabelSetter _statusLabelSetter;
private readonly IShopDialogFactory _shopDialogFactory;
Expand Down Expand Up @@ -66,6 +67,7 @@ public InGameDialogActions(IFriendIgnoreListDialogFactory friendIgnoreListDialog
IJukeboxDialogFactory jukeboxDialogFactory,
IInnkeeperDialogFactory innkeeperDialogFactory,
ILawDialogFactory lawDialogFactory,
IHelpDialogFactory helpDialogFactory,
ISfxPlayer sfxPlayer,
IStatusLabelSetter statusLabelSetter)
{
Expand All @@ -89,6 +91,7 @@ public InGameDialogActions(IFriendIgnoreListDialogFactory friendIgnoreListDialog
_jukeboxDialogFactory = jukeboxDialogFactory;
_innkeeperDialogFactory = innkeeperDialogFactory;
_lawDialogFactory = lawDialogFactory;
_helpDialogFactory = helpDialogFactory;
_sfxPlayer = sfxPlayer;
_statusLabelSetter = statusLabelSetter;
_shopDialogFactory = shopDialogFactory;
Expand Down Expand Up @@ -433,6 +436,20 @@ public void ShowLawDialog()
});
}

public void ShowHelpDialog()
{
_activeDialogRepository.HelpDialog.MatchNone(() =>
{
var dlg = _helpDialogFactory.Create();
dlg.DialogClosed += (_, _) => _activeDialogRepository.HelpDialog = Option.None<ScrollingListDialog>();
_activeDialogRepository.HelpDialog = Option.Some(dlg);

dlg.Show();

UseDefaultDialogSounds(dlg);
});
}

private void UseDefaultDialogSounds(ScrollingListDialog dialog)
{
UseDefaultDialogSounds((BaseEODialog)dialog);
Expand Down Expand Up @@ -503,5 +520,7 @@ public interface IInGameDialogActions
void ShowInnkeeperDialog();

void ShowLawDialog();

void ShowHelpDialog();
}
}
8 changes: 8 additions & 0 deletions EndlessClient/Dialogs/ActiveDialogRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public interface IActiveDialogProvider : IDisposable

Option<LawDialog> LawDialog { get; }

Option<ScrollingListDialog> HelpDialog { get; }

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

Expand Down Expand Up @@ -90,6 +92,8 @@ public interface IActiveDialogRepository : IDisposable

Option<LawDialog> LawDialog { get; set; }

Option<ScrollingListDialog> HelpDialog { get; set; }

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

Expand Down Expand Up @@ -134,6 +138,8 @@ public class ActiveDialogRepository : IActiveDialogRepository, IActiveDialogProv

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

public Option<ScrollingListDialog> HelpDialog { get; set; }

IReadOnlyList<Option<IXNADialog>> ActiveDialogs
{
get
Expand All @@ -159,6 +165,7 @@ IReadOnlyList<Option<IXNADialog>> ActiveDialogs
JukeboxDialog.Map(Map),
InnkeeperDialog.Map(Map),
LawDialog.Map(Map),
HelpDialog.Map(Map),
}.ToList();

static IXNADialog Map(object d)
Expand Down Expand Up @@ -196,6 +203,7 @@ public void Dispose()
JukeboxDialog = Option.None<JukeboxDialog>();
InnkeeperDialog = Option.None<InnkeeperDialog>();
LawDialog = Option.None<LawDialog>();
HelpDialog = Option.None<ScrollingListDialog>();
}
}
}
77 changes: 77 additions & 0 deletions EndlessClient/Dialogs/Factories/HelpDialogFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using AutomaticTypeMapper;
using EndlessClient.Content;
using EndlessClient.Dialogs.Actions;
using EndlessClient.Dialogs.Services;
using EOLib;
using EOLib.Graphics;
using EOLib.Localization;
using System;
using System.Collections.Generic;

namespace EndlessClient.Dialogs.Factories
{
[AutoMappedType(IsSingleton = true)]
public class HelpDialogFactory : IHelpDialogFactory
{
private readonly INativeGraphicsManager _nativeGraphicsManager;
private readonly IEODialogButtonService _dialogButtonService;
private readonly IContentProvider _contentProvider;
private readonly ILocalizedStringFinder _localizedStringFinder;
private readonly IHelpActions _helpActions;

public HelpDialogFactory(INativeGraphicsManager nativeGraphicsManager,
IEODialogButtonService dialogButtonService,
IContentProvider contentProvider,
ILocalizedStringFinder localizedStringFinder,
IHelpActions helpActions)
{
_nativeGraphicsManager = nativeGraphicsManager;
_dialogButtonService = dialogButtonService;
_contentProvider = contentProvider;
_localizedStringFinder = localizedStringFinder;
_helpActions = helpActions;
}

public ScrollingListDialog Create()
{
var dlg = new ScrollingListDialog(_nativeGraphicsManager, _dialogButtonService, DialogType.Help)
{
Buttons = ScrollingListDialogButtons.Cancel,
ListItemType = ListDialogItem.ListItemStyle.Small,
};

dlg.AddTextAsListItems(_contentProvider.Fonts[Constants.FontSize08pt5], GetActions(), GetMessages());

return dlg;
}

private string[] GetMessages()
{
return new[]
{
_localizedStringFinder.GetString(EOResourceID.ENDLESS_HELP_SUMMARY_1),
string.Empty,
_localizedStringFinder.GetString(EOResourceID.ENDLESS_HELP_SUMMARY_2),
string.Empty,
_localizedStringFinder.GetString(EOResourceID.ENDLESS_HELP_LINK_RESET_PASSWORD),
_localizedStringFinder.GetString(EOResourceID.ENDLESS_HELP_LINK_REPORT_SOMEONE),
_localizedStringFinder.GetString(EOResourceID.ENDLESS_HELP_LINK_SPEAK_TO_ADMIN),
};
}

private List<Action> GetActions()
{
return new List<Action>
{
_helpActions.ResetPassword,
_helpActions.ReportSomeone,
_helpActions.SpeakToAdmin,
};
}
}

public interface IHelpDialogFactory
{
ScrollingListDialog Create();
}
}
18 changes: 15 additions & 3 deletions EndlessClient/Dialogs/ScrollingListDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public enum DialogType
Inn = Shop,
Law = Shop,

// large / alternate background
Help,

// large no scroll
Chest,

Expand Down Expand Up @@ -109,6 +112,7 @@ public int ItemsToShow
{

case DialogType.Shop:
case DialogType.Help:
case DialogType.QuestProgressHistory:
return 12;
case DialogType.NpcQuestDialog: return 6;
Expand Down Expand Up @@ -395,7 +399,7 @@ public void ClearItemList()
_scrollBar.ScrollToTop();
}

public void AddTextAsListItems(BitmapFont font, Action linkClickAction, params string[] messages)
public void AddTextAsListItems(BitmapFont font, List<Action> linkClickActions, params string[] messages)
{
ListItemType = ListDialogItem.ListItemStyle.Small;

Expand All @@ -408,6 +412,8 @@ public void AddTextAsListItems(BitmapFont font, Action linkClickAction, params s
drawStrings.Add(" ");
}

int linkIndex = 0;

foreach (string s in drawStrings)
{
var link = s.Length > 0 && s[0] == '*';
Expand All @@ -416,8 +422,9 @@ public void AddTextAsListItems(BitmapFont font, Action linkClickAction, params s
PrimaryText = link ? s.Remove(0, 1) : s
};

if (link)
if (link && linkIndex < linkClickActions.Count)
{
var linkClickAction = linkClickActions[linkIndex++];
nextItem.SetPrimaryClickAction((_, _) => linkClickAction());
}

Expand Down Expand Up @@ -491,6 +498,7 @@ protected static int GetScrollBarHeight(DialogType size)
switch (size)
{
case DialogType.Shop:
case DialogType.Help:
case DialogType.Chest:
case DialogType.QuestProgressHistory:
return 199;
Expand All @@ -506,6 +514,7 @@ private static int GetBackgroundTexture(DialogType size)
switch (size)
{
case DialogType.Shop: return 52;
case DialogType.Help: return 64;
case DialogType.Chest: return 51;
case DialogType.QuestProgressHistory: return 59;
case DialogType.Jukebox: return 60;
Expand All @@ -520,6 +529,7 @@ private static int GetBackgroundTexture(DialogType size)
switch (size)
{
case DialogType.Shop:
case DialogType.Help:
case DialogType.Chest: return null;
case DialogType.QuestProgressHistory:
return new Rectangle(0, 0, backgroundTexture.Width, backgroundTexture.Height / 2);
Expand All @@ -536,7 +546,8 @@ private static Vector2 GetButton1Position(Rectangle dialogArea, Rectangle button
switch (size)
{
// buttons are centered on these dialogs
case DialogType.Shop:
case DialogType.Shop:
case DialogType.Help:
case DialogType.Chest:
case DialogType.BankAccountDialog:
case DialogType.Jukebox: return new Vector2((int)Math.Floor((dialogArea.Width - buttonArea.Width) / 2.0) - 48, yCoord);
Expand All @@ -555,6 +566,7 @@ private static Vector2 GetButton2Position(Rectangle dialogArea, Rectangle button
{
// buttons are centered on these dialogs
case DialogType.Shop:
case DialogType.Help:
case DialogType.Chest:
case DialogType.BankAccountDialog:
case DialogType.Jukebox: return new Vector2((int)Math.Floor((dialogArea.Width - buttonArea.Width) / 2.0) + 48, yCoord);
Expand Down
Loading

0 comments on commit b0bc1f9

Please sign in to comment.