From ee8e5c9db13129c8af676a0bc4d199e5caa23b44 Mon Sep 17 00:00:00 2001 From: Yako Date: Thu, 24 Jul 2025 22:40:28 +0200 Subject: [PATCH] trade editor complete except for adding / removing trades --- DS_Map/Editors/TradeEditor.Designer.cs | 99 +++++-- DS_Map/Editors/TradeEditor.cs | 376 ++++++++++++++++++------- 2 files changed, 347 insertions(+), 128 deletions(-) diff --git a/DS_Map/Editors/TradeEditor.Designer.cs b/DS_Map/Editors/TradeEditor.Designer.cs index 645291b..454e2b4 100644 --- a/DS_Map/Editors/TradeEditor.Designer.cs +++ b/DS_Map/Editors/TradeEditor.Designer.cs @@ -30,13 +30,14 @@ { this.components = new System.ComponentModel.Container(); this.mainPanel = new System.Windows.Forms.Panel(); + this.saveAllButton = new System.Windows.Forms.Button(); this.saveTextDataButton = new System.Windows.Forms.Button(); this.saveTradeButton = new System.Windows.Forms.Button(); this.textDataGroupBox = new System.Windows.Forms.GroupBox(); this.nicknameTextBox = new System.Windows.Forms.TextBox(); this.otNameTextBox = new System.Windows.Forms.TextBox(); this.nicknameLabel = new System.Windows.Forms.Label(); - this.label1 = new System.Windows.Forms.Label(); + this.otNameLabel = new System.Windows.Forms.Label(); this.tradeDataGroupBox = new System.Windows.Forms.GroupBox(); this.requestedComboBox = new System.Windows.Forms.ComboBox(); this.requestedLabel = new System.Windows.Forms.Label(); @@ -87,6 +88,8 @@ this.tradeIDNumericUpDown = new System.Windows.Forms.NumericUpDown(); this.tradeIDLabel = new System.Windows.Forms.Label(); this.toolTip = new System.Windows.Forms.ToolTip(this.components); + this.addFileButton = new System.Windows.Forms.Button(); + this.removeLastButton = new System.Windows.Forms.Button(); this.mainPanel.SuspendLayout(); this.textDataGroupBox.SuspendLayout(); this.tradeDataGroupBox.SuspendLayout(); @@ -114,6 +117,9 @@ // // mainPanel // + this.mainPanel.Controls.Add(this.removeLastButton); + this.mainPanel.Controls.Add(this.saveAllButton); + this.mainPanel.Controls.Add(this.addFileButton); this.mainPanel.Controls.Add(this.saveTextDataButton); this.mainPanel.Controls.Add(this.saveTradeButton); this.mainPanel.Controls.Add(this.textDataGroupBox); @@ -123,28 +129,42 @@ this.mainPanel.Size = new System.Drawing.Size(624, 444); this.mainPanel.TabIndex = 0; // + // saveAllButton + // + this.saveAllButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.saveAllButton.Image = global::DSPRE.Properties.Resources.saveButton; + this.saveAllButton.ImageAlign = System.Drawing.ContentAlignment.TopCenter; + this.saveAllButton.Location = new System.Drawing.Point(470, 389); + this.saveAllButton.Name = "saveAllButton"; + this.saveAllButton.Size = new System.Drawing.Size(147, 47); + this.saveAllButton.TabIndex = 6; + this.saveAllButton.Text = "Save All"; + this.saveAllButton.TextAlign = System.Drawing.ContentAlignment.BottomCenter; + this.saveAllButton.UseVisualStyleBackColor = true; + this.saveAllButton.Click += new System.EventHandler(this.saveAllButton_Click); + // // saveTextDataButton // this.saveTextDataButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.saveTextDataButton.Image = global::DSPRE.Properties.Resources.saveButton; - this.saveTextDataButton.ImageAlign = System.Drawing.ContentAlignment.MiddleRight; - this.saveTextDataButton.Location = new System.Drawing.Point(479, 156); + this.saveTextDataButton.ImageAlign = System.Drawing.ContentAlignment.TopCenter; + this.saveTextDataButton.Location = new System.Drawing.Point(479, 142); this.saveTextDataButton.Name = "saveTextDataButton"; - this.saveTextDataButton.Size = new System.Drawing.Size(126, 44); + this.saveTextDataButton.Size = new System.Drawing.Size(126, 40); this.saveTextDataButton.TabIndex = 5; this.saveTextDataButton.Text = "Save Text Data"; - this.saveTextDataButton.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.saveTextDataButton.TextAlign = System.Drawing.ContentAlignment.BottomCenter; this.saveTextDataButton.UseVisualStyleBackColor = true; this.saveTextDataButton.Click += new System.EventHandler(this.saveTextDataButton_Click); // // saveTradeButton // - this.saveTradeButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.saveTradeButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.saveTradeButton.Image = global::DSPRE.Properties.Resources.saveButton; this.saveTradeButton.ImageAlign = System.Drawing.ContentAlignment.TopCenter; - this.saveTradeButton.Location = new System.Drawing.Point(470, 383); + this.saveTradeButton.Location = new System.Drawing.Point(480, 342); this.saveTradeButton.Name = "saveTradeButton"; - this.saveTradeButton.Size = new System.Drawing.Size(147, 47); + this.saveTradeButton.Size = new System.Drawing.Size(126, 40); this.saveTradeButton.TabIndex = 4; this.saveTradeButton.Text = "Save Trade Data"; this.saveTradeButton.TextAlign = System.Drawing.ContentAlignment.BottomCenter; @@ -156,11 +176,11 @@ this.textDataGroupBox.Controls.Add(this.nicknameTextBox); this.textDataGroupBox.Controls.Add(this.otNameTextBox); this.textDataGroupBox.Controls.Add(this.nicknameLabel); - this.textDataGroupBox.Controls.Add(this.label1); + this.textDataGroupBox.Controls.Add(this.otNameLabel); this.textDataGroupBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.textDataGroupBox.Location = new System.Drawing.Point(470, 3); this.textDataGroupBox.Name = "textDataGroupBox"; - this.textDataGroupBox.Size = new System.Drawing.Size(147, 147); + this.textDataGroupBox.Size = new System.Drawing.Size(147, 133); this.textDataGroupBox.TabIndex = 3; this.textDataGroupBox.TabStop = false; this.textDataGroupBox.Text = "Text Data"; @@ -189,15 +209,15 @@ this.nicknameLabel.TabIndex = 15; this.nicknameLabel.Text = "Pokémon Nickname"; // - // label1 + // otNameLabel // - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label1.Location = new System.Drawing.Point(6, 25); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(66, 16); - this.label1.TabIndex = 13; - this.label1.Text = "OT Name"; + this.otNameLabel.AutoSize = true; + this.otNameLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.otNameLabel.Location = new System.Drawing.Point(6, 25); + this.otNameLabel.Name = "otNameLabel"; + this.otNameLabel.Size = new System.Drawing.Size(66, 16); + this.otNameLabel.TabIndex = 13; + this.otNameLabel.Text = "OT Name"; // // tradeDataGroupBox // @@ -220,6 +240,7 @@ // // requestedComboBox // + this.requestedComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; this.requestedComboBox.FormattingEnabled = true; this.requestedComboBox.Location = new System.Drawing.Point(165, 44); this.requestedComboBox.Name = "requestedComboBox"; @@ -305,6 +326,7 @@ // // abilityComboBox // + this.abilityComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; this.abilityComboBox.FormattingEnabled = true; this.abilityComboBox.Location = new System.Drawing.Point(6, 218); this.abilityComboBox.Name = "abilityComboBox"; @@ -317,9 +339,9 @@ this.abilityLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.abilityLabel.Location = new System.Drawing.Point(3, 198); this.abilityLabel.Name = "abilityLabel"; - this.abilityLabel.Size = new System.Drawing.Size(43, 16); + this.abilityLabel.Size = new System.Drawing.Size(101, 16); this.abilityLabel.TabIndex = 27; - this.abilityLabel.Text = "Ability"; + this.abilityLabel.Text = "Ability (Unused)"; // // unknownNumericUpDown // @@ -359,6 +381,7 @@ // // langComboBox // + this.langComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; this.langComboBox.FormattingEnabled = true; this.langComboBox.Location = new System.Drawing.Point(6, 166); this.langComboBox.Name = "langComboBox"; @@ -377,6 +400,7 @@ // // heldItemComboBox // + this.heldItemComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; this.heldItemComboBox.FormattingEnabled = true; this.heldItemComboBox.Location = new System.Drawing.Point(6, 98); this.heldItemComboBox.Name = "heldItemComboBox"; @@ -641,6 +665,7 @@ // // speciesComboBox // + this.speciesComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; this.speciesComboBox.FormattingEnabled = true; this.speciesComboBox.Location = new System.Drawing.Point(6, 30); this.speciesComboBox.Name = "speciesComboBox"; @@ -676,6 +701,34 @@ this.tradeIDLabel.TabIndex = 1; this.tradeIDLabel.Text = "Trade ID"; // + // addFileButton + // + this.addFileButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.addFileButton.Image = global::DSPRE.Properties.Resources.addIcon; + this.addFileButton.ImageAlign = System.Drawing.ContentAlignment.TopCenter; + this.addFileButton.Location = new System.Drawing.Point(480, 242); + this.addFileButton.Name = "addFileButton"; + this.addFileButton.Size = new System.Drawing.Size(126, 40); + this.addFileButton.TabIndex = 13; + this.addFileButton.Text = "Add File"; + this.addFileButton.TextAlign = System.Drawing.ContentAlignment.BottomCenter; + this.addFileButton.UseVisualStyleBackColor = true; + this.addFileButton.Click += new System.EventHandler(this.addFileButton_Click); + // + // removeLastButton + // + this.removeLastButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.removeLastButton.Image = global::DSPRE.Properties.Resources.deleteIcon; + this.removeLastButton.ImageAlign = System.Drawing.ContentAlignment.TopCenter; + this.removeLastButton.Location = new System.Drawing.Point(480, 292); + this.removeLastButton.Name = "removeLastButton"; + this.removeLastButton.Size = new System.Drawing.Size(126, 40); + this.removeLastButton.TabIndex = 14; + this.removeLastButton.Text = "Remove Last"; + this.removeLastButton.TextAlign = System.Drawing.ContentAlignment.BottomCenter; + this.removeLastButton.UseVisualStyleBackColor = true; + this.removeLastButton.Click += new System.EventHandler(this.removeLastButton_Click); + // // TradeEditor // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -684,6 +737,7 @@ this.Controls.Add(this.mainPanel); this.Name = "TradeEditor"; this.Text = "TradeEditor"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TradeEditor_FormClosing); this.mainPanel.ResumeLayout(false); this.textDataGroupBox.ResumeLayout(false); this.textDataGroupBox.PerformLayout(); @@ -774,7 +828,10 @@ private System.Windows.Forms.TextBox nicknameTextBox; private System.Windows.Forms.TextBox otNameTextBox; private System.Windows.Forms.Label nicknameLabel; - private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label otNameLabel; private System.Windows.Forms.Button saveTextDataButton; + private System.Windows.Forms.Button saveAllButton; + private System.Windows.Forms.Button addFileButton; + private System.Windows.Forms.Button removeLastButton; } } \ No newline at end of file diff --git a/DS_Map/Editors/TradeEditor.cs b/DS_Map/Editors/TradeEditor.cs index d6daef4..931c01b 100644 --- a/DS_Map/Editors/TradeEditor.cs +++ b/DS_Map/Editors/TradeEditor.cs @@ -17,6 +17,10 @@ namespace DSPRE.Editors private TradeData curTradeData; private TextArchive tradeArchive; + // Track if any changes have been made + private bool tradeDirty = false; + private bool textDirty = false; + #region Enums public enum OriginLang { @@ -40,6 +44,7 @@ namespace DSPRE.Editors InitLimits(); InitDataRanges(); SetToolTips(); + RegisterMarkDirtyHandlers(); if (TradeData.GetTradeCount() == 0) { @@ -53,78 +58,14 @@ namespace DSPRE.Editors unknownNumericUpDown.Enabled = false; } + // Disable buttons until trade expansion is implemented + addFileButton.Enabled = false; + removeLastButton.Enabled = false; + tradeArchive = new TextArchive(GetTextBankIndex()); LoadFromFile(0); } - public void LoadFromFile(int tradeID) - { - Helpers.DisableHandlers(); - curTradeData = new TradeData(tradeID); - tradeIDNumericUpDown.Value = tradeID; - speciesComboBox.SelectedIndex = curTradeData.species; - hpIVNumericUpDown.Value = curTradeData.hpIV; - atkIVNumericUpDown.Value = curTradeData.atkIV; - defIVNumericUpDown.Value = curTradeData.defIV; - speIVNumericUpDown.Value = curTradeData.speedIV; - spaIVNumericUpDown.Value = curTradeData.spAtkIV; - spdIVNumericUpDown.Value = curTradeData.spDefIV; - abilityComboBox.SelectedIndex = curTradeData.ability; - otIDNumericUpDown.Value = curTradeData.otID; - coolNumericUpDown.Value = curTradeData.cool; - beautyNumericUpDown.Value = curTradeData.beauty; - cuteNumericUpDown.Value = curTradeData.cute; - smartNumericUpDown.Value = curTradeData.smart; - toughNumericUpDown.Value = curTradeData.tough; - pidNumericUpDown.Value = curTradeData.pid; - heldItemComboBox.SelectedIndex = curTradeData.heldItem; - otGenderComboBox.SelectedIndex = curTradeData.otGender; - sheenNumericUpDown.Value = curTradeData.sheen; - langComboBox.SelectedIndex = curTradeData.language; - requestedComboBox.SelectedIndex = curTradeData.requestedSpecies; - unknownNumericUpDown.Value = curTradeData.unknown; - - otNameTextBox.Text = GetOTName(tradeID); - nicknameTextBox.Text = GetMonNickname(tradeID); - - Helpers.EnableHandlers(); - } - - private void SaveToFile() - { - curTradeData.species = speciesComboBox.SelectedIndex; - curTradeData.hpIV = (int)hpIVNumericUpDown.Value; - curTradeData.atkIV = (int)atkIVNumericUpDown.Value; - curTradeData.defIV = (int)defIVNumericUpDown.Value; - curTradeData.speedIV = (int)speIVNumericUpDown.Value; - curTradeData.spAtkIV = (int)spaIVNumericUpDown.Value; - curTradeData.spDefIV = (int)spdIVNumericUpDown.Value; - curTradeData.ability = abilityComboBox.SelectedIndex; - curTradeData.otID = (int)otIDNumericUpDown.Value; - curTradeData.cool = (int)coolNumericUpDown.Value; - curTradeData.beauty = (int)beautyNumericUpDown.Value; - curTradeData.cute = (int)cuteNumericUpDown.Value; - curTradeData.smart = (int)smartNumericUpDown.Value; - curTradeData.tough = (int)toughNumericUpDown.Value; - curTradeData.pid = (int)pidNumericUpDown.Value; - curTradeData.heldItem = heldItemComboBox.SelectedIndex; - curTradeData.otGender = otGenderComboBox.SelectedIndex; - curTradeData.sheen = (int)sheenNumericUpDown.Value; - curTradeData.language = langComboBox.SelectedIndex; - curTradeData.requestedSpecies = requestedComboBox.SelectedIndex; - - if (RomInfo.gameFamily == RomInfo.GameFamilies.HGSS) - { - curTradeData.unknown = (int)unknownNumericUpDown.Value; - } - else - { - curTradeData.unknown = 0; - } - - curTradeData.SaveToFileDefaultDir((int)tradeIDNumericUpDown.Value, true); - } - private void InitLimits() { // IVs: 0-31 @@ -167,7 +108,7 @@ namespace DSPRE.Editors // Trade ID: (dynamic based on loaded data) tradeIDNumericUpDown.Minimum = 0; - tradeIDNumericUpDown.Maximum = TradeData.GetTradeCount()-1; + tradeIDNumericUpDown.Maximum = TradeData.GetTradeCount() - 1; // OT ID: (32-bit unsigned) otIDNumericUpDown.Minimum = 0; @@ -191,7 +132,7 @@ namespace DSPRE.Editors heldItemComboBox.DataSource = RomInfo.GetItemNames(); // OT Gender - otGenderComboBox.DataSource = new string[] {"Male", "Female"}; + otGenderComboBox.DataSource = new string[] { "Male", "Female" }; // Languages langComboBox.DataSource = Enum.GetNames(typeof(OriginLang)); @@ -199,42 +140,143 @@ namespace DSPRE.Editors private void SetToolTips() { - toolTip.SetToolTip(tradeIDNumericUpDown, "The Trade ID to edit."); - toolTip.SetToolTip(speciesComboBox, "The species of the Pokémon being traded."); - toolTip.SetToolTip(IVGroupBox, "Individual Values (IVs)"); - toolTip.SetToolTip(abilityComboBox, "The ability of the Pokémon.\nThis value is unused!"); - toolTip.SetToolTip(otIDNumericUpDown, "The Original Trainer ID of the Pokémon."); - toolTip.SetToolTip(contestGroupBox, "Contest stats for the Pokémon."); - toolTip.SetToolTip(pidNumericUpDown, "The PID of the Pokémon."); - toolTip.SetToolTip(heldItemComboBox, "The held item of the Pokémon."); - toolTip.SetToolTip(otGenderComboBox, "The gender of the Original Trainer (OT).\nThe OT name is determined by the text bank."); - toolTip.SetToolTip(langComboBox, "The language of origin of the traded Pokémon."); - toolTip.SetToolTip(requestedComboBox, "The species of the requested Pokémon.\nWhether the Pokémon selected by the player matches this species or not is checked via scripting."); - toolTip.SetToolTip(unknownNumericUpDown, "An unknown value, present in HGSS only.\nAppears to be unused."); - + SetToolTipsForControls(new Control[] { tradeIDNumericUpDown, tradeIDLabel }, "The Trade ID to edit."); + SetToolTipsForControls(new Control[] { speciesComboBox, speciesLabel }, "The species of the Pokémon being traded."); + SetToolTipsForControls(new Control[] { IVGroupBox }, "Individual Values (IVs)"); + SetToolTipsForControls(new Control[] { abilityComboBox, abilityLabel }, "The ability of the Pokémon.\nThis value is unused and will have no effect!"); + SetToolTipsForControls(new Control[] { otIDNumericUpDown, otIDLabel }, "The Original Trainer ID of the Pokémon."); + SetToolTipsForControls(new Control[] { contestGroupBox }, "Contest stats for the Pokémon."); + SetToolTipsForControls(new Control[] { pidNumericUpDown, pidLabel }, "The PID of the Pokémon.\nDetermines ability and nature."); + SetToolTipsForControls(new Control[] { heldItemComboBox, heldItemLabel }, "The held item of the Pokémon."); + SetToolTipsForControls(new Control[] { otGenderComboBox, otGenderLabel }, "The gender of the Original Trainer (OT).\nThe OT name is determined by the text bank."); + SetToolTipsForControls(new Control[] { langComboBox, langLabel }, "The language of origin of the traded Pokémon."); + SetToolTipsForControls(new Control[] { requestedComboBox, requestedLabel }, "The species of the requested Pokémon.\nWhether the Pokémon selected by the player matches this species or not is checked via scripting."); + SetToolTipsForControls(new Control[] { unknownNumericUpDown, unknownLabel }, "An unknown value, present in HGSS only.\nAppears to be unused."); + SetToolTipsForControls(new Control[] { otNameTextBox, otNameLabel }, + $"The Original Trainer's name.\nStored in text bank {GetTextBankIndex()}.\nAt most {otNameTextBox.MaxLength} characters."); + SetToolTipsForControls(new Control[] { nicknameTextBox, nicknameLabel }, + $"The nickname of the Pokémon.\nStored in text bank {GetTextBankIndex()}.\nAt most {nicknameTextBox.MaxLength} characters."); } - private void tradeIDNumericUpDown_ValueChanged(object sender, EventArgs e) + private void SetToolTipsForControls(IEnumerable controls, string text) { - if (Helpers.HandlersDisabled) + foreach (var control in controls) { - return; + toolTip.SetToolTip(control, text); + } + } + + public void LoadFromFile(int tradeID) + { + Helpers.DisableHandlers(); + curTradeData = new TradeData(tradeID); + tradeIDNumericUpDown.Value = tradeID; + speciesComboBox.SelectedIndex = curTradeData.species; + hpIVNumericUpDown.Value = curTradeData.hpIV; + atkIVNumericUpDown.Value = curTradeData.atkIV; + defIVNumericUpDown.Value = curTradeData.defIV; + speIVNumericUpDown.Value = curTradeData.speedIV; + spaIVNumericUpDown.Value = curTradeData.spAtkIV; + spdIVNumericUpDown.Value = curTradeData.spDefIV; + abilityComboBox.SelectedIndex = curTradeData.ability; + otIDNumericUpDown.Value = curTradeData.otID; + coolNumericUpDown.Value = curTradeData.cool; + beautyNumericUpDown.Value = curTradeData.beauty; + cuteNumericUpDown.Value = curTradeData.cute; + smartNumericUpDown.Value = curTradeData.smart; + toughNumericUpDown.Value = curTradeData.tough; + pidNumericUpDown.Value = curTradeData.pid; + heldItemComboBox.SelectedIndex = curTradeData.heldItem; + otGenderComboBox.SelectedIndex = curTradeData.otGender; + sheenNumericUpDown.Value = curTradeData.sheen; + langComboBox.SelectedIndex = curTradeData.language; + requestedComboBox.SelectedIndex = curTradeData.requestedSpecies; + unknownNumericUpDown.Value = curTradeData.unknown; + + otNameTextBox.Text = GetOTName(tradeID); + nicknameTextBox.Text = GetMonNickname(tradeID); + tradeDataGroupBox.Text = "Trade Data"; + textDataGroupBox.Text = "Text Data"; + this.Text = "Trade Editor"; + + tradeDirty = false; + textDirty = false; + + Helpers.EnableHandlers(); + } + + private void SaveTradeToFile() + { + Helpers.DisableHandlers(); + curTradeData.species = speciesComboBox.SelectedIndex; + curTradeData.hpIV = (int)hpIVNumericUpDown.Value; + curTradeData.atkIV = (int)atkIVNumericUpDown.Value; + curTradeData.defIV = (int)defIVNumericUpDown.Value; + curTradeData.speedIV = (int)speIVNumericUpDown.Value; + curTradeData.spAtkIV = (int)spaIVNumericUpDown.Value; + curTradeData.spDefIV = (int)spdIVNumericUpDown.Value; + curTradeData.ability = abilityComboBox.SelectedIndex; + curTradeData.otID = (int)otIDNumericUpDown.Value; + curTradeData.cool = (int)coolNumericUpDown.Value; + curTradeData.beauty = (int)beautyNumericUpDown.Value; + curTradeData.cute = (int)cuteNumericUpDown.Value; + curTradeData.smart = (int)smartNumericUpDown.Value; + curTradeData.tough = (int)toughNumericUpDown.Value; + curTradeData.pid = (int)pidNumericUpDown.Value; + curTradeData.heldItem = heldItemComboBox.SelectedIndex; + curTradeData.otGender = otGenderComboBox.SelectedIndex; + curTradeData.sheen = (int)sheenNumericUpDown.Value; + curTradeData.language = langComboBox.SelectedIndex; + curTradeData.requestedSpecies = requestedComboBox.SelectedIndex; + + if (RomInfo.gameFamily == RomInfo.GameFamilies.HGSS) + { + curTradeData.unknown = (int)unknownNumericUpDown.Value; + } + else + { + curTradeData.unknown = 0; } + curTradeData.SaveToFileDefaultDir((int)tradeIDNumericUpDown.Value, false); + tradeDataGroupBox.Text = "Trade Data"; + tradeDirty = false; + if (!textDirty) + { + this.Text = "Trade Editor"; + } + Helpers.EnableHandlers(); + } + + private void SaveTextDataToFile() + { + Helpers.DisableHandlers(); int tradeID = (int)tradeIDNumericUpDown.Value; - if (tradeID < 0 || tradeID >= TradeData.GetTradeCount()) + + if (tradeID < 0 || tradeID + TradeData.GetTradeCount() > tradeArchive.messages.Count) { - MessageBox.Show("Invalid Trade ID selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Can't save to text bank. Index is out of range.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + AppLogger.Error("TradeEditor: Can't save to text bank. Index is out of range."); + Helpers.EnableHandlers(); return; } - LoadFromFile(tradeID); + // Nickname + tradeArchive.messages[tradeID] = nicknameTextBox.Text; - } + // OT Name + tradeArchive.messages[tradeID + TradeData.GetTradeCount()] = otNameTextBox.Text; - private void saveTradeButton_Click(object sender, EventArgs e) - { - SaveToFile(); + tradeArchive.SaveToFileDefaultDir(GetTextBankIndex(), false); + + // Reset the text data group box and dirty flags + textDataGroupBox.Text = "Text Data"; + textDirty = false; + if (!tradeDirty) + { + this.Text = "Trade Editor"; + } + Helpers.EnableHandlers(); } private int GetTextBankIndex() @@ -270,7 +312,7 @@ namespace DSPRE.Editors MessageBox.Show("Invalid game family for text bank index retrieval.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return 0; } - + } private string GetMonNickname(int tradeID) { @@ -291,29 +333,149 @@ namespace DSPRE.Editors msg = msg.Substring(0, otNameTextBox.MaxLength); } return msg; - } + } - private void saveTextDataButton_Click(object sender, EventArgs e) + private void RegisterMarkDirtyHandlers() { - Helpers.DisableHandlers(); - int tradeID = (int)tradeIDNumericUpDown.Value; + // ComboBoxes + speciesComboBox.SelectedIndexChanged += MarkDirty; + abilityComboBox.SelectedIndexChanged += MarkDirty; + heldItemComboBox.SelectedIndexChanged += MarkDirty; + otGenderComboBox.SelectedIndexChanged += MarkDirty; + langComboBox.SelectedIndexChanged += MarkDirty; + requestedComboBox.SelectedIndexChanged += MarkDirty; - if (tradeID < 0 || tradeID + TradeData.GetTradeCount() > tradeArchive.messages.Count) + // NumericUpDowns + hpIVNumericUpDown.ValueChanged += MarkDirty; + atkIVNumericUpDown.ValueChanged += MarkDirty; + defIVNumericUpDown.ValueChanged += MarkDirty; + speIVNumericUpDown.ValueChanged += MarkDirty; + spaIVNumericUpDown.ValueChanged += MarkDirty; + spdIVNumericUpDown.ValueChanged += MarkDirty; + otIDNumericUpDown.ValueChanged += MarkDirty; + coolNumericUpDown.ValueChanged += MarkDirty; + beautyNumericUpDown.ValueChanged += MarkDirty; + cuteNumericUpDown.ValueChanged += MarkDirty; + smartNumericUpDown.ValueChanged += MarkDirty; + toughNumericUpDown.ValueChanged += MarkDirty; + pidNumericUpDown.ValueChanged += MarkDirty; + sheenNumericUpDown.ValueChanged += MarkDirty; + unknownNumericUpDown.ValueChanged += MarkDirty; + + // TextBoxes + otNameTextBox.TextChanged += MarkDirty; + nicknameTextBox.TextChanged += MarkDirty; + } + + #region Handlers + + private void MarkDirty(object sender, EventArgs e) + { + if (Helpers.HandlersDisabled) { - MessageBox.Show("Can't save to text bank. Index is out of range.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - AppLogger.Error("TradeEditor: Can't save to text bank. Index is out of range."); - Helpers.EnableHandlers(); return; } - // Nickname - tradeArchive.messages[tradeID] = nicknameTextBox.Text; + Helpers.DisableHandlers(); - // OT Name - tradeArchive.messages[tradeID + TradeData.GetTradeCount()] = otNameTextBox.Text; + if (sender.Equals(otNameTextBox) || sender.Equals(nicknameTextBox)) + { + textDataGroupBox.Text = "Text Data*"; + this.Text = "Trade Editor*"; + textDirty = true; + } + else + { + tradeDataGroupBox.Text = "Trade Data*"; + this.Text = "Trade Editor*"; + tradeDirty = true; + } - tradeArchive.SaveToFileDefaultDir(GetTextBankIndex(), false); Helpers.EnableHandlers(); } + + private void tradeIDNumericUpDown_ValueChanged(object sender, EventArgs e) + { + if (Helpers.HandlersDisabled) + { + return; + } + + Helpers.DisableHandlers(); + + if (tradeDirty || textDirty) + { + DialogResult result = MessageBox.Show("You have unsaved changes. Do you want to save before changing the Trade ID?", "Unsaved Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); + if (result == DialogResult.Yes) + { + SaveTradeToFile(); + SaveTextDataToFile(); + } + else if (result == DialogResult.Cancel) + { + // Revert the change + tradeIDNumericUpDown.Value = curTradeData.id; + Helpers.EnableHandlers(); + return; + } + } + + int tradeID = (int)tradeIDNumericUpDown.Value; + if (tradeID < 0 || tradeID >= TradeData.GetTradeCount()) + { + MessageBox.Show("Invalid Trade ID selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + LoadFromFile(tradeID); + + Helpers.EnableHandlers(); + + } + + private void saveTradeButton_Click(object sender, EventArgs e) + { + SaveTradeToFile(); + } + + private void saveTextDataButton_Click(object sender, EventArgs e) + { + SaveTextDataToFile(); + } + + private void saveAllButton_Click(object sender, EventArgs e) + { + SaveTradeToFile(); + SaveTextDataToFile(); + } + + private void TradeEditor_FormClosing(object sender, FormClosingEventArgs e) + { + if (tradeDirty || textDirty) + { + DialogResult result = MessageBox.Show("You have unsaved changes. Do you want to save before closing?", "Unsaved Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); + if (result == DialogResult.Yes) + { + SaveTradeToFile(); + SaveTextDataToFile(); + } + else if (result == DialogResult.Cancel) + { + e.Cancel = true; // Cancel the closing + } + } + } + + #endregion + + private void addFileButton_Click(object sender, EventArgs e) + { + + } + + private void removeLastButton_Click(object sender, EventArgs e) + { + + } } }