Use filterable combo in special collections selector.

This commit is contained in:
Ottermandias 2022-09-28 16:37:32 +02:00
parent 1d6d696cb7
commit bb06c27359
3 changed files with 54 additions and 33 deletions

@ -1 +1 @@
Subproject commit c84ff1b1c313c5f4ae28645a2e3fcb4d214f240a Subproject commit 51d7cc6247240f3b76db00d48a8004eeb0ef32cb

View file

@ -292,23 +292,28 @@ public partial class ModCollection
public static void MigrateUngenderedCollections() public static void MigrateUngenderedCollections()
{ {
if( !ReadActiveCollections( out var jObject ) ) if( !ReadActiveCollections( out var jObject ) )
{
return; return;
}
foreach( var (type, _, _) in CollectionTypeExtensions.Special.Where( t => t.Item2.StartsWith( "Male " ) ) ) foreach( var (type, _, _) in CollectionTypeExtensions.Special.Where( t => t.Item2.StartsWith( "Male " ) ) )
{ {
var oldName = type.ToString()[ 5.. ]; var oldName = type.ToString()[ 4.. ];
var value = jObject[oldName]; var value = jObject[ oldName ];
if( value == null ) if( value == null )
{
continue; continue;
}
jObject.Remove( oldName ); jObject.Remove( oldName );
jObject.Add( "Male" + oldName, value ); jObject.Add( "Male" + oldName, value );
jObject.Add( "Female" + oldName, value ); jObject.Add( "Female" + oldName, value );
} }
using var stream = File.Open( ActiveCollectionFile, FileMode.Truncate ); using var stream = File.Open( ActiveCollectionFile, FileMode.Truncate );
using var writer = new StreamWriter( stream ); using var writer = new StreamWriter( stream );
using var j = new JsonTextWriter( writer ); using var j = new JsonTextWriter( writer );
j.Formatting = Formatting.Indented;
jObject.WriteTo( j ); jObject.WriteTo( j );
} }

View file

@ -1,3 +1,4 @@
using System;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using Dalamud.Interface; using Dalamud.Interface;
@ -5,6 +6,7 @@ using Dalamud.Interface.Components;
using ImGuiNET; using ImGuiNET;
using OtterGui; using OtterGui;
using OtterGui.Raii; using OtterGui.Raii;
using OtterGui.Widgets;
using Penumbra.Collections; using Penumbra.Collections;
namespace Penumbra.UI; namespace Penumbra.UI;
@ -38,10 +40,9 @@ public partial class ConfigWindow
// Input text fields. // Input text fields.
private string _newCollectionName = string.Empty; private string _newCollectionName = string.Empty;
private bool _canAddCollection = false; private bool _canAddCollection = false;
private string _newCharacterName = string.Empty; private string _newCharacterName = string.Empty;
private (CollectionType, string, string)? _currentType = CollectionTypeExtensions.Special.First();
// Create a new collection that is either empty or a duplicate of the current collection. // Create a new collection that is either empty or a duplicate of the current collection.
// Resets the new collection name. // Resets the new collection name.
@ -142,6 +143,34 @@ public partial class ConfigWindow
$"Mods in the {InterfaceCollection} are loaded for any file that the game categorizes as an UI file. This is mostly icons as well as the tiles that generate the user interface windows themselves." ); $"Mods in the {InterfaceCollection} are loaded for any file that the game categorizes as an UI file. This is mostly icons as well as the tiles that generate the user interface windows themselves." );
} }
private sealed class SpecialCombo : FilteredCombo< (CollectionType, string, string) >
{
public (CollectionType, string, string)? CurrentType
=> CollectionTypeExtensions.Special[ CurrentIdx ];
public int CurrentIdx = 0;
public SpecialCombo( string label, float unscaledWidth )
: base( label, unscaledWidth, CollectionTypeExtensions.Special )
{ }
public void Draw()
=> Draw( CurrentIdx );
protected override void Select( int globalIdx )
{
CurrentIdx = globalIdx;
}
protected override string ToString( (CollectionType, string, string) obj )
=> obj.Item2;
protected override bool IsVisible( (CollectionType, string, string) obj )
=> Filter.IsContained( obj.Item2 ) && Penumbra.CollectionManager.ByType( obj.Item1 ) == null;
}
private readonly SpecialCombo _specialCollectionCombo = new("##NewSpecial", 350);
// We do not check for valid character names. // We do not check for valid character names.
private void DrawNewSpecialCollection() private void DrawNewSpecialCollection()
{ {
@ -150,43 +179,29 @@ public partial class ConfigWindow
+ $"but all {IndividualAssignments} take precedence before them."; + $"but all {IndividualAssignments} take precedence before them.";
ImGui.SetNextItemWidth( _window._inputTextWidth.X ); ImGui.SetNextItemWidth( _window._inputTextWidth.X );
if( _currentType == null || Penumbra.CollectionManager.ByType( _currentType.Value.Item1 ) != null ) if( _specialCollectionCombo.CurrentIdx == -1
|| Penumbra.CollectionManager.ByType( _specialCollectionCombo.CurrentType!.Value.Item1 ) != null )
{ {
_currentType = CollectionTypeExtensions.Special.FindFirst( t => Penumbra.CollectionManager.ByType( t.Item1 ) == null, _specialCollectionCombo.ResetFilter();
out var t2 ) _specialCollectionCombo.CurrentIdx = CollectionTypeExtensions.Special
? t2 .IndexOf( t => Penumbra.CollectionManager.ByType( t.Item1 ) == null );
: null;
} }
if( _currentType == null ) if( _specialCollectionCombo.CurrentType == null )
{ {
return; return;
} }
using( var combo = ImRaii.Combo( "##NewSpecial", _currentType.Value.Item2 ) ) _specialCollectionCombo.Draw();
{
if( combo )
{
foreach( var type in CollectionTypeExtensions.Special.Where( t => Penumbra.CollectionManager.ByType( t.Item1 ) == null ) )
{
if( ImGui.Selectable( type.Item2, type.Item1 == _currentType.Value.Item1 ) )
{
_currentType = type;
}
ImGuiUtil.HoverTooltip( type.Item3 );
}
}
}
ImGui.SameLine(); ImGui.SameLine();
var disabled = _currentType == null; var disabled = _specialCollectionCombo.CurrentType == null;
var tt = disabled var tt = disabled
? $"Please select a condition for a {GroupAssignment} before creating the collection.\n\n" + description ? $"Please select a condition for a {GroupAssignment} before creating the collection.\n\n" + description
: description; : description;
if( ImGuiUtil.DrawDisabledButton( $"Assign {ConditionalGroup}", new Vector2( 120 * ImGuiHelpers.GlobalScale, 0 ), tt, disabled ) ) if( ImGuiUtil.DrawDisabledButton( $"Assign {ConditionalGroup}", new Vector2( 120 * ImGuiHelpers.GlobalScale, 0 ), tt, disabled ) )
{ {
Penumbra.CollectionManager.CreateSpecialCollection( _currentType!.Value.Item1 ); Penumbra.CollectionManager.CreateSpecialCollection( _specialCollectionCombo.CurrentType!.Value.Item1 );
_currentType = null; _specialCollectionCombo.CurrentIdx = -1;
} }
} }
@ -226,6 +241,7 @@ public partial class ConfigWindow
false, true ) ) false, true ) )
{ {
Penumbra.CollectionManager.RemoveSpecialCollection( type ); Penumbra.CollectionManager.RemoveSpecialCollection( type );
_specialCollectionCombo.ResetFilter();
} }
ImGui.SameLine(); ImGui.SameLine();