Skip to content

Commit 0d5ec4e

Browse files
committed
Actually just add a handful of date & time options
1 parent 1253329 commit 0d5ec4e

File tree

6 files changed

+46
-11
lines changed

6 files changed

+46
-11
lines changed

ContentEditor.App/Configuration/AppConfig.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public static class Keys
5353
public const string WindowRect = "window_rect";
5454
public const string PauseAnimPlayerOnSeek = "pause_anim_player_on_seek";
5555
public const string UseFullscreenAnimPlayback = "use_fullscreen_anim_playback";
56+
public const string DateFormat = "date_format";
57+
public const string ClockFormat = "clock_format";
5658

5759
public const string RenderAxis = "render_axis";
5860
public const string RenderMeshes = "render_meshes";
@@ -191,6 +193,8 @@ public void Set(T? value) => SetAndSave(value, (v) => {
191193
public readonly SettingWrapper<DateTime> LastUpdateCheck = new SettingWrapper<DateTime>(Keys.LastUpdateCheck, _lock, DateTime.MinValue);
192194
public readonly SettingWrapper<bool> PauseAnimPlayerOnSeek = new SettingWrapper<bool>(Keys.PauseAnimPlayerOnSeek, _lock, true);
193195
public readonly SettingWrapper<bool> UseFullscreenAnimPlayback = new SettingWrapper<bool>(Keys.UseFullscreenAnimPlayback, _lock, false);
196+
public readonly SettingWrapper<int> DateFormat = new SettingWrapper<int>(Keys.DateFormat, _lock, 0);
197+
public readonly SettingWrapper<bool> ClockFormat = new SettingWrapper<bool>(Keys.ClockFormat, _lock, false);
194198

195199
public readonly SettingWrapper<int> PakDisplayModeValue = new SettingWrapper<int>(Keys.LogToFile, _lock, (int)FileDisplayMode.List);
196200
public FileDisplayMode PakDisplayMode { get => (FileDisplayMode)PakDisplayModeValue.Get(); set => PakDisplayModeValue.Set((int)value); }
@@ -339,6 +343,8 @@ public static void SaveConfigToIni()
339343
(Keys.QuaternionsAsEuler, instance.ShowQuaternionsAsEuler.value.ToString(), null),
340344
(Keys.PauseAnimPlayerOnSeek, instance.PauseAnimPlayerOnSeek.value.ToString(), null),
341345
(Keys.UseFullscreenAnimPlayback, instance.UseFullscreenAnimPlayback.value.ToString(), null),
346+
(Keys.DateFormat, instance.DateFormat.value.ToString(), null),
347+
(Keys.ClockFormat, instance.ClockFormat.value.ToString(), null),
342348

343349
(Keys.RenderAxis, instance.RenderAxis.value.ToString(), null),
344350
(Keys.RenderMeshes, instance.RenderMeshes.value.ToString(), null),
@@ -452,10 +458,13 @@ private void LoadConfigs(IEnumerable<(string key, string value, string? group)>
452458
if (int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsed)) UnpackMaxThreads.value = Math.Clamp(parsed, 1, 64);
453459
break;
454460
case Keys.BackgroundColor:
455-
if (ReeLib.via.Color.TryParse(value, out var _col)) BackgroundColor.value = _col;
461+
if (ReeLib.via.Color.TryParse(value, out var _col)) BackgroundColor.value = _col;
456462
break;
457463
case Keys.LogLevel:
458-
if (int.TryParse(value, out var _intvalue)) LogLevel.value = _intvalue;
464+
if (int.TryParse(value, out var _intvalue)) LogLevel.value = _intvalue;
465+
break;
466+
case Keys.DateFormat:
467+
if (int.TryParse(value, out _intvalue)) DateFormat.value = _intvalue;
459468
break;
460469
case Keys.MaxUndoSteps:
461470
if (int.TryParse(value, out _intvalue)) MaxUndoSteps.value = Math.Max(_intvalue, 0);
@@ -478,6 +487,9 @@ private void LoadConfigs(IEnumerable<(string key, string value, string? group)>
478487
case Keys.UseFullscreenAnimPlayback:
479488
UseFullscreenAnimPlayback.value = ReadBool(value);
480489
break;
490+
case Keys.ClockFormat:
491+
ClockFormat.value = ReadBool(value);
492+
break;
481493
case Keys.RecentFiles:
482494
JsonSettings.RecentFiles.AddRange(value.Split('|', StringSplitOptions.RemoveEmptyEntries));
483495
break;

ContentEditor.App/Core/Time.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ public class Time
1616

1717
internal Time() { mainThread = Thread.CurrentThread; }
1818

19+
private static readonly string[] DateFormats =
20+
[
21+
"dd/MM/yyyy",
22+
"MM/dd/yyyy",
23+
"yyyy/MM/dd"
24+
];
25+
public static string dateFormat => DateFormats[Math.Clamp(AppConfig.Instance.DateFormat.Get(), 0, DateFormats.Length - 1)];
1926
internal void Init()
2027
{
2128

@@ -31,4 +38,4 @@ internal void Update(float deltaTime, bool isMainThread)
3138
_totalTime += deltaTime;
3239
}
3340
}
34-
}
41+
}

ContentEditor.App/Imgui/App/BundleManagementUI.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using ReeLib;
77
using ReeLib.Aimp;
88
using System;
9+
using System.Globalization;
910
using System.Numerics;
1011
using System.Runtime.InteropServices;
1112
using System.Text.Json.Nodes;
@@ -49,6 +50,7 @@ public BundleManagementUI(BundleManager workspace, string? preselectBundle, Acti
4950
protected UIContext context = null!;
5051
private readonly CreateBundleFromLooseFileFolderDelegate? createFromLooseFileFolder;
5152
private readonly CreateBundleFromPakDelegate? createFromPak;
53+
private static string timeFormat => AppConfig.Instance.ClockFormat.Get() ? " hh:mm:ss tt" : " HH:mm:ss";
5254

5355
public void Init(UIContext context)
5456
{
@@ -283,8 +285,8 @@ private void ShowBundlesMenu()
283285
}
284286

285287
ImGui.BeginDisabled();
286-
string createDate = $"Created at: {bundle.CreatedAt}";
287-
string updateDate = $"Updated at: {bundle.UpdatedAt}";
288+
string createDate = "Created at: " + FormatUTCString(bundle.CreatedAt);
289+
string updateDate = "Updated at: " + FormatUTCString(bundle.UpdatedAt);
288290
ImGui.InputText("##CreationDate", ref createDate, 100);
289291
ImGui.InputText("##UpdateDate", ref updateDate, 100);
290292
ImGui.EndDisabled();
@@ -491,7 +493,14 @@ private void OpenFileFromNode(HierarchyTreeWidget node, Bundle bundle)
491493
openFileCallback!(path);
492494
}
493495
}
494-
496+
private string FormatUTCString(string utcString)
497+
{
498+
utcString = utcString.Replace("UTC", "").Trim();
499+
if (DateTime.TryParseExact(utcString, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out var utc)) {
500+
return utc.ToLocalTime().ToString(Time.dateFormat + timeFormat, CultureInfo.InvariantCulture);
501+
}
502+
return utcString;
503+
}
495504
public bool RequestClose()
496505
{
497506
return false;

ContentEditor.App/Imgui/App/Home.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using System.Numerics;
21
using ContentEditor.App.Github;
32
using ContentEditor.App.Internal;
43
using ContentEditor.App.Windowing;
54
using ContentEditor.Core;
65
using ContentEditor.Themes;
76
using ReeLib;
7+
using System.Numerics;
88

99
namespace ContentEditor.App;
1010

@@ -33,6 +33,7 @@ public class HomeWindow : IWindowHandler
3333
private static string[] gameNameCodes = null!;
3434
private string chosenGame = "";
3535
private bool customGame;
36+
private static string timeFormat => AppConfig.Instance.ClockFormat.Get() ? " hh:mm tt" : " HH:mm";
3637
public BundleDisplayMode DisplayMode { get; set; } = AppConfig.Instance.BundleDisplayMode;
3738

3839
private static Dictionary<string, Func<Vector4[]>> GameColors = new() // TODO SILVER: Add the rest of the games
@@ -583,8 +584,7 @@ private void ShowUpdateLog()
583584
ImGui.PushFont(null, UI.FontSize * 2);
584585
ImGui.Text("Version " + release.TagName);
585586
ImGui.PopFont();
586-
587-
ImGui.TextColored(Colors.Faded, $"Release date: {release.ReleaseDate.ToLocalTime().ToString("yyyy/MM/dd hh:mm tt")}");
587+
ImGui.TextColored(Colors.Faded, $"Release date: {release.ReleaseDate.ToLocalTime().ToString(Time.dateFormat + timeFormat)}");
588588

589589
if (release.TagName == AppConfig.Version) {
590590
ImGui.SameLine();
@@ -653,7 +653,7 @@ private void ShowCommitLog()
653653
var commits = AppConfig.Settings.Changelogs.FindCurrentAndNewCommits();
654654
ImGui.BeginChild("CommitLog");
655655
foreach (var commit in commits) {
656-
ImGui.TextColored(Colors.Faded, commit.Commit.Author?.Date.ToLocalTime().ToString("yyyy/MM/dd hh:mm tt") ?? "[unknown time]");
656+
ImGui.TextColored(Colors.Faded, commit.Commit.Author?.Date.ToLocalTime().ToString(Time.dateFormat + timeFormat) ?? "[unknown time]");
657657
ImGui.SameLine();
658658
ImGui.Text(commit.Commit.Message ?? "<no message>");
659659
if (AppConfig.RevisionHash != null && commit.Sha?.StartsWith(AppConfig.RevisionHash) == true) {

ContentEditor.App/Imgui/SettingsWindowHandler.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class SettingsWindowHandler : IWindowHandler, IKeepEnabledWhileSaving
2020
private int selectedSubGroup = -1;
2121
private static bool? _wasOriginallyAlphaBg;
2222
private static readonly string[] LogLevels = ["Debug", "Info", "Error"];
23+
private static readonly string[] DateFormats = ["DD/MM/YYYY [ EU ]", "MM/DD/YYYY [ US ]", "YYYY/MM/DD [ JP ]"];
2324
private string customGameNameInput = "", customGameFilepath = "";
2425
private static HashSet<string>? fullSupportedGames;
2526
private enum SubGroupID
@@ -313,6 +314,12 @@ private static void ShowDisplayGeneralTab()
313314
ShowSlider(config.MaxFps, "Max FPS", 10, 240, "The maximum FPS for rendering.");
314315
ShowSlider(config.BackgroundMaxFps, "Max FPS in background", 5, config.MaxFps.Get(), "The maximum FPS when the editor window is not focused.");
315316
ShowSetting(config.UseFullscreenAnimPlayback, "Fullscreen Animation Playback Overlay", "Whether to keep the animation playback overlay in the top-right corner of the Mesh Viewer or make it fullscreen.");
317+
ImGui.SeparatorText("Date & Time");
318+
var dateFormat = config.DateFormat.Get();
319+
if (ImGui.Combo("Date Format", ref dateFormat, DateFormats, DateFormats.Length)) {
320+
config.DateFormat.Set(dateFormat);
321+
}
322+
ShowSetting(config.ClockFormat, "12-hour Clock", "Switch the time format from 24-hour to 12-hour clock.");
316323
}
317324
private static void ShowDisplayThemeTab()
318325
{

ContentEditor.Core/Data/Bundle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class Bundle
6969

7070
public void Touch()
7171
{
72-
UpdatedAt = DateTime.UtcNow.ToString("yyyy/MM/dd hh:mm:ss tt");
72+
UpdatedAt = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss \\U\\T\\C");
7373
UpdatedAtTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
7474
if (CreatedAt == null) CreatedAt = UpdatedAt;
7575
_nativeToLocalResourcePathCache = null;

0 commit comments

Comments
 (0)