mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-10-01 23:48:40 -05:00
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:
844
PKHeX.WinForms/Controls/PKM Editor/PKMEditor.Designer.cs
generated
844
PKHeX.WinForms/Controls/PKM Editor/PKMEditor.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
@@ -267,6 +267,8 @@ public void UpdateLegality(LegalityAnalysis la = null, bool skipMoveRepop = fals
|
||||
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 @@ private void ReloadMoves(IReadOnlyCollection<int> moves)
|
||||
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 @@ private void ValidateMovePaint(object sender, DrawItemEventArgs e)
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user