Rename public "pkm" properties to non-lowercase

lowercase = local variable or private member
This commit is contained in:
Kurt
2019-10-27 12:57:04 -07:00
parent ba593800d8
commit b8835facd5
17 changed files with 322 additions and 329 deletions

View File

@@ -243,7 +243,7 @@ internal static ModifyResult TryModifyPKM(PKM pk, IEnumerable<StringInstruction>
/// <returns>True if filtered, else false.</returns>
private static ModifyResult SetPKMProperty(StringInstruction cmd, PKMInfo info, IReadOnlyDictionary<string, PropertyInfo> props)
{
var pk = info.pkm;
var pk = info.Entity;
if (cmd.PropertyValue.StartsWith(CONST_BYTES))
return SetByteArrayProperty(pk, cmd);
@@ -277,7 +277,7 @@ private static bool IsFilterMatch(StringInstruction cmd, PKMInfo info, IReadOnly
{
if (IsLegalFiltered(cmd, () => info.Legal))
return true;
return IsPropertyFiltered(cmd, info.pkm, props);
return IsPropertyFiltered(cmd, info.Entity, props);
}
/// <summary>
@@ -350,7 +350,7 @@ private static bool IsLegalFiltered(StringInstruction cmd, Func<bool> isLegal)
/// <param name="info">Cached info storing Legal data.</param>
private static ModifyResult SetSuggestedPKMProperty(string name, PKMInfo info)
{
var pk = info.pkm;
var pk = info.Entity;
switch (name)
{
// pb7 only

View File

@@ -7,11 +7,11 @@ namespace PKHeX.Core
/// </summary>
internal sealed class PKMInfo
{
internal PKM pkm { get; }
internal PKMInfo(PKM pk) { pkm = pk; }
internal PKM Entity { get; }
internal PKMInfo(PKM pk) { Entity = pk; }
private LegalityAnalysis? la;
internal LegalityAnalysis Legality => la ??= new LegalityAnalysis(pkm);
internal LegalityAnalysis Legality => la ??= new LegalityAnalysis(Entity);
public bool Legal => Legality.Valid;
internal IReadOnlyList<int> SuggestedRelearn => Legality.GetSuggestedRelearn();

View File

@@ -78,10 +78,10 @@ private class PartyReversion : SlotReversion
private class SingleSlotReversion : SlotReversion
{
private readonly PKM PKM;
public SingleSlotReversion(ISlotInfo info, SaveFile sav) : base(info) => PKM = info.Read(sav);
private readonly PKM pkm;
public SingleSlotReversion(ISlotInfo info, SaveFile sav) : base(info) => pkm = info.Read(sav);
public override void Revert(SaveFile sav) => Info.WriteTo(sav, PKM, PKMImportSetting.Skip);
public override void Revert(SaveFile sav) => Info.WriteTo(sav, pkm, PKMImportSetting.Skip);
}
}
}

View File

@@ -1,4 +1,5 @@
using PKHeX.Core;
using System;
using PKHeX.Core;
namespace PKHeX.WinForms.Controls
{
@@ -6,8 +7,8 @@ public partial class PKMEditor
{
private void PopulateFieldsPK1()
{
if (!(pkm is PK1 pk1))
return;
if (!(Entity is PK1 pk1))
throw new FormatException(nameof(Entity));
LoadMisc1(pk1);
TID_Trainer.LoadIDValues(pk1);
@@ -20,10 +21,10 @@ private void PopulateFieldsPK1()
UpdateStats();
}
private PKM PreparePK1()
private PK1 PreparePK1()
{
if (!(pkm is PK1 pk1))
return null;
if (!(Entity is PK1 pk1))
throw new FormatException(nameof(Entity));
SaveMisc1(pk1);

View File

@@ -1,4 +1,5 @@
using PKHeX.Core;
using System;
using PKHeX.Core;
namespace PKHeX.WinForms.Controls
{
@@ -6,8 +7,8 @@ public partial class PKMEditor
{
private void PopulateFieldsPK2()
{
if (!(pkm is PK2 pk2))
return;
if (!(Entity is PK2 pk2))
throw new FormatException(nameof(Entity));
LoadMisc1(pk2);
LoadMisc2(pk2);
@@ -24,10 +25,10 @@ private void PopulateFieldsPK2()
UpdateStats();
}
private PKM PreparePK2()
private PK2 PreparePK2()
{
if (!(pkm is PK2 pk2))
return null;
if (!(Entity is PK2 pk2))
throw new FormatException(nameof(Entity));
SaveMisc1(pk2);
SaveMisc2(pk2);

View File

@@ -1,4 +1,5 @@
using PKHeX.Core;
using System;
using PKHeX.Core;
namespace PKHeX.WinForms.Controls
{
@@ -6,8 +7,8 @@ public partial class PKMEditor
{
private void PopulateFieldsPK3()
{
if (!(pkm is G3PKM pk3))
return;
if (!(Entity is G3PKM pk3))
throw new FormatException(nameof(Entity));
LoadMisc1(pk3);
LoadMisc2(pk3);
@@ -21,17 +22,17 @@ private void PopulateFieldsPK3()
UpdateStats();
}
private PKM PreparePK3()
private G3PKM PreparePK3()
{
if (!(pkm is G3PKM pk3))
return null;
if (!(Entity is G3PKM pk3))
throw new FormatException(nameof(Entity));
SaveMisc1(pk3);
SaveMisc2(pk3);
SaveMisc3(pk3);
pk3.AbilityBit = CB_Ability.SelectedIndex != 0;
if (pkm is IShadowPKM ck3)
if (Entity is IShadowPKM ck3)
SaveShadow3(ck3);
SavePartyStats(pk3);

View File

@@ -1,4 +1,5 @@
using PKHeX.Core;
using System;
using PKHeX.Core;
namespace PKHeX.WinForms.Controls
{
@@ -6,9 +7,8 @@ public partial class PKMEditor
{
private void PopulateFieldsPK4()
{
var pk4 = pkm;
if (pk4?.Format != 4)
return;
if (!(Entity is G4PKM pk4))
throw new FormatException(nameof(Entity));
LoadMisc1(pk4);
LoadMisc2(pk4);
@@ -16,7 +16,7 @@ private void PopulateFieldsPK4()
LoadMisc4(pk4);
CB_EncounterType.SelectedValue = pk4.Gen4 ? pk4.EncounterType : 0;
CB_EncounterType.Visible = Label_EncounterType.Visible = pkm.Gen4;
CB_EncounterType.Visible = Label_EncounterType.Visible = Entity.Gen4;
if (HaX)
DEV_Ability.SelectedValue = pk4.Ability;
@@ -24,21 +24,16 @@ private void PopulateFieldsPK4()
LoadAbility4(pk4);
// Minor properties
switch (pk4)
{
case G4PKM p4: ShinyLeaf.SetValue(p4.ShinyLeaf);
break;
}
ShinyLeaf.SetValue(pk4.ShinyLeaf);
LoadPartyStats(pk4);
UpdateStats();
}
private PKM PreparePK4()
private G4PKM PreparePK4()
{
var pk4 = pkm;
if (pk4?.Format != 4)
return null;
if (!(Entity is G4PKM pk4))
throw new FormatException(nameof(Entity));
SaveMisc1(pk4);
SaveMisc2(pk4);
@@ -48,12 +43,7 @@ private PKM PreparePK4()
pk4.EncounterType = WinFormsUtil.GetIndex(CB_EncounterType);
// Minor properties
switch (pk4)
{
case G4PKM p4:
p4.ShinyLeaf = ShinyLeaf.GetValue();
break;
}
pk4.ShinyLeaf = ShinyLeaf.GetValue();
SavePartyStats(pk4);
pk4.FixMoves();

View File

@@ -1,4 +1,5 @@
using PKHeX.Core;
using System;
using PKHeX.Core;
namespace PKHeX.WinForms.Controls
{
@@ -6,15 +7,15 @@ public partial class PKMEditor
{
private void PopulateFieldsPK5()
{
if (!(pkm is PK5 pk5))
return;
if (!(Entity is PK5 pk5))
throw new FormatException(nameof(Entity));
LoadMisc1(pk5);
LoadMisc2(pk5);
LoadMisc3(pk5);
LoadMisc4(pk5);
CB_EncounterType.SelectedValue = pk5.Gen4 ? pk5.EncounterType : 0;
CB_EncounterType.Visible = Label_EncounterType.Visible = pkm.Gen4;
CB_EncounterType.Visible = Label_EncounterType.Visible = pk5.Gen4;
CHK_NSparkle.Checked = pk5.NPokémon;
if (HaX)
@@ -28,10 +29,10 @@ private void PopulateFieldsPK5()
UpdateStats();
}
private PKM PreparePK5()
private PK5 PreparePK5()
{
if (!(pkm is PK5 pk5))
return null;
if (!(Entity is PK5 pk5))
throw new FormatException(nameof(Entity));
SaveMisc1(pk5);
SaveMisc2(pk5);

View File

@@ -1,4 +1,5 @@
using PKHeX.Core;
using System;
using PKHeX.Core;
namespace PKHeX.WinForms.Controls
{
@@ -6,8 +7,8 @@ public partial class PKMEditor
{
private void PopulateFieldsPK6()
{
if (!(pkm is PK6 pk6))
return;
if (!(Entity is PK6 pk6))
throw new FormatException(nameof(Entity));
LoadMisc1(pk6);
LoadMisc2(pk6);
@@ -16,16 +17,16 @@ private void PopulateFieldsPK6()
LoadMisc6(pk6);
CB_EncounterType.SelectedValue = pk6.Gen4 ? pk6.EncounterType : 0;
CB_EncounterType.Visible = Label_EncounterType.Visible = pkm.Gen4;
CB_EncounterType.Visible = Label_EncounterType.Visible = pk6.Gen4;
LoadPartyStats(pk6);
UpdateStats();
}
private PKM PreparePK6()
private PK6 PreparePK6()
{
if (!(pkm is PK6 pk6))
return null;
if (!(Entity is PK6 pk6))
throw new FormatException(nameof(Entity));
CheckTransferPIDValid();
SaveMisc1(pk6);

View File

@@ -1,4 +1,5 @@
using PKHeX.Core;
using System;
using PKHeX.Core;
namespace PKHeX.WinForms.Controls
{
@@ -6,8 +7,8 @@ public partial class PKMEditor
{
private void PopulateFieldsPK7()
{
if (!(pkm is PK7 pk7))
return;
if (!(Entity is PK7 pk7))
throw new FormatException(nameof(Entity));
LoadMisc1(pk7);
LoadMisc2(pk7);
@@ -19,10 +20,10 @@ private void PopulateFieldsPK7()
UpdateStats();
}
private PKM PreparePK7()
private PK7 PreparePK7()
{
if (!(pkm is PK7 pk7))
return null;
if (!(Entity is PK7 pk7))
throw new FormatException(nameof(Entity));
CheckTransferPIDValid();
SaveMisc1(pk7);
@@ -50,8 +51,8 @@ private PKM PreparePK7()
private void PopulateFieldsPB7()
{
if (!(pkm is PB7 pk7))
return;
if (!(Entity is PB7 pk7))
throw new FormatException(nameof(Entity));
LoadMisc1(pk7);
LoadMisc2(pk7);
@@ -65,10 +66,10 @@ private void PopulateFieldsPB7()
UpdateStats();
}
private PKM PreparePB7()
private PB7 PreparePB7()
{
if (!(pkm is PB7 pk7))
return null;
if (!(Entity is PB7 pk7))
throw new FormatException(nameof(Entity));
CheckTransferPIDValid();
SaveMisc1(pk7);

View File

@@ -1,4 +1,5 @@
using PKHeX.Core;
using System;
using PKHeX.Core;
namespace PKHeX.WinForms.Controls
{
@@ -6,8 +7,8 @@ public partial class PKMEditor
{
private void PopulateFieldsPK8()
{
if (!(pkm is PK8 pk8))
return;
if (!(Entity is PK8 pk8))
throw new FormatException(nameof(Entity));
LoadMisc1(pk8);
LoadMisc2(pk8);
@@ -20,10 +21,10 @@ private void PopulateFieldsPK8()
UpdateStats();
}
private PKM PreparePK8()
private PK8 PreparePK8()
{
if (!(pkm is PK8 pk8))
return null;
if (!(Entity is PK8 pk8))
throw new FormatException(nameof(Entity));
CheckTransferPIDValid();
SaveMisc1(pk8);

View File

@@ -5,7 +5,7 @@ namespace PKHeX.WinForms.Controls
public interface IMainEditor : IPKMView
{
void UpdateIVsGB(bool skipForm);
PKM pkm { get; }
PKM Entity { get; }
SaveFile RequestSaveFile { get; }
}
}

View File

@@ -174,8 +174,8 @@ private void LoadMisc2(PKM pk)
CB_Form.SelectedIndex = CB_Form.Items.Count > pk.AltForm ? pk.AltForm : CB_Form.Items.Count - 1;
TB_Friendship.Text = pk.CurrentFriendship.ToString();
Label_HatchCounter.Visible = CHK_IsEgg.Checked && pkm.Format > 1;
Label_Friendship.Visible = !CHK_IsEgg.Checked && pkm.Format > 1;
Label_HatchCounter.Visible = CHK_IsEgg.Checked && Entity.Format > 1;
Label_Friendship.Visible = !CHK_IsEgg.Checked && Entity.Format > 1;
}
private void SaveMisc2(PKM pk)
@@ -341,14 +341,14 @@ private void SaveHandlingTrainer(PKM pk)
// Misc
private void CheckTransferPIDValid()
{
if (pkm.Version >= 24)
if (Entity.Version >= 24)
return;
uint EC = Util.GetHexValue(TB_EC.Text);
uint PID = Util.GetHexValue(TB_PID.Text);
uint LID = PID & 0xFFFF;
uint HID = PID >> 16;
uint XOR = (uint)(pkm.TID ^ LID ^ pkm.SID ^ HID);
uint XOR = (uint)(Entity.TID ^ LID ^ Entity.SID ^ HID);
// Ensure we don't have a shiny.
if (XOR >> 3 == 1) // Illegal, fix. (not 16<XOR>=8)

View File

@@ -63,7 +63,7 @@ public void InitializeBinding()
private void UpdateStats()
{
Stats.UpdateStats();
if (pkm is PB7)
if (Entity is PB7)
SizeCP.TryResetStats();
}
@@ -75,7 +75,7 @@ private void SavePartyStats(PKM pk)
pk.Stat_Level = CurrentLevel;
}
public PKM CurrentPKM { get => PreparePKM(); set => pkm = value; }
public PKM CurrentPKM { get => PreparePKM(); set => Entity = value; }
public bool ModifyPKM { private get; set; } = true;
private bool _hideSecret;
@@ -97,8 +97,8 @@ public bool HideSecretValues
public bool HaX { get => _hax; set => _hax = Stats.HaX = value; }
public byte[] LastData { private get; set; }
public PKM Data { get => pkm; set => pkm = value; }
public PKM pkm { get; private set; }
public PKM Data { get => Entity; set => Entity = value; }
public PKM Entity { get; private set; }
public bool FieldsLoaded { get; private set; }
public bool ChangingFields { get; set; }
public int CurrentLevel => Util.ToInt32((HaX ? MT_Level : TB_Level).Text);
@@ -136,10 +136,8 @@ public PKM PreparePKM(bool click = true)
ValidateChildren();
forceValidation = false;
}
var pk = GetPKMfromFields();
if (pk == null)
return pkm;
var pk = GetPKMfromFields();
LastData = pk.Data;
return pk.Clone();
}
@@ -237,12 +235,12 @@ private void LoadFieldsFromPKM(PKM pk, bool focus = true, bool skipConversionChe
if (focus)
Tab_Main.Focus();
if (!skipConversionCheck && !PKMConverter.TryMakePKMCompatible(pk, pkm, out string c, out pk))
if (!skipConversionCheck && !PKMConverter.TryMakePKMCompatible(pk, Entity, out string c, out pk))
{ WinFormsUtil.Alert(c); return; }
FieldsLoaded = false;
pkm = pk.Clone();
Entity = pk.Clone();
try { GetFieldsfromPKM(); }
catch { }
@@ -273,8 +271,8 @@ public void UpdateLegality(LegalityAnalysis la = null, bool skipMoveRepop = fals
if (!FieldsLoaded)
return;
Legality = la ?? new LegalityAnalysis(pkm, RequestSaveFile.Personal);
if (!Legality.Parsed || HaX || pkm.Species == 0)
Legality = la ?? new LegalityAnalysis(Entity, RequestSaveFile.Personal);
if (!Legality.Parsed || HaX || Entity.Species == 0)
{
PB_WarnMove1.Visible = PB_WarnMove2.Visible = PB_WarnMove3.Visible = PB_WarnMove4.Visible =
PB_WarnRelearn1.Visible = PB_WarnRelearn2.Visible = PB_WarnRelearn3.Visible = PB_WarnRelearn4.Visible = false;
@@ -286,7 +284,7 @@ public void UpdateLegality(LegalityAnalysis la = null, bool skipMoveRepop = fals
for (int i = 0; i < 4; i++)
movePB[i].Visible = !Legality.Info?.Moves[i].Valid ?? false;
if (pkm.Format >= 6)
if (Entity.Format >= 6)
{
for (int i = 0; i < 4; i++)
relearnPB[i].Visible = !Legality.Info?.Relearn[i].Valid ?? false;
@@ -364,8 +362,8 @@ private void SetDetailsOT(ITrainerInfo tr)
}
// Copy OT trash bytes for sensitive games (Gen1/2)
if (tr is SAV1 s1 && pkm is PK1 p1) p1.OT_Trash = s1.OT_Trash;
else if (tr is SAV2 s2 && pkm is PK2 p2) p2.OT_Trash = s2.OT_Trash;
if (tr is SAV1 s1 && Entity is PK1 p1) p1.OT_Trash = s1.OT_Trash;
else if (tr is SAV2 s2 && Entity is PK2 p2) p2.OT_Trash = s2.OT_Trash;
UpdateNickname(null, EventArgs.Empty);
}
@@ -381,18 +379,18 @@ private void SetDetailsHT(ITrainerInfo tr)
private void SetForms()
{
int species = pkm.Species;
var pi = RequestSaveFile?.Personal[species] ?? pkm.PersonalInfo;
bool hasForms = FormConverter.HasFormSelection(pi, species, pkm.Format);
int species = Entity.Species;
var pi = RequestSaveFile?.Personal[species] ?? Entity.PersonalInfo;
bool hasForms = FormConverter.HasFormSelection(pi, species, Entity.Format);
CB_Form.Enabled = CB_Form.Visible = Label_Form.Visible = hasForms;
if (HaX && pkm.Format >= 4)
if (HaX && Entity.Format >= 4)
Label_Form.Visible = true; // show with value entry textbox
if (!hasForms)
return;
var ds = FormConverter.GetFormList(species, GameInfo.Strings.types, GameInfo.Strings.forms, gendersymbols, pkm.Format);
var ds = FormConverter.GetFormList(species, GameInfo.Strings.types, GameInfo.Strings.forms, gendersymbols, Entity.Format);
if (ds.Length == 1 && string.IsNullOrEmpty(ds[0])) // empty (Alolan Totems)
CB_Form.Enabled = CB_Form.Visible = Label_Form.Visible = false;
else
@@ -401,17 +399,17 @@ private void SetForms()
private void SetAbilityList()
{
if (pkm.Format < 3) // no abilities
if (Entity.Format < 3) // no abilities
return;
if (pkm.Format > 3 && FieldsLoaded) // has forms
pkm.AltForm = CB_Form.SelectedIndex; // update pkm field for form specific abilities
if (Entity.Format > 3 && FieldsLoaded) // has forms
Entity.AltForm = CB_Form.SelectedIndex; // update pkm field for form specific abilities
int abil = CB_Ability.SelectedIndex;
bool tmp = FieldsLoaded;
FieldsLoaded = false;
CB_Ability.DataSource = GameInfo.FilteredSources.GetAbilityList(pkm);
CB_Ability.DataSource = GameInfo.FilteredSources.GetAbilityList(Entity);
CB_Ability.SelectedIndex = GetSafeIndex(CB_Ability, abil); // restore original index if available
FieldsLoaded = tmp;
}
@@ -421,7 +419,7 @@ private void SetAbilityList()
private void UpdateIsShiny()
{
// Recalculate shininiess
bool isShiny = pkm.IsShiny;
bool isShiny = Entity.IsShiny;
// Set the Controls
BTN_Shinytize.Visible = BTN_Shinytize.Enabled = !isShiny;
@@ -438,23 +436,23 @@ private void SetMarkings()
: ImageUtil.ChangeOpacity(p.InitialImage, opacity);
var pba = Markings;
var markings = pkm.Markings;
var markings = Entity.Markings;
for (int i = 0; i < pba.Length; i++)
pba[i].Image = changeOpacity(pba[i], getOpacity(markings[i] != 0));
PB_MarkShiny.Image = changeOpacity(PB_MarkShiny, getOpacity(!BTN_Shinytize.Enabled));
PB_MarkCured.Image = changeOpacity(PB_MarkCured, getOpacity(CHK_Cured.Checked));
PB_MarkPentagon.Image = changeOpacity(PB_MarkPentagon, getOpacity(pkm.Gen6));
PB_Favorite.Image = changeOpacity(PB_Favorite, getOpacity(pkm is PB7 pb7 && pb7.Favorite));
PB_MarkPentagon.Image = changeOpacity(PB_MarkPentagon, getOpacity(Entity.Gen6));
PB_Favorite.Image = changeOpacity(PB_Favorite, getOpacity(Entity is PB7 pb7 && pb7.Favorite));
// Gen7 Markings
if (pkm.Format != 7)
if (Entity.Format != 7)
return;
PB_MarkAlola.Image = changeOpacity(PB_MarkAlola, getOpacity(pkm.Gen7));
PB_MarkVC.Image = changeOpacity(PB_MarkVC, getOpacity(pkm.VC));
PB_MarkGO.Image = changeOpacity(PB_MarkGO, getOpacity(pkm.GO));
PB_MarkAlola.Image = changeOpacity(PB_MarkAlola, getOpacity(Entity.Gen7));
PB_MarkVC.Image = changeOpacity(PB_MarkVC, getOpacity(Entity.VC));
PB_MarkGO.Image = changeOpacity(PB_MarkGO, getOpacity(Entity.GO));
for (int i = 0; i < pba.Length; i++)
{
@@ -465,7 +463,7 @@ private void SetMarkings()
private void UpdateGender()
{
int Gender = pkm.GetSaneGender();
int Gender = Entity.GetSaneGender();
Label_Gender.Text = gendersymbols[Gender];
Label_Gender.ForeColor = Draw.GetGenderColor(Gender);
}
@@ -485,7 +483,7 @@ private void ClickFriendship(object sender, EventArgs e)
if (ModifierKeys == Keys.Control) // clear
TB_Friendship.Text = "0";
else
TB_Friendship.Text = TB_Friendship.Text == "255" ? pkm.PersonalInfo.BaseFriendship.ToString() : "255";
TB_Friendship.Text = TB_Friendship.Text == "255" ? Entity.PersonalInfo.BaseFriendship.ToString() : "255";
}
private void ClickLevel(object sender, EventArgs e)
@@ -496,25 +494,25 @@ private void ClickLevel(object sender, EventArgs e)
private void ClickGender(object sender, EventArgs e)
{
if (!pkm.PersonalInfo.IsDualGender)
if (!Entity.PersonalInfo.IsDualGender)
return; // can't toggle
int newGender = (PKX.GetGenderFromString(Label_Gender.Text) & 1) ^ 1;
if (pkm.Format <= 2)
if (Entity.Format <= 2)
{
Stats.SetATKIVGender(newGender);
UpdateIsShiny();
}
else if (pkm.Format <= 4)
else if (Entity.Format <= 4)
{
pkm.Version = WinFormsUtil.GetIndex(CB_GameOrigin);
pkm.Nature = WinFormsUtil.GetIndex(CB_Nature);
pkm.AltForm = CB_Form.SelectedIndex;
Entity.Version = WinFormsUtil.GetIndex(CB_GameOrigin);
Entity.Nature = WinFormsUtil.GetIndex(CB_Nature);
Entity.AltForm = CB_Form.SelectedIndex;
pkm.SetPIDGender(newGender);
TB_PID.Text = pkm.PID.ToString("X8");
Entity.SetPIDGender(newGender);
TB_PID.Text = Entity.PID.ToString("X8");
}
pkm.Gender = newGender;
Entity.Gender = newGender;
Label_Gender.Text = gendersymbols[newGender];
Label_Gender.ForeColor = Draw.GetGenderColor(newGender);
@@ -537,13 +535,13 @@ private void ClickPPUps(object sender, EventArgs e)
private void ClickMarking(object sender, EventArgs e)
{
int index = Array.IndexOf(Markings, (PictureBox)sender);
pkm.ToggleMarking(index);
Entity.ToggleMarking(index);
SetMarkings();
}
private void ClickFavorite(object sender, EventArgs e)
{
if (pkm is PB7 pb7)
if (Entity is PB7 pb7)
pb7.Favorite ^= true;
SetMarkings();
}
@@ -565,7 +563,7 @@ private void ClickTRGender(object sender, EventArgs e)
private void ClickBall(object sender, EventArgs e)
{
pkm.Ball = WinFormsUtil.GetIndex(CB_Ball);
Entity.Ball = WinFormsUtil.GetIndex(CB_Ball);
if (ModifierKeys.HasFlag(Keys.Alt))
{
CB_Ball.SelectedValue = (int)Ball.Poke;
@@ -573,12 +571,12 @@ private void ClickBall(object sender, EventArgs e)
}
if (ModifierKeys.HasFlag(Keys.Shift))
{
CB_Ball.SelectedValue = BallRandomizer.ApplyBallLegalByColor(pkm);
CB_Ball.SelectedValue = BallRandomizer.ApplyBallLegalByColor(Entity);
return;
}
using var frm = new BallBrowser();
frm.LoadBalls(pkm);
frm.LoadBalls(Entity);
frm.ShowDialog();
if (frm.BallChoice >= 0)
CB_Ball.SelectedValue = frm.BallChoice;
@@ -591,14 +589,14 @@ private void ClickMetLocation(object sender, EventArgs e)
if (HaX)
return;
pkm = PreparePKM();
Entity = PreparePKM();
UpdateLegality(skipMoveRepop: true);
if (Legality.Valid)
return;
if (!SetSuggestedMetLocation())
return;
pkm = PreparePKM();
Entity = PreparePKM();
UpdateLegality();
}
@@ -608,12 +606,12 @@ private void ClickGT(object sender, EventArgs e)
return;
if (sender == GB_OT)
pkm.CurrentHandler = 0;
Entity.CurrentHandler = 0;
else if (TB_OTt2.Text.Length > 0)
pkm.CurrentHandler = 1;
UpadteHandlingTrainerBackground(pkm);
Entity.CurrentHandler = 1;
UpadteHandlingTrainerBackground(Entity);
TB_Friendship.Text = pkm.CurrentFriendship.ToString();
TB_Friendship.Text = Entity.CurrentFriendship.ToString();
}
private void ClickMoves(object sender, EventArgs e)
@@ -639,7 +637,7 @@ private void ClickMoves(object sender, EventArgs e)
private bool SetSuggestedMoves(bool random = false, bool silent = false)
{
int[] m = pkm.GetMoveSet(random);
int[] m = Entity.GetMoveSet(random);
if (m?.Any(z => z != 0) != true)
{
if (!silent)
@@ -647,7 +645,7 @@ private bool SetSuggestedMoves(bool random = false, bool silent = false)
return false;
}
if (pkm.Moves.SequenceEqual(m))
if (Entity.Moves.SequenceEqual(m))
return false;
if (!silent)
@@ -659,20 +657,20 @@ private bool SetSuggestedMoves(bool random = false, bool silent = false)
return false;
}
pkm.SetMoves(m);
Entity.SetMoves(m);
FieldsLoaded = false;
LoadMoves(pkm);
LoadMoves(Entity);
FieldsLoaded = true;
return true;
}
private bool SetSuggestedRelearnMoves(bool silent = false)
{
if (pkm.Format < 6)
if (Entity.Format < 6)
return false;
var m = Legality.GetSuggestedRelearnMoves();
if (pkm.RelearnMoves.SequenceEqual(m))
if (Entity.RelearnMoves.SequenceEqual(m))
return false;
if (!silent)
@@ -694,7 +692,7 @@ private bool SetSuggestedRelearnMoves(bool silent = false)
private bool SetSuggestedMetLocation(bool silent = false)
{
var encounter = Legality.GetSuggestedMetInfo();
if (encounter == null || (pkm.Format >= 3 && encounter.Location < 0))
if (encounter == null || (Entity.Format >= 3 && encounter.Location < 0))
{
if (!silent)
WinFormsUtil.Alert(MsgPKMSuggestionNone);
@@ -703,18 +701,18 @@ private bool SetSuggestedMetLocation(bool silent = false)
int level = encounter.Level;
int location = encounter.Location;
int minlvl = Legal.GetLowestLevel(pkm, encounter.LevelMin);
int minlvl = Legal.GetLowestLevel(Entity, encounter.LevelMin);
if (minlvl == 0)
minlvl = level;
if (pkm.CurrentLevel >= minlvl && pkm.Met_Level == level && pkm.Met_Location == location)
if (Entity.CurrentLevel >= minlvl && Entity.Met_Level == level && Entity.Met_Location == location)
return false;
if (minlvl < level)
minlvl = level;
if (!silent)
{
var suggestions = EditPKMUtil.GetSuggestionMessage(pkm, level, location, minlvl);
var suggestions = EditPKMUtil.GetSuggestionMessage(Entity, level, location, minlvl);
if (suggestions.Count <= 1) // no suggestion
return false;
@@ -723,16 +721,16 @@ private bool SetSuggestedMetLocation(bool silent = false)
return false;
}
if (pkm.Format >= 3)
if (Entity.Format >= 3)
{
TB_MetLevel.Text = level.ToString();
CB_MetLocation.SelectedValue = location;
if (pkm.Gen6 && pkm.WasEgg && ModifyPKM)
pkm.SetHatchMemory6();
if (Entity.Gen6 && Entity.WasEgg && ModifyPKM)
Entity.SetHatchMemory6();
}
if (pkm.CurrentLevel < minlvl)
if (Entity.CurrentLevel < minlvl)
TB_Level.Text = minlvl.ToString();
return true;
@@ -742,10 +740,10 @@ public void UpdateIVsGB(bool skipForm)
{
if (!FieldsLoaded)
return;
Label_Gender.Text = gendersymbols[pkm.Gender];
Label_Gender.ForeColor = Draw.GetGenderColor(pkm.Gender);
if (pkm.Species == (int)Species.Unown && !skipForm)
CB_Form.SelectedIndex = pkm.AltForm;
Label_Gender.Text = gendersymbols[Entity.Gender];
Label_Gender.ForeColor = Draw.GetGenderColor(Entity.Gender);
if (Entity.Species == (int)Species.Unown && !skipForm)
CB_Form.SelectedIndex = Entity.AltForm;
UpdateIsShiny();
UpdateSprite();
@@ -765,8 +763,8 @@ private void UpdateEXPLevel(object sender, EventArgs e)
{
// Change the Level
uint EXP = Util.ToUInt32(TB_EXP.Text);
int Species = pkm.Species;
int Form = pkm.AltForm;
int Species = Entity.Species;
int Form = Entity.AltForm;
int Level = Experience.GetLevel(EXP, Species, Form);
if (Level == 100)
EXP = Experience.GetEXP(100, Species, Form);
@@ -794,13 +792,13 @@ private void UpdateEXPLevel(object sender, EventArgs e)
if (Level > byte.MaxValue)
MT_Level.Text = "255";
else if (Level <= 100)
TB_EXP.Text = Experience.GetEXP(Level, pkm.Species, pkm.AltForm).ToString();
TB_EXP.Text = Experience.GetEXP(Level, Entity.Species, Entity.AltForm).ToString();
}
ChangingFields = false;
if (FieldsLoaded) // store values back
{
pkm.EXP = Util.ToUInt32(TB_EXP.Text);
pkm.Stat_Level = Util.ToInt32((HaX ? MT_Level : TB_Level).Text);
Entity.EXP = Util.ToUInt32(TB_EXP.Text);
Entity.Stat_Level = Util.ToInt32((HaX ? MT_Level : TB_Level).Text);
}
UpdateStats();
UpdateLegality();
@@ -808,33 +806,33 @@ private void UpdateEXPLevel(object sender, EventArgs e)
private void UpdateRandomPID(object sender, EventArgs e)
{
if (pkm.Format < 3)
if (Entity.Format < 3)
return;
if (FieldsLoaded)
pkm.PID = Util.GetHexValue(TB_PID.Text);
Entity.PID = Util.GetHexValue(TB_PID.Text);
if (sender == Label_Gender)
pkm.SetPIDGender(pkm.Gender);
else if (sender == CB_Nature && pkm.Nature != WinFormsUtil.GetIndex(CB_Nature))
pkm.SetPIDNature(WinFormsUtil.GetIndex(CB_Nature));
Entity.SetPIDGender(Entity.Gender);
else if (sender == CB_Nature && Entity.Nature != WinFormsUtil.GetIndex(CB_Nature))
Entity.SetPIDNature(WinFormsUtil.GetIndex(CB_Nature));
else if (sender == BTN_RerollPID)
pkm.SetPIDGender(pkm.Gender);
else if (sender == CB_Ability && CB_Ability.SelectedIndex != pkm.PIDAbility && pkm.PIDAbility > -1)
pkm.SetAbilityIndex(CB_Ability.SelectedIndex);
Entity.SetPIDGender(Entity.Gender);
else if (sender == CB_Ability && CB_Ability.SelectedIndex != Entity.PIDAbility && Entity.PIDAbility > -1)
Entity.SetAbilityIndex(CB_Ability.SelectedIndex);
TB_PID.Text = pkm.PID.ToString("X8");
if (pkm.Format >= 6 && (pkm.Gen3 || pkm.Gen4 || pkm.Gen5))
TB_PID.Text = Entity.PID.ToString("X8");
if (Entity.Format >= 6 && (Entity.Gen3 || Entity.Gen4 || Entity.Gen5))
TB_EC.Text = TB_PID.Text;
Update_ID(TB_EC, e);
}
private void UpdateRandomEC(object sender, EventArgs e)
{
if (pkm.Format < 6)
if (Entity.Format < 6)
return;
pkm.SetRandomEC();
TB_EC.Text = pkm.EncryptionConstant.ToString("X8");
Entity.SetRandomEC();
TB_EC.Text = Entity.EncryptionConstant.ToString("X8");
Update_ID(TB_EC, e);
UpdateLegality();
}
@@ -847,7 +845,7 @@ private void Update255_MTB(object sender, EventArgs e)
tb.Text = "255";
if (sender == TB_Friendship && int.TryParse(TB_Friendship.Text, out var val))
{
pkm.CurrentFriendship = val;
Entity.CurrentFriendship = val;
UpdateStats();
}
}
@@ -856,8 +854,8 @@ private void UpdateForm(object sender, EventArgs e)
{
if (CB_Form == sender && FieldsLoaded)
{
pkm.AltForm = CB_Form.SelectedIndex;
uint EXP = Experience.GetEXP(pkm.CurrentLevel, pkm.Species, pkm.AltForm);
Entity.AltForm = CB_Form.SelectedIndex;
uint EXP = Experience.GetEXP(Entity.CurrentLevel, Entity.Species, Entity.AltForm);
TB_EXP.Text = EXP.ToString();
}
@@ -867,15 +865,15 @@ private void UpdateForm(object sender, EventArgs e)
// Gender Forms
if (WinFormsUtil.GetIndex(CB_Species) == (int)Species.Unown && FieldsLoaded)
{
if (pkm.Format == 3)
if (Entity.Format == 3)
{
pkm.SetPIDUnown3(CB_Form.SelectedIndex);
TB_PID.Text = pkm.PID.ToString("X8");
Entity.SetPIDUnown3(CB_Form.SelectedIndex);
TB_PID.Text = Entity.PID.ToString("X8");
}
else if (pkm.Format == 2)
else if (Entity.Format == 2)
{
int desiredForm = CB_Form.SelectedIndex;
while (pkm.AltForm != desiredForm)
while (Entity.AltForm != desiredForm)
{
FieldsLoaded = false;
Stats.UpdateRandomIVs(null, EventArgs.Empty);
@@ -887,7 +885,7 @@ private void UpdateForm(object sender, EventArgs e)
{
if (CB_Form.Items.Count == 2) // actually M/F; Pumpkaboo formes in German are S,M,L,XL
{
pkm.Gender = CB_Form.SelectedIndex;
Entity.Gender = CB_Form.SelectedIndex;
UpdateGender();
}
}
@@ -910,7 +908,7 @@ private void UpdateHaXForm(object sender, EventArgs e)
if (ChangingFields)
return;
ChangingFields = true;
int form = pkm.AltForm = Util.ToInt32(MT_Form.Text);
int form = Entity.AltForm = Util.ToInt32(MT_Form.Text);
CB_Form.SelectedIndex = CB_Form.Items.Count > form ? form : -1;
ChangingFields = false;
@@ -937,7 +935,7 @@ private void UpdatePP(object sender, EventArgs e)
}
else
{
MovePP[index].Text = pkm.GetMovePP(move, ppups).ToString();
MovePP[index].Text = Entity.GetMovePP(move, ppups).ToString();
}
}
@@ -1036,8 +1034,8 @@ private void UpdateSpecies(object sender, EventArgs e)
{
// Get Species dependent information
if (FieldsLoaded)
pkm.Species = WinFormsUtil.GetIndex(CB_Species);
SpeciesIDTip.SetToolTip(CB_Species, pkm.Species.ToString("000"));
Entity.Species = WinFormsUtil.GetIndex(CB_Species);
SpeciesIDTip.SetToolTip(CB_Species, Entity.Species.ToString("000"));
SetAbilityList();
SetForms();
UpdateForm(null, EventArgs.Empty);
@@ -1046,7 +1044,7 @@ private void UpdateSpecies(object sender, EventArgs e)
return;
// Recalculate EXP for Given Level
uint EXP = Experience.GetEXP(pkm.CurrentLevel, pkm.Species, pkm.AltForm);
uint EXP = Experience.GetEXP(Entity.CurrentLevel, Entity.Species, Entity.AltForm);
TB_EXP.Text = EXP.ToString();
// Check for Gender Changes
@@ -1063,7 +1061,7 @@ private void UpdateOriginGame(object sender, EventArgs e)
{
GameVersion Version = (GameVersion)WinFormsUtil.GetIndex(CB_GameOrigin);
if (FieldsLoaded)
pkm.Version = (int)Version;
Entity.Version = (int)Version;
// check if differs
var group = GameUtil.GetMetLocationVersionGroup(Version);
@@ -1073,10 +1071,10 @@ private void UpdateOriginGame(object sender, EventArgs e)
origintrack = group;
// Visibility logic for Gen 4 encounter type; only show for Gen 4 Pokemon.
if (pkm.Format >= 4)
if (Entity.Format >= 4)
{
bool g4 = pkm.Gen4;
CB_EncounterType.Visible = Label_EncounterType.Visible = g4 && pkm.Format < 7;
bool g4 = Entity.Gen4;
CB_EncounterType.Visible = Label_EncounterType.Visible = g4 && Entity.Format < 7;
if (!g4)
CB_EncounterType.SelectedValue = 0;
}
@@ -1084,28 +1082,28 @@ private void UpdateOriginGame(object sender, EventArgs e)
if (!FieldsLoaded)
return;
TID_Trainer.LoadIDValues(pkm);
TID_Trainer.LoadIDValues(Entity);
UpdateLegality();
}
private void ReloadMetLocations(GameVersion Version)
{
var met_list = GameInfo.GetLocationList(Version, pkm.Format, egg: false);
var met_list = GameInfo.GetLocationList(Version, Entity.Format, egg: false);
CB_MetLocation.DataSource = new BindingSource(met_list, null);
var egg_list = GameInfo.GetLocationList(Version, pkm.Format, egg: true);
var egg_list = GameInfo.GetLocationList(Version, Entity.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)
if (Version == GameVersion.CXD && Entity.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);
int metLoc = EncounterSuggestion.GetSuggestedTransferLocation(Entity);
CB_MetLocation.SelectedValue = Math.Max(0, metLoc);
CB_EggLocation.SelectedIndex = CHK_AsEgg.Checked ? 1 : 0; // daycare : none
}
@@ -1125,7 +1123,7 @@ private void UpdateExtraByteValue(object sender, EventArgs e)
int value = Util.ToInt32(mtb.Text);
int offset = Convert.ToInt32(CB_ExtraBytes.Text, 16);
pkm.Data[offset] = (byte)value;
Entity.Data[offset] = (byte)value;
}
private void UpdateExtraByteIndex(object sender, EventArgs e)
@@ -1133,12 +1131,12 @@ private void UpdateExtraByteIndex(object sender, EventArgs e)
if (CB_ExtraBytes.Items.Count == 0)
return;
// Byte changed, need to refresh the Text box for the byte's value.
TB_ExtraByte.Text = pkm.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString();
TB_ExtraByte.Text = Entity.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString();
}
private void UpdateNatureModification(object sender, EventArgs e)
{
string text = Stats.UpdateNatureModification(pkm.Nature);
string text = Stats.UpdateNatureModification(Entity.Nature);
NatureTip.SetToolTip(CB_Nature, text);
}
@@ -1147,18 +1145,18 @@ private void UpdateIsNicknamed(object sender, EventArgs e)
if (!FieldsLoaded)
return;
pkm.Nickname = TB_Nickname.Text;
Entity.Nickname = TB_Nickname.Text;
if (CHK_Nicknamed.Checked)
return;
int species = WinFormsUtil.GetIndex(CB_Species);
if (species < 1 || species > pkm.MaxSpeciesID)
if (species < 1 || species > Entity.MaxSpeciesID)
return;
if (CHK_IsEgg.Checked)
species = 0; // get the egg name.
if (SpeciesName.IsNicknamedAnyLanguage(species, TB_Nickname.Text, pkm.Format))
if (SpeciesName.IsNicknamedAnyLanguage(species, TB_Nickname.Text, Entity.Format))
CHK_Nicknamed.Checked = true;
}
@@ -1182,18 +1180,18 @@ private void UpdateNickname(object sender, EventArgs e)
// Fetch Current Species and set it as Nickname Text
int species = WinFormsUtil.GetIndex(CB_Species);
if (species < 1 || species > pkm.MaxSpeciesID)
if (species < 1 || species > Entity.MaxSpeciesID)
{ TB_Nickname.Text = string.Empty; return; }
if (CHK_IsEgg.Checked)
species = 0; // get the egg name.
// If name is that of another language, don't replace the nickname
if (sender != CB_Language && species != 0 && !SpeciesName.IsNicknamedAnyLanguage(species, TB_Nickname.Text, pkm.Format))
if (sender != CB_Language && species != 0 && !SpeciesName.IsNicknamedAnyLanguage(species, TB_Nickname.Text, Entity.Format))
return;
TB_Nickname.Text = SpeciesName.GetSpeciesNameGeneration(species, lang, pkm.Format);
if (pkm is GBPKM pk)
TB_Nickname.Text = SpeciesName.GetSpeciesNameGeneration(species, lang, Entity.Format);
if (Entity is GBPKM pk)
pk.SetNotNicknamed();
}
@@ -1210,27 +1208,27 @@ private void UpdateNicknameClick(object sender, MouseEventArgs e)
if (tb == TB_Nickname)
{
pkm.Nickname = tb.Text;
var d = new TrashEditor(tb, pkm.Nickname_Trash, sav);
Entity.Nickname = tb.Text;
var d = new TrashEditor(tb, Entity.Nickname_Trash, sav);
d.ShowDialog();
tb.Text = d.FinalString;
pkm.Nickname_Trash = d.FinalBytes;
Entity.Nickname_Trash = d.FinalBytes;
}
else if (tb == TB_OT)
{
pkm.OT_Name = tb.Text;
var d = new TrashEditor(tb, pkm.OT_Trash, sav);
Entity.OT_Name = tb.Text;
var d = new TrashEditor(tb, Entity.OT_Trash, sav);
d.ShowDialog();
tb.Text = d.FinalString;
pkm.OT_Trash = d.FinalBytes;
Entity.OT_Trash = d.FinalBytes;
}
else if (tb == TB_OTt2)
{
pkm.HT_Name = tb.Text;
var d = new TrashEditor(tb, pkm.HT_Trash, sav);
Entity.HT_Name = tb.Text;
var d = new TrashEditor(tb, Entity.HT_Trash, sav);
d.ShowDialog();
tb.Text = d.FinalString;
pkm.HT_Trash = d.FinalBytes;
Entity.HT_Trash = d.FinalBytes;
}
}
@@ -1240,7 +1238,7 @@ private void UpdateNotOT(object sender, EventArgs e)
{
ClickGT(GB_OT, null); // Switch CT over to OT.
Label_CTGender.Text = string.Empty;
TB_Friendship.Text = pkm.CurrentFriendship.ToString();
TB_Friendship.Text = Entity.CurrentFriendship.ToString();
}
else if (string.IsNullOrWhiteSpace(Label_CTGender.Text))
{
@@ -1251,13 +1249,13 @@ private void UpdateNotOT(object sender, EventArgs e)
private void UpdateIsEgg(object sender, EventArgs e)
{
// Display hatch counter if it is an egg, Display Friendship if it is not.
Label_HatchCounter.Visible = CHK_IsEgg.Checked && pkm.Format > 1;
Label_Friendship.Visible = !CHK_IsEgg.Checked && pkm.Format > 1;
Label_HatchCounter.Visible = CHK_IsEgg.Checked && Entity.Format > 1;
Label_Friendship.Visible = !CHK_IsEgg.Checked && Entity.Format > 1;
if (!FieldsLoaded)
return;
pkm.IsEgg = CHK_IsEgg.Checked;
Entity.IsEgg = CHK_IsEgg.Checked;
if (CHK_IsEgg.Checked)
{
TB_Friendship.Text = "1";
@@ -1272,26 +1270,26 @@ private void UpdateIsEgg(object sender, EventArgs e)
bool isTraded = false;
var sav = SaveFileRequested?.Invoke(this, e);
if (sav != null)
isTraded = sav.OT != TB_OT.Text || sav.TID != pkm.TID || sav.SID != pkm.SID;
isTraded = sav.OT != TB_OT.Text || sav.TID != Entity.TID || sav.SID != Entity.SID;
CB_MetLocation.SelectedIndex = isTraded ? 2 : 0;
if (!CHK_Nicknamed.Checked)
{
TB_Nickname.Text = SpeciesName.GetSpeciesNameGeneration(0, WinFormsUtil.GetIndex(CB_Language), pkm.Format);
if (pkm.Format != 4) // eggs in gen4 do not have nickname flag
TB_Nickname.Text = SpeciesName.GetSpeciesNameGeneration(0, WinFormsUtil.GetIndex(CB_Language), Entity.Format);
if (Entity.Format != 4) // eggs in gen4 do not have nickname flag
CHK_Nicknamed.Checked = true;
}
// Wipe egg memories
if (pkm.Format >= 6 && ModifyPKM)
pkm.ClearMemories();
if (Entity.Format >= 6 && ModifyPKM)
Entity.ClearMemories();
}
else // Not Egg
{
if (!CHK_Nicknamed.Checked)
UpdateNickname(null, EventArgs.Empty);
TB_Friendship.Text = pkm.PersonalInfo.BaseFriendship.ToString();
TB_Friendship.Text = Entity.PersonalInfo.BaseFriendship.ToString();
if (CB_EggLocation.SelectedIndex == 0)
{
@@ -1300,7 +1298,7 @@ private void UpdateIsEgg(object sender, EventArgs e)
GB_EggConditions.Enabled = false;
}
if (TB_Nickname.Text == SpeciesName.GetSpeciesNameGeneration(0, WinFormsUtil.GetIndex(CB_Language), pkm.Format))
if (TB_Nickname.Text == SpeciesName.GetSpeciesNameGeneration(0, WinFormsUtil.GetIndex(CB_Language), Entity.Format))
CHK_Nicknamed.Checked = false;
}
@@ -1330,38 +1328,38 @@ private void UpdateMetAsEgg(object sender, EventArgs e)
private void UpdateShinyPID(object sender, EventArgs e)
{
var ShinyPID = pkm.Format <= 2 || ModifierKeys != Keys.Control;
var ShinyPID = Entity.Format <= 2 || ModifierKeys != Keys.Control;
UpdateShiny(ShinyPID);
}
private void UpdateShiny(bool PID)
{
pkm.PID = Util.GetHexValue(TB_PID.Text);
pkm.Nature = WinFormsUtil.GetIndex(CB_Nature);
pkm.Gender = PKX.GetGenderFromString(Label_Gender.Text);
pkm.AltForm = CB_Form.SelectedIndex;
pkm.Version = WinFormsUtil.GetIndex(CB_GameOrigin);
Entity.PID = Util.GetHexValue(TB_PID.Text);
Entity.Nature = WinFormsUtil.GetIndex(CB_Nature);
Entity.Gender = PKX.GetGenderFromString(Label_Gender.Text);
Entity.AltForm = CB_Form.SelectedIndex;
Entity.Version = WinFormsUtil.GetIndex(CB_GameOrigin);
if (pkm.Format > 2)
if (Entity.Format > 2)
{
if (PID)
{
pkm.SetShiny();
TB_PID.Text = pkm.PID.ToString("X8");
Entity.SetShiny();
TB_PID.Text = Entity.PID.ToString("X8");
if (pkm.GenNumber < 6 && TB_EC.Visible)
if (Entity.GenNumber < 6 && TB_EC.Visible)
TB_EC.Text = TB_PID.Text;
}
else
{
pkm.SetShinySID();
Entity.SetShinySID();
TID_Trainer.UpdateSID();
}
}
else
{
pkm.SetShiny();
Stats.LoadIVs(pkm.IVs);
Entity.SetShiny();
Stats.LoadIVs(Entity.IVs);
Stats.UpdateIVs(null, EventArgs.Empty);
}
@@ -1372,13 +1370,13 @@ private void UpdateShiny(bool PID)
private void UpdateTSV(object sender, EventArgs e)
{
if (pkm.Format < 6)
if (Entity.Format < 6)
return;
TID_Trainer.UpdateTSV();
pkm.PID = Util.GetHexValue(TB_PID.Text);
Tip3.SetToolTip(TB_PID, $"PSV: {pkm.PSV:d4}");
Entity.PID = Util.GetHexValue(TB_PID.Text);
Tip3.SetToolTip(TB_PID, $"PSV: {Entity.PSV:d4}");
}
private void Update_ID(object sender, EventArgs e)
@@ -1386,19 +1384,19 @@ private void Update_ID(object sender, EventArgs e)
if (!FieldsLoaded)
return;
// Trim out nonhex characters
TB_PID.Text = (pkm.PID = Util.GetHexValue(TB_PID.Text)).ToString("X8");
TB_EC.Text = (pkm.EncryptionConstant = Util.GetHexValue(TB_EC.Text)).ToString("X8");
TB_PID.Text = (Entity.PID = Util.GetHexValue(TB_PID.Text)).ToString("X8");
TB_EC.Text = (Entity.EncryptionConstant = Util.GetHexValue(TB_EC.Text)).ToString("X8");
UpdateIsShiny();
UpdateSprite();
Stats.UpdateCharacteristic(); // If the EC is changed, EC%6 (Characteristic) might be changed.
if (pkm.Format <= 4)
if (Entity.Format <= 4)
{
FieldsLoaded = false;
pkm.PID = Util.GetHexValue(TB_PID.Text);
CB_Nature.SelectedValue = pkm.Nature;
Label_Gender.Text = gendersymbols[pkm.Gender];
Label_Gender.ForeColor = Draw.GetGenderColor(pkm.Gender);
Entity.PID = Util.GetHexValue(TB_PID.Text);
CB_Nature.SelectedValue = Entity.Nature;
Label_Gender.Text = gendersymbols[Entity.Gender];
Label_Gender.ForeColor = Draw.GetGenderColor(Entity.Gender);
FieldsLoaded = true;
}
}
@@ -1425,7 +1423,7 @@ private void UpdateShadowCHK(object sender, EventArgs e)
return;
FieldsLoaded = false;
NUD_Purification.Value = CHK_Shadow.Checked ? NUD_Purification.Maximum : 0;
((IShadowPKM)pkm).Purification = (int)NUD_Purification.Value;
((IShadowPKM)Entity).Purification = (int)NUD_Purification.Value;
UpdatePreviewSprite?.Invoke(this, EventArgs.Empty);
FieldsLoaded = true;
}
@@ -1457,17 +1455,17 @@ private void ValidateComboBox2(object sender, EventArgs e)
ValidateComboBox(sender, null);
if (sender == CB_Ability)
{
if (pkm.Format >= 6)
if (Entity.Format >= 6)
TB_AbilityNumber.Text = (1 << CB_Ability.SelectedIndex).ToString();
else if (pkm.Format <= 5 && CB_Ability.SelectedIndex < 2) // Format <= 5, not hidden
else if (Entity.Format <= 5 && CB_Ability.SelectedIndex < 2) // Format <= 5, not hidden
UpdateRandomPID(sender, e);
UpdateLegality();
}
else if (sender == CB_Nature)
{
if (pkm.Format <= 4)
if (Entity.Format <= 4)
UpdateRandomPID(sender, e);
pkm.Nature = WinFormsUtil.GetIndex(CB_Nature);
Entity.Nature = WinFormsUtil.GetIndex(CB_Nature);
UpdateNatureModification(sender, EventArgs.Empty);
Stats.UpdateIVs(null, EventArgs.Empty); // updating Nature will trigger stats to update as well
UpdateLegality();
@@ -1488,8 +1486,8 @@ private void ValidateMove(object sender, EventArgs e)
UpdatePP(sender, e);
// Legality
pkm.Moves = Moves.Select(WinFormsUtil.GetIndex).ToArray();
pkm.RelearnMoves = Relearn.Select(WinFormsUtil.GetIndex).ToArray();
Entity.Moves = Moves.Select(WinFormsUtil.GetIndex).ToArray();
Entity.RelearnMoves = Relearn.Select(WinFormsUtil.GetIndex).ToArray();
UpdateLegality(skipMoveRepop: true);
}
@@ -1542,34 +1540,34 @@ private void ValidateLocation(object sender, EventArgs e)
return;
ValidateComboBox((ComboBox)sender);
pkm.Met_Location = WinFormsUtil.GetIndex(CB_MetLocation);
pkm.Egg_Location = WinFormsUtil.GetIndex(CB_EggLocation);
Entity.Met_Location = WinFormsUtil.GetIndex(CB_MetLocation);
Entity.Egg_Location = WinFormsUtil.GetIndex(CB_EggLocation);
UpdateLegality();
}
// Secondary Windows for Ribbons/Amie/Memories
private void OpenRibbons(object sender, EventArgs e)
{
using var form = new RibbonEditor(pkm);
using var form = new RibbonEditor(Entity);
form.ShowDialog();
}
private void OpenMedals(object sender, EventArgs e)
{
using var form = new SuperTrainingEditor(pkm);
using var form = new SuperTrainingEditor(Entity);
form.ShowDialog();
}
private void OpenHistory(object sender, EventArgs e)
{
// Write back current values
pkm.HT_Name = TB_OTt2.Text;
pkm.OT_Name = TB_OT.Text;
pkm.IsEgg = CHK_IsEgg.Checked;
pkm.CurrentFriendship = Util.ToInt32(TB_Friendship.Text);
using var form = new MemoryAmie(pkm);
Entity.HT_Name = TB_OTt2.Text;
Entity.OT_Name = TB_OT.Text;
Entity.IsEgg = CHK_IsEgg.Checked;
Entity.CurrentFriendship = Util.ToInt32(TB_Friendship.Text);
using var form = new MemoryAmie(Entity);
form.ShowDialog();
TB_Friendship.Text = pkm.CurrentFriendship.ToString();
TB_Friendship.Text = Entity.CurrentFriendship.ToString();
}
/// <summary>
@@ -1579,8 +1577,8 @@ private void OpenHistory(object sender, EventArgs e)
/// <param name="pk">Pokémon data to edit</param>
public bool ToggleInterface(SaveFile sav, PKM pk)
{
pkm = sav.GetCompatiblePKM(pk);
ToggleInterface(pkm);
Entity = sav.GetCompatiblePKM(pk);
ToggleInterface(Entity);
return FinalizeInterface(sav);
}
@@ -1590,7 +1588,7 @@ private void ToggleInterface(PKM t)
FLP_SizeCP.Visible = PB_Favorite.Visible = t is PB7;
BTN_Medals.Visible = BTN_History.Visible = t.Format >= 6 && !(t is PB7);
BTN_Ribbons.Visible = t.Format >= 3 && !(t is PB7);
ToggleInterface(pkm.Format);
ToggleInterface(Entity.Format);
}
private void ToggleSecrets(bool hidden, int gen)
@@ -1638,8 +1636,8 @@ private void ToggleInterface(int gen)
FLP_EncounterType.Visible = gen >= 4 && gen <= 6;
FLP_TimeOfDay.Visible = gen == 2;
Contest.ToggleInterface(pkm, gen);
Stats.ToggleInterface(pkm, gen);
Contest.ToggleInterface(Entity, gen);
Stats.ToggleInterface(Entity, gen);
CenterSubEditors();
}
@@ -1650,19 +1648,19 @@ private bool FinalizeInterface(SaveFile sav)
bool TranslationRequired = false;
PopulateFilteredDataSources(sav);
PopulateFields(pkm);
PopulateFields(Entity);
// Save File Specific Limits
TB_OT.MaxLength = pkm.OTLength;
TB_OTt2.MaxLength = pkm.OTLength;
TB_Nickname.MaxLength = pkm.NickLength;
TB_OT.MaxLength = Entity.OTLength;
TB_OTt2.MaxLength = Entity.OTLength;
TB_Nickname.MaxLength = Entity.NickLength;
// Hide Unused Tabs
if (pkm.Format == 1 && tabMain.TabPages.Contains(Tab_Met))
if (Entity.Format == 1 && tabMain.TabPages.Contains(Tab_Met))
{
tabMain.TabPages.Remove(Tab_Met);
}
else if (pkm.Format != 1 && !tabMain.TabPages.Contains(Tab_Met))
else if (Entity.Format != 1 && !tabMain.TabPages.Contains(Tab_Met))
{
tabMain.TabPages.Insert(1, Tab_Met);
TranslationRequired = true;
@@ -1681,7 +1679,7 @@ private bool FinalizeInterface(SaveFile sav)
TB_Level.Visible = !HaX;
// pk2 save files do not have an Origin Game stored. Prompt the met location list to update.
if (pkm.Format == 2)
if (Entity.Format == 2)
UpdateOriginGame(null, EventArgs.Empty);
return TranslationRequired;
}

View File

@@ -38,11 +38,11 @@ public bool Valid
{
get
{
if (pkm.Format < 3)
if (Entity.Format < 3)
return true;
if (CHK_HackedStats.Checked)
return true;
if (pkm is IAwakened a)
if (Entity is IAwakened a)
return a.AwakeningAllValid();
return Convert.ToUInt32(TB_EVTotal.Text) <= 510;
}
@@ -50,7 +50,7 @@ public bool Valid
private readonly Label[] L_Stats;
private readonly MaskedTextBox[] MT_EVs, MT_IVs, MT_AVs, MT_Stats, MT_Base;
private PKM pkm => MainEditor.pkm;
private PKM Entity => MainEditor.Entity;
private bool ChangingFields
{
@@ -70,9 +70,9 @@ private void ClickIV(object sender, EventArgs e)
else if (ModifierKeys.HasFlag(Keys.Control))
{
var index = Array.IndexOf(MT_IVs, t);
t.Text = pkm.GetMaximumIV(index, true).ToString();
t.Text = Entity.GetMaximumIV(index, true).ToString();
}
else if (pkm is IHyperTrain h && ModifierKeys.HasFlag(Keys.Shift))
else if (Entity is IHyperTrain h && ModifierKeys.HasFlag(Keys.Shift))
{
var index = Array.IndexOf(MT_IVs, t);
bool flag = h.HyperTrainInvert(index);
@@ -94,7 +94,7 @@ private void ClickEV(object sender, EventArgs e)
}
int index = Array.IndexOf(MT_EVs, t);
int newEV = pkm.GetMaximumEV(index);
int newEV = Entity.GetMaximumEV(index);
t.Text = newEV.ToString();
}
@@ -118,14 +118,14 @@ public void UpdateIVs(object sender, EventArgs e)
if (sender is MaskedTextBox m)
{
int value = Util.ToInt32(m.Text);
if (value > pkm.MaxIV)
if (value > Entity.MaxIV)
{
m.Text = pkm.MaxIV.ToString();
m.Text = Entity.MaxIV.ToString();
return; // recursive on text set
}
int index = Array.IndexOf(MT_IVs, m);
pkm.SetIV(index, value);
Entity.SetIV(index, value);
}
RefreshDerivedValues(e);
UpdateStats();
@@ -133,10 +133,10 @@ public void UpdateIVs(object sender, EventArgs e)
private void RefreshDerivedValues(object sender)
{
if (pkm.Format < 3)
if (Entity.Format < 3)
{
TB_IVHP.Text = pkm.IV_HP.ToString();
TB_IVSPD.Text = pkm.IV_SPD.ToString();
TB_IVHP.Text = Entity.IV_HP.ToString();
TB_IVSPD.Text = Entity.IV_SPD.ToString();
MainEditor.UpdateIVsGB(sender == null);
}
@@ -144,15 +144,15 @@ private void RefreshDerivedValues(object sender)
if (!ChangingFields)
{
ChangingFields = true;
CB_HPType.SelectedValue = pkm.HPType;
CB_HPType.SelectedValue = Entity.HPType;
ChangingFields = false;
}
// Potential Reading
L_Potential.Text = pkm.GetPotentialString(MainEditor.Unicode);
L_Potential.Text = Entity.GetPotentialString(MainEditor.Unicode);
TB_IVTotal.Text = pkm.IVTotal.ToString();
UpdateCharacteristic(pkm.Characteristic);
TB_IVTotal.Text = Entity.IVTotal.ToString();
UpdateCharacteristic(Entity.Characteristic);
}
private void UpdateEVs(object sender, EventArgs e)
@@ -160,19 +160,19 @@ private void UpdateEVs(object sender, EventArgs e)
if (sender is MaskedTextBox m)
{
int value = Util.ToInt32(m.Text);
if (value > pkm.MaxEV)
if (value > Entity.MaxEV)
{
m.Text = pkm.MaxEV.ToString();
m.Text = Entity.MaxEV.ToString();
return; // recursive on text set
}
int index = Array.IndexOf(MT_EVs, m);
pkm.SetEV(index, value);
Entity.SetEV(index, value);
}
UpdateEVTotals();
if (pkm.Format < 3)
if (Entity.Format < 3)
{
ChangingFields = true;
TB_EVSPD.Text = TB_EVSPA.Text;
@@ -184,7 +184,7 @@ private void UpdateEVs(object sender, EventArgs e)
private void UpdateAVs(object sender, EventArgs e)
{
if (!(pkm is IAwakened a))
if (!(Entity is IAwakened a))
return;
if (sender is MaskedTextBox m)
{
@@ -206,7 +206,7 @@ private void UpdateAVs(object sender, EventArgs e)
private void UpdateRandomEVs(object sender, EventArgs e)
{
bool zero = ModifierKeys.HasFlag(Keys.Control);
var evs = zero ? new int[6] : PKX.GetRandomEVs(pkm.Format);
var evs = zero ? new int[6] : PKX.GetRandomEVs(Entity.Format);
LoadEVs(evs);
UpdateEVs(null, EventArgs.Empty);
}
@@ -246,7 +246,7 @@ private void UpdateHPType(object sender, EventArgs e)
// Change IVs to match the new Hidden Power
int hpower = WinFormsUtil.GetIndex(CB_HPType);
int[] newIVs = HiddenPower.SetIVs(hpower, pkm.IVs, pkm.Format);
int[] newIVs = HiddenPower.SetIVs(hpower, Entity.IVs, Entity.Format);
LoadIVs(newIVs);
}
@@ -259,27 +259,27 @@ private void ClickStatLabel(object sender, MouseEventArgs e)
if (ModifierKeys.HasFlag(Keys.Alt)) // EV
{
bool min = e.Button != MouseButtons.Left;
if (pkm is PB7)
if (Entity is PB7)
{
var value = min ? 0 : 200;
MT_AVs[index].Text = value.ToString();
}
else
{
var value = min ? 0 : pkm.GetMaximumEV(index);
var value = min ? 0 : Entity.GetMaximumEV(index);
MT_EVs[index].Text = value.ToString();
}
}
else if (ModifierKeys.HasFlag(Keys.Control)) // IV
{
var value = e.Button != MouseButtons.Left ? 0 : pkm.GetMaximumIV(index, true);
var value = e.Button != MouseButtons.Left ? 0 : Entity.GetMaximumIV(index, true);
MT_IVs[index].Text = value.ToString();
}
}
private void LoadHyperTraining()
{
if (!(pkm is IHyperTrain h))
if (!(Entity is IHyperTrain h))
{
foreach (var iv in MT_IVs)
iv.ResetBackColor();
@@ -292,7 +292,7 @@ private void LoadHyperTraining()
private void UpdateAVTotals()
{
if (!(pkm is IAwakened a))
if (!(Entity is IAwakened a))
return;
var total = a.AwakeningSum();
TB_AVTotal.Text = total.ToString();
@@ -300,7 +300,7 @@ private void UpdateAVTotals()
private void UpdateEVTotals()
{
var evtotal = pkm.EVTotal;
var evtotal = Entity.EVTotal;
TB_EVTotal.BackColor = GetEVTotalColor(evtotal, TB_IVTotal.BackColor);
TB_EVTotal.Text = evtotal.ToString();
EVTip.SetToolTip(TB_EVTotal, $"Remaining: {510 - evtotal}");
@@ -320,13 +320,13 @@ private Color GetEVTotalColor(int evtotal, Color defaultColor)
public void UpdateStats()
{
// Generate the stats.
if (!CHK_HackedStats.Checked || pkm.Stat_HPCurrent == 0) // no stats when initially loaded from non-partyformat slot
if (!CHK_HackedStats.Checked || Entity.Stat_HPCurrent == 0) // no stats when initially loaded from non-partyformat slot
{
var pt = MainEditor.RequestSaveFile.Personal;
var pi = pt.GetFormeEntry(pkm.Species, pkm.AltForm);
pkm.SetStats(pkm.GetStats(pi));
var pi = pt.GetFormeEntry(Entity.Species, Entity.AltForm);
Entity.SetStats(Entity.GetStats(pi));
LoadBST(pi);
LoadPartyStats(pkm);
LoadPartyStats(Entity);
}
}
@@ -346,19 +346,19 @@ private void LoadBST(PersonalInfo pi)
public void UpdateRandomIVs(object sender, EventArgs e)
{
int? flawless = ModifierKeys.HasFlag(Keys.Control) ? (int?)6 : null;
var IVs = pkm.SetRandomIVs(flawless);
var IVs = Entity.SetRandomIVs(flawless);
LoadIVs(IVs);
}
private void UpdateRandomAVs(object sender, EventArgs e)
{
if (!(pkm is IAwakened a))
if (!(Entity is IAwakened a))
return;
switch (ModifierKeys)
{
case Keys.Control:
a.SetSuggestedAwakenedValues(pkm);
a.SetSuggestedAwakenedValues(Entity);
break;
case Keys.Alt:
a.AwakeningSetAllTo(0);
@@ -371,7 +371,7 @@ private void UpdateRandomAVs(object sender, EventArgs e)
LoadAVs(a);
}
public void UpdateCharacteristic() => UpdateCharacteristic(pkm.Characteristic);
public void UpdateCharacteristic() => UpdateCharacteristic(Entity.Characteristic);
private void UpdateCharacteristic(int characteristic)
{
@@ -397,8 +397,8 @@ public string UpdateNatureModification(int nature)
public void SetATKIVGender(int gender)
{
pkm.SetATKIVGender(gender);
TB_IVATK.Text = pkm.IV_ATK.ToString();
Entity.SetATKIVGender(gender);
TB_IVATK.Text = Entity.IV_ATK.ToString();
}
public void LoadPartyStats(PKM pk)

View File

@@ -758,7 +758,7 @@ private void ResetSAVPKMEditors(SaveFile sav)
var isBlank = pk.Data.SequenceEqual(sav.BlankPKM.Data);
if (isBlank)
EditPKMUtil.TemplateFields(pk, sav);
bool init = PKME_Tabs.pkm == null;
bool init = PKME_Tabs.Entity == null;
PKME_Tabs.CurrentPKM = pk;
if (init)
{
@@ -1138,7 +1138,7 @@ private void Dragout_MouseDown(object sender, MouseEventArgs e)
private void DragoutEnter(object sender, EventArgs e)
{
dragout.BackgroundImage = PKME_Tabs.pkm.Species > 0 ? Resources.slotSet : Resources.slotDel;
dragout.BackgroundImage = PKME_Tabs.Entity.Species > 0 ? Resources.slotSet : Resources.slotDel;
Cursor = Cursors.Hand;
}

View File

@@ -12,12 +12,14 @@ namespace PKHeX.WinForms
public partial class BatchEditor : Form
{
private readonly SaveFile SAV;
private readonly PKM pkm;
private int currentFormat = -1;
public BatchEditor(PKM pk, SaveFile sav)
{
InitializeComponent();
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
pkmref = pk;
pkm = pk;
SAV = sav;
DragDrop += TabMain_DragDrop;
DragEnter += TabMain_DragEnter;
@@ -34,10 +36,6 @@ public BatchEditor(PKM pk, SaveFile sav)
toolTip3.SetToolTip(L_PropValue, MsgBEToolTipPropValue);
}
private readonly PKM pkmref;
private int currentFormat = -1;
private void B_Open_Click(object sender, EventArgs e)
{
if (!B_Go.Enabled) return;
@@ -88,9 +86,9 @@ private void CB_Format_SelectedIndexChanged(object sender, EventArgs e)
private void CB_Property_SelectedIndexChanged(object sender, EventArgs e)
{
L_PropType.Text = BatchEditing.GetPropertyType(CB_Property.Text, CB_Format.SelectedIndex);
if (BatchEditing.TryGetHasProperty(pkmref, CB_Property.Text, out var pi))
if (BatchEditing.TryGetHasProperty(pkm, CB_Property.Text, out var pi))
{
L_PropValue.Text = pi.GetValue(pkmref)?.ToString();
L_PropValue.Text = pi.GetValue(pkm)?.ToString();
L_PropType.ForeColor = L_PropValue.ForeColor; // reset color
}
else // no property, flag
@@ -252,9 +250,9 @@ private void ProcessFolder(IReadOnlyList<string> files, IReadOnlyList<StringInst
int format = PKX.GetPKMFormatFromExtension(fi.Extension, SAV.Generation);
byte[] data = File.ReadAllBytes(file);
var pkm = PKMConverter.GetPKMfromBytes(data, prefer: format);
if (editor.ProcessPKM(pkm, Filters, Instructions))
File.WriteAllBytes(Path.Combine(destPath, Path.GetFileName(file)), pkm.DecryptedBoxData);
var pk = PKMConverter.GetPKMfromBytes(data, prefer: format);
if (editor.ProcessPKM(pk, Filters, Instructions))
File.WriteAllBytes(Path.Combine(destPath, Path.GetFileName(file)), pk.DecryptedBoxData);
b.ReportProgress(i);
}