Simplify hex seed editing

Undo is nifty, no need to have 3 separate methods when the underlying
function is the same.
This commit is contained in:
Kurt 2016-12-28 14:35:14 -08:00
parent c99ed5ead2
commit d81cf50f99
2 changed files with 28 additions and 85 deletions

View file

@ -5134,7 +5134,7 @@
this.TB_RNGSeed.Size = new System.Drawing.Size(120, 20); this.TB_RNGSeed.Size = new System.Drawing.Size(120, 20);
this.TB_RNGSeed.TabIndex = 8; this.TB_RNGSeed.TabIndex = 8;
this.TB_RNGSeed.Text = "0123456789ABCDEF"; this.TB_RNGSeed.Text = "0123456789ABCDEF";
this.TB_RNGSeed.TextChanged += new System.EventHandler(this.updateEggRNGSeed); this.TB_RNGSeed.Validated += new System.EventHandler(this.updateStringSeed);
// //
// dcpkx2 // dcpkx2
// //
@ -5349,7 +5349,7 @@
this.TB_Secure2.Size = new System.Drawing.Size(120, 20); this.TB_Secure2.Size = new System.Drawing.Size(120, 20);
this.TB_Secure2.TabIndex = 17; this.TB_Secure2.TabIndex = 17;
this.TB_Secure2.Text = "0000000000000000"; this.TB_Secure2.Text = "0000000000000000";
this.TB_Secure2.TextChanged += new System.EventHandler(this.updateU64); this.TB_Secure2.Validated += new System.EventHandler(this.updateStringSeed);
// //
// L_Secure1 // L_Secure1
// //
@ -5370,7 +5370,7 @@
this.TB_Secure1.Size = new System.Drawing.Size(120, 20); this.TB_Secure1.Size = new System.Drawing.Size(120, 20);
this.TB_Secure1.TabIndex = 15; this.TB_Secure1.TabIndex = 15;
this.TB_Secure1.Text = "0000000000000000"; this.TB_Secure1.Text = "0000000000000000";
this.TB_Secure1.TextChanged += new System.EventHandler(this.updateU64); this.TB_Secure1.Validated += new System.EventHandler(this.updateStringSeed);
// //
// B_JPEG // B_JPEG
// //
@ -5401,7 +5401,7 @@
this.TB_GameSync.Size = new System.Drawing.Size(120, 20); this.TB_GameSync.Size = new System.Drawing.Size(120, 20);
this.TB_GameSync.TabIndex = 10; this.TB_GameSync.TabIndex = 10;
this.TB_GameSync.Text = "0000000000000000"; this.TB_GameSync.Text = "0000000000000000";
this.TB_GameSync.TextChanged += new System.EventHandler(this.updateGameSyncID); this.TB_GameSync.Validated += new System.EventHandler(this.updateStringSeed);
// //
// B_SaveBoxBin // B_SaveBoxBin
// //

View file

@ -3466,106 +3466,49 @@ namespace PKHeX
((SAV4BR)SAV).CurrentSlot = Util.getIndex(CB_SaveSlot); ((SAV4BR)SAV).CurrentSlot = Util.getIndex(CB_SaveSlot);
setPKXBoxes(); setPKXBoxes();
} }
private void updateEggRNGSeed(object sender, EventArgs e) private void updateStringSeed(object sender, EventArgs e)
{
if (TB_RNGSeed.Text.Length == 0)
{
// Reset to 0
TB_RNGSeed.Text = 0.ToString("X"+SAV.DaycareSeedSize);
return; // recursively triggers this method, no need to continue
}
string filterText = Util.getOnlyHex(TB_RNGSeed.Text);
if (filterText.Length != TB_RNGSeed.Text.Length)
{
Util.Alert("Expected HEX (0-9, A-F).", "Received: " + Environment.NewLine + TB_RNGSeed.Text);
// Reset to Stored Value
var seed = SAV.getDaycareRNGSeed(SAV.DaycareIndex);
if (seed != null)
TB_RNGSeed.Text = seed;
return; // recursively triggers this method, no need to continue
}
// Write final value back to the save
var value = filterText.PadLeft(SAV.DaycareSeedSize, '0');
if (value != SAV.getDaycareRNGSeed(SAV.DaycareIndex))
{
SAV.setDaycareRNGSeed(SAV.DaycareIndex, value);
SAV.Edited = true;
}
}
private void updateGameSyncID(object sender, EventArgs e)
{
TextBox tb = TB_GameSync;
if (tb.Text.Length == 0)
{
// Reset to 0
tb.Text = 0.ToString("X" + SAV.GameSyncIDSize);
return; // recursively triggers this method, no need to continue
}
string filterText = Util.getOnlyHex(tb.Text);
if (filterText.Length != tb.Text.Length)
{
Util.Alert("Expected HEX (0-9, A-F).", "Received: " + Environment.NewLine + tb.Text);
// Reset to Stored Value
var seed = SAV.GameSyncID;
if (seed != null)
tb.Text = seed;
return; // recursively triggers this method, no need to continue
}
// Write final value back to the save
var value = filterText.PadLeft(SAV.GameSyncIDSize, '0');
if (value != SAV.GameSyncID)
{
SAV.GameSyncID = value;
SAV.Edited = true;
}
}
private void updateU64(object sender, EventArgs e)
{ {
if (!fieldsLoaded) if (!fieldsLoaded)
return; return;
TextBox tb = sender as TextBox; TextBox tb = sender as TextBox;
if (tb?.Text.Length == 0) if (tb == null)
{ return;
// Reset to 0
tb.Text = 0.ToString("X16");
return; // recursively triggers this method, no need to continue
}
// Currently saved Value if (tb.Text.Length == 0)
ulong? oldval = 0;
if (SAV.Generation == 6)
{ {
if (tb == TB_Secure1) tb.Undo();
oldval = SAV.Secure1; return;
else if (tb == TB_Secure2)
oldval = SAV.Secure2;
} }
string filterText = Util.getOnlyHex(tb.Text); string filterText = Util.getOnlyHex(tb.Text);
if (filterText.Length != tb.Text.Length) if (filterText.Length != tb.Text.Length)
{ {
Util.Alert("Expected HEX (0-9, A-F).", "Received: " + Environment.NewLine + tb.Text); Util.Alert("Expected HEX (0-9, A-F).", "Received: " + Environment.NewLine + tb.Text);
// Reset to Stored Value tb.Undo();
tb.Text = (oldval ?? 0).ToString("X16"); return;
return; // recursively triggers this method, no need to continue
} }
// Write final value back to the save // Write final value back to the save
ulong? newval = Convert.ToUInt64(filterText, 16); if (tb == TB_RNGSeed)
if (newval == oldval) return;
if (SAV.Generation >= 6)
{ {
var value = filterText.PadLeft(SAV.DaycareSeedSize, '0');
SAV.setDaycareRNGSeed(SAV.DaycareIndex, value);
SAV.Edited = true;
}
else if (tb == TB_GameSync)
{
var value = filterText.PadLeft(SAV.GameSyncIDSize, '0');
SAV.GameSyncID = value;
SAV.Edited = true;
}
else if (SAV.Generation >= 6)
{
var value = Convert.ToUInt64(filterText, 16);
if (tb == TB_Secure1) if (tb == TB_Secure1)
SAV.Secure1 = newval; SAV.Secure1 = value;
else if (tb == TB_Secure2) else if (tb == TB_Secure2)
SAV.Secure2 = newval; SAV.Secure2 = value;
SAV.Edited = true; SAV.Edited = true;
} }
} }