@@ -758,7 +758,8 @@ private void UpdateIncubationParents(CreatureCollection cc)
758
758
private void ShowCreaturesInListView ( IEnumerable < Creature > creatures )
759
759
{
760
760
listViewLibrary . BeginUpdate ( ) ;
761
- _creaturesDisplayed = _creatureListSorter . DoSort ( creatures , orderBySpecies : Properties . Settings . Default . LibraryGroupBySpecies ? _speciesInLibraryOrdered : null ) ;
761
+ IEnumerable < Creature > sorted = _creatureListSorter . DoSort ( creatures , orderBySpecies : Properties . Settings . Default . LibraryGroupBySpecies ? _speciesInLibraryOrdered : null ) ;
762
+ _creaturesDisplayed = Properties . Settings . Default . LibraryGroupBySpecies ? InsertDividers ( sorted ) : sorted . ToArray ( ) ;
762
763
listViewLibrary . VirtualListSize = _creaturesDisplayed . Length ;
763
764
_libraryListViewItemCache = null ;
764
765
listViewLibrary . EndUpdate ( ) ;
@@ -777,6 +778,31 @@ private void ShowCreaturesInListView(IEnumerable<Creature> creatures)
777
778
}
778
779
}
779
780
781
+ private Creature [ ] InsertDividers ( IEnumerable < Creature > creatures )
782
+ {
783
+ var enumerable = creatures . ToList ( ) ;
784
+ if ( ! enumerable . Any ( ) )
785
+ {
786
+ return Array . Empty < Creature > ( ) ;
787
+ }
788
+ List < Creature > result = new List < Creature > ( ) ;
789
+ Species lastSpecies = null ;
790
+ foreach ( Creature c in enumerable )
791
+ {
792
+ if ( lastSpecies == null || c . Species != lastSpecies )
793
+ {
794
+ result . Add ( new Creature ( c . Species )
795
+ {
796
+ flags = CreatureFlags . Placeholder | CreatureFlags . Divider ,
797
+ Status = CreatureStatus . Unavailable
798
+ } ) ;
799
+ }
800
+ result . Add ( c ) ;
801
+ lastSpecies = c . Species ;
802
+ }
803
+ return result . ToArray ( ) ;
804
+ }
805
+
780
806
#region ListViewLibrary virtual
781
807
782
808
private Creature [ ] _creaturesDisplayed ;
@@ -821,6 +847,33 @@ private void ListViewLibrary_CacheVirtualItems(object sender, CacheVirtualItemsE
821
847
}
822
848
}
823
849
850
+ private void ListViewLibrary_DrawItem ( object sender , DrawListViewItemEventArgs e )
851
+ {
852
+ e . DrawDefault = true ;
853
+
854
+ if ( ! ( e . Item . Tag is Creature creature ) )
855
+ {
856
+ return ;
857
+ }
858
+
859
+ if ( creature . flags . HasFlag ( CreatureFlags . Divider ) )
860
+ {
861
+ e . DrawDefault = false ;
862
+ var rect = e . Bounds ;
863
+ float middle = ( rect . Top + rect . Bottom ) / 2f ;
864
+ e . Graphics . FillRectangle ( Brushes . Blue , rect . Left , middle , rect . Width - 3 , 1 ) ;
865
+ SizeF strSize = e . Graphics . MeasureString ( creature . Species . DescriptiveNameAndMod , e . Item . Font ) ;
866
+ e . Graphics . FillRectangle ( new SolidBrush ( e . Item . BackColor ) , rect . Left , rect . Top , strSize . Width + 15 , rect . Height ) ;
867
+ e . Graphics . DrawString ( creature . Species . DescriptiveNameAndMod , e . Item . Font , Brushes . Black , rect . Left + 10 , rect . Top + ( ( rect . Height - strSize . Height ) / 2f ) ) ;
868
+ }
869
+ }
870
+
871
+ private void ListViewLibrary_DrawSubItem ( object sender , DrawListViewSubItemEventArgs e )
872
+ {
873
+ var isDivider = e . Item . Tag is Creature creature && creature . flags . HasFlag ( CreatureFlags . Divider ) ;
874
+ e . DrawDefault = ! isDivider ;
875
+ }
876
+
824
877
#endregion
825
878
826
879
/// <summary>
@@ -951,6 +1004,14 @@ private void UpdateCreatureListViewItem(Creature creature)
951
1004
952
1005
private ListViewItem CreateCreatureLvItem ( Creature cr )
953
1006
{
1007
+ if ( cr . flags . HasFlag ( CreatureFlags . Divider ) )
1008
+ {
1009
+ return new ListViewItem ( Enumerable . Repeat ( string . Empty , listViewLibrary . Columns . Count ) . ToArray ( ) )
1010
+ {
1011
+ Tag = cr
1012
+ } ;
1013
+ }
1014
+
954
1015
double colorFactor = 100d / _creatureCollection . maxChartLevel ;
955
1016
956
1017
string [ ] subItems = new [ ]
@@ -1187,7 +1248,8 @@ private void SortLibrary(int columnIndex = -1)
1187
1248
foreach ( int i in listViewLibrary . SelectedIndices )
1188
1249
selectedCreatures . Add ( _creaturesDisplayed [ i ] ) ;
1189
1250
1190
- _creaturesDisplayed = _creatureListSorter . DoSort ( _creaturesDisplayed , columnIndex , Properties . Settings . Default . LibraryGroupBySpecies ? _speciesInLibraryOrdered : null ) ;
1251
+ IEnumerable < Creature > sorted = _creatureListSorter . DoSort ( _creaturesDisplayed . Where ( c => ! c . flags . HasFlag ( CreatureFlags . Divider ) ) , columnIndex , Properties . Settings . Default . LibraryGroupBySpecies ? _speciesInLibraryOrdered : null ) ;
1252
+ _creaturesDisplayed = Properties . Settings . Default . LibraryGroupBySpecies ? InsertDividers ( sorted ) : sorted . ToArray ( ) ;
1191
1253
_libraryListViewItemCache = null ;
1192
1254
listViewLibrary . EndUpdate ( ) ;
1193
1255
SelectCreaturesInLibrary ( selectedCreatures ) ;
@@ -1207,6 +1269,13 @@ private void listViewLibrary_SelectedIndexChanged(object sender, EventArgs e)
1207
1269
/// </summary>
1208
1270
private void LibrarySelectedIndexChanged ( )
1209
1271
{
1272
+ // remove dividers from selection
1273
+ foreach ( int i in listViewLibrary . SelectedIndices )
1274
+ {
1275
+ if ( _creaturesDisplayed [ i ] . flags . HasFlag ( CreatureFlags . Divider ) )
1276
+ listViewLibrary . SelectedIndices . Remove ( i ) ;
1277
+ }
1278
+
1210
1279
int cnt = listViewLibrary . SelectedIndices . Count ;
1211
1280
if ( cnt == 0 )
1212
1281
{
0 commit comments