Skip to content

Commit

Permalink
Add display of ImportDate and allow resetting it, add button to open …
Browse files Browse the repository at this point in the history
…local data json.
  • Loading branch information
Ottermandias committed Sep 8, 2024
1 parent 22cbecc commit bd59591
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
11 changes: 11 additions & 0 deletions Penumbra/Mods/Manager/ModDataEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,17 @@ public void ChangeModFavorite(Mod mod, bool state)
communicatorService.ModDataChanged.Invoke(ModDataChangeType.Favorite, mod, null);
}

public void ResetModImportDate(Mod mod)
{
var newDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
if (mod.ImportDate == newDate)
return;

mod.ImportDate = newDate;
saveService.QueueSave(new ModLocalData(mod));
communicatorService.ModDataChanged.Invoke(ModDataChangeType.ImportDate, mod, null);
}

public void ChangeModNote(Mod mod, string newNote)
{
if (mod.Note == newNote)
Expand Down
2 changes: 1 addition & 1 deletion Penumbra/Mods/ModCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public bool ReloadMod(Mod mod, bool incorporateMetaChanges, bool deleteDefaultMe
if (modDataChange.HasFlag(ModDataChangeType.Deletion) || mod.Name.Length == 0)
return false;

dataEditor.LoadLocalData(mod);
modDataChange |= dataEditor.LoadLocalData(mod);
LoadDefaultOption(mod);
LoadAllGroups(mod);
if (incorporateMetaChanges)
Expand Down
19 changes: 9 additions & 10 deletions Penumbra/UI/ModsTab/ModFileSystemSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,16 +447,15 @@ private void OnSettingChange(ModCollection collection, ModSettingChange type, Mo

private void OnModDataChange(ModDataChangeType type, Mod mod, string? oldName)
{
switch (type)
{
case ModDataChangeType.Name:
case ModDataChangeType.Author:
case ModDataChangeType.ModTags:
case ModDataChangeType.LocalTags:
case ModDataChangeType.Favorite:
SetFilterDirty();
break;
}
const ModDataChangeType relevantFlags =
ModDataChangeType.Name
| ModDataChangeType.Author
| ModDataChangeType.ModTags
| ModDataChangeType.LocalTags
| ModDataChangeType.Favorite
| ModDataChangeType.ImportDate;
if ((type & relevantFlags) != 0)
SetFilterDirty();
}

private void OnInheritanceChange(ModCollection collection, bool _)
Expand Down
37 changes: 37 additions & 0 deletions Penumbra/UI/ModsTab/ModPanelEditTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using OtterGui.Widgets;
using OtterGui.Classes;
using OtterGui.Services;
using OtterGui.Text;
using Penumbra.Mods;
using Penumbra.Mods.Editor;
using Penumbra.Mods.Manager;
Expand Down Expand Up @@ -50,6 +51,8 @@ public void DrawContent()
EditButtons();
EditRegularMeta();
UiHelpers.DefaultLineSpace();
EditLocalData();
UiHelpers.DefaultLineSpace();

if (Input.Text("Mod Path", Input.Path, Input.None, _leaf.FullName(), out var newPath, 256, UiHelpers.InputTextWidth.X))
try
Expand Down Expand Up @@ -182,6 +185,40 @@ private void EditRegularMeta()
DrawOpenDefaultMod();
}

private void EditLocalData()
{
DrawImportDate();
DrawOpenLocalData();
}

private void DrawImportDate()
{
ImUtf8.TextFramed($"{DateTimeOffset.FromUnixTimeMilliseconds(_mod.ImportDate).ToLocalTime():yyyy/MM/dd HH:mm}",
ImGui.GetColorU32(ImGuiCol.FrameBg, 0.5f), new Vector2(UiHelpers.InputTextMinusButton3, 0));
ImGui.SameLine(0, 3 * ImUtf8.GlobalScale);

var canRefresh = config.DeleteModModifier.IsActive();
var tt = canRefresh
? "Reset the import date to the current date and time."
: $"Reset the import date to the current date and time.\nHold {config.DeleteModModifier} while clicking to refresh.";

if (ImUtf8.IconButton(FontAwesomeIcon.Sync, tt, disabled: !canRefresh))
modManager.DataEditor.ResetModImportDate(_mod);
ImUtf8.SameLineInner();
ImUtf8.Text("Import Date"u8);
}

private void DrawOpenLocalData()
{
var file = filenames.LocalDataFile(_mod);
var fileExists = File.Exists(file);
var tt = fileExists
? "Open the local mod data file in the text editor of your choice."u8
: "The local mod data file does not exist."u8;
if (ImUtf8.ButtonEx("Open Local Data"u8, tt, UiHelpers.InputTextWidth, !fileExists))
Process.Start(new ProcessStartInfo(file) { UseShellExecute = true });
}

private void DrawOpenDefaultMod()
{
var file = filenames.OptionGroupFile(_mod, -1, false);
Expand Down

0 comments on commit bd59591

Please sign in to comment.