mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 12:33:06 +00: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:
parent
0ee9b04bf7
commit
0745ba3294
2 changed files with 455 additions and 426 deletions
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 @@ 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);
|
||||
|
|
Loading…
Reference in a new issue