mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-14 18:05:16 -05:00
Relocate logic to core
probable/possible lgpe uses similar dex stuff, so best I totally understand it (assuming quirks will be present)
This commit is contained in:
@@ -17,12 +17,16 @@ public sealed class PokeDex7 : PokeDex
|
||||
public readonly bool[][] Displayed = new bool[4][];
|
||||
public readonly bool[] LanguageFlags;
|
||||
|
||||
private readonly IList<int> FormBaseSpecies;
|
||||
|
||||
public PokeDex7(SAV7 SAV)
|
||||
{
|
||||
Parent = SAV;
|
||||
if (Parent.Generation != 7)
|
||||
return;
|
||||
|
||||
FormBaseSpecies = GetFormIndexBaseSpeciesList();
|
||||
|
||||
int ofs = Parent.PokeDex + 0x8 + MiscLen;
|
||||
Owned = SetBits(Parent.Data, ofs, OwnedLen);
|
||||
|
||||
@@ -38,6 +42,7 @@ public PokeDex7(SAV7 SAV)
|
||||
ofs += SeenDispLen;
|
||||
}
|
||||
LanguageFlags = SetBits(Parent.Data, Parent.PokeDexLanguageFlags, LanguageLen);
|
||||
|
||||
}
|
||||
|
||||
public void Write()
|
||||
@@ -100,5 +105,70 @@ public int GetDexFormStart(int spec, int fc)
|
||||
? SaveUtil.GetDexFormIndexUSUM(spec, fc, Parent.MaxSpeciesID - 1)
|
||||
: SaveUtil.GetDexFormIndexSM(spec, fc, Parent.MaxSpeciesID - 1);
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetEntryNames(IReadOnlyList<string> Species)
|
||||
{
|
||||
var names = new List<string>();
|
||||
for (int i = 1; i <= Parent.MaxSpeciesID; i++)
|
||||
names.Add($"{i:000} - {Species[i]}");
|
||||
|
||||
// Add Formes
|
||||
int ctr = Parent.MaxSpeciesID;
|
||||
for (int spec = 1; spec <= Parent.MaxSpeciesID; spec++)
|
||||
{
|
||||
int c = Parent.Personal[spec].FormeCount;
|
||||
for (int f = 1; f < c; f++)
|
||||
{
|
||||
int x = GetDexFormIndex(spec, c, f);
|
||||
if (x >= 0)
|
||||
names.Add($"{ctr++:000} - {Species[spec]}-{f}");
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of Species IDs that a given dex-forme index corresponds to.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private List<int> GetFormIndexBaseSpeciesList()
|
||||
{
|
||||
var baseSpecies = new List<int>();
|
||||
for (int spec = 1; spec <= Parent.MaxSpeciesID; spec++)
|
||||
{
|
||||
int c = Parent.Personal[spec].FormeCount;
|
||||
for (int f = 1; f < c; f++)
|
||||
{
|
||||
int x = GetDexFormIndex(spec, c, f);
|
||||
if (x >= 0)
|
||||
baseSpecies.Add(spec);
|
||||
}
|
||||
}
|
||||
return baseSpecies;
|
||||
}
|
||||
|
||||
public int GetBaseSpeciesGenderValue(int index)
|
||||
{
|
||||
// meowstic special handling
|
||||
const int meow = 678;
|
||||
if (index == meow - 1 || (index >= Parent.MaxSpeciesID && FormBaseSpecies[index - Parent.MaxSpeciesID] == meow))
|
||||
return index < Parent.MaxSpeciesID ? 0 : 254; // M : F
|
||||
|
||||
if (index < Parent.MaxSpeciesID)
|
||||
return Parent.Personal[index + 1].Gender;
|
||||
|
||||
index -= Parent.MaxSpeciesID;
|
||||
int spec = FormBaseSpecies[index];
|
||||
return Parent.Personal[spec].Gender;
|
||||
}
|
||||
|
||||
|
||||
public int GetBaseSpecies(int index)
|
||||
{
|
||||
if (index <= Parent.MaxSpeciesID)
|
||||
return index;
|
||||
|
||||
return FormBaseSpecies[index - Parent.MaxSpeciesID - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
@@ -29,27 +28,12 @@ public SAV_PokedexSM(SaveFile sav)
|
||||
CB_Species.InitializeBinding();
|
||||
CB_Species.DataSource = new BindingSource(GameInfo.SpeciesDataSource.Skip(1).ToList(), null);
|
||||
|
||||
for (int i = 1; i < SAV.MaxSpeciesID + 1; i++)
|
||||
LB_Species.Items.Add($"{i:000} - {GameInfo.Strings.specieslist[i]}");
|
||||
|
||||
Dex = new PokeDex7(SAV);
|
||||
|
||||
// Add Formes
|
||||
int ctr = SAV.MaxSpeciesID;
|
||||
baseSpecies = new List<int>();
|
||||
for (int spec = 1; spec < SAV.MaxSpeciesID + 1; spec++)
|
||||
{
|
||||
int c = SAV.Personal[spec].FormeCount;
|
||||
for (int f = 1; f < c; f++)
|
||||
{
|
||||
int x = Dex.GetDexFormIndex(spec, c, f);
|
||||
if (x == -1)
|
||||
continue;
|
||||
baseSpecies.Add(spec);
|
||||
ctr++;
|
||||
LB_Species.Items.Add($"{ctr:000} - {GameInfo.Strings.specieslist[spec]}-{f}");
|
||||
}
|
||||
}
|
||||
var Species = GameInfo.Strings.Species;
|
||||
var names = Dex.GetEntryNames(Species);
|
||||
foreach (var n in names)
|
||||
LB_Species.Items.Add(n);
|
||||
|
||||
editing = false;
|
||||
LB_Species.SelectedIndex = 0;
|
||||
@@ -62,21 +46,6 @@ public SAV_PokedexSM(SaveFile sav)
|
||||
private int species = -1;
|
||||
private readonly CheckBox[] CP, CL;
|
||||
|
||||
private readonly List<int> baseSpecies;
|
||||
private int GetBaseSpeciesGender(int index)
|
||||
{
|
||||
// meowstic special handling
|
||||
const int meow = 678;
|
||||
if (index == meow - 1 || index >= SAV.MaxSpeciesID && baseSpecies[index - SAV.MaxSpeciesID] == meow)
|
||||
return index < SAV.MaxSpeciesID ? 0 : 254; // M : F
|
||||
|
||||
if (index < SAV.MaxSpeciesID)
|
||||
return SAV.Personal[index + 1].Gender;
|
||||
|
||||
index -= SAV.MaxSpeciesID;
|
||||
int spec = baseSpecies[index];
|
||||
return SAV.Personal[spec].Gender;
|
||||
}
|
||||
|
||||
private void ChangeCBSpecies(object sender, EventArgs e)
|
||||
{
|
||||
@@ -111,7 +80,7 @@ private void ChangeLBForms(object sender, EventArgs e)
|
||||
|
||||
editing = true;
|
||||
int fspecies = LB_Species.SelectedIndex + 1;
|
||||
var bspecies = fspecies <= SAV.MaxSpeciesID ? fspecies : baseSpecies[fspecies - SAV.MaxSpeciesID - 1];
|
||||
var bspecies = Dex.GetBaseSpecies(fspecies);
|
||||
int form = LB_Forms.SelectedIndex;
|
||||
if (form > 0)
|
||||
{
|
||||
@@ -141,7 +110,7 @@ private bool FillLBForms()
|
||||
LB_Forms.Items.Clear();
|
||||
|
||||
int fspecies = LB_Species.SelectedIndex + 1;
|
||||
var bspecies = fspecies <= SAV.MaxSpeciesID ? fspecies : baseSpecies[fspecies - SAV.MaxSpeciesID - 1];
|
||||
var bspecies = Dex.GetBaseSpecies(fspecies);
|
||||
bool hasForms = FormConverter.HasFormSelection(SAV.Personal[bspecies], bspecies, 7);
|
||||
LB_Forms.Enabled = hasForms;
|
||||
if (!hasForms) return false;
|
||||
@@ -178,6 +147,7 @@ private bool FillLBForms()
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ChangeDisplayed(object sender, EventArgs e)
|
||||
{
|
||||
if (!((CheckBox) sender).Checked)
|
||||
@@ -217,7 +187,7 @@ private void GetEntry()
|
||||
CHK_P1.Enabled = species <= SAV.MaxSpeciesID;
|
||||
CHK_P1.Checked = CHK_P1.Enabled && Dex.Owned[pk];
|
||||
|
||||
int gt = GetBaseSpeciesGender(LB_Species.SelectedIndex);
|
||||
int gt = Dex.GetBaseSpeciesGenderValue(LB_Species.SelectedIndex);
|
||||
|
||||
CHK_P2.Enabled = CHK_P4.Enabled = CHK_P6.Enabled = CHK_P8.Enabled = gt != 254; // Not Female-Only
|
||||
CHK_P3.Enabled = CHK_P5.Enabled = CHK_P7.Enabled = CHK_P9.Enabled = gt != 0 && gt != 255; // Not Male-Only and Not Genderless
|
||||
@@ -288,7 +258,7 @@ private void B_GiveAll_Click(object sender, EventArgs e)
|
||||
{
|
||||
CHK_P1.Checked = ModifierKeys != Keys.Control;
|
||||
}
|
||||
int gt = GetBaseSpeciesGender(LB_Species.SelectedIndex);
|
||||
int gt = Dex.GetBaseSpeciesGenderValue(LB_Species.SelectedIndex);
|
||||
|
||||
CHK_P2.Checked = CHK_P4.Checked = gt != 254 && ModifierKeys != Keys.Control;
|
||||
CHK_P3.Checked = CHK_P5.Checked = gt != 0 && gt != 255 && ModifierKeys != Keys.Control;
|
||||
@@ -346,7 +316,7 @@ private void SetAll(object sender, int lang)
|
||||
for (int i = 0; i < SAV.MaxSpeciesID; i++)
|
||||
{
|
||||
int spec = i + 1;
|
||||
var gt = GetBaseSpeciesGender(i);
|
||||
var gt = Dex.GetBaseSpeciesGenderValue(i);
|
||||
|
||||
// Set base species flags
|
||||
LB_Species.SelectedIndex = i;
|
||||
|
||||
Reference in New Issue
Block a user