Skip to content

Commit

Permalink
Reimplement Message_Open handler for setting status label from quest
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Apr 5, 2022
1 parent 574fb4f commit ca9611f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 32 deletions.
15 changes: 15 additions & 0 deletions EOLib/Domain/Interact/Quest/IStatusLabelNotifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using AutomaticTypeMapper;

namespace EOLib.Domain.Interact.Quest
{
public interface IStatusLabelNotifier
{
void ShowWarning(string message);
}

[AutoMappedType]
public class NoOpStatusLabelNotifier : IStatusLabelNotifier
{
public void ShowWarning(string message) { }
}
}
21 changes: 0 additions & 21 deletions EOLib/Net/API/Message.cs

This file was deleted.

1 change: 0 additions & 1 deletion EOLib/Net/API/PacketAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public PacketAPI(EOClient client)
_createChestMembers();
_createInitMembers();
_createLockerMembers();
_createMessageMembers();
_createMusicMembers();
_createPartyMembers();
_createNPCMembers();
Expand Down
43 changes: 43 additions & 0 deletions EOLib/PacketHandlers/Quest/QuestStatusMessageHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using AutomaticTypeMapper;
using EOLib.Domain.Chat;
using EOLib.Domain.Interact.Quest;
using EOLib.Domain.Login;
using EOLib.Net;
using EOLib.Net.Handlers;
using System.Collections.Generic;

namespace EOLib.PacketHandlers.Quest
{
[AutoMappedType]
public class QuestStatusMessageHandler : InGameOnlyPacketHandler
{
private readonly IChatRepository _chatRepository;
private readonly IEnumerable<IStatusLabelNotifier> _statusLabelNotifiers;

public override PacketFamily Family => PacketFamily.Message;

public override PacketAction Action => PacketAction.Open;

public QuestStatusMessageHandler(IPlayerInfoProvider playerInfoProvider,
IChatRepository chatRepository,
IEnumerable<IStatusLabelNotifier> statusLabelNotifiers)
: base(playerInfoProvider)
{
_chatRepository = chatRepository;
_statusLabelNotifiers = statusLabelNotifiers;
}

public override bool HandlePacket(IPacket packet)
{
var message = packet.ReadEndString();

foreach (var notifier in _statusLabelNotifiers)
notifier.ShowWarning(message);

var chatData = new ChatData(string.Empty, message, ChatIcon.QuestMessage, ChatColor.Server);
_chatRepository.AllChat[ChatTab.System].Add(chatData);

return true;
}
}
}
8 changes: 7 additions & 1 deletion EndlessClient/HUD/StatusLabelSetter.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using AutomaticTypeMapper;
using EOLib.Domain.Interact.Quest;
using EOLib.Localization;

namespace EndlessClient.HUD
{
[MappedType(BaseType = typeof(IStatusLabelSetter))]
public class StatusLabelSetter : IStatusLabelSetter
public class StatusLabelSetter : IStatusLabelSetter, IStatusLabelNotifier
{
private readonly IStatusLabelTextRepository _statusLabelTextRepository;
private readonly ILocalizedStringFinder _localizedStringFinder;
Expand Down Expand Up @@ -40,6 +41,11 @@ public void SetStatusLabel(EOResourceID type, string text)
SetStatusLabelText(_localizedStringFinder.GetString(type), text);
}

public void ShowWarning(string message)
{
SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, message);
}

private void SetStatusLabelText(string type, string text, string extra = "")
{
_statusLabelTextRepository.StatusText = $"[ {type} ] {text}{extra}";
Expand Down
9 changes: 0 additions & 9 deletions EndlessClient/Old/PacketAPICallbackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using EndlessClient.Dialogs;
using EndlessClient.Dialogs.Old;
using EOLib.Domain.Character;
using EOLib.Domain.Chat;
using EOLib.Domain.Map;
using EOLib.Localization;
using EOLib.Net.API;
using XNAControls.Old;
Expand Down Expand Up @@ -74,7 +72,6 @@ public void AssignCallbacks()
m_packetAPI.OnQuestDialog += _questDialog;
m_packetAPI.OnViewQuestProgress += _questProgress;
m_packetAPI.OnViewQuestHistory += _questHistory;
m_packetAPI.OnStatusMessage += _setStatusLabel;

m_packetAPI.OnPlaySoundEffect += _playSoundEffect;

Expand Down Expand Up @@ -369,12 +366,6 @@ private void _questHistory(short numquests, List<string> completedquestnames)
QuestProgressDialog.Instance.SetHistoryDisplayData(numquests, completedquestnames);
}

private void _setStatusLabel(string message)
{
m_game.Hud.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, message);
m_game.Hud.AddChat(ChatTab.System, "", message, ChatIcon.QuestMessage, ChatColor.Server);
}

private void _playSoundEffect(int effectID)
{
try
Expand Down

0 comments on commit ca9611f

Please sign in to comment.