44 lines
1.1 KiB
C#
Raw Normal View History

2023-05-07 18:24:02 +01:00
using QSB.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2023-09-08 11:23:01 +01:00
using QSB.Player;
using UnityEngine;
2023-05-07 18:24:02 +01:00
namespace QSB.HUD.Messages;
2023-07-28 00:45:39 +01:00
public class ChatMessage : QSBMessage<(string message, Color color)>
2023-05-07 18:24:02 +01:00
{
public ChatMessage(string msg, Color color) : base((msg, color)) { }
2023-05-07 18:24:02 +01:00
public override void OnReceiveLocal() => OnReceiveRemote();
public override void OnReceiveRemote()
{
MultiplayerHUDManager.Instance.WriteMessage(Data.message, Data.color);
2023-09-08 11:23:01 +01:00
var fromPlayer = QSBPlayerManager.GetPlayer(From);
var qsb = false;
string name;
if (Data.message.StartsWith("QSB: "))
{
name = "QSB: ";
qsb = true;
}
else if (Data.message.StartsWith($"{fromPlayer.Name}: "))
{
name = $"{fromPlayer.Name}: ";
}
else
{
// uhhh idk what happened
MultiplayerHUDManager.OnChatMessageEvent.Invoke(Data.message, From);
return;
}
var messageWithoutName = Data.message.Remove(Data.message.IndexOf(name), name.Length);
MultiplayerHUDManager.OnChatMessageEvent.Invoke(messageWithoutName, qsb ? uint.MaxValue : From);
2023-05-07 18:24:02 +01:00
}
}