PKHeX/PKHeX.WinForms/Subforms/Save Editors/SAV_SimplePokedex.cs
Kurt 3c232505e5
Refactoring: Narrow some value types (Species, Move, Form) (#3575)
In this pull request I've changed a ton of method signatures to reflect the more-narrow types of Species, Move# and Form; additionally, I've narrowed other large collections that stored lists of species / permitted values, and reworked them to be more performant with the latest API spaghetti that PKHeX provides. Roamer met locations, usually in a range of [max-min]<64, can be quickly checked using a bitflag operation on a UInt64. Other collections (like "Is this from Colosseum or XD") were eliminated -- shadow state is not transferred COLO<->XD, so having a Shadow ID or matching the met location from a gift/wild encounter is a sufficient check for "originated in XD".
2022-08-26 23:43:36 -07:00

90 lines
2.5 KiB
C#

using System;
using System.Windows.Forms;
using PKHeX.Core;
namespace PKHeX.WinForms;
public partial class SAV_SimplePokedex : Form
{
private readonly SaveFile Origin;
private readonly SaveFile SAV;
public SAV_SimplePokedex(SaveFile sav)
{
InitializeComponent();
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
SAV = (Origin = sav).Clone();
seen = new bool[SAV.MaxSpeciesID];
caught = new bool[SAV.MaxSpeciesID];
var speciesNames = GameInfo.Strings.specieslist;
for (int i = 0; i < seen.Length; i++)
{
ushort species = (ushort)(i + 1);
seen[i] = SAV.GetSeen(species);
caught[i] = SAV.GetCaught(species);
CLB_Seen.Items.Add(speciesNames[species]);
CLB_Caught.Items.Add(speciesNames[species]);
CLB_Seen.SetItemChecked(i, seen[i]);
CLB_Caught.SetItemChecked(i, caught[i]);
}
initialized = true;
}
private readonly bool[] seen;
private readonly bool[] caught;
private readonly bool initialized;
private void B_Save_Click(object sender, EventArgs e)
{
for (int i = 0; i < seen.Length; i++)
{
ushort species = (ushort)(i + 1);
SAV.SetSeen(species, seen[i]);
SAV.SetCaught(species, caught[i]);
}
Origin.CopyChangesFrom(SAV);
Close();
}
private void B_Cancel_Click(object sender, EventArgs e)
{
Close();
}
private void B_SeenAll_Click(object sender, EventArgs e)
{
for (int i = 0; i < SAV.MaxSpeciesID; i++)
CLB_Seen.SetItemChecked(i, true);
}
private void B_SeenNone_Click(object sender, EventArgs e)
{
for (int i = 0; i < SAV.MaxSpeciesID; i++)
CLB_Seen.SetItemChecked(i, false);
}
private void B_CaughtAll_Click(object sender, EventArgs e)
{
for (int i = 0; i < SAV.MaxSpeciesID; i++)
CLB_Caught.SetItemChecked(i, true);
}
private void B_CaughtNone_Click(object sender, EventArgs e)
{
for (int i = 0; i < SAV.MaxSpeciesID; i++)
CLB_Caught.SetItemChecked(i, false);
}
private void CLB_Seen_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (!initialized) return;
seen[e.Index] = e.NewValue == CheckState.Checked;
}
private void CLB_Caught_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (!initialized) return;
caught[e.Index] = e.NewValue == CheckState.Checked;
}
}