PKHeX/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Roamer3.cs
Kurt 3c232505e5
Refactoring: Narrow some value types (Species, Move, Form) (#3575)
In this pull request I've changed a ton of method signatures to reflect the more-narrow types of Species, Move# and Form; additionally, I've narrowed other large collections that stored lists of species / permitted values, and reworked them to be more performant with the latest API spaghetti that PKHeX provides. Roamer met locations, usually in a range of [max-min]<64, can be quickly checked using a bitflag operation on a UInt64. Other collections (like "Is this from Colosseum or XD") were eliminated -- shadow state is not transferred COLO<->XD, so having a Shadow ID or matching the met location from a gift/wild encounter is a sufficient check for "originated in XD".
2022-08-26 23:43:36 -07:00

70 lines
1.9 KiB
C#

using System;
using System.Windows.Forms;
using PKHeX.Core;
namespace PKHeX.WinForms;
public partial class SAV_Roamer3 : Form
{
private readonly Roamer3 Reader;
public SAV_Roamer3(SaveFile sav)
{
InitializeComponent();
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
Reader = new Roamer3((SAV3)sav);
CB_Species.InitializeBinding();
CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species, null);
LoadData();
}
private void LoadData()
{
TB_PID.Text = $"{Reader.PID:X8}";
CHK_Shiny.Checked = Reader.IsShiny(Reader.PID);
CB_Species.SelectedValue = (int)Reader.Species;
var IVs = Reader.IVs;
var iv = new[] {TB_HPIV, TB_ATKIV, TB_DEFIV, TB_SPEIV, TB_SPAIV, TB_SPDIV};
for (int i = 0; i < iv.Length; i++)
iv[i].Text = IVs[i].ToString();
CHK_Active.Checked = Reader.Active;
NUD_Level.Value = Math.Min(NUD_Level.Maximum, Reader.CurrentLevel);
}
private void SaveData()
{
Span<int> IVs = stackalloc int[6];
var iv = new[] { TB_HPIV, TB_ATKIV, TB_DEFIV, TB_SPEIV, TB_SPAIV, TB_SPDIV };
for (int i = 0; i < iv.Length; i++)
IVs[i] = Util.ToInt32(iv[i].Text);
Reader.PID = Util.GetHexValue(TB_PID.Text);
Reader.Species = (ushort)WinFormsUtil.GetIndex(CB_Species);
Reader.SetIVs(IVs);
Reader.Active = CHK_Active.Checked;
Reader.CurrentLevel = (int)NUD_Level.Value;
}
private void B_Save_Click(object sender, EventArgs e)
{
SaveData();
Close();
}
private void B_Cancel_Click(object sender, EventArgs e)
{
Close();
}
private void TB_PID_TextChanged(object sender, EventArgs e)
{
var pid = Util.GetHexValue(TB_PID.Text);
CHK_Shiny.Checked = Reader.IsShiny(pid);
}
}