Rework TID/SID loading

Move TID/SID load to after version set (special handling for pk1/pk2
which don't store version, just call manually).
Update TID/SID on every gameversion change anyway
Rename LoadOTID to LoadOT since it does not deal with ID.

Closes #1962
This commit is contained in:
Kurt 2018-05-24 16:53:51 -07:00
parent c349ab8218
commit bb55532c4a
4 changed files with 46 additions and 41 deletions

View file

@ -10,6 +10,7 @@ namespace PKHeX.WinForms.Controls
return;
LoadMisc1(pk1);
TID_Trainer.LoadIDValues(pkm);
// Attempt to detect language
CB_Language.SelectedValue = PKX.GetVCLanguage(pk1);

View file

@ -12,6 +12,7 @@ namespace PKHeX.WinForms.Controls
LoadMisc1(pk2);
LoadMisc2(pk2);
TID_Trainer.LoadIDValues(pkm);
TB_MetLevel.Text = pk2.Met_Level.ToString();
CB_MetLocation.SelectedValue = pk2.Met_Location;
CB_MetTimeOfDay.SelectedIndex = pk2.Met_TimeOfDay;

View file

@ -33,15 +33,14 @@ namespace PKHeX.WinForms.Controls
pk.EXP = Util.ToUInt32(TB_EXP.Text);
}
private void LoadOTID(PKM pk)
private void LoadOT(PKM pk)
{
GB_OT.BackgroundImage = null;
TB_OT.Text = pk.OT_Name;
Label_OTGender.Text = gendersymbols[pk.OT_Gender];
Label_OTGender.ForeColor = GetGenderColor(pk.OT_Gender);
TID_Trainer.LoadIDValues(pk);
}
private void SaveOTID(PKM pk)
private void SaveOT(PKM pk)
{
pk.OT_Name = TB_OT.Text;
pk.OT_Gender = PKX.GetGenderFromString(Label_OTGender.Text);
@ -162,7 +161,7 @@ namespace PKHeX.WinForms.Controls
{
LoadSpeciesLevelEXP(pk);
LoadNickname(pk);
LoadOTID(pk);
LoadOT(pk);
LoadIVs(pk);
LoadEVs(pk);
LoadMoves(pk);
@ -171,7 +170,7 @@ namespace PKHeX.WinForms.Controls
{
SaveSpeciesLevelEXP(pk);
SaveNickname(pk);
SaveOTID(pk);
SaveOT(pk);
SaveMoves(pk);
}
@ -209,6 +208,7 @@ namespace PKHeX.WinForms.Controls
CHK_Fateful.Checked = pk.FatefulEncounter;
LoadContestStats(pk);
TID_Trainer.LoadIDValues(pk);
// Load Extrabyte Value
TB_ExtraByte.Text = pk.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString();

View file

@ -1019,43 +1019,15 @@ namespace PKHeX.WinForms.Controls
GameVersion Version = (GameVersion)WinFormsUtil.GetIndex(CB_GameOrigin);
// check if differs
GameVersion newTrack = GameUtil.GetMetLocationVersionGroup(Version);
if (newTrack != origintrack && FieldsLoaded)
{
pkm.Version = (int)Version;
TID_Trainer.LoadIDValues(pkm);
}
var group = GameUtil.GetMetLocationVersionGroup(Version);
if (group == GameVersion.GSC && pkm.Format >= 7)
group = GameVersion.USUM;
else if (pkm.Format < 3)
group = GameVersion.GSC;
if (newTrack != origintrack)
{
var met_list = GameInfo.GetLocationList(Version, pkm.Format, egg: false);
InitializeBinding(CB_MetLocation);
CB_MetLocation.DataSource = new BindingSource(met_list, null);
if (FieldsLoaded)
{
SetMarkings(); // Set/Remove the Nativity marking when gamegroup changes too
int metLoc = EncounterSuggestion.GetSuggestedTransferLocation(pkm);
CB_MetLocation.SelectedValue = Math.Max(0, metLoc);
}
var egg_list = GameInfo.GetLocationList(Version, pkm.Format, egg: true);
InitializeBinding(CB_EggLocation);
CB_EggLocation.DataSource = new BindingSource(egg_list, null);
if (FieldsLoaded)
CB_EggLocation.SelectedIndex = CHK_AsEgg.Checked ? 1 : 0; // daycare : none
origintrack = newTrack;
// Stretch C/XD met location dropdowns
int width = CB_EggLocation.DropDownWidth;
if (Version == GameVersion.CXD && pkm.Format == 3)
width = 2 * width;
CB_MetLocation.DropDownWidth = width;
if (!FieldsLoaded)
CB_GameOrigin.Focus(); // hacky validation forcing
}
if (group != origintrack)
ReloadMetLocations(Version);
origintrack = group;
// Visibility logic for Gen 4 encounter type; only show for Gen 4 Pokemon.
if (pkm.Format >= 4)
@ -1068,9 +1040,40 @@ namespace PKHeX.WinForms.Controls
if (!FieldsLoaded)
return;
pkm.Version = (int)Version;
TID_Trainer.LoadIDValues(pkm);
UpdateLegality();
}
private void ReloadMetLocations(GameVersion Version)
{
InitializeBinding(CB_MetLocation);
InitializeBinding(CB_EggLocation);
var met_list = GameInfo.GetLocationList(Version, pkm.Format, egg: false);
CB_MetLocation.DataSource = new BindingSource(met_list, null);
var egg_list = GameInfo.GetLocationList(Version, pkm.Format, egg: true);
CB_EggLocation.DataSource = new BindingSource(egg_list, null);
// Stretch C/XD met location dropdowns
int width = CB_EggLocation.DropDownWidth;
if (Version == GameVersion.CXD && pkm.Format == 3)
width *= 2;
CB_MetLocation.DropDownWidth = width;
if (FieldsLoaded)
{
SetMarkings(); // Set/Remove the Nativity marking when gamegroup changes too
int metLoc = EncounterSuggestion.GetSuggestedTransferLocation(pkm);
CB_MetLocation.SelectedValue = Math.Max(0, metLoc);
CB_EggLocation.SelectedIndex = CHK_AsEgg.Checked ? 1 : 0; // daycare : none
}
else
{
CB_GameOrigin.Focus(); // hacky validation forcing
}
}
private void UpdateExtraByteValue(object sender, EventArgs e)
{
if (CB_ExtraBytes.Items.Count == 0 || !(sender is MaskedTextBox mtb))