mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Add filters to the effective files tab.
This commit is contained in:
parent
0c0eeec158
commit
572f4f5e6b
1 changed files with 156 additions and 49 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Dalamud.Interface;
|
using Dalamud.Interface;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using Penumbra.GameData.Util;
|
using Penumbra.GameData.Util;
|
||||||
using Penumbra.Meta;
|
|
||||||
using Penumbra.Mods;
|
using Penumbra.Mods;
|
||||||
using Penumbra.UI.Custom;
|
using Penumbra.UI.Custom;
|
||||||
using Penumbra.Util;
|
using Penumbra.Util;
|
||||||
|
|
@ -17,14 +17,21 @@ namespace Penumbra.UI
|
||||||
private const string LabelTab = "Effective Changes";
|
private const string LabelTab = "Effective Changes";
|
||||||
private readonly ModManager _modManager;
|
private readonly ModManager _modManager;
|
||||||
|
|
||||||
|
private string _gamePathFilter = string.Empty;
|
||||||
|
private string _gamePathFilterLower = string.Empty;
|
||||||
|
private string _filePathFilter = string.Empty;
|
||||||
|
private string _filePathFilterLower = string.Empty;
|
||||||
|
|
||||||
private readonly float _leftTextLength =
|
private readonly float _leftTextLength =
|
||||||
ImGui.CalcTextSize( "chara/human/c0000/obj/body/b0000/material/v0000/mt_c0000b0000_b.mtrl" ).X + 40;
|
ImGui.CalcTextSize( "chara/human/c0000/obj/body/b0000/material/v0000/mt_c0000b0000_b.mtrl" ).X / ImGuiHelpers.GlobalScale + 40;
|
||||||
|
|
||||||
|
private float _arrowLength = 0;
|
||||||
|
|
||||||
public TabEffective()
|
public TabEffective()
|
||||||
=> _modManager = Service< ModManager >.Get();
|
=> _modManager = Service< ModManager >.Get();
|
||||||
|
|
||||||
|
|
||||||
private static void DrawFileLine( FileInfo file, GamePath path )
|
private static void DrawLine( string path, string name )
|
||||||
{
|
{
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
ImGuiCustom.CopyOnClickSelectable( path );
|
ImGuiCustom.CopyOnClickSelectable( path );
|
||||||
|
|
@ -32,18 +39,92 @@ namespace Penumbra.UI
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
ImGuiCustom.PrintIcon( FontAwesomeIcon.LongArrowAltLeft );
|
ImGuiCustom.PrintIcon( FontAwesomeIcon.LongArrowAltLeft );
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
ImGuiCustom.CopyOnClickSelectable( file.FullName );
|
ImGuiCustom.CopyOnClickSelectable( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DrawManipulationLine( MetaManipulation manip, Mod.Mod mod )
|
private void DrawFilters()
|
||||||
{
|
{
|
||||||
ImGui.TableNextColumn();
|
if( _arrowLength == 0 )
|
||||||
ImGui.Selectable( manip.IdentifierString() );
|
{
|
||||||
|
using var font = ImGuiRaii.PushFont( UiBuilder.IconFont );
|
||||||
|
_arrowLength = ImGui.CalcTextSize( FontAwesomeIcon.LongArrowAltLeft.ToIconString() ).X / ImGuiHelpers.GlobalScale;
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.TableNextColumn();
|
ImGui.SetNextItemWidth( _leftTextLength * ImGuiHelpers.GlobalScale );
|
||||||
ImGuiCustom.PrintIcon( FontAwesomeIcon.LongArrowAltLeft );
|
if( ImGui.InputTextWithHint( "##effective_changes_gfilter", "Filter game path...", ref _gamePathFilter, 256 ) )
|
||||||
ImGui.SameLine();
|
{
|
||||||
ImGui.Selectable( mod.Data.Meta.Name );
|
_gamePathFilterLower = _gamePathFilter.ToLowerInvariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.SameLine( ( _leftTextLength + _arrowLength ) * ImGuiHelpers.GlobalScale + 3 * ImGui.GetStyle().ItemSpacing.X );
|
||||||
|
ImGui.SetNextItemWidth( -1 );
|
||||||
|
if( ImGui.InputTextWithHint( "##effective_changes_ffilter", "Filter file path...", ref _filePathFilter, 256 ) )
|
||||||
|
{
|
||||||
|
_filePathFilterLower = _filePathFilter.ToLowerInvariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CheckFilters( KeyValuePair< GamePath, FileInfo > kvp )
|
||||||
|
{
|
||||||
|
if( _gamePathFilter.Any() && !kvp.Key.ToString().Contains( _gamePathFilterLower ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !_filePathFilter.Any() || kvp.Value.FullName.ToLowerInvariant().Contains( _filePathFilterLower );
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CheckFilters( KeyValuePair< GamePath, GamePath > kvp )
|
||||||
|
{
|
||||||
|
if( _gamePathFilter.Any() && !kvp.Key.ToString().Contains( _gamePathFilterLower ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !_filePathFilter.Any() || kvp.Value.ToString().Contains( _filePathFilterLower );
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CheckFilters( (string, string, string) kvp )
|
||||||
|
{
|
||||||
|
if( _gamePathFilter.Any() && !kvp.Item1.ToLowerInvariant().Contains( _gamePathFilterLower ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !_filePathFilter.Any() || kvp.Item3.Contains( _filePathFilterLower );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawFilteredRows( ModCollectionCache? active, ModCollectionCache? forced )
|
||||||
|
{
|
||||||
|
void DrawFileLines( ModCollectionCache cache )
|
||||||
|
{
|
||||||
|
foreach( var (gp, fp) in cache.ResolvedFiles.Where( CheckFilters ) )
|
||||||
|
{
|
||||||
|
DrawLine( gp, fp.FullName );
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach( var (gp, fp) in cache.SwappedFiles.Where( CheckFilters ) )
|
||||||
|
{
|
||||||
|
DrawLine( gp, fp );
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach( var (mp, mod, _) in cache.MetaManipulations.Manipulations
|
||||||
|
.Select( p => ( p.Item1.IdentifierString(), p.Item2.Data.Meta.Name, p.Item2.Data.Meta.LowerName ) )
|
||||||
|
.Where( CheckFilters ) )
|
||||||
|
{
|
||||||
|
DrawLine( mp, mod );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( active != null )
|
||||||
|
{
|
||||||
|
DrawFileLines( active );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( forced != null )
|
||||||
|
{
|
||||||
|
DrawFileLines( forced );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw()
|
public void Draw()
|
||||||
|
|
@ -55,31 +136,45 @@ namespace Penumbra.UI
|
||||||
|
|
||||||
using var raii = ImGuiRaii.DeferredEnd( ImGui.EndTabItem );
|
using var raii = ImGuiRaii.DeferredEnd( ImGui.EndTabItem );
|
||||||
|
|
||||||
|
DrawFilters();
|
||||||
|
|
||||||
const ImGuiTableFlags flags = ImGuiTableFlags.RowBg | ImGuiTableFlags.ScrollX;
|
const ImGuiTableFlags flags = ImGuiTableFlags.RowBg | ImGuiTableFlags.ScrollX;
|
||||||
|
|
||||||
var activeCollection = _modManager.Collections.ActiveCollection.Cache;
|
var activeCollection = _modManager.Collections.ActiveCollection.Cache;
|
||||||
var forcedCollection = _modManager.Collections.ForcedCollection.Cache;
|
var forcedCollection = _modManager.Collections.ForcedCollection.Cache;
|
||||||
|
|
||||||
var (activeResolved, activeMeta) = activeCollection != null
|
var (activeResolved, activeSwap, activeMeta) = activeCollection != null
|
||||||
? ( activeCollection.ResolvedFiles.Count, activeCollection.MetaManipulations.Count )
|
? ( activeCollection.ResolvedFiles.Count, activeCollection.SwappedFiles.Count, activeCollection.MetaManipulations.Count )
|
||||||
: ( 0, 0 );
|
: ( 0, 0, 0 );
|
||||||
var (forcedResolved, forcedMeta) = forcedCollection != null
|
var (forcedResolved, forcedSwap, forcedMeta) = forcedCollection != null
|
||||||
? ( forcedCollection.ResolvedFiles.Count, forcedCollection.MetaManipulations.Count )
|
? ( forcedCollection.ResolvedFiles.Count, forcedCollection.SwappedFiles.Count, forcedCollection.MetaManipulations.Count )
|
||||||
: ( 0, 0 );
|
: ( 0, 0, 0 );
|
||||||
|
var totalLines = activeResolved + forcedResolved + activeSwap + forcedSwap + activeMeta + forcedMeta;
|
||||||
|
if( totalLines == 0 )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var lines = activeResolved + forcedResolved + activeMeta + forcedMeta;
|
if( ImGui.BeginTable( "##effective_changes", 2, flags, AutoFillSize ) )
|
||||||
|
{
|
||||||
|
raii.Push( ImGui.EndTable );
|
||||||
|
ImGui.TableSetupColumn( "##tableGamePathCol", ImGuiTableColumnFlags.None, _leftTextLength * ImGuiHelpers.GlobalScale );
|
||||||
|
|
||||||
|
if( _filePathFilter.Any() || _gamePathFilter.Any() )
|
||||||
|
{
|
||||||
|
DrawFilteredRows( activeCollection, forcedCollection );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ImGuiListClipperPtr clipper;
|
ImGuiListClipperPtr clipper;
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
clipper = new ImGuiListClipperPtr( ImGuiNative.ImGuiListClipper_ImGuiListClipper() );
|
clipper = new ImGuiListClipperPtr( ImGuiNative.ImGuiListClipper_ImGuiListClipper() );
|
||||||
}
|
}
|
||||||
|
|
||||||
clipper.Begin( lines );
|
clipper.Begin( totalLines );
|
||||||
|
|
||||||
|
|
||||||
if( ImGui.BeginTable( "##effective_changes", 2, flags, AutoFillSize ) )
|
|
||||||
{
|
|
||||||
raii.Push( ImGui.EndTable );
|
|
||||||
ImGui.TableSetupColumn( "##tableGamePathCol", ImGuiTableColumnFlags.None, _leftTextLength );
|
|
||||||
while( clipper.Step() )
|
while( clipper.Step() )
|
||||||
{
|
{
|
||||||
for( var actualRow = clipper.DisplayStart; actualRow < clipper.DisplayEnd; actualRow++ )
|
for( var actualRow = clipper.DisplayStart; actualRow < clipper.DisplayEnd; actualRow++ )
|
||||||
|
|
@ -89,23 +184,34 @@ namespace Penumbra.UI
|
||||||
if( row < activeResolved )
|
if( row < activeResolved )
|
||||||
{
|
{
|
||||||
var (gamePath, file) = activeCollection!.ResolvedFiles.ElementAt( row );
|
var (gamePath, file) = activeCollection!.ResolvedFiles.ElementAt( row );
|
||||||
DrawFileLine( file, gamePath );
|
DrawLine( gamePath, file.FullName );
|
||||||
}
|
}
|
||||||
else if( ( row -= activeResolved ) < forcedResolved )
|
else if( ( row -= activeResolved ) < activeSwap )
|
||||||
{
|
{
|
||||||
var (gamePath, file) = forcedCollection!.ResolvedFiles.ElementAt( row );
|
var (gamePath, swap) = activeCollection!.SwappedFiles.ElementAt( row );
|
||||||
DrawFileLine( file, gamePath );
|
DrawLine( gamePath, swap );
|
||||||
}
|
}
|
||||||
else if( ( row -= forcedResolved ) < activeMeta )
|
else if( ( row -= activeSwap ) < activeMeta )
|
||||||
{
|
{
|
||||||
var (manip, mod) = activeCollection!.MetaManipulations.Manipulations.ElementAt( row );
|
var (manip, mod) = activeCollection!.MetaManipulations.Manipulations.ElementAt( row );
|
||||||
DrawManipulationLine( manip, mod );
|
DrawLine( manip.IdentifierString(), mod.Data.Meta.Name );
|
||||||
|
}
|
||||||
|
else if( ( row -= activeMeta ) < forcedResolved )
|
||||||
|
{
|
||||||
|
var (gamePath, file) = forcedCollection!.ResolvedFiles.ElementAt( row );
|
||||||
|
DrawLine( gamePath, file.FullName );
|
||||||
|
}
|
||||||
|
else if( ( row -= forcedResolved ) < forcedSwap )
|
||||||
|
{
|
||||||
|
var (gamePath, swap) = forcedCollection!.SwappedFiles.ElementAt( row );
|
||||||
|
DrawLine( gamePath, swap );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
row -= activeMeta;
|
row -= forcedSwap;
|
||||||
var (manip, mod) = forcedCollection!.MetaManipulations.Manipulations.ElementAt( row );
|
var (manip, mod) = forcedCollection!.MetaManipulations.Manipulations.ElementAt( row );
|
||||||
DrawManipulationLine( manip, mod );
|
DrawLine( manip.IdentifierString(), mod.Data.Meta.Name );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -114,3 +220,4 @@ namespace Penumbra.UI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue