PCE - add ui for controller config

This commit is contained in:
adelikat 2017-07-18 11:01:50 -05:00
parent d99d2dd3dc
commit 9fc8b8700d
3 changed files with 71 additions and 90 deletions

View File

@ -28,52 +28,63 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PCEControllerConfig)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PCEControllerConfig));
this.CancelBtn = new System.Windows.Forms.Button(); this.CancelBtn = new System.Windows.Forms.Button();
this.OkBtn = new System.Windows.Forms.Button(); this.OkBtn = new System.Windows.Forms.Button();
this.SuspendLayout(); this.ControllerPropertyGrid = new System.Windows.Forms.PropertyGrid();
// this.SuspendLayout();
// CancelBtn //
// // 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.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.CancelBtn.Location = new System.Drawing.Point(235, 145); this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.CancelBtn.Name = "CancelBtn"; this.CancelBtn.Location = new System.Drawing.Point(235, 203);
this.CancelBtn.Size = new System.Drawing.Size(60, 23); this.CancelBtn.Name = "CancelBtn";
this.CancelBtn.TabIndex = 3; this.CancelBtn.Size = new System.Drawing.Size(60, 23);
this.CancelBtn.Text = "&Cancel"; this.CancelBtn.TabIndex = 3;
this.CancelBtn.UseVisualStyleBackColor = true; this.CancelBtn.Text = "&Cancel";
this.CancelBtn.Click += new System.EventHandler(this.CancelBtn_Click); this.CancelBtn.UseVisualStyleBackColor = true;
// this.CancelBtn.Click += new System.EventHandler(this.CancelBtn_Click);
// OkBtn //
// // 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(169, 145); this.OkBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.OkBtn.Name = "OkBtn"; this.OkBtn.Location = new System.Drawing.Point(169, 203);
this.OkBtn.Size = new System.Drawing.Size(60, 23); this.OkBtn.Name = "OkBtn";
this.OkBtn.TabIndex = 2; this.OkBtn.Size = new System.Drawing.Size(60, 23);
this.OkBtn.Text = "&OK"; this.OkBtn.TabIndex = 2;
this.OkBtn.UseVisualStyleBackColor = true; this.OkBtn.Text = "&OK";
this.OkBtn.Click += new System.EventHandler(this.OkBtn_Click); this.OkBtn.UseVisualStyleBackColor = true;
// this.OkBtn.Click += new System.EventHandler(this.OkBtn_Click);
// PCEControllerConfig //
// // ControllerPropertyGrid
this.AcceptButton = this.OkBtn; //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.ControllerPropertyGrid.Location = new System.Drawing.Point(12, 12);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ControllerPropertyGrid.Name = "ControllerPropertyGrid";
this.CancelButton = this.CancelBtn; this.ControllerPropertyGrid.PropertySort = System.Windows.Forms.PropertySort.Alphabetical;
this.ClientSize = new System.Drawing.Size(307, 180); this.ControllerPropertyGrid.Size = new System.Drawing.Size(283, 181);
this.Controls.Add(this.CancelBtn); this.ControllerPropertyGrid.TabIndex = 4;
this.Controls.Add(this.OkBtn); this.ControllerPropertyGrid.ToolbarVisible = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; //
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); // PCEControllerConfig
this.MaximizeBox = false; //
this.MinimizeBox = false; this.AcceptButton = this.OkBtn;
this.Name = "PCEControllerConfig"; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Controller Settings"; this.CancelButton = this.CancelBtn;
this.Load += new System.EventHandler(this.PCEControllerConfig_Load); this.ClientSize = new System.Drawing.Size(307, 238);
this.ResumeLayout(false); this.Controls.Add(this.ControllerPropertyGrid);
this.Controls.Add(this.CancelBtn);
this.Controls.Add(this.OkBtn);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "PCEControllerConfig";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Controller Settings";
this.Load += new System.EventHandler(this.PCEControllerConfig_Load);
this.ResumeLayout(false);
} }
@ -81,5 +92,6 @@
private System.Windows.Forms.Button CancelBtn; private System.Windows.Forms.Button CancelBtn;
private System.Windows.Forms.Button OkBtn; private System.Windows.Forms.Button OkBtn;
private System.Windows.Forms.PropertyGrid ControllerPropertyGrid;
} }
} }

View File

@ -1,6 +1,4 @@
using System; using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Emulation.Cores.PCEngine; using BizHawk.Emulation.Cores.PCEngine;
@ -10,6 +8,8 @@ namespace BizHawk.Client.EmuHawk
{ {
public partial class PCEControllerConfig : Form public partial class PCEControllerConfig : Form
{ {
private PCEngine.PCESyncSettings _controllerSettings;
public PCEControllerConfig() public PCEControllerConfig()
{ {
InitializeComponent(); InitializeComponent();
@ -18,36 +18,15 @@ namespace BizHawk.Client.EmuHawk
private void PCEControllerConfig_Load(object sender, EventArgs e) private void PCEControllerConfig_Load(object sender, EventArgs e)
{ {
var pceSettings = ((PCEngine)Global.Emulator).GetSyncSettings(); var pceSettings = ((PCEngine)Global.Emulator).GetSyncSettings();
for (int i = 0; i < 5; i++) _controllerSettings = pceSettings; // Assumes only controller data is in sync settings! If there are ever more sync settings, this dialog should just become a general sync settings dialog (or both settings/sync settings)
{ ControllerPropertyGrid.SelectedObject = _controllerSettings;
Controls.Add(new Label
{
Text = "Controller " + (i + 1),
Location = new Point(15, 15 + (i * 25))
});
Controls.Add(new CheckBox
{
Text = "Connected",
Name = "Controller" + i,
Location = new Point(135, 15 + (i * 25)),
Checked = pceSettings.Controllers[i].IsConnected
});
}
} }
private void OkBtn_Click(object sender, EventArgs e) private void OkBtn_Click(object sender, EventArgs e)
{ {
var pceSettings = ((PCEngine)Global.Emulator).GetSyncSettings(); var pceSettings = ((PCEngine)Global.Emulator).GetSyncSettings();
Controls pceSettings = _controllerSettings;
.OfType<CheckBox>()
.OrderBy(c => c.Name)
.ToList()
.ForEach(c =>
{
var index = int.Parse(c.Name.Replace("Controller", ""));
pceSettings.Controllers[index].IsConnected = c.Checked;
});
GlobalWin.MainForm.PutCoreSyncSettings(pceSettings); GlobalWin.MainForm.PutCoreSyncSettings(pceSettings);
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
Close(); Close();

View File

@ -69,8 +69,8 @@ namespace BizHawk.Emulation.Cores.PCEngine
[DisplayName("Port 1 Device")] [DisplayName("Port 1 Device")]
[Description("The type of controller plugged into the first controller port")] [Description("The type of controller plugged into the first controller port")]
[TypeConverter(typeof(DescribableEnumConverter))] [TypeConverter(typeof(DescribableEnumConverter))]
public PceControllerType Port1 { get; set; } = PceControllerType.GamePad; public PceControllerType Port1 { get; set; } = PceControllerType.GamePad;
[DefaultValue(PceControllerType.Unplugged)] [DefaultValue(PceControllerType.Unplugged)]
[DisplayName("Port 2 Device")] [DisplayName("Port 2 Device")]
[Description("The type of controller plugged into the second controller port")] [Description("The type of controller plugged into the second controller port")]
@ -106,13 +106,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
public PCESyncSettings Clone() public PCESyncSettings Clone()
{ {
var ret = new PCESyncSettings(); return (PCESyncSettings)MemberwiseClone();
for (int i = 0; i < Controllers.Length; i++)
{
ret.Controllers[i].IsConnected = Controllers[i].IsConnected;
}
return ret;
} }
public class ControllerSetting public class ControllerSetting
@ -122,15 +116,11 @@ namespace BizHawk.Emulation.Cores.PCEngine
public static bool NeedsReboot(PCESyncSettings x, PCESyncSettings y) public static bool NeedsReboot(PCESyncSettings x, PCESyncSettings y)
{ {
for (int i = 0; i < x.Controllers.Length; i++) return x.Port1 != y.Port1
{ || x.Port2 != y.Port2
if (x.Controllers[i].IsConnected != y.Controllers[i].IsConnected) || x.Port3 != y.Port3
{ || x.Port4 != y.Port4
return true; || x.Port5 != y.Port5;
}
}
return false;
} }
} }
} }