From 9c4c80eb36214daa0d7b721b05741dc705aa9206 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Mon, 7 Nov 2022 20:14:03 +0000 Subject: [PATCH] setting for player names --- QSB/Player/PlayerHUDMarker.cs | 8 +++++- QSB/Player/PlayerMapMarker.cs | 8 +++++- QSB/QSBCore.cs | 11 ++++++++ .../Messages/RequestGameStateMessage.cs | 2 ++ QSB/ServerSettings/ServerSettingsManager.cs | 9 +++++++ QSB/ServerSettings/ServerSettingsMessage.cs | 26 +++++++++++++++++++ QSB/default-config.json | 3 ++- 7 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 QSB/ServerSettings/ServerSettingsManager.cs create mode 100644 QSB/ServerSettings/ServerSettingsMessage.cs diff --git a/QSB/Player/PlayerHUDMarker.cs b/QSB/Player/PlayerHUDMarker.cs index ebcc7e04..02e33c3c 100644 --- a/QSB/Player/PlayerHUDMarker.cs +++ b/QSB/Player/PlayerHUDMarker.cs @@ -1,4 +1,5 @@ -using QSB.Utility; +using QSB.ServerSettings; +using QSB.Utility; using UnityEngine; namespace QSB.Player; @@ -34,6 +35,11 @@ public class PlayerHUDMarker : HUDDistanceMarker return false; } + if (!ServerSettingsManager.ShowPlayerNames) + { + return false; + } + return _player.IsReady && !_player.IsDead && _player.Visible && diff --git a/QSB/Player/PlayerMapMarker.cs b/QSB/Player/PlayerMapMarker.cs index 6904b095..4bca061b 100644 --- a/QSB/Player/PlayerMapMarker.cs +++ b/QSB/Player/PlayerMapMarker.cs @@ -1,4 +1,5 @@ -using QSB.Utility; +using QSB.ServerSettings; +using QSB.Utility; using UnityEngine; namespace QSB.Player; @@ -57,6 +58,11 @@ public class PlayerMapMarker : MonoBehaviour return false; } + if (!ServerSettingsManager.ShowPlayerNames) + { + return false; + } + var playerScreenPos = Locator.GetActiveCamera().WorldToScreenPoint(transform.position); var isInfrontOfCamera = playerScreenPos.z > 0f; diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index b7107571..361b566a 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -4,9 +4,11 @@ using OWML.Common; using OWML.ModHelper; using QSB.Localization; using QSB.Menus; +using QSB.Messaging; using QSB.Patches; using QSB.QuantumSync; using QSB.SaveSync; +using QSB.ServerSettings; using QSB.Utility; using QSB.WorldSync; using System; @@ -56,6 +58,7 @@ public class QSBCore : ModBehaviour Application.version.Split('.').Take(3).Join(delimiter: "."); public static bool DLCInstalled => EntitlementsManager.IsDlcOwned() == EntitlementsManager.AsyncOwnershipStatus.Owned; public static bool IncompatibleModsAllowed { get; private set; } + public static bool ShowPlayerNames { get; private set; } public static GameVendor GameVendor { get; private set; } = GameVendor.None; public static bool IsStandalone => GameVendor is GameVendor.Epic or GameVendor.Steam; public static IProfileManager ProfileManager => IsStandalone @@ -242,6 +245,14 @@ public class QSBCore : ModBehaviour { DefaultServerIP = config.GetSettingsValue("defaultServerIP"); IncompatibleModsAllowed = config.GetSettingsValue("incompatibleModsAllowed"); + var _showPlayerNames = config.GetSettingsValue("showPlayerNames"); + + if (_showPlayerNames != ShowPlayerNames) + { + new ServerSettingsMessage().Send(); + } + + ShowPlayerNames = _showPlayerNames; } private void Update() diff --git a/QSB/SaveSync/Messages/RequestGameStateMessage.cs b/QSB/SaveSync/Messages/RequestGameStateMessage.cs index 42a24547..da49e43c 100644 --- a/QSB/SaveSync/Messages/RequestGameStateMessage.cs +++ b/QSB/SaveSync/Messages/RequestGameStateMessage.cs @@ -1,6 +1,7 @@ using QSB.ConversationSync.Messages; using QSB.Messaging; using QSB.Player; +using QSB.ServerSettings; using QSB.Utility; namespace QSB.SaveSync.Messages; @@ -21,6 +22,7 @@ internal class RequestGameStateMessage : QSBMessage } new GameStateMessage(From).Send(); + new ServerSettingsMessage().Send(); var gameSave = PlayerData._currentGameSave; diff --git a/QSB/ServerSettings/ServerSettingsManager.cs b/QSB/ServerSettings/ServerSettingsManager.cs new file mode 100644 index 00000000..42710214 --- /dev/null +++ b/QSB/ServerSettings/ServerSettingsManager.cs @@ -0,0 +1,9 @@ +using QSB.Utility; +using UnityEngine; + +namespace QSB.ServerSettings; + +internal class ServerSettingsManager : MonoBehaviour, IAddComponentOnStart +{ + public static bool ShowPlayerNames; +} diff --git a/QSB/ServerSettings/ServerSettingsMessage.cs b/QSB/ServerSettings/ServerSettingsMessage.cs new file mode 100644 index 00000000..cecb6be4 --- /dev/null +++ b/QSB/ServerSettings/ServerSettingsMessage.cs @@ -0,0 +1,26 @@ +using Mirror; +using QSB.Messaging; + +namespace QSB.ServerSettings; + +internal class ServerSettingsMessage : QSBMessage +{ + private bool _showPlayerNames; + + public override void Serialize(NetworkWriter writer) + { + base.Serialize(writer); + writer.Write(QSBCore.ShowPlayerNames); + } + + public override void Deserialize(NetworkReader reader) + { + base.Deserialize(reader); + _showPlayerNames = reader.ReadBool(); + } + + public override void OnReceiveRemote() + { + ServerSettingsManager.ShowPlayerNames = _showPlayerNames; + } +} diff --git a/QSB/default-config.json b/QSB/default-config.json index f78c880c..afa11fb5 100644 --- a/QSB/default-config.json +++ b/QSB/default-config.json @@ -2,6 +2,7 @@ "enabled": true, "settings": { "defaultServerIP": "localhost", - "incompatibleModsAllowed": false + "incompatibleModsAllowed": false, + "showPlayerNames": true } } \ No newline at end of file