Controller Config - a new type of controller panel, this one uses reflection to dynamically load and set its values, still some bugs with the dialog

This commit is contained in:
adelikat 2012-11-07 04:31:29 +00:00
parent 30c0564bda
commit 28cc3bb6c6
6 changed files with 376 additions and 102 deletions

View File

@ -169,6 +169,12 @@
<Compile Include="config\ControllerConfig.Designer.cs">
<DependentUpon>ControllerConfig.cs</DependentUpon>
</Compile>
<Compile Include="config\ControllerConfig\ControllerConfigPanel.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="config\ControllerConfig\ControllerConfigPanel.Designer.cs">
<DependentUpon>ControllerConfigPanel.cs</DependentUpon>
</Compile>
<Compile Include="config\ControllerConfig\GamepadConfigPanel.cs">
<SubType>Component</SubType>
</Compile>
@ -460,6 +466,9 @@
<EmbeddedResource Include="config\ControllerConfig.resx">
<DependentUpon>ControllerConfig.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="config\ControllerConfig\ControllerConfigPanel.resx">
<DependentUpon>ControllerConfigPanel.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="config\GifAnimator.resx">
<DependentUpon>GifAnimator.cs</DependentUpon>
</EmbeddedResource>

View File

@ -32,14 +32,22 @@
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabControl2 = new System.Windows.Forms.TabControl();
this.tabPage13 = new System.Windows.Forms.TabPage();
this.NESController1Panel = new BizHawk.MultiClient.ControllerConfigPanel();
this.tabPage14 = new System.Windows.Forms.TabPage();
this.NESController2Panel = new BizHawk.MultiClient.ControllerConfigPanel();
this.tabPage15 = new System.Windows.Forms.TabPage();
this.NESController3Panel = new BizHawk.MultiClient.ControllerConfigPanel();
this.tabPage16 = new System.Windows.Forms.TabPage();
this.NESController4Panel = new BizHawk.MultiClient.ControllerConfigPanel();
this.tabPage17 = new System.Windows.Forms.TabPage();
this.tabPage18 = new System.Windows.Forms.TabPage();
this.NESAutofire1Panel = new BizHawk.MultiClient.ControllerConfigPanel();
this.tabPage19 = new System.Windows.Forms.TabPage();
this.NESAutofire2Panel = new BizHawk.MultiClient.ControllerConfigPanel();
this.tabPage20 = new System.Windows.Forms.TabPage();
this.NESAutofire3Panel = new BizHawk.MultiClient.ControllerConfigPanel();
this.tabPage21 = new System.Windows.Forms.TabPage();
this.NESAutofire4Panel = new BizHawk.MultiClient.ControllerConfigPanel();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.tabControl3 = new System.Windows.Forms.TabControl();
this.tabPage22 = new System.Windows.Forms.TabPage();
@ -95,15 +103,6 @@
this.tabPage8 = new System.Windows.Forms.TabPage();
this.Cancel = new System.Windows.Forms.Button();
this.OK = new System.Windows.Forms.Button();
this.NESController1Panel = new BizHawk.MultiClient.NESGamePad();
this.NESController2Panel = new BizHawk.MultiClient.NESGamePad();
this.NESController3Panel = new BizHawk.MultiClient.NESGamePad();
this.NESController4Panel = new BizHawk.MultiClient.NESGamePad();
this.NESAutofire1Panel = new BizHawk.MultiClient.NESGamePad();
this.NESAutofire2Panel = new BizHawk.MultiClient.NESGamePad();
this.NESAutofire3Panel = new BizHawk.MultiClient.NESGamePad();
this.NESAutofire4Panel = new BizHawk.MultiClient.NESGamePad();
this.NESConsolePad = new BizHawk.MultiClient.NESConsoleButtons();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabControl2.SuspendLayout();
@ -111,7 +110,6 @@
this.tabPage14.SuspendLayout();
this.tabPage15.SuspendLayout();
this.tabPage16.SuspendLayout();
this.tabPage17.SuspendLayout();
this.tabPage18.SuspendLayout();
this.tabPage19.SuspendLayout();
this.tabPage20.SuspendLayout();
@ -193,6 +191,13 @@
this.tabPage13.Text = "Pad 1";
this.tabPage13.UseVisualStyleBackColor = true;
//
// NESController1Panel
//
this.NESController1Panel.Location = new System.Drawing.Point(10, 10);
this.NESController1Panel.Name = "NESController1Panel";
this.NESController1Panel.Size = new System.Drawing.Size(392, 332);
this.NESController1Panel.TabIndex = 0;
//
// tabPage14
//
this.tabPage14.Controls.Add(this.NESController2Panel);
@ -204,6 +209,13 @@
this.tabPage14.Text = "Pad 2";
this.tabPage14.UseVisualStyleBackColor = true;
//
// NESController2Panel
//
this.NESController2Panel.Location = new System.Drawing.Point(10, 10);
this.NESController2Panel.Name = "NESController2Panel";
this.NESController2Panel.Size = new System.Drawing.Size(392, 332);
this.NESController2Panel.TabIndex = 0;
//
// tabPage15
//
this.tabPage15.Controls.Add(this.NESController3Panel);
@ -214,6 +226,13 @@
this.tabPage15.Text = "Pad 3";
this.tabPage15.UseVisualStyleBackColor = true;
//
// NESController3Panel
//
this.NESController3Panel.Location = new System.Drawing.Point(10, 10);
this.NESController3Panel.Name = "NESController3Panel";
this.NESController3Panel.Size = new System.Drawing.Size(392, 332);
this.NESController3Panel.TabIndex = 0;
//
// tabPage16
//
this.tabPage16.Controls.Add(this.NESController4Panel);
@ -224,9 +243,15 @@
this.tabPage16.Text = "Pad 4";
this.tabPage16.UseVisualStyleBackColor = true;
//
// NESController4Panel
//
this.NESController4Panel.Location = new System.Drawing.Point(10, 10);
this.NESController4Panel.Name = "NESController4Panel";
this.NESController4Panel.Size = new System.Drawing.Size(392, 332);
this.NESController4Panel.TabIndex = 0;
//
// tabPage17
//
this.tabPage17.Controls.Add(this.NESConsolePad);
this.tabPage17.Location = new System.Drawing.Point(4, 22);
this.tabPage17.Name = "tabPage17";
this.tabPage17.Size = new System.Drawing.Size(445, 378);
@ -244,6 +269,13 @@
this.tabPage18.Text = "Autofire 1";
this.tabPage18.UseVisualStyleBackColor = true;
//
// NESAutofire1Panel
//
this.NESAutofire1Panel.Location = new System.Drawing.Point(10, 10);
this.NESAutofire1Panel.Name = "NESAutofire1Panel";
this.NESAutofire1Panel.Size = new System.Drawing.Size(392, 332);
this.NESAutofire1Panel.TabIndex = 0;
//
// tabPage19
//
this.tabPage19.Controls.Add(this.NESAutofire2Panel);
@ -254,6 +286,13 @@
this.tabPage19.Text = "Autofire 2";
this.tabPage19.UseVisualStyleBackColor = true;
//
// NESAutofire2Panel
//
this.NESAutofire2Panel.Location = new System.Drawing.Point(10, 10);
this.NESAutofire2Panel.Name = "NESAutofire2Panel";
this.NESAutofire2Panel.Size = new System.Drawing.Size(392, 332);
this.NESAutofire2Panel.TabIndex = 0;
//
// tabPage20
//
this.tabPage20.Controls.Add(this.NESAutofire3Panel);
@ -264,6 +303,13 @@
this.tabPage20.Text = "Autofire 3";
this.tabPage20.UseVisualStyleBackColor = true;
//
// NESAutofire3Panel
//
this.NESAutofire3Panel.Location = new System.Drawing.Point(10, 10);
this.NESAutofire3Panel.Name = "NESAutofire3Panel";
this.NESAutofire3Panel.Size = new System.Drawing.Size(392, 332);
this.NESAutofire3Panel.TabIndex = 0;
//
// tabPage21
//
this.tabPage21.Controls.Add(this.NESAutofire4Panel);
@ -274,6 +320,13 @@
this.tabPage21.Text = "Autofire 4";
this.tabPage21.UseVisualStyleBackColor = true;
//
// NESAutofire4Panel
//
this.NESAutofire4Panel.Location = new System.Drawing.Point(10, 10);
this.NESAutofire4Panel.Name = "NESAutofire4Panel";
this.NESAutofire4Panel.Size = new System.Drawing.Size(392, 332);
this.NESAutofire4Panel.TabIndex = 0;
//
// tabPage2
//
this.tabPage2.Controls.Add(this.tabControl3);
@ -838,69 +891,6 @@
this.OK.UseVisualStyleBackColor = true;
this.OK.Click += new System.EventHandler(this.OK_Click);
//
// NESController1Panel
//
this.NESController1Panel.Location = new System.Drawing.Point(10, 10);
this.NESController1Panel.Name = "NESController1Panel";
this.NESController1Panel.Size = new System.Drawing.Size(392, 332);
this.NESController1Panel.TabIndex = 0;
//
// NESController2Panel
//
this.NESController2Panel.Location = new System.Drawing.Point(10, 10);
this.NESController2Panel.Name = "NESController2Panel";
this.NESController2Panel.Size = new System.Drawing.Size(392, 332);
this.NESController2Panel.TabIndex = 0;
//
// NESController3Panel
//
this.NESController3Panel.Location = new System.Drawing.Point(10, 10);
this.NESController3Panel.Name = "NESController3Panel";
this.NESController3Panel.Size = new System.Drawing.Size(392, 332);
this.NESController3Panel.TabIndex = 0;
//
// NESController4Panel
//
this.NESController4Panel.Location = new System.Drawing.Point(10, 10);
this.NESController4Panel.Name = "NESController4Panel";
this.NESController4Panel.Size = new System.Drawing.Size(392, 332);
this.NESController4Panel.TabIndex = 0;
//
// NESAutofire1Panel
//
this.NESAutofire1Panel.Location = new System.Drawing.Point(10, 10);
this.NESAutofire1Panel.Name = "NESAutofire1Panel";
this.NESAutofire1Panel.Size = new System.Drawing.Size(392, 332);
this.NESAutofire1Panel.TabIndex = 0;
//
// NESAutofire2Panel
//
this.NESAutofire2Panel.Location = new System.Drawing.Point(10, 10);
this.NESAutofire2Panel.Name = "NESAutofire2Panel";
this.NESAutofire2Panel.Size = new System.Drawing.Size(392, 332);
this.NESAutofire2Panel.TabIndex = 0;
//
// NESAutofire3Panel
//
this.NESAutofire3Panel.Location = new System.Drawing.Point(10, 10);
this.NESAutofire3Panel.Name = "NESAutofire3Panel";
this.NESAutofire3Panel.Size = new System.Drawing.Size(392, 332);
this.NESAutofire3Panel.TabIndex = 0;
//
// NESAutofire4Panel
//
this.NESAutofire4Panel.Location = new System.Drawing.Point(10, 10);
this.NESAutofire4Panel.Name = "NESAutofire4Panel";
this.NESAutofire4Panel.Size = new System.Drawing.Size(392, 332);
this.NESAutofire4Panel.TabIndex = 0;
//
// NESConsolePad
//
this.NESConsolePad.Location = new System.Drawing.Point(14, 13);
this.NESConsolePad.Name = "NESConsolePad";
this.NESConsolePad.Size = new System.Drawing.Size(392, 332);
this.NESConsolePad.TabIndex = 1;
//
// ControllerConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -921,7 +911,6 @@
this.tabPage14.ResumeLayout(false);
this.tabPage15.ResumeLayout(false);
this.tabPage16.ResumeLayout(false);
this.tabPage17.ResumeLayout(false);
this.tabPage18.ResumeLayout(false);
this.tabPage19.ResumeLayout(false);
this.tabPage20.ResumeLayout(false);
@ -1013,14 +1002,13 @@
private System.Windows.Forms.TabPage tabPage57;
private System.Windows.Forms.TabPage tabPage35;
private System.Windows.Forms.TabPage tabPage58;
private NESGamePad NESController1Panel;
private NESGamePad NESController2Panel;
private NESGamePad NESController3Panel;
private NESGamePad NESController4Panel;
private NESGamePad NESAutofire1Panel;
private NESGamePad NESAutofire2Panel;
private NESGamePad NESAutofire3Panel;
private NESGamePad NESAutofire4Panel;
private NESConsoleButtons NESConsolePad;
private ControllerConfigPanel NESController1Panel;
private ControllerConfigPanel NESController2Panel;
private ControllerConfigPanel NESController3Panel;
private ControllerConfigPanel NESController4Panel;
private ControllerConfigPanel NESAutofire1Panel;
private ControllerConfigPanel NESAutofire2Panel;
private ControllerConfigPanel NESAutofire3Panel;
private ControllerConfigPanel NESAutofire4Panel;
}
}

View File

@ -18,25 +18,31 @@ namespace BizHawk.MultiClient
private void ControllerConfig_Load(object sender, EventArgs e)
{
NESController1Panel.ControllerNumber = 1;
NESController1Panel.Autofire = false;
NESController1Panel.Load();
NESController2Panel.ControllerNumber = 2;
NESController2Panel.Autofire = false;
NESController2Panel.Load();
NESController1Panel.LoadSettings(Global.Config.NESController[0]);
NESController2Panel.LoadSettings(Global.Config.NESController[1]);
NESController3Panel.LoadSettings(Global.Config.NESController[2]);
NESController4Panel.LoadSettings(Global.Config.NESController[3]);
//NESController1Panel.ControllerNumber = 1;
//NESController1Panel.Autofire = false;
//NESController1Panel.Load();
//NESController2Panel.ControllerNumber = 2;
//NESController2Panel.Autofire = false;
//NESController2Panel.Load();
NESController3Panel.ControllerNumber = 3;
NESController3Panel.Autofire = false;
NESController4Panel.ControllerNumber = 4;
NESController4Panel.Autofire = false;
NESAutofire1Panel.ControllerNumber = 1;
NESAutofire1Panel.Autofire = false;
NESAutofire2Panel.ControllerNumber = 2;
NESAutofire2Panel.Autofire = false;
NESAutofire3Panel.ControllerNumber = 3;
NESAutofire3Panel.Autofire = false;
NESAutofire4Panel.ControllerNumber = 4;
NESAutofire4Panel.Autofire = false;
//NESController3Panel.ControllerNumber = 3;
//NESController3Panel.Autofire = false;
//NESController4Panel.ControllerNumber = 4;
//NESController4Panel.Autofire = false;
//NESAutofire1Panel.ControllerNumber = 1;
//NESAutofire1Panel.Autofire = false;
//NESAutofire2Panel.ControllerNumber = 2;
//NESAutofire2Panel.Autofire = false;
//NESAutofire3Panel.ControllerNumber = 3;
//NESAutofire3Panel.Autofire = false;
//NESAutofire4Panel.ControllerNumber = 4;
//NESAutofire4Panel.Autofire = false;
SetAutoTab(true);
}
@ -81,6 +87,8 @@ namespace BizHawk.MultiClient
{
NESController1Panel.Save();
NESController2Panel.Save();
NESController3Panel.Save();
NESController4Panel.Save();
Global.OSD.AddMessage("Controller settings saved");
Close();

View File

@ -0,0 +1,45 @@
namespace BizHawk.MultiClient
{
partial class ControllerConfigPanel
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// ControllerConfigPanel
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "ControllerConfigPanel";
this.Load += new System.EventHandler(this.ControllerConfigPanel_Load);
this.ResumeLayout(false);
}
#endregion
}
}

View File

@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Windows.Forms;
namespace BizHawk.MultiClient
{
public partial class ControllerConfigPanel : UserControl
{
object ControllerConfigObject; //Object that values will be saved to (In Config.cs)
public static List<string> buttons = new List<string>();
public int ControllerNumber = 1;
public bool Autofire = false;
public int InputMarginLeft = 0;
public int LabelPadding = 10;
public int MarginTop = 0;
public int Spacing = 30;
public int InputSize = 200;
protected List<InputWidget> Inputs = new List<InputWidget>();
protected List<Label> Labels = new List<Label>();
public ControllerConfigPanel()
{
InitializeComponent();
}
private void ControllerConfigPanel_Load(object sender, EventArgs e)
{
}
public void Save()
{
for (int button = 0; button < buttons.Count; button++)
{
FieldInfo buttonF = ControllerConfigObject.GetType().GetField(buttons[button]);
buttonF.SetValue(ControllerConfigObject, Inputs[button].Text);
}
}
public void LoadSettings(object configobj)
{
ControllerConfigObject = configobj;
SetButtonList();
Startup();
SetWidgetStrings();
}
private void SetButtonList()
{
buttons.Clear();
MemberInfo[] members = ControllerConfigObject.GetType().GetMembers();
foreach (MemberInfo member in members)
{
Type type = member.GetType();
if (member.MemberType.ToString() == "Field" && member.ToString().Contains("System.String"))
{
buttons.Add(member.Name);
}
}
}
private void SetWidgetStrings()
{
for (int button = 0; button < buttons.Count; button++)
{
FieldInfo buttonF = ControllerConfigObject.GetType().GetField(buttons[button]);
object field = ControllerConfigObject.GetType().GetField(buttons[button]).GetValue(ControllerConfigObject);
Inputs[button].Text = field.ToString();
}
}
private void Startup()
{
for (int i = 0; i < buttons.Count; i++)
{
InputWidget iw = new InputWidget();
iw.Location = new Point(InputMarginLeft, MarginTop + (i * Spacing));
iw.Size = new Size(InputSize, 23);
iw.TabIndex = i;
Controls.Add(iw);
Inputs.Add(iw);
Label l = new Label();
l.Location = new Point(InputMarginLeft + InputSize + LabelPadding, MarginTop + (i * Spacing) + 3);
l.Text = buttons[i];
Controls.Add(l);
Labels.Add(l);
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>