From a36f9ccec7f4a1adf6e95c484da5a5a9ae9c2d3b Mon Sep 17 00:00:00 2001 From: Exter-N Date: Mon, 5 Aug 2024 03:45:02 +0200 Subject: [PATCH] Improve ResourceTree display with new function --- Penumbra/Interop/ResourceTree/ResourceNode.cs | 4 ++++ .../ResourceTree/ResourceTreeFactory.cs | 19 ++++++++++++++++++- .../UI/AdvancedWindow/ResourceTreeViewer.cs | 5 ++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Penumbra/Interop/ResourceTree/ResourceNode.cs b/Penumbra/Interop/ResourceTree/ResourceNode.cs index 6ab48325..85d12ce7 100644 --- a/Penumbra/Interop/ResourceTree/ResourceNode.cs +++ b/Penumbra/Interop/ResourceTree/ResourceNode.cs @@ -15,6 +15,8 @@ public class ResourceNode : ICloneable public readonly nint ResourceHandle; public Utf8GamePath[] PossibleGamePaths; public FullPath FullPath; + public string? ModName; + public string? ModRelativePath; public CiByteString AdditionalData; public readonly ulong Length; public readonly List Children; @@ -57,6 +59,8 @@ public class ResourceNode : ICloneable ResourceHandle = other.ResourceHandle; PossibleGamePaths = other.PossibleGamePaths; FullPath = other.FullPath; + ModName = other.ModName; + ModRelativePath = other.ModRelativePath; AdditionalData = other.AdditionalData; Length = other.Length; Children = other.Children; diff --git a/Penumbra/Interop/ResourceTree/ResourceTreeFactory.cs b/Penumbra/Interop/ResourceTree/ResourceTreeFactory.cs index 65fac68f..9738148f 100644 --- a/Penumbra/Interop/ResourceTree/ResourceTreeFactory.cs +++ b/Penumbra/Interop/ResourceTree/ResourceTreeFactory.cs @@ -9,6 +9,7 @@ using Penumbra.GameData.Enums; using Penumbra.GameData.Interop; using Penumbra.Interop.PathResolving; using Penumbra.Meta; +using Penumbra.Mods.Manager; using Penumbra.String.Classes; namespace Penumbra.Interop.ResourceTree; @@ -21,7 +22,8 @@ public class ResourceTreeFactory( ObjectIdentification objectIdentifier, Configuration config, ActorManager actors, - PathState pathState) : IService + PathState pathState, + ModManager modManager) : IService { private TreeBuildCache CreateTreeBuildCache() => new(objects, gameData, actors); @@ -93,7 +95,10 @@ public class ResourceTreeFactory( // This is currently unneeded as we can resolve all paths by querying the draw object: // ResolveGamePaths(tree, collectionResolveData.ModCollection); if (globalContext.WithUiData) + { ResolveUiData(tree); + ResolveModData(tree); + } FilterFullPaths(tree, (flags & Flags.RedactExternalPaths) != 0 ? config.ModDirectory : null); Cleanup(tree); @@ -123,6 +128,18 @@ public class ResourceTreeFactory( }); } + private void ResolveModData(ResourceTree tree) + { + foreach (var node in tree.FlatNodes) + { + if (node.FullPath.IsRooted && modManager.TryIdentifyPath(node.FullPath.FullName, out var mod, out var relativePath)) + { + node.ModName = mod.Name; + node.ModRelativePath = relativePath; + } + } + } + private static void FilterFullPaths(ResourceTree tree, string? onlyWithinPath) { foreach (var node in tree.FlatNodes) diff --git a/Penumbra/UI/AdvancedWindow/ResourceTreeViewer.cs b/Penumbra/UI/AdvancedWindow/ResourceTreeViewer.cs index a991c948..361094c4 100644 --- a/Penumbra/UI/AdvancedWindow/ResourceTreeViewer.cs +++ b/Penumbra/UI/AdvancedWindow/ResourceTreeViewer.cs @@ -316,7 +316,10 @@ public class ResourceTreeViewer ImGui.TableNextColumn(); if (resourceNode.FullPath.FullName.Length > 0) { - ImGui.Selectable(resourceNode.FullPath.ToPath(), false, 0, new Vector2(ImGui.GetContentRegionAvail().X, cellHeight)); + var uiFullPathStr = resourceNode.ModName != null && resourceNode.ModRelativePath != null + ? $"[{resourceNode.ModName}] {resourceNode.ModRelativePath}" + : resourceNode.FullPath.ToPath(); + ImGui.Selectable(uiFullPathStr, false, 0, new Vector2(ImGui.GetContentRegionAvail().X, cellHeight)); if (ImGui.IsItemClicked()) ImGui.SetClipboardText(resourceNode.FullPath.ToPath()); ImGuiUtil.HoverTooltip(