From 6599d3e65d7bebb52c96e735a4267698851f4519 Mon Sep 17 00:00:00 2001 From: cadon Date: Tue, 31 Jan 2023 21:38:31 +0100 Subject: [PATCH] text export of missing color ids of a species --- ARKBreedingStats/Form1.Designer.cs | 20 ++++ ARKBreedingStats/Form1.cs | 7 ++ .../library/CreatureCollection.cs | 95 +++++++++++++++++++ 3 files changed, 122 insertions(+) diff --git a/ARKBreedingStats/Form1.Designer.cs b/ARKBreedingStats/Form1.Designer.cs index 2be76237..1b4ab581 100644 --- a/ARKBreedingStats/Form1.Designer.cs +++ b/ARKBreedingStats/Form1.Designer.cs @@ -353,6 +353,8 @@ private void InitializeComponent() this.contextMenuStripLibraryHeader = new System.Windows.Forms.ContextMenuStrip(this.components); this.toolStripMenuItemResetLibraryColumnWidths = new System.Windows.Forms.ToolStripMenuItem(); this.speciesSelector1 = new ARKBreedingStats.SpeciesSelector(); + this.libraryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.copyColorInformationToClipboardToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownImprintingBonusTester)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NumericUpDownTestingTE)).BeginInit(); @@ -973,6 +975,7 @@ private void InitializeComponent() this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem, this.editToolStripMenuItem, + this.libraryToolStripMenuItem, this.libraryFilterToolStripMenuItem, this.settingsToolStripMenuItem, this.helpToolStripMenuItem, @@ -3452,6 +3455,21 @@ private void InitializeComponent() this.speciesSelector1.SplitterDistance = 500; this.speciesSelector1.TabIndex = 0; // + // libraryToolStripMenuItem + // + this.libraryToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.copyColorInformationToClipboardToolStripMenuItem}); + this.libraryToolStripMenuItem.Name = "libraryToolStripMenuItem"; + this.libraryToolStripMenuItem.Size = new System.Drawing.Size(55, 20); + this.libraryToolStripMenuItem.Text = "Library"; + // + // copyColorInformationToClipboardToolStripMenuItem + // + this.copyColorInformationToClipboardToolStripMenuItem.Name = "copyColorInformationToClipboardToolStripMenuItem"; + this.copyColorInformationToClipboardToolStripMenuItem.Size = new System.Drawing.Size(265, 22); + this.copyColorInformationToClipboardToolStripMenuItem.Text = "Copy color information to clipboard"; + this.copyColorInformationToClipboardToolStripMenuItem.Click += new System.EventHandler(this.copyColorInformationToClipboardToolStripMenuItem_Click); + // // Form1 // this.AcceptButton = this.btExtractLevels; @@ -3876,5 +3894,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripLabel TsLbLabelSet; private System.Windows.Forms.ToolStripComboBox TsCbbLabelSets; private System.Windows.Forms.Label LbWarningLevel255; + private System.Windows.Forms.ToolStripMenuItem libraryToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem copyColorInformationToClipboardToolStripMenuItem; } } diff --git a/ARKBreedingStats/Form1.cs b/ARKBreedingStats/Form1.cs index 5dff5f84..fdd88e10 100644 --- a/ARKBreedingStats/Form1.cs +++ b/ARKBreedingStats/Form1.cs @@ -3629,5 +3629,12 @@ private void colorDefinitionsToClipboardToolStripMenuItem_Click(object sender, E // copy currently loaded color definitions to the clipboard Clipboard.SetText(string.Join("\n", Values.V.Colors.ColorsList.Select(c => $"{c.Id,3}: {c}"))); } + + private void copyColorInformationToClipboardToolStripMenuItem_Click(object sender, EventArgs e) + { + var colorInfo = _creatureCollection.GetColorInfo(speciesSelector1.SelectedSpecies); + Clipboard.SetText(string.IsNullOrEmpty(colorInfo) ? $"no color info available for species {speciesSelector1.SelectedSpecies}" : colorInfo); + 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); + } } } diff --git a/ARKBreedingStats/library/CreatureCollection.cs b/ARKBreedingStats/library/CreatureCollection.cs index aa0badc7..4e25eafb 100644 --- a/ARKBreedingStats/library/CreatureCollection.cs +++ b/ARKBreedingStats/library/CreatureCollection.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; +using System.Text; using ARKBreedingStats.mods; namespace ARKBreedingStats.Library @@ -560,5 +561,99 @@ public enum ColorExisting /// ColorIsNew } + + /// + /// Returns information about what color ids exist in which regions of the creatures of a species. + /// + internal string GetColorInfo(Species species) + { + if (species == null) return null; + + var colorsExistPerRegion = new HashSet[Ark.ColorRegionCount]; + var colorsDontExistPerRegion = new HashSet[Ark.ColorRegionCount]; + var allAvailableColorIds = Values.V.Colors.ColorsList.Select(c => c.Id).ToArray(); + for (int i = 0; i < Ark.ColorRegionCount; i++) + { + colorsExistPerRegion[i] = new HashSet(); + colorsDontExistPerRegion[i] = new HashSet(allAvailableColorIds); + } + + + foreach (var cr in creatures) + { + if (cr.speciesBlueprint != species.blueprintPath + || cr.colors == null) + continue; + + var ci = 0; + foreach (var co in cr.colors) + { + if (colorsExistPerRegion[ci].Contains(co)) continue; + colorsExistPerRegion[ci].Add(co); + colorsDontExistPerRegion[ci].Remove(co); + ci++; + } + } + + var sb = new StringBuilder($"Color information about {species.DescriptiveNameAndMod} ({species.blueprintPath})\n\n"); + for (int i = 0; i < Ark.ColorRegionCount; i++) + { + if (!species.EnabledColorRegions[i]) continue; + sb.AppendLine($"Color region {i}: {species.colors[i].name}"); + var colorsExist = colorsExistPerRegion[i].Count; + sb.AppendLine($"{colorsExist} color id{(colorsExist != 1 ? "s" : "")} available in your library:"); + CreateNumberRanges(colorsExistPerRegion[i]); + sb.AppendLine(); + var colorsDontExist = colorsDontExistPerRegion[i].Count; + sb.AppendLine($"{colorsDontExist} color id{(colorsDontExist != 1 ? "s" : "")} missing in your library:"); + CreateNumberRanges(colorsDontExistPerRegion[i]); + sb.AppendLine(); + sb.AppendLine(); + } + + void CreateNumberRanges(HashSet numbers) + { + var count = numbers.Count; + if (count == 0) return; + if (count == 1) + { + sb.Append(numbers.First()); + return; + } + + int lastNumber = -2; + bool currentlyInRange = false; + foreach (var number in numbers.OrderBy(c => c)) + { + var lastNumberOfSet = --count == 0; + if (lastNumber + 1 == number) + { + if (lastNumberOfSet) + { + if (currentlyInRange) + sb.Append($"-{number}"); + else sb.Append($", {number}"); + } + currentlyInRange = true; + } + else if (currentlyInRange) + { + // was a number range that now ends + sb.Append($"-{lastNumber}, {number}"); + currentlyInRange = false; + } + else + { + if (lastNumber == -2) + sb.Append($"{number}"); // first number of row + else + sb.Append($", {number}"); + } + lastNumber = number; + } + } + + return sb.ToString(); + } } }