From f715771f65d6a12153d5356728628cb6aa9ebfd4 Mon Sep 17 00:00:00 2001 From: ThatGamerBlue Date: Tue, 6 Dec 2022 18:56:34 +0000 Subject: [PATCH 01/10] Add species dividers to the library tab (#1296) * feat/dividers: add support for rendering dividers in the library tab current issues: crashes when left clicking a divider can still right click dividers switching species filters crashes because it tries to select a divider * feat/dividers: can no longer select dividers --- .gitignore | 3 + ARKBreedingStats/Form1.cs | 4 + ARKBreedingStats/Form1.library.cs | 81 +++++++++++++++++++- ARKBreedingStats/library/Creature.cs | 3 +- ARKBreedingStats/utils/CreatureListSorter.cs | 4 +- 5 files changed, 90 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index e9e457f6e..8f9b55a2a 100644 --- a/.gitignore +++ b/.gitignore @@ -212,3 +212,6 @@ GeneratedArtifacts/ _Pvt_Extensions/ ModelManifest.xml /_publish/ + +*.asb +.idea/ \ No newline at end of file diff --git a/ARKBreedingStats/Form1.cs b/ARKBreedingStats/Form1.cs index dab886842..ff6628fa1 100644 --- a/ARKBreedingStats/Form1.cs +++ b/ARKBreedingStats/Form1.cs @@ -172,6 +172,10 @@ public Form1() listViewLibrary.VirtualMode = true; listViewLibrary.RetrieveVirtualItem += ListViewLibrary_RetrieveVirtualItem; listViewLibrary.CacheVirtualItems += ListViewLibrary_CacheVirtualItems; + listViewLibrary.OwnerDraw = true; + listViewLibrary.DrawItem += ListViewLibrary_DrawItem; + listViewLibrary.DrawColumnHeader += (sender, args) => args.DrawDefault = true; + listViewLibrary.DrawSubItem += ListViewLibrary_DrawSubItem; speciesSelector1.SetTextBox(tbSpeciesGlobal); diff --git a/ARKBreedingStats/Form1.library.cs b/ARKBreedingStats/Form1.library.cs index 93b35b3cf..d716ede1b 100644 --- a/ARKBreedingStats/Form1.library.cs +++ b/ARKBreedingStats/Form1.library.cs @@ -758,7 +758,8 @@ private void UpdateIncubationParents(CreatureCollection cc) private void ShowCreaturesInListView(IEnumerable creatures) { listViewLibrary.BeginUpdate(); - _creaturesDisplayed = _creatureListSorter.DoSort(creatures, orderBySpecies: Properties.Settings.Default.LibraryGroupBySpecies ? _speciesInLibraryOrdered : null); + IEnumerable sorted = _creatureListSorter.DoSort(creatures, orderBySpecies: Properties.Settings.Default.LibraryGroupBySpecies ? _speciesInLibraryOrdered : null); + _creaturesDisplayed = Properties.Settings.Default.LibraryGroupBySpecies ? InsertDividers(sorted) : sorted.ToArray(); listViewLibrary.VirtualListSize = _creaturesDisplayed.Length; _libraryListViewItemCache = null; listViewLibrary.EndUpdate(); @@ -777,6 +778,31 @@ private void ShowCreaturesInListView(IEnumerable creatures) } } + private Creature[] InsertDividers(IEnumerable creatures) + { + var enumerable = creatures.ToList(); + if (!enumerable.Any()) + { + return Array.Empty(); + } + List result = new List(); + Creature last = null; + foreach (Creature c in enumerable) + { + if (last == null || c.Species != last.Species) + { + result.Add(new Creature(c.Species, "ASB_Dummy123!?") + { + flags = CreatureFlags.Placeholder | CreatureFlags.Divider, + Status = CreatureStatus.Unavailable + }); + } + result.Add(c); + last = c; + } + return result.ToArray(); + } + #region ListViewLibrary virtual private Creature[] _creaturesDisplayed; @@ -821,6 +847,41 @@ private void ListViewLibrary_CacheVirtualItems(object sender, CacheVirtualItemsE } } + private void ListViewLibrary_DrawItem(object sender, DrawListViewItemEventArgs e) + { + e.DrawDefault = true; + + if (!(e.Item.Tag is Creature creature)) + { + return; + } + + if (creature.flags.HasFlag(CreatureFlags.Divider)) + { + e.DrawDefault = false; + var rect = e.Bounds; + float middle = (rect.Top + rect.Bottom) / 2f; + e.Graphics.FillRectangle(Brushes.Blue, rect.Left, middle, rect.Width, 1); + SizeF strSize = e.Graphics.MeasureString(creature.Species.name, e.Item.Font); + e.Graphics.FillRectangle(new SolidBrush(e.Item.BackColor), rect.Left, rect.Top, strSize.Width + 10, rect.Height); + e.Graphics.DrawString(creature.Species.name, e.Item.Font, Brushes.Black, rect.Left + 5, rect.Top + ((rect.Height - strSize.Height) / 2f)); + } + } + + private void ListViewLibrary_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) + { + e.DrawDefault = true; + if (!(e.Item.Tag is Creature creature)) + { + return; + } + + if (creature.flags.HasFlag(CreatureFlags.Divider)) + { + e.DrawDefault = false; + } + } + #endregion /// @@ -951,6 +1012,13 @@ private void UpdateCreatureListViewItem(Creature creature) private ListViewItem CreateCreatureLvItem(Creature cr) { + if (cr.flags.HasFlag(CreatureFlags.Divider)) + { + ListViewItem div = new ListViewItem(Enumerable.Repeat("", listViewLibrary.Columns.Count).ToArray()); + div.Tag = cr; + return div; + } + double colorFactor = 100d / _creatureCollection.maxChartLevel; string[] subItems = new[] @@ -1187,7 +1255,8 @@ private void SortLibrary(int columnIndex = -1) foreach (int i in listViewLibrary.SelectedIndices) selectedCreatures.Add(_creaturesDisplayed[i]); - _creaturesDisplayed = _creatureListSorter.DoSort(_creaturesDisplayed, columnIndex, Properties.Settings.Default.LibraryGroupBySpecies ? _speciesInLibraryOrdered : null); + IEnumerable sorted = _creatureListSorter.DoSort(_creaturesDisplayed.Where(c => !c.flags.HasFlag(CreatureFlags.Divider)), columnIndex, Properties.Settings.Default.LibraryGroupBySpecies ? _speciesInLibraryOrdered : null); + _creaturesDisplayed = Properties.Settings.Default.LibraryGroupBySpecies ? InsertDividers(sorted) : sorted.ToArray(); _libraryListViewItemCache = null; listViewLibrary.EndUpdate(); SelectCreaturesInLibrary(selectedCreatures); @@ -1207,6 +1276,14 @@ private void listViewLibrary_SelectedIndexChanged(object sender, EventArgs e) /// private void LibrarySelectedIndexChanged() { + for (var index = 0; index < listViewLibrary.SelectedIndices.Count; index++) + { + var creatureIdx = listViewLibrary.SelectedIndices[index]; + Creature c = _creaturesDisplayed[creatureIdx]; + if (!c.flags.HasFlag(CreatureFlags.Divider)) continue; + listViewLibrary.SelectedIndices.Remove(creatureIdx); + } + int cnt = listViewLibrary.SelectedIndices.Count; if (cnt == 0) { diff --git a/ARKBreedingStats/library/Creature.cs b/ARKBreedingStats/library/Creature.cs index e9e530a8d..df9c28fde 100644 --- a/ARKBreedingStats/library/Creature.cs +++ b/ARKBreedingStats/library/Creature.cs @@ -570,9 +570,10 @@ public enum CreatureFlags Female = 512, Male = 1024, MutagenApplied = 2048, + Divider = 4096, /// /// If applied to the flags with &, the status is removed. /// - StatusMask = Mutated | Neutered | Placeholder | Female | Male | MutagenApplied + StatusMask = Mutated | Neutered | Placeholder | Female | Male | MutagenApplied | Divider } } \ No newline at end of file diff --git a/ARKBreedingStats/utils/CreatureListSorter.cs b/ARKBreedingStats/utils/CreatureListSorter.cs index 4a196d6f9..7f96c9c13 100644 --- a/ARKBreedingStats/utils/CreatureListSorter.cs +++ b/ARKBreedingStats/utils/CreatureListSorter.cs @@ -34,7 +34,7 @@ public class CreatureListSorter /// /// Sort list by given column index. If the columnIndex is -1, use last sorting. /// - public Creature[] DoSort(IEnumerable list, int columnIndex = -1, Species[] orderBySpecies = null) + public IEnumerable DoSort(IEnumerable list, int columnIndex = -1, Species[] orderBySpecies = null) { if (list == null) return null; @@ -54,7 +54,7 @@ public Creature[] DoSort(IEnumerable list, int columnIndex = -1, Speci } // Perform the sort with these new sort options. - return OrderList(list, orderBySpecies).ToArray(); + return OrderList(list, orderBySpecies); } private IEnumerable OrderList(IEnumerable list, Species[] orderBySpecies = null) From 3680abb72bb19e7ea9dea825f6a7d9b1496d6cf3 Mon Sep 17 00:00:00 2001 From: cadon Date: Tue, 6 Dec 2022 21:42:00 +0100 Subject: [PATCH 02/10] performance tweaks for species divider --- .gitignore | 3 -- ARKBreedingStats/AboutBox1.cs | 1 + ARKBreedingStats/Form1.library.cs | 46 ++++++++++++---------------- ARKBreedingStats/library/Creature.cs | 13 +++++++- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 8f9b55a2a..e9e457f6e 100644 --- a/.gitignore +++ b/.gitignore @@ -212,6 +212,3 @@ GeneratedArtifacts/ _Pvt_Extensions/ ModelManifest.xml /_publish/ - -*.asb -.idea/ \ No newline at end of file diff --git a/ARKBreedingStats/AboutBox1.cs b/ARKBreedingStats/AboutBox1.cs index d2edd5eab..316555e84 100644 --- a/ARKBreedingStats/AboutBox1.cs +++ b/ARKBreedingStats/AboutBox1.cs @@ -108,6 +108,7 @@ private void linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs * dunger (fixes) * Myrmecoleon (extra species images) * Lunat1q (improved OCR) +* ThatGamerBlue (species dividers in virtual listview) Translations: * French by Vykan and Yanuut diff --git a/ARKBreedingStats/Form1.library.cs b/ARKBreedingStats/Form1.library.cs index d716ede1b..16ec6d476 100644 --- a/ARKBreedingStats/Form1.library.cs +++ b/ARKBreedingStats/Form1.library.cs @@ -786,19 +786,19 @@ private Creature[] InsertDividers(IEnumerable creatures) return Array.Empty(); } List result = new List(); - Creature last = null; + Species lastSpecies = null; foreach (Creature c in enumerable) { - if (last == null || c.Species != last.Species) + if (lastSpecies == null || c.Species != lastSpecies) { - result.Add(new Creature(c.Species, "ASB_Dummy123!?") + result.Add(new Creature(c.Species) { flags = CreatureFlags.Placeholder | CreatureFlags.Divider, Status = CreatureStatus.Unavailable }); } result.Add(c); - last = c; + lastSpecies = c.Species; } return result.ToArray(); } @@ -861,25 +861,17 @@ private void ListViewLibrary_DrawItem(object sender, DrawListViewItemEventArgs e e.DrawDefault = false; var rect = e.Bounds; float middle = (rect.Top + rect.Bottom) / 2f; - e.Graphics.FillRectangle(Brushes.Blue, rect.Left, middle, rect.Width, 1); - SizeF strSize = e.Graphics.MeasureString(creature.Species.name, e.Item.Font); - e.Graphics.FillRectangle(new SolidBrush(e.Item.BackColor), rect.Left, rect.Top, strSize.Width + 10, rect.Height); - e.Graphics.DrawString(creature.Species.name, e.Item.Font, Brushes.Black, rect.Left + 5, rect.Top + ((rect.Height - strSize.Height) / 2f)); + e.Graphics.FillRectangle(Brushes.Blue, rect.Left, middle, rect.Width - 3, 1); + SizeF strSize = e.Graphics.MeasureString(creature.Species.DescriptiveNameAndMod, e.Item.Font); + e.Graphics.FillRectangle(new SolidBrush(e.Item.BackColor), rect.Left, rect.Top, strSize.Width + 15, rect.Height); + e.Graphics.DrawString(creature.Species.DescriptiveNameAndMod, e.Item.Font, Brushes.Black, rect.Left + 10, rect.Top + ((rect.Height - strSize.Height) / 2f)); } } private void ListViewLibrary_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { - e.DrawDefault = true; - if (!(e.Item.Tag is Creature creature)) - { - return; - } - - if (creature.flags.HasFlag(CreatureFlags.Divider)) - { - e.DrawDefault = false; - } + var isDivider = e.Item.Tag is Creature creature && creature.flags.HasFlag(CreatureFlags.Divider); + e.DrawDefault = !isDivider; } #endregion @@ -1014,11 +1006,12 @@ private ListViewItem CreateCreatureLvItem(Creature cr) { if (cr.flags.HasFlag(CreatureFlags.Divider)) { - ListViewItem div = new ListViewItem(Enumerable.Repeat("", listViewLibrary.Columns.Count).ToArray()); - div.Tag = cr; - return div; + return new ListViewItem(Enumerable.Repeat(string.Empty, listViewLibrary.Columns.Count).ToArray()) + { + Tag = cr + }; } - + double colorFactor = 100d / _creatureCollection.maxChartLevel; string[] subItems = new[] @@ -1276,12 +1269,11 @@ private void listViewLibrary_SelectedIndexChanged(object sender, EventArgs e) /// private void LibrarySelectedIndexChanged() { - for (var index = 0; index < listViewLibrary.SelectedIndices.Count; index++) + // remove dividers from selection + foreach (int i in listViewLibrary.SelectedIndices) { - var creatureIdx = listViewLibrary.SelectedIndices[index]; - Creature c = _creaturesDisplayed[creatureIdx]; - if (!c.flags.HasFlag(CreatureFlags.Divider)) continue; - listViewLibrary.SelectedIndices.Remove(creatureIdx); + if (_creaturesDisplayed[i].flags.HasFlag(CreatureFlags.Divider)) + listViewLibrary.SelectedIndices.Remove(i); } int cnt = listViewLibrary.SelectedIndices.Count; diff --git a/ARKBreedingStats/library/Creature.cs b/ARKBreedingStats/library/Creature.cs index df9c28fde..6ece1e8a0 100644 --- a/ARKBreedingStats/library/Creature.cs +++ b/ARKBreedingStats/library/Creature.cs @@ -1,5 +1,4 @@ using ARKBreedingStats.species; -using ARKBreedingStats.values; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -240,6 +239,15 @@ public Creature(long arkId) flags = CreatureFlags.Placeholder; } + /// + /// Creates a placeholder creature with a species and no other info. + /// + public Creature(Species species) + { + _species = species; + flags = CreatureFlags.Placeholder; + } + public bool Equals(Creature other) => other != null && other.guid == guid; public override bool Equals(object obj) => obj is Creature creatureObj && creatureObj.guid == guid; @@ -570,6 +578,9 @@ public enum CreatureFlags Female = 512, Male = 1024, MutagenApplied = 2048, + /// + /// Indicates a dummy creature used as a species separator in the library listView. + /// Divider = 4096, /// /// If applied to the flags with &, the status is removed. From 2e0ed095c8fb6ec7706a0aed75224159fabccf39 Mon Sep 17 00:00:00 2001 From: cadon Date: Tue, 6 Dec 2022 21:42:19 +0100 Subject: [PATCH 03/10] ommit redundant species variant info --- ARKBreedingStats/species/Species.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ARKBreedingStats/species/Species.cs b/ARKBreedingStats/species/Species.cs index f9be23005..a2f1b1c0d 100644 --- a/ARKBreedingStats/species/Species.cs +++ b/ARKBreedingStats/species/Species.cs @@ -199,18 +199,19 @@ private void Initialize(StreamingContext context) /// public void InitializeNames() { + string variantInfoForName = null; if (variants != null && variants.Any()) { VariantInfo = string.Join(", ", variants); + variantInfoForName = string.Join(", ", variants.Where(v => !name.Contains(v))); } - DescriptiveName = name + (string.IsNullOrEmpty(VariantInfo) ? string.Empty : " (" + VariantInfo + ")"); + DescriptiveName = name + (string.IsNullOrEmpty(variantInfoForName) ? string.Empty : " (" + variantInfoForName + ")"); string modSuffix = string.IsNullOrEmpty(_mod?.title) ? string.Empty : _mod.title; DescriptiveNameAndMod = DescriptiveName + (string.IsNullOrEmpty(modSuffix) ? string.Empty : " (" + modSuffix + ")"); SortName = DescriptiveNameAndMod; } - /// /// Sets the ArkColor objects for the natural occurring colors. Call after colors are loaded or changed by loading mods. /// From 87d8c7399467acce5ab2350c5951b9f94b4ab50b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Dec 2022 22:31:02 +0100 Subject: [PATCH 04/10] Bump Newtonsoft.Json from 13.0.1 to 13.0.2 in /ARKBreedingStats (#1297) Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 13.0.1 to 13.0.2. - [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases) - [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/13.0.1...13.0.2) --- updated-dependencies: - dependency-name: Newtonsoft.Json dependency-type: direct:production ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- ARKBreedingStats/ARKBreedingStats.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ARKBreedingStats/ARKBreedingStats.csproj b/ARKBreedingStats/ARKBreedingStats.csproj index 8e46f8891..2eabdac14 100644 --- a/ARKBreedingStats/ARKBreedingStats.csproj +++ b/ARKBreedingStats/ARKBreedingStats.csproj @@ -961,7 +961,7 @@ all - 13.0.1 + 13.0.2 From 77e22fe4a43a39c33b66232e1037e2e578bd4986 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Dec 2022 22:35:02 +0100 Subject: [PATCH 05/10] Bump Newtonsoft.Json from 13.0.1 to 13.0.2 in /ASB-Updater (#1298) Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 13.0.1 to 13.0.2. - [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases) - [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/13.0.1...13.0.2) --- updated-dependencies: - dependency-name: Newtonsoft.Json dependency-type: direct:production ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- ASB-Updater/ASB Updater.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ASB-Updater/ASB Updater.csproj b/ASB-Updater/ASB Updater.csproj index 00eb2c595..b349ad769 100644 --- a/ASB-Updater/ASB Updater.csproj +++ b/ASB-Updater/ASB Updater.csproj @@ -142,7 +142,7 @@ all - 13.0.1 + 13.0.2 4.3.0 From c9532f53c682e9534ee7a2a76d48fef55c8b5778 Mon Sep 17 00:00:00 2001 From: cadon Date: Sat, 10 Dec 2022 00:23:05 +0100 Subject: [PATCH 06/10] status / flag fix #1295 --- ARKBreedingStats/library/Creature.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ARKBreedingStats/library/Creature.cs b/ARKBreedingStats/library/Creature.cs index 6ece1e8a0..e39e8f4f0 100644 --- a/ARKBreedingStats/library/Creature.cs +++ b/ARKBreedingStats/library/Creature.cs @@ -257,6 +257,9 @@ public CreatureStatus Status get => _status; set { + // remove other status while keeping the other flags + flags = (flags & CreatureFlags.StatusMask) | (CreatureFlags)(1 << (int)value); + if (_status == value) return; if (Maturation < 1) @@ -272,9 +275,6 @@ public CreatureStatus Status } _status = value; - // remove other status while keeping the other flags - flags = (flags & CreatureFlags.StatusMask) | (CreatureFlags)(1 << (int)value); - } } From c6dacbbd0ba853a7f8d55f794b60a8733e4bb563 Mon Sep 17 00:00:00 2001 From: cadon Date: Sun, 11 Dec 2022 16:15:32 +0100 Subject: [PATCH 07/10] MouseWheel support --- ARKBreedingStats/uiControls/dhmsInput.cs | 118 +++++++++++++---------- 1 file changed, 66 insertions(+), 52 deletions(-) diff --git a/ARKBreedingStats/uiControls/dhmsInput.cs b/ARKBreedingStats/uiControls/dhmsInput.cs index 0622430e1..aceaefa67 100644 --- a/ARKBreedingStats/uiControls/dhmsInput.cs +++ b/ARKBreedingStats/uiControls/dhmsInput.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Text.RegularExpressions; using System.Windows.Forms; @@ -13,77 +12,92 @@ public partial class dhmsInput : UserControl public event ValueChangedEventHandler ValueChanged; public bool changed; - private bool change; + private bool _change; public dhmsInput() { InitializeComponent(); ts = TimeSpan.Zero; changed = false; - change = true; + _change = true; + + mTBD.MouseWheel += (s, e) => ChangeValue((TextBox)s, Math.Sign(e.Delta)); + mTBH.MouseWheel += (s, e) => ChangeValue((TextBox)s, Math.Sign(e.Delta)); + mTBM.MouseWheel += (s, e) => ChangeValue((TextBox)s, Math.Sign(e.Delta) * 5); + mTBS.MouseWheel += (s, e) => ChangeValue((TextBox)s, Math.Sign(e.Delta) * 5); } private void mTB_KeyUp(object sender, KeyEventArgs e) { TextBox input = (TextBox)sender; - if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Right) + switch (e.KeyCode) { - int i = 0; - if (input == mTBH) - { - i = 1; - } - else if (input == mTBM) - { - i = 2; - } - else if (input == mTBS) - { - i = 3; - } + case Keys.Left: + case Keys.Right: + { + int i = 0; + if (input == mTBH) + { + i = 1; + } + else if (input == mTBM) + { + i = 2; + } + else if (input == mTBS) + { + i = 3; + } - List inputs = new List { mTBD, mTBH, mTBM, mTBS }; + var inputs = new TextBox[] { mTBD, mTBH, mTBM, mTBS }; - if (e.KeyCode == Keys.Left) i--; - else i++; + if (e.KeyCode == Keys.Left) i--; + else i++; - if (i < 0) i = 3; - else if (i > 3) i = 0; + if (i < 0) i = 3; + else if (i > 3) i = 0; - inputs[i].Focus(); - } - else if (e.KeyCode == Keys.Up) - { - int.TryParse(input.Text, out int i); - input.Text = (++i).ToString("D2"); - input.SelectAll(); + inputs[i].Focus(); + break; + } + case Keys.Up: + { + ChangeValue(input, 1); + break; + } + case Keys.Down: + { + ChangeValue(input, -1); + break; + } + default: + input.Text = RegexNonNumbers.Replace(input.Text, string.Empty); + break; } - else if (e.KeyCode == Keys.Down) - { - int.TryParse(input.Text, out int i); - i--; - if (i < 0) i = 0; - input.Text = i.ToString("D2"); + } + + private static readonly Regex RegexNonNumbers = new Regex(@"\D", RegexOptions.Compiled); + + private void ChangeValue(TextBox input, int valueChange, bool selectAfterChange = true) + { + int.TryParse(input.Text, out var v); + v += valueChange; + if (v < 0) v = 0; + input.Text = v.ToString("D2"); + if (selectAfterChange) input.SelectAll(); - } - else - { - input.Text = Regex.Replace(input.Text, @"\D", ""); - } } private void mTB_TextChanged(object sender, EventArgs e) { - if (change) - { - int.TryParse(mTBD.Text, out int d); - int.TryParse(mTBH.Text, out int h); - int.TryParse(mTBM.Text, out int m); - int.TryParse(mTBS.Text, out int s); - ts = new TimeSpan(d, h, m, s); - changed = true; - ValueChanged?.Invoke(this, ts); - } + if (!_change) return; + int.TryParse(mTBD.Text, out int d); + int.TryParse(mTBH.Text, out int h); + int.TryParse(mTBM.Text, out int m); + int.TryParse(mTBS.Text, out int s); + ts = new TimeSpan(d, h, m, s); + changed = true; + ValueChanged?.Invoke(this, ts); } public TimeSpan Timespan @@ -91,14 +105,14 @@ public TimeSpan Timespan get => ts; set { - change = false; + _change = false; ts = value.TotalSeconds >= 0 ? value : TimeSpan.Zero; mTBD.Text = ((int)Math.Floor(ts.TotalDays)).ToString("D2"); mTBH.Text = ts.Hours.ToString("D2"); mTBM.Text = ts.Minutes.ToString("D2"); mTBS.Text = ts.Seconds.ToString("D2"); changed = false; - change = true; + _change = true; } } From 5f6b94b54b5740bbcd0f4f1b6240222afc16ca72 Mon Sep 17 00:00:00 2001 From: cadon Date: Sun, 11 Dec 2022 16:52:05 +0100 Subject: [PATCH 08/10] improved display of maturation timer in editor --- .../CreatureInfoInput.Designer.cs | 12 +++- ARKBreedingStats/CreatureInfoInput.cs | 67 ++++++++++--------- ARKBreedingStats/Form1.tester.cs | 3 +- ARKBreedingStats/library/Creature.cs | 11 ++- 4 files changed, 55 insertions(+), 38 deletions(-) diff --git a/ARKBreedingStats/CreatureInfoInput.Designer.cs b/ARKBreedingStats/CreatureInfoInput.Designer.cs index 1aeea6971..52e7eeda9 100644 --- a/ARKBreedingStats/CreatureInfoInput.Designer.cs +++ b/ARKBreedingStats/CreatureInfoInput.Designer.cs @@ -412,7 +412,7 @@ private void InitializeComponent() this.label12.AutoSize = true; this.label12.Location = new System.Drawing.Point(173, 388); this.label12.Name = "label12"; - this.label12.Size = new System.Drawing.Size(17, 13); + this.label12.Size = new System.Drawing.Size(19, 13); this.label12.TabIndex = 34; this.label12.Text = "♂"; // @@ -421,7 +421,7 @@ private void InitializeComponent() this.label11.AutoSize = true; this.label11.Location = new System.Drawing.Point(85, 388); this.label11.Name = "label11"; - this.label11.Size = new System.Drawing.Size(16, 13); + this.label11.Size = new System.Drawing.Size(19, 13); this.label11.TabIndex = 33; this.label11.Text = "♀"; // @@ -432,6 +432,7 @@ private void InitializeComponent() this.dhmsInputGrown.Size = new System.Drawing.Size(136, 26); this.dhmsInputGrown.TabIndex = 10; this.dhmsInputGrown.Timespan = System.TimeSpan.Parse("00:00:00"); + this.dhmsInputGrown.ValueChanged += new ARKBreedingStats.uiControls.dhmsInput.ValueChangedEventHandler(this.dhmsInputGrown_ValueChanged); // // dhmsInputCooldown // @@ -541,6 +542,13 @@ private void InitializeComponent() // // regionColorChooser1 // + this.regionColorChooser1.ColorIdsAlsoPossible = new byte[] { + ((byte)(0)), + ((byte)(0)), + ((byte)(0)), + ((byte)(0)), + ((byte)(0)), + ((byte)(0))}; this.regionColorChooser1.Location = new System.Drawing.Point(82, 496); this.regionColorChooser1.Margin = new System.Windows.Forms.Padding(0); this.regionColorChooser1.Name = "regionColorChooser1"; diff --git a/ARKBreedingStats/CreatureInfoInput.cs b/ARKBreedingStats/CreatureInfoInput.cs index b0754d0ed..eb1304624 100644 --- a/ARKBreedingStats/CreatureInfoInput.cs +++ b/ARKBreedingStats/CreatureInfoInput.cs @@ -80,8 +80,6 @@ public CreatureInfoInput() parentComboBoxFather.SelectedIndex = 0; _updateMaturation = true; _regionColorIDs = new byte[Ark.ColorRegionCount]; - CooldownUntil = new DateTime(2000, 1, 1); - GrowingUntil = new DateTime(2000, 1, 1); NamesOfAllCreatures = new List(); var namingPatternButtons = ButtonsNamingPattern; @@ -291,38 +289,39 @@ private void groupBox1_Enter(object sender, EventArgs e) ParentListRequested?.Invoke(this); } - //private void dhmsInputGrown_ValueChanged(object sender, TimeSpan ts) - //{ - // if (_updateMaturation && _selectedSpecies != null) - // { - // _updateMaturation = false; - // double maturation = 0; - // if (_selectedSpecies.breeding != null && _selectedSpecies.breeding.maturationTimeAdjusted > 0) - // { - // maturation = 1 - dhmsInputGrown.Timespan.TotalSeconds / _selectedSpecies.breeding.maturationTimeAdjusted; - // if (maturation < 0) maturation = 0; - // if (maturation > 1) maturation = 1; - // } - // nudMaturation.Value = (decimal)maturation * 100; - - // _updateMaturation = true; - // } - //} + private void dhmsInputGrown_ValueChanged(object sender, TimeSpan ts) + { + if (!_updateMaturation || _selectedSpecies?.breeding == null) return; + dhmsInputGrown.changed = true; + SetMaturationAccordingToGrownUpIn(); + } + + private void SetMaturationAccordingToGrownUpIn() + { + double maturation = 1; + if (_selectedSpecies.breeding != null && _selectedSpecies.breeding.maturationTimeAdjusted > 0) + { + maturation = 1 - dhmsInputGrown.Timespan.TotalSeconds / _selectedSpecies.breeding.maturationTimeAdjusted; + if (maturation < 0) maturation = 0; + if (maturation > 1) maturation = 1; + } + _updateMaturation = false; + nudMaturation.Value = (decimal)maturation * 100; + _updateMaturation = true; + } private void nudMaturation_ValueChanged(object sender, EventArgs e) { - if (_updateMaturation) + if (!_updateMaturation) return; + + _updateMaturation = false; + if (_selectedSpecies.breeding != null) { - _updateMaturation = false; - if (_selectedSpecies.breeding != null) - { - dhmsInputGrown.Timespan = new TimeSpan(0, 0, (int)(_selectedSpecies.breeding.maturationTimeAdjusted * - (1 - (double)nudMaturation.Value / 100))); - dhmsInputGrown.changed = true; - } - else dhmsInputGrown.Timespan = TimeSpan.Zero; - _updateMaturation = true; + dhmsInputGrown.Timespan = TimeSpan.FromSeconds(_selectedSpecies.breeding.maturationTimeAdjusted * (1 - (double)nudMaturation.Value / 100)); + dhmsInputGrown.changed = true; } + else dhmsInputGrown.Timespan = TimeSpan.Zero; + _updateMaturation = true; } /// @@ -348,8 +347,9 @@ public DateTime? GrowingUntil get => dhmsInputGrown.changed ? DateTime.Now.Add(dhmsInputGrown.Timespan) : default(DateTime?); set { - if (value.HasValue) - dhmsInputGrown.Timespan = value.Value - DateTime.Now; + if (!value.HasValue) return; + dhmsInputGrown.Timespan = value.Value - DateTime.Now; + SetMaturationAccordingToGrownUpIn(); } } @@ -540,7 +540,7 @@ public Species SelectedSpecies lbMaturationPerc.Visible = breedingPossible; if (!breedingPossible) { - nudMaturation.Value = 0; + nudMaturation.Value = 1; dhmsInputGrown.Timespan = TimeSpan.Zero; dhmsInputCooldown.Timespan = TimeSpan.Zero; } @@ -632,7 +632,8 @@ public void SetCreatureData(Creature cr) cr.colors = RegionColors; cr.ColorIdsAlsoPossible = ColorIdsAlsoPossible; cr.cooldownUntil = CooldownUntil; - cr.growingUntil = GrowingUntil; + if (GrowingUntil != null) // if growing was not changed, don't change that value, growing could be paused + cr.growingUntil = GrowingUntil; cr.domesticatedAt = DomesticatedAt; cr.ArkId = ArkId; cr.InitializeArkInGame(); diff --git a/ARKBreedingStats/Form1.tester.cs b/ARKBreedingStats/Form1.tester.cs index 8b10fc066..5b3660371 100644 --- a/ARKBreedingStats/Form1.tester.cs +++ b/ARKBreedingStats/Form1.tester.cs @@ -215,7 +215,8 @@ private void creatureInfoInputTester_Save2Library_Clicked(CreatureInfoInput send _creatureTesterEdit.RecalculateNewMutations(); // if maturation was changed, update raising-timers - if (_creatureTesterEdit.growingUntil != creatureInfoInputTester.GrowingUntil) + var newGrownUpAt = creatureInfoInputTester.GrowingUntil; + if (newGrownUpAt != null && _creatureTesterEdit.growingUntil != newGrownUpAt) { raisingControl1.RecreateList(); _creatureTesterEdit.StartStopMatureTimer(true); diff --git a/ARKBreedingStats/library/Creature.cs b/ARKBreedingStats/library/Creature.cs index e39e8f4f0..f3dc69a1f 100644 --- a/ARKBreedingStats/library/Creature.cs +++ b/ARKBreedingStats/library/Creature.cs @@ -159,8 +159,15 @@ private int[] ColorIdsAlsoPossibleSerialization get => ColorIdsAlsoPossible?.Select(i => (int)i).ToArray(); } + private DateTime? _growingUntil; + [JsonProperty] - public DateTime? growingUntil; + public DateTime? growingUntil + { + set => _growingUntil = value; + get => growingPaused ? DateTime.Now.Add(growingLeft) : _growingUntil; + } + public TimeSpan growingLeft; [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public bool growingPaused; @@ -462,13 +469,13 @@ private void PauseMaturationTimer() { if (!growingPaused) { - growingPaused = true; growingLeft = growingUntil?.Subtract(DateTime.Now) ?? TimeSpan.Zero; if (growingLeft.Ticks <= 0) { growingLeft = TimeSpan.Zero; growingUntil = null; } + growingPaused = true; } } From f48ee8c5a5caccd2b7c060a2547fba665340d8b1 Mon Sep 17 00:00:00 2001 From: cadon Date: Sun, 11 Dec 2022 19:08:19 +0100 Subject: [PATCH 09/10] keep timer paused when changing grow time --- ARKBreedingStats/Form1.tester.cs | 1 - ARKBreedingStats/library/Creature.cs | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ARKBreedingStats/Form1.tester.cs b/ARKBreedingStats/Form1.tester.cs index 5b3660371..2d1273c77 100644 --- a/ARKBreedingStats/Form1.tester.cs +++ b/ARKBreedingStats/Form1.tester.cs @@ -219,7 +219,6 @@ private void creatureInfoInputTester_Save2Library_Clicked(CreatureInfoInput send if (newGrownUpAt != null && _creatureTesterEdit.growingUntil != newGrownUpAt) { raisingControl1.RecreateList(); - _creatureTesterEdit.StartStopMatureTimer(true); } SetTesterInfoInputCreature(); diff --git a/ARKBreedingStats/library/Creature.cs b/ARKBreedingStats/library/Creature.cs index f3dc69a1f..dbfa8443c 100644 --- a/ARKBreedingStats/library/Creature.cs +++ b/ARKBreedingStats/library/Creature.cs @@ -164,7 +164,13 @@ private int[] ColorIdsAlsoPossibleSerialization [JsonProperty] public DateTime? growingUntil { - set => _growingUntil = value; + set + { + if (growingPaused && value != null) + growingLeft = value.Value.Subtract(DateTime.Now); + else + _growingUntil = value; + } get => growingPaused ? DateTime.Now.Add(growingLeft) : _growingUntil; } From 39d8dd6c3133af6f78d0182c057260f2a7fbfea8 Mon Sep 17 00:00:00 2001 From: cadon Date: Sun, 11 Dec 2022 19:24:48 +0100 Subject: [PATCH 10/10] ver --- ARKBreedingStats/Properties/AssemblyInfo.cs | 2 +- ARKBreedingStats/_manifest.json | 2 +- ARKBreedingStats/json/values/_manifest.json | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ARKBreedingStats/Properties/AssemblyInfo.cs b/ARKBreedingStats/Properties/AssemblyInfo.cs index a92ab41f6..ba3e6990c 100644 --- a/ARKBreedingStats/Properties/AssemblyInfo.cs +++ b/ARKBreedingStats/Properties/AssemblyInfo.cs @@ -30,6 +30,6 @@ // Revision // [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("0.50.7.0")] +[assembly: AssemblyFileVersion("0.50.8.0")] [assembly: NeutralResourcesLanguage("en")] diff --git a/ARKBreedingStats/_manifest.json b/ARKBreedingStats/_manifest.json index ec42f75df..09be4a9dd 100644 --- a/ARKBreedingStats/_manifest.json +++ b/ARKBreedingStats/_manifest.json @@ -4,7 +4,7 @@ "ARK Smart Breeding": { "Id": "ARK Smart Breeding", "Category": "main", - "version": "0.50.7.0" + "version": "0.50.8.0" }, "SpeciesColorImages": { "Id": "SpeciesColorImages", diff --git a/ARKBreedingStats/json/values/_manifest.json b/ARKBreedingStats/json/values/_manifest.json index 48a4430b9..4de1620c3 100644 --- a/ARKBreedingStats/json/values/_manifest.json +++ b/ARKBreedingStats/json/values/_manifest.json @@ -35,7 +35,7 @@ "mod": { "id": "1139775728", "tag": "Confuciusornis", "title": "Confuciusornis" } }, "1169020368-Trex.json": { - "version": "354.4.1669539497", + "version": "354.6.1670659701", "mod": { "id": "1169020368", "tag": "Trex", "title": "Ark Creature Rebalance (AG Reborn)" } }, "1178308359-ShadDragon.json": { @@ -235,7 +235,7 @@ "mod": { "id": "2000326197", "tag": "ExtraResources", "title": "Event Assets" } }, "2003934830-Beasts.json": { - "version": "354.4.1669867458", + "version": "354.4.1670199617", "mod": { "id": "2003934830", "tag": "Beasts", "title": "Prehistoric Beasts" } }, "2019846325-ApexMod.json": { @@ -263,7 +263,7 @@ "mod": { "id": "2135314513", "tag": "CI_Dinos", "title": "Crystal Isles Dino Addition" } }, "2447186973-ArkOmega.json": { - "version": "351.6.1667016777", + "version": "354.6.1670707999", "mod": { "id": "2447186973", "tag": "ArkOmega", "title": "Ark Omega" } }, "2869411055-SDinoVariants.json": {