Defer move combobox repop until dropdown

Yay sneaky smart solutions!
Instead of refilling the combobox when the legal move list changes, wait
until the full list is required then repopulate the individual combobox
can't even notice the lag besides the individual tab load. yess
This commit is contained in:
Kurt 2018-08-01 21:57:15 -07:00
parent 0ee9b04bf7
commit 0745ba3294
2 changed files with 455 additions and 426 deletions

File diff suppressed because it is too large Load diff

View file

@ -267,6 +267,8 @@ namespace PKHeX.WinForms.Controls
LegalityChanged?.Invoke(Legality.Valid, null);
}
private List<ComboItem> MoveDataAllowed = new List<ComboItem>();
private void ReloadMoves(IReadOnlyCollection<int> moves)
{
// check prior movepool to not needlessly refresh the dataset
@ -274,15 +276,20 @@ namespace PKHeX.WinForms.Controls
return;
AllowedMoves = new HashSet<int>(moves);
var moveList = GameInfo.Strings.MoveDataSource.OrderByDescending(m => AllowedMoves.Contains(m.Value)).ToList();
foreach (var c in Moves)
{
var index = WinFormsUtil.GetIndex(c);
c.DataSource = new BindingSource(moveList, null);
c.SelectedValue = index;
if (c.Visible)
c.SelectionLength = 0; // flicker hack
}
MoveDataAllowed = GameInfo.Strings.MoveDataSource.OrderByDescending(m => AllowedMoves.Contains(m.Value)).ToList();
// defer repop until dropdown is opened; handled by dropdown event
for (int i = 0; i < IsMoveBoxOrdered.Count; i++)
IsMoveBoxOrdered[i] = false;
}
private void SetMoveDataSource(ComboBox c)
{
var index = WinFormsUtil.GetIndex(c);
c.DataSource = new BindingSource(MoveDataAllowed, null);
c.SelectedValue = index;
if (c.Visible)
c.SelectionLength = 0; // flicker hack
}
public void UpdateUnicode(string[] symbols)
@ -1501,6 +1508,18 @@ namespace PKHeX.WinForms.Controls
e.Graphics.DrawString(i.Text, e.Font, tBrush, e.Bounds, StringFormat.GenericDefault);
}
private readonly IList<bool> IsMoveBoxOrdered = new bool[4];
private void ValidateMoveDropDown(object sender, EventArgs e)
{
var s = (ComboBox) sender;
var index = Array.IndexOf(Moves, s);
if (IsMoveBoxOrdered[index])
return;
SetMoveDataSource(s);
IsMoveBoxOrdered[index] = true;
}
private void ValidateLocation(object sender, EventArgs e)
{
ValidateComboBox(sender);