mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-21 09:53:14 +00:00
02420d3e93
* Handle some nullable cases Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data) Make some classes have explicit constructors instead of { } initialization * Handle bits more obviously without null * Make SaveFile.BAK explicitly readonly again * merge constructor methods to have readonly fields * Inline some properties * More nullable handling * Rearrange box actions define straightforward classes to not have any null properties * Make extrabyte reference array immutable * Move tooltip creation to designer * Rearrange some logic to reduce nesting * Cache generated fonts * Split mystery gift album purpose * Handle more tooltips * Disallow null setters * Don't capture RNG object, only type enum * Unify learnset objects Now have readonly properties which are never null don't new() empty learnsets (>800 Learnset objects no longer created, total of 2400 objects since we also new() a move & level array) optimize g1/2 reader for early abort case * Access rewrite Initialize blocks in a separate object, and get via that object removes a couple hundred "might be null" warnings since blocks are now readonly getters some block references have been relocated, but interfaces should expose all that's needed put HoF6 controls in a groupbox, and disable * Readonly personal data * IVs non nullable for mystery gift * Explicitly initialize forced encounter moves * Make shadow objects readonly & non-null Put murkrow fix in binary data resource, instead of on startup * Assign dex form fetch on constructor Fixes legality parsing edge cases also handle cxd parse for valid; exit before exception is thrown in FrameGenerator * Remove unnecessary null checks * Keep empty value until init SetPouch sets the value to an actual one during load, but whatever * Readonly team lock data * Readonly locks Put locked encounters at bottom (favor unlocked) * Mail readonly data / offset Rearrange some call flow and pass defaults Add fake classes for SaveDataEditor mocking Always party size, no need to check twice in stat editor use a fake save file as initial data for savedata editor, and for gamedata (wow i found a usage) constrain eventwork editor to struct variable types (uint, int, etc), thus preventing null assignment errors
169 lines
4.8 KiB
C#
169 lines
4.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using PKHeX.Core;
|
|
|
|
namespace PKHeX.WinForms.Controls
|
|
{
|
|
public partial class TrainerID : UserControl
|
|
{
|
|
public TrainerID() => InitializeComponent();
|
|
public event EventHandler UpdatedID;
|
|
|
|
private int Format = -1;
|
|
private ITrainerID Trainer;
|
|
|
|
public void UpdateTSV()
|
|
{
|
|
var tsv = GetTSV();
|
|
if (tsv < 0)
|
|
return;
|
|
|
|
string IDstr = $"TSV: {tsv:d4}";
|
|
var repack = (Trainer.SID * 1_000_000) + Trainer.TID;
|
|
|
|
string supplement = Format < 7
|
|
? $"G7ID: ({repack / 1_000_000:D4}){repack % 1_000_000:D6}"
|
|
: $"ID: {Trainer.TID:D5}/{Trainer.SID:D5}";
|
|
|
|
IDstr += Environment.NewLine + supplement;
|
|
TSVTooltip.SetToolTip(TB_TID, IDstr);
|
|
TSVTooltip.SetToolTip(TB_SID, IDstr);
|
|
TSVTooltip.SetToolTip(TB_TID7, IDstr);
|
|
TSVTooltip.SetToolTip(TB_SID7, IDstr);
|
|
}
|
|
|
|
private int GetTSV()
|
|
{
|
|
if (Format <= 2)
|
|
return -1;
|
|
var xor = Trainer.SID ^ Trainer.TID;
|
|
if (Format <= 5)
|
|
return xor >> 3;
|
|
return xor >> 4;
|
|
}
|
|
|
|
public void LoadIDValues(ITrainerID tr)
|
|
{
|
|
Trainer = tr;
|
|
int format = tr.GetTrainerIDFormat();
|
|
SetFormat(format);
|
|
LoadValues();
|
|
}
|
|
|
|
public void UpdateSID() => LoadValues();
|
|
|
|
public void LoadInfo(ITrainerInfo info)
|
|
{
|
|
Trainer.TID = info.TID;
|
|
Trainer.SID = info.SID;
|
|
LoadValues();
|
|
}
|
|
|
|
private void LoadValues()
|
|
{
|
|
if (Format <= 2)
|
|
TB_TID.Text = Trainer.TID.ToString();
|
|
else if (Format <= 6)
|
|
LoadTID(Trainer.TID, Trainer.SID);
|
|
else
|
|
LoadTID7(Trainer.TID, Trainer.SID);
|
|
}
|
|
|
|
private void LoadTID(int tid, int sid)
|
|
{
|
|
TB_TID.Text = tid.ToString("D5");
|
|
TB_SID.Text = sid.ToString("D5");
|
|
}
|
|
|
|
private void LoadTID7(int tid, int sid)
|
|
{
|
|
var repack = (uint)((sid << 16) | tid);
|
|
sid = (int)(repack / 1_000_000);
|
|
tid = (int)(repack % 1_000_000);
|
|
|
|
TB_TID7.Text = tid.ToString("D6");
|
|
TB_SID7.Text = sid.ToString("D4");
|
|
}
|
|
|
|
private void SetFormat(int format)
|
|
{
|
|
if (format == Format)
|
|
return;
|
|
|
|
var controls = GetControlsForFormat(format);
|
|
FLP.Controls.Clear(); int i = 0;
|
|
foreach (var c in controls)
|
|
{
|
|
FLP.Controls.Add(c);
|
|
FLP.Controls.SetChildIndex(c, i++); // because you don't listen the first time
|
|
}
|
|
|
|
Format = format;
|
|
}
|
|
|
|
private IEnumerable<Control> GetControlsForFormat(int format)
|
|
{
|
|
if (format >= 7)
|
|
return new Control[] { Label_SID, TB_SID7, Label_TID, TB_TID7 };
|
|
if (format >= 3)
|
|
return new Control[] { Label_TID, TB_TID, Label_SID, TB_SID };
|
|
return new Control[] { Label_TID, TB_TID };
|
|
}
|
|
|
|
private void UpdateTSV(object sender, EventArgs e) => UpdateTSV();
|
|
|
|
private void Update_ID(object sender, EventArgs e)
|
|
{
|
|
if (!(sender is MaskedTextBox mt))
|
|
return;
|
|
|
|
int.TryParse(mt.Text, out var val);
|
|
if (mt == TB_TID7)
|
|
{
|
|
if (val > 999_999)
|
|
{
|
|
mt.Text = "999999";
|
|
return;
|
|
}
|
|
int.TryParse(TB_SID7.Text, out var sid);
|
|
SanityCheckSID7(val, sid);
|
|
}
|
|
else if (mt == TB_SID7)
|
|
{
|
|
if (val > 4294) // max 4 digits of 32bit int
|
|
{
|
|
mt.Text = "4294";
|
|
return;
|
|
}
|
|
int.TryParse(TB_TID7.Text, out var tid);
|
|
SanityCheckSID7(tid, val);
|
|
}
|
|
else
|
|
{
|
|
if (val > ushort.MaxValue) // prior to gen7
|
|
mt.Text = (val = ushort.MaxValue).ToString();
|
|
|
|
if (mt == TB_TID)
|
|
Trainer.TID = val;
|
|
else
|
|
Trainer.SID = val;
|
|
}
|
|
|
|
UpdatedID?.Invoke(sender, e);
|
|
}
|
|
|
|
private void SanityCheckSID7(int tid, int sid)
|
|
{
|
|
var repack = ((long)sid * 1_000_000) + tid;
|
|
if (repack > uint.MaxValue)
|
|
{
|
|
TB_SID7.Text = (sid - 1).ToString();
|
|
return;
|
|
}
|
|
|
|
Trainer.SID = (ushort)(repack >> 16);
|
|
Trainer.TID = (ushort)repack;
|
|
}
|
|
}
|
|
}
|