diff --git a/PKHeX.WinForms/Controls/PKM Editor/LoadSave.cs b/PKHeX.WinForms/Controls/PKM Editor/LoadSave.cs index 0bde7a48e..e6846e594 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/LoadSave.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/LoadSave.cs @@ -39,15 +39,12 @@ namespace PKHeX.WinForms.Controls TB_OT.Text = pk.OT_Name; Label_OTGender.Text = gendersymbols[pk.OT_Gender]; Label_OTGender.ForeColor = GetGenderColor(pk.OT_Gender); - TB_TID.Text = $"{pk.TID:00000}"; - TB_SID.Text = $"{pk.SID:00000}"; + TID_Trainer.LoadIDValues(pk); } private void SaveOTID(PKM pk) { pk.OT_Name = TB_OT.Text; pk.OT_Gender = PKX.GetGenderFromString(Label_OTGender.Text); - pk.TID = Util.ToInt32(TB_TID.Text); - pk.SID = Util.ToInt32(TB_SID.Text); } private void LoadPKRS(PKM pk) @@ -343,11 +340,9 @@ namespace PKHeX.WinForms.Controls uint EC = Util.GetHexValue(TB_EC.Text); uint PID = Util.GetHexValue(TB_PID.Text); - uint SID = Util.ToUInt32(TB_SID.Text); - uint TID = Util.ToUInt32(TB_TID.Text); uint LID = PID & 0xFFFF; uint HID = PID >> 16; - uint XOR = TID ^ LID ^ SID ^ HID; + uint XOR = (uint)(pkm.TID ^ LID ^ pkm.SID ^ HID); // Ensure we don't have a shiny. if (XOR >> 3 == 1) // Illegal, fix. (not 16=8) diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.Designer.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.Designer.cs index 3589b40e0..a6c8091d0 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.Designer.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.Designer.cs @@ -112,7 +112,6 @@ this.CHK_Shadow = new System.Windows.Forms.CheckBox(); this.FLP_ShinyLeaf = new System.Windows.Forms.FlowLayoutPanel(); this.L_ShinyLeaf = new System.Windows.Forms.Label(); - this.ShinyLeaf = new PKHeX.WinForms.Controls.ShinyLeaf(); this.Tab_Met = new System.Windows.Forms.TabPage(); this.CHK_AsEgg = new System.Windows.Forms.CheckBox(); this.GB_EggConditions = new System.Windows.Forms.GroupBox(); @@ -148,8 +147,6 @@ this.L_MetTimeOfDay = new System.Windows.Forms.Label(); this.CB_MetTimeOfDay = new System.Windows.Forms.ComboBox(); this.Tab_Stats = new System.Windows.Forms.TabPage(); - this.Stats = new PKHeX.WinForms.Controls.StatEditor(); - this.Contest = new PKHeX.WinForms.Controls.ContestStat(); this.Tab_Attacks = new System.Windows.Forms.TabPage(); this.PB_WarnMove4 = new System.Windows.Forms.PictureBox(); this.PB_WarnMove3 = new System.Windows.Forms.PictureBox(); @@ -209,12 +206,12 @@ this.GB_OT = new System.Windows.Forms.GroupBox(); this.Label_OTGender = new System.Windows.Forms.Label(); this.TB_OT = new System.Windows.Forms.TextBox(); - this.TB_SID = new System.Windows.Forms.MaskedTextBox(); - this.TB_TID = new System.Windows.Forms.MaskedTextBox(); this.Label_OT = new System.Windows.Forms.Label(); - this.Label_SID = new System.Windows.Forms.Label(); - this.Label_TID = new System.Windows.Forms.Label(); this.Label_EncryptionConstant = new System.Windows.Forms.Label(); + this.ShinyLeaf = new PKHeX.WinForms.Controls.ShinyLeaf(); + this.Stats = new PKHeX.WinForms.Controls.StatEditor(); + this.Contest = new PKHeX.WinForms.Controls.ContestStat(); + this.TID_Trainer = new PKHeX.WinForms.Controls.TrainerID(); this.tabMain.SuspendLayout(); this.Tab_Main.SuspendLayout(); this.FLP_Main.SuspendLayout(); @@ -1319,15 +1316,6 @@ this.L_ShinyLeaf.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.L_ShinyLeaf.Click += new System.EventHandler(this.ClickShinyLeaf); // - // ShinyLeaf - // - this.ShinyLeaf.Location = new System.Drawing.Point(110, 0); - this.ShinyLeaf.Margin = new System.Windows.Forms.Padding(0); - this.ShinyLeaf.Name = "ShinyLeaf"; - this.ShinyLeaf.Size = new System.Drawing.Size(140, 56); - this.ShinyLeaf.TabIndex = 116; - this.ShinyLeaf.Value = 0; - // // Tab_Met // this.Tab_Met.AllowDrop = true; @@ -1733,27 +1721,6 @@ this.Tab_Stats.Text = "Stats"; this.Tab_Stats.UseVisualStyleBackColor = true; // - // Stats - // - this.Stats.Location = new System.Drawing.Point(0, 0); - this.Stats.Name = "Stats"; - this.Stats.Size = new System.Drawing.Size(270, 240); - this.Stats.TabIndex = 118; - // - // Contest - // - this.Contest.Beauty = 0; - this.Contest.Cool = 0; - this.Contest.Cute = 0; - this.Contest.Location = new System.Drawing.Point(21, 247); - this.Contest.Margin = new System.Windows.Forms.Padding(0); - this.Contest.Name = "Contest"; - this.Contest.Sheen = 0; - this.Contest.Size = new System.Drawing.Size(230, 50); - this.Contest.Smart = 0; - this.Contest.TabIndex = 117; - this.Contest.Tough = 0; - // // Tab_Attacks // this.Tab_Attacks.AllowDrop = true; @@ -2471,13 +2438,10 @@ // // GB_OT // + this.GB_OT.Controls.Add(this.TID_Trainer); this.GB_OT.Controls.Add(this.Label_OTGender); this.GB_OT.Controls.Add(this.TB_OT); - this.GB_OT.Controls.Add(this.TB_SID); - this.GB_OT.Controls.Add(this.TB_TID); this.GB_OT.Controls.Add(this.Label_OT); - this.GB_OT.Controls.Add(this.Label_SID); - this.GB_OT.Controls.Add(this.Label_TID); this.GB_OT.Location = new System.Drawing.Point(40, 8); this.GB_OT.Name = "GB_OT"; this.GB_OT.Size = new System.Drawing.Size(190, 75); @@ -2506,30 +2470,6 @@ this.TB_OT.TabIndex = 3; this.TB_OT.MouseDown += new System.Windows.Forms.MouseEventHandler(this.UpdateNicknameClick); // - // TB_SID - // - this.TB_SID.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.TB_SID.Location = new System.Drawing.Point(132, 20); - this.TB_SID.Mask = "00000"; - this.TB_SID.Name = "TB_SID"; - this.TB_SID.Size = new System.Drawing.Size(40, 20); - this.TB_SID.TabIndex = 2; - this.TB_SID.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; - this.TB_SID.MouseHover += new System.EventHandler(this.UpdateTSV); - this.TB_SID.Validated += new System.EventHandler(this.Update_ID); - // - // TB_TID - // - this.TB_TID.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.TB_TID.Location = new System.Drawing.Point(46, 20); - this.TB_TID.Mask = "00000"; - this.TB_TID.Name = "TB_TID"; - this.TB_TID.Size = new System.Drawing.Size(40, 20); - this.TB_TID.TabIndex = 1; - this.TB_TID.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; - this.TB_TID.MouseHover += new System.EventHandler(this.UpdateTSV); - this.TB_TID.Validated += new System.EventHandler(this.Update_ID); - // // Label_OT // this.Label_OT.Location = new System.Drawing.Point(4, 48); @@ -2540,24 +2480,6 @@ this.Label_OT.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.Label_OT.Click += new System.EventHandler(this.ClickOT); // - // Label_SID - // - this.Label_SID.Location = new System.Drawing.Point(86, 22); - this.Label_SID.Name = "Label_SID"; - this.Label_SID.Size = new System.Drawing.Size(45, 13); - this.Label_SID.TabIndex = 4; - this.Label_SID.Text = "SID:"; - this.Label_SID.TextAlign = System.Drawing.ContentAlignment.MiddleRight; - // - // Label_TID - // - this.Label_TID.Location = new System.Drawing.Point(4, 22); - this.Label_TID.Name = "Label_TID"; - this.Label_TID.Size = new System.Drawing.Size(40, 13); - this.Label_TID.TabIndex = 3; - this.Label_TID.Text = "TID:"; - this.Label_TID.TextAlign = System.Drawing.ContentAlignment.MiddleRight; - // // Label_EncryptionConstant // this.Label_EncryptionConstant.Location = new System.Drawing.Point(20, 279); @@ -2567,6 +2489,43 @@ this.Label_EncryptionConstant.Text = "Encryption Constant:"; this.Label_EncryptionConstant.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // + // ShinyLeaf + // + this.ShinyLeaf.Location = new System.Drawing.Point(110, 0); + this.ShinyLeaf.Margin = new System.Windows.Forms.Padding(0); + this.ShinyLeaf.Name = "ShinyLeaf"; + this.ShinyLeaf.Size = new System.Drawing.Size(140, 56); + this.ShinyLeaf.TabIndex = 116; + this.ShinyLeaf.Value = 0; + // + // Stats + // + this.Stats.Location = new System.Drawing.Point(0, 0); + this.Stats.Name = "Stats"; + this.Stats.Size = new System.Drawing.Size(270, 240); + this.Stats.TabIndex = 118; + // + // Contest + // + this.Contest.Beauty = 0; + this.Contest.Cool = 0; + this.Contest.Cute = 0; + this.Contest.Location = new System.Drawing.Point(21, 247); + this.Contest.Margin = new System.Windows.Forms.Padding(0); + this.Contest.Name = "Contest"; + this.Contest.Sheen = 0; + this.Contest.Size = new System.Drawing.Size(230, 50); + this.Contest.Smart = 0; + this.Contest.TabIndex = 117; + this.Contest.Tough = 0; + // + // TID_Trainer + // + this.TID_Trainer.Location = new System.Drawing.Point(13, 18); + this.TID_Trainer.Name = "TID_Trainer"; + this.TID_Trainer.Size = new System.Drawing.Size(178, 27); + this.TID_Trainer.TabIndex = 57; + // // PKMEditor // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; @@ -2852,16 +2811,13 @@ public System.Windows.Forms.GroupBox GB_OT; private System.Windows.Forms.Label Label_OTGender; private System.Windows.Forms.TextBox TB_OT; - private System.Windows.Forms.MaskedTextBox TB_SID; - private System.Windows.Forms.MaskedTextBox TB_TID; private System.Windows.Forms.Label Label_OT; - private System.Windows.Forms.Label Label_SID; - private System.Windows.Forms.Label Label_TID; private System.Windows.Forms.Label Label_EncryptionConstant; private System.Windows.Forms.FlowLayoutPanel FLP_ShinyLeaf; private System.Windows.Forms.Label L_ShinyLeaf; private Controls.ShinyLeaf ShinyLeaf; private ContestStat Contest; private StatEditor Stats; + private TrainerID TID_Trainer; } } diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index f257e69e1..a0d9cb9b0 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -45,6 +45,7 @@ namespace PKHeX.WinForms.Controls Stats.SetMainEditor(this); LoadShowdownSet = LoadShowdownSetDefault; + TID_Trainer.UpdatedID += Update_ID; } private void UpdateStats() => Stats.UpdateStats(); @@ -82,7 +83,7 @@ namespace PKHeX.WinForms.Controls public delegate SaveFile ReturnSAVEventHandler(object sender, EventArgs e); private readonly PictureBox[] movePB, relearnPB; - private readonly ToolTip Tip1 = new ToolTip(), Tip2 = new ToolTip(), Tip3 = new ToolTip(), NatureTip = new ToolTip(); + private readonly ToolTip Tip3 = new ToolTip(), NatureTip = new ToolTip(); private SaveFile RequestSaveFile => SaveFileRequested?.Invoke(this, EventArgs.Empty); public bool PKMIsUnsaved => FieldsInitialized && FieldsLoaded && LastData != null && LastData.Any(b => b != 0) && !LastData.SequenceEqual(CurrentPKM.Data); public bool IsEmptyOrEgg => CHK_IsEgg.Checked || CB_Species.SelectedIndex == 0; @@ -278,7 +279,7 @@ namespace PKHeX.WinForms.Controls if (!Unicode) { BTN_Shinytize.Text = "*"; - TB_Nickname.Font = TB_OT.Font = TB_OTt2.Font = Label_TID.Font; + TB_Nickname.Font = TB_OT.Font = TB_OTt2.Font = GB_OT.Font; } else { @@ -317,8 +318,7 @@ namespace PKHeX.WinForms.Controls TB_OT.Text = SAV.OT; Label_OTGender.Text = gendersymbols[SAV.Gender & 1]; Label_OTGender.ForeColor = GetGenderColor(SAV.Gender & 1); - TB_TID.Text = SAV.TID.ToString("00000"); - TB_SID.Text = SAV.SID.ToString("00000"); + TID_Trainer.LoadInfo(SAV); if (SAV.Game >= 0) CB_GameOrigin.SelectedValue = SAV.Game; @@ -412,10 +412,6 @@ namespace PKHeX.WinForms.Controls { if (sender == TB_PID) pkm.PID = Util.GetHexValue(TB_PID.Text); - else if (sender == TB_TID) - pkm.TID = (int)Util.ToUInt32(TB_TID.Text); - else if (sender == TB_SID) - pkm.SID = (int)Util.ToUInt32(TB_SID.Text); // Recalculate shininiess bool isShiny = pkm.IsShiny; @@ -1061,6 +1057,12 @@ namespace PKHeX.WinForms.Controls if (!FieldsLoaded) CB_GameOrigin.Focus(); // hacky validation forcing + + if (FieldsLoaded) + { + pkm.Version = (int)Version; + TID_Trainer.LoadIDValues(pkm); + } } // Visibility logic for Gen 4 encounter type; only show for Gen 4 Pokemon. @@ -1232,7 +1234,7 @@ namespace PKHeX.WinForms.Controls bool isTraded = false; var SAV = SaveFileRequested?.Invoke(this, e); if (SAV != null) - isTraded = SAV.OT != TB_OT.Text || SAV.TID != Util.ToInt32(TB_TID.Text) || SAV.SID != Util.ToInt32(TB_SID.Text); + isTraded = SAV.OT != TB_OT.Text || SAV.TID != pkm.TID || SAV.SID != pkm.SID; CB_MetLocation.SelectedIndex = isTraded ? 2 : 0; if (!CHK_Nicknamed.Checked) @@ -1293,8 +1295,6 @@ namespace PKHeX.WinForms.Controls } private void UpdateShiny(bool PID) { - pkm.TID = Util.ToInt32(TB_TID.Text); - pkm.SID = Util.ToInt32(TB_SID.Text); pkm.PID = Util.GetHexValue(TB_PID.Text); pkm.Nature = WinFormsUtil.GetIndex(CB_Nature); pkm.Gender = PKX.GetGenderFromString(Label_Gender.Text); @@ -1314,7 +1314,7 @@ namespace PKHeX.WinForms.Controls else { pkm.SetShinySID(); - TB_SID.Text = pkm.SID.ToString(); + TID_Trainer.UpdateSID(); } } else @@ -1333,12 +1333,7 @@ namespace PKHeX.WinForms.Controls if (pkm.Format < 6) return; - string IDstr = $"TSV: {pkm.TSV:d4}"; - if (pkm.Format > 6) - IDstr += Environment.NewLine + $"G7TID: ({pkm.TrainerSID7:d4}){pkm.TrainerID7:d6}"; - - Tip1.SetToolTip(TB_TID, IDstr); - Tip2.SetToolTip(TB_SID, IDstr); + TID_Trainer.UpdateTSV(); pkm.PID = Util.GetHexValue(TB_PID.Text); Tip3.SetToolTip(TB_PID, $"PSV: {pkm.PSV:d4}"); @@ -1349,10 +1344,6 @@ namespace PKHeX.WinForms.Controls TB_PID.Text = Util.GetHexValue(TB_PID.Text).ToString("X8"); TB_EC.Text = Util.GetHexValue(TB_EC.Text).ToString("X8"); - // Max TID/SID is 65535 - if (Util.ToUInt32(TB_TID.Text) > ushort.MaxValue) TB_TID.Text = "65535"; - if (Util.ToUInt32(TB_SID.Text) > ushort.MaxValue) TB_SID.Text = "65535"; - SetIsShiny(sender); UpdateSprite(); Stats.UpdateIVs(null, null); // If the EC is changed, EC%6 (Characteristic) might be changed. @@ -1519,8 +1510,6 @@ namespace PKHeX.WinForms.Controls } private void ToggleInterface(int gen) { - Tip1.RemoveAll(); Tip2.RemoveAll(); Tip3.RemoveAll(); // TSV/PSV - FLP_Country.Visible = FLP_SubRegion.Visible = FLP_3DSRegion.Visible = gen >= 6; Label_EncryptionConstant.Visible = BTN_RerollEC.Visible = TB_EC.Visible = gen >= 6; GB_nOT.Visible = GB_RelearnMoves.Visible = BTN_Medals.Visible = BTN_History.Visible = gen >= 6; @@ -1541,7 +1530,7 @@ namespace PKHeX.WinForms.Controls GB_Markings.Visible = gen >= 3; BTN_Ribbons.Visible = gen >= 3; CB_Form.Enabled = gen >= 3; - BTN_RerollPID.Visible = Label_PID.Visible = TB_PID.Visible = Label_SID.Visible = TB_SID.Visible = gen >= 3; + BTN_RerollPID.Visible = Label_PID.Visible = TB_PID.Visible = gen >= 3; FLP_FriendshipForm.Visible = gen >= 2; FLP_HeldItem.Visible = gen >= 2; diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.resx b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.resx index 2f9dcc1cb..82e270991 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.resx +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.resx @@ -123,6 +123,18 @@ True + + True + + + True + + + True + + + True + True @@ -461,36 +473,6 @@ True - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - True @@ -1315,42 +1297,18 @@ True - - True - - - True - True - - True - - - True - True True - - True - - - True - True - - True - - - True - True diff --git a/PKHeX.WinForms/Controls/PKM Editor/TrainerID.Designer.cs b/PKHeX.WinForms/Controls/PKM Editor/TrainerID.Designer.cs new file mode 100644 index 000000000..1181a1903 --- /dev/null +++ b/PKHeX.WinForms/Controls/PKM Editor/TrainerID.Designer.cs @@ -0,0 +1,156 @@ +namespace PKHeX.WinForms.Controls +{ + partial class TrainerID + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.FLP = new System.Windows.Forms.FlowLayoutPanel(); + this.Label_TID = new System.Windows.Forms.Label(); + this.TB_TID = new System.Windows.Forms.MaskedTextBox(); + this.TB_TID7 = new System.Windows.Forms.MaskedTextBox(); + this.Label_SID = new System.Windows.Forms.Label(); + this.TB_SID = new System.Windows.Forms.MaskedTextBox(); + this.TB_SID7 = new System.Windows.Forms.MaskedTextBox(); + this.FLP.SuspendLayout(); + this.SuspendLayout(); + // + // FLP + // + this.FLP.Controls.Add(this.Label_TID); + this.FLP.Controls.Add(this.TB_TID); + this.FLP.Controls.Add(this.TB_TID7); + this.FLP.Controls.Add(this.Label_SID); + this.FLP.Controls.Add(this.TB_SID); + this.FLP.Controls.Add(this.TB_SID7); + this.FLP.Dock = System.Windows.Forms.DockStyle.Fill; + this.FLP.Location = new System.Drawing.Point(0, 0); + this.FLP.Name = "FLP"; + this.FLP.Size = new System.Drawing.Size(125, 54); + this.FLP.TabIndex = 0; + // + // Label_TID + // + this.Label_TID.AutoSize = true; + this.Label_TID.Location = new System.Drawing.Point(3, 6); + this.Label_TID.Margin = new System.Windows.Forms.Padding(3, 6, 2, 0); + this.Label_TID.Name = "Label_TID"; + this.Label_TID.Size = new System.Drawing.Size(28, 13); + this.Label_TID.TabIndex = 7; + this.Label_TID.Text = "TID:"; + this.Label_TID.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // TB_TID + // + this.TB_TID.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.TB_TID.Location = new System.Drawing.Point(33, 3); + this.TB_TID.Margin = new System.Windows.Forms.Padding(0, 3, 3, 3); + this.TB_TID.Mask = "00000"; + this.TB_TID.Name = "TB_TID"; + this.TB_TID.Size = new System.Drawing.Size(40, 20); + this.TB_TID.TabIndex = 5; + this.TB_TID.Text = "12345"; + this.TB_TID.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.TB_TID.MouseHover += new System.EventHandler(this.UpdateTSV); + this.TB_TID.Validated += new System.EventHandler(this.Update_ID); + // + // TB_TID7 + // + this.TB_TID7.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.TB_TID7.Location = new System.Drawing.Point(76, 3); + this.TB_TID7.Margin = new System.Windows.Forms.Padding(0, 3, 3, 3); + this.TB_TID7.Mask = "000000"; + this.TB_TID7.Name = "TB_TID7"; + this.TB_TID7.Size = new System.Drawing.Size(42, 20); + this.TB_TID7.TabIndex = 9; + this.TB_TID7.Text = "123456"; + this.TB_TID7.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.TB_TID7.MouseHover += new System.EventHandler(this.UpdateTSV); + this.TB_TID7.Validated += new System.EventHandler(this.Update_ID); + // + // Label_SID + // + this.Label_SID.AutoSize = true; + this.Label_SID.Location = new System.Drawing.Point(3, 32); + this.Label_SID.Margin = new System.Windows.Forms.Padding(3, 6, 2, 0); + this.Label_SID.Name = "Label_SID"; + this.Label_SID.Size = new System.Drawing.Size(28, 13); + this.Label_SID.TabIndex = 8; + this.Label_SID.Text = "SID:"; + this.Label_SID.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // TB_SID + // + this.TB_SID.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.TB_SID.Location = new System.Drawing.Point(33, 29); + this.TB_SID.Margin = new System.Windows.Forms.Padding(0, 3, 3, 3); + this.TB_SID.Mask = "00000"; + this.TB_SID.Name = "TB_SID"; + this.TB_SID.Size = new System.Drawing.Size(40, 20); + this.TB_SID.TabIndex = 6; + this.TB_SID.Text = "12345"; + this.TB_SID.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.TB_SID.MouseHover += new System.EventHandler(this.UpdateTSV); + this.TB_SID.Validated += new System.EventHandler(this.Update_ID); + // + // TB_SID7 + // + this.TB_SID7.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.TB_SID7.Location = new System.Drawing.Point(76, 29); + this.TB_SID7.Margin = new System.Windows.Forms.Padding(0, 3, 3, 3); + this.TB_SID7.Mask = "0000"; + this.TB_SID7.Name = "TB_SID7"; + this.TB_SID7.Size = new System.Drawing.Size(30, 20); + this.TB_SID7.TabIndex = 10; + this.TB_SID7.Text = "1234"; + this.TB_SID7.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.TB_SID7.MouseHover += new System.EventHandler(this.UpdateTSV); + this.TB_SID7.Validated += new System.EventHandler(this.Update_ID); + // + // TrainerID + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.FLP); + this.Name = "TrainerID"; + this.Size = new System.Drawing.Size(125, 54); + this.FLP.ResumeLayout(false); + this.FLP.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.FlowLayoutPanel FLP; + private System.Windows.Forms.MaskedTextBox TB_SID; + private System.Windows.Forms.MaskedTextBox TB_TID; + private System.Windows.Forms.Label Label_SID; + private System.Windows.Forms.Label Label_TID; + private System.Windows.Forms.MaskedTextBox TB_TID7; + private System.Windows.Forms.MaskedTextBox TB_SID7; + } +} diff --git a/PKHeX.WinForms/Controls/PKM Editor/TrainerID.cs b/PKHeX.WinForms/Controls/PKM Editor/TrainerID.cs new file mode 100644 index 000000000..73aff7e55 --- /dev/null +++ b/PKHeX.WinForms/Controls/PKM Editor/TrainerID.cs @@ -0,0 +1,136 @@ +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 PKM pkm; + private readonly ToolTip TSVTooltip = new ToolTip(); + + public void UpdateTSV() + { + string IDstr = $"TSV: {pkm.TSV:d4}"; + TSVTooltip.SetToolTip(TB_TID, IDstr); + TSVTooltip.SetToolTip(TB_SID, IDstr); + TSVTooltip.SetToolTip(TB_TID7, IDstr); + TSVTooltip.SetToolTip(TB_SID7, IDstr); + } + public void LoadIDValues(PKM pk) + { + pkm = pk; + SetFormat(pkm.GenNumber); + LoadValues(); + } + public void UpdateSID() => LoadValues(); + public void LoadInfo(ITrainerInfo info) + { + pkm.TID = info.TID; + pkm.SID = info.SID; + LoadValues(); + } + + private void LoadValues() + { + if (Format <= 2) + TB_TID.Text = pkm.TID.ToString(); + else if (Format <= 6) + LoadTID(pkm.TID, pkm.SID); + else + LoadTID7(pkm.TID, pkm.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 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; + + var val = int.Parse(mt.Text); + if (mt == TB_TID7) + { + if (val > 999_999) + { + mt.Text = "999999"; + return; + } + SanityCheckSID7(val, int.Parse(TB_SID7.Text)); + } + else if (mt == TB_SID7) + { + if (val > 4294) // max 4 digits of 32bit int + { + mt.Text = "4294"; + return; + } + SanityCheckSID7(int.Parse(TB_TID7.Text), val); + } + else + { + if (val > ushort.MaxValue) // prior to gen7 + mt.Text = (val = ushort.MaxValue).ToString(); + + if (mt == TB_TID) + pkm.TID = val; + else + pkm.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; + } + + pkm.SID = (ushort)(repack >> 16); + pkm.TID = (ushort)repack; + } + } +} diff --git a/PKHeX.WinForms/Controls/PKM Editor/TrainerID.resx b/PKHeX.WinForms/Controls/PKM Editor/TrainerID.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/PKHeX.WinForms/Controls/PKM Editor/TrainerID.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PKHeX.WinForms/PKHeX.WinForms.csproj b/PKHeX.WinForms/PKHeX.WinForms.csproj index f5246c6c8..c50059b72 100644 --- a/PKHeX.WinForms/PKHeX.WinForms.csproj +++ b/PKHeX.WinForms/PKHeX.WinForms.csproj @@ -172,6 +172,12 @@ ShinyLeaf.cs + + UserControl + + + TrainerID.cs + UserControl @@ -594,6 +600,9 @@ ShinyLeaf.cs + + TrainerID.cs + BoxEditor.cs