Skip to content

Commit 4bd6524

Browse files
authored
Merge pull request #631 from misternebula/dev
0.28.2
2 parents 03bcc60 + e95fc17 commit 4bd6524

File tree

6 files changed

+29
-22
lines changed

6 files changed

+29
-22
lines changed

QSB/DeathSync/Messages/PlayerDeathMessage.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using QSB.Player;
66
using QSB.RespawnSync;
77
using QSB.Utility;
8+
using UnityEngine;
89

910
namespace QSB.DeathSync.Messages;
1011

@@ -41,7 +42,7 @@ public override void OnReceiveRemote()
4142
var deathMessage = Necronomicon.GetPhrase(Data, NecronomiconIndex);
4243
if (deathMessage != null)
4344
{
44-
MultiplayerHUDManager.Instance.WriteMessage($"<color=brown>{string.Format(deathMessage, playerName)}</color>");
45+
MultiplayerHUDManager.Instance.WriteMessage(string.Format(deathMessage, playerName), Color.grey);
4546
}
4647

4748
RespawnManager.Instance.OnPlayerDeath(player);

QSB/HUD/Messages/ChatMessage.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
using System.Linq;
55
using System.Text;
66
using System.Threading.Tasks;
7+
using UnityEngine;
78

89
namespace QSB.HUD.Messages;
910

10-
internal class ChatMessage : QSBMessage<string>
11+
internal class ChatMessage : QSBMessage<(string message, Color color)>
1112
{
12-
public ChatMessage(string msg) : base(msg) { }
13+
public ChatMessage(string msg, Color color) : base((msg, color)) { }
1314

1415
public override void OnReceiveLocal() => OnReceiveRemote();
1516

1617
public override void OnReceiveRemote()
1718
{
18-
MultiplayerHUDManager.Instance.WriteMessage(Data);
19+
MultiplayerHUDManager.Instance.WriteMessage(Data.message, Data.color);
1920
}
2021
}

QSB/HUD/MultiplayerHUDManager.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ private void Start()
7171
private const float FADE_TIME = 2f;
7272

7373
private bool _writingMessage;
74-
private readonly string[] _lines = new string[LINE_COUNT];
74+
private readonly (string msg, Color color)[] _lines = new (string msg, Color color)[LINE_COUNT];
7575
// this should really be a deque, but eh
76-
private readonly ListStack<string> _messages = new(false);
76+
private readonly ListStack<(string msg, Color color)> _messages = new(false);
7777
private float _lastMessageTime;
7878

79-
public void WriteMessage(string message)
79+
public void WriteMessage(string message, Color color)
8080
{
8181
/* Tricky problem to solve.
8282
* - 11 available lines for text to fit onto
8383
* - Each line can be max 41 characters
84-
* - Newest messages apepear at the bottom, and get pushed up by newer messages.
84+
* - Newest messages appear at the bottom, and get pushed up by newer messages.
8585
* - Messages can use several lines.
8686
*
8787
* From newest to oldest message, work out how many lines it needs
@@ -90,7 +90,7 @@ public void WriteMessage(string message)
9090

9191
_lastMessageTime = Time.time;
9292

93-
_messages.Push(message);
93+
_messages.Push((message, color));
9494

9595
if (_messages.Count > LINE_COUNT)
9696
{
@@ -101,7 +101,7 @@ public void WriteMessage(string message)
101101

102102
foreach (var msg in _messages.Reverse())
103103
{
104-
var characterCount = msg.Length;
104+
var characterCount = msg.msg.Length;
105105
var linesNeeded = Mathf.CeilToInt((float)characterCount / CHAR_COUNT);
106106
var chunk = 0;
107107
for (var i = linesNeeded - 1; i >= 0; i--)
@@ -112,8 +112,8 @@ public void WriteMessage(string message)
112112
continue;
113113
}
114114

115-
var chunkString = string.Concat(msg.Skip(CHAR_COUNT * chunk).Take(CHAR_COUNT));
116-
_lines[currentLineIndex - i] = chunkString;
115+
var chunkString = string.Concat(msg.msg.Skip(CHAR_COUNT * chunk).Take(CHAR_COUNT));
116+
_lines[currentLineIndex - i] = (chunkString, msg.color);
117117
chunk++;
118118
}
119119

@@ -128,17 +128,20 @@ public void WriteMessage(string message)
128128
var finalText = "";
129129
foreach (var line in _lines)
130130
{
131+
var msgColor = ColorUtility.ToHtmlStringRGBA(line.color);
132+
var msg = $"<color=#{msgColor}>{line.msg}</color>";
133+
131134
if (line == default)
132135
{
133136
finalText += Environment.NewLine;
134137
}
135-
else if (line.Length == 42)
138+
else if (line.msg.Length == CHAR_COUNT + 1)
136139
{
137-
finalText += line;
140+
finalText += msg;
138141
}
139142
else
140143
{
141-
finalText += $"{line}{Environment.NewLine}";
144+
finalText += $"{msg}{Environment.NewLine}";
142145
}
143146
}
144147

@@ -183,7 +186,7 @@ private void Update()
183186
_inputField.text = "";
184187
message = message.Replace("\n", "").Replace("\r", "");
185188
message = $"{QSBPlayerManager.LocalPlayer.Name}: {message}";
186-
new ChatMessage(message).Send();
189+
new ChatMessage(message, Color.white).Send();
187190
}
188191

189192
if (OWInput.IsNewlyPressed(InputLibrary.escape, InputMode.KeyboardInput) && _writingMessage)
@@ -398,7 +401,7 @@ private void OnRemovePlayer(PlayerInfo player)
398401
Destroy(player.HUDBox?.gameObject);
399402
Destroy(player.MinimapPlayerMarker);
400403

401-
WriteMessage($"<color=yellow>{string.Format(QSBLocalization.Current.PlayerLeftTheGame, player.Name)}</color>");
404+
WriteMessage(string.Format(QSBLocalization.Current.PlayerLeftTheGame, player.Name), Color.yellow);
402405
}
403406

404407
private PlanetTrigger CreateTrigger(string parentPath, HUDIcon icon)

QSB/Player/Messages/PlayerJoinMessage.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using QSB.Messaging;
77
using QSB.Utility;
88
using System.Linq;
9+
using UnityEngine;
910

1011
namespace QSB.Player.Messages;
1112

@@ -126,7 +127,7 @@ public override void OnReceiveRemote()
126127

127128
var player = QSBPlayerManager.GetPlayer(From);
128129
player.Name = PlayerName;
129-
MultiplayerHUDManager.Instance.WriteMessage($"<color=green>{string.Format(QSBLocalization.Current.PlayerJoinedTheGame, player.Name)}</color>");
130+
MultiplayerHUDManager.Instance.WriteMessage(string.Format(QSBLocalization.Current.PlayerJoinedTheGame, player.Name), Color.green);
130131
DebugLog.DebugWrite($"{player} joined. qsbVersion:{QSBVersion}, gameVersion:{GameVersion}, dlcInstalled:{DlcInstalled}", MessageType.Info);
131132
}
132133

QSB/Player/Messages/PlayerKickMessage.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using QSB.Menus;
55
using QSB.Messaging;
66
using QSB.Utility;
7+
using UnityEngine;
78

89
namespace QSB.Player.Messages;
910

@@ -35,15 +36,15 @@ public override void OnReceiveRemote()
3536
{
3637
if (QSBPlayerManager.PlayerExists(PlayerId))
3738
{
38-
MultiplayerHUDManager.Instance.WriteMessage($"<color=red>{string.Format(QSBLocalization.Current.PlayerWasKicked, QSBPlayerManager.GetPlayer(PlayerId).Name)}</color>");
39+
MultiplayerHUDManager.Instance.WriteMessage(string.Format(QSBLocalization.Current.PlayerWasKicked, QSBPlayerManager.GetPlayer(PlayerId).Name), Color.red);
3940
return;
4041
}
4142

42-
MultiplayerHUDManager.Instance.WriteMessage($"<color=red>{string.Format(QSBLocalization.Current.PlayerWasKicked, PlayerId)}</color>");
43+
MultiplayerHUDManager.Instance.WriteMessage(string.Format(QSBLocalization.Current.PlayerWasKicked, PlayerId), Color.red);
4344
return;
4445
}
4546

46-
MultiplayerHUDManager.Instance.WriteMessage($"<color=red>{string.Format(QSBLocalization.Current.KickedFromServer, Data)}</color>");
47+
MultiplayerHUDManager.Instance.WriteMessage(string.Format(QSBLocalization.Current.KickedFromServer, Data), Color.red);
4748
MenuManager.Instance.OnKicked(Data);
4849

4950
NetworkClient.Disconnect();

QSB/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"body": "- Disable *all* other mods. (Can heavily affect performance)\n- Make sure you are not running any other network-intensive applications."
88
},
99
"uniqueName": "Raicuparta.QuantumSpaceBuddies",
10-
"version": "0.28.1",
10+
"version": "0.28.2",
1111
"owmlVersion": "2.9.0",
1212
"dependencies": [ "_nebula.MenuFramework", "JohnCorby.VanillaFix" ],
1313
"pathsToPreserve": [ "debugsettings.json" ],

0 commit comments

Comments
 (0)