mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-04 01:39:13 +00:00
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:
parent
bd56999b20
commit
e7f7e3dc3f
2 changed files with 299 additions and 225 deletions
453
PKHeX.WinForms/Subforms/SAV_Encounters.Designer.cs
generated
453
PKHeX.WinForms/Subforms/SAV_Encounters.Designer.cs
generated
File diff suppressed because it is too large
Load diff
|
@ -5,6 +5,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using static PKHeX.Core.MessageStrings;
|
using static PKHeX.Core.MessageStrings;
|
||||||
|
@ -22,7 +23,6 @@ namespace PKHeX.WinForms
|
||||||
|
|
||||||
ToolStripMenuItem mnuView = new ToolStripMenuItem {Name = "mnuView", Text = "View"};
|
ToolStripMenuItem mnuView = new ToolStripMenuItem {Name = "mnuView", Text = "View"};
|
||||||
|
|
||||||
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
|
||||||
ContextMenuStrip mnu = new ContextMenuStrip();
|
ContextMenuStrip mnu = new ContextMenuStrip();
|
||||||
mnu.Items.AddRange(new ToolStripItem[] { mnuView });
|
mnu.Items.AddRange(new ToolStripItem[] { mnuView });
|
||||||
|
|
||||||
|
@ -70,6 +70,10 @@ namespace PKHeX.WinForms
|
||||||
foreach (PictureBox p in PKXBOXES)
|
foreach (PictureBox p in PKXBOXES)
|
||||||
p.ContextMenuStrip = mnu;
|
p.ContextMenuStrip = mnu;
|
||||||
|
|
||||||
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
||||||
|
|
||||||
|
TLP_Filters.Controls.Add(TypeFilters = GetTypeFilters(), 2, TLP_Filters.RowCount - 1);
|
||||||
|
|
||||||
// Load Data
|
// Load Data
|
||||||
L_Count.Text = "Ready...";
|
L_Count.Text = "Ready...";
|
||||||
|
|
||||||
|
@ -81,6 +85,34 @@ namespace PKHeX.WinForms
|
||||||
CenterToParent();
|
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 readonly PictureBox[] PKXBOXES;
|
||||||
private List<IEncounterable> Results;
|
private List<IEncounterable> Results;
|
||||||
private int slotSelected = -1; // = null;
|
private int slotSelected = -1; // = null;
|
||||||
|
@ -88,7 +120,7 @@ namespace PKHeX.WinForms
|
||||||
private const int RES_MAX = 66;
|
private const int RES_MAX = 66;
|
||||||
private const int RES_MIN = 6;
|
private const int RES_MIN = 6;
|
||||||
private readonly string Counter;
|
private readonly string Counter;
|
||||||
private const int MAXFORMAT = PKX.Generation;
|
private readonly FlowLayoutPanel TypeFilters;
|
||||||
|
|
||||||
// Important Events
|
// Important Events
|
||||||
private void ClickView(object sender, EventArgs e)
|
private void ClickView(object sender, EventArgs e)
|
||||||
|
@ -107,7 +139,10 @@ namespace PKHeX.WinForms
|
||||||
return;
|
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;
|
slotSelected = index;
|
||||||
slotColor = Properties.Resources.slotView;
|
slotColor = Properties.Resources.slotView;
|
||||||
FillPKXBoxes(SCR_Box.Value);
|
FillPKXBoxes(SCR_Box.Value);
|
||||||
|
@ -117,6 +152,7 @@ namespace PKHeX.WinForms
|
||||||
{
|
{
|
||||||
// Set the Text
|
// Set the Text
|
||||||
CB_Species.InitializeBinding();
|
CB_Species.InitializeBinding();
|
||||||
|
CB_GameOrigin.InitializeBinding();
|
||||||
|
|
||||||
var Any = new ComboItem {Text = MsgAny, Value = -1};
|
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
|
// Trigger a Reset
|
||||||
ResetFilters(null, null);
|
ResetFilters(null, null);
|
||||||
}
|
}
|
||||||
|
@ -141,10 +180,12 @@ namespace PKHeX.WinForms
|
||||||
private void ResetFilters(object sender, EventArgs e)
|
private void ResetFilters(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
CB_Species.SelectedIndex = 0;
|
CB_Species.SelectedIndex = 0;
|
||||||
|
|
||||||
CB_Move1.SelectedIndex = CB_Move2.SelectedIndex = CB_Move3.SelectedIndex = CB_Move4.SelectedIndex = 0;
|
CB_Move1.SelectedIndex = CB_Move2.SelectedIndex = CB_Move3.SelectedIndex = CB_Move4.SelectedIndex = 0;
|
||||||
|
CB_GameOrigin.SelectedIndex = 0;
|
||||||
|
|
||||||
RTB_Instructions.Clear();
|
RTB_Instructions.Clear();
|
||||||
|
foreach (var chk in TypeFilters.Controls.OfType<CheckBox>())
|
||||||
|
chk.Checked = true;
|
||||||
|
|
||||||
if (sender != null)
|
if (sender != null)
|
||||||
System.Media.SystemSounds.Asterisk.Play();
|
System.Media.SystemSounds.Asterisk.Play();
|
||||||
|
@ -159,22 +200,25 @@ namespace PKHeX.WinForms
|
||||||
var pk = SAV.BlankPKM;
|
var pk = SAV.BlankPKM;
|
||||||
|
|
||||||
var species = settings.Species <= 0 ? Enumerable.Range(1, SAV.MaxSpeciesID) : new[] { settings.Species };
|
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)
|
if (settings.SearchEgg != null)
|
||||||
results = results.Where(z => z.EggEncounter == settings.SearchEgg);
|
results = results.Where(z => z.EggEncounter == settings.SearchEgg);
|
||||||
|
|
||||||
// return filtered results
|
// 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;
|
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);
|
return EncounterMovesetGenerator.GenerateEncounters(pk, moves, vers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,6 +232,7 @@ namespace PKHeX.WinForms
|
||||||
Species = WinFormsUtil.GetIndex(CB_Species),
|
Species = WinFormsUtil.GetIndex(CB_Species),
|
||||||
|
|
||||||
BatchInstructions = RTB_Instructions.Lines,
|
BatchInstructions = RTB_Instructions.Lines,
|
||||||
|
Version = WinFormsUtil.GetIndex(CB_GameOrigin),
|
||||||
};
|
};
|
||||||
|
|
||||||
settings.AddMove(WinFormsUtil.GetIndex(CB_Move1));
|
settings.AddMove(WinFormsUtil.GetIndex(CB_Move1));
|
||||||
|
@ -204,6 +249,7 @@ namespace PKHeX.WinForms
|
||||||
private async void B_Search_Click(object sender, EventArgs e)
|
private async void B_Search_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
B_Search.Enabled = false;
|
B_Search.Enabled = false;
|
||||||
|
EncounterMovesetGenerator.PriorityList = GetTypes();
|
||||||
var search = SearchDatabase();
|
var search = SearchDatabase();
|
||||||
|
|
||||||
var results = await Task.Run(() => search.ToList()).ConfigureAwait(true);
|
var results = await Task.Run(() => search.ToList()).ConfigureAwait(true);
|
||||||
|
@ -214,6 +260,7 @@ namespace PKHeX.WinForms
|
||||||
SetResults(results); // updates Count Label as well.
|
SetResults(results); // updates Count Label as well.
|
||||||
System.Media.SystemSounds.Asterisk.Play();
|
System.Media.SystemSounds.Asterisk.Play();
|
||||||
B_Search.Enabled = true;
|
B_Search.Enabled = true;
|
||||||
|
EncounterMovesetGenerator.ResetFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateScroll(object sender, ScrollEventArgs e)
|
private void UpdateScroll(object sender, ScrollEventArgs e)
|
||||||
|
|
Loading…
Reference in a new issue