Skip box name repop if same names

This commit is contained in:
Kurt 2023-05-05 00:08:26 -07:00
parent 68c94a93b2
commit 8e177708b7
2 changed files with 35 additions and 6 deletions

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
@ -149,15 +150,43 @@ public partial class BoxEditor : UserControl, ISlotViewer<PictureBox>
if (!SAV.HasBox) if (!SAV.HasBox)
return; return;
CB_BoxSelect.Items.Clear(); var currentIndex = CurrentBox;
CB_BoxSelect.Items.AddRange(BoxUtil.GetBoxNames(SAV)); var update = BoxUtil.GetBoxNames(SAV);
var current = CB_BoxSelect.Items;
if (!GetIsSame(update, current))
{
// try to keep list elements if same length
if (update.Length == current.Count)
{
for (int i = 0; i < update.Length; i++)
current[i] = update[i];
}
else // rebuild completely
{
current.Clear();
current.AddRange(update);
}
}
if (box < 0 && (uint)SAV.CurrentBox < CB_BoxSelect.Items.Count) if (box < 0)
CurrentBox = SAV.CurrentBox; // restore selected box box = currentIndex;
else box = Math.Clamp(box, 0, current.Count - 1);
if (box != CurrentBox)
CurrentBox = box; CurrentBox = box;
} }
private static bool GetIsSame(IReadOnlyList<string> a, IList b)
{
if (a.Count != b.Count)
return false;
for (int i = 0; i < a.Count; i++)
{
if (b[i] is not string s || s != a[i])
return false;
}
return true;
}
public void ResetSlots() public void ResetSlots()
{ {
Editor.Reload(); Editor.Reload();

View file

@ -84,6 +84,6 @@ namespace PKHeX.WinForms
private System.Windows.Forms.Label L_Site; private System.Windows.Forms.Label L_Site;
private System.Windows.Forms.PictureBox PB_Icon; private System.Windows.Forms.PictureBox PB_Icon;
public System.Windows.Forms.Label L_Status; private System.Windows.Forms.Label L_Status;
} }
} }