implement TargetScreen virtual pad and wire up to Nes zapper

This commit is contained in:
adelikat 2014-06-22 21:50:27 +00:00
parent a248e2d99b
commit b364b5c48f
8 changed files with 502 additions and 7 deletions

View File

@ -892,6 +892,12 @@
<Compile Include="tools\VirtualPads\controls\VirtualPadButton.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="tools\VirtualPads\controls\VirtualPadTargetScreen.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="tools\VirtualPads\controls\VirtualPadTargetScreen.Designer.cs">
<DependentUpon>VirtualPadTargetScreen.cs</DependentUpon>
</Compile>
<Compile Include="tools\VirtualPads\IVirtualPad.cs" />
<Compile Include="tools\VirtualPads\schema\N64Schema.cs" />
<Compile Include="tools\VirtualPads\schema\NesSchema.cs" />
@ -1231,6 +1237,9 @@
<EmbeddedResource Include="tools\VirtualPads\controls\VirtualPadAnalogStick.resx">
<DependentUpon>VirtualPadAnalogStick.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="tools\VirtualPads\controls\VirtualPadTargetScreen.resx">
<DependentUpon>VirtualPadTargetScreen.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="tools\VirtualPads\VirtualPad.resx">
<DependentUpon>VirtualPad.cs</DependentUpon>
</EmbeddedResource>

View File

@ -51,6 +51,16 @@ namespace BizHawk.Client.EmuHawk
Location = button.Location
});
break;
case PadSchema.PadInputType.TargetedPair:
Controls.Add(new VirtualPadTargetScreen
{
Name = button.Name,
Location = button.Location,
XName = button.Name,
YName = button.SecondaryNames[0],
FireButton = button.SecondaryNames[1]
});
break;
}
}
}

View File

@ -76,11 +76,16 @@ namespace BizHawk.Client.EmuHawk
{
Location = new Point(15, 15)
});
//ControllerBox.Controls.Add(new VirtualPad(
// NesSchema.StandardController(2))
// {
// Location = new Point(200, 15)
// });
ControllerBox.Controls.Add(new VirtualPad(
NesSchema.StandardController(2))
{
Location = new Point(200, 15)
});
NesSchema.Zapper(2))
{
Location = new Point(200, 15)
});
break;
case "N64":
ControllerBox.Controls.Add(new VirtualPad(
@ -152,6 +157,8 @@ namespace BizHawk.Client.EmuHawk
return;
}
Pads.ForEach(p => p.Refresh());
if (!StickyBox.Checked)
{
Pads.ForEach(pad => pad.Clear());

View File

@ -0,0 +1,122 @@
namespace BizHawk.Client.EmuHawk
{
partial class VirtualPadTargetScreen
{
/// <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.TargetPanel = new System.Windows.Forms.Panel();
this.XNumeric = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.YNumeric = new System.Windows.Forms.NumericUpDown();
((System.ComponentModel.ISupportInitialize)(this.XNumeric)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.YNumeric)).BeginInit();
this.SuspendLayout();
//
// TargetPanel
//
this.TargetPanel.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.TargetPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.TargetPanel.Location = new System.Drawing.Point(0, 0);
this.TargetPanel.Name = "TargetPanel";
this.TargetPanel.Size = new System.Drawing.Size(256, 224);
this.TargetPanel.TabIndex = 0;
this.TargetPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.TargetPanel_Paint);
this.TargetPanel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TargetPanel_MouseDown);
this.TargetPanel.MouseMove += new System.Windows.Forms.MouseEventHandler(this.TargetPanel_MouseMove);
this.TargetPanel.MouseUp += new System.Windows.Forms.MouseEventHandler(this.TargetPanel_MouseUp);
//
// XNumeric
//
this.XNumeric.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.XNumeric.Location = new System.Drawing.Point(23, 229);
this.XNumeric.Name = "XNumeric";
this.XNumeric.Size = new System.Drawing.Size(50, 20);
this.XNumeric.TabIndex = 1;
this.XNumeric.ValueChanged += new System.EventHandler(this.XNumeric_ValueChanged);
this.XNumeric.KeyUp += new System.Windows.Forms.KeyEventHandler(this.XNumeric_KeyUp);
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(3, 233);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(14, 13);
this.label1.TabIndex = 2;
this.label1.Text = "X";
//
// label2
//
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(91, 233);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(14, 13);
this.label2.TabIndex = 4;
this.label2.Text = "Y";
//
// YNumeric
//
this.YNumeric.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.YNumeric.Location = new System.Drawing.Point(111, 229);
this.YNumeric.Name = "YNumeric";
this.YNumeric.Size = new System.Drawing.Size(50, 20);
this.YNumeric.TabIndex = 3;
this.YNumeric.ValueChanged += new System.EventHandler(this.YNumeric_ValueChanged);
this.YNumeric.KeyUp += new System.Windows.Forms.KeyEventHandler(this.YNumeric_KeyUp);
//
// VirtualPadTargetScreen
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.label2);
this.Controls.Add(this.YNumeric);
this.Controls.Add(this.label1);
this.Controls.Add(this.XNumeric);
this.Controls.Add(this.TargetPanel);
this.Name = "VirtualPadTargetScreen";
this.Size = new System.Drawing.Size(256, 254);
this.Load += new System.EventHandler(this.VirtualPadTargetScreen_Load);
((System.ComponentModel.ISupportInitialize)(this.XNumeric)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.YNumeric)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Panel TargetPanel;
private System.Windows.Forms.NumericUpDown XNumeric;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.NumericUpDown YNumeric;
}
}

View File

@ -0,0 +1,199 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
public partial class VirtualPadTargetScreen : UserControl, IVirtualPadControl
{
private readonly Pen BlackPen = new Pen(Brushes.Black, 2);
private readonly Pen WhitePen = new Pen(Brushes.White, 2);
private bool _isProgrammicallyChangingNumerics = false;
private bool _isDragging = false;
public VirtualPadTargetScreen()
{
InitializeComponent();
}
private void VirtualPadTargetScreen_Load(object sender, EventArgs e)
{
XNumeric.Maximum = TargetPanel.Width;
YNumeric.Maximum = TargetPanel.Height;
}
public string XName { get; set; }
public string YName { get; set; }
public string FireButton { get; set; } // Fire, Press, etc
public int X
{
get
{
return (int)Global.StickyXORAdapter.GetFloat(XName);
}
set
{
if (value < 0)
{
XNumeric.Value = 0;
}
else if (value <= XNumeric.Maximum)
{
XNumeric.Value = value;
}
else
{
XNumeric.Value = XNumeric.Maximum;
}
Global.StickyXORAdapter.SetFloat(XName, (int)XNumeric.Value);
}
}
public int Y
{
get
{
return (int)Global.StickyXORAdapter.GetFloat(YName);
}
set
{
if (value < 0)
{
YNumeric.Value = 0;
}
else if (value <= YNumeric.Maximum)
{
YNumeric.Value = value;
}
else
{
YNumeric.Value = YNumeric.Maximum;
}
Global.StickyXORAdapter.SetFloat(YName, (int)YNumeric.Value);
}
}
public bool Fire
{
get
{
return Global.StickyXORAdapter.IsPressed(FireButton);
}
}
public void Clear()
{
X = 0;
Y = 0;
}
private void UpdatePanelFromNumeric()
{
if (!_isProgrammicallyChangingNumerics)
{
TargetPanel.Refresh();
}
}
private void TargetPanel_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawEllipse(
Fire ? WhitePen : BlackPen,
X - 10,
Y - 10,
21,
21);
e.Graphics.DrawLine(
Fire ? WhitePen : BlackPen,
new Point(X, Y - 10),
new Point(X, Y + 10));
e.Graphics.DrawLine(
Fire ? WhitePen : BlackPen,
new Point(X - 10, Y),
new Point(X + 10, Y));
e.Graphics.FillEllipse(
Brushes.Red,
new Rectangle(X - 2, Y - 2, 4, 4));
}
private void XNumeric_ValueChanged(object sender, EventArgs e)
{
UpdatePanelFromNumeric();
}
private void XNumeric_KeyUp(object sender, KeyEventArgs e)
{
UpdatePanelFromNumeric();
}
private void YNumeric_ValueChanged(object sender, EventArgs e)
{
UpdatePanelFromNumeric();
}
private void YNumeric_KeyUp(object sender, KeyEventArgs e)
{
UpdatePanelFromNumeric();
}
private void TargetPanel_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_isDragging = true;
X = e.X;
Y = e.Y;
TargetPanel.Refresh();
}
}
private void TargetPanel_MouseMove(object sender, MouseEventArgs e)
{
if (_isDragging)
{
_isProgrammicallyChangingNumerics = true;
X = e.X;
Y = e.Y;
_isProgrammicallyChangingNumerics = false;
TargetPanel.Refresh();
}
}
private void TargetPanel_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_isDragging = false;
_isProgrammicallyChangingNumerics = false;
Global.StickyXORAdapter.SetSticky(XName, false);
Global.StickyXORAdapter.SetSticky(YName, false);
TargetPanel.Refresh();
}
}
public override void Refresh()
{
X = X;
Y = Y;
base.Refresh();
}
}
}

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>

View File

@ -77,9 +77,35 @@ namespace BizHawk.Client.EmuHawk
}
// TODO
public static PadSchema Zapper()
public static PadSchema Zapper(int controller)
{
return new PadSchema();
return new PadSchema
{
IsConsole = false,
DefaultSize = new Size(356, 260),
Buttons = new[]
{
new PadSchema.ButtonScema
{
Name = "P" + controller + " Zapper X",
Location = new Point(14, 2),
Type = PadSchema.PadInputType.TargetedPair,
TargetSize = new Size(256, 240),
SecondaryNames = new []
{
"P" + controller + " Zapper Y",
"P" + controller + " Fire",
}
},
new PadSchema.ButtonScema
{
Name = "P" + controller + " Fire",
DisplayName = "Fire",
Location = new Point(284, 2),
Type = PadSchema.PadInputType.Boolean
}
}
};
}
// TODO

View File

@ -13,7 +13,7 @@ namespace BizHawk.Client.EmuHawk
public enum PadInputType
{
Boolean, // A single on/off button
AnalogStick, // An analog stick X,Y Pair
AnalogStick, // An analog stick X,Y Pair
FloatSingle, // A single analog button (pressure sensitive button for instance)
TargetedPair // A X,Y pair intended to be a screen cooridnate (for zappers, mouse, stylus, etc)
}
@ -30,6 +30,8 @@ namespace BizHawk.Client.EmuHawk
public PadInputType Type { get; set; }
public Point Location { get; set; }
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
}
}