Skip to content

Commit b837557

Browse files
committed
libraryInfo: ignore placeholders, option to use library filter
1 parent e15a8ca commit b837557

File tree

6 files changed

+103
-22
lines changed

6 files changed

+103
-22
lines changed

ARKBreedingStats/App.config

+3
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,9 @@
478478
<setting name="LibraryGroupBySpecies" serializeAs="String">
479479
<value>True</value>
480480
</setting>
481+
<setting name="LibraryColorInfoUseFilter" serializeAs="String">
482+
<value>False</value>
483+
</setting>
481484
</ARKBreedingStats.Properties.Settings>
482485
</userSettings>
483486
</configuration>

ARKBreedingStats/Form1.Designer.cs

+18-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ARKBreedingStats/Form1.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ private void Form1_Load(object sender, EventArgs e)
222222

223223
LoadListViewSettings(tribesControl1.ListViewPlayers, "PlayerListColumnWidths", "PlayerListColumnDisplayIndices", "PlayerListSortColumn", "PlayerListSortAsc");
224224

225+
CbLibraryInfoUseFilter.Checked = Properties.Settings.Default.LibraryColorInfoUseFilter;
226+
225227
// load stat weights
226228
double[][] custWd = Properties.Settings.Default.customStatWeights;
227229
string[] custWs = Properties.Settings.Default.customStatWeightNames;
@@ -676,7 +678,7 @@ private void SpeciesSelector1OnSpeciesSelected(bool speciesChanged)
676678
}
677679
else if (tabControlMain.SelectedTab == tabPageLibraryInfo)
678680
{
679-
LibraryInfo.SetColorInfo(speciesSelector1.SelectedSpecies, _creatureCollection.creatures, tlpLibraryInfo);
681+
LibraryInfo.SetColorInfo(speciesSelector1.SelectedSpecies, CbLibraryInfoUseFilter.Checked ? (IList<Creature>)ApplyLibraryFilterSettings(_creatureCollection.creatures).ToArray() : _creatureCollection.creatures, CbLibraryInfoUseFilter.Checked, tlpLibraryInfo);
680682
}
681683
else if (tabControlMain.SelectedTab == tabPagePedigree)
682684
{
@@ -924,6 +926,7 @@ private void UpdateCreatureListings(Species species = null, bool keepCurrentlySe
924926
breedingPlan1.BreedingPlanNeedsUpdate = true;
925927
pedigree1.SetSpecies(forceUpdate: true);
926928
raisingControl1.RecreateList();
929+
LibraryInfo.ClearInfo();
927930
}
928931

929932
/// <summary>
@@ -1296,6 +1299,7 @@ private void Form1_FormClosed(object sender, FormClosedEventArgs e)
12961299
Properties.Settings.Default.DisabledVariants = speciesSelector1.VariantSelector?.DisabledVariants?.ToArray();
12971300

12981301
Properties.Settings.Default.RaisingFoodLastSelected = raisingControl1.LastSelectedFood;
1302+
Properties.Settings.Default.LibraryColorInfoUseFilter = CbLibraryInfoUseFilter.Checked;
12991303

13001304
/////// save settings for next session
13011305
Properties.Settings.Default.Save();
@@ -1525,7 +1529,7 @@ private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
15251529
}
15261530
else if (tabControlMain.SelectedTab == tabPageLibraryInfo)
15271531
{
1528-
LibraryInfo.SetColorInfo(speciesSelector1.SelectedSpecies, _creatureCollection.creatures, tlpLibraryInfo);
1532+
LibraryInfo.SetColorInfo(speciesSelector1.SelectedSpecies, CbLibraryInfoUseFilter.Checked ? (IList<Creature>)ApplyLibraryFilterSettings(_creatureCollection.creatures).ToArray() : _creatureCollection.creatures, CbLibraryInfoUseFilter.Checked, tlpLibraryInfo);
15291533
}
15301534
else if (tabControlMain.SelectedTab == tabPagePedigree)
15311535
{
@@ -3640,10 +3644,15 @@ private void colorDefinitionsToClipboardToolStripMenuItem_Click(object sender, E
36403644

36413645
private void BtCopyLibraryColorToClipboard_Click(object sender, EventArgs e)
36423646
{
3643-
LibraryInfo.SetColorInfo(speciesSelector1.SelectedSpecies, _creatureCollection.creatures);
3647+
LibraryInfo.SetColorInfo(speciesSelector1.SelectedSpecies, CbLibraryInfoUseFilter.Checked ? (IList<Creature>)ApplyLibraryFilterSettings(_creatureCollection.creatures).ToArray() : _creatureCollection.creatures, CbLibraryInfoUseFilter.Checked);
36443648
var colorInfo = LibraryInfo.GetSpeciesInfo();
36453649
Clipboard.SetText(string.IsNullOrEmpty(colorInfo) ? $"no color info available for species {speciesSelector1.SelectedSpecies}" : colorInfo);
36463650
SetMessageLabelText($"Color information about {speciesSelector1.SelectedSpecies} has been copied to the clipboard, you can paste it in a text editor to view it.", MessageBoxIcon.Information);
36473651
}
3652+
3653+
private void CbLibraryInfoUseFilter_CheckedChanged(object sender, EventArgs e)
3654+
{
3655+
LibraryInfo.SetColorInfo(speciesSelector1.SelectedSpecies, CbLibraryInfoUseFilter.Checked ? (IList<Creature>)ApplyLibraryFilterSettings(_creatureCollection.creatures).ToArray() : _creatureCollection.creatures, CbLibraryInfoUseFilter.Checked, tlpLibraryInfo);
3656+
}
36483657
}
36493658
}

ARKBreedingStats/Properties/Settings.Designer.cs

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ARKBreedingStats/Properties/Settings.settings

+3
Original file line numberDiff line numberDiff line change
@@ -536,5 +536,8 @@
536536
<Setting Name="LibraryGroupBySpecies" Type="System.Boolean" Scope="User">
537537
<Value Profile="(Default)">True</Value>
538538
</Setting>
539+
<Setting Name="LibraryColorInfoUseFilter" Type="System.Boolean" Scope="User">
540+
<Value Profile="(Default)">False</Value>
541+
</Setting>
539542
</Settings>
540543
</SettingsFile>

ARKBreedingStats/uiControls/LibraryInfo.cs

+54-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using ARKBreedingStats.Library;
1+
using System;
2+
using ARKBreedingStats.Library;
23
using ARKBreedingStats.species;
34
using ARKBreedingStats.values;
45
using System.Collections.Generic;
@@ -12,8 +13,12 @@ namespace ARKBreedingStats.uiControls
1213
internal static class LibraryInfo
1314
{
1415
private static Species _infoForSpecies;
16+
private static bool _libraryFilterConsidered;
1517
private static string _speciesInfo;
1618

19+
/// <summary>
20+
/// Clear the cached information.
21+
/// </summary>
1722
internal static void ClearInfo()
1823
{
1924
_infoForSpecies = null;
@@ -25,16 +30,20 @@ internal static void ClearInfo()
2530
/// <summary>
2631
/// Returns information about what color ids exist in which regions of the creatures of a species.
2732
/// </summary>
28-
internal static bool SetColorInfo(Species species, IList<Creature> creatures, TableLayoutPanel tlp = null)
33+
internal static bool SetColorInfo(Species species, IList<Creature> creatures, bool libraryFilterConsidered, TableLayoutPanel tlp = null)
2934
{
3035
if (species == null || creatures == null) return false;
31-
if (species == _infoForSpecies) return true;
36+
if (species == _infoForSpecies
37+
&& _libraryFilterConsidered == libraryFilterConsidered
38+
&& _infoForSpecies != null) return true;
3239

3340
_infoForSpecies = species;
41+
_libraryFilterConsidered = libraryFilterConsidered;
3442
if (tlp != null)
3543
{
36-
// remove all controls except copy to clipboard button
37-
for (int i = tlp.Controls.Count - 1; i > 0; i--)
44+
tlp.SuspendLayout();
45+
// remove all controls except copy to clipboard button and filter checkbox
46+
for (int i = tlp.Controls.Count - 1; i > 1; i--)
3847
tlp.Controls.RemoveAt(i);
3948
}
4049

@@ -47,38 +56,66 @@ internal static bool SetColorInfo(Species species, IList<Creature> creatures, Ta
4756
colorsDontExistPerRegion[i] = new HashSet<byte>(allAvailableColorIds);
4857
}
4958

59+
var properties = new Dictionary<CreatureFlags, int>();
60+
var flags = ((CreatureFlags[])Enum.GetValues(typeof(CreatureFlags))).Where(f => f != CreatureFlags.None).ToArray();
61+
foreach (var flag in flags)
62+
properties[flag] = 0;
63+
var creatureCount = 0;
64+
5065
foreach (var cr in creatures)
5166
{
5267
if (cr.speciesBlueprint != species.blueprintPath
53-
|| cr.colors == null)
68+
|| cr.flags.HasFlag(CreatureFlags.Placeholder)
69+
|| cr.colors == null)
5470
continue;
5571

72+
creatureCount++;
5673
for (var ci = 0; ci < Ark.ColorRegionCount; ci++)
5774
{
5875
var co = cr.colors[ci];
5976
if (colorsExistPerRegion[ci].Contains(co)) continue;
6077
colorsExistPerRegion[ci].Add(co);
6178
colorsDontExistPerRegion[ci].Remove(co);
6279
}
80+
81+
foreach (var flag in flags)
82+
{
83+
if (cr.flags.HasFlag(flag))
84+
properties[flag]++;
85+
}
6386
}
6487

6588
var sb = new StringBuilder();
6689
var tableRow = 1;
6790

68-
void AddParagraph(string text, string appendToPlainText = null, bool bold = false, float relativeFontSize = 1)
91+
void AddParagraph(string text, string suffixForPlainText = null, bool bold = false, float relativeFontSize = 1)
6992
{
70-
tlp?.RowStyles.Add(new RowStyle(SizeType.AutoSize));
71-
tlp?.Controls.Add(new Label
93+
if (tlp != null)
7294
{
73-
Text = text,
74-
Font = bold || relativeFontSize != 1 ? new Font(Control.DefaultFont.FontFamily, Control.DefaultFont.Size * relativeFontSize, bold ? FontStyle.Bold : FontStyle.Regular) : Control.DefaultFont,
75-
Margin = new Padding(3, bold ? 8 : 3, 3, 3),
76-
AutoSize = true
77-
}, 0, tableRow++);
78-
sb.AppendLine(text + appendToPlainText);
95+
while (tlp.RowStyles.Count <= tableRow)
96+
tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize));
97+
var l = new Label
98+
{
99+
Text = text,
100+
Font = bold || relativeFontSize != 1
101+
? new Font(Control.DefaultFont.FontFamily, Control.DefaultFont.Size * relativeFontSize,
102+
bold ? FontStyle.Bold : FontStyle.Regular)
103+
: Control.DefaultFont,
104+
Margin = new Padding(3, bold ? 8 : 3, 3, 3),
105+
AutoSize = true
106+
};
107+
tlp.Controls.Add(l, 0, tableRow++);
108+
tlp.SetColumnSpan(l, 2);
109+
}
110+
111+
sb.AppendLine(text + suffixForPlainText);
79112
}
80113

81-
AddParagraph($"Color information about {species.DescriptiveNameAndMod} ({species.blueprintPath})", "\n", true, 1.5f);
114+
AddParagraph($"Information about the {species.DescriptiveNameAndMod} in this library", "\n", true, 1.5f);
115+
AddParagraph(
116+
$"{creatureCount} creatures. {string.Join(", ", properties.Where(p => p.Value > 0).Select(p => $"{Loc.S(p.Key.ToString())}: {p.Value}"))}",
117+
"\n");
118+
AddParagraph($"Color information", null, true, 1.3f);
82119

83120
var rangeSb = new StringBuilder();
84121
for (int i = 0; i < Ark.ColorRegionCount; i++)
@@ -138,6 +175,7 @@ string CreateNumberRanges(HashSet<byte> numbers)
138175
}
139176

140177
_speciesInfo = sb.ToString();
178+
tlp?.ResumeLayout();
141179
return true;
142180
}
143181

0 commit comments

Comments
 (0)