]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
version watermark (#35284)
authorErrant <35878406+Errant-4@users.noreply.github.com>
Sun, 23 Feb 2025 19:01:17 +0000 (20:01 +0100)
committerGitHub <noreply@github.com>
Sun, 23 Feb 2025 19:01:17 +0000 (20:01 +0100)
* version watermark

* force version watermarks on vulture

Content.Client/Changelog/ChangelogManager.cs
Content.Client/Changelog/ChangelogWindow.xaml.cs
Content.Client/Gameplay/GameplayState.cs
Content.Shared/CCVar/CCVars.Hud.cs
Content.Shared/CCVar/CCVars.Server.cs
Resources/ConfigPresets/WizardsDen/vulture.toml

index 4383f4661795baccbfdbd412714c36bb1765d7ca..657d0cb3acf6c00a55e3852b3de4ad0167ceaddd 100644 (file)
@@ -1,6 +1,7 @@
 using System.Linq;
 using System.Threading.Tasks;
 using Content.Shared.CCVar;
+using Robust.Shared;
 using Robust.Shared.Configuration;
 using Robust.Shared.ContentPack;
 using Robust.Shared.Serialization.Manager;
@@ -125,6 +126,27 @@ namespace Content.Client.Changelog
             _sawmill = _logManager.GetSawmill(SawmillName);
         }
 
+        /// <summary>
+        ///     Tries to return a human-readable version number from the build.json file
+        /// </summary>
+        public string GetClientVersion()
+        {
+            var fork = _configManager.GetCVar(CVars.BuildForkId);
+            var version = _configManager.GetCVar(CVars.BuildVersion);
+
+            // This trimming might become annoying if down the line some codebases want to switch to a real
+            // version format like "104.11.3" while others are still using the git hashes
+            if (version.Length > 7)
+                version = version[..7];
+
+            if (string.IsNullOrEmpty(version) || string.IsNullOrEmpty(fork))
+                return Loc.GetString("changelog-version-unknown");
+
+            return Loc.GetString("changelog-version-tag",
+                ("fork", fork),
+                ("version", version));
+        }
+
         [DataDefinition]
         public sealed partial class Changelog
         {
index cb07e16a9c28f82ff268ce66445a0b10c6822c08..0b1afcbb0a67a87ca324ee06f4d11218d88ea404 100644 (file)
@@ -70,22 +70,7 @@ namespace Content.Client.Changelog
                 Tabs.SetTabTitle(i++, Loc.GetString($"changelog-tab-title-{changelog.Name}"));
             }
 
-            // Try to get the current version from the build.json file
-            var version = _cfg.GetCVar(CVars.BuildVersion);
-            var forkId = _cfg.GetCVar(CVars.BuildForkId);
-
-            var versionText = Loc.GetString("changelog-version-unknown");
-
-            // Make sure these aren't empty, like in a dev env
-            if (!string.IsNullOrEmpty(version) && !string.IsNullOrEmpty(forkId))
-            {
-                versionText = Loc.GetString("changelog-version-tag",
-                    ("fork", forkId),
-                    ("version", version[..7])); // Only show the first 7 characters
-            }
-
-            // if else statements are ugly, shut up
-            VersionLabel.Text = versionText;
+            VersionLabel.Text = _changelog.GetClientVersion();
 
             TabsUpdated();
         }
index 1efee978f39c0e6e480248922953c063a95204d7..427dd5c071896ea76498fe9e7f8344c21d79b302 100644 (file)
@@ -1,3 +1,5 @@
+using System.Numerics;
+using Content.Client.Changelog;
 using Content.Client.Hands;
 using Content.Client.UserInterface.Controls;
 using Content.Client.UserInterface.Screens;
@@ -7,6 +9,7 @@ using Content.Shared.CCVar;
 using Robust.Client.Graphics;
 using Robust.Client.Input;
 using Robust.Client.UserInterface;
+using Robust.Client.UserInterface.Controls;
 using Robust.Client.UserInterface.CustomControls;
 using Robust.Shared.Configuration;
 using Robust.Shared.Timing;
@@ -20,9 +23,11 @@ namespace Content.Client.Gameplay
         [Dependency] private readonly IOverlayManager _overlayManager = default!;
         [Dependency] private readonly IGameTiming _gameTiming = default!;
         [Dependency] private readonly IUserInterfaceManager _uiManager = default!;
+        [Dependency] private readonly ChangelogManager _changelog = default!;
         [Dependency] private readonly IConfigurationManager _configurationManager = default!;
 
         private FpsCounter _fpsCounter = default!;
+        private Label _version = default!;
 
         public MainViewport Viewport => _uiManager.ActiveScreen!.GetWidget<MainViewport>()!;
 
@@ -40,6 +45,7 @@ namespace Content.Client.Gameplay
             base.Startup();
 
             LoadMainScreen();
+            _configurationManager.OnValueChanged(CCVars.UILayout, ReloadMainScreenValueChange);
 
             // Add the hand-item overlay.
             _overlayManager.AddOverlay(new ShowHandItemOverlay());
@@ -50,7 +56,24 @@ namespace Content.Client.Gameplay
             UserInterfaceManager.PopupRoot.AddChild(_fpsCounter);
             _fpsCounter.Visible = _configurationManager.GetCVar(CCVars.HudFpsCounterVisible);
             _configurationManager.OnValueChanged(CCVars.HudFpsCounterVisible, (show) => { _fpsCounter.Visible = show; });
-            _configurationManager.OnValueChanged(CCVars.UILayout, ReloadMainScreenValueChange);
+
+            // Version number watermark.
+            _version = new Label();
+            _version.Text = _changelog.GetClientVersion();
+            _version.Visible = VersionVisible();
+            UserInterfaceManager.PopupRoot.AddChild(_version);
+            _configurationManager.OnValueChanged(CCVars.HudVersionWatermark, (show) => { _version.Visible = VersionVisible(); });
+            _configurationManager.OnValueChanged(CCVars.ForceClientHudVersionWatermark, (show) => { _version.Visible = VersionVisible(); });
+            // TODO make this centered or something
+            LayoutContainer.SetPosition(_version, new Vector2(800, 0));
+        }
+
+        // This allows servers to force the watermark on clients
+        private bool VersionVisible()
+        {
+            var client = _configurationManager.GetCVar(CCVars.HudVersionWatermark);
+            var server = _configurationManager.GetCVar(CCVars.ForceClientHudVersionWatermark);
+            return client || server;
         }
 
         protected override void Shutdown()
index f96924b34964d56e35365e060b6f747c80864f01..c435f07cbef0fb2fc08a871a653422d33e9af307 100644 (file)
@@ -19,6 +19,15 @@ public sealed partial class CCVars
     public static readonly CVarDef<float> HudHeldItemOffset =
         CVarDef.Create("hud.held_item_offset", 28f, CVar.ARCHIVE | CVar.CLIENTONLY);
 
+    /// <summary>
+    ///     Displays framerate counter
+    /// </summary>
     public static readonly CVarDef<bool> HudFpsCounterVisible =
         CVarDef.Create("hud.fps_counter_visible", false, CVar.CLIENTONLY | CVar.ARCHIVE);
+
+    /// <summary>
+    ///     Displays the fork ID and version number
+    /// </summary>
+    public static readonly CVarDef<bool> HudVersionWatermark =
+        CVarDef.Create("hud.version_watermark", false, CVar.CLIENTONLY | CVar.ARCHIVE);
 }
index 88e7b251ba071f7af441c8f28a4a4f6a5503873e..aad6d0a8081639e68811d856c89f33d593a2fe72 100644 (file)
@@ -53,4 +53,10 @@ public sealed partial class CCVars
     /// </summary>
     public static readonly CVarDef<int> ServerLobbyRightPanelWidth =
         CVarDef.Create("server.lobby_right_panel_width", 650, CVar.REPLICATED | CVar.SERVER);
+
+    /// <summary>
+    ///     Forces clients to display version watermark, as if HudVersionWatermark was true
+    /// </summary>
+    public static readonly CVarDef<bool> ForceClientHudVersionWatermark =
+        CVarDef.Create("server.force_client_hud_version_watermark", false, CVar.REPLICATED | CVar.SERVER);
 }
index ab1d8459f3715167a8b28fcca19ca3cd42083fbf..8eccfa48e19f4cc12c0d81de4f743a110d9b1a45 100644 (file)
@@ -10,6 +10,7 @@ tags = "lang:en,region:am_n_e,rp:low"
 [server]
 # This needs to be specified even though it's identical to the hostname, because fallback lobby name is "Lobby <hostname>" which would be too long and go out of bounds
 lobby_name = "[EN][Testing] Wizard's Den Vulture [US East 2]"
+force_client_hud_version_watermark = true
 
 [chat]
-motd = "\n########################################################\n\n[font size=17]This is a test server. You can play with the newest changes to the game, but these [color=red]changes may not be final or stable[/color], and may be reverted. Please report bugs via our GitHub, forum, or community Discord.[/font]\n\n########################################################\n"
\ No newline at end of file
+motd = "\n########################################################\n\n[font size=17]This is a test server. You can play with the newest changes to the game, but these [color=red]changes may not be final or stable[/color], and may be reverted. Please report bugs via our GitHub, forum, or community Discord.[/font]\n\n########################################################\n"