From 0a1e811cc653ff3cb40807a4499c3e4db7d16353 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sat, 31 Jul 2021 12:54:09 +0200 Subject: [PATCH] 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. --- Penumbra/UI/MenuTabs/TabEffective.cs | 37 +++++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/Penumbra/UI/MenuTabs/TabEffective.cs b/Penumbra/UI/MenuTabs/TabEffective.cs index 117d0f95..70061097 100644 --- a/Penumbra/UI/MenuTabs/TabEffective.cs +++ b/Penumbra/UI/MenuTabs/TabEffective.cs @@ -52,16 +52,24 @@ namespace Penumbra.UI public void Draw() { - var ret = ImGui.BeginTabItem( LabelTab ); - if( !ret ) + if( !ImGui.BeginTabItem( LabelTab ) ) { return; } const ImGuiTableFlags flags = ImGuiTableFlags.RowBg | ImGuiTableFlags.ScrollX; - var activeCollection = _modManager.Collections.ActiveCollection.Cache!; - var lines = activeCollection.ResolvedFiles.Count + activeCollection.MetaManipulations.Count; + var activeCollection = _modManager.Collections.ActiveCollection.Cache; + 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; unsafe { @@ -75,18 +83,29 @@ namespace Penumbra.UI ImGui.TableSetupColumn( "##tableGamePathCol", ImGuiTableColumnFlags.None, _leftTextLength ); 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(); - 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 ); } + 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 { - var manip = activeCollection.MetaManipulations.Manipulations.ElementAt( - row - activeCollection.ResolvedFiles.Count ); + row -= activeMeta; + var manip = forcedCollection!.MetaManipulations.Manipulations.ElementAt( row ); DrawManipulationLine( manip.Item1, manip.Item2 ); } }