diff --git a/QSB/DeathSync/Messages/PlayerDeathMessage.cs b/QSB/DeathSync/Messages/PlayerDeathMessage.cs index 5aedbef6..376f7c09 100644 --- a/QSB/DeathSync/Messages/PlayerDeathMessage.cs +++ b/QSB/DeathSync/Messages/PlayerDeathMessage.cs @@ -5,6 +5,7 @@ using QSB.Messaging; using QSB.Player; using QSB.RespawnSync; using QSB.Utility; +using UnityEngine; namespace QSB.DeathSync.Messages; @@ -41,7 +42,7 @@ public class PlayerDeathMessage : QSBMessage var deathMessage = Necronomicon.GetPhrase(Data, NecronomiconIndex); if (deathMessage != null) { - MultiplayerHUDManager.Instance.WriteMessage($"{string.Format(deathMessage, playerName)}"); + MultiplayerHUDManager.Instance.WriteMessage(string.Format(deathMessage, playerName), Color.grey); } RespawnManager.Instance.OnPlayerDeath(player); diff --git a/QSB/HUD/Messages/ChatMessage.cs b/QSB/HUD/Messages/ChatMessage.cs index a8404ade..e9d25bbc 100644 --- a/QSB/HUD/Messages/ChatMessage.cs +++ b/QSB/HUD/Messages/ChatMessage.cs @@ -4,17 +4,18 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using UnityEngine; namespace QSB.HUD.Messages; -internal class ChatMessage : QSBMessage +internal class ChatMessage : QSBMessage<(string message, Color color)> { - public ChatMessage(string msg) : base(msg) { } + public ChatMessage(string msg, Color color) : base((msg, color)) { } public override void OnReceiveLocal() => OnReceiveRemote(); public override void OnReceiveRemote() { - MultiplayerHUDManager.Instance.WriteMessage(Data); + MultiplayerHUDManager.Instance.WriteMessage(Data.message, Data.color); } } \ No newline at end of file diff --git a/QSB/HUD/MultiplayerHUDManager.cs b/QSB/HUD/MultiplayerHUDManager.cs index 05e4404f..d3886162 100644 --- a/QSB/HUD/MultiplayerHUDManager.cs +++ b/QSB/HUD/MultiplayerHUDManager.cs @@ -71,17 +71,17 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart private const float FADE_TIME = 2f; private bool _writingMessage; - private readonly string[] _lines = new string[LINE_COUNT]; + private readonly (string msg, Color color)[] _lines = new (string msg, Color color)[LINE_COUNT]; // this should really be a deque, but eh - private readonly ListStack _messages = new(false); + private readonly ListStack<(string msg, Color color)> _messages = new(false); private float _lastMessageTime; - public void WriteMessage(string message) + public void WriteMessage(string message, Color color) { /* Tricky problem to solve. * - 11 available lines for text to fit onto * - Each line can be max 41 characters - * - Newest messages apepear at the bottom, and get pushed up by newer messages. + * - Newest messages appear at the bottom, and get pushed up by newer messages. * - Messages can use several lines. * * From newest to oldest message, work out how many lines it needs @@ -90,7 +90,7 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart _lastMessageTime = Time.time; - _messages.Push(message); + _messages.Push((message, color)); if (_messages.Count > LINE_COUNT) { @@ -101,7 +101,7 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart foreach (var msg in _messages.Reverse()) { - var characterCount = msg.Length; + var characterCount = msg.msg.Length; var linesNeeded = Mathf.CeilToInt((float)characterCount / CHAR_COUNT); var chunk = 0; for (var i = linesNeeded - 1; i >= 0; i--) @@ -112,8 +112,8 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart continue; } - var chunkString = string.Concat(msg.Skip(CHAR_COUNT * chunk).Take(CHAR_COUNT)); - _lines[currentLineIndex - i] = chunkString; + var chunkString = string.Concat(msg.msg.Skip(CHAR_COUNT * chunk).Take(CHAR_COUNT)); + _lines[currentLineIndex - i] = (chunkString, msg.color); chunk++; } @@ -128,17 +128,20 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart var finalText = ""; foreach (var line in _lines) { + var msgColor = ColorUtility.ToHtmlStringRGBA(line.color); + var msg = $"{line.msg}"; + if (line == default) { finalText += Environment.NewLine; } - else if (line.Length == 42) + else if (line.msg.Length == CHAR_COUNT + 1) { - finalText += line; + finalText += msg; } else { - finalText += $"{line}{Environment.NewLine}"; + finalText += $"{msg}{Environment.NewLine}"; } } @@ -183,7 +186,7 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart _inputField.text = ""; message = message.Replace("\n", "").Replace("\r", ""); message = $"{QSBPlayerManager.LocalPlayer.Name}: {message}"; - new ChatMessage(message).Send(); + new ChatMessage(message, Color.white).Send(); } if (OWInput.IsNewlyPressed(InputLibrary.escape, InputMode.KeyboardInput) && _writingMessage) @@ -398,7 +401,7 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart Destroy(player.HUDBox?.gameObject); Destroy(player.MinimapPlayerMarker); - WriteMessage($"{string.Format(QSBLocalization.Current.PlayerLeftTheGame, player.Name)}"); + WriteMessage(string.Format(QSBLocalization.Current.PlayerLeftTheGame, player.Name), Color.yellow); } private PlanetTrigger CreateTrigger(string parentPath, HUDIcon icon) diff --git a/QSB/Player/Messages/PlayerJoinMessage.cs b/QSB/Player/Messages/PlayerJoinMessage.cs index 6a8bc110..f7af042b 100644 --- a/QSB/Player/Messages/PlayerJoinMessage.cs +++ b/QSB/Player/Messages/PlayerJoinMessage.cs @@ -6,6 +6,7 @@ using QSB.Localization; using QSB.Messaging; using QSB.Utility; using System.Linq; +using UnityEngine; namespace QSB.Player.Messages; @@ -126,7 +127,7 @@ public class PlayerJoinMessage : QSBMessage var player = QSBPlayerManager.GetPlayer(From); player.Name = PlayerName; - MultiplayerHUDManager.Instance.WriteMessage($"{string.Format(QSBLocalization.Current.PlayerJoinedTheGame, player.Name)}"); + MultiplayerHUDManager.Instance.WriteMessage(string.Format(QSBLocalization.Current.PlayerJoinedTheGame, player.Name), Color.green); DebugLog.DebugWrite($"{player} joined. qsbVersion:{QSBVersion}, gameVersion:{GameVersion}, dlcInstalled:{DlcInstalled}", MessageType.Info); } diff --git a/QSB/Player/Messages/PlayerKickMessage.cs b/QSB/Player/Messages/PlayerKickMessage.cs index 7cc62816..84834b5e 100644 --- a/QSB/Player/Messages/PlayerKickMessage.cs +++ b/QSB/Player/Messages/PlayerKickMessage.cs @@ -4,6 +4,7 @@ using QSB.Localization; using QSB.Menus; using QSB.Messaging; using QSB.Utility; +using UnityEngine; namespace QSB.Player.Messages; @@ -35,15 +36,15 @@ internal class PlayerKickMessage : QSBMessage { if (QSBPlayerManager.PlayerExists(PlayerId)) { - MultiplayerHUDManager.Instance.WriteMessage($"{string.Format(QSBLocalization.Current.PlayerWasKicked, QSBPlayerManager.GetPlayer(PlayerId).Name)}"); + MultiplayerHUDManager.Instance.WriteMessage(string.Format(QSBLocalization.Current.PlayerWasKicked, QSBPlayerManager.GetPlayer(PlayerId).Name), Color.red); return; } - MultiplayerHUDManager.Instance.WriteMessage($"{string.Format(QSBLocalization.Current.PlayerWasKicked, PlayerId)}"); + MultiplayerHUDManager.Instance.WriteMessage(string.Format(QSBLocalization.Current.PlayerWasKicked, PlayerId), Color.red); return; } - MultiplayerHUDManager.Instance.WriteMessage($"{string.Format(QSBLocalization.Current.KickedFromServer, Data)}"); + MultiplayerHUDManager.Instance.WriteMessage(string.Format(QSBLocalization.Current.KickedFromServer, Data), Color.red); MenuManager.Instance.OnKicked(Data); NetworkClient.Disconnect(); diff --git a/QSB/manifest.json b/QSB/manifest.json index d81b0959..20357d06 100644 --- a/QSB/manifest.json +++ b/QSB/manifest.json @@ -7,7 +7,7 @@ "body": "- Disable *all* other mods. (Can heavily affect performance)\n- Make sure you are not running any other network-intensive applications." }, "uniqueName": "Raicuparta.QuantumSpaceBuddies", - "version": "0.28.1", + "version": "0.28.2", "owmlVersion": "2.9.0", "dependencies": [ "_nebula.MenuFramework", "JohnCorby.VanillaFix" ], "pathsToPreserve": [ "debugsettings.json" ],