2022-06-18 18:04:24 +00:00
|
|
|
using System;
|
2016-06-22 00:35:12 +00:00
|
|
|
using System.Linq;
|
|
|
|
using System.Windows.Forms;
|
2017-01-08 07:54:09 +00:00
|
|
|
using PKHeX.Core;
|
2016-06-22 00:35:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.WinForms;
|
|
|
|
|
|
|
|
public partial class SAV_SimpleTrainer : Form
|
2016-06-22 00:35:12 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
private readonly SaveFile Origin;
|
|
|
|
private readonly SaveFile SAV;
|
2018-08-04 17:06:06 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public SAV_SimpleTrainer(SaveFile sav)
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
|
|
|
SAV = (Origin = sav).Clone();
|
|
|
|
Loading = true;
|
|
|
|
|
2023-12-04 04:13:20 +00:00
|
|
|
cba = [CHK_1, CHK_2, CHK_3, CHK_4, CHK_5, CHK_6, CHK_7, CHK_8];
|
2022-11-25 01:42:17 +00:00
|
|
|
TB_OTName.MaxLength = SAV.MaxStringLengthOT;
|
2022-06-18 18:04:24 +00:00
|
|
|
B_MaxCash.Click += (sender, e) => MT_Money.Text = SAV.MaxMoney.ToString();
|
|
|
|
B_MaxCoins.Click += (sender, e) => MT_Coins.Text = SAV.MaxCoins.ToString();
|
|
|
|
MT_Money.Mask = "".PadRight((int)Math.Floor(Math.Log10(SAV.MaxMoney) + 1), '0');
|
|
|
|
MT_Coins.Mask = "".PadRight((int)Math.Floor(Math.Log10(SAV.MaxCoins) + 1), '0');
|
|
|
|
|
|
|
|
CB_Gender.Items.Clear();
|
|
|
|
CB_Gender.Items.AddRange(Main.GenderSymbols.Take(2).ToArray()); // m/f depending on unicode selection
|
|
|
|
|
|
|
|
L_SID.Visible = MT_SID.Visible = SAV.Generation > 2;
|
|
|
|
L_Coins.Visible = B_MaxCoins.Visible = MT_Coins.Visible = SAV.Generation < 3;
|
|
|
|
CB_Gender.Visible = SAV.Generation > 1;
|
2023-02-27 00:33:53 +00:00
|
|
|
L_Country.Visible = L_Region.Visible = CB_Country.Visible = CB_Region.Visible = SAV.Generation > 3;
|
|
|
|
CB_Country.InitializeBinding();
|
|
|
|
CB_Region.InitializeBinding();
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
L_PikaFriend.Visible = MT_PikaFriend.Visible = L_PikaBeach.Visible = MT_PikaBeach.Visible = SAV.Generation == 1;
|
|
|
|
|
|
|
|
TB_OTName.Text = SAV.OT;
|
|
|
|
CB_Gender.SelectedIndex = SAV.Gender;
|
2023-01-22 04:02:33 +00:00
|
|
|
MT_TID.Text = SAV.TID16.ToString("00000");
|
|
|
|
MT_SID.Text = SAV.SID16.ToString("00000");
|
2022-06-18 18:04:24 +00:00
|
|
|
MT_Money.Text = SAV.Money.ToString();
|
|
|
|
MT_Hours.Text = SAV.PlayedHours.ToString();
|
|
|
|
MT_Minutes.Text = SAV.PlayedMinutes.ToString();
|
|
|
|
MT_Seconds.Text = SAV.PlayedSeconds.ToString();
|
|
|
|
|
|
|
|
int badgeval = 0;
|
|
|
|
if (SAV is SAV1 sav1)
|
2016-06-22 00:35:12 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
MT_Coins.Text = sav1.Coin.ToString();
|
|
|
|
badgeval = sav1.Badges;
|
|
|
|
|
|
|
|
L_Started.Visible = L_Fame.Visible = false;
|
|
|
|
CAL_AdventureStartDate.Visible = CAL_HoFDate.Visible = false;
|
|
|
|
CAL_AdventureStartTime.Visible = CAL_HoFTime.Visible = false;
|
|
|
|
GB_Map.Visible = false;
|
|
|
|
GB_Options.Visible = true;
|
2023-12-18 00:38:53 +00:00
|
|
|
CB_BattleStyle.Items.AddRange(["Switch", "Set"]);
|
|
|
|
CB_SoundType.Items.AddRange(["Mono", "Stereo", "Left", "Right"]);
|
|
|
|
CB_TextSpeed.Items.AddRange(["0 (Instant)", "1 (Fast)", "2", "3 (Normal)", "4", "5 (Slow)", "6", "7"]);
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
CHK_BattleEffects.Checked = sav1.BattleEffects;
|
|
|
|
CB_BattleStyle.SelectedIndex = sav1.BattleStyleSwitch ? 0 : 1;
|
|
|
|
CB_SoundType.SelectedIndex = sav1.Sound;
|
|
|
|
CB_TextSpeed.SelectedIndex = sav1.TextSpeed;
|
|
|
|
|
|
|
|
MT_PikaFriend.Text = sav1.PikaFriendship.ToString();
|
|
|
|
MT_PikaBeach.Text = sav1.PikaBeachScore.ToString();
|
|
|
|
if (!sav1.Version.Contains(GameVersion.YW))
|
2016-08-30 00:48:05 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
L_PikaFriend.Visible = MT_PikaFriend.Visible = false;
|
|
|
|
L_PikaBeach.Visible = MT_PikaBeach.Visible = false;
|
|
|
|
CB_SoundType.Visible = LBL_SoundType.Visible = false;
|
2016-08-30 00:48:05 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2016-08-30 00:48:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (SAV is SAV2 sav2)
|
|
|
|
{
|
|
|
|
MT_Coins.Text = sav2.Coin.ToString();
|
|
|
|
|
|
|
|
L_Started.Visible = L_Fame.Visible = false;
|
|
|
|
CAL_AdventureStartDate.Visible = CAL_HoFDate.Visible = false;
|
|
|
|
CAL_AdventureStartTime.Visible = CAL_HoFTime.Visible = false;
|
|
|
|
GB_Map.Visible = false;
|
|
|
|
GB_Options.Visible = true;
|
2023-12-18 00:38:53 +00:00
|
|
|
CB_BattleStyle.Items.AddRange(["Switch", "Set"]);
|
|
|
|
CB_SoundType.Items.AddRange(["Mono", "Stereo"]);
|
|
|
|
CB_TextSpeed.Items.AddRange(["0 (Instant)", "1 (Fast)", "2", "3 (Normal)", "4", "5 (Slow)", "6", "7"]);
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
CHK_BattleEffects.Checked = sav2.BattleEffects;
|
|
|
|
CB_BattleStyle.SelectedIndex = sav2.BattleStyleSwitch ? 0 : 1;
|
|
|
|
CB_SoundType.SelectedIndex = sav2.Sound > 0 ? 1 : 0;
|
|
|
|
CB_TextSpeed.SelectedIndex = sav2.TextSpeed;
|
|
|
|
badgeval = sav2.Badges;
|
2023-12-04 04:13:20 +00:00
|
|
|
cba = [CHK_1, CHK_2, CHK_3, CHK_4, CHK_6, CHK_5, CHK_7, CHK_8, CHK_H1, CHK_H2, CHK_H3, CHK_H4, CHK_H5, CHK_H6, CHK_H7, CHK_H8];
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2016-09-04 01:57:54 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (SAV is SAV3 sav3)
|
|
|
|
{
|
|
|
|
GB_Map.Visible = false;
|
|
|
|
badgeval = sav3.Badges;
|
2016-06-26 21:23:41 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
L_Started.Visible = L_Fame.Visible = false;
|
|
|
|
CAL_AdventureStartDate.Visible = CAL_HoFDate.Visible = false;
|
|
|
|
CAL_AdventureStartTime.Visible = CAL_HoFTime.Visible = false;
|
|
|
|
}
|
|
|
|
if (SAV is SAV3Colosseum or SAV3XD)
|
|
|
|
{
|
|
|
|
GB_Map.Visible = false;
|
|
|
|
GB_Badges.Visible = false;
|
|
|
|
L_Started.Visible = L_Fame.Visible = false;
|
|
|
|
CAL_AdventureStartDate.Visible = CAL_HoFDate.Visible = false;
|
|
|
|
CAL_AdventureStartTime.Visible = CAL_HoFTime.Visible = false;
|
|
|
|
GB_Adventure.Visible = false;
|
|
|
|
return;
|
|
|
|
}
|
2016-06-22 00:35:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (SAV is SAV4 sav4)
|
|
|
|
{
|
|
|
|
NUD_M.Value = sav4.M;
|
|
|
|
NUD_X.Value = sav4.X;
|
|
|
|
NUD_Z.Value = sav4.Z;
|
|
|
|
NUD_Y.Value = sav4.Y;
|
|
|
|
|
|
|
|
badgeval = sav4.Badges;
|
|
|
|
if (sav4 is SAV4HGSS hgss)
|
2016-06-22 00:35:12 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
badgeval |= hgss.Badges16 << 8;
|
2023-12-04 04:13:20 +00:00
|
|
|
cba = [..cba, CHK_H1, CHK_H2, CHK_H3, CHK_H4, CHK_H5, CHK_H6, CHK_H7, CHK_H8];
|
2016-06-22 00:35:12 +00:00
|
|
|
}
|
2023-02-27 00:33:53 +00:00
|
|
|
|
|
|
|
Main.SetCountrySubRegion(CB_Country, "gen4_countries");
|
|
|
|
CB_Country.SelectedValue = sav4.Country;
|
|
|
|
CB_Region.SelectedValue = sav4.Region;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
else if (SAV is SAV5 s)
|
|
|
|
{
|
2023-02-27 00:33:53 +00:00
|
|
|
foreach (var control in new Control[] { L_Coins, B_MaxCoins, MT_Coins })
|
2016-06-22 00:35:12 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var pos = control.Location;
|
|
|
|
GB_Badges.Controls.Add(control);
|
|
|
|
control.Location = pos;
|
|
|
|
control.Visible = true;
|
2016-06-22 00:35:12 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
L_Coins.Text = "BP"; // no translation boo
|
|
|
|
MT_Coins.Text = s.BattleSubway.BP.ToString();
|
|
|
|
|
2024-03-05 05:46:11 +00:00
|
|
|
var pd = s.PlayerPosition;
|
2022-06-18 18:04:24 +00:00
|
|
|
NUD_M.Value = pd.M;
|
|
|
|
NUD_X.Value = pd.X;
|
|
|
|
NUD_Z.Value = pd.Z;
|
|
|
|
NUD_Y.Value = pd.Y;
|
|
|
|
badgeval = s.Misc.Badges;
|
2023-02-27 00:33:53 +00:00
|
|
|
|
|
|
|
Main.SetCountrySubRegion(CB_Country, "gen5_countries");
|
|
|
|
CB_Country.SelectedValue = s.Country;
|
|
|
|
CB_Region.SelectedValue = s.Region;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2016-06-22 00:35:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
for (int i = 0; i < cba.Length; i++)
|
|
|
|
{
|
|
|
|
cba[i].Visible = true;
|
|
|
|
cba[i].Checked = (badgeval & (1 << i)) != 0;
|
|
|
|
}
|
2016-06-22 00:35:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
DateUtil.GetDateTime2000(SAV.SecondsToStart, out var date, out var time);
|
|
|
|
CAL_AdventureStartDate.Value = date;
|
|
|
|
CAL_AdventureStartTime.Value = time;
|
2019-09-16 05:12:32 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
DateUtil.GetDateTime2000(SAV.SecondsToFame, out date, out time);
|
|
|
|
CAL_HoFDate.Value = date;
|
|
|
|
CAL_HoFTime.Value = time;
|
2016-12-31 23:45:04 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Loading = false;
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private readonly CheckBox[] cba;
|
|
|
|
private readonly bool Loading;
|
|
|
|
private bool MapUpdated;
|
2016-12-31 23:45:04 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ChangeFFFF(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
MaskedTextBox box = (MaskedTextBox)sender;
|
|
|
|
if (box.Text.Length == 0) box.Text = "0";
|
|
|
|
if (Util.ToInt32(box.Text) > 65535) box.Text = "65535";
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void Change255(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
MaskedTextBox box = (MaskedTextBox)sender;
|
|
|
|
if (box.Text.Length == 0) box.Text = "0";
|
|
|
|
if (Util.ToInt32(box.Text) > byte.MaxValue) box.Text = "255";
|
|
|
|
}
|
2016-06-22 00:35:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void B_Save_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (SAV.OT != TB_OTName.Text) // only modify if changed (preserve trash bytes?)
|
|
|
|
SAV.OT = TB_OTName.Text;
|
|
|
|
SAV.Gender = (byte)CB_Gender.SelectedIndex;
|
2016-06-22 00:35:12 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
SAV.TID16 = (ushort)Util.ToUInt32(MT_TID.Text);
|
|
|
|
SAV.SID16 = (ushort)Util.ToUInt32(MT_SID.Text);
|
2022-06-18 18:04:24 +00:00
|
|
|
SAV.Money = Util.ToUInt32(MT_Money.Text);
|
2016-06-22 00:35:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
SAV.PlayedHours = ushort.Parse(MT_Hours.Text);
|
|
|
|
SAV.PlayedMinutes = ushort.Parse(MT_Minutes.Text) % 60;
|
|
|
|
SAV.PlayedSeconds = ushort.Parse(MT_Seconds.Text) % 60;
|
2016-06-26 21:23:41 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Copy Badges
|
|
|
|
int badgeval = 0;
|
|
|
|
for (int i = 0; i < cba.Length; i++)
|
|
|
|
badgeval |= (cba[i].Checked ? 1 : 0) << i;
|
2016-06-22 00:35:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (SAV is SAV1 sav1)
|
|
|
|
{
|
|
|
|
sav1.Coin = (ushort)Math.Min(Util.ToUInt32(MT_Coins.Text), SAV.MaxCoins);
|
|
|
|
sav1.Badges = badgeval & 0xFF;
|
|
|
|
sav1.PikaFriendship = (byte)Math.Min(255, Util.ToUInt32(MT_PikaFriend.Text));
|
|
|
|
sav1.PikaBeachScore = (ushort)Math.Min(9999, Util.ToUInt32(MT_PikaBeach.Text));
|
|
|
|
sav1.BattleEffects = CHK_BattleEffects.Checked;
|
|
|
|
sav1.BattleStyleSwitch = CB_BattleStyle.SelectedIndex == 0;
|
|
|
|
sav1.Sound = CB_SoundType.SelectedIndex;
|
|
|
|
sav1.TextSpeed = CB_TextSpeed.SelectedIndex;
|
|
|
|
}
|
2016-08-30 00:48:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (SAV is SAV2 sav2)
|
|
|
|
{
|
|
|
|
sav2.Coin = (ushort)Math.Min(Util.ToUInt32(MT_Coins.Text), SAV.MaxCoins);
|
|
|
|
sav2.Badges = badgeval & 0xFFFF;
|
2016-09-04 01:57:54 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
sav2.BattleEffects = CHK_BattleEffects.Checked;
|
|
|
|
sav2.BattleStyleSwitch = CB_BattleStyle.SelectedIndex == 0;
|
|
|
|
sav2.Sound = CB_SoundType.SelectedIndex > 0 ? 2 : 0;
|
|
|
|
sav2.TextSpeed = CB_TextSpeed.SelectedIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SAV is SAV3 sav3)
|
|
|
|
{
|
|
|
|
sav3.Badges = badgeval & 0xFF;
|
|
|
|
}
|
2016-09-04 01:57:54 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (SAV is SAV4 sav4)
|
|
|
|
{
|
|
|
|
if (MapUpdated)
|
2017-04-16 06:14:07 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
sav4.M = (int)NUD_M.Value;
|
|
|
|
sav4.X = (int)NUD_X.Value;
|
|
|
|
sav4.Z = (int)NUD_Z.Value;
|
|
|
|
sav4.Y = (int)NUD_Y.Value;
|
2017-04-16 06:14:07 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
sav4.Badges = badgeval & 0xFF;
|
|
|
|
if (sav4 is SAV4HGSS hgss)
|
2016-06-22 00:35:12 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
hgss.Badges16 = badgeval >> 8;
|
2016-06-22 00:35:12 +00:00
|
|
|
}
|
2023-02-27 00:33:53 +00:00
|
|
|
sav4.Country = WinFormsUtil.GetIndex(CB_Country);
|
|
|
|
sav4.Region = WinFormsUtil.GetIndex(CB_Region);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
else if (SAV is SAV5 s)
|
|
|
|
{
|
|
|
|
if (MapUpdated)
|
2016-06-22 00:35:12 +00:00
|
|
|
{
|
2024-03-05 05:46:11 +00:00
|
|
|
var pd = s.PlayerPosition;
|
2022-06-18 18:04:24 +00:00
|
|
|
pd.M = (int)NUD_M.Value;
|
|
|
|
pd.X = (int)NUD_X.Value;
|
|
|
|
pd.Z = (int)NUD_Z.Value;
|
|
|
|
pd.Y = (int)NUD_Y.Value;
|
2016-06-22 00:35:12 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
s.Misc.Badges = badgeval & 0xFF;
|
|
|
|
s.BattleSubway.BP = (ushort)Math.Min(Util.ToUInt32(MT_Coins.Text), SAV.MaxCoins);
|
2023-02-27 00:33:53 +00:00
|
|
|
s.Country = WinFormsUtil.GetIndex(CB_Country);
|
|
|
|
s.Region = WinFormsUtil.GetIndex(CB_Region);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2017-05-23 04:55:05 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
SAV.SecondsToStart = (uint)DateUtil.GetSecondsFrom2000(CAL_AdventureStartDate.Value, CAL_AdventureStartTime.Value);
|
|
|
|
SAV.SecondsToFame = (uint)DateUtil.GetSecondsFrom2000(CAL_HoFDate.Value, CAL_HoFTime.Value);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Origin.CopyChangesFrom(SAV);
|
|
|
|
Close();
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void B_Cancel_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void ChangeMapValue(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (!Loading)
|
|
|
|
MapUpdated = true;
|
2016-06-22 00:35:12 +00:00
|
|
|
}
|
2023-02-27 00:33:53 +00:00
|
|
|
|
|
|
|
private void UpdateCountry(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (sender is ComboBox c)
|
|
|
|
{
|
|
|
|
int index = WinFormsUtil.GetIndex(c);
|
2023-04-13 07:05:10 +00:00
|
|
|
if (SAV is SAV4)
|
2023-02-27 00:33:53 +00:00
|
|
|
{
|
|
|
|
Main.SetCountrySubRegion(CB_Region, $"gen4_sr_{index:000}");
|
|
|
|
if (CB_Region.Items.Count == 0)
|
2023-04-13 07:05:10 +00:00
|
|
|
Main.SetCountrySubRegion(CB_Region, "gen4_sr_default");
|
2023-02-27 00:33:53 +00:00
|
|
|
}
|
2023-04-13 07:05:10 +00:00
|
|
|
else if (SAV is SAV5)
|
2023-02-27 00:33:53 +00:00
|
|
|
{
|
|
|
|
Main.SetCountrySubRegion(CB_Region, $"gen5_sr_{index:000}");
|
|
|
|
if (CB_Region.Items.Count == 0)
|
2023-04-13 07:05:10 +00:00
|
|
|
Main.SetCountrySubRegion(CB_Region, "gen5_sr_default");
|
2023-02-27 00:33:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-22 00:35:12 +00:00
|
|
|
}
|