2022-06-28 02:59:36 +00:00
|
|
|
using PKHeX.Core;
|
2018-11-11 04:23:21 +00:00
|
|
|
using PKHeX.Core.Searching;
|
|
|
|
using PKHeX.WinForms.Controls;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Linq;
|
2018-12-31 01:33:31 +00:00
|
|
|
using System.Runtime.CompilerServices;
|
2022-05-07 16:25:59 +00:00
|
|
|
using System.Threading;
|
2018-11-11 04:23:21 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Windows.Forms;
|
2021-11-27 23:48:08 +00:00
|
|
|
using PKHeX.Drawing.PokeSprite;
|
2019-09-29 16:47:06 +00:00
|
|
|
using PKHeX.WinForms.Properties;
|
2018-11-11 04:23:21 +00:00
|
|
|
using static PKHeX.Core.MessageStrings;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.WinForms;
|
|
|
|
|
|
|
|
public partial class SAV_Encounters : Form
|
2018-11-11 04:23:21 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
private readonly PKMEditor PKME_Tabs;
|
|
|
|
private SaveFile SAV => PKME_Tabs.RequestSaveFile;
|
|
|
|
private readonly SummaryPreviewer ShowSet = new();
|
|
|
|
private readonly TrainerDatabase Trainers;
|
|
|
|
private readonly CancellationTokenSource TokenSource = new();
|
2022-09-17 09:00:06 +00:00
|
|
|
private readonly EntityInstructionBuilder UC_Builder;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public SAV_Encounters(PKMEditor f1, TrainerDatabase db)
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
2022-08-20 17:43:04 +00:00
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
2022-09-17 09:00:06 +00:00
|
|
|
UC_Builder = new EntityInstructionBuilder(() => f1.PreparePKM())
|
2022-06-28 02:59:36 +00:00
|
|
|
{
|
|
|
|
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
|
|
|
|
Width = Tab_Advanced.Width,
|
|
|
|
Dock = DockStyle.Top,
|
|
|
|
ReadOnly = true,
|
|
|
|
};
|
|
|
|
Tab_Advanced.Controls.Add(UC_Builder);
|
2022-09-17 09:00:06 +00:00
|
|
|
UC_Builder.SendToBack();
|
2022-06-28 02:59:36 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
PKME_Tabs = f1;
|
|
|
|
Trainers = db;
|
|
|
|
|
|
|
|
var grid = EncounterPokeGrid;
|
|
|
|
var smallWidth = grid.Width;
|
|
|
|
var smallHeight = grid.Height;
|
|
|
|
grid.InitializeGrid(6, 11, SpriteUtil.Spriter);
|
|
|
|
grid.SetBackground(Resources.box_wp_clean);
|
|
|
|
var newWidth = grid.Width;
|
|
|
|
var newHeight = grid.Height;
|
|
|
|
var wdelta = newWidth - smallWidth;
|
|
|
|
if (wdelta != 0)
|
|
|
|
Width += wdelta;
|
|
|
|
var hdelta = newHeight - smallHeight;
|
|
|
|
if (hdelta != 0)
|
|
|
|
Height += hdelta;
|
|
|
|
|
2023-12-04 04:13:20 +00:00
|
|
|
PKXBOXES = [..grid.Entries];
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
// Enable Scrolling when hovered over
|
|
|
|
foreach (var slot in PKXBOXES)
|
2018-11-11 04:23:21 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Enable Click
|
|
|
|
slot.MouseClick += (sender, e) =>
|
2018-11-11 04:23:21 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (sender == null)
|
|
|
|
return;
|
|
|
|
if (ModifierKeys == Keys.Control)
|
|
|
|
ClickView(sender, e);
|
|
|
|
};
|
2023-02-05 08:42:37 +00:00
|
|
|
slot.Enter += (sender, e) =>
|
|
|
|
{
|
|
|
|
if (sender is not PictureBox pb)
|
|
|
|
return;
|
2024-02-23 03:20:54 +00:00
|
|
|
var index = Array.IndexOf(PKXBOXES, pb);
|
2023-02-05 08:42:37 +00:00
|
|
|
if (index < 0)
|
|
|
|
return;
|
|
|
|
index += (SCR_Box.Value * RES_MIN);
|
|
|
|
if (index >= Results.Count)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var enc = Results[index];
|
2023-04-15 08:58:37 +00:00
|
|
|
pb.AccessibleDescription = string.Join(Environment.NewLine, enc.GetTextLines());
|
2023-02-05 08:42:37 +00:00
|
|
|
};
|
2022-06-18 18:04:24 +00:00
|
|
|
slot.ContextMenuStrip = mnu;
|
|
|
|
if (Main.Settings.Hover.HoverSlotShowText)
|
|
|
|
slot.MouseEnter += (o, args) => ShowHoverTextForSlot(slot, args);
|
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Counter = L_Count.Text;
|
2024-02-23 03:20:54 +00:00
|
|
|
L_Viewed.Text = string.Empty; // invisible for now
|
2022-06-18 18:04:24 +00:00
|
|
|
L_Viewed.MouseEnter += (sender, e) => hover.SetToolTip(L_Viewed, L_Viewed.Text);
|
|
|
|
PopulateComboBoxes();
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
|
|
|
GetTypeFilters();
|
2018-12-31 01:33:31 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Load Data
|
|
|
|
L_Count.Text = "Ready...";
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
CenterToParent();
|
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void GetTypeFilters()
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
var types = Enum.GetValues<EncounterTypeGroup>();
|
2022-06-18 18:04:24 +00:00
|
|
|
var checks = types.Select(z => new CheckBox
|
2018-12-31 01:33:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Name = z.ToString(),
|
|
|
|
Text = z.ToString(),
|
|
|
|
AutoSize = true,
|
|
|
|
Checked = true,
|
|
|
|
Padding = Padding.Empty,
|
|
|
|
Margin = Padding.Empty,
|
|
|
|
}).ToArray();
|
|
|
|
foreach (var chk in checks)
|
2018-12-31 01:33:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
TypeFilters.Controls.Add(chk);
|
|
|
|
TypeFilters.SetFlowBreak(chk, true);
|
2018-12-31 01:33:31 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-12-31 01:33:31 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private EncounterTypeGroup[] GetTypes()
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
return TypeFilters.Controls.OfType<CheckBox>().Where(z => z.Checked).Select(z => z.Name)
|
2023-01-22 04:02:33 +00:00
|
|
|
.Select(z => (EncounterTypeGroup)Enum.Parse(typeof(EncounterTypeGroup), z)).ToArray();
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private readonly PictureBox[] PKXBOXES;
|
2023-12-04 04:13:20 +00:00
|
|
|
private List<IEncounterInfo> Results = [];
|
2022-06-18 18:04:24 +00:00
|
|
|
private int slotSelected = -1; // = null;
|
|
|
|
private Image? slotColor;
|
|
|
|
private const int RES_MAX = 66;
|
|
|
|
private const int RES_MIN = 6;
|
|
|
|
private readonly string Counter;
|
|
|
|
|
|
|
|
private bool GetShiftedIndex(ref int index)
|
|
|
|
{
|
|
|
|
if (index >= RES_MAX)
|
|
|
|
return false;
|
|
|
|
index += SCR_Box.Value * RES_MIN;
|
|
|
|
return index < Results.Count;
|
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Important Events
|
|
|
|
private void ClickView(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
var pb = WinFormsUtil.GetUnderlyingControl<PictureBox>(sender);
|
|
|
|
int index = Array.IndexOf(PKXBOXES, pb);
|
|
|
|
if (index >= RES_MAX)
|
2021-02-07 06:33:13 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
System.Media.SystemSounds.Exclamation.Play();
|
|
|
|
return;
|
2021-02-07 06:33:13 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
index += SCR_Box.Value * RES_MIN;
|
|
|
|
if (index >= Results.Count)
|
2018-11-11 04:23:21 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
System.Media.SystemSounds.Exclamation.Play();
|
|
|
|
return;
|
2018-11-11 04:23:21 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var enc = Results[index];
|
|
|
|
var criteria = GetCriteria(enc, Main.Settings.EncounterDb);
|
|
|
|
var trainer = Trainers.GetTrainer(enc.Version, enc.Generation <= 2 ? (LanguageID)SAV.Language : null) ?? SAV;
|
|
|
|
var pk = enc.ConvertToPKM(trainer, criteria);
|
|
|
|
pk.RefreshChecksum();
|
|
|
|
PKME_Tabs.PopulateFields(pk, false);
|
|
|
|
slotSelected = index;
|
|
|
|
slotColor = SpriteUtil.Spriter.View;
|
|
|
|
FillPKXBoxes(SCR_Box.Value);
|
|
|
|
}
|
2021-06-15 03:26:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private EncounterCriteria GetCriteria(ISpeciesForm enc, EncounterDatabaseSettings settings)
|
|
|
|
{
|
|
|
|
if (!settings.UseTabsAsCriteria)
|
|
|
|
return EncounterCriteria.Unrestricted;
|
2021-06-15 05:20:17 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var editor = PKME_Tabs.Data;
|
|
|
|
var tree = EvolutionTree.GetEvolutionTree(editor.Context);
|
2022-08-27 06:43:36 +00:00
|
|
|
bool isInChain = tree.IsSpeciesDerivedFrom(editor.Species, editor.Form, enc.Species, enc.Form);
|
2021-06-15 03:26:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (!settings.UseTabsAsCriteriaAnySpecies)
|
|
|
|
{
|
2021-06-15 05:20:17 +00:00
|
|
|
if (!isInChain)
|
2022-06-18 18:04:24 +00:00
|
|
|
return EncounterCriteria.Unrestricted;
|
2021-06-15 03:26:12 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var set = new ShowdownSet(editor);
|
|
|
|
var criteria = EncounterCriteria.GetCriteria(set, editor.PersonalInfo);
|
|
|
|
if (!isInChain)
|
2024-03-17 18:54:36 +00:00
|
|
|
criteria = criteria with { Gender = default }; // Genderless tabs and a gendered enc -> let's play safe.
|
2022-06-18 18:04:24 +00:00
|
|
|
return criteria;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void PopulateComboBoxes()
|
|
|
|
{
|
|
|
|
// Set the Text
|
|
|
|
CB_Species.InitializeBinding();
|
|
|
|
CB_GameOrigin.InitializeBinding();
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
var Any = new ComboItem(MsgAny, 0);
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var DS_Species = new List<ComboItem>(GameInfo.SpeciesDataSource);
|
|
|
|
DS_Species.RemoveAt(0); DS_Species.Insert(0, Any); CB_Species.DataSource = DS_Species;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2023-12-04 04:13:20 +00:00
|
|
|
// Set the Move ComboBoxes too.
|
2022-06-18 18:04:24 +00:00
|
|
|
var DS_Move = new List<ComboItem>(GameInfo.MoveDataSource);
|
|
|
|
DS_Move.RemoveAt(0); DS_Move.Insert(0, Any);
|
|
|
|
{
|
|
|
|
foreach (ComboBox cb in new[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4 })
|
2018-11-11 04:23:21 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
cb.InitializeBinding();
|
|
|
|
cb.DataSource = new BindingSource(DS_Move, null);
|
2018-11-11 04:23:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var DS_Version = new List<ComboItem>(GameInfo.VersionDataSource);
|
2022-11-28 00:13:31 +00:00
|
|
|
DS_Version.Insert(0, Any);
|
|
|
|
DS_Version.RemoveAt(DS_Version.Count - 1);
|
|
|
|
CB_GameOrigin.DataSource = DS_Version;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Trigger a Reset
|
|
|
|
ResetFilters(this, EventArgs.Empty);
|
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
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;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
RTB_Instructions.Clear();
|
|
|
|
if (sender == this)
|
|
|
|
return; // still starting up
|
|
|
|
foreach (var chk in TypeFilters.Controls.OfType<CheckBox>())
|
|
|
|
chk.Checked = true;
|
2021-06-04 00:48:32 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
System.Media.SystemSounds.Asterisk.Play();
|
|
|
|
}
|
2022-05-07 16:25:59 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// View Updates
|
|
|
|
private IEnumerable<IEncounterInfo> SearchDatabase(CancellationToken token)
|
|
|
|
{
|
|
|
|
var settings = GetSearchSettings();
|
|
|
|
|
|
|
|
// If nothing is specified, instead of just returning all possible encounters, just return nothing.
|
2023-01-22 04:02:33 +00:00
|
|
|
if (settings is { Species: 0, Moves.Count: 0 } && Main.Settings.EncounterDb.ReturnNoneIfEmptySearch)
|
2023-12-04 04:13:20 +00:00
|
|
|
return [];
|
2022-06-18 18:04:24 +00:00
|
|
|
var pk = SAV.BlankPKM;
|
|
|
|
|
2022-08-30 22:00:45 +00:00
|
|
|
var moves = settings.Moves.ToArray();
|
2022-06-18 18:04:24 +00:00
|
|
|
var versions = settings.GetVersions(SAV);
|
2023-12-18 00:38:53 +00:00
|
|
|
var species = settings.Species == 0 ? GetFullRange(SAV.MaxSpeciesID) : [settings.Species];
|
2022-06-18 18:04:24 +00:00
|
|
|
var results = GetAllSpeciesFormEncounters(species, SAV.Personal, versions, moves, pk, token);
|
|
|
|
if (settings.SearchEgg != null)
|
|
|
|
results = results.Where(z => z.EggEncounter == settings.SearchEgg);
|
|
|
|
if (settings.SearchShiny != null)
|
|
|
|
results = results.Where(z => z.IsShiny == settings.SearchShiny);
|
|
|
|
|
|
|
|
// return filtered results
|
|
|
|
var comparer = new ReferenceComparer<IEncounterInfo>();
|
|
|
|
results = results.Distinct(comparer); // only distinct objects
|
|
|
|
|
2023-08-12 23:01:16 +00:00
|
|
|
static Func<IEncounterInfo, bool> IsPresent<TTable>(TTable pt) where TTable : IPersonalTable => z =>
|
|
|
|
{
|
|
|
|
if (pt.IsPresentInGame(z.Species, z.Form))
|
|
|
|
return true;
|
|
|
|
return z is IEncounterFormRandom { IsRandomUnspecificForm: true } && pt.IsSpeciesInGame(z.Species);
|
|
|
|
};
|
2022-06-18 18:04:24 +00:00
|
|
|
if (Main.Settings.EncounterDb.FilterUnavailableSpecies)
|
|
|
|
{
|
|
|
|
results = SAV switch
|
2021-06-09 03:14:27 +00:00
|
|
|
{
|
2023-08-12 23:01:16 +00:00
|
|
|
SAV9SV s9 => results.Where(IsPresent(s9.Personal)),
|
|
|
|
SAV8SWSH s8 => results.Where(IsPresent(s8.Personal)),
|
|
|
|
SAV8BS b8 => results.Where(IsPresent(b8.Personal)),
|
|
|
|
SAV8LA a8 => results.Where(IsPresent(a8.Personal)),
|
2022-06-18 18:04:24 +00:00
|
|
|
_ => results.Where(z => z.Generation <= 7),
|
|
|
|
};
|
|
|
|
}
|
2021-06-09 03:14:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (token.IsCancellationRequested)
|
2019-11-17 05:55:38 +00:00
|
|
|
return results;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
ReadOnlySpan<char> batchText = RTB_Instructions.Text;
|
|
|
|
if (batchText.Length > 0 && !StringInstructionSet.HasEmptyLine(batchText))
|
2021-06-11 17:58:38 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
var filters = StringInstruction.GetFilters(batchText);
|
2022-06-18 18:04:24 +00:00
|
|
|
BatchEditing.ScreenStrings(filters);
|
|
|
|
results = results.Where(enc => BatchEditing.IsFilterMatch(filters, enc)); // Compare across all filters
|
2021-06-11 17:58:38 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
private static IEnumerable<ushort> GetFullRange(int max)
|
|
|
|
{
|
|
|
|
for (ushort i = 1; i <= max; i++)
|
|
|
|
yield return i;
|
|
|
|
}
|
|
|
|
|
2024-01-02 23:45:35 +00:00
|
|
|
private IEnumerable<IEncounterInfo> GetAllSpeciesFormEncounters(IEnumerable<ushort> species, IPersonalTable pt, IReadOnlyList<GameVersion> versions, ReadOnlyMemory<ushort> moves, PKM pk, CancellationToken token)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
foreach (var s in species)
|
2018-11-11 04:23:21 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (token.IsCancellationRequested)
|
|
|
|
break;
|
|
|
|
|
|
|
|
var pi = pt.GetFormEntry(s, 0);
|
|
|
|
var fc = pi.FormCount;
|
|
|
|
if (fc == 0 && !Main.Settings.EncounterDb.FilterUnavailableSpecies) // not present in game
|
2020-10-18 18:02:39 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// try again using past-gen table
|
|
|
|
pi = PersonalTable.USUM.GetFormEntry(s, 0);
|
|
|
|
fc = pi.FormCount;
|
2020-10-18 18:02:39 +00:00
|
|
|
}
|
2022-08-27 06:43:36 +00:00
|
|
|
for (byte f = 0; f < fc; f++)
|
2020-10-18 18:02:39 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (FormInfo.IsBattleOnlyForm(s, f, pk.Format))
|
|
|
|
continue;
|
|
|
|
var encs = GetEncounters(s, f, moves, pk, versions);
|
|
|
|
foreach (var enc in encs)
|
|
|
|
yield return enc;
|
2020-10-18 18:02:39 +00:00
|
|
|
}
|
2018-12-31 01:33:31 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private sealed class ReferenceComparer<T> : IEqualityComparer<T> where T : class
|
|
|
|
{
|
|
|
|
public bool Equals(T? x, T? y)
|
2018-12-31 01:33:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (x == null)
|
|
|
|
return false;
|
|
|
|
if (y == null)
|
|
|
|
return false;
|
|
|
|
return RuntimeHelpers.GetHashCode(x).Equals(RuntimeHelpers.GetHashCode(y));
|
2018-11-11 04:23:21 +00:00
|
|
|
}
|
|
|
|
|
2023-02-23 09:07:46 +00:00
|
|
|
public int GetHashCode(T obj) => RuntimeHelpers.GetHashCode(obj);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2024-01-02 23:45:35 +00:00
|
|
|
private IEnumerable<IEncounterInfo> GetEncounters(ushort species, byte form, ReadOnlyMemory<ushort> moves, PKM pk, IReadOnlyList<GameVersion> vers)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
pk.Species = species;
|
|
|
|
pk.Form = form;
|
|
|
|
pk.SetGender(pk.GetSaneGender());
|
2023-02-01 07:23:12 +00:00
|
|
|
EncounterMovesetGenerator.OptimizeCriteria(pk, SAV);
|
2022-06-18 18:04:24 +00:00
|
|
|
return EncounterMovesetGenerator.GenerateEncounters(pk, moves, vers);
|
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private SearchSettings GetSearchSettings()
|
|
|
|
{
|
|
|
|
var settings = new SearchSettings
|
|
|
|
{
|
|
|
|
Format = SAV.Generation, // 0->(n-1) => 1->n
|
|
|
|
Generation = SAV.Generation,
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-09-02 17:29:55 +00:00
|
|
|
Species = GetU16(CB_Species),
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
BatchInstructions = RTB_Instructions.Text,
|
2024-02-23 03:20:54 +00:00
|
|
|
Version = (GameVersion)WinFormsUtil.GetIndex(CB_GameOrigin),
|
2022-06-18 18:04:24 +00:00
|
|
|
};
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-09-02 17:29:55 +00:00
|
|
|
static ushort GetU16(ListControl cb)
|
|
|
|
{
|
|
|
|
var val = WinFormsUtil.GetIndex(cb);
|
|
|
|
if (val <= 0)
|
|
|
|
return 0;
|
|
|
|
return (ushort)val;
|
|
|
|
}
|
|
|
|
|
|
|
|
settings.AddMove(GetU16(CB_Move1));
|
|
|
|
settings.AddMove(GetU16(CB_Move2));
|
|
|
|
settings.AddMove(GetU16(CB_Move3));
|
|
|
|
settings.AddMove(GetU16(CB_Move4));
|
2021-05-18 23:17:57 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (CHK_IsEgg.CheckState != CheckState.Indeterminate)
|
|
|
|
settings.SearchEgg = CHK_IsEgg.CheckState == CheckState.Checked;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (CHK_Shiny.CheckState != CheckState.Indeterminate)
|
|
|
|
settings.SearchShiny = CHK_Shiny.CheckState == CheckState.Checked;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return settings;
|
|
|
|
}
|
2022-05-07 16:25:59 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private async void B_Search_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
B_Search.Enabled = false;
|
|
|
|
EncounterMovesetGenerator.PriorityList = GetTypes();
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var token = TokenSource.Token;
|
|
|
|
var search = SearchDatabase(token);
|
|
|
|
if (token.IsCancellationRequested)
|
2023-07-14 05:18:34 +00:00
|
|
|
{
|
|
|
|
EncounterMovesetGenerator.ResetFilters();
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
2023-07-14 05:18:34 +00:00
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var results = await Task.Run(() => search.ToList(), token).ConfigureAwait(true);
|
|
|
|
if (token.IsCancellationRequested)
|
2023-07-14 05:18:34 +00:00
|
|
|
{
|
|
|
|
EncounterMovesetGenerator.ResetFilters();
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
2023-07-14 05:18:34 +00:00
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (results.Count == 0)
|
|
|
|
WinFormsUtil.Alert(MsgDBSearchNone);
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
SetResults(results); // updates Count Label as well.
|
|
|
|
System.Media.SystemSounds.Asterisk.Play();
|
|
|
|
B_Search.Enabled = true;
|
|
|
|
EncounterMovesetGenerator.ResetFilters();
|
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void UpdateScroll(object sender, ScrollEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.OldValue != e.NewValue)
|
|
|
|
FillPKXBoxes(e.NewValue);
|
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void SetResults(List<IEncounterInfo> res)
|
|
|
|
{
|
|
|
|
Results = res;
|
|
|
|
ShowSet.Clear();
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
SCR_Box.Maximum = (int)Math.Ceiling((decimal)Results.Count / RES_MIN);
|
|
|
|
if (SCR_Box.Maximum > 0) SCR_Box.Maximum--;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
slotSelected = -1; // reset the slot last viewed
|
|
|
|
SCR_Box.Value = 0;
|
|
|
|
FillPKXBoxes(0);
|
2021-05-27 17:27:50 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
L_Count.Text = string.Format(Counter, Results.Count);
|
|
|
|
B_Search.Enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void FillPKXBoxes(int start)
|
|
|
|
{
|
|
|
|
var boxes = PKXBOXES;
|
|
|
|
if (Results.Count == 0)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < RES_MAX; i++)
|
2018-11-11 04:23:21 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
boxes[i].Image = null;
|
|
|
|
boxes[i].BackgroundImage = null;
|
2018-11-11 04:23:21 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-05-27 17:27:50 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Load new sprites
|
2023-04-22 03:47:04 +00:00
|
|
|
int begin = start * RES_MIN;
|
2022-06-18 18:04:24 +00:00
|
|
|
int end = Math.Min(RES_MAX, Results.Count - begin);
|
|
|
|
for (int i = 0; i < end; i++)
|
|
|
|
{
|
2023-02-05 08:42:37 +00:00
|
|
|
var pb = boxes[i];
|
2022-06-18 18:04:24 +00:00
|
|
|
var enc = Results[i + begin];
|
2023-02-05 08:42:37 +00:00
|
|
|
pb.Image = enc.Sprite();
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Clear empty slots
|
|
|
|
for (int i = end; i < RES_MAX; i++)
|
|
|
|
boxes[i].Image = null;
|
2021-05-27 17:27:50 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Reset backgrounds for all
|
|
|
|
for (int i = 0; i < RES_MAX; i++)
|
|
|
|
boxes[i].BackgroundImage = SpriteUtil.Spriter.Transparent;
|
2021-05-27 17:27:50 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Reload last viewed index's background if still within view
|
|
|
|
if (slotSelected != -1 && slotSelected >= begin && slotSelected < begin + RES_MAX)
|
|
|
|
boxes[slotSelected - begin].BackgroundImage = slotColor ?? SpriteUtil.Spriter.View;
|
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void Menu_Exit_Click(object sender, EventArgs e) => Close();
|
2021-02-07 06:33:13 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override void OnMouseWheel(MouseEventArgs e)
|
|
|
|
{
|
|
|
|
if (!EncounterPokeGrid.RectangleToScreen(EncounterPokeGrid.ClientRectangle).Contains(MousePosition))
|
|
|
|
return;
|
|
|
|
int oldval = SCR_Box.Value;
|
|
|
|
int newval = oldval + (e.Delta < 0 ? 1 : -1);
|
|
|
|
if (newval >= SCR_Box.Minimum && SCR_Box.Maximum >= newval)
|
|
|
|
FillPKXBoxes(SCR_Box.Value = newval);
|
|
|
|
}
|
2021-02-07 06:33:13 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ShowHoverTextForSlot(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
var pb = (PictureBox)sender;
|
|
|
|
int index = Array.IndexOf(PKXBOXES, pb);
|
|
|
|
if (!GetShiftedIndex(ref index))
|
|
|
|
return;
|
2022-05-07 16:25:59 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
ShowSet.Show(pb, Results[index]);
|
2018-11-11 04:23:21 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
private void SAV_Encounters_FormClosing(object sender, FormClosingEventArgs e) => TokenSource.Cancel();
|
2022-09-17 09:00:06 +00:00
|
|
|
|
|
|
|
private void B_Add_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
var s = UC_Builder.Create();
|
|
|
|
if (s.Length == 0)
|
|
|
|
{ WinFormsUtil.Alert(MsgBEPropertyInvalid); return; }
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
// If we already have text, add a new line (except if the last line is blank).
|
|
|
|
var tb = RTB_Instructions;
|
|
|
|
var batchText = tb.Text;
|
|
|
|
if (batchText.Length > 0 && !batchText.EndsWith('\n'))
|
|
|
|
tb.AppendText(Environment.NewLine);
|
2022-09-17 09:00:06 +00:00
|
|
|
RTB_Instructions.AppendText(s);
|
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
}
|