2020-12-14 16:24:52 +00:00
|
|
|
|
using QSB.Events;
|
2020-11-03 21:33:48 +00:00
|
|
|
|
using QSB.Player;
|
2020-10-24 11:17:52 +01:00
|
|
|
|
using QSB.WorldSync;
|
2021-03-07 23:54:23 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2020-09-22 21:11:29 +01:00
|
|
|
|
|
2020-11-03 17:56:48 +00:00
|
|
|
|
namespace QSB.ConversationSync.Events
|
2020-09-22 21:11:29 +01:00
|
|
|
|
{
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public class ConversationEvent : QSBEvent<ConversationMessage>
|
|
|
|
|
{
|
|
|
|
|
public override EventType Type => EventType.Conversation;
|
2020-09-22 21:11:29 +01:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public override void SetupListener() => GlobalMessenger<uint, string, ConversationType>.AddListener(EventNames.QSBConversation, Handler);
|
|
|
|
|
public override void CloseListener() => GlobalMessenger<uint, string, ConversationType>.RemoveListener(EventNames.QSBConversation, Handler);
|
2020-09-22 21:11:29 +01:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private void Handler(uint id, string message, ConversationType type) => SendEvent(CreateMessage(id, message, type));
|
2020-09-22 21:11:29 +01:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private ConversationMessage CreateMessage(uint id, string message, ConversationType type) => new ConversationMessage
|
|
|
|
|
{
|
|
|
|
|
AboutId = LocalPlayerId,
|
|
|
|
|
ObjectId = (int)id,
|
2021-03-29 14:36:16 +01:00
|
|
|
|
EnumValue = type,
|
2020-12-02 21:23:01 +00:00
|
|
|
|
Message = message
|
|
|
|
|
};
|
2020-09-22 21:39:53 +01:00
|
|
|
|
|
2020-12-11 22:42:21 +00:00
|
|
|
|
public override void OnReceiveRemote(bool server, ConversationMessage message)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2021-05-08 16:57:01 +01:00
|
|
|
|
if (!QSBCore.WorldObjectsReady)
|
2020-12-19 10:56:25 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-03-29 14:36:16 +01:00
|
|
|
|
switch (message.EnumValue)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
case ConversationType.Character:
|
|
|
|
|
var translated = TextTranslation.Translate(message.Message).Trim();
|
2021-03-23 13:18:29 +00:00
|
|
|
|
translated = Regex.Replace(translated, @"<[Pp]ause=?\d*\.?\d*\s?\/?>", "");
|
2020-12-02 21:23:01 +00:00
|
|
|
|
ConversationManager.Instance.DisplayCharacterConversationBox(message.ObjectId, translated);
|
|
|
|
|
break;
|
2020-12-03 08:28:05 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
case ConversationType.Player:
|
|
|
|
|
ConversationManager.Instance.DisplayPlayerConversationBox((uint)message.ObjectId, message.Message);
|
|
|
|
|
break;
|
2020-12-03 08:28:05 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
case ConversationType.CloseCharacter:
|
|
|
|
|
if (message.ObjectId == -1)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-12-11 13:14:58 +00:00
|
|
|
|
var tree = QSBWorldSync.OldDialogueTrees[message.ObjectId];
|
2020-12-02 21:23:01 +00:00
|
|
|
|
UnityEngine.Object.Destroy(ConversationManager.Instance.BoxMappings[tree]);
|
|
|
|
|
break;
|
2020-12-03 08:28:05 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
case ConversationType.ClosePlayer:
|
|
|
|
|
UnityEngine.Object.Destroy(QSBPlayerManager.GetPlayer((uint)message.ObjectId).CurrentDialogueBox);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|