Merge pull request #631 from misternebula/dev

0.28.2
This commit is contained in:
_nebula 2023-06-23 20:41:51 +01:00 committed by GitHub
commit 4bd6524bfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 22 deletions

View File

@ -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<DeathType>
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);

View File

@ -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<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);
}
}

View File

@ -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<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
@ -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 = $"<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}";
}
}
@ -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($"<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)

View File

@ -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($"<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);
}

View File

@ -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<string>
{
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();

View File

@ -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" ],