issue #7 add ability to load SC game default mappings (new Button)

some refactoring to allow for this
pull/20/head
bm98 10 years ago
parent ee62bddf08
commit 778b333ffd

49
Form1.Designer.cs generated

@ -79,6 +79,7 @@
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.btResetDefaults = new System.Windows.Forms.Button();
this.UC_JoyPanel = new SCJMapper_V2.UC_JoyPanel();
this.cmCopyPaste.SuspendLayout();
this.panel3.SuspendLayout();
@ -94,9 +95,9 @@
//
// btDumpList
//
this.btDumpList.Location = new System.Drawing.Point(3, 52);
this.btDumpList.Location = new System.Drawing.Point(3, 33);
this.btDumpList.Name = "btDumpList";
this.btDumpList.Size = new System.Drawing.Size(94, 26);
this.btDumpList.Size = new System.Drawing.Size(120, 24);
this.btDumpList.TabIndex = 24;
this.btDumpList.Text = "Dump List-->";
this.btDumpList.UseVisualStyleBackColor = true;
@ -104,10 +105,9 @@
//
// btReset
//
this.btReset.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btReset.Location = new System.Drawing.Point(3, 72);
this.btReset.Name = "btReset";
this.btReset.Size = new System.Drawing.Size(94, 24);
this.btReset.Size = new System.Drawing.Size(120, 24);
this.btReset.TabIndex = 23;
this.btReset.Text = "Reset";
this.btReset.Click += new System.EventHandler(this.btReset_Click);
@ -201,9 +201,9 @@
// btGrab
//
this.btGrab.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btGrab.Location = new System.Drawing.Point(197, 3);
this.btGrab.Location = new System.Drawing.Point(171, 3);
this.btGrab.Name = "btGrab";
this.btGrab.Size = new System.Drawing.Size(94, 26);
this.btGrab.Size = new System.Drawing.Size(120, 24);
this.btGrab.TabIndex = 19;
this.btGrab.Text = "<-- Grab XML";
this.btGrab.UseVisualStyleBackColor = true;
@ -213,7 +213,7 @@
//
this.btDump.Location = new System.Drawing.Point(3, 3);
this.btDump.Name = "btDump";
this.btDump.Size = new System.Drawing.Size(94, 26);
this.btDump.Size = new System.Drawing.Size(120, 24);
this.btDump.TabIndex = 20;
this.btDump.Text = "Dump XML-->";
this.btDump.UseVisualStyleBackColor = true;
@ -491,10 +491,10 @@
//
// buttonExit
//
this.buttonExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonExit.Location = new System.Drawing.Point(197, 72);
this.buttonExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonExit.Location = new System.Drawing.Point(171, 72);
this.buttonExit.Name = "buttonExit";
this.buttonExit.Size = new System.Drawing.Size(94, 24);
this.buttonExit.Size = new System.Drawing.Size(120, 24);
this.buttonExit.TabIndex = 13;
this.buttonExit.Text = "Exit";
this.buttonExit.Click += new System.EventHandler(this.buttonExit_Click);
@ -568,9 +568,10 @@
this.tableLayoutPanel1.GrowStyle = System.Windows.Forms.TableLayoutPanelGrowStyle.FixedSize;
this.tableLayoutPanel1.Location = new System.Drawing.Point(306, 621);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.RowCount = 3;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(294, 99);
this.tableLayoutPanel1.TabIndex = 23;
//
@ -579,18 +580,29 @@
this.tableLayoutPanel2.ColumnCount = 2;
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel2.Controls.Add(this.btReset, 0, 1);
this.tableLayoutPanel2.Controls.Add(this.buttonExit, 1, 1);
this.tableLayoutPanel2.Controls.Add(this.btReset, 0, 2);
this.tableLayoutPanel2.Controls.Add(this.buttonExit, 1, 2);
this.tableLayoutPanel2.Controls.Add(this.btResetDefaults, 0, 1);
this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel2.GrowStyle = System.Windows.Forms.TableLayoutPanelGrowStyle.FixedSize;
this.tableLayoutPanel2.Location = new System.Drawing.Point(306, 726);
this.tableLayoutPanel2.Name = "tableLayoutPanel2";
this.tableLayoutPanel2.RowCount = 2;
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel2.RowCount = 3;
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
this.tableLayoutPanel2.Size = new System.Drawing.Size(294, 99);
this.tableLayoutPanel2.TabIndex = 24;
//
// btResetDefaults
//
this.btResetDefaults.Location = new System.Drawing.Point(3, 42);
this.btResetDefaults.Name = "btResetDefaults";
this.btResetDefaults.Size = new System.Drawing.Size(120, 24);
this.btResetDefaults.TabIndex = 24;
this.btResetDefaults.Text = "Reset to defaults";
this.btResetDefaults.Click += new System.EventHandler(this.btResetDefaults_Click);
//
// UC_JoyPanel
//
this.UC_JoyPanel.Location = new System.Drawing.Point(0, 6);
@ -674,6 +686,7 @@
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2;
private System.Windows.Forms.Button btResetDefaults;
}
}

@ -146,12 +146,12 @@ namespace SCJMapper_V2
/// <summary>
/// Resets the Action Tree
/// </summary>
private void InitActionTree( )
private void InitActionTree( Boolean addDefaultBinding )
{
// build TreeView and the ActionMaps
m_AT = new ActionTree( );
m_AT.Ctrl = treeView1; // the ActionTree owns the TreeView control
m_AT.LoadTree( ); // Init with default profile filepath
m_AT.LoadTree( addDefaultBinding ); // Init with default profile filepath
// default JS to Joystick mapping - can be changed and reloaded from XML
if ( tc1.TabCount > 0 ) { cbJs1.SelectedIndex = 0; m_AT.ActionMaps.js1 = cbJs1.Text; }
@ -215,7 +215,7 @@ namespace SCJMapper_V2
return false;
}
InitActionTree( );
InitActionTree( false );
return true;
}
@ -302,6 +302,16 @@ namespace SCJMapper_V2
btGrab.BackColor = btClear.BackColor; btGrab.UseVisualStyleBackColor = btClear.UseVisualStyleBackColor; // neutral again
}
private void btReset_Click( object sender, EventArgs e )
{
InitActionTree( false ); // start over
}
private void btResetDefaults_Click( object sender, EventArgs e )
{
InitActionTree( true ); // start over and load defaults from SC game
}
private void tsiCopy_Click( object sender, EventArgs e )
{
rtb.Focus( );
@ -329,11 +339,6 @@ namespace SCJMapper_V2
btGrab.BackColor = MyColors.DirtyColor;
}
private void btReset_Click( object sender, EventArgs e )
{
InitActionTree( ); // start over
}
private void tsiOpen_Click( object sender, EventArgs e )
{
if ( OFD.ShowDialog( this ) == System.Windows.Forms.DialogResult.OK ) {
@ -398,5 +403,6 @@ namespace SCJMapper_V2
}
}

@ -392,7 +392,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAQ
DgAAAk1TRnQBSQFMAgEBBwEAAXgBBQF4AQUBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
DgAAAk1TRnQBSQFMAgEBBwEAAZABBQGQAQUBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAASADAAEBAQABCAYAAQgYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA

@ -26,7 +26,7 @@ namespace SCJMapper_V2
{
switch ( device.ToLower( ) ) {
case "keyboard": return "K";
case "joystick": return "J";
case JoystickCls.DeviceName: return "J";
case "xboxpad": return "X";
case "ps3pad": return "P";
default: return "Z";
@ -42,7 +42,7 @@ namespace SCJMapper_V2
{
switch ( devID ) {
case "K": return "keyboard";
case "J": return "joystick";
case "J": return JoystickCls.DeviceName;
case "X": return "xboxpad";
case "P": return "ps3pad";
default: return "unknown";
@ -56,6 +56,7 @@ namespace SCJMapper_V2
public String name { get; set; }
public String device { get; set; }
public String input { get; set; }
public String defBinding { get; set; } // the default binding
/// <summary>
/// ctor
@ -69,7 +70,7 @@ namespace SCJMapper_V2
/// Merge action is simply copying the new input control
/// </summary>
/// <param name="newAc"></param>
public void Merge(ActionCls newAc)
public void Merge( ActionCls newAc )
{
input = newAc.input;
}
@ -81,7 +82,7 @@ namespace SCJMapper_V2
public String toXML( )
{
String r = "";
if (! String.IsNullOrEmpty(input) ) r = String.Format( "\t<action name=\"{0}\">\n\t\t\t<rebind device=\"{1}\" input=\"{2}\" />\n\t\t</action>\n", name, device, input );
if ( !String.IsNullOrEmpty( input ) ) r = String.Format( "\t<action name=\"{0}\">\n\t\t\t<rebind device=\"{1}\" input=\"{2}\" />\n\t\t</action>\n", name, device, input );
return r;
}
@ -96,7 +97,7 @@ namespace SCJMapper_V2
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.IgnoreWhitespace = true;
settings.IgnoreComments = true;
XmlReader reader = XmlReader.Create(new StringReader( xml ), settings);
XmlReader reader = XmlReader.Create( new StringReader( xml ), settings );
reader.Read( );

@ -15,7 +15,7 @@ namespace SCJMapper_V2
// Load MappingVars.csv into the ActionList and create the Control TreeView
public void LoadTree( )
public void LoadTree( Boolean addDefaultBinding )
{
TreeNode tn = null;
TreeNode[] cnl = { };
@ -38,6 +38,7 @@ namespace SCJMapper_V2
txReader = new StringReader( dpReader.CSVMap );
}
Ctrl.BeginUpdate( );
using ( TextReader sr = txReader ) {
String buf = sr.ReadLine( );
while ( !String.IsNullOrEmpty( buf ) ) {
@ -47,17 +48,30 @@ namespace SCJMapper_V2
Array.Resize( ref cnl, 0 );
acm = new ActionMapCls( ); acm.name = elem[0]; // get actionmap name
// process items
for ( int ei=1; ei < elem.Length; ei++ ) {
for ( int ei=1; ei < elem.Length; ei += 2 ) { // step 2 - action;defaultBinding come in pairs
if ( !String.IsNullOrEmpty( elem[ei] ) ) {
String action = elem[ei].Substring( 1 );
String defBinding = elem[ei + 1].Substring( 0 );
cn = new TreeNode( action ); cn.Name = elem[ei]; // name with the key it to find it..
String devID = elem[ei].Substring( 0, 1 );
String device = ActionCls.DeviceFromID( devID );
cn.ImageKey = devID;
Array.Resize( ref cnl, cnl.Length + 1 ); cnl[cnl.Length - 1] = cn;
ac = new ActionCls( ); ac.key = cn.Name; ac.name = action; ac.device = device;
ac = new ActionCls( ); ac.key = cn.Name; ac.name = action; ac.device = device; ac.defBinding = defBinding;
acm.Add( ac ); // add to our map
if ( addDefaultBinding ) {
// right now this application only works with joysticks
if ( JoystickCls.IsJoystick( ac.device ) ) {
int jNum = JoystickCls.JSNum( ac.defBinding );
if ( JoystickCls.IsJSValid( jNum ) ) {
ac.input = ac.defBinding;
cn.Text += " - " + ac.defBinding;
cn.BackColor = MyColors.JColor[jNum - 1]; // color list is 0 based
}
}
}
}
}//for
tn = new TreeNode( acm.name, cnl ); tn.Name = acm.name; // name it to find it..
@ -83,6 +97,8 @@ namespace SCJMapper_V2
Ctrl.ExpandAll( );
if ( topNode != null ) Ctrl.TopNode = topNode;
Dirty = false;
Ctrl.EndUpdate( );
}

@ -52,7 +52,7 @@ namespace SCJMapper_V2
/// <summary>
/// Returns the collected actionmaps as CSV (same format as MappingVars)
/// i.e. one line per actionmap where the first element is the actionmap and following are actions lead by the input Key in uppercase (JKXP)
/// i.e. one line per actionmap where the first element is the actionmap and following are actions;defaultBinding lead by the input Key in uppercase (JKXP)
/// </summary>
public String CSVMap
{
@ -62,7 +62,7 @@ namespace SCJMapper_V2
foreach ( ActionMap am in m_aMap.Values ) {
buf += am.name + ";";
foreach ( Action a in am ) {
buf += a.keyName + ";";
buf += a.keyName + ";" + a.defBinding + ";"; // add default binding to the CSV
}
buf += String.Format( "\n" );
}

@ -8,213 +8,231 @@ using System.Windows.Forms;
namespace SCJMapper_V2
{
/// <summary>
/// Handles one JS device as DXInput device
/// In addition provide some static tools to handle JS props here in one place
/// Also owns the GUI i.e. the user control that shows all values
/// </summary>
class JoystickCls
{
#region Static Items
public const String DeviceName = "joystick"; // the device name used throughout this app
static private int JSnum_UNKNOWN = 0;
/// <summary>
/// Handles one JS device as DXInput device
/// In addition provide some static tools to handle JS props here in one place
/// Also owns the GUI i.e. the user control that shows all values
/// Returns true if the devicename is a joystick
/// </summary>
class JoystickCls
/// <param name="device"></param>
/// <returns></returns>
static public Boolean IsJoystick( String device )
{
private Joystick m_device;
private JoystickState m_state = new JoystickState();
private JoystickState m_prevState = new JoystickState();
private Control m_hwnd;
private int m_numPOVs = 0; // static counter for UpdateControls
private int m_sliderCount = 0; // static counter for UpdateControls
private String m_lastItem = "";
private UC_JoyPanel m_jPanel = null; // the GUI panel
/// <summary>
/// Returns a CryEngine compatible hat direction
/// </summary>
/// <param name="value">The Hat value</param>
/// <returns>The direction string</returns>
private String HatDir(int value)
{
// Hats have a 360deg -> 36000 value reporting
if (value == 0) return "up";
if (value == 9000) return "right";
if (value == 18000) return "down";
if (value == 27000) return "left";
return "";
}
return ( device == DeviceName );
}
/// <summary>
/// Returns properly formatted jsn_ string
/// </summary>
/// <param name="jsNum">The JS number</param>
/// <returns>The formatted JS name for the CryEngine XML</returns>
static public String JSTag(int jsNum)
{
return "js" + jsNum.ToString() + "_";
}
/// <summary>
/// Returns properly formatted jsn_ string
/// </summary>
/// <param name="jsNum">The JS number</param>
/// <returns>The formatted JS name for the CryEngine XML</returns>
static public String JSTag( int jsNum )
{
if ( IsJSValid( jsNum ) ) return "js" + jsNum.ToString( ) + "_";
else return "";
}
/// <summary>
/// Extract the JS number from a JS string
/// </summary>
/// <param name="jsTag">The JS string</param>
/// <returns>The JS number</returns>
static public int JSNum(String jsTag)
{
int retNum = 0;
if (!String.IsNullOrEmpty(jsTag))
{
int.TryParse(jsTag.Substring(2, 1), out retNum);
}
return retNum;
}
/// <summary>
/// The povides the JS ProductName property
/// </summary>
public String DevName { get { return m_device.Properties.ProductName; } }
public int AxisCount { get { return m_device.Capabilities.AxeCount; } }
public int ButtonCount { get { return m_device.Capabilities.ButtonCount; } }
public int POVCount { get { return m_device.Capabilities.PovCount; } }
/// <summary>
/// ctor and init
/// </summary>
/// <param name="device">A DXInput device</param>
/// <param name="hwnd">The WinHandle of the main window</param>
/// <param name="panel">The respective JS panel to show the properties</param>
public JoystickCls(Joystick device, Control hwnd, UC_JoyPanel panel)
{
m_device = device;
m_hwnd = hwnd;
m_jPanel = panel;
// Set BufferSize in order to use buffered data.
m_device.Properties.BufferSize = 128;
m_jPanel.Caption = DevName;
m_jPanel.nAxis = AxisCount.ToString();
m_jPanel.nButtons = ButtonCount.ToString();
m_jPanel.nPOVs = POVCount.ToString();
// Set the data format to the c_dfDIJoystick pre-defined format.
//m_device.SetDataFormat( DeviceDataFormat.Joystick );
// Set the cooperative level for the device.
m_device.SetCooperativeLevel(m_hwnd, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
// Enumerate all the objects on the device.
foreach (DeviceObjectInstance d in m_device.GetObjects())
{
// For axes that are returned, set the DIPROP_RANGE property for the
// enumerated axis in order to scale min/max values.
if ((0 != (d.ObjectId.Flags & DeviceObjectTypeFlags.Axis)))
{
// Set the range for the axis.
m_device.Properties.Range = new InputRange(-1000, +1000);
}
// Update the controls to reflect what objects the device supports.
UpdateControls(d);
}
/// <summary>
/// Extract the JS number from a JS string
/// </summary>
/// <param name="jsTag">The JS string</param>
/// <returns>The JS number</returns>
static public int JSNum( String jsTag )
{
int retNum = JSnum_UNKNOWN;
if ( !String.IsNullOrEmpty( jsTag ) ) {
int.TryParse( jsTag.Substring( 2, 1 ), out retNum );
}
return retNum;
}
/// <summary>
/// Returns the validity of a JSnumber
/// Done here to maintain the ownership of how things are done
/// </summary>
/// <param name="jsNum">The JS number</param>
/// <returns>True if it is a valid one</returns>
static public Boolean IsJSValid( int jsNum )
{
return ( jsNum > JSnum_UNKNOWN );
}
#endregion
private Joystick m_device;
private JoystickState m_state = new JoystickState( );
private JoystickState m_prevState = new JoystickState( );
private Control m_hwnd;
private int m_numPOVs = 0; // static counter for UpdateControls
private int m_sliderCount = 0; // static counter for UpdateControls
private String m_lastItem = "";
private UC_JoyPanel m_jPanel = null; // the GUI panel
/// <summary>
/// Returns a CryEngine compatible hat direction
/// </summary>
/// <param name="value">The Hat value</param>
/// <returns>The direction string</returns>
private String HatDir( int value )
{
// Hats have a 360deg -> 36000 value reporting
if ( value == 0 ) return "up";
if ( value == 9000 ) return "right";
if ( value == 18000 ) return "down";
if ( value == 27000 ) return "left";
return "";
}
/// <summary>
/// The povides the JS ProductName property
/// </summary>
public String DevName { get { return m_device.Properties.ProductName; } }
public int AxisCount { get { return m_device.Capabilities.AxeCount; } }
public int ButtonCount { get { return m_device.Capabilities.ButtonCount; } }
public int POVCount { get { return m_device.Capabilities.PovCount; } }
}
/// <summary>
/// Shutdown device access
/// </summary>
public void FinishDX()
{
if (null != m_device)
m_device.Unacquire();
/// <summary>
/// ctor and init
/// </summary>
/// <param name="device">A DXInput device</param>
/// <param name="hwnd">The WinHandle of the main window</param>
/// <param name="panel">The respective JS panel to show the properties</param>
public JoystickCls( Joystick device, Control hwnd, UC_JoyPanel panel )
{
m_device = device;
m_hwnd = hwnd;
m_jPanel = panel;
// Set BufferSize in order to use buffered data.
m_device.Properties.BufferSize = 128;
m_jPanel.Caption = DevName;
m_jPanel.nAxis = AxisCount.ToString( );
m_jPanel.nButtons = ButtonCount.ToString( );
m_jPanel.nPOVs = POVCount.ToString( );
// Set the data format to the c_dfDIJoystick pre-defined format.
//m_device.SetDataFormat( DeviceDataFormat.Joystick );
// Set the cooperative level for the device.
m_device.SetCooperativeLevel( m_hwnd, CooperativeLevel.Exclusive | CooperativeLevel.Foreground );
// Enumerate all the objects on the device.
foreach ( DeviceObjectInstance d in m_device.GetObjects( ) ) {
// For axes that are returned, set the DIPROP_RANGE property for the
// enumerated axis in order to scale min/max values.
if ( ( 0 != ( d.ObjectId.Flags & DeviceObjectTypeFlags.Axis ) ) ) {
// Set the range for the axis.
m_device.Properties.Range = new InputRange( -1000, +1000 );
}
// Update the controls to reflect what objects the device supports.
UpdateControls( d );
}
}
/// <summary>
/// Shutdown device access
/// </summary>
public void FinishDX( )
{
if ( null != m_device )
m_device.Unacquire( );
}
/// <summary>
/// Enable the properties that are supported by the device
/// </summary>
/// <param name="d"></param>
private void UpdateControls(DeviceObjectInstance d)
{
// Set the UI to reflect what objects the joystick supports.
if (ObjectGuid.XAxis == d.ObjectType)
{
m_jPanel.Xe = true;
m_jPanel.Xname = d.Name + ":";
}
if (ObjectGuid.YAxis == d.ObjectType)
{
m_jPanel.Ye = true;
m_jPanel.Yname = d.Name + ":";
}
if (ObjectGuid.ZAxis == d.ObjectType)
{
m_jPanel.Ze = true;
m_jPanel.Zname = d.Name + ":";
}
if (ObjectGuid.RxAxis == d.ObjectType)
{
m_jPanel.Xre = true;
m_jPanel.Xrname = d.Name + ":";
}
if (ObjectGuid.RyAxis == d.ObjectType)
{
m_jPanel.Yre = true;
m_jPanel.Yrname = d.Name + ":";
}
if (ObjectGuid.RzAxis == d.ObjectType)
{
m_jPanel.Zre = true;
m_jPanel.Zrname = d.Name + ":";
}
if (ObjectGuid.Slider == d.ObjectType)
{
switch (m_sliderCount++)
{
case 0:
m_jPanel.S1e = true;
m_jPanel.S1name = d.Name + ":";
break;
case 1:
m_jPanel.S2e = true;
m_jPanel.S2name = d.Name + ":";
break;
}
}
if (ObjectGuid.PovController == d.ObjectType)
{
switch (m_numPOVs++)
{
case 0:
m_jPanel.H1e = true;
m_jPanel.H1name = d.Name + ":";
break;
case 1:
m_jPanel.H2e = true;
m_jPanel.H2name = d.Name + ":";
break;
case 2:
m_jPanel.H3e = true;
m_jPanel.H3name = d.Name + ":";
break;
case 3:
m_jPanel.H4e = true;
m_jPanel.H4name = d.Name + ":";
break;
}
}
/// <summary>
/// Enable the properties that are supported by the device
/// </summary>
/// <param name="d"></param>
private void UpdateControls( DeviceObjectInstance d )
{
// Set the UI to reflect what objects the joystick supports.
if ( ObjectGuid.XAxis == d.ObjectType ) {
m_jPanel.Xe = true;
m_jPanel.Xname = d.Name + ":";
}
if ( ObjectGuid.YAxis == d.ObjectType ) {
m_jPanel.Ye = true;
m_jPanel.Yname = d.Name + ":";
}
if ( ObjectGuid.ZAxis == d.ObjectType ) {
m_jPanel.Ze = true;
m_jPanel.Zname = d.Name + ":";
}
if ( ObjectGuid.RxAxis == d.ObjectType ) {
m_jPanel.Xre = true;
m_jPanel.Xrname = d.Name + ":";
}
if ( ObjectGuid.RyAxis == d.ObjectType ) {
m_jPanel.Yre = true;
m_jPanel.Yrname = d.Name + ":";
}
if ( ObjectGuid.RzAxis == d.ObjectType ) {
m_jPanel.Zre = true;
m_jPanel.Zrname = d.Name + ":";
}
if ( ObjectGuid.Slider == d.ObjectType ) {
switch ( m_sliderCount++ ) {
case 0:
m_jPanel.S1e = true;
m_jPanel.S1name = d.Name + ":";
break;
case 1:
m_jPanel.S2e = true;
m_jPanel.S2name = d.Name + ":";
break;
}
}
if ( ObjectGuid.PovController == d.ObjectType ) {
switch ( m_numPOVs++ ) {
case 0:
m_jPanel.H1e = true;
m_jPanel.H1name = d.Name + ":";
break;
case 1:
m_jPanel.H2e = true;
m_jPanel.H2name = d.Name + ":";
break;
case 2:
m_jPanel.H3e = true;
m_jPanel.H3name = d.Name + ":";
break;
case 3:
m_jPanel.H4e = true;
m_jPanel.H4name = d.Name + ":";
break;
}
}
}
/// <summary>
/// Find the last change the user did on that device
/// </summary>
/// <returns>The last action as CryEngine compatible string</returns>
public String GetLastChange()
{
// TODO: Expand this out into a joystick class (see commit for details)
Dictionary<string, string> axies = new Dictionary<string, string>()
/// <summary>
/// Find the last change the user did on that device
/// </summary>
/// <returns>The last action as CryEngine compatible string</returns>
public String GetLastChange( )
{
// TODO: Expand this out into a joystick class (see commit for details)
Dictionary<string, string> axies = new Dictionary<string, string>( )
{
{"X","x"},
{"Y","y"},
@ -224,146 +242,137 @@ namespace SCJMapper_V2
{"RotationZ","rotz"}
};
foreach (KeyValuePair<string, string> entry in axies)
{
PropertyInfo axisProperty = typeof(JoystickState).GetProperty(entry.Key);
if (DidAxisChange((int)axisProperty.GetValue(this.m_state, null), (int)axisProperty.GetValue(this.m_prevState, null)))
this.m_lastItem = entry.Value;
}
int[] slider = m_state.Sliders;
int[] pslider = m_prevState.Sliders;
if (slider[0] != pslider[0]) m_lastItem = "slider1";
if (slider[1] != pslider[1]) m_lastItem = "slider2";
int[] pov = m_state.PointOfViewControllers;
int[] ppov = m_prevState.PointOfViewControllers;
if (pov[0] >= 0) if (pov[0] != ppov[0]) m_lastItem = "hat1_" + HatDir(pov[0]);
if (pov[1] >= 0) if (pov[1] != ppov[1]) m_lastItem = "hat2_" + HatDir(pov[0]);
if (pov[2] >= 0) if (pov[2] != ppov[2]) m_lastItem = "hat3_" + HatDir(pov[0]);
if (pov[3] >= 0) if (pov[3] != ppov[3]) m_lastItem = "hat4_" + HatDir(pov[0]);
bool[] buttons = m_state.Buttons;
bool[] prevButtons = m_prevState.Buttons;
for (int bi = 0; bi < buttons.Length; bi++)
{
if (buttons[bi] && buttons[bi] != prevButtons[bi])
m_lastItem = "button" + (bi + 1).ToString();
}
return m_lastItem;
}
foreach ( KeyValuePair<string, string> entry in axies ) {
PropertyInfo axisProperty = typeof( JoystickState ).GetProperty( entry.Key );
if ( DidAxisChange( ( int )axisProperty.GetValue( this.m_state, null ), ( int )axisProperty.GetValue( this.m_prevState, null ) ) )
this.m_lastItem = entry.Value;
}
int[] slider = m_state.Sliders;
int[] pslider = m_prevState.Sliders;
if ( slider[0] != pslider[0] ) m_lastItem = "slider1";
if ( slider[1] != pslider[1] ) m_lastItem = "slider2";
int[] pov = m_state.PointOfViewControllers;
int[] ppov = m_prevState.PointOfViewControllers;
if ( pov[0] >= 0 ) if ( pov[0] != ppov[0] ) m_lastItem = "hat1_" + HatDir( pov[0] );
if ( pov[1] >= 0 ) if ( pov[1] != ppov[1] ) m_lastItem = "hat2_" + HatDir( pov[0] );
if ( pov[2] >= 0 ) if ( pov[2] != ppov[2] ) m_lastItem = "hat3_" + HatDir( pov[0] );
if ( pov[3] >= 0 ) if ( pov[3] != ppov[3] ) m_lastItem = "hat4_" + HatDir( pov[0] );
bool[] buttons = m_state.Buttons;
bool[] prevButtons = m_prevState.Buttons;
for ( int bi = 0; bi < buttons.Length; bi++ ) {
if ( buttons[bi] && buttons[bi] != prevButtons[bi] )
m_lastItem = "button" + ( bi + 1 ).ToString( );
}
return m_lastItem;
}
///<summary>
/// Figure out if an axis changed enough to consider it as a changed state
/// </summary>
private bool DidAxisChange(int current, int prev)
{
// determine if the axis drifts more than x% to account for bounce
// old-new/old
if (current == prev)
return false;
if (prev == 0)
prev = 1;
int changepct = Math.Abs(prev) - Math.Abs(current) / Math.Abs(prev);
// if the axis has changed more than 70% relative to it's last value
return changepct > 70 ? true : false;
///<summary>
/// Figure out if an axis changed enough to consider it as a changed state
/// </summary>
private bool DidAxisChange( int current, int prev )
{
// determine if the axis drifts more than x% to account for bounce
// old-new/old
if ( current == prev )
return false;
if ( prev == 0 )
prev = 1;
int changepct = Math.Abs( prev ) - Math.Abs( current ) / Math.Abs( prev );
// if the axis has changed more than 70% relative to it's last value
return changepct > 70 ? true : false;
}
}
/// <summary>
/// Show the current props in the GUI
/// </summary>
private void UpdateUI()
{
// This function updated the UI with joystick state information.
string strText = null;
/// <summary>
/// Show the current props in the GUI
/// </summary>
private void UpdateUI( )
{
// This function updated the UI with joystick state information.
string strText = null;
m_jPanel.X = m_state.X.ToString();
m_jPanel.Y = m_state.Y.ToString();
m_jPanel.Z = m_state.Z.ToString();
m_jPanel.X = m_state.X.ToString( );
m_jPanel.Y = m_state.Y.ToString( );
m_jPanel.Z = m_state.Z.ToString( );
m_jPanel.Xr = m_state.RotationX.ToString();
m_jPanel.Yr = m_state.RotationY.ToString();
m_jPanel.Zr = m_state.RotationZ.ToString();
m_jPanel.Xr = m_state.RotationX.ToString( );
m_jPanel.Yr = m_state.RotationY.ToString( );
m_jPanel.Zr = m_state.RotationZ.ToString( );
int[] slider = m_state.Sliders;
int[] slider = m_state.Sliders;
m_jPanel.S1 = slider[0].ToString();
m_jPanel.S2 = slider[1].ToString();
m_jPanel.S1 = slider[0].ToString( );
m_jPanel.S2 = slider[1].ToString( );
int[] pov = m_state.PointOfViewControllers;
int[] pov = m_state.PointOfViewControllers;
m_jPanel.H1 = pov[0].ToString();
m_jPanel.H2 = pov[1].ToString();
m_jPanel.H3 = pov[2].ToString();
m_jPanel.H4 = pov[3].ToString();
m_jPanel.H1 = pov[0].ToString( );
m_jPanel.H2 = pov[1].ToString( );
m_jPanel.H3 = pov[2].ToString( );
m_jPanel.H4 = pov[3].ToString( );
// Fill up text with which buttons are pressed
bool[] buttons = m_state.Buttons;
// Fill up text with which buttons are pressed
bool[] buttons = m_state.Buttons;
int button = 0;
foreach (bool b in buttons)
{
if (b)
strText += (button + 1).ToString("00 "); // buttons are 1 based
button++;
}
m_jPanel.Button = strText;
}
int button = 0;
foreach ( bool b in buttons ) {
if ( b )
strText += ( button + 1 ).ToString( "00 " ); // buttons are 1 based
button++;
}
m_jPanel.Button = strText;
}
/// <summary>
/// Collect the current data from the device
/// </summary>
public void GetData()
{
// Make sure there is a valid device.
if (null == m_device)
return;
// Poll the device for info.
try
{
m_device.Poll();
}
catch (SharpDXException e)
{
if ((e.ResultCode == ResultCode.NotAcquired) || (e.ResultCode == ResultCode.InputLost))
{
// Check to see if either the app needs to acquire the device, or
// if the app lost the device to another process.
try
{
// Acquire the device.
m_device.Acquire();
}
catch (SharpDXException)
{
// Failed to acquire the device.
// This could be because the app doesn't have focus.
return;
}
}
}
// Get the state of the device - retaining the previous state to find the lates change
m_prevState = m_state;
try { m_state = m_device.GetCurrentState(); }
// Catch any exceptions. None will be handled here,
// any device re-aquisition will be handled above.
catch (SharpDXException)
{
return;
}
UpdateUI(); // and update the GUI
/// <summary>
/// Collect the current data from the device
/// </summary>
public void GetData( )
{
// Make sure there is a valid device.
if ( null == m_device )
return;
// Poll the device for info.
try {
m_device.Poll( );
}
catch ( SharpDXException e ) {
if ( ( e.ResultCode == ResultCode.NotAcquired ) || ( e.ResultCode == ResultCode.InputLost ) ) {
// Check to see if either the app needs to acquire the device, or
// if the app lost the device to another process.
try {
// Acquire the device.
m_device.Acquire( );
}
catch ( SharpDXException ) {
// Failed to acquire the device.
// This could be because the app doesn't have focus.
return;
}
}
}
// Get the state of the device - retaining the previous state to find the lates change
m_prevState = m_state;
try { m_state = m_device.GetCurrentState( ); }
// Catch any exceptions. None will be handled here,
// any device re-aquisition will be handled above.
catch ( SharpDXException ) {
return;
}
UpdateUI( ); // and update the GUI
}
}
}

Loading…
Cancel
Save