Fix crashing when no collection is active and entering Effective Changes tab, as well as display Forced collection items in addition to active in that tab.

This commit is contained in:
Ottermandias 2021-07-31 12:54:09 +02:00
parent ac468852c7
commit 0a1e811cc6

View file

@ -52,16 +52,24 @@ namespace Penumbra.UI
public void Draw() public void Draw()
{ {
var ret = ImGui.BeginTabItem( LabelTab ); if( !ImGui.BeginTabItem( LabelTab ) )
if( !ret )
{ {
return; return;
} }
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 lines = activeCollection.ResolvedFiles.Count + activeCollection.MetaManipulations.Count; var forcedCollection = _modManager.Collections.ForcedCollection.Cache;
var (activeResolved, activeMeta) = activeCollection != null
? ( activeCollection.ResolvedFiles.Count, activeCollection.MetaManipulations.Count )
: ( 0, 0 );
var (forcedResolved, forcedMeta) = forcedCollection != null
? (forcedCollection.ResolvedFiles.Count, forcedCollection.MetaManipulations.Count)
: (0, 0);
var lines = activeResolved + forcedResolved + activeMeta + forcedMeta;
ImGuiListClipperPtr clipper; ImGuiListClipperPtr clipper;
unsafe unsafe
{ {
@ -75,18 +83,29 @@ namespace Penumbra.UI
ImGui.TableSetupColumn( "##tableGamePathCol", ImGuiTableColumnFlags.None, _leftTextLength ); ImGui.TableSetupColumn( "##tableGamePathCol", ImGuiTableColumnFlags.None, _leftTextLength );
while( clipper.Step() ) while( clipper.Step() )
{ {
for( var row = clipper.DisplayStart; row < clipper.DisplayEnd; row++ ) for( var actualRow = clipper.DisplayStart; actualRow < clipper.DisplayEnd; actualRow++ )
{ {
var row = actualRow;
ImGui.TableNextRow(); ImGui.TableNextRow();
if( row < activeCollection.ResolvedFiles.Count ) if( row < activeResolved )
{ {
var file = activeCollection.ResolvedFiles.ElementAt( row ); var file = activeCollection!.ResolvedFiles.ElementAt( row );
DrawFileLine( file.Value, file.Key ); DrawFileLine( file.Value, file.Key );
} }
else if( ( row -= activeResolved ) < forcedResolved )
{
var file = forcedCollection!.ResolvedFiles.ElementAt( row );
DrawFileLine( file.Value, file.Key );
}
else if( ( row -= forcedResolved ) < activeMeta )
{
var manip = activeCollection!.MetaManipulations.Manipulations.ElementAt( row );
DrawManipulationLine( manip.Item1, manip.Item2 );
}
else else
{ {
var manip = activeCollection.MetaManipulations.Manipulations.ElementAt( row -= activeMeta;
row - activeCollection.ResolvedFiles.Count ); var manip = forcedCollection!.MetaManipulations.Manipulations.ElementAt( row );
DrawManipulationLine( manip.Item1, manip.Item2 ); DrawManipulationLine( manip.Item1, manip.Item2 );
} }
} }