From 3208440225ac52adc9df23496e495e50eb23aecc Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 24 Jun 2014 12:58:08 +0000 Subject: [PATCH] Virtual Pads - basic analog button control and wire up to NES arkanoid paddle --- .../BizHawk.Client.EmuHawk.csproj | 9 ++ .../tools/VirtualPads/VirtualPad.cs | 13 +- .../VirtualPadAnalogButton.Designer.cs | 88 +++++++++++++ .../controls/VirtualPadAnalogButton.cs | 75 +++++++++++ .../controls/VirtualPadAnalogButton.resx | 120 ++++++++++++++++++ .../tools/VirtualPads/schema/NesSchema.cs | 35 ++++- .../tools/VirtualPads/schema/PadSchema.cs | 1 + 7 files changed, 337 insertions(+), 4 deletions(-) create mode 100644 BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogButton.Designer.cs create mode 100644 BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogButton.cs create mode 100644 BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogButton.resx diff --git a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj index d0df18643c..11cde1f03d 100644 --- a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj +++ b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj @@ -883,6 +883,12 @@ Component + + UserControl + + + VirtualPadAnalogButton.cs + UserControl @@ -1242,6 +1248,9 @@ TI83KeyPad.cs + + VirtualPadAnalogButton.cs + VirtualPadAnalogStick.cs diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs index 81b6805b05..e7e115604d 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/VirtualPad.cs @@ -58,7 +58,18 @@ namespace BizHawk.Client.EmuHawk Location = button.Location, XName = button.Name, YName = button.SecondaryNames[0], - FireButton = button.SecondaryNames[1] + FireButton = button.SecondaryNames[1], + Size = button.TargetSize + }); + break; + case PadSchema.PadInputType.FloatSingle: + Controls.Add(new VirtualPadAnalogButton + { + Name = button.Name, + DisplayName = button.DisplayName, + Location = button.Location, + Size = button.TargetSize, + MaxValue = button.MaxValue }); break; } diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogButton.Designer.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogButton.Designer.cs new file mode 100644 index 0000000000..a44b50977d --- /dev/null +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogButton.Designer.cs @@ -0,0 +1,88 @@ +namespace BizHawk.Client.EmuHawk +{ + partial class VirtualPadAnalogButton + { + /// + /// 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 Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.AnalogTrackBar = new System.Windows.Forms.TrackBar(); + this.DisplayNameLabel = new System.Windows.Forms.Label(); + this.ValueLabel = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.AnalogTrackBar)).BeginInit(); + this.SuspendLayout(); + // + // AnalogTrackBar + // + this.AnalogTrackBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.AnalogTrackBar.Location = new System.Drawing.Point(3, 3); + this.AnalogTrackBar.Name = "AnalogTrackBar"; + this.AnalogTrackBar.Size = new System.Drawing.Size(299, 45); + this.AnalogTrackBar.TabIndex = 0; + this.AnalogTrackBar.ValueChanged += new System.EventHandler(this.AnalogTrackBar_ValueChanged); + // + // DisplayNameLabel + // + this.DisplayNameLabel.AutoSize = true; + this.DisplayNameLabel.Location = new System.Drawing.Point(13, 51); + this.DisplayNameLabel.Name = "DisplayNameLabel"; + this.DisplayNameLabel.Size = new System.Drawing.Size(33, 13); + this.DisplayNameLabel.TabIndex = 1; + this.DisplayNameLabel.Text = "Slider"; + // + // ValueLabel + // + this.ValueLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ValueLabel.AutoSize = true; + this.ValueLabel.Location = new System.Drawing.Point(297, 7); + this.ValueLabel.Name = "ValueLabel"; + this.ValueLabel.Size = new System.Drawing.Size(37, 13); + this.ValueLabel.TabIndex = 2; + this.ValueLabel.Text = "99999"; + // + // VirtualPadAnalogButton + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.ValueLabel); + this.Controls.Add(this.DisplayNameLabel); + this.Controls.Add(this.AnalogTrackBar); + this.Name = "VirtualPadAnalogButton"; + this.Size = new System.Drawing.Size(338, 74); + this.Load += new System.EventHandler(this.VirtualPadAnalogButton_Load); + ((System.ComponentModel.ISupportInitialize)(this.AnalogTrackBar)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TrackBar AnalogTrackBar; + private System.Windows.Forms.Label DisplayNameLabel; + private System.Windows.Forms.Label ValueLabel; + } +} diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogButton.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogButton.cs new file mode 100644 index 0000000000..e8d1b42ce9 --- /dev/null +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogButton.cs @@ -0,0 +1,75 @@ +using System; +using System.Windows.Forms; +using System.Drawing; + +using BizHawk.Client.Common; + +namespace BizHawk.Client.EmuHawk +{ + public partial class VirtualPadAnalogButton : UserControl, IVirtualPadControl + { + private string _displayName = string.Empty; + private int _maxValue = 0; + + public VirtualPadAnalogButton() + { + InitializeComponent(); + } + + private void VirtualPadAnalogButton_Load(object sender, EventArgs e) + { + DisplayNameLabel.Text = DisplayName; + ValueLabel.Text = AnalogTrackBar.Value.ToString(); + + } + + public string DisplayName + { + get + { + return _displayName; + } + + set + { + _displayName = value ?? string.Empty; + if (DisplayNameLabel != null) + { + DisplayNameLabel.Text = _displayName; + } + } + } + + public int MaxValue + { + get + { + return _maxValue; + } + + set + { + _maxValue = value; + if (AnalogTrackBar != null) + { + AnalogTrackBar.Maximum = _maxValue; + AnalogTrackBar.TickFrequency = _maxValue / 10; + } + } + } + + // TODO + public void Clear() + { + } + + private void AnalogTrackBar_ValueChanged(object sender, EventArgs e) + { + ValueLabel.Text = AnalogTrackBar.Value.ToString(); + Refresh(); + Global.StickyXORAdapter.SetFloat(Name, AnalogTrackBar.Value); + } + + + } +} diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogButton.resx b/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogButton.resx new file mode 100644 index 0000000000..29dcb1b3a3 --- /dev/null +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/VirtualPadAnalogButton.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.Client.EmuHawk/tools/VirtualPads/schema/NesSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/NesSchema.cs index 5282cd7af2..032926aebd 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/NesSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/NesSchema.cs @@ -28,6 +28,9 @@ namespace BizHawk.Client.EmuHawk case "Zapper": schemaL = Zapper(1); break; + case "ArkanoidNES": + schemaL = ArkanoidPaddle(1); + break; } if (schemaL != null) @@ -50,6 +53,9 @@ namespace BizHawk.Client.EmuHawk case "Zapper": schemaR = Zapper(2); break; + case "ArkanoidNES": + schemaR = ArkanoidPaddle(2); + break; } if (schemaR != null) @@ -179,13 +185,36 @@ namespace BizHawk.Client.EmuHawk } // TODO - private static PadSchema ArkanoidPaddle() + private static PadSchema ArkanoidPaddle(int controller) { - return new PadSchema(); + return new PadSchema + { + IsConsole = false, + DefaultSize = new Size(380, 110), + Buttons = new[] + { + new PadSchema.ButtonScema + { + Name = "P" + controller + " Paddle", + DisplayName = "Arkanoid Paddle", + Location = new Point(14, 2), + Type = PadSchema.PadInputType.FloatSingle, + TargetSize = new Size(375, 75), + MaxValue = 160 + }, + new PadSchema.ButtonScema + { + Name = "P" + controller + " Fire", + DisplayName = "Fire", + Location = new Point(14, 80), + Type = PadSchema.PadInputType.Boolean + } + } + }; } // TODO - private static PadSchema PowerPad() + private static PadSchema PowerPad(int controller) { return new PadSchema(); } diff --git a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchema.cs b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchema.cs index 4322474bcc..44e9e810a7 100644 --- a/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchema.cs +++ b/BizHawk.Client.EmuHawk/tools/VirtualPads/schema/PadSchema.cs @@ -32,6 +32,7 @@ namespace BizHawk.Client.EmuHawk public Bitmap Icon { get; set; } public Size TargetSize { get; set; } // Specifically for TargetedPair, specifies the screen size public string[] SecondaryNames { get; set; } // Any other buttons necessary to operate (such as the Y axis, fire buttons, etc + public int MaxValue { get; set; } // For non-boolean values, specifies the maximum value the button allows } }