Refactoring

reduce cross-class chatter, simplifly large methods to smaller pieces
some speed improvements
This commit is contained in:
Kurt 2017-06-18 22:27:40 -07:00
parent 82c8bc01bd
commit b4222c756a
10 changed files with 309 additions and 258 deletions

View file

@ -273,7 +273,7 @@ namespace PKHeX.Core
} }
} }
} }
public static GameStrings Strings; public static GameStrings Strings { get; set; }
// DataSource providing // DataSource providing
public static List<ComboItem> ItemDataSource { get; private set; } public static List<ComboItem> ItemDataSource { get; private set; }

View file

@ -8,27 +8,43 @@ namespace PKHeX.Core
{ {
public static partial class Legal public static partial class Legal
{ {
/// <summary>Event Database for a given Generation</summary> /// <summary>Event Database for Generation 3</summary>
public static MysteryGift[] MGDB_G3, MGDB_G4, MGDB_G5, MGDB_G6, MGDB_G7 = new MysteryGift[0]; public static MysteryGift[] MGDB_G3 { get; private set; } = new MysteryGift[0];
/// <summary>Event Database for Generation 4</summary>
public static MysteryGift[] MGDB_G4 { get; private set; } = new MysteryGift[0];
/// <summary>Event Database for Generation 5</summary>
public static MysteryGift[] MGDB_G5 { get; private set; } = new MysteryGift[0];
/// <summary>Event Database for Generation 6</summary>
public static MysteryGift[] MGDB_G6 { get; private set; } = new MysteryGift[0];
/// <summary>Event Database for Generation 7</summary>
public static MysteryGift[] MGDB_G7 { get; private set; } = new MysteryGift[0];
/// <summary>Setting to specify if an analysis should permit data sourced from the physical cartridge era of GameBoy games.</summary> /// <summary>Setting to specify if an analysis should permit data sourced from the physical cartridge era of GameBoy games.</summary>
public static bool AllowGBCartEra = false; public static bool AllowGBCartEra { get; set; }
public static bool AllowGen1Tradeback = false; public static bool AllowGen1Tradeback { get; set; }
public static bool AllowGen2VCTransfer => AllowGen1Tradeback; public static bool AllowGen2VCTransfer => AllowGen1Tradeback;
public static bool AllowGen2VCCrystal = false; public static bool AllowGen2VCCrystal => false;
public static bool AllowGen2Crystal => AllowGBCartEra || AllowGen2VCCrystal; public static bool AllowGen2Crystal => AllowGBCartEra || AllowGen2VCCrystal;
public static bool AllowGen2MoveReminder => AllowGBCartEra; public static bool AllowGen2MoveReminder => AllowGBCartEra;
/// <summary>Setting to specify if the e-berry index item is an eningma berry or a e-reader berry and the name of the e-reader berry</summary> /// <summary> e-Reader Berry originates from a Japanese SaveFile </summary>
public static bool EReaderBerryIsEnigma = true; public static bool SavegameJapanese { get; set; }
public static string EReaderBerryName = string.Empty; /// <summary> e-Reader Berry is Enigma or special berry </summary>
public static bool EReaderBerryIsEnigma { get; set; } = true;
/// <summary> e-Reader Berry Name </summary>
public static string EReaderBerryName { get; set; } = string.Empty;
/// <summary> e-Reader Berry Name formatted in Title Case </summary>
public static string EReaderBerryDisplayName => string.Format(V372, Util.ToTitleCase(EReaderBerryName.ToLower())); public static string EReaderBerryDisplayName => string.Format(V372, Util.ToTitleCase(EReaderBerryName.ToLower()));
public static bool SavegameJapanese = false;
public static string Savegame_OT = string.Empty; public static string Savegame_OT { private get; set; } = string.Empty;
public static int Savegame_TID = 0; public static int Savegame_TID { private get; set; }
public static int Savegame_SID = 0; public static int Savegame_SID { private get; set; }
public static int Savegame_Gender = 0; public static int Savegame_Gender { private get; set; }
public static GameVersion Savegame_Version = GameVersion.Any; public static GameVersion Savegame_Version { private get; set; } = GameVersion.Any;
// Gen 1 // Gen 1
private static readonly Learnset[] LevelUpRB = Learnset1.GetArray(Util.GetBinaryResource("lvlmove_rb.pkl"), MaxSpeciesID_1); private static readonly Learnset[] LevelUpRB = Learnset1.GetArray(Util.GetBinaryResource("lvlmove_rb.pkl"), MaxSpeciesID_1);

View file

@ -6,12 +6,12 @@ namespace PKHeX.Core
{ {
public static class PKMConverter public static class PKMConverter
{ {
public static int Country = 49; public static int Country { get; private set; } = 49;
public static int Region = 7; public static int Region { get; private set; } = 7;
public static int ConsoleRegion = 1; public static int ConsoleRegion { get; private set; } = 1;
public static string OT_Name = "PKHeX"; public static string OT_Name { get; private set; } = "PKHeX";
public static int OT_Gender; // Male public static int OT_Gender { get; private set; } // Male
public static int Language = 1; // en public static int Language { get; private set; } = 1; // en
public static void UpdateConfig(int SUBREGION, int COUNTRY, int _3DSREGION, string TRAINERNAME, int TRAINERGENDER, int LANGUAGE) public static void UpdateConfig(int SUBREGION, int COUNTRY, int _3DSREGION, string TRAINERNAME, int TRAINERGENDER, int LANGUAGE)
{ {

View file

@ -296,7 +296,7 @@ namespace PKHeX.Core
else if (Set.Species == 676) Set.Form = ""; // Furfrou else if (Set.Species == 676) Set.Form = ""; // Furfrou
else if (Set.Species == 666 && Set.Form == "Poké Ball") Set.Form = "Pokeball"; // Vivillon else if (Set.Species == 666 && Set.Form == "Poké Ball") Set.Form = "Pokeball"; // Vivillon
return Set.GetText(); return Set.Text;
} }
private void ParseFirstLine(string line) private void ParseFirstLine(string line)
{ {

View file

@ -6,8 +6,8 @@ namespace PKHeX.Core
// Base Class for Save Files // Base Class for Save Files
public abstract class SaveFile public abstract class SaveFile
{ {
public static bool SetUpdateDex = true; public static bool SetUpdateDex { protected get; set; } = true;
public static bool SetUpdatePKM = true; public static bool SetUpdatePKM { protected get; set; } = true;
// General Object Properties // General Object Properties
public byte[] Data; public byte[] Data;

View file

@ -32,22 +32,22 @@ namespace PKHeX.WinForms.Controls
c.KeyDown += WinFormsUtil.RemoveDropCB; c.KeyDown += WinFormsUtil.RemoveDropCB;
} }
public PKM pkm; public PKM CurrentPKM { get => fieldsInitialized ? PreparePKM() : pkm; set => pkm = value; }
public bool HaX; public bool ModifyPKM { private get; set; } = true;
public bool fieldsInitialized; public bool Unicode { private get; set; } = true;
public bool fieldsLoaded; public bool HaX { private get; set; }
public bool Unicode; public byte[] LastData { private get; set; }
public bool? IsLegal;
public byte[] lastData;
public bool ModifyPKM = true;
public GameVersion origintrack;
private PKM pkm;
private bool fieldsInitialized;
private bool fieldsLoaded;
private bool changingFields; private bool changingFields;
private GameVersion origintrack;
private Action GetFieldsfromPKM; private Action GetFieldsfromPKM;
private Func<PKM> GetPKMfromFields; private Func<PKM> GetPKMfromFields;
private LegalityAnalysis Legality; private LegalityAnalysis Legality;
private string[] gendersymbols = { "♂", "♀", "-" }; private string[] gendersymbols = { "♂", "♀", "-" };
private static readonly Image mixedHighlight = ImageUtil.ChangeOpacity(Resources.slotSet, 0.5); private readonly Image mixedHighlight = ImageUtil.ChangeOpacity(Resources.slotSet, 0.5);
public event EventHandler LegalityChanged; public event EventHandler LegalityChanged;
public event EventHandler UpdatePreviewSprite; public event EventHandler UpdatePreviewSprite;
@ -59,7 +59,7 @@ namespace PKHeX.WinForms.Controls
private readonly PictureBox[] movePB, relearnPB; private readonly PictureBox[] movePB, relearnPB;
private readonly ToolTip Tip1 = new ToolTip(), Tip2 = new ToolTip(), Tip3 = new ToolTip(), NatureTip = new ToolTip(), EVTip = new ToolTip(); private readonly ToolTip Tip1 = new ToolTip(), Tip2 = new ToolTip(), Tip3 = new ToolTip(), NatureTip = new ToolTip(), EVTip = new ToolTip();
private SaveFile RequestSaveFile => SaveFileRequested?.Invoke(this, EventArgs.Empty); private SaveFile RequestSaveFile => SaveFileRequested?.Invoke(this, EventArgs.Empty);
public bool PKMIsUnsaved => fieldsInitialized && fieldsLoaded && lastData != null && lastData.Any(b => b != 0) && !lastData.SequenceEqual(PreparePKM().Data); public bool PKMIsUnsaved => fieldsInitialized && fieldsLoaded && LastData != null && LastData.Any(b => b != 0) && !LastData.SequenceEqual(PreparePKM().Data);
public bool IsEmptyOrEgg => CHK_IsEgg.Checked || CB_Species.SelectedIndex == 0; public bool IsEmptyOrEgg => CHK_IsEgg.Checked || CB_Species.SelectedIndex == 0;
public PKM PreparePKM(bool click = true) public PKM PreparePKM(bool click = true)
@ -98,10 +98,6 @@ namespace PKHeX.WinForms.Controls
return false; return false;
} }
public void UpdateStringDisplay()
{
UpdateIVs(null, null); // Prompt an update for the characteristics
}
public void InitializeFields() public void InitializeFields()
{ {
// Now that the ComboBoxes are ready, load the data. // Now that the ComboBoxes are ready, load the data.
@ -231,9 +227,8 @@ namespace PKHeX.WinForms.Controls
SetMarkings(); SetMarkings();
UpdateLegality(); UpdateLegality();
lastData = PreparePKM()?.Data; UpdateSprite();
// Refresh the Preview Box LastData = PreparePKM()?.Data;
UpdatePreviewSprite?.Invoke(this, null);
} }
public void UpdateLegality(LegalityAnalysis la = null, bool skipMoveRepop = false) public void UpdateLegality(LegalityAnalysis la = null, bool skipMoveRepop = false)
{ {
@ -245,12 +240,9 @@ namespace PKHeX.WinForms.Controls
{ {
PB_WarnMove1.Visible = PB_WarnMove2.Visible = PB_WarnMove3.Visible = PB_WarnMove4.Visible = 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; PB_WarnRelearn1.Visible = PB_WarnRelearn2.Visible = PB_WarnRelearn3.Visible = PB_WarnRelearn4.Visible = false;
IsLegal = null;
return; return;
} }
IsLegal = Legality.Valid;
// Refresh Move Legality // Refresh Move Legality
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
movePB[i].Visible = !Legality.info?.Moves[i].Valid ?? false; movePB[i].Visible = !Legality.info?.Moves[i].Valid ?? false;
@ -276,7 +268,7 @@ namespace PKHeX.WinForms.Controls
c.SelectionLength = 0; // flicker hack c.SelectionLength = 0; // flicker hack
} }
fieldsLoaded |= tmp; fieldsLoaded |= tmp;
LegalityChanged?.Invoke(this, null); LegalityChanged?.Invoke(Legality.Valid, null);
} }
public void UpdateUnicode(string[] symbols) public void UpdateUnicode(string[] symbols)
{ {
@ -299,6 +291,11 @@ namespace PKHeX.WinForms.Controls
if (PKX.GetGender(Label_CTGender.Text) < 2) if (PKX.GetGender(Label_CTGender.Text) < 2)
Label_CTGender.Text = gendersymbols[PKX.GetGender(Label_CTGender.Text)]; Label_CTGender.Text = gendersymbols[PKX.GetGender(Label_CTGender.Text)];
} }
private void UpdateSprite()
{
if (fieldsLoaded && fieldsInitialized)
UpdatePreviewSprite?.Invoke(this, null);
}
// General Use Functions // // General Use Functions //
private Color GetGenderColor(int gender) private Color GetGenderColor(int gender)
@ -827,8 +824,7 @@ namespace PKHeX.WinForms.Controls
CB_Form.SelectedIndex = pkm.AltForm; CB_Form.SelectedIndex = pkm.AltForm;
} }
SetIsShiny(null); SetIsShiny(null);
if (fieldsLoaded) UpdateSprite();
UpdatePreviewSprite?.Invoke(this, null);
} }
CB_HPType.SelectedValue = pkm.HPType; CB_HPType.SelectedValue = pkm.HPType;
@ -1001,7 +997,7 @@ namespace PKHeX.WinForms.Controls
TB_PID.Text = pkm.PID.ToString("X8"); TB_PID.Text = pkm.PID.ToString("X8");
SetIsShiny(null); SetIsShiny(null);
UpdatePreviewSprite?.Invoke(this, null); UpdateSprite();
if (pkm.GenNumber < 6 && pkm.Format >= 6) if (pkm.GenNumber < 6 && pkm.Format >= 6)
TB_EC.Text = TB_PID.Text; TB_EC.Text = TB_PID.Text;
} }
@ -1094,8 +1090,7 @@ namespace PKHeX.WinForms.Controls
MT_Form.Text = CB_Form.SelectedIndex.ToString(); MT_Form.Text = CB_Form.SelectedIndex.ToString();
changingFields = false; changingFields = false;
if (fieldsLoaded) UpdateSprite();
UpdatePreviewSprite?.Invoke(this, null);
} }
private void UpdateHaXForm(object sender, EventArgs e) private void UpdateHaXForm(object sender, EventArgs e)
{ {
@ -1106,8 +1101,7 @@ namespace PKHeX.WinForms.Controls
CB_Form.SelectedIndex = CB_Form.Items.Count > form ? form : -1; CB_Form.SelectedIndex = CB_Form.Items.Count > form ? form : -1;
changingFields = false; changingFields = false;
if (fieldsLoaded) UpdateSprite();
UpdatePreviewSprite?.Invoke(this, null);
} }
private void UpdatePP(object sender, EventArgs e) private void UpdatePP(object sender, EventArgs e)
{ {
@ -1481,7 +1475,7 @@ namespace PKHeX.WinForms.Controls
} }
UpdateNickname(null, null); UpdateNickname(null, null);
UpdatePreviewSprite?.Invoke(this, null); UpdateSprite();
} }
private void UpdateMetAsEgg(object sender, EventArgs e) private void UpdateMetAsEgg(object sender, EventArgs e)
{ {
@ -1584,7 +1578,7 @@ namespace PKHeX.WinForms.Controls
if (Util.ToUInt32(TB_SID.Text) > ushort.MaxValue) TB_SID.Text = "65535"; if (Util.ToUInt32(TB_SID.Text) > ushort.MaxValue) TB_SID.Text = "65535";
SetIsShiny(sender); SetIsShiny(sender);
UpdatePreviewSprite?.Invoke(this, null); UpdateSprite();
UpdateIVs(null, null); // If the EC is changed, EC%6 (Characteristic) might be changed. UpdateIVs(null, null); // If the EC is changed, EC%6 (Characteristic) might be changed.
TB_PID.Select(60, 0); // position cursor at end of field TB_PID.Select(60, 0); // position cursor at end of field
if (pkm.Format <= 4 && fieldsLoaded) if (pkm.Format <= 4 && fieldsLoaded)
@ -1640,9 +1634,7 @@ namespace PKHeX.WinForms.Controls
return; return;
ValidateComboBox(sender); ValidateComboBox(sender);
UpdateSprite();
if (fieldsLoaded)
UpdatePreviewSprite?.Invoke(this, null);
} }
private void ValidateComboBox2(object sender, EventArgs e) private void ValidateComboBox2(object sender, EventArgs e)
{ {
@ -1735,79 +1727,86 @@ namespace PKHeX.WinForms.Controls
/// <summary> /// <summary>
/// Refreshes the interface for the current PKM format. /// Refreshes the interface for the current PKM format.
/// </summary> /// </summary>
public void ToggleInterface() public bool ToggleInterface(SaveFile sav, PKM pk)
{ {
Tip1.RemoveAll(); Tip2.RemoveAll(); Tip3.RemoveAll(); // TSV/PSV Tip1.RemoveAll(); Tip2.RemoveAll(); Tip3.RemoveAll(); // TSV/PSV
FLP_Country.Visible = FLP_SubRegion.Visible = FLP_3DSRegion.Visible = pkm.Format >= 6; FLP_Country.Visible = FLP_SubRegion.Visible = FLP_3DSRegion.Visible = pk.Format >= 6;
Label_EncryptionConstant.Visible = BTN_RerollEC.Visible = TB_EC.Visible = pkm.Format >= 6; Label_EncryptionConstant.Visible = BTN_RerollEC.Visible = TB_EC.Visible = pk.Format >= 6;
GB_nOT.Visible = GB_RelearnMoves.Visible = BTN_Medals.Visible = BTN_History.Visible = pkm.Format >= 6; GB_nOT.Visible = GB_RelearnMoves.Visible = BTN_Medals.Visible = BTN_History.Visible = pk.Format >= 6;
PB_MarkPentagon.Visible = pkm.Format >= 6; PB_MarkPentagon.Visible = pk.Format >= 6;
PB_MarkAlola.Visible = PB_MarkVC.Visible = PB_MarkHorohoro.Visible = pkm.Format >= 7; PB_MarkAlola.Visible = PB_MarkVC.Visible = PB_MarkHorohoro.Visible = pk.Format >= 7;
FLP_NSparkle.Visible = L_NSparkle.Visible = CHK_NSparkle.Visible = pkm.Format == 5; FLP_NSparkle.Visible = L_NSparkle.Visible = CHK_NSparkle.Visible = pk.Format == 5;
CB_Form.Visible = Label_Form.Visible = CHK_AsEgg.Visible = GB_EggConditions.Visible = PB_Mark5.Visible = PB_Mark6.Visible = pkm.Format >= 4; CB_Form.Visible = Label_Form.Visible = CHK_AsEgg.Visible = GB_EggConditions.Visible = PB_Mark5.Visible = PB_Mark6.Visible = pk.Format >= 4;
FLP_ShinyLeaf.Visible = L_ShinyLeaf.Visible = ShinyLeaf.Visible = pkm.Format == 4; FLP_ShinyLeaf.Visible = L_ShinyLeaf.Visible = ShinyLeaf.Visible = pk.Format == 4;
DEV_Ability.Enabled = DEV_Ability.Visible = pkm.Format > 3 && HaX; DEV_Ability.Enabled = DEV_Ability.Visible = pk.Format > 3 && HaX;
CB_Ability.Visible = !DEV_Ability.Enabled && pkm.Format >= 3; CB_Ability.Visible = !DEV_Ability.Enabled && pk.Format >= 3;
FLP_Nature.Visible = pkm.Format >= 3; FLP_Nature.Visible = pk.Format >= 3;
FLP_Ability.Visible = pkm.Format >= 3; FLP_Ability.Visible = pk.Format >= 3;
FLP_Language.Visible = pkm.Format >= 3; FLP_Language.Visible = pk.Format >= 3;
GB_ExtraBytes.Visible = GB_ExtraBytes.Enabled = pkm.Format >= 3; GB_ExtraBytes.Visible = GB_ExtraBytes.Enabled = pk.Format >= 3;
GB_Markings.Visible = pkm.Format >= 3; GB_Markings.Visible = pk.Format >= 3;
BTN_Ribbons.Visible = pkm.Format >= 3; BTN_Ribbons.Visible = pk.Format >= 3;
CB_HPType.Enabled = CB_Form.Enabled = pkm.Format >= 3; CB_HPType.Enabled = CB_Form.Enabled = pk.Format >= 3;
BTN_RerollPID.Visible = Label_PID.Visible = TB_PID.Visible = Label_SID.Visible = TB_SID.Visible = pkm.Format >= 3; BTN_RerollPID.Visible = Label_PID.Visible = TB_PID.Visible = Label_SID.Visible = TB_SID.Visible = pk.Format >= 3;
FLP_FriendshipForm.Visible = pkm.Format >= 2; FLP_FriendshipForm.Visible = pk.Format >= 2;
FLP_HeldItem.Visible = pkm.Format >= 2; FLP_HeldItem.Visible = pk.Format >= 2;
CHK_IsEgg.Visible = Label_Gender.Visible = pkm.Format >= 2; CHK_IsEgg.Visible = Label_Gender.Visible = pk.Format >= 2;
FLP_PKRS.Visible = FLP_EggPKRSRight.Visible = pkm.Format >= 2; FLP_PKRS.Visible = FLP_EggPKRSRight.Visible = pk.Format >= 2;
Label_OTGender.Visible = pkm.Format >= 2; Label_OTGender.Visible = pk.Format >= 2;
FLP_Purification.Visible = FLP_ShadowID.Visible = pkm is XK3 || pkm is CK3; FLP_Purification.Visible = FLP_ShadowID.Visible = pk is XK3 || pk is CK3;
NUD_ShadowID.Maximum = 127; NUD_ShadowID.Maximum = 127;
// HaX override, needs to be after DEV_Ability enabled assignment. // HaX override, needs to be after DEV_Ability enabled assignment.
TB_AbilityNumber.Visible = pkm.Format >= 6 && DEV_Ability.Enabled; TB_AbilityNumber.Visible = pk.Format >= 6 && DEV_Ability.Enabled;
// Met Tab // Met Tab
FLP_MetDate.Visible = pkm.Format >= 4; FLP_MetDate.Visible = pk.Format >= 4;
FLP_Fateful.Visible = FLP_Ball.Visible = FLP_OriginGame.Visible = pkm.Format >= 3; FLP_Fateful.Visible = FLP_Ball.Visible = FLP_OriginGame.Visible = pk.Format >= 3;
FLP_MetLocation.Visible = FLP_MetLevel.Visible = pkm.Format >= 2; FLP_MetLocation.Visible = FLP_MetLevel.Visible = pk.Format >= 2;
FLP_TimeOfDay.Visible = pkm.Format == 2; FLP_TimeOfDay.Visible = pk.Format == 2;
// Stats // Stats
FLP_StatsTotal.Visible = pkm.Format >= 3; FLP_StatsTotal.Visible = pk.Format >= 3;
FLP_Characteristic.Visible = pkm.Format >= 3; FLP_Characteristic.Visible = pk.Format >= 3;
FLP_HPType.Visible = pkm.Format >= 2; FLP_HPType.Visible = pk.Format >= 2;
PAN_Contest.Visible = pkm.Format >= 3; PAN_Contest.Visible = pk.Format >= 3;
if (pkm.Format == 1) ToggleStats(pk);
CenterSubEditors();
return FinalizeInterface(sav, pk);
}
private void ToggleStats(PKM pk)
{
if (pk.Format == 1)
{ {
FLP_SpD.Visible = false; FLP_SpD.Visible = false;
Label_SPA.Visible = false; Label_SPA.Visible = false;
Label_SPC.Visible = true; Label_SPC.Visible = true;
TB_HPIV.Enabled = false; TB_HPIV.Enabled = false;
MaskedTextBox[] evControls = { TB_SPAEV, TB_HPEV, TB_ATKEV, TB_DEFEV, TB_SPEEV, TB_SPDEV }; MaskedTextBox[] evControls = {TB_SPAEV, TB_HPEV, TB_ATKEV, TB_DEFEV, TB_SPEEV, TB_SPDEV};
foreach (var ctrl in evControls) foreach (var ctrl in evControls)
{ {
ctrl.Mask = "00000"; ctrl.Mask = "00000";
ctrl.Size = Stat_HP.Size; ctrl.Size = Stat_HP.Size;
} }
} }
else if (pkm.Format == 2) else if (pk.Format == 2)
{ {
FLP_SpD.Visible = true; FLP_SpD.Visible = true;
Label_SPA.Visible = true; Label_SPA.Visible = true;
Label_SPC.Visible = false; Label_SPC.Visible = false;
TB_SPDEV.Enabled = TB_SPDIV.Enabled = false; TB_SPDEV.Enabled = TB_SPDIV.Enabled = false;
TB_HPIV.Enabled = false; TB_HPIV.Enabled = false;
MaskedTextBox[] evControls = { TB_SPAEV, TB_HPEV, TB_ATKEV, TB_DEFEV, TB_SPEEV, TB_SPDEV }; MaskedTextBox[] evControls = {TB_SPAEV, TB_HPEV, TB_ATKEV, TB_DEFEV, TB_SPEEV, TB_SPDEV};
foreach (var ctrl in evControls) foreach (var ctrl in evControls)
{ {
ctrl.Mask = "00000"; ctrl.Mask = "00000";
@ -1821,24 +1820,19 @@ namespace PKHeX.WinForms.Controls
Label_SPC.Visible = false; Label_SPC.Visible = false;
TB_SPDEV.Enabled = TB_SPDIV.Enabled = true; TB_SPDEV.Enabled = TB_SPDIV.Enabled = true;
TB_HPIV.Enabled = true; TB_HPIV.Enabled = true;
MaskedTextBox[] evControls = { TB_SPAEV, TB_HPEV, TB_ATKEV, TB_DEFEV, TB_SPEEV, TB_SPDEV }; MaskedTextBox[] evControls = {TB_SPAEV, TB_HPEV, TB_ATKEV, TB_DEFEV, TB_SPEEV, TB_SPDEV};
foreach (var ctrl in evControls) foreach (var ctrl in evControls)
{ {
ctrl.Mask = "000"; ctrl.Mask = "000";
ctrl.Size = TB_ExtraByte.Size; ctrl.Size = TB_ExtraByte.Size;
} }
} }
}
private bool FinalizeInterface(SaveFile SAV, PKM pk)
{
bool init = fieldsInitialized;
fieldsInitialized = fieldsLoaded = false;
// Recenter PKM SubEditors
FLP_PKMEditors.Location = new Point((Tab_OTMisc.Width - FLP_PKMEditors.Width) / 2, FLP_PKMEditors.Location.Y);
}
public void FlickerInterface()
{
tabMain.SelectedTab = Tab_Met; // parent tab of CB_GameOrigin
tabMain.SelectedTab = Tab_Main; // first tab
}
public bool FinalizeInterface(bool init, SaveFile SAV, PKM pk)
{
pkm = pk.GetType() != SAV.PKMType ? SAV.BlankPKM : pk; pkm = pk.GetType() != SAV.PKMType ? SAV.BlankPKM : pk;
if (pkm.Format < 3) if (pkm.Format < 3)
pkm = SAV.BlankPKM; pkm = SAV.BlankPKM;
@ -1874,7 +1868,7 @@ namespace PKHeX.WinForms.Controls
UpdateOriginGame(null, null); UpdateOriginGame(null, null);
return TranslationRequired; return TranslationRequired;
} }
public void CenterSubEditors() private void CenterSubEditors()
{ {
// Recenter PKM SubEditors // Recenter PKM SubEditors
FLP_PKMEditors.Location = new Point((Tab_OTMisc.Width - FLP_PKMEditors.Width) / 2, FLP_PKMEditors.Location.Y); FLP_PKMEditors.Location = new Point((Tab_OTMisc.Width - FLP_PKMEditors.Width) / 2, FLP_PKMEditors.Location.Y);
@ -1886,7 +1880,7 @@ namespace PKHeX.WinForms.Controls
if (template != null) if (template != null)
{ {
PopulateFields(template); PopulateFields(template);
lastData = null; LastData = null;
return; return;
} }
if (CB_GameOrigin.Items.Count > 0) if (CB_GameOrigin.Items.Count > 0)
@ -1902,7 +1896,7 @@ namespace PKHeX.WinForms.Controls
CAL_MetDate.Value = CAL_EggDate.Value = DateTime.Today; CAL_MetDate.Value = CAL_EggDate.Value = DateTime.Today;
CB_Species.SelectedValue = pkm.MaxSpeciesID; CB_Species.SelectedValue = pkm.MaxSpeciesID;
CHK_Nicknamed.Checked = false; CHK_Nicknamed.Checked = false;
lastData = null; LastData = null;
} }
public void EnableDragDrop(DragEventHandler enter, DragEventHandler drop) public void EnableDragDrop(DragEventHandler enter, DragEventHandler drop)
{ {
@ -1915,7 +1909,7 @@ namespace PKHeX.WinForms.Controls
tab.DragDrop += drop; tab.DragDrop += drop;
} }
} }
public void LoadShowdownSet(ShowdownSet Set, SaveFile SAV) public void LoadShowdownSet(ShowdownSet Set)
{ {
CB_Species.SelectedValue = Set.Species; CB_Species.SelectedValue = Set.Species;
CHK_Nicknamed.Checked = Set.Nickname != null; CHK_Nicknamed.Checked = Set.Nickname != null;
@ -1938,11 +1932,8 @@ namespace PKHeX.WinForms.Controls
{ form = i; break; } { form = i; break; }
CB_Form.SelectedIndex = Math.Min(CB_Form.Items.Count - 1, form); CB_Form.SelectedIndex = Math.Min(CB_Form.Items.Count - 1, form);
// Set Ability // Set Ability and Moves
int[] abilities = SAV.Personal.GetAbilities(Set.Species, form); CB_Ability.SelectedIndex = Math.Max(0, Array.IndexOf(pkm.PersonalInfo.Abilities, Set.Ability));
int ability = Array.IndexOf(abilities, Set.Ability);
if (ability < 0) ability = 0;
CB_Ability.SelectedIndex = ability;
ComboBox[] m = { CB_Move1, CB_Move2, CB_Move3, CB_Move4 }; ComboBox[] m = { CB_Move1, CB_Move2, CB_Move3, CB_Move4 };
for (int i = 0; i < 4; i++) m[i].SelectedValue = Set.Moves[i]; for (int i = 0; i < 4; i++) m[i].SelectedValue = Set.Moves[i];
@ -1984,7 +1975,25 @@ namespace PKHeX.WinForms.Controls
if (Legality.info.Relearn.Any(z => !z.Valid)) if (Legality.info.Relearn.Any(z => !z.Valid))
SetSuggestedRelearnMoves(silent: true); SetSuggestedRelearnMoves(silent: true);
} }
public void InitializeLanguage(SaveFile SAV) public void ChangeLanguage(SaveFile sav, PKM pk)
{
// Force an update to the met locations
origintrack = GameVersion.Unknown;
bool alreadyInit = fieldsInitialized;
fieldsInitialized = false;
InitializeLanguage(sav);
CenterSubEditors();
PopulateFields(pk); // put data back in form
fieldsInitialized |= alreadyInit;
}
public void FlickerInterface()
{
tabMain.SelectedTab = Tab_Met; // parent tab of CB_GameOrigin
tabMain.SelectedTab = Tab_Main; // first tab
}
private void InitializeLanguage(SaveFile SAV)
{ {
ComboBox[] cbs = ComboBox[] cbs =
{ {
@ -2005,7 +2014,6 @@ namespace PKHeX.WinForms.Controls
PopulateFilteredDataSources(SAV); PopulateFilteredDataSources(SAV);
} }
private void PopulateFilteredDataSources(SaveFile SAV) private void PopulateFilteredDataSources(SaveFile SAV)
{ {
GameInfo.SetItemDataSource(HaX, pkm.MaxItemID, SAV.HeldItems, pkm.Format, SAV.Version, GameInfo.Strings); GameInfo.SetItemDataSource(HaX, pkm.MaxItemID, SAV.HeldItems, pkm.Format, SAV.Version, GameInfo.Strings);

View file

@ -11,11 +11,11 @@ namespace PKHeX.WinForms.Controls
{ {
public partial class BoxEditor : UserControl public partial class BoxEditor : UserControl
{ {
public readonly List<PictureBox> SlotPictureBoxes;
public readonly int BoxSlotCount;
public SlotChangeManager M;
private SaveFile SAV => M?.SE.SAV; private SaveFile SAV => M?.SE.SAV;
public bool FlagIllegal; public List<PictureBox> SlotPictureBoxes { get; }
public int BoxSlotCount { get; }
public SlotChangeManager M { get; set; }
public bool FlagIllegal { get; set; }
public BoxEditor() public BoxEditor()
{ {

View file

@ -84,7 +84,7 @@ namespace PKHeX.WinForms.Controls
m.SetPKM(pk, info, true, Resources.slotSet); m.SetPKM(pk, info, true, Resources.slotSet);
} }
editor.lastData = pk.Data; editor.LastData = pk.Data;
m.SE.RedoStack.Clear(); m.SE.Menu_Redo.Enabled = false; m.SE.RedoStack.Clear(); m.SE.Menu_Redo.Enabled = false;
} }
private static void ClickDelete(object sender, EventArgs e) private static void ClickDelete(object sender, EventArgs e)

View file

@ -863,9 +863,26 @@ namespace PKHeX.WinForms.Controls
public bool ToggleInterface() public bool ToggleInterface()
{ {
bool WindowTranslationRequired = false;
FieldsLoaded = false; FieldsLoaded = false;
ToggleViewReset();
ToggleViewSubEditors(SAV);
int BoxTab = tabBoxMulti.TabPages.IndexOf(Tab_Box);
int PartyTab = tabBoxMulti.TabPages.IndexOf(Tab_PartyBattle);
bool WindowTranslationRequired = false;
WindowTranslationRequired |= ToggleViewBox(SAV);
WindowTranslationRequired |= ToggleViewParty(SAV, BoxTab);
WindowTranslationRequired |= ToggleViewDaycare(SAV, BoxTab, PartyTab);
ToggleViewMisc(SAV);
FieldsLoaded = true;
return WindowTranslationRequired;
}
private void ToggleViewReset()
{
// Close subforms that are save dependent // Close subforms that are save dependent
foreach (var z in M.Boxes.Skip(1).ToArray()) foreach (var z in M.Boxes.Skip(1).ToArray())
z.FindForm()?.Close(); z.FindForm()?.Close();
@ -875,133 +892,145 @@ namespace PKHeX.WinForms.Controls
Box.M = M; Box.M = M;
Box.ResetBoxNames(); // Display the Box Names Box.ResetBoxNames(); // Display the Box Names
M.SetColor(-1, -1, null); M.SetColor(-1, -1, null);
if (SAV.HasBox)
{
int startBox = !SAV.Exportable ? 0 : SAV.CurrentBox; // FF if BattleBox
if (startBox > SAV.BoxCount - 1) { tabBoxMulti.SelectedIndex = 1; Box.CurrentBox = 0; }
else { tabBoxMulti.SelectedIndex = 0; Box.CurrentBox = startBox; }
} }
private bool ToggleViewBox(SaveFile sav)
{
if (!sav.HasBox)
{
if (tabBoxMulti.TabPages.Contains(Tab_Box))
tabBoxMulti.TabPages.Remove(Tab_Box);
B_SaveBoxBin.Enabled = false;
return false;
}
B_SaveBoxBin.Enabled = true;
int startBox = !sav.Exportable ? 0 : sav.CurrentBox; // FF if BattleBox
if (startBox > sav.BoxCount - 1) { tabBoxMulti.SelectedIndex = 1; Box.CurrentBox = 0; }
else { tabBoxMulti.SelectedIndex = 0; Box.CurrentBox = startBox; }
SetPKMBoxes(); // Reload all of the PKX Windows SetPKMBoxes(); // Reload all of the PKX Windows
// Hide content if not present in game. if (tabBoxMulti.TabPages.Contains(Tab_Box))
GB_SUBE.Visible = SAV.HasSUBE; return false;
PB_Locked.Visible = SAV.HasBattleBox && SAV.BattleBoxLocked;
if (!SAV.HasBox && tabBoxMulti.TabPages.Contains(Tab_Box))
tabBoxMulti.TabPages.Remove(Tab_Box);
else if (SAV.HasBox && !tabBoxMulti.TabPages.Contains(Tab_Box))
{
tabBoxMulti.TabPages.Insert(0, Tab_Box); tabBoxMulti.TabPages.Insert(0, Tab_Box);
WindowTranslationRequired = true; return true;
} }
B_SaveBoxBin.Enabled = SAV.HasBox; private bool ToggleViewParty(SaveFile sav, int BoxTab)
int BoxTab = tabBoxMulti.TabPages.IndexOf(Tab_Box);
int PartyTab = tabBoxMulti.TabPages.IndexOf(Tab_PartyBattle);
if (!SAV.HasParty && tabBoxMulti.TabPages.Contains(Tab_PartyBattle))
tabBoxMulti.TabPages.Remove(Tab_PartyBattle);
else if (SAV.HasParty && !tabBoxMulti.TabPages.Contains(Tab_PartyBattle))
{ {
if (!sav.HasParty)
{
if (tabBoxMulti.TabPages.Contains(Tab_PartyBattle))
tabBoxMulti.TabPages.Remove(Tab_PartyBattle);
return false;
}
PB_Locked.Visible = sav.HasBattleBox && sav.BattleBoxLocked;
if (tabBoxMulti.TabPages.Contains(Tab_PartyBattle))
return false;
int index = BoxTab; int index = BoxTab;
if (index < 0) if (index < 0)
index = -1; index = -1;
tabBoxMulti.TabPages.Insert(index + 1, Tab_PartyBattle); tabBoxMulti.TabPages.Insert(index + 1, Tab_PartyBattle);
WindowTranslationRequired = true; return true;
}
private bool ToggleViewDaycare(SaveFile sav, int BoxTab, int PartyTab)
{
if (!sav.HasDaycare)
{
if (tabBoxMulti.TabPages.Contains(Tab_Other))
tabBoxMulti.TabPages.Remove(Tab_Other);
return false;
} }
if (!SAV.HasDaycare && tabBoxMulti.TabPages.Contains(Tab_Other)) SlotPictureBoxes[43].Visible = sav.Generation >= 2; // Second daycare slot
tabBoxMulti.TabPages.Remove(Tab_Other); if (tabBoxMulti.TabPages.Contains(Tab_Other))
else if (SAV.HasDaycare && !tabBoxMulti.TabPages.Contains(Tab_Other)) return false;
{
int index = PartyTab; int index = PartyTab;
if (index < 0) if (index < 0)
index = BoxTab; index = BoxTab;
if (index < 0) if (index < 0)
index = -1; index = -1;
tabBoxMulti.TabPages.Insert(index + 1, Tab_Other); tabBoxMulti.TabPages.Insert(index + 1, Tab_Other);
WindowTranslationRequired = true; return true;
} }
private void ToggleViewSubEditors(SaveFile sav)
if (SAV.Exportable) // Actual save file
{ {
PAN_BattleBox.Visible = L_BattleBox.Visible = L_ReadOnlyPBB.Visible = SAV.HasBattleBox; if (sav.Exportable) // Actual save file
GB_Daycare.Visible = SAV.HasDaycare; {
GB_Fused.Visible = SAV.HasFused; PAN_BattleBox.Visible = L_BattleBox.Visible = L_ReadOnlyPBB.Visible = sav.HasBattleBox;
GB_GTS.Visible = SAV.HasGTS; GB_Daycare.Visible = sav.HasDaycare;
B_OpenSecretBase.Enabled = SAV.HasSecretBase; GB_Fused.Visible = sav.HasFused;
B_OpenPokepuffs.Enabled = SAV.HasPuff; GB_GTS.Visible = sav.HasGTS;
B_OpenPokeBeans.Enabled = SAV.Generation == 7; B_OpenSecretBase.Enabled = sav.HasSecretBase;
B_OpenZygardeCells.Enabled = SAV.Generation == 7; B_OpenPokepuffs.Enabled = sav.HasPuff;
B_OUTPasserby.Enabled = SAV.HasPSS; B_OpenPokeBeans.Enabled = sav.Generation == 7;
B_OpenBoxLayout.Enabled = SAV.HasBoxWallpapers; B_OpenZygardeCells.Enabled = sav.Generation == 7;
B_OpenWondercards.Enabled = SAV.HasWondercards; B_OUTPasserby.Enabled = sav.HasPSS;
B_OpenSuperTraining.Enabled = SAV.HasSuperTrain; B_OpenBoxLayout.Enabled = sav.HasBoxWallpapers;
B_OpenHallofFame.Enabled = SAV.HasHoF; B_OpenWondercards.Enabled = sav.HasWondercards;
B_OpenOPowers.Enabled = SAV.HasOPower; B_OpenSuperTraining.Enabled = sav.HasSuperTrain;
B_OpenPokedex.Enabled = SAV.HasPokeDex; B_OpenHallofFame.Enabled = sav.HasHoF;
B_OpenBerryField.Enabled = SAV.HasBerryField && SAV.XY; B_OpenOPowers.Enabled = sav.HasOPower;
B_OpenFriendSafari.Enabled = SAV.XY; B_OpenPokedex.Enabled = sav.HasPokeDex;
B_OpenPokeblocks.Enabled = SAV.HasPokeBlock; B_OpenBerryField.Enabled = sav.HasBerryField && sav.XY;
B_JPEG.Visible = SAV.HasJPEG; B_OpenFriendSafari.Enabled = sav.XY;
B_OpenEventFlags.Enabled = SAV.HasEvents; B_OpenPokeblocks.Enabled = sav.HasPokeBlock;
B_OpenLinkInfo.Enabled = SAV.HasLink; B_JPEG.Visible = sav.HasJPEG;
B_CGearSkin.Enabled = SAV.Generation == 5; B_OpenEventFlags.Enabled = sav.HasEvents;
B_OpenLinkInfo.Enabled = sav.HasLink;
B_CGearSkin.Enabled = sav.Generation == 5;
B_OpenTrainerInfo.Enabled = B_OpenItemPouch.Enabled = SAV.HasParty; // Box RS B_OpenTrainerInfo.Enabled = B_OpenItemPouch.Enabled = sav.HasParty; // Box RS
B_OpenMiscEditor.Enabled = SAV is SAV3 || SAV is SAV4 || SAV is SAV5; B_OpenMiscEditor.Enabled = sav is SAV3 || sav is SAV4 || sav is SAV5;
B_OpenHoneyTreeEditor.Enabled = SAV.DP || SAV.Pt; B_OpenHoneyTreeEditor.Enabled = sav.DP || sav.Pt;
B_OpenRTCEditor.Enabled = SAV.RS || SAV.E; B_OpenRTCEditor.Enabled = sav.RS || sav.E;
} }
GB_SAVtools.Visible = SAV.Exportable && FLP_SAVtools.Controls.Cast<Control>().Any(c => c.Enabled); GB_SAVtools.Visible = sav.Exportable && FLP_SAVtools.Controls.Cast<Control>().Any(c => c.Enabled);
foreach (Control c in FLP_SAVtools.Controls.Cast<Control>()) foreach (Control c in FLP_SAVtools.Controls.Cast<Control>())
c.Visible = c.Enabled; c.Visible = c.Enabled;
B_VerifyCHK.Enabled = SAV.Exportable;
// Second daycare slot
SlotPictureBoxes[43].Visible = SAV.Generation >= 2;
return WindowTranslationRequired;
} }
public void FinalizeInterface() private void ToggleViewMisc(SaveFile sav)
{ {
// Generational Interface // Generational Interface
TB_Secure1.Visible = TB_Secure2.Visible = L_Secure1.Visible = L_Secure2.Visible = SAV.Exportable && SAV.Generation >= 6; TB_Secure1.Visible = TB_Secure2.Visible = L_Secure1.Visible = L_Secure2.Visible = sav.Exportable && sav.Generation >= 6;
TB_GameSync.Visible = L_GameSync.Visible = SAV.Exportable && SAV.Generation >= 6; TB_GameSync.Visible = L_GameSync.Visible = sav.Exportable && sav.Generation >= 6;
GB_SUBE.Visible = SAV.HasSUBE;
B_VerifyCHK.Enabled = SAV.Exportable;
if (SAV.Version == GameVersion.BATREV) if (sav.Version == GameVersion.BATREV)
{ {
L_SaveSlot.Visible = CB_SaveSlot.Visible = true; L_SaveSlot.Visible = CB_SaveSlot.Visible = true;
CB_SaveSlot.DisplayMember = "Text"; CB_SaveSlot.ValueMember = "Value"; CB_SaveSlot.DisplayMember = "Text"; CB_SaveSlot.ValueMember = "Value";
CB_SaveSlot.DataSource = new BindingSource(((SAV4BR)SAV).SaveSlots.Select(i => new ComboItem CB_SaveSlot.DataSource = new BindingSource(((SAV4BR)sav).SaveSlots.Select(i => new ComboItem
{ {
Text = ((SAV4BR)SAV).SaveNames[i], Text = ((SAV4BR)sav).SaveNames[i],
Value = i Value = i
}).ToList(), null); }).ToList(), null);
CB_SaveSlot.SelectedValue = ((SAV4BR)SAV).CurrentSlot; CB_SaveSlot.SelectedValue = ((SAV4BR)sav).CurrentSlot;
} }
else else
L_SaveSlot.Visible = CB_SaveSlot.Visible = false; L_SaveSlot.Visible = CB_SaveSlot.Visible = false;
switch (SAV.Generation) switch (sav.Generation)
{ {
case 6: case 6:
TB_GameSync.Enabled = SAV.GameSyncID != null; TB_GameSync.Enabled = sav.GameSyncID != null;
TB_GameSync.MaxLength = SAV.GameSyncIDSize; TB_GameSync.MaxLength = sav.GameSyncIDSize;
TB_GameSync.Text = (SAV.GameSyncID ?? 0.ToString()).PadLeft(SAV.GameSyncIDSize, '0'); TB_GameSync.Text = (sav.GameSyncID ?? 0.ToString()).PadLeft(sav.GameSyncIDSize, '0');
TB_Secure1.Text = SAV.Secure1?.ToString("X16"); TB_Secure1.Text = sav.Secure1?.ToString("X16");
TB_Secure2.Text = SAV.Secure2?.ToString("X16"); TB_Secure2.Text = sav.Secure2?.ToString("X16");
break; break;
case 7: case 7:
TB_GameSync.Enabled = SAV.GameSyncID != null; TB_GameSync.Enabled = sav.GameSyncID != null;
TB_GameSync.MaxLength = SAV.GameSyncIDSize; TB_GameSync.MaxLength = sav.GameSyncIDSize;
TB_GameSync.Text = (SAV.GameSyncID ?? 0.ToString()).PadLeft(SAV.GameSyncIDSize, '0'); TB_GameSync.Text = (sav.GameSyncID ?? 0.ToString()).PadLeft(sav.GameSyncIDSize, '0');
TB_Secure1.Text = SAV.Secure1?.ToString("X16"); TB_Secure1.Text = sav.Secure1?.ToString("X16");
TB_Secure2.Text = SAV.Secure2?.ToString("X16"); TB_Secure2.Text = sav.Secure2?.ToString("X16");
break; break;
} }
FieldsLoaded = true;
} }
// DragDrop // DragDrop

View file

@ -33,6 +33,7 @@ namespace PKHeX.WinForms
FormLoadInitialFiles(args); FormLoadInitialFiles(args);
IsInitialized = true; // Splash Screen closes on its own. IsInitialized = true; // Splash Screen closes on its own.
PKME_Tabs_UpdatePreviewSprite(null, null);
BringToFront(); BringToFront();
WindowState = FormWindowState.Minimized; WindowState = FormWindowState.Minimized;
Show(); Show();
@ -52,8 +53,7 @@ namespace PKHeX.WinForms
get => GameInfo.CurrentLanguage; get => GameInfo.CurrentLanguage;
private set => GameInfo.CurrentLanguage = value; private set => GameInfo.CurrentLanguage = value;
} }
public static string[] GenderSymbols { get; private set; } = {"♂", "♀", "-"}; private static bool _unicode { get; set; }
private static bool _unicode;
public static bool Unicode public static bool Unicode
{ {
get => _unicode; get => _unicode;
@ -64,9 +64,10 @@ namespace PKHeX.WinForms
} }
} }
public static bool HaX; public static string[] GenderSymbols { get; private set; } = { "♂", "♀", "-" };
public static bool IsInitialized; public static bool HaX { get; private set; }
private static readonly string[] main_langlist = public static bool IsInitialized { get; private set; }
private readonly string[] main_langlist =
{ {
"日本語", // JPN "日本語", // JPN
"English", // ENG "English", // ENG
@ -101,7 +102,7 @@ namespace PKHeX.WinForms
// Set up Language Selection // Set up Language Selection
foreach (var cbItem in main_langlist) foreach (var cbItem in main_langlist)
CB_MainLanguage.Items.Add(cbItem); CB_MainLanguage.Items.Add(cbItem);
C_SAV.HaX = PKME_Tabs.HaX = HaX = args.Any(x => x.Trim('-').ToLower() == "hax"); C_SAV.HaX = PKME_Tabs.HaX = HaX = args.Any(x => string.Equals(x.Trim('-'), nameof(HaX), StringComparison.CurrentCultureIgnoreCase));
PB_Legal.Visible = !HaX; PB_Legal.Visible = !HaX;
int languageID = 1; // English int languageID = 1; // English
@ -404,25 +405,33 @@ namespace PKHeX.WinForms
if (Set.Species < 0) if (Set.Species < 0)
{ WinFormsUtil.Alert("Set data not found in clipboard."); return; } { WinFormsUtil.Alert("Set data not found in clipboard."); return; }
if (Set.Nickname != null && Set.Nickname.Length > C_SAV.SAV.NickLength) if (Set.Nickname?.Length > C_SAV.SAV.NickLength)
Set.Nickname = Set.Nickname.Substring(0, C_SAV.SAV.NickLength); Set.Nickname = Set.Nickname.Substring(0, C_SAV.SAV.NickLength);
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Import this set?", Set.Text)) if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Import this set?", Set.Text))
{ return; } return;
if (Set.InvalidLines.Any()) if (Set.InvalidLines.Any())
WinFormsUtil.Alert("Invalid lines detected:", string.Join(Environment.NewLine, Set.InvalidLines)); WinFormsUtil.Alert("Invalid lines detected:", string.Join(Environment.NewLine, Set.InvalidLines));
// Set Species & Nickname // Set Species & Nickname
PKME_Tabs.LoadShowdownSet(Set, C_SAV.SAV); PKME_Tabs.LoadShowdownSet(Set);
} }
private void ClickShowdownExportPKM(object sender, EventArgs e) private void ClickShowdownExportPKM(object sender, EventArgs e)
{ {
if (!PKME_Tabs.VerifiedPKM()) if (!PKME_Tabs.VerifiedPKM())
{ WinFormsUtil.Alert("Fix data before exporting."); return; } {
WinFormsUtil.Alert("Fix data before exporting.");
return;
}
Clipboard.SetText(PreparePKM().ShowdownText); var text = PreparePKM().ShowdownText;
WinFormsUtil.Alert("Exported Showdown Set to Clipboard:", Clipboard.GetText()); Clipboard.SetText(text);
var clip = Clipboard.GetText();
if (clip != text)
WinFormsUtil.Alert("Unable to set to Clipboard.", "Try exporting again.");
else
WinFormsUtil.Alert("Exported Showdown Set to Clipboard:", text);
} }
private void ClickShowdownExportParty(object sender, EventArgs e) private void ClickShowdownExportParty(object sender, EventArgs e)
{ {
@ -570,7 +579,7 @@ namespace PKHeX.WinForms
if (temp == null) if (temp == null)
return false; return false;
var type = PKME_Tabs.pkm.GetType(); var type = PKME_Tabs.CurrentPKM.GetType();
PKM pk = PKMConverter.ConvertToType(temp, type, out string c); PKM pk = PKMConverter.ConvertToType(temp, type, out string c);
if (pk == null) if (pk == null)
{ {
@ -757,25 +766,23 @@ namespace PKHeX.WinForms
private void ResetSAVPKMEditors(SaveFile sav) private void ResetSAVPKMEditors(SaveFile sav)
{ {
bool WindowToggleRequired = C_SAV.SAV.Generation < 3 && sav.Generation >= 3; // version combobox refresh hack bool WindowToggleRequired = C_SAV.SAV.Generation < 3 && sav.Generation >= 3; // version combobox refresh hack
bool WindowTranslationRequired = false;
PKM pk = PreparePKM(); PKM pk = PreparePKM();
PKME_Tabs.pkm = sav.BlankPKM; var blank = sav.BlankPKM;
PKME_Tabs.CurrentPKM = blank;
PKME_Tabs.SetPKMFormatMode(sav.Generation); PKME_Tabs.SetPKMFormatMode(sav.Generation);
PKME_Tabs.PopulateFields(PKME_Tabs.pkm); PKME_Tabs.PopulateFields(blank);
C_SAV.SAV = sav; C_SAV.SAV = sav;
// Initialize Subviews // Initialize Overall Info
PKME_Tabs.ToggleInterface();
bool init = PKME_Tabs.fieldsInitialized;
PKME_Tabs.fieldsInitialized = PKME_Tabs.fieldsLoaded = false;
WindowTranslationRequired |= PKME_Tabs.FinalizeInterface(init, sav, pk);
WindowTranslationRequired |= C_SAV.ToggleInterface();
C_SAV.FinalizeInterface();
// Finalize Overall Info
Menu_LoadBoxes.Enabled = Menu_DumpBoxes.Enabled = Menu_Report.Enabled = Menu_Modify.Enabled = C_SAV.SAV.HasBox; Menu_LoadBoxes.Enabled = Menu_DumpBoxes.Enabled = Menu_Report.Enabled = Menu_Modify.Enabled = C_SAV.SAV.HasBox;
// Initialize Subviews
bool WindowTranslationRequired = false;
WindowTranslationRequired |= PKME_Tabs.ToggleInterface(sav, pk);
WindowTranslationRequired |= C_SAV.ToggleInterface();
if (WindowTranslationRequired) // force update -- re-added controls may be untranslated if (WindowTranslationRequired) // force update -- re-added controls may be untranslated
WinFormsUtil.TranslateInterface(this, CurrentLanguage); WinFormsUtil.TranslateInterface(this, CurrentLanguage);
if (WindowToggleRequired) // Version combobox selectedvalue needs a little help, only updates once it is visible if (WindowToggleRequired) // Version combobox selectedvalue needs a little help, only updates once it is visible
PKME_Tabs.FlickerInterface(); PKME_Tabs.FlickerInterface();
@ -923,20 +930,16 @@ namespace PKHeX.WinForms
Thread.CurrentThread.CurrentCulture = new CultureInfo(CurrentLanguage.Substring(0, 2)); Thread.CurrentThread.CurrentCulture = new CultureInfo(CurrentLanguage.Substring(0, 2));
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
PKM pk = C_SAV.SAV.GetPKM((PKME_Tabs.fieldsInitialized ? PreparePKM() : PKME_Tabs.pkm).Data);
bool alreadyInit = PKME_Tabs.fieldsInitialized;
PKME_Tabs.fieldsInitialized = false;
Menu_Options.DropDown.Close(); Menu_Options.DropDown.Close();
PKM pk = C_SAV.SAV.GetPKM(PKME_Tabs.CurrentPKM.Data);
InitializeStrings(); InitializeStrings();
PKME_Tabs.InitializeLanguage(C_SAV.SAV); PKME_Tabs.ChangeLanguage(C_SAV.SAV, pk);
string ProgramTitle = Text; string ProgramTitle = Text;
WinFormsUtil.TranslateInterface(this, CurrentLanguage); // Translate the UI to language. WinFormsUtil.TranslateInterface(this, CurrentLanguage); // Translate the UI to language.
Text = ProgramTitle; Text = ProgramTitle;
PKME_Tabs.CenterSubEditors();
PKME_Tabs.PopulateFields(pk); // put data back in form
PKME_Tabs.fieldsInitialized |= alreadyInit;
} }
private void InitializeStrings() private static void InitializeStrings()
{ {
string l = CurrentLanguage; string l = CurrentLanguage;
GameInfo.Strings = GameInfo.GetStrings(l); GameInfo.Strings = GameInfo.GetStrings(l);
@ -945,15 +948,9 @@ namespace PKHeX.WinForms
// Clipboard.SetText(string.Join(Environment.NewLine, Util.GetLocalization(typeof(LegalityCheckStrings)))); // Clipboard.SetText(string.Join(Environment.NewLine, Util.GetLocalization(typeof(LegalityCheckStrings))));
Task.Run(() => Util.SetLocalization(typeof(LegalityCheckStrings), Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName.Substring(0, 2))); Task.Run(() => Util.SetLocalization(typeof(LegalityCheckStrings), Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName.Substring(0, 2)));
// Force an update to the met locations
PKME_Tabs.origintrack = GameVersion.Unknown;
// Update Legality Analysis strings // Update Legality Analysis strings
LegalityAnalysis.MoveStrings = GameInfo.Strings.movelist; LegalityAnalysis.MoveStrings = GameInfo.Strings.movelist;
LegalityAnalysis.SpeciesStrings = GameInfo.Strings.specieslist; LegalityAnalysis.SpeciesStrings = GameInfo.Strings.specieslist;
if (PKME_Tabs.fieldsInitialized)
PKME_Tabs.UpdateStringDisplay();
} }
#endregion #endregion
@ -1068,7 +1065,8 @@ namespace PKHeX.WinForms
} }
private void GetPreview(PictureBox pb, PKM pk = null) private void GetPreview(PictureBox pb, PKM pk = null)
{ {
if (!PKME_Tabs.fieldsInitialized) return; if (!IsInitialized)
return;
pk = pk ?? PreparePKM(false); // don't perform control loss click pk = pk ?? PreparePKM(false); // don't perform control loss click
if (pb == dragout) dragout.ContextMenuStrip.Enabled = pk.Species != 0 || HaX; // Species if (pb == dragout) dragout.ContextMenuStrip.Enabled = pk.Species != 0 || HaX; // Species
@ -1080,14 +1078,14 @@ namespace PKHeX.WinForms
private void PKME_Tabs_UpdatePreviewSprite(object sender, EventArgs e) => GetPreview(dragout); private void PKME_Tabs_UpdatePreviewSprite(object sender, EventArgs e) => GetPreview(dragout);
private void PKME_Tabs_LegalityChanged(object sender, EventArgs e) private void PKME_Tabs_LegalityChanged(object sender, EventArgs e)
{ {
if (PKME_Tabs.IsLegal == null || HaX) if (sender == null || HaX)
{ {
PB_Legal.Visible = false; PB_Legal.Visible = false;
return; return;
} }
PB_Legal.Visible = true; PB_Legal.Visible = true;
PB_Legal.Image = PKME_Tabs.IsLegal == false ? Resources.warn : Resources.valid; PB_Legal.Image = sender as bool? == false ? Resources.warn : Resources.valid;
} }
private void PKME_Tabs_RequestShowdownExport(object sender, EventArgs e) => ClickShowdownExportPKM(sender, e); private void PKME_Tabs_RequestShowdownExport(object sender, EventArgs e) => ClickShowdownExportPKM(sender, e);
private void PKME_Tabs_RequestShowdownImport(object sender, EventArgs e) => ClickShowdownImportPKM(sender, e); private void PKME_Tabs_RequestShowdownImport(object sender, EventArgs e) => ClickShowdownImportPKM(sender, e);