Update encounter search

Add version specific search or all compatible
Add encounter type checkboxes (others are ignored)
Only return distinct encounters (by reference)
Refresh Checksum from generated iencounterable->pk before converting (to
eventually be fixed in iencounterable rewrite maybe)
Closes #2219
This commit is contained in:
Kurt 2018-12-30 17:33:31 -08:00
parent bd56999b20
commit e7f7e3dc3f
2 changed files with 299 additions and 225 deletions

View file

@ -123,6 +123,8 @@
this.TLP_Filters = new System.Windows.Forms.TableLayoutPanel();
this.FLP_Level = new System.Windows.Forms.FlowLayoutPanel();
this.RTB_Instructions = new System.Windows.Forms.RichTextBox();
this.L_Version = new System.Windows.Forms.Label();
this.CB_GameOrigin = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.bpkx30)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bpkx29)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bpkx28)).BeginInit();
@ -192,7 +194,6 @@
((System.ComponentModel.ISupportInitialize)(this.bpkx63)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bpkx62)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bpkx61)).BeginInit();
this.FLP_Egg.SuspendLayout();
this.TLP_Filters.SuspendLayout();
this.SuspendLayout();
//
@ -1082,7 +1083,7 @@
this.CB_Species.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CB_Species.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CB_Species.FormattingEnabled = true;
this.CB_Species.Location = new System.Drawing.Point(54, 17);
this.CB_Species.Location = new System.Drawing.Point(69, 17);
this.CB_Species.Margin = new System.Windows.Forms.Padding(0);
this.CB_Species.Name = "CB_Species";
this.CB_Species.Size = new System.Drawing.Size(122, 21);
@ -1094,7 +1095,7 @@
this.CB_Move4.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CB_Move4.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CB_Move4.FormattingEnabled = true;
this.CB_Move4.Location = new System.Drawing.Point(54, 101);
this.CB_Move4.Location = new System.Drawing.Point(69, 101);
this.CB_Move4.Margin = new System.Windows.Forms.Padding(0);
this.CB_Move4.Name = "CB_Move4";
this.CB_Move4.Size = new System.Drawing.Size(122, 21);
@ -1106,7 +1107,7 @@
this.CB_Move3.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CB_Move3.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CB_Move3.FormattingEnabled = true;
this.CB_Move3.Location = new System.Drawing.Point(54, 80);
this.CB_Move3.Location = new System.Drawing.Point(69, 80);
this.CB_Move3.Margin = new System.Windows.Forms.Padding(0);
this.CB_Move3.Name = "CB_Move3";
this.CB_Move3.Size = new System.Drawing.Size(122, 21);
@ -1118,7 +1119,7 @@
this.CB_Move2.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CB_Move2.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CB_Move2.FormattingEnabled = true;
this.CB_Move2.Location = new System.Drawing.Point(54, 59);
this.CB_Move2.Location = new System.Drawing.Point(69, 59);
this.CB_Move2.Margin = new System.Windows.Forms.Padding(0);
this.CB_Move2.Name = "CB_Move2";
this.CB_Move2.Size = new System.Drawing.Size(122, 21);
@ -1130,7 +1131,7 @@
this.CB_Move1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.CB_Move1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.CB_Move1.FormattingEnabled = true;
this.CB_Move1.Location = new System.Drawing.Point(54, 38);
this.CB_Move1.Location = new System.Drawing.Point(69, 38);
this.CB_Move1.Margin = new System.Windows.Forms.Padding(0);
this.CB_Move1.Name = "CB_Move1";
this.CB_Move1.Size = new System.Drawing.Size(122, 21);
@ -1140,7 +1141,7 @@
//
this.Label_Species.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.Label_Species.AutoSize = true;
this.Label_Species.Location = new System.Drawing.Point(3, 21);
this.Label_Species.Location = new System.Drawing.Point(18, 21);
this.Label_Species.Margin = new System.Windows.Forms.Padding(3);
this.Label_Species.Name = "Label_Species";
this.Label_Species.Size = new System.Drawing.Size(48, 13);
@ -1163,7 +1164,7 @@
//
this.L_Move1.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.L_Move1.AutoSize = true;
this.L_Move1.Location = new System.Drawing.Point(5, 42);
this.L_Move1.Location = new System.Drawing.Point(20, 42);
this.L_Move1.Margin = new System.Windows.Forms.Padding(3);
this.L_Move1.Name = "L_Move1";
this.L_Move1.Size = new System.Drawing.Size(46, 13);
@ -1175,7 +1176,7 @@
//
this.L_Move2.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.L_Move2.AutoSize = true;
this.L_Move2.Location = new System.Drawing.Point(5, 63);
this.L_Move2.Location = new System.Drawing.Point(20, 63);
this.L_Move2.Margin = new System.Windows.Forms.Padding(3);
this.L_Move2.Name = "L_Move2";
this.L_Move2.Size = new System.Drawing.Size(46, 13);
@ -1187,7 +1188,7 @@
//
this.L_Move3.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.L_Move3.AutoSize = true;
this.L_Move3.Location = new System.Drawing.Point(5, 84);
this.L_Move3.Location = new System.Drawing.Point(20, 84);
this.L_Move3.Margin = new System.Windows.Forms.Padding(3);
this.L_Move3.Name = "L_Move3";
this.L_Move3.Size = new System.Drawing.Size(46, 13);
@ -1199,7 +1200,7 @@
//
this.L_Move4.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.L_Move4.AutoSize = true;
this.L_Move4.Location = new System.Drawing.Point(5, 105);
this.L_Move4.Location = new System.Drawing.Point(20, 105);
this.L_Move4.Margin = new System.Windows.Forms.Padding(3);
this.L_Move4.Name = "L_Move4";
this.L_Move4.Size = new System.Drawing.Size(46, 13);
@ -1240,11 +1241,10 @@
//
this.FLP_Egg.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.FLP_Egg.AutoSize = true;
this.FLP_Egg.Controls.Add(this.CHK_IsEgg);
this.FLP_Egg.Location = new System.Drawing.Point(54, 0);
this.FLP_Egg.Location = new System.Drawing.Point(0, 8);
this.FLP_Egg.Margin = new System.Windows.Forms.Padding(0);
this.FLP_Egg.Name = "FLP_Egg";
this.FLP_Egg.Size = new System.Drawing.Size(45, 17);
this.FLP_Egg.Size = new System.Drawing.Size(0, 0);
this.FLP_Egg.TabIndex = 120;
//
// CHK_IsEgg
@ -1253,7 +1253,7 @@
this.CHK_IsEgg.AutoSize = true;
this.CHK_IsEgg.Checked = true;
this.CHK_IsEgg.CheckState = System.Windows.Forms.CheckState.Indeterminate;
this.CHK_IsEgg.Location = new System.Drawing.Point(0, 0);
this.CHK_IsEgg.Location = new System.Drawing.Point(69, 0);
this.CHK_IsEgg.Margin = new System.Windows.Forms.Padding(0);
this.CHK_IsEgg.Name = "CHK_IsEgg";
this.CHK_IsEgg.Size = new System.Drawing.Size(45, 17);
@ -1273,7 +1273,6 @@
this.TLP_Filters.ColumnCount = 2;
this.TLP_Filters.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.TLP_Filters.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.TLP_Filters.Controls.Add(this.FLP_Egg, 1, 0);
this.TLP_Filters.Controls.Add(this.Label_Species, 0, 1);
this.TLP_Filters.Controls.Add(this.CB_Species, 1, 1);
this.TLP_Filters.Controls.Add(this.FLP_Level, 1, 5);
@ -1285,9 +1284,13 @@
this.TLP_Filters.Controls.Add(this.CB_Move3, 1, 11);
this.TLP_Filters.Controls.Add(this.L_Move4, 0, 12);
this.TLP_Filters.Controls.Add(this.CB_Move4, 1, 12);
this.TLP_Filters.Controls.Add(this.CHK_IsEgg, 1, 0);
this.TLP_Filters.Controls.Add(this.CB_GameOrigin, 1, 16);
this.TLP_Filters.Controls.Add(this.FLP_Egg, 0, 0);
this.TLP_Filters.Controls.Add(this.L_Version, 0, 16);
this.TLP_Filters.Location = new System.Drawing.Point(304, 16);
this.TLP_Filters.Name = "TLP_Filters";
this.TLP_Filters.RowCount = 17;
this.TLP_Filters.RowCount = 18;
this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle());
@ -1305,6 +1308,7 @@
this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.TLP_Filters.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.TLP_Filters.Size = new System.Drawing.Size(228, 359);
this.TLP_Filters.TabIndex = 118;
//
@ -1312,7 +1316,7 @@
//
this.FLP_Level.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.FLP_Level.AutoSize = true;
this.FLP_Level.Location = new System.Drawing.Point(54, 38);
this.FLP_Level.Location = new System.Drawing.Point(69, 38);
this.FLP_Level.Margin = new System.Windows.Forms.Padding(0);
this.FLP_Level.Name = "FLP_Level";
this.FLP_Level.Size = new System.Drawing.Size(0, 0);
@ -1328,6 +1332,29 @@
this.RTB_Instructions.TabIndex = 119;
this.RTB_Instructions.Text = "";
//
// L_Version
//
this.L_Version.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.L_Version.AutoSize = true;
this.L_Version.Location = new System.Drawing.Point(3, 126);
this.L_Version.Margin = new System.Windows.Forms.Padding(3);
this.L_Version.Name = "L_Version";
this.L_Version.Size = new System.Drawing.Size(63, 13);
this.L_Version.TabIndex = 122;
this.L_Version.Text = "OT Version:";
this.L_Version.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// CB_GameOrigin
//
this.CB_GameOrigin.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.CB_GameOrigin.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CB_GameOrigin.FormattingEnabled = true;
this.CB_GameOrigin.Location = new System.Drawing.Point(69, 122);
this.CB_GameOrigin.Margin = new System.Windows.Forms.Padding(0);
this.CB_GameOrigin.Name = "CB_GameOrigin";
this.CB_GameOrigin.Size = new System.Drawing.Size(122, 21);
this.CB_GameOrigin.TabIndex = 121;
//
// SAV_Encounters
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -1420,8 +1447,6 @@
((System.ComponentModel.ISupportInitialize)(this.bpkx63)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bpkx62)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bpkx61)).EndInit();
this.FLP_Egg.ResumeLayout(false);
this.FLP_Egg.PerformLayout();
this.TLP_Filters.ResumeLayout(false);
this.TLP_Filters.PerformLayout();
this.ResumeLayout(false);
@ -1525,5 +1550,7 @@
private System.Windows.Forms.FlowLayoutPanel FLP_Level;
private System.Windows.Forms.RichTextBox RTB_Instructions;
private System.Windows.Forms.ToolStripMenuItem Menu_SearchAdvanced;
private System.Windows.Forms.ComboBox CB_GameOrigin;
private System.Windows.Forms.Label L_Version;
}
}

View file

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows.Forms;
using static PKHeX.Core.MessageStrings;
@ -22,7 +23,6 @@ namespace PKHeX.WinForms
ToolStripMenuItem mnuView = new ToolStripMenuItem {Name = "mnuView", Text = "View"};
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
ContextMenuStrip mnu = new ContextMenuStrip();
mnu.Items.AddRange(new ToolStripItem[] { mnuView });
@ -70,6 +70,10 @@ namespace PKHeX.WinForms
foreach (PictureBox p in PKXBOXES)
p.ContextMenuStrip = mnu;
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
TLP_Filters.Controls.Add(TypeFilters = GetTypeFilters(), 2, TLP_Filters.RowCount - 1);
// Load Data
L_Count.Text = "Ready...";
@ -81,6 +85,34 @@ namespace PKHeX.WinForms
CenterToParent();
}
private static FlowLayoutPanel GetTypeFilters()
{
var flp = new FlowLayoutPanel { Dock = DockStyle.Fill };
var types = (EncounterOrder[])Enum.GetValues(typeof(EncounterOrder));
var checks = types.Select(z => new CheckBox
{
Name = z.ToString(),
Text = z.ToString(),
AutoSize = true,
Checked = true,
Padding = Padding.Empty,
Margin = Padding.Empty,
}).ToArray();
foreach (var chk in checks)
{
flp.Controls.Add(chk);
flp.SetFlowBreak(chk, true);
}
flp.AutoSize = true;
return flp;
}
private EncounterOrder[] GetTypes()
{
return TypeFilters.Controls.OfType<CheckBox>().Where(z => z.Checked).Select(z => z.Name)
.Select(z => (EncounterOrder)Enum.Parse(typeof(EncounterOrder), z)).ToArray();
}
private readonly PictureBox[] PKXBOXES;
private List<IEncounterable> Results;
private int slotSelected = -1; // = null;
@ -88,7 +120,7 @@ namespace PKHeX.WinForms
private const int RES_MAX = 66;
private const int RES_MIN = 6;
private readonly string Counter;
private const int MAXFORMAT = PKX.Generation;
private readonly FlowLayoutPanel TypeFilters;
// Important Events
private void ClickView(object sender, EventArgs e)
@ -107,7 +139,10 @@ namespace PKHeX.WinForms
return;
}
PKME_Tabs.PopulateFields(Results[index].ConvertToPKM(SAV), false);
var enc = Results[index];
var pk = enc.ConvertToPKM(SAV);
pk.RefreshChecksum();
PKME_Tabs.PopulateFields(pk, false);
slotSelected = index;
slotColor = Properties.Resources.slotView;
FillPKXBoxes(SCR_Box.Value);
@ -117,6 +152,7 @@ namespace PKHeX.WinForms
{
// Set the Text
CB_Species.InitializeBinding();
CB_GameOrigin.InitializeBinding();
var Any = new ComboItem {Text = MsgAny, Value = -1};
@ -134,6 +170,9 @@ namespace PKHeX.WinForms
}
}
var DS_Version = new List<ComboItem>(GameInfo.VersionDataSource);
DS_Version.Insert(0, Any); CB_GameOrigin.DataSource = DS_Version;
// Trigger a Reset
ResetFilters(null, null);
}
@ -141,10 +180,12 @@ namespace PKHeX.WinForms
private void ResetFilters(object sender, EventArgs e)
{
CB_Species.SelectedIndex = 0;
CB_Move1.SelectedIndex = CB_Move2.SelectedIndex = CB_Move3.SelectedIndex = CB_Move4.SelectedIndex = 0;
CB_GameOrigin.SelectedIndex = 0;
RTB_Instructions.Clear();
foreach (var chk in TypeFilters.Controls.OfType<CheckBox>())
chk.Checked = true;
if (sender != null)
System.Media.SystemSounds.Asterisk.Play();
@ -159,22 +200,25 @@ namespace PKHeX.WinForms
var pk = SAV.BlankPKM;
var species = settings.Species <= 0 ? Enumerable.Range(1, SAV.MaxSpeciesID) : new[] { settings.Species };
var results = species.SelectMany(z => GetEncounters(z, moves, pk));
var versions = settings.GetVersions(SAV);
var results = species.SelectMany(z => GetEncounters(z, moves, pk, versions));
if (settings.SearchEgg != null)
results = results.Where(z => z.EggEncounter == settings.SearchEgg);
// return filtered results
return results;
var comparer = new ReferenceComparer<IEncounterable>();
return results.Distinct(comparer); // only distinct objects
}
private IEnumerable<IEncounterable> GetEncounters(int species, int[] moves, PKM pk)
private class ReferenceComparer<T> : IEqualityComparer<T>
{
public bool Equals(T x, T y) => RuntimeHelpers.GetHashCode(x).Equals(RuntimeHelpers.GetHashCode(y));
public int GetHashCode(T obj) => RuntimeHelpers.GetHashCode(obj);
}
private static IEnumerable<IEncounterable> GetEncounters(int species, int[] moves, PKM pk, GameVersion[] vers)
{
pk.Species = species;
var parent = GameUtil.GetMetLocationVersionGroup(SAV.Version);
if (parent == GameVersion.Invalid)
parent = GameUtil.GetMetLocationVersionGroup(GameUtil.GetVersion(SAV.Generation));
var vers = GameUtil.GameVersions.Where(z => parent.Contains(z)).ToArray();
return EncounterMovesetGenerator.GenerateEncounters(pk, moves, vers);
}
@ -188,6 +232,7 @@ namespace PKHeX.WinForms
Species = WinFormsUtil.GetIndex(CB_Species),
BatchInstructions = RTB_Instructions.Lines,
Version = WinFormsUtil.GetIndex(CB_GameOrigin),
};
settings.AddMove(WinFormsUtil.GetIndex(CB_Move1));
@ -204,6 +249,7 @@ namespace PKHeX.WinForms
private async void B_Search_Click(object sender, EventArgs e)
{
B_Search.Enabled = false;
EncounterMovesetGenerator.PriorityList = GetTypes();
var search = SearchDatabase();
var results = await Task.Run(() => search.ToList()).ConfigureAwait(true);
@ -214,6 +260,7 @@ namespace PKHeX.WinForms
SetResults(results); // updates Count Label as well.
System.Media.SystemSounds.Asterisk.Play();
B_Search.Enabled = true;
EncounterMovesetGenerator.ResetFilters();
}
private void UpdateScroll(object sender, ScrollEventArgs e)