diff --git a/Penumbra/Import/Textures/Texture.cs b/Penumbra/Import/Textures/Texture.cs index c55f4df1..a3ca306c 100644 --- a/Penumbra/Import/Textures/Texture.cs +++ b/Penumbra/Import/Textures/Texture.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Numerics; using Dalamud.Interface; using Dalamud.Interface.ImGuiFileDialog; @@ -130,17 +131,19 @@ public sealed class Texture : IDisposable Path = path; Clean(); + if( path.Length == 0 ) + { + return; + } + try { - if( !File.Exists( path ) ) - throw new FileNotFoundException(); - var _ = System.IO.Path.GetExtension( Path ) switch { ".dds" => LoadDds(), ".png" => LoadPng(), ".tex" => LoadTex(), - _ => throw new Exception($"Extension {System.IO.Path.GetExtension( Path )} unknown."), + _ => throw new Exception( $"Extension {System.IO.Path.GetExtension( Path )} unknown." ), }; Loaded?.Invoke( true ); } @@ -202,20 +205,40 @@ public sealed class Texture : IDisposable private string? _tmpPath; - public void PathSelectBox( string label, string tooltip, IEnumerable< string > paths ) + public void PathSelectBox( string label, string tooltip, IEnumerable< (string, bool) > paths, int skipPrefix ) { ImGui.SetNextItemWidth( -0.0001f ); - var startPath = Path.Length > 0 ? Path : "Choose a modded texture here..."; + var startPath = Path.Length > 0 ? Path : "Choose a modded texture from this mod here..."; using var combo = ImRaii.Combo( label, startPath ); if( combo ) { - foreach( var (path, idx) in paths.WithIndex() ) + foreach( var ((path, game), idx) in paths.WithIndex() ) { - using var id = ImRaii.PushId( idx ); - if( ImGui.Selectable( path, path == startPath ) && path != startPath ) + if( game ) { - Load( path ); + if( !Dalamud.GameData.FileExists( path ) ) + { + continue; + } } + else if( !File.Exists( path ) ) + { + continue; + } + + using var id = ImRaii.PushId( idx ); + using( var color = ImRaii.PushColor( ImGuiCol.Text, ColorId.FolderExpanded.Value(), game ) ) + { + var p = game ? $"--> {path}" : path[ skipPrefix.. ]; + if( ImGui.Selectable( p, path == startPath ) && path != startPath ) + { + Load( path ); + } + } + + ImGuiUtil.HoverTooltip( game + ? "This is a game path and refers to an unmanipulated file from your game data." + : "This is a path to a modded file on your file system." ); } } diff --git a/Penumbra/UI/Classes/ModEditWindow.Textures.cs b/Penumbra/UI/Classes/ModEditWindow.Textures.cs index 43307773..7d244dd6 100644 --- a/Penumbra/UI/Classes/ModEditWindow.Textures.cs +++ b/Penumbra/UI/Classes/ModEditWindow.Textures.cs @@ -21,7 +21,7 @@ public partial class ModEditWindow private readonly FileDialogManager _dialogManager = ConfigWindow.SetupFileManager(); private bool _overlayCollapsed = true; - private bool _addMipMaps = true; + private bool _addMipMaps = true; private int _currentSaveAs = 0; private static readonly (string, string)[] SaveAsStrings = @@ -49,10 +49,10 @@ public partial class ModEditWindow tex.PathInputBox( "##input", "Import Image...", "Can import game paths as well as your own files.", _mod!.ModPath.FullName, _dialogManager ); - var files = _editor!.TexFiles.Select( f => f.File.FullName ) - .Concat( _editor.TexFiles.SelectMany( f => f.SubModUsage.Select( p => p.Item2.ToString() ) ) ); + var files = _editor!.TexFiles.SelectMany( f => f.SubModUsage.Select( p => (p.Item2.ToString(), true) ) + .Prepend( (f.File.FullName, false ))); tex.PathSelectBox( "##combo", "Select the textures included in this mod on your drive or the ones they replace from the game files.", - files ); + files, _mod.ModPath.FullName.Length + 1 ); if( tex == _left ) {