]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Change the window titlebar to show the joined server (#32547)
authorVasilis <vasilis@pikachu.systems>
Thu, 17 Oct 2024 11:06:07 +0000 (13:06 +0200)
committerGitHub <noreply@github.com>
Thu, 17 Oct 2024 11:06:07 +0000 (13:06 +0200)
* Change the window titlebar to show the joined server

Requires https://github.com/space-wizards/RobustToolbox/pull/5475/

* Totally not a webedit

* Can you tell what cvar I copied?

* And this kids is why we don't webedit

* Reviews

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Content.Client/Entry/EntryPoint.cs
Content.Client/GameTicking/Managers/TitleWindowManager.cs [new file with mode: 0644]
Content.Client/IoC/ClientContentIoC.cs
Content.Shared/CCVar/CCVars.cs

index cd73d3397dfe4b1f1be22115d61e0626998d9b05..5c1f94f333291187915eff79ff2c5fd8fed84b24 100644 (file)
@@ -4,6 +4,7 @@ using Content.Client.Chat.Managers;
 using Content.Client.DebugMon;
 using Content.Client.Eui;
 using Content.Client.Fullscreen;
+using Content.Client.GameTicking.Managers;
 using Content.Client.GhostKick;
 using Content.Client.Guidebook;
 using Content.Client.Input;
@@ -70,6 +71,7 @@ namespace Content.Client.Entry
         [Dependency] private readonly IReplayLoadManager _replayLoad = default!;
         [Dependency] private readonly ILogManager _logManager = default!;
         [Dependency] private readonly DebugMonitorManager _debugMonitorManager = default!;
+        [Dependency] private readonly TitleWindowManager _titleWindowManager = default!;
 
         public override void Init()
         {
@@ -139,6 +141,12 @@ namespace Content.Client.Entry
             _configManager.SetCVar("interface.resolutionAutoScaleMinimum", 0.5f);
         }
 
+        public override void Shutdown()
+        {
+            base.Shutdown();
+            _titleWindowManager.Shutdown();
+        }
+
         public override void PostInit()
         {
             base.PostInit();
@@ -159,6 +167,7 @@ namespace Content.Client.Entry
             _userInterfaceManager.SetDefaultTheme("SS14DefaultTheme");
             _userInterfaceManager.SetActiveTheme(_configManager.GetCVar(CVars.InterfaceTheme));
             _documentParsingManager.Initialize();
+            _titleWindowManager.Initialize();
 
             _baseClient.RunLevelChanged += (_, args) =>
             {
diff --git a/Content.Client/GameTicking/Managers/TitleWindowManager.cs b/Content.Client/GameTicking/Managers/TitleWindowManager.cs
new file mode 100644 (file)
index 0000000..18ce16f
--- /dev/null
@@ -0,0 +1,62 @@
+using Content.Shared.CCVar;
+using Robust.Client;
+using Robust.Client.Graphics;
+using Robust.Shared;
+using Robust.Shared.Configuration;
+
+namespace Content.Client.GameTicking.Managers;
+
+public sealed class TitleWindowManager
+{
+    [Dependency] private readonly IBaseClient _client = default!;
+    [Dependency] private readonly IClyde _clyde = default!;
+    [Dependency] private readonly IConfigurationManager _cfg = default!;
+    [Dependency] private readonly IGameController _gameController = default!;
+
+    public void Initialize()
+    {
+        _cfg.OnValueChanged(CVars.GameHostName, OnHostnameChange, true);
+        _cfg.OnValueChanged(CCVars.GameHostnameInTitlebar, OnHostnameTitleChange, true);
+
+        _client.RunLevelChanged += OnRunLevelChangedChange;
+    }
+
+    public void Shutdown()
+    {
+        _cfg.UnsubValueChanged(CVars.GameHostName, OnHostnameChange);
+        _cfg.UnsubValueChanged(CCVars.GameHostnameInTitlebar, OnHostnameTitleChange);
+    }
+
+    private void OnHostnameChange(string hostname)
+    {
+        var defaultWindowTitle = _gameController.GameTitle();
+
+        // Since the game assumes the server name is MyServer and that GameHostnameInTitlebar CCVar is true by default
+        // Lets just... not show anything. This also is used to revert back to just the game title on disconnect.
+        if (_client.RunLevel == ClientRunLevel.Initialize)
+        {
+            _clyde.SetWindowTitle(defaultWindowTitle);
+            return;
+        }
+
+        if (_cfg.GetCVar(CCVars.GameHostnameInTitlebar))
+            // If you really dislike the dash I guess change it here
+            _clyde.SetWindowTitle(hostname + " - " + defaultWindowTitle);
+        else
+            _clyde.SetWindowTitle(defaultWindowTitle);
+    }
+
+    // Clients by default assume game.hostname_in_titlebar is true
+    // but we need to clear it as soon as we join and actually receive the servers preference on this.
+    // This will ensure we rerun OnHostnameChange and set the correct title bar name.
+    private void OnHostnameTitleChange(bool colonthree)
+    {
+        OnHostnameChange(_cfg.GetCVar(CVars.GameHostName));
+    }
+
+    // This is just used we can rerun the hostname change function when we disconnect to revert back to just the games title.
+    private void OnRunLevelChangedChange(object? sender, RunLevelChangedEventArgs runLevelChangedEventArgs)
+    {
+        OnHostnameChange(_cfg.GetCVar(CVars.GameHostName));
+    }
+}
index e643552f70b3b12ca6c06782b0268aab7f7e2fef..370188e3c61de280009b53fae19264da2083e090 100644 (file)
@@ -5,6 +5,7 @@ using Content.Client.Clickable;
 using Content.Client.DebugMon;
 using Content.Client.Eui;
 using Content.Client.Fullscreen;
+using Content.Client.GameTicking.Managers;
 using Content.Client.GhostKick;
 using Content.Client.Guidebook;
 using Content.Client.Launcher;
@@ -57,6 +58,7 @@ namespace Content.Client.IoC
             collection.Register<DebugMonitorManager>();
             collection.Register<PlayerRateLimitManager>();
             collection.Register<SharedPlayerRateLimitManager, PlayerRateLimitManager>();
+            collection.Register<TitleWindowManager>();
         }
     }
 }
index a4f315d62c567f60fd30d5b5576d964d2f98df4b..2d6aa563904dc8924376f1bee57ab9ee34a4317e 100644 (file)
@@ -436,6 +436,12 @@ namespace Content.Shared.CCVar
         public static readonly CVarDef<float> GameEntityMenuLookup =
             CVarDef.Create("game.entity_menu_lookup", 0.25f, CVar.CLIENTONLY | CVar.ARCHIVE);
 
+        /// <summary>
+        /// Should the clients window show the server hostname in the title?
+        /// </summary>
+        public static readonly CVarDef<bool> GameHostnameInTitlebar =
+            CVarDef.Create("game.hostname_in_titlebar", true, CVar.SERVER | CVar.REPLICATED);
+
         /*
          * Discord
          */