From edb90839d0303c61f4b526fb98e7e86caf99a50e Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 11 May 2014 18:53:32 +0000 Subject: [PATCH] Dual GB XML Creator - a "Use Current Rom for all" button for the uberlazy --- .../config/GB/DualGBFileSelector.cs | 5 ++ .../tools/GB/DualGBXMLCreator.Designer.cs | 15 ++++++ .../tools/GB/DualGBXMLCreator.cs | 49 +++++++++++++------ 3 files changed, 53 insertions(+), 16 deletions(-) diff --git a/BizHawk.Client.EmuHawk/config/GB/DualGBFileSelector.cs b/BizHawk.Client.EmuHawk/config/GB/DualGBFileSelector.cs index 3a9bc24af6..fa2c825fcb 100644 --- a/BizHawk.Client.EmuHawk/config/GB/DualGBFileSelector.cs +++ b/BizHawk.Client.EmuHawk/config/GB/DualGBFileSelector.cs @@ -20,6 +20,11 @@ namespace BizHawk.Client.EmuHawk return textBox1.Text; } + public void SetName(string val) + { + textBox1.Text = val; + } + public event EventHandler NameChanged; private void HandleLabelTextChanged(object sender, EventArgs e) diff --git a/BizHawk.Client.EmuHawk/tools/GB/DualGBXMLCreator.Designer.cs b/BizHawk.Client.EmuHawk/tools/GB/DualGBXMLCreator.Designer.cs index 6f9a2c2c2b..1cc066773f 100644 --- a/BizHawk.Client.EmuHawk/tools/GB/DualGBXMLCreator.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/GB/DualGBXMLCreator.Designer.cs @@ -39,6 +39,7 @@ this.groupBox5 = new System.Windows.Forms.GroupBox(); this.textBoxXML = new System.Windows.Forms.TextBox(); this.SaveRunButton = new System.Windows.Forms.Button(); + this.CurrentForAllButton = new System.Windows.Forms.Button(); this.dualGBFileSelector2 = new BizHawk.Client.EmuHawk.DualGBFileSelector(); this.dualGBFileSelector1 = new BizHawk.Client.EmuHawk.DualGBFileSelector(); this.groupBox1.SuspendLayout(); @@ -104,6 +105,7 @@ this.buttonCancel.TabIndex = 7; this.buttonCancel.Text = "&Cancel"; this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); // // groupBox4 // @@ -167,6 +169,17 @@ this.SaveRunButton.UseVisualStyleBackColor = true; this.SaveRunButton.Click += new System.EventHandler(this.SaveRunButton_Click); // + // CurrentForAllButton + // + this.CurrentForAllButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.CurrentForAllButton.Location = new System.Drawing.Point(12, 477); + this.CurrentForAllButton.Name = "CurrentForAllButton"; + this.CurrentForAllButton.Size = new System.Drawing.Size(128, 23); + this.CurrentForAllButton.TabIndex = 9; + this.CurrentForAllButton.Text = "Use Current Rom for All"; + this.CurrentForAllButton.UseVisualStyleBackColor = true; + this.CurrentForAllButton.Click += new System.EventHandler(this.CurrentForAllButton_Click); + // // dualGBFileSelector2 // this.dualGBFileSelector2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) @@ -194,6 +207,7 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.buttonCancel; this.ClientSize = new System.Drawing.Size(456, 512); + this.Controls.Add(this.CurrentForAllButton); this.Controls.Add(this.SaveRunButton); this.Controls.Add(this.groupBox5); this.Controls.Add(this.groupBox4); @@ -232,5 +246,6 @@ private System.Windows.Forms.GroupBox groupBox5; private System.Windows.Forms.TextBox textBoxXML; private System.Windows.Forms.Button SaveRunButton; + private System.Windows.Forms.Button CurrentForAllButton; } } \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/GB/DualGBXMLCreator.cs b/BizHawk.Client.EmuHawk/tools/GB/DualGBXMLCreator.cs index 2568940916..849dd947f4 100644 --- a/BizHawk.Client.EmuHawk/tools/GB/DualGBXMLCreator.cs +++ b/BizHawk.Client.EmuHawk/tools/GB/DualGBXMLCreator.cs @@ -4,11 +4,15 @@ using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; +using BizHawk.Client.Common; +using BizHawk.Emulation.Cores.Nintendo.Gameboy; namespace BizHawk.Client.EmuHawk { public partial class DualGBXMLCreator : Form { + private bool _suspendRecalculate = false; + public DualGBXMLCreator() { InitializeComponent(); @@ -51,8 +55,13 @@ namespace BizHawk.Client.EmuHawk throw new FileNotFoundException(); } - bool Recalculate() + private bool Recalculate() { + if (_suspendRecalculate) + { + return false; + } + try { var PathLeft = dualGBFileSelector1.GetName(); @@ -130,23 +139,13 @@ namespace BizHawk.Client.EmuHawk Recalculate(); } - private void buttonOK_Click(object sender, EventArgs e) - { - if (Recalculate()) - { - using (var sw = new StreamWriter(textBoxOutputDir.Text)) - { - sw.Write(textBoxXML.Text); - } - - DialogResult = DialogResult.OK; - Close(); - } - } - private void DualGBXMLCreator_Load(object sender, EventArgs e) { - + CurrentForAllButton.Enabled = Global.Emulator != null && // For the designer + (Global.Emulator is Gameboy) && + !string.IsNullOrEmpty(GlobalWin.MainForm.CurrentlyOpenRom) && + !GlobalWin.MainForm.CurrentlyOpenRom.Contains('|') && // Can't be archive + !GlobalWin.MainForm.CurrentlyOpenRom.Contains(".xml"); // Can't already be an xml } private void SaveRunButton_Click(object sender, EventArgs e) @@ -163,5 +162,23 @@ namespace BizHawk.Client.EmuHawk GlobalWin.MainForm.LoadRom(textBoxOutputDir.Text); } } + + private void CurrentForAllButton_Click(object sender, EventArgs e) + { + _suspendRecalculate = true; + dualGBFileSelector1.SetName(GlobalWin.MainForm.CurrentlyOpenRom); + dualGBFileSelector2.SetName(GlobalWin.MainForm.CurrentlyOpenRom); + + textBoxName.Text = Path.GetFileNameWithoutExtension(GlobalWin.MainForm.CurrentlyOpenRom); + _suspendRecalculate = false; + + Recalculate(); + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } } }