Add file selection combo to textures.

This commit is contained in:
Ottermandias 2022-09-17 00:48:38 +02:00
parent 19e5e94c64
commit 01c360416f
3 changed files with 32 additions and 5 deletions

View file

@ -5,7 +5,6 @@ using System.Numerics;
using Dalamud.Interface;
using Dalamud.Interface.ImGuiFileDialog;
using Dalamud.Utility;
using FFXIVClientStructs.FFXIV.Component.GUI;
using ImGuiNET;
using ImGuiScene;
using Lumina.Data.Files;
@ -19,7 +18,7 @@ using Image = SixLabors.ImageSharp.Image;
namespace Penumbra.Import.Textures;
public class Texture : IDisposable
public sealed class Texture : IDisposable
{
public enum FileType
{
@ -193,10 +192,29 @@ public class Texture : IDisposable
private string? _tmpPath;
public void PathSelectBox( string label, string tooltip, IEnumerable<string> paths )
{
ImGui.SetNextItemWidth( -0.0001f );
var startPath = Path.Length > 0 ? Path : "Choose a modded texture here...";
using var combo = ImRaii.Combo( label, startPath );
if( combo )
{
foreach( var (path, idx) in paths.WithIndex() )
{
using var id = ImRaii.PushId( idx );
if( ImGui.Selectable( path, path == startPath ) && path != startPath )
{
Load( path );
}
}
}
ImGuiUtil.HoverTooltip( tooltip );
}
public void PathInputBox( string label, string hint, string tooltip, string startPath, FileDialogManager manager )
{
_tmpPath ??= Path;
using var spacing = ImRaii.PushStyle( ImGuiStyleVar.ItemSpacing, new Vector2( 3 * ImGuiHelpers.GlobalScale, 0 ) );
using var spacing = ImRaii.PushStyle( ImGuiStyleVar.ItemSpacing, new Vector2( 3 * ImGuiHelpers.GlobalScale, ImGui.GetStyle().ItemSpacing.Y ) );
ImGui.SetNextItemWidth( -ImGui.GetFrameHeight() - 3 * ImGuiHelpers.GlobalScale );
ImGui.InputTextWithHint( label, hint, ref _tmpPath, Utf8GamePath.MaxGamePathLength );
if( ImGui.IsItemDeactivatedAfterEdit() )

View file

@ -40,7 +40,7 @@ public partial class Mod
public bool Equals( FileRegistry? other )
{
if( ReferenceEquals( null, other ) )
if( other is null )
{
return false;
}
@ -50,7 +50,7 @@ public partial class Mod
public override bool Equals( object? obj )
{
if( ReferenceEquals( null, obj ) )
if( obj is null )
{
return false;
}
@ -75,6 +75,7 @@ public partial class Mod
private List< FileRegistry > _availableFiles = null!;
private List< FileRegistry > _mtrlFiles = null!;
private List< FileRegistry > _mdlFiles = null!;
private List<FileRegistry> _texFiles = null!;
private readonly HashSet< Utf8GamePath > _usedPaths = new();
// All paths that are used in
@ -89,6 +90,9 @@ public partial class Mod
public IReadOnlyList< FileRegistry > MdlFiles
=> _mdlFiles;
public IReadOnlyList<FileRegistry> TexFiles
=> _texFiles;
// Remove all path redirections where the pointed-to file does not exist.
public void RemoveMissingPaths()
{
@ -130,6 +134,7 @@ public partial class Mod
_usedPaths.Clear();
_mtrlFiles = _availableFiles.Where( f => f.File.FullName.EndsWith( ".mtrl", StringComparison.OrdinalIgnoreCase ) ).ToList();
_mdlFiles = _availableFiles.Where( f => f.File.FullName.EndsWith( ".mdl", StringComparison.OrdinalIgnoreCase ) ).ToList();
_texFiles = _availableFiles.Where( f => f.File.FullName.EndsWith( ".tex", StringComparison.OrdinalIgnoreCase ) ).ToList();
FileChanges = false;
foreach( var subMod in _mod.AllSubMods )
{

View file

@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using Dalamud.Interface.ImGuiFileDialog;
using ImGuiNET;
@ -34,6 +35,9 @@ 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() ) ) );
tex.PathSelectBox( "##combo", "Select the textures included in this mod on your drive or the ones they replace from the game files.", files);
if( tex == _left )
{