2020-09-22 21:11:29 +01:00
|
|
|
|
using QSB.Events;
|
|
|
|
|
using QSB.Messaging;
|
2020-09-22 21:39:53 +01:00
|
|
|
|
using QSB.Utility;
|
2020-09-22 21:11:29 +01:00
|
|
|
|
|
|
|
|
|
namespace QSB.ConversationSync
|
|
|
|
|
{
|
2020-09-29 20:42:45 +02:00
|
|
|
|
public class ConversationEvent : QSBEvent<ConversationMessage>
|
2020-09-22 21:11:29 +01:00
|
|
|
|
{
|
|
|
|
|
public override EventType Type => EventType.Conversation;
|
|
|
|
|
|
2020-10-23 19:06:11 +01:00
|
|
|
|
public override void SetupListener() => GlobalMessenger<uint, string, ConversationType>.AddListener(EventNames.QSBConversation, Handler);
|
2020-09-22 21:11:29 +01:00
|
|
|
|
|
2020-10-23 19:06:11 +01:00
|
|
|
|
public override void CloseListener() => GlobalMessenger<uint, string, ConversationType>.RemoveListener(EventNames.QSBConversation, Handler);
|
2020-09-22 21:11:29 +01:00
|
|
|
|
|
2020-10-23 19:06:11 +01:00
|
|
|
|
private void Handler(uint id, string message, ConversationType type) => SendEvent(CreateMessage(id, message, type));
|
2020-09-22 21:11:29 +01:00
|
|
|
|
|
2020-10-23 19:06:11 +01:00
|
|
|
|
private ConversationMessage CreateMessage(uint id, string message, ConversationType type) => new ConversationMessage
|
2020-09-22 21:11:29 +01:00
|
|
|
|
{
|
|
|
|
|
AboutId = LocalPlayerId,
|
2020-10-23 19:06:11 +01:00
|
|
|
|
ObjectId = (int)id,
|
2020-09-22 21:11:29 +01:00
|
|
|
|
Type = type,
|
|
|
|
|
Message = message
|
|
|
|
|
};
|
2020-09-22 21:39:53 +01:00
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote(ConversationMessage message)
|
|
|
|
|
{
|
2020-10-23 19:06:11 +01:00
|
|
|
|
switch (message.Type)
|
|
|
|
|
{
|
|
|
|
|
case ConversationType.Character:
|
|
|
|
|
var translated = TextTranslation.Translate(message.Message).Trim();
|
|
|
|
|
DebugLog.DebugWrite($"CHARACTER id [{message.ObjectId}] text [{translated}]");
|
|
|
|
|
break;
|
|
|
|
|
case ConversationType.Player:
|
|
|
|
|
ConversationManager.Instance.DisplayPlayerConversationBox((uint)message.ObjectId, message.Message);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-22 21:39:53 +01:00
|
|
|
|
}
|
2020-09-22 21:11:29 +01:00
|
|
|
|
}
|
|
|
|
|
}
|