1+ using System ;
12using System . Collections . Generic ;
23using System . IO ;
4+ using System . Linq ;
35using System . Numerics ;
46using Dalamud . Interface ;
57using ImGuiNET ;
68using Lumina . Data . Files ;
79using OtterGui ;
810using OtterGui . Raii ;
11+ using OtterGui . Widgets ;
912using OtterTex ;
13+ using Penumbra . Mods ;
1014using Penumbra . String . Classes ;
1115using Penumbra . UI ;
1216using Penumbra . UI . Classes ;
@@ -33,41 +37,6 @@ public static void Draw(Texture texture, Vector2 size)
3337 }
3438 }
3539
36- public static void PathSelectBox ( TextureManager textures , Texture current , string label , string tooltip , IEnumerable < ( string , bool ) > paths ,
37- int skipPrefix )
38- {
39- ImGui . SetNextItemWidth ( - 0.0001f ) ;
40- var startPath = current . Path . Length > 0 ? current . Path : "Choose a modded texture from this mod here..." ;
41- using var combo = ImRaii . Combo ( label , startPath ) ;
42- if ( combo )
43- foreach ( var ( ( path , game ) , idx ) in paths . WithIndex ( ) )
44- {
45- if ( game )
46- {
47- if ( ! textures . GameFileExists ( path ) )
48- continue ;
49- }
50- else if ( ! File . Exists ( path ) )
51- {
52- continue ;
53- }
54-
55- using var id = ImRaii . PushId ( idx ) ;
56- using ( var color = ImRaii . PushColor ( ImGuiCol . Text , ColorId . FolderExpanded . Value ( ) , game ) )
57- {
58- var p = game ? $ "--> { path } " : path [ skipPrefix ..] ;
59- if ( ImGui . Selectable ( p , path == startPath ) && path != startPath )
60- current . Load ( textures , path ) ;
61- }
62-
63- ImGuiUtil . HoverTooltip ( game
64- ? "This is a game path and refers to an unmanipulated file from your game data."
65- : "This is a path to a modded file on your file system." ) ;
66- }
67-
68- ImGuiUtil . HoverTooltip ( tooltip ) ;
69- }
70-
7140 public static void PathInputBox ( TextureManager textures , Texture current , ref string ? tmpPath , string label , string hint , string tooltip ,
7241 string startPath , FileDialogService fileDialog , string defaultModImportPath )
7342 {
@@ -136,4 +105,53 @@ private static void DrawData(Texture texture)
136105 break ;
137106 }
138107 }
108+
109+ public sealed class PathSelectCombo : FilterComboCache < ( string , bool ) >
110+ {
111+ private int _skipPrefix = 0 ;
112+
113+ public PathSelectCombo ( TextureManager textures , ModEditor editor )
114+ : base ( ( ) => CreateFiles ( textures , editor ) )
115+ { }
116+
117+ protected override string ToString ( ( string , bool ) obj )
118+ => obj . Item1 ;
119+
120+ protected override bool DrawSelectable ( int globalIdx , bool selected )
121+ {
122+ var ( path , game ) = Items [ globalIdx ] ;
123+ bool ret ;
124+ using ( var color = ImRaii . PushColor ( ImGuiCol . Text , ColorId . FolderExpanded . Value ( ) , game ) )
125+ {
126+ var equals = string . Equals ( CurrentSelection . Item1 , path , StringComparison . OrdinalIgnoreCase ) ;
127+ var p = game ? $ "--> { path } " : path [ _skipPrefix ..] ;
128+ ret = ImGui . Selectable ( p , selected ) && ! equals ;
129+ }
130+
131+ ImGuiUtil . HoverTooltip ( game
132+ ? "This is a game path and refers to an unmanipulated file from your game data."
133+ : "This is a path to a modded file on your file system." ) ;
134+ return ret ;
135+ }
136+
137+ private static IReadOnlyList < ( string , bool ) > CreateFiles ( TextureManager textures , ModEditor editor )
138+ => editor . Files . Tex . SelectMany ( f => f . SubModUsage . Select ( p => ( p . Item2 . ToString ( ) , true ) )
139+ . Prepend ( ( f . File . FullName , false ) ) )
140+ . Where ( p => p . Item2 ? textures . GameFileExists ( p . Item1 ) : File . Exists ( p . Item1 ) )
141+ . ToList ( ) ;
142+
143+ public bool Draw ( string label , string tooltip , string current , int skipPrefix , out string newPath )
144+ {
145+ _skipPrefix = skipPrefix ;
146+ var startPath = current . Length > 0 ? current : "Choose a modded texture from this mod here..." ;
147+ if ( ! Draw ( label , startPath , tooltip , - 0.0001f , ImGui . GetTextLineHeightWithSpacing ( ) ) )
148+ {
149+ newPath = current ;
150+ return false ;
151+ }
152+
153+ newPath = CurrentSelection . Item1 ;
154+ return true ;
155+ }
156+ }
139157}
0 commit comments