]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix playtime formatting (#32974)
authorStalen <33173619+stalengd@users.noreply.github.com>
Mon, 28 Oct 2024 18:00:00 +0000 (21:00 +0300)
committerVasilis The Pikachu <vasilis@pikachu.systems>
Mon, 28 Oct 2024 18:00:37 +0000 (19:00 +0100)
Content.Client/Info/PlaytimeStats/PlaytimeStatsEntry.cs
Content.Client/Info/PlaytimeStats/PlaytimeStatsWindow.cs
Content.Shared/Localizations/ContentLocalizationManager.cs
Content.Shared/Roles/JobRequirement/DepartmentTimeRequirement.cs
Content.Shared/Roles/JobRequirement/OverallPlaytimeRequirement.cs
Content.Shared/Roles/JobRequirement/RoleTimeRequirement.cs
Resources/Locale/en-US/_lib.ftl
Resources/Locale/en-US/info/playtime-stats.ftl
Resources/Locale/en-US/job/role-requirements.ftl

index 16e8f55a7e274e8788763fe39b26c623d819900c..632ad8de4ac68c62291669d7fa5dc4eabd1e2baf 100644 (file)
@@ -1,3 +1,4 @@
+using Content.Shared.Localizations;
 using Robust.Client.AutoGenerated;
 using Robust.Client.Graphics;
 using Robust.Client.UserInterface.Controls;
@@ -16,7 +17,7 @@ public sealed partial class PlaytimeStatsEntry : ContainerButton
 
         RoleLabel.Text = role;
         Playtime = playtime;  // store the TimeSpan value directly
-        PlaytimeLabel.Text = playtime.ToString(Loc.GetString("ui-playtime-time-format"));  // convert to string for display
+        PlaytimeLabel.Text = ContentLocalizationManager.FormatPlaytime(playtime);  // convert to string for display
         BackgroundColorPanel.PanelOverride = styleBox;
     }
 
index 1a530d950f983f0e29d87e93864916c3c92c52e4..98241b2ccab38a27663f3006cff0dd0e2e2bf38d 100644 (file)
@@ -104,8 +104,7 @@ public sealed partial class PlaytimeStatsWindow : FancyWindow
     {
         var overallPlaytime = _jobRequirementsManager.FetchOverallPlaytime();
 
-        var formattedPlaytime = overallPlaytime.ToString(Loc.GetString("ui-playtime-time-format"));
-        OverallPlaytimeLabel.Text = Loc.GetString("ui-playtime-overall", ("time", formattedPlaytime));
+        OverallPlaytimeLabel.Text = Loc.GetString("ui-playtime-overall", ("time", overallPlaytime));
 
         var rolePlaytimes = _jobRequirementsManager.FetchPlaytimeByRoles();
 
index ad8890ae0fdb04a313b80bf8c9509c2f943db256..e60ca74a37fab2b01e3662382e75f469b1d508af 100644 (file)
@@ -36,6 +36,7 @@ namespace Content.Shared.Localizations
             _loc.AddFunction(culture, "LOC", FormatLoc);
             _loc.AddFunction(culture, "NATURALFIXED", FormatNaturalFixed);
             _loc.AddFunction(culture, "NATURALPERCENT", FormatNaturalPercent);
+            _loc.AddFunction(culture, "PLAYTIME", FormatPlaytime);
 
 
             /*
@@ -141,6 +142,16 @@ namespace Content.Shared.Localizations
             return Loc.GetString($"zzzz-fmt-direction-{dir.ToString()}");
         }
 
+        /// <summary>
+        /// Formats playtime as hours and minutes.
+        /// </summary>
+        public static string FormatPlaytime(TimeSpan time)
+        {
+            var hours = (int)time.TotalHours;
+            var minutes = time.Minutes;
+            return Loc.GetString($"zzzz-fmt-playtime", ("hours", hours), ("minutes", minutes));
+        }
+
         private static ILocValue FormatLoc(LocArgs args)
         {
             var id = ((LocValueString) args.Args[0]).Value;
@@ -229,5 +240,15 @@ namespace Content.Shared.Localizations
 
             return new LocValueString(res);
         }
+
+        private static ILocValue FormatPlaytime(LocArgs args)
+        {
+            var time = TimeSpan.Zero;
+            if (args.Args is { Count: > 0 } && args.Args[0].Value is TimeSpan timeArg)
+            {
+                time = timeArg;
+            }
+            return new LocValueString(FormatPlaytime(time));
+        }
     }
 }
index 78c6bd251779846c825310ddbd41c84000a2a7ac..8c8629921031f403f85153088baa5b14f57841c8 100644 (file)
@@ -1,4 +1,5 @@
 using System.Diagnostics.CodeAnalysis;
+using Content.Shared.Localizations;
 using Content.Shared.Preferences;
 using JetBrains.Annotations;
 using Robust.Shared.Prototypes;
@@ -49,7 +50,7 @@ public sealed partial class DepartmentTimeRequirement : JobRequirement
 
         var deptDiffSpan = Time - playtime;
         var deptDiff = deptDiffSpan.TotalMinutes;
-        var formattedDeptDiff = deptDiffSpan.ToString(Loc.GetString("role-timer-time-format"));
+        var formattedDeptDiff = ContentLocalizationManager.FormatPlaytime(deptDiffSpan);
         var nameDepartment = "role-timer-department-unknown";
 
         if (protoManager.TryIndex(Department, out var departmentIndexed))
index ed985cadfba07ede18079355648206b956ece3a7..67b3938e1a71f20bf0043046c7eb8ece7c3c5453 100644 (file)
@@ -1,4 +1,5 @@
 using System.Diagnostics.CodeAnalysis;
+using Content.Shared.Localizations;
 using Content.Shared.Players.PlayTimeTracking;
 using Content.Shared.Preferences;
 using JetBrains.Annotations;
@@ -27,7 +28,7 @@ public sealed partial class OverallPlaytimeRequirement : JobRequirement
         var overallTime = playTimes.GetValueOrDefault(PlayTimeTrackingShared.TrackerOverall);
         var overallDiffSpan = Time - overallTime;
         var overallDiff = overallDiffSpan.TotalMinutes;
-        var formattedOverallDiff = overallDiffSpan.ToString(Loc.GetString("role-timer-time-format"));
+        var formattedOverallDiff = ContentLocalizationManager.FormatPlaytime(overallDiffSpan);
 
         if (!Inverted)
         {
index 23498ab91ad21c8eee1be1b0f1aec949599266e8..e75a18f011da6dad4cc955b8efb8f74fdc91fe7c 100644 (file)
@@ -1,4 +1,5 @@
 using System.Diagnostics.CodeAnalysis;
+using Content.Shared.Localizations;
 using Content.Shared.Players.PlayTimeTracking;
 using Content.Shared.Preferences;
 using Content.Shared.Roles.Jobs;
@@ -36,7 +37,7 @@ public sealed partial class RoleTimeRequirement : JobRequirement
         playTimes.TryGetValue(proto, out var roleTime);
         var roleDiffSpan = Time - roleTime;
         var roleDiff = roleDiffSpan.TotalMinutes;
-        var formattedRoleDiff = roleDiffSpan.ToString(Loc.GetString("role-timer-time-format"));
+        var formattedRoleDiff = ContentLocalizationManager.FormatPlaytime(roleDiffSpan);
         var departmentColor = Color.Yellow;
 
         if (entManager.EntitySysManager.TryGetEntitySystem(out SharedJobSystem? jobSystem))
index c901d0f461e6bc5df039916f9da4fcbbec8f77a9..5c6f73af66fa0db1488d01123f4de0527028b8a7 100644 (file)
@@ -31,3 +31,6 @@ zzzz-fmt-power-joules = { TOSTRING($divided, "F1") } { $places ->
     [4] TJ
     *[5] ???
 }
+
+# Used internally by the PLAYTIME() function.
+zzzz-fmt-playtime = {$hours}H {$minutes}M
\ No newline at end of file
index 85508c1d09cd9b5ac474aef75c786606aad5f6eb..b4925176a766a2302efeee789201b9d23a60f5f1 100644 (file)
@@ -2,9 +2,8 @@
 
 ui-playtime-stats-title = User Playtime Stats
 ui-playtime-overall-base = Overall Playtime:
-ui-playtime-overall = Overall Playtime: {$time}
+ui-playtime-overall = Overall Playtime: {PLAYTIME($time)}
 ui-playtime-first-time = First Time Playing
 ui-playtime-roles = Playtime per Role
-ui-playtime-time-format = %h\H\ %m\M
 ui-playtime-header-role-type = Role
 ui-playtime-header-role-time = Time
index 79a216fccaf41fb8e39d9464c1fb1db4c17f5143..686fcb93cb12465c3b5fc3b6b92b37610a75cac3 100644 (file)
@@ -4,7 +4,6 @@ role-timer-overall-insufficient = You require [color=yellow]{$time}[/color] more
 role-timer-overall-too-high = You require [color=yellow]{$time}[/color] less overall playtime to play this role. (Are you trying to play a trainee role?)
 role-timer-role-insufficient = You require [color=yellow]{$time}[/color] more playtime with [color={$departmentColor}]{$job}[/color] to play this role.
 role-timer-role-too-high = You require[color=yellow] {$time}[/color] less playtime with [color={$departmentColor}]{$job}[/color] to play this role. (Are you trying to play a trainee role?)
-role-timer-time-format = %h\H\ %m\M
 role-timer-age-too-old = Your character must be under the age of [color=yellow]{$age}[/color] to play this role.
 role-timer-age-too-young = Your character must be over the age of [color=yellow]{$age}[/color] to play this role.
 role-timer-whitelisted-species = Your character must be one of the following species to play this role: