Skip to content

Commit

Permalink
Merge pull request #631 from misternebula/dev
Browse files Browse the repository at this point in the history
0.28.2
  • Loading branch information
misternebula authored Jun 23, 2023
2 parents 03bcc60 + e95fc17 commit 4bd6524
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
3 changes: 2 additions & 1 deletion QSB/DeathSync/Messages/PlayerDeathMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using QSB.Player;
using QSB.RespawnSync;
using QSB.Utility;
using UnityEngine;

namespace QSB.DeathSync.Messages;

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

RespawnManager.Instance.OnPlayerDeath(player);
Expand Down
7 changes: 4 additions & 3 deletions QSB/HUD/Messages/ChatMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace QSB.HUD.Messages;

internal class ChatMessage : QSBMessage<string>
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);
}
}
29 changes: 16 additions & 13 deletions QSB/HUD/MultiplayerHUDManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ private void Start()
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<string> _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
Expand All @@ -90,7 +90,7 @@ public void WriteMessage(string message)

_lastMessageTime = Time.time;

_messages.Push(message);
_messages.Push((message, color));

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

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--)
Expand All @@ -112,8 +112,8 @@ public void WriteMessage(string message)
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++;
}

Expand All @@ -128,17 +128,20 @@ public void WriteMessage(string message)
var finalText = "";
foreach (var line in _lines)
{
var msgColor = ColorUtility.ToHtmlStringRGBA(line.color);
var msg = $"<color=#{msgColor}>{line.msg}</color>";

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}";
}
}

Expand Down Expand Up @@ -183,7 +186,7 @@ private void Update()
_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)
Expand Down Expand Up @@ -398,7 +401,7 @@ private void OnRemovePlayer(PlayerInfo player)
Destroy(player.HUDBox?.gameObject);
Destroy(player.MinimapPlayerMarker);

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

private PlanetTrigger CreateTrigger(string parentPath, HUDIcon icon)
Expand Down
3 changes: 2 additions & 1 deletion QSB/Player/Messages/PlayerJoinMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using QSB.Messaging;
using QSB.Utility;
using System.Linq;
using UnityEngine;

namespace QSB.Player.Messages;

Expand Down Expand Up @@ -126,7 +127,7 @@ public override void OnReceiveRemote()

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

Expand Down
7 changes: 4 additions & 3 deletions QSB/Player/Messages/PlayerKickMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using QSB.Menus;
using QSB.Messaging;
using QSB.Utility;
using UnityEngine;

namespace QSB.Player.Messages;

Expand Down Expand Up @@ -35,15 +36,15 @@ public override void OnReceiveRemote()
{
if (QSBPlayerManager.PlayerExists(PlayerId))
{
MultiplayerHUDManager.Instance.WriteMessage($"<color=red>{string.Format(QSBLocalization.Current.PlayerWasKicked, QSBPlayerManager.GetPlayer(PlayerId).Name)}</color>");
MultiplayerHUDManager.Instance.WriteMessage(string.Format(QSBLocalization.Current.PlayerWasKicked, QSBPlayerManager.GetPlayer(PlayerId).Name), Color.red);
return;
}

MultiplayerHUDManager.Instance.WriteMessage($"<color=red>{string.Format(QSBLocalization.Current.PlayerWasKicked, PlayerId)}</color>");
MultiplayerHUDManager.Instance.WriteMessage(string.Format(QSBLocalization.Current.PlayerWasKicked, PlayerId), Color.red);
return;
}

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

NetworkClient.Disconnect();
Expand Down
2 changes: 1 addition & 1 deletion QSB/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ],
Expand Down

0 comments on commit 4bd6524

Please sign in to comment.