Fix stupid file existence check, improve texture file selector.

This commit is contained in:
Ottermandias 2022-09-23 18:01:49 +02:00
parent 5c81970558
commit cadaafb887
2 changed files with 37 additions and 14 deletions

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Numerics; using System.Numerics;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.ImGuiFileDialog; using Dalamud.Interface.ImGuiFileDialog;
@ -130,17 +131,19 @@ public sealed class Texture : IDisposable
Path = path; Path = path;
Clean(); Clean();
if( path.Length == 0 )
{
return;
}
try try
{ {
if( !File.Exists( path ) )
throw new FileNotFoundException();
var _ = System.IO.Path.GetExtension( Path ) switch var _ = System.IO.Path.GetExtension( Path ) switch
{ {
".dds" => LoadDds(), ".dds" => LoadDds(),
".png" => LoadPng(), ".png" => LoadPng(),
".tex" => LoadTex(), ".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 ); Loaded?.Invoke( true );
} }
@ -202,20 +205,40 @@ public sealed class Texture : IDisposable
private string? _tmpPath; 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 ); 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 ); using var combo = ImRaii.Combo( label, startPath );
if( combo ) if( combo )
{ {
foreach( var (path, idx) in paths.WithIndex() ) foreach( var ((path, game), idx) in paths.WithIndex() )
{ {
using var id = ImRaii.PushId( idx ); if( game )
if( ImGui.Selectable( path, path == startPath ) && path != startPath )
{ {
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." );
} }
} }

View file

@ -21,7 +21,7 @@ public partial class ModEditWindow
private readonly FileDialogManager _dialogManager = ConfigWindow.SetupFileManager(); private readonly FileDialogManager _dialogManager = ConfigWindow.SetupFileManager();
private bool _overlayCollapsed = true; private bool _overlayCollapsed = true;
private bool _addMipMaps = true; private bool _addMipMaps = true;
private int _currentSaveAs = 0; private int _currentSaveAs = 0;
private static readonly (string, string)[] SaveAsStrings = 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, tex.PathInputBox( "##input", "Import Image...", "Can import game paths as well as your own files.", _mod!.ModPath.FullName,
_dialogManager ); _dialogManager );
var files = _editor!.TexFiles.Select( f => f.File.FullName ) var files = _editor!.TexFiles.SelectMany( f => f.SubModUsage.Select( p => (p.Item2.ToString(), true) )
.Concat( _editor.TexFiles.SelectMany( f => f.SubModUsage.Select( p => p.Item2.ToString() ) ) ); .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.", 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 ) if( tex == _left )
{ {