From 32b4f940a91925721923e9b14bbecfca22719cfc Mon Sep 17 00:00:00 2001 From: adelikat Date: Mon, 14 Apr 2014 01:59:57 +0000 Subject: [PATCH] Add a Platform Chooser that activates when the user attempts to load a .bin file that is not in the game database. Still todo: more platforms, and interim flag logic on some unreleased cores --- BizHawk.Client.Common/RomLoader.cs | 7 + .../BizHawk.Client.EmuHawk.csproj | 9 ++ BizHawk.Client.EmuHawk/MainForm.cs | 12 ++ .../PlatformChooser.Designer.cs | 130 ++++++++++++++++++ BizHawk.Client.EmuHawk/PlatformChooser.cs | 92 +++++++++++++ BizHawk.Client.EmuHawk/PlatformChooser.resx | 120 ++++++++++++++++ BizHawk.Emulation.Common/Database/Database.cs | 2 +- 7 files changed, 371 insertions(+), 1 deletion(-) create mode 100644 BizHawk.Client.EmuHawk/PlatformChooser.Designer.cs create mode 100644 BizHawk.Client.EmuHawk/PlatformChooser.cs create mode 100644 BizHawk.Client.EmuHawk/PlatformChooser.resx diff --git a/BizHawk.Client.Common/RomLoader.cs b/BizHawk.Client.Common/RomLoader.cs index 981a69858d..44038a410a 100644 --- a/BizHawk.Client.Common/RomLoader.cs +++ b/BizHawk.Client.Common/RomLoader.cs @@ -99,6 +99,8 @@ namespace BizHawk.Client.Common public Func ChooseArchive { get; set; } + public Func ChoosePlatform { get; set; } + private int? HandleArchive(HawkFile file) { if (ChooseArchive != null) @@ -263,6 +265,11 @@ namespace BizHawk.Client.Common else // most extensions { rom = new RomGame(file); + if (string.IsNullOrEmpty(rom.GameInfo.System) && ChoosePlatform != null) + { + rom.GameInfo.System = ChoosePlatform(rom); + } + game = rom.GameInfo; var isXml = false; diff --git a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj index 0c1e57ac5c..3f38833a9e 100644 --- a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj +++ b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj @@ -467,6 +467,12 @@ NameStateForm.cs + + Form + + + PlatformChooser.cs + @@ -1016,6 +1022,9 @@ NameStateForm.cs Designer + + PlatformChooser.cs + ResXFileCodeGenerator Designer diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index d3d8239d19..246c800694 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -2783,6 +2783,17 @@ namespace BizHawk.Client.EmuHawk GlobalWin.OSD.AddMessage(message); } + private string ChoosePlatformForRom(RomGame rom) + { + var platformChooser = new PlatformChooser() + { + RomGame = rom + }; + + platformChooser.ShowDialog(); + return platformChooser.PlatformChoice; + } + // Still needs a good bit of refactoring public bool LoadRom(string path, bool deterministicemulation = false, bool hasmovie = false) { @@ -2794,6 +2805,7 @@ namespace BizHawk.Client.EmuHawk var loader = new RomLoader { ChooseArchive = LoadArhiveChooser, + ChoosePlatform = ChoosePlatformForRom }; loader.OnLoadError += ShowLoadError; diff --git a/BizHawk.Client.EmuHawk/PlatformChooser.Designer.cs b/BizHawk.Client.EmuHawk/PlatformChooser.Designer.cs new file mode 100644 index 0000000000..1f8c5708a5 --- /dev/null +++ b/BizHawk.Client.EmuHawk/PlatformChooser.Designer.cs @@ -0,0 +1,130 @@ +namespace BizHawk.Client.EmuHawk +{ + partial class PlatformChooser + { + /// + /// 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 Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBox1 = new System.Windows.Forms.TextBox(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.OkBtn = new System.Windows.Forms.Button(); + this.CancelBtn = new System.Windows.Forms.Button(); + this.PlatformsGroupBox = new System.Windows.Forms.Panel(); + this.SuspendLayout(); + // + // textBox1 + // + this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.textBox1.Location = new System.Drawing.Point(12, 12); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.ReadOnly = true; + this.textBox1.Size = new System.Drawing.Size(333, 56); + this.textBox1.TabIndex = 2; + this.textBox1.Text = "This Rom was not found in the database. Further more, the extension (*.bin) leav" + + "es no clue as to which platform should be chosen."; + // + // textBox2 + // + this.textBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.textBox2.Location = new System.Drawing.Point(12, 74); + this.textBox2.Multiline = true; + this.textBox2.Name = "textBox2"; + this.textBox2.ReadOnly = true; + this.textBox2.Size = new System.Drawing.Size(333, 41); + this.textBox2.TabIndex = 3; + this.textBox2.Text = "Please choose the intended platform to use for this Rom"; + // + // OkBtn + // + this.OkBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.OkBtn.Location = new System.Drawing.Point(219, 439); + this.OkBtn.Name = "OkBtn"; + this.OkBtn.Size = new System.Drawing.Size(60, 23); + this.OkBtn.TabIndex = 4; + this.OkBtn.Text = "&Ok"; + this.OkBtn.UseVisualStyleBackColor = true; + this.OkBtn.Click += new System.EventHandler(this.OkBtn_Click); + // + // CancelBtn + // + this.CancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.CancelBtn.Location = new System.Drawing.Point(285, 439); + this.CancelBtn.Name = "CancelBtn"; + this.CancelBtn.Size = new System.Drawing.Size(60, 23); + this.CancelBtn.TabIndex = 5; + this.CancelBtn.Text = "&Cancel"; + this.CancelBtn.UseVisualStyleBackColor = true; + this.CancelBtn.Click += new System.EventHandler(this.CancelButton_Click); + // + // PlatformsGroupBox + // + this.PlatformsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.PlatformsGroupBox.AutoScroll = true; + this.PlatformsGroupBox.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; + this.PlatformsGroupBox.Location = new System.Drawing.Point(12, 97); + this.PlatformsGroupBox.Name = "PlatformsGroupBox"; + this.PlatformsGroupBox.Size = new System.Drawing.Size(333, 336); + this.PlatformsGroupBox.TabIndex = 6; + // + // PlatformChooser + // + this.AcceptButton = this.OkBtn; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.CancelBtn; + this.ClientSize = new System.Drawing.Size(357, 474); + this.Controls.Add(this.PlatformsGroupBox); + this.Controls.Add(this.CancelBtn); + this.Controls.Add(this.OkBtn); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.textBox1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Name = "PlatformChooser"; + this.ShowIcon = false; + this.Text = "Choose a Platform"; + this.Load += new System.EventHandler(this.PlatformChooser_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.Button OkBtn; + private System.Windows.Forms.Button CancelBtn; + private System.Windows.Forms.Panel PlatformsGroupBox; + } +} \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/PlatformChooser.cs b/BizHawk.Client.EmuHawk/PlatformChooser.cs new file mode 100644 index 0000000000..4716f2475e --- /dev/null +++ b/BizHawk.Client.EmuHawk/PlatformChooser.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +using BizHawk.Client.Common; + +namespace BizHawk.Client.EmuHawk +{ + public partial class PlatformChooser : Form + { + // Because we don't have enough places where we list SystemID's + private readonly Dictionary Platforms = new Dictionary + { + + { "A26", "Atari 2600" }, + { "A78", "Atari 7800" }, + + { "NES", "Nintendo Entertainment System" }, + { "SNES", "Super Nintendo" }, + { "N64", "Nintendo 64" }, + + { "GB", "Game Boy" }, + { "GBC", "Game Boy Color" }, + + { "PCE", "PC Engine/TurboGrafx 16" }, + { "SGX", "Super Grafx" }, + + { "SMS", "Sega Master System" }, + { "GG", "Sega Game Gear" }, + { "SG", "SG-1000" }, + { "GEN", "Sega Genesis" }, + + { "Coleco", "Colecovision" }, + }; + + public RomGame RomGame { get; set; } + public string PlatformChoice { get; set; } + + private RadioButton SelectedRadio + { + get + { + return PlatformsGroupBox.Controls.OfType().FirstOrDefault(x => x.Checked); + } + } + + public PlatformChooser() + { + InitializeComponent(); + } + + private void PlatformChooser_Load(object sender, EventArgs e) + { + int count = 0; + int spacing = 25; + foreach (var platform in Platforms) + { + var radio = new RadioButton + { + Text = platform.Value, + Location = new Point(15, 15 + (count * spacing)), + Size = new Size(200, 23) + }; + + PlatformsGroupBox.Controls.Add(radio); + count++; + } + + PlatformsGroupBox.Controls + .OfType() + .First() + .Select(); + } + + private void CancelButton_Click(object sender, EventArgs e) + { + Close(); + } + + private void OkBtn_Click(object sender, EventArgs e) + { + var selectedValue = SelectedRadio != null ? SelectedRadio.Text : string.Empty; + PlatformChoice = Platforms.FirstOrDefault(x => x.Value == selectedValue).Key; + Close(); + } + } +} diff --git a/BizHawk.Client.EmuHawk/PlatformChooser.resx b/BizHawk.Client.EmuHawk/PlatformChooser.resx new file mode 100644 index 0000000000..29dcb1b3a3 --- /dev/null +++ b/BizHawk.Client.EmuHawk/PlatformChooser.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/BizHawk.Emulation.Common/Database/Database.cs b/BizHawk.Emulation.Common/Database/Database.cs index 90091e1819..14bb7130d9 100644 --- a/BizHawk.Emulation.Common/Database/Database.cs +++ b/BizHawk.Emulation.Common/Database/Database.cs @@ -165,7 +165,7 @@ namespace BizHawk.Emulation.Common Game.System = "SG"; break; - case ".BIN": + //case ".BIN": case ".GEN": case ".MD": case ".SMD":