15
15
16
16
namespace Penumbra . UI . ModsTab . Groups ;
17
17
18
- public sealed class ModGroupDrawer ( Configuration config , CollectionManager collectionManager ) : IUiService
18
+ public sealed class ModGroupDrawer : IUiService
19
19
{
20
20
private readonly List < ( IModGroup , int ) > _blockGroupCache = [ ] ;
21
21
private bool _temporary ;
22
22
private bool _locked ;
23
23
private TemporaryModSettings ? _tempSettings ;
24
24
private ModSettings ? _settings ;
25
+ private readonly SingleGroupCombo _combo ;
26
+ private readonly Configuration _config ;
27
+ private readonly CollectionManager _collectionManager ;
28
+
29
+ public ModGroupDrawer ( Configuration config , CollectionManager collectionManager )
30
+ {
31
+ _config = config ;
32
+ _collectionManager = collectionManager ;
33
+ _combo = new SingleGroupCombo ( this ) ;
34
+ }
35
+
36
+ private sealed class SingleGroupCombo ( ModGroupDrawer parent )
37
+ : FilterComboCache < IModOption > ( ( ) => _group ! . Options , MouseWheelType . Control , Penumbra . Log )
38
+ {
39
+ private static IModGroup ? _group ;
40
+ private static int _groupIdx ;
41
+
42
+ protected override bool DrawSelectable ( int globalIdx , bool selected )
43
+ {
44
+ var option = _group ! . Options [ globalIdx ] ;
45
+ var ret = ImUtf8 . Selectable ( option . Name , globalIdx == CurrentSelectionIdx ) ;
46
+
47
+ if ( option . Description . Length > 0 )
48
+ ImUtf8 . SelectableHelpMarker ( option . Description ) ;
49
+
50
+ return ret ;
51
+ }
52
+
53
+ protected override string ToString ( IModOption obj )
54
+ => obj . Name ;
55
+
56
+ public void Draw ( IModGroup group , int groupIndex , int currentOption )
57
+ {
58
+ _group = group ;
59
+ _groupIdx = groupIndex ;
60
+ CurrentSelectionIdx = currentOption ;
61
+ CurrentSelection = _group . Options [ CurrentSelectionIdx ] ;
62
+ if ( Draw ( string . Empty , CurrentSelection . Name , string . Empty , ref CurrentSelectionIdx , UiHelpers . InputTextWidth . X * 3 / 4 ,
63
+ ImGui . GetTextLineHeightWithSpacing ( ) ) )
64
+ parent . SetModSetting ( _group , _groupIdx , Setting . Single ( CurrentSelectionIdx ) ) ;
65
+ }
66
+ }
25
67
26
68
public void Draw ( Mod mod , ModSettings settings , TemporaryModSettings ? tempSettings )
27
69
{
@@ -41,7 +83,7 @@ public void Draw(Mod mod, ModSettings settings, TemporaryModSettings? tempSettin
41
83
42
84
switch ( group . Behaviour )
43
85
{
44
- case GroupDrawBehaviour . SingleSelection when group . Options . Count <= config . SingleGroupRadioMax :
86
+ case GroupDrawBehaviour . SingleSelection when group . Options . Count <= _config . SingleGroupRadioMax :
45
87
case GroupDrawBehaviour . MultiSelection :
46
88
_blockGroupCache . Add ( ( group , idx ) ) ;
47
89
break ;
@@ -76,25 +118,7 @@ private void DrawSingleGroupCombo(IModGroup group, int groupIdx, Setting setting
76
118
using var id = ImUtf8 . PushId ( groupIdx ) ;
77
119
var selectedOption = setting . AsIndex ;
78
120
using var disabled = ImRaii . Disabled ( _locked ) ;
79
- ImGui . SetNextItemWidth ( UiHelpers . InputTextWidth . X * 3 / 4 ) ;
80
- var options = group . Options ;
81
- using ( var combo = ImUtf8 . Combo ( ""u8 , options [ selectedOption ] . Name ) )
82
- {
83
- if ( combo )
84
- for ( var idx2 = 0 ; idx2 < options . Count ; ++ idx2 )
85
- {
86
- id . Push ( idx2 ) ;
87
- var option = options [ idx2 ] ;
88
- if ( ImUtf8 . Selectable ( option . Name , idx2 == selectedOption ) )
89
- SetModSetting ( group , groupIdx , Setting . Single ( idx2 ) ) ;
90
-
91
- if ( option . Description . Length > 0 )
92
- ImUtf8 . SelectableHelpMarker ( option . Description ) ;
93
-
94
- id . Pop ( ) ;
95
- }
96
- }
97
-
121
+ _combo . Draw ( group , groupIdx , selectedOption ) ;
98
122
ImGui . SameLine ( ) ;
99
123
if ( group . Description . Length > 0 )
100
124
ImUtf8 . LabeledHelpMarker ( group . Name , group . Description ) ;
@@ -195,7 +219,7 @@ private void DrawMultiPopup(IModGroup group, int groupIdx, string label)
195
219
196
220
private void DrawCollapseHandling ( IReadOnlyList < IModOption > options , float minWidth , Action draw )
197
221
{
198
- if ( options . Count <= config . OptionGroupCollapsibleMin )
222
+ if ( options . Count <= _config . OptionGroupCollapsibleMin )
199
223
{
200
224
draw ( ) ;
201
225
}
@@ -240,21 +264,21 @@ private void DrawCollapseHandling(IReadOnlyList<IModOption> options, float minWi
240
264
}
241
265
242
266
private ModCollection Current
243
- => collectionManager . Active . Current ;
267
+ => _collectionManager . Active . Current ;
244
268
245
269
[ MethodImpl ( MethodImplOptions . AggressiveInlining | MethodImplOptions . AggressiveOptimization ) ]
246
270
private void SetModSetting ( IModGroup group , int groupIdx , Setting setting )
247
271
{
248
- if ( _temporary || config . DefaultTemporaryMode )
272
+ if ( _temporary || _config . DefaultTemporaryMode )
249
273
{
250
274
_tempSettings ??= new TemporaryModSettings ( group . Mod , _settings ) ;
251
275
_tempSettings ! . ForceInherit = false ;
252
276
_tempSettings ! . Settings [ groupIdx ] = setting ;
253
- collectionManager . Editor . SetTemporarySettings ( Current , group . Mod , _tempSettings ) ;
277
+ _collectionManager . Editor . SetTemporarySettings ( Current , group . Mod , _tempSettings ) ;
254
278
}
255
279
else
256
280
{
257
- collectionManager . Editor . SetModSetting ( Current , group . Mod , groupIdx , setting ) ;
281
+ _collectionManager . Editor . SetModSetting ( Current , group . Mod , groupIdx , setting ) ;
258
282
}
259
283
}
260
284
}
0 commit comments