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

View file

@ -112,6 +112,7 @@
this.CHK_Shadow = new System.Windows.Forms.CheckBox();
this.FLP_ShinyLeaf = new System.Windows.Forms.FlowLayoutPanel();
this.L_ShinyLeaf = new System.Windows.Forms.Label();
this.ShinyLeaf = new PKHeX.WinForms.Controls.ShinyLeaf();
this.Tab_Met = new System.Windows.Forms.TabPage();
this.CHK_AsEgg = new System.Windows.Forms.CheckBox();
this.GB_EggConditions = new System.Windows.Forms.GroupBox();
@ -147,6 +148,8 @@
this.L_MetTimeOfDay = new System.Windows.Forms.Label();
this.CB_MetTimeOfDay = new System.Windows.Forms.ComboBox();
this.Tab_Stats = new System.Windows.Forms.TabPage();
this.Stats = new PKHeX.WinForms.Controls.StatEditor();
this.Contest = new PKHeX.WinForms.Controls.ContestStat();
this.Tab_Attacks = new System.Windows.Forms.TabPage();
this.PB_WarnMove4 = new System.Windows.Forms.PictureBox();
this.PB_WarnMove3 = new System.Windows.Forms.PictureBox();
@ -204,14 +207,11 @@
this.TB_ExtraByte = new System.Windows.Forms.MaskedTextBox();
this.CB_ExtraBytes = new System.Windows.Forms.ComboBox();
this.GB_OT = new System.Windows.Forms.GroupBox();
this.TID_Trainer = new PKHeX.WinForms.Controls.TrainerID();
this.Label_OTGender = new System.Windows.Forms.Label();
this.TB_OT = new System.Windows.Forms.TextBox();
this.Label_OT = new System.Windows.Forms.Label();
this.Label_EncryptionConstant = new System.Windows.Forms.Label();
this.ShinyLeaf = new PKHeX.WinForms.Controls.ShinyLeaf();
this.Stats = new PKHeX.WinForms.Controls.StatEditor();
this.Contest = new PKHeX.WinForms.Controls.ContestStat();
this.TID_Trainer = new PKHeX.WinForms.Controls.TrainerID();
this.tabMain.SuspendLayout();
this.Tab_Main.SuspendLayout();
this.FLP_Main.SuspendLayout();
@ -1316,6 +1316,15 @@
this.L_ShinyLeaf.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.L_ShinyLeaf.Click += new System.EventHandler(this.ClickShinyLeaf);
//
// ShinyLeaf
//
this.ShinyLeaf.Location = new System.Drawing.Point(110, 0);
this.ShinyLeaf.Margin = new System.Windows.Forms.Padding(0);
this.ShinyLeaf.Name = "ShinyLeaf";
this.ShinyLeaf.Size = new System.Drawing.Size(140, 56);
this.ShinyLeaf.TabIndex = 116;
this.ShinyLeaf.Value = 0;
//
// Tab_Met
//
this.Tab_Met.AllowDrop = true;
@ -1325,7 +1334,7 @@
this.Tab_Met.Location = new System.Drawing.Point(4, 22);
this.Tab_Met.Name = "Tab_Met";
this.Tab_Met.Padding = new System.Windows.Forms.Padding(3);
this.Tab_Met.Size = new System.Drawing.Size(272, 462);
this.Tab_Met.Size = new System.Drawing.Size(192, 74);
this.Tab_Met.TabIndex = 1;
this.Tab_Met.Text = "Met";
this.Tab_Met.UseVisualStyleBackColor = true;
@ -1716,11 +1725,38 @@
this.Tab_Stats.Location = new System.Drawing.Point(4, 22);
this.Tab_Stats.Name = "Tab_Stats";
this.Tab_Stats.Padding = new System.Windows.Forms.Padding(3);
this.Tab_Stats.Size = new System.Drawing.Size(272, 462);
this.Tab_Stats.Size = new System.Drawing.Size(192, 74);
this.Tab_Stats.TabIndex = 2;
this.Tab_Stats.Text = "Stats";
this.Tab_Stats.UseVisualStyleBackColor = true;
//
// Stats
//
this.Stats.EVsFishy = System.Drawing.Color.LightYellow;
this.Stats.EVsInvalid = System.Drawing.Color.Red;
this.Stats.EVsMaxed = System.Drawing.Color.Honeydew;
this.Stats.Location = new System.Drawing.Point(0, 0);
this.Stats.Name = "Stats";
this.Stats.Size = new System.Drawing.Size(270, 240);
this.Stats.StatDecreased = System.Drawing.Color.Blue;
this.Stats.StatHyperTrained = System.Drawing.Color.LightGreen;
this.Stats.StatIncreased = System.Drawing.Color.Red;
this.Stats.TabIndex = 118;
//
// Contest
//
this.Contest.CNT_Beauty = 0;
this.Contest.CNT_Cool = 0;
this.Contest.CNT_Cute = 0;
this.Contest.CNT_Sheen = 0;
this.Contest.CNT_Smart = 0;
this.Contest.CNT_Tough = 0;
this.Contest.Location = new System.Drawing.Point(21, 247);
this.Contest.Margin = new System.Windows.Forms.Padding(0);
this.Contest.Name = "Contest";
this.Contest.Size = new System.Drawing.Size(230, 50);
this.Contest.TabIndex = 117;
//
// Tab_Attacks
//
this.Tab_Attacks.AllowDrop = true;
@ -2025,6 +2061,7 @@
this.CB_Move4.Size = new System.Drawing.Size(121, 21);
this.CB_Move4.TabIndex = 10;
this.CB_Move4.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ValidateMovePaint);
this.CB_Move4.DropDown += new System.EventHandler(this.ValidateMoveDropDown);
this.CB_Move4.SelectedIndexChanged += new System.EventHandler(this.ValidateMove);
this.CB_Move4.Leave += new System.EventHandler(this.ValidateComboBox2);
this.CB_Move4.Validating += new System.ComponentModel.CancelEventHandler(this.ValidateComboBox);
@ -2055,6 +2092,7 @@
this.CB_Move3.Size = new System.Drawing.Size(121, 21);
this.CB_Move3.TabIndex = 7;
this.CB_Move3.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ValidateMovePaint);
this.CB_Move3.DropDown += new System.EventHandler(this.ValidateMoveDropDown);
this.CB_Move3.SelectedIndexChanged += new System.EventHandler(this.ValidateMove);
this.CB_Move3.Leave += new System.EventHandler(this.ValidateComboBox2);
this.CB_Move3.Validating += new System.ComponentModel.CancelEventHandler(this.ValidateComboBox);
@ -2070,6 +2108,7 @@
this.CB_Move2.Size = new System.Drawing.Size(121, 21);
this.CB_Move2.TabIndex = 4;
this.CB_Move2.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ValidateMovePaint);
this.CB_Move2.DropDown += new System.EventHandler(this.ValidateMoveDropDown);
this.CB_Move2.SelectedIndexChanged += new System.EventHandler(this.ValidateMove);
this.CB_Move2.Leave += new System.EventHandler(this.ValidateComboBox2);
this.CB_Move2.Validating += new System.ComponentModel.CancelEventHandler(this.ValidateComboBox);
@ -2085,6 +2124,7 @@
this.CB_Move1.Size = new System.Drawing.Size(121, 21);
this.CB_Move1.TabIndex = 1;
this.CB_Move1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ValidateMovePaint);
this.CB_Move1.DropDown += new System.EventHandler(this.ValidateMoveDropDown);
this.CB_Move1.SelectedIndexChanged += new System.EventHandler(this.ValidateMove);
this.CB_Move1.Leave += new System.EventHandler(this.ValidateComboBox2);
this.CB_Move1.Validating += new System.ComponentModel.CancelEventHandler(this.ValidateComboBox);
@ -2103,7 +2143,7 @@
this.Tab_OTMisc.Location = new System.Drawing.Point(4, 22);
this.Tab_OTMisc.Name = "Tab_OTMisc";
this.Tab_OTMisc.Padding = new System.Windows.Forms.Padding(3);
this.Tab_OTMisc.Size = new System.Drawing.Size(272, 462);
this.Tab_OTMisc.Size = new System.Drawing.Size(192, 74);
this.Tab_OTMisc.TabIndex = 4;
this.Tab_OTMisc.Text = "OT/Misc";
this.Tab_OTMisc.UseVisualStyleBackColor = true;
@ -2449,6 +2489,13 @@
this.GB_OT.TabStop = false;
this.GB_OT.Text = "Trainer Information";
//
// TID_Trainer
//
this.TID_Trainer.Location = new System.Drawing.Point(13, 18);
this.TID_Trainer.Name = "TID_Trainer";
this.TID_Trainer.Size = new System.Drawing.Size(178, 27);
this.TID_Trainer.TabIndex = 57;
//
// Label_OTGender
//
this.Label_OTGender.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
@ -2489,43 +2536,6 @@
this.Label_EncryptionConstant.Text = "Encryption Constant:";
this.Label_EncryptionConstant.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// ShinyLeaf
//
this.ShinyLeaf.Location = new System.Drawing.Point(110, 0);
this.ShinyLeaf.Margin = new System.Windows.Forms.Padding(0);
this.ShinyLeaf.Name = "ShinyLeaf";
this.ShinyLeaf.Size = new System.Drawing.Size(140, 56);
this.ShinyLeaf.TabIndex = 116;
this.ShinyLeaf.Value = 0;
//
// Stats
//
this.Stats.Location = new System.Drawing.Point(0, 0);
this.Stats.Name = "Stats";
this.Stats.Size = new System.Drawing.Size(270, 240);
this.Stats.TabIndex = 118;
//
// Contest
//
this.Contest.CNT_Beauty = 0;
this.Contest.CNT_Cool = 0;
this.Contest.CNT_Cute = 0;
this.Contest.CNT_Sheen = 0;
this.Contest.CNT_Smart = 0;
this.Contest.CNT_Tough = 0;
this.Contest.Location = new System.Drawing.Point(21, 247);
this.Contest.Margin = new System.Windows.Forms.Padding(0);
this.Contest.Name = "Contest";
this.Contest.Size = new System.Drawing.Size(230, 50);
this.Contest.TabIndex = 117;
//
// TID_Trainer
//
this.TID_Trainer.Location = new System.Drawing.Point(13, 18);
this.TID_Trainer.Name = "TID_Trainer";
this.TID_Trainer.Size = new System.Drawing.Size(178, 27);
this.TID_Trainer.TabIndex = 57;
//
// PKMEditor
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;

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);