From d8667b5aa35f6b8db28c663e6ddf75631168b29d Mon Sep 17 00:00:00 2001
From: stalengd
Date: Thu, 24 Oct 2024 02:06:58 +0300
Subject: [PATCH 1/2] Fixed playtime formatting
---
.../Info/PlaytimeStats/PlaytimeStatsEntry.cs | 3 ++-
.../Info/PlaytimeStats/PlaytimeStatsWindow.cs | 3 +--
.../ContentLocalizationManager.cs | 21 +++++++++++++++++++
.../DepartmentTimeRequirement.cs | 3 ++-
.../OverallPlaytimeRequirement.cs | 3 ++-
.../JobRequirement/RoleTimeRequirement.cs | 3 ++-
Resources/Locale/en-US/_lib.ftl | 3 +++
.../Locale/en-US/info/playtime-stats.ftl | 3 +--
.../Locale/en-US/job/role-requirements.ftl | 1 -
9 files changed, 34 insertions(+), 9 deletions(-)
diff --git a/Content.Client/Info/PlaytimeStats/PlaytimeStatsEntry.cs b/Content.Client/Info/PlaytimeStats/PlaytimeStatsEntry.cs
index 16e8f55a7e27..632ad8de4ac6 100644
--- a/Content.Client/Info/PlaytimeStats/PlaytimeStatsEntry.cs
+++ b/Content.Client/Info/PlaytimeStats/PlaytimeStatsEntry.cs
@@ -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 PlaytimeStatsEntry(string role, TimeSpan playtime, StyleBox styleBox)
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;
}
diff --git a/Content.Client/Info/PlaytimeStats/PlaytimeStatsWindow.cs b/Content.Client/Info/PlaytimeStats/PlaytimeStatsWindow.cs
index 1a530d950f98..98241b2ccab3 100644
--- a/Content.Client/Info/PlaytimeStats/PlaytimeStatsWindow.cs
+++ b/Content.Client/Info/PlaytimeStats/PlaytimeStatsWindow.cs
@@ -104,8 +104,7 @@ private void PopulatePlaytimeData()
{
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();
diff --git a/Content.Shared/Localizations/ContentLocalizationManager.cs b/Content.Shared/Localizations/ContentLocalizationManager.cs
index ca381bbb3951..c18890caa782 100644
--- a/Content.Shared/Localizations/ContentLocalizationManager.cs
+++ b/Content.Shared/Localizations/ContentLocalizationManager.cs
@@ -40,6 +40,7 @@ public void Initialize()
_loc.AddFunction(culture, "LOC", FormatLoc);
_loc.AddFunction(culture, "NATURALFIXED", FormatNaturalFixed);
_loc.AddFunction(culture, "NATURALPERCENT", FormatNaturalPercent);
+ _loc.AddFunction(culture, "PLAYTIME", FormatPlaytime);
/*
@@ -191,6 +192,16 @@ public static string FormatDirection(Direction dir)
return Loc.GetString($"zzzz-fmt-direction-{dir.ToString()}");
}
+ ///
+ /// Formats playtime as hours and minutes.
+ ///
+ 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;
@@ -279,5 +290,15 @@ private static ILocValue FormatUnits(LocArgs args)
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));
+ }
}
}
diff --git a/Content.Shared/Roles/JobRequirement/DepartmentTimeRequirement.cs b/Content.Shared/Roles/JobRequirement/DepartmentTimeRequirement.cs
index 78c6bd251779..8c8629921031 100644
--- a/Content.Shared/Roles/JobRequirement/DepartmentTimeRequirement.cs
+++ b/Content.Shared/Roles/JobRequirement/DepartmentTimeRequirement.cs
@@ -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 override bool Check(IEntityManager entManager,
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))
diff --git a/Content.Shared/Roles/JobRequirement/OverallPlaytimeRequirement.cs b/Content.Shared/Roles/JobRequirement/OverallPlaytimeRequirement.cs
index ed985cadfba0..67b3938e1a71 100644
--- a/Content.Shared/Roles/JobRequirement/OverallPlaytimeRequirement.cs
+++ b/Content.Shared/Roles/JobRequirement/OverallPlaytimeRequirement.cs
@@ -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 override bool Check(IEntityManager entManager,
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)
{
diff --git a/Content.Shared/Roles/JobRequirement/RoleTimeRequirement.cs b/Content.Shared/Roles/JobRequirement/RoleTimeRequirement.cs
index 23498ab91ad2..e75a18f011da 100644
--- a/Content.Shared/Roles/JobRequirement/RoleTimeRequirement.cs
+++ b/Content.Shared/Roles/JobRequirement/RoleTimeRequirement.cs
@@ -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 override bool Check(IEntityManager entManager,
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))
diff --git a/Resources/Locale/en-US/_lib.ftl b/Resources/Locale/en-US/_lib.ftl
index c901d0f461e6..5c6f73af66fa 100644
--- a/Resources/Locale/en-US/_lib.ftl
+++ b/Resources/Locale/en-US/_lib.ftl
@@ -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
diff --git a/Resources/Locale/en-US/info/playtime-stats.ftl b/Resources/Locale/en-US/info/playtime-stats.ftl
index 85508c1d09cd..b4925176a766 100644
--- a/Resources/Locale/en-US/info/playtime-stats.ftl
+++ b/Resources/Locale/en-US/info/playtime-stats.ftl
@@ -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
diff --git a/Resources/Locale/en-US/job/role-requirements.ftl b/Resources/Locale/en-US/job/role-requirements.ftl
index 79a216fccaf4..686fcb93cb12 100644
--- a/Resources/Locale/en-US/job/role-requirements.ftl
+++ b/Resources/Locale/en-US/job/role-requirements.ftl
@@ -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:
From 6d7d12fca94c052fc61b6b1e2c41ec5e6ef6749e Mon Sep 17 00:00:00 2001
From: stalengd
Date: Sat, 26 Oct 2024 05:33:33 +0300
Subject: [PATCH 2/2] SS220 comments
---
Content.Client/Info/PlaytimeStats/PlaytimeStatsEntry.cs | 4 ++--
Content.Client/Info/PlaytimeStats/PlaytimeStatsWindow.cs | 2 +-
Content.Shared/Localizations/ContentLocalizationManager.cs | 6 +++++-
.../Roles/JobRequirement/DepartmentTimeRequirement.cs | 4 ++--
.../Roles/JobRequirement/OverallPlaytimeRequirement.cs | 4 ++--
Content.Shared/Roles/JobRequirement/RoleTimeRequirement.cs | 4 ++--
6 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/Content.Client/Info/PlaytimeStats/PlaytimeStatsEntry.cs b/Content.Client/Info/PlaytimeStats/PlaytimeStatsEntry.cs
index 632ad8de4ac6..f8cb04bddea3 100644
--- a/Content.Client/Info/PlaytimeStats/PlaytimeStatsEntry.cs
+++ b/Content.Client/Info/PlaytimeStats/PlaytimeStatsEntry.cs
@@ -1,4 +1,4 @@
-using Content.Shared.Localizations;
+using Content.Shared.Localizations; // SS220 Playtime Format Fix
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
@@ -17,7 +17,7 @@ public PlaytimeStatsEntry(string role, TimeSpan playtime, StyleBox styleBox)
RoleLabel.Text = role;
Playtime = playtime; // store the TimeSpan value directly
- PlaytimeLabel.Text = ContentLocalizationManager.FormatPlaytime(playtime); // convert to string for display
+ PlaytimeLabel.Text = ContentLocalizationManager.FormatPlaytime(playtime); // convert to string for display // SS220 Playtime Format Fix
BackgroundColorPanel.PanelOverride = styleBox;
}
diff --git a/Content.Client/Info/PlaytimeStats/PlaytimeStatsWindow.cs b/Content.Client/Info/PlaytimeStats/PlaytimeStatsWindow.cs
index 98241b2ccab3..abfac3bf6cb0 100644
--- a/Content.Client/Info/PlaytimeStats/PlaytimeStatsWindow.cs
+++ b/Content.Client/Info/PlaytimeStats/PlaytimeStatsWindow.cs
@@ -104,7 +104,7 @@ private void PopulatePlaytimeData()
{
var overallPlaytime = _jobRequirementsManager.FetchOverallPlaytime();
- OverallPlaytimeLabel.Text = Loc.GetString("ui-playtime-overall", ("time", overallPlaytime));
+ OverallPlaytimeLabel.Text = Loc.GetString("ui-playtime-overall", ("time", overallPlaytime)); // SS220 Playtime Format Fix
var rolePlaytimes = _jobRequirementsManager.FetchPlaytimeByRoles();
diff --git a/Content.Shared/Localizations/ContentLocalizationManager.cs b/Content.Shared/Localizations/ContentLocalizationManager.cs
index c18890caa782..1017c701099e 100644
--- a/Content.Shared/Localizations/ContentLocalizationManager.cs
+++ b/Content.Shared/Localizations/ContentLocalizationManager.cs
@@ -40,7 +40,7 @@ public void Initialize()
_loc.AddFunction(culture, "LOC", FormatLoc);
_loc.AddFunction(culture, "NATURALFIXED", FormatNaturalFixed);
_loc.AddFunction(culture, "NATURALPERCENT", FormatNaturalPercent);
- _loc.AddFunction(culture, "PLAYTIME", FormatPlaytime);
+ _loc.AddFunction(culture, "PLAYTIME", FormatPlaytime); // SS220 Playtime Format Fix
/*
@@ -192,6 +192,7 @@ public static string FormatDirection(Direction dir)
return Loc.GetString($"zzzz-fmt-direction-{dir.ToString()}");
}
+ // SS220 Playtime Format Fix begin
///
/// Formats playtime as hours and minutes.
///
@@ -201,6 +202,7 @@ public static string FormatPlaytime(TimeSpan time)
var minutes = time.Minutes;
return Loc.GetString($"zzzz-fmt-playtime", ("hours", hours), ("minutes", minutes));
}
+ // SS220 Playtime Format Fix end
private static ILocValue FormatLoc(LocArgs args)
{
@@ -291,6 +293,7 @@ private static ILocValue FormatUnits(LocArgs args)
return new LocValueString(res);
}
+ // SS220 Playtime Format Fix begin
private static ILocValue FormatPlaytime(LocArgs args)
{
var time = TimeSpan.Zero;
@@ -300,5 +303,6 @@ private static ILocValue FormatPlaytime(LocArgs args)
}
return new LocValueString(FormatPlaytime(time));
}
+ // SS220 Playtime Format Fix end
}
}
diff --git a/Content.Shared/Roles/JobRequirement/DepartmentTimeRequirement.cs b/Content.Shared/Roles/JobRequirement/DepartmentTimeRequirement.cs
index 8c8629921031..851d629d86bb 100644
--- a/Content.Shared/Roles/JobRequirement/DepartmentTimeRequirement.cs
+++ b/Content.Shared/Roles/JobRequirement/DepartmentTimeRequirement.cs
@@ -1,5 +1,5 @@
using System.Diagnostics.CodeAnalysis;
-using Content.Shared.Localizations;
+using Content.Shared.Localizations; // SS220 Playtime Format Fix
using Content.Shared.Preferences;
using JetBrains.Annotations;
using Robust.Shared.Prototypes;
@@ -50,7 +50,7 @@ public override bool Check(IEntityManager entManager,
var deptDiffSpan = Time - playtime;
var deptDiff = deptDiffSpan.TotalMinutes;
- var formattedDeptDiff = ContentLocalizationManager.FormatPlaytime(deptDiffSpan);
+ var formattedDeptDiff = ContentLocalizationManager.FormatPlaytime(deptDiffSpan); // SS220 Playtime Format Fix
var nameDepartment = "role-timer-department-unknown";
if (protoManager.TryIndex(Department, out var departmentIndexed))
diff --git a/Content.Shared/Roles/JobRequirement/OverallPlaytimeRequirement.cs b/Content.Shared/Roles/JobRequirement/OverallPlaytimeRequirement.cs
index 67b3938e1a71..85d06bb03862 100644
--- a/Content.Shared/Roles/JobRequirement/OverallPlaytimeRequirement.cs
+++ b/Content.Shared/Roles/JobRequirement/OverallPlaytimeRequirement.cs
@@ -1,5 +1,5 @@
using System.Diagnostics.CodeAnalysis;
-using Content.Shared.Localizations;
+using Content.Shared.Localizations; // SS220 Playtime Format Fix
using Content.Shared.Players.PlayTimeTracking;
using Content.Shared.Preferences;
using JetBrains.Annotations;
@@ -28,7 +28,7 @@ public override bool Check(IEntityManager entManager,
var overallTime = playTimes.GetValueOrDefault(PlayTimeTrackingShared.TrackerOverall);
var overallDiffSpan = Time - overallTime;
var overallDiff = overallDiffSpan.TotalMinutes;
- var formattedOverallDiff = ContentLocalizationManager.FormatPlaytime(overallDiffSpan);
+ var formattedOverallDiff = ContentLocalizationManager.FormatPlaytime(overallDiffSpan); // SS220 Playtime Format Fix
if (!Inverted)
{
diff --git a/Content.Shared/Roles/JobRequirement/RoleTimeRequirement.cs b/Content.Shared/Roles/JobRequirement/RoleTimeRequirement.cs
index e75a18f011da..2f29c8b2432e 100644
--- a/Content.Shared/Roles/JobRequirement/RoleTimeRequirement.cs
+++ b/Content.Shared/Roles/JobRequirement/RoleTimeRequirement.cs
@@ -1,5 +1,5 @@
using System.Diagnostics.CodeAnalysis;
-using Content.Shared.Localizations;
+using Content.Shared.Localizations; // SS220 Playtime Format Fix
using Content.Shared.Players.PlayTimeTracking;
using Content.Shared.Preferences;
using Content.Shared.Roles.Jobs;
@@ -37,7 +37,7 @@ public override bool Check(IEntityManager entManager,
playTimes.TryGetValue(proto, out var roleTime);
var roleDiffSpan = Time - roleTime;
var roleDiff = roleDiffSpan.TotalMinutes;
- var formattedRoleDiff = ContentLocalizationManager.FormatPlaytime(roleDiffSpan);
+ var formattedRoleDiff = ContentLocalizationManager.FormatPlaytime(roleDiffSpan); // SS220 Playtime Format Fix
var departmentColor = Color.Yellow;
if (entManager.EntitySysManager.TryGetEntitySystem(out SharedJobSystem? jobSystem))