Second V2.8 - more BETA now

Supports Gamepad Tuning too, cleanup and some refactoring
pull/104/head v2.8beta
bm98 10 years ago
parent 7dc4b37164
commit 44a37ce10c

@ -11,9 +11,9 @@ namespace SCJMapper_V2
/// </summary>
public abstract class DeviceCls
{
public const String DeviceName ="UNDEF";
public const String DeviceClass ="UNDEF";
public const String BlendedInput = " ";
static public Boolean IsDevice( String device ) { return false; }
static public Boolean IsDeviceClass( String deviceClass ) { return false; }
public enum InputKind
{
@ -23,6 +23,7 @@ namespace SCJMapper_V2
Gamepad,
}
public abstract String DevClass { get; }
public abstract String DevName { get; }
public abstract System.Drawing.Color MapColor { get; }
@ -31,6 +32,7 @@ namespace SCJMapper_V2
public virtual void ApplySettings( ){}
public abstract String GetLastChange( );
public abstract void GetCmdData( String cmd, out int data );
public abstract void GetData( );
}
}

22
Form1.Designer.cs generated

@ -61,6 +61,7 @@
this.treeView1 = new System.Windows.Forms.TreeView();
this.tc1 = new System.Windows.Forms.TabControl();
this.tabJS1 = new System.Windows.Forms.TabPage();
this.UC_JoyPanel = new SCJMapper_V2.UC_JoyPanel();
this.panel1 = new System.Windows.Forms.Panel();
this.btClip = new System.Windows.Forms.Button();
this.txRebind = new System.Windows.Forms.TextBox();
@ -101,7 +102,6 @@
this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.UC_JoyPanel = new SCJMapper_V2.UC_JoyPanel();
this.cmCopyPaste.SuspendLayout();
this.panel2.SuspendLayout();
this.tc1.SuspendLayout();
@ -393,6 +393,15 @@
this.tabJS1.TabIndex = 0;
this.tabJS1.Text = "Joystick 1";
//
// UC_JoyPanel
//
this.UC_JoyPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.UC_JoyPanel.JsAssignment = 0;
this.UC_JoyPanel.Location = new System.Drawing.Point(3, 3);
this.UC_JoyPanel.Name = "UC_JoyPanel";
this.UC_JoyPanel.Size = new System.Drawing.Size(275, 315);
this.UC_JoyPanel.TabIndex = 0;
//
// panel1
//
this.tlpanel.SetColumnSpan(this.panel1, 3);
@ -581,7 +590,7 @@
this.btJSTuning.Name = "btJSTuning";
this.btJSTuning.Size = new System.Drawing.Size(120, 24);
this.btJSTuning.TabIndex = 17;
this.btJSTuning.Text = "Joystick Tuning";
this.btJSTuning.Text = "Device Tuning";
this.btJSTuning.Click += new System.EventHandler(this.btJSTuning_Click);
//
// tableLayoutPanel2
@ -830,15 +839,6 @@
this.statusStrip1.TabIndex = 26;
this.statusStrip1.Text = "statusStrip1";
//
// UC_JoyPanel
//
this.UC_JoyPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.UC_JoyPanel.JsAssignment = 0;
this.UC_JoyPanel.Location = new System.Drawing.Point(3, 3);
this.UC_JoyPanel.Name = "UC_JoyPanel";
this.UC_JoyPanel.Size = new System.Drawing.Size(275, 315);
this.UC_JoyPanel.TabIndex = 0;
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

@ -85,7 +85,7 @@ namespace SCJMapper_V2
return DeviceCls.InputKind.Kbd;
}
else {
if ( IsGamepadTab( tc1.SelectedTab) ) {
if ( IsGamepadTab( tc1.SelectedTab ) ) {
return DeviceCls.InputKind.Gamepad;
}
else {
@ -414,6 +414,7 @@ namespace SCJMapper_V2
UC_JoyPanel.Enabled = false; UC_JoyPanel.Visible = false; // don't use this one
log.Debug( "Create Gamepad instance" );
gs = new GamepadCls( gpDevice, uUC_GpadPanelNew, 0 ); // does all device related activities for that particular item
gs.SetDeviceName( instance.ProductName );
}
else {
log.Debug( "Add first Joystick panel" );
@ -430,6 +431,7 @@ namespace SCJMapper_V2
UC_JoyPanel.Enabled = false; UC_JoyPanel.Visible = false; // don't use this one
log.Debug( "Create Gamepad instance" );
gs = new GamepadCls( gpDevice, uUC_GpadPanelNew, tabs ); // does all device related activities for that particular item
gs.SetDeviceName( instance.ProductName );
}
else {
log.Debug( "Add next Joystick panel" );
@ -508,8 +510,8 @@ namespace SCJMapper_V2
// for all supported jsN
for ( int i=0; i < JoystickCls.JSnum_MAX; i++ ) {
j = null;
if ( !String.IsNullOrEmpty( m_AT.ActionMaps.jsNGUID[i] ) ) j = m_Joystick.Find_jsInstance( m_AT.ActionMaps.jsNGUID[i] );
else if ( !String.IsNullOrEmpty( m_AT.ActionMaps.jsN[i] ) ) j = m_Joystick.Find_jsDev( m_AT.ActionMaps.jsN[i] );
if ( !String.IsNullOrEmpty( m_AT.ActionMaps.jsNGUID[i] ) ) j = m_Joystick.Find_jsInstance( m_AT.ActionMaps.jsNGUID[i] );
else if ( !String.IsNullOrEmpty( m_AT.ActionMaps.jsN[i] ) ) j = m_Joystick.Find_jsDev( m_AT.ActionMaps.jsN[i] );
if ( j != null ) {
m_AT.ActionMaps.jsNGUID[i] = j.DevInstanceGUID; // subst for missing one (version up etc.)
@ -526,8 +528,8 @@ namespace SCJMapper_V2
// maintain the new JsN assignment and update the colorlist
List<int> newL = new List<int>( );
foreach ( TabPage tp in tc1.TabPages ) {
if ( IsGamepadTab( tp ) ) newL.Add( 0 );
else newL.Add( m_Joystick[(int)tp.Tag].JSAssignment );
if ( IsGamepadTab( tp ) ) newL.Add( 0 );
else newL.Add( m_Joystick[( int )tp.Tag].JSAssignment );
}
JoystickCls.ReassignJsColor( newL );
@ -962,51 +964,108 @@ namespace SCJMapper_V2
JSCAL = new FormJSCalCurve( );
// get current mapping from ActionMaps
String cmd = "";
String nodeText = "";
// attach Yaw command
cmd = m_AT.FindCommand( "v_yaw - js" );
if ( cmd.ToLowerInvariant( ).EndsWith( "x" ) ) {
m_AT.ActionMaps.TuningX.Command = cmd;
JSCAL.YawTuning = m_AT.ActionMaps.TuningX;
DeviceCls dev = null;
nodeText = m_AT.FindText( "v_yaw - js" ); // returns "" or a complete text ("action - command")
if ( !String.IsNullOrWhiteSpace( nodeText ) ) {
dev = m_Joystick.Find_jsN( JoystickCls.JSNum( ActionTreeNode.CommandFromNodeText( nodeText ) ) );
}
else if ( cmd.ToLowerInvariant( ).EndsWith( "y" ) ) {
m_AT.ActionMaps.TuningY.Command = cmd;
JSCAL.YawTuning = m_AT.ActionMaps.TuningY;
else {
nodeText = m_AT.FindText( "v_yaw - xi" );
if ( !String.IsNullOrWhiteSpace( nodeText ) ) {
dev = m_Gamepad;
}
}
else if ( cmd.ToLowerInvariant( ).EndsWith( "z" ) ) {
m_AT.ActionMaps.TuningZ.Command = cmd;
JSCAL.YawTuning = m_AT.ActionMaps.TuningZ;
if ( dev != null ) {
// JS commands that are supported
if ( nodeText.ToLowerInvariant( ).EndsWith( "_x" ) || nodeText.ToLowerInvariant( ).EndsWith( "_rotx" ) ) {
m_AT.ActionMaps.TuningX.JsDevice = dev;
m_AT.ActionMaps.TuningX.Command = nodeText;
JSCAL.YawTuning = m_AT.ActionMaps.TuningX;
}
else if ( nodeText.ToLowerInvariant( ).EndsWith( "_y" ) || nodeText.ToLowerInvariant( ).EndsWith( "_roty" ) ) {
m_AT.ActionMaps.TuningY.JsDevice = dev;
m_AT.ActionMaps.TuningY.Command = nodeText;
JSCAL.YawTuning = m_AT.ActionMaps.TuningY;
}
else if ( nodeText.ToLowerInvariant( ).EndsWith( "_z" ) || nodeText.ToLowerInvariant( ).EndsWith( "_rotz" ) ) {
m_AT.ActionMaps.TuningZ.JsDevice = dev;
m_AT.ActionMaps.TuningZ.Command = nodeText;
JSCAL.YawTuning = m_AT.ActionMaps.TuningZ;
}
// GP commands that are supported - X
else if ( nodeText.ToLowerInvariant( ).Contains( "_thumblx" ) || nodeText.ToLowerInvariant( ).Contains( "_thumbrx" ) ) {
m_AT.ActionMaps.TuningX.JsDevice = dev;
m_AT.ActionMaps.TuningX.Command = nodeText;
JSCAL.YawTuning = m_AT.ActionMaps.TuningX;
}
}
// attach Pitch command
cmd = m_AT.FindCommand( "v_pitch - js" );
if ( cmd.ToLowerInvariant( ).EndsWith( "x" ) ) {
m_AT.ActionMaps.TuningX.Command = cmd;
JSCAL.PitchTuning = m_AT.ActionMaps.TuningX;
}
else if ( cmd.ToLowerInvariant( ).EndsWith( "y" ) ) {
m_AT.ActionMaps.TuningY.Command = cmd;
JSCAL.PitchTuning = m_AT.ActionMaps.TuningY;
dev = null;
nodeText = m_AT.FindText( "v_pitch - js" );
if ( !String.IsNullOrWhiteSpace( nodeText ) ) {
dev = m_Joystick.Find_jsN( JoystickCls.JSNum( ActionTreeNode.CommandFromNodeText( nodeText ) ) );
}
else if ( cmd.ToLowerInvariant( ).EndsWith( "z" ) ) {
m_AT.ActionMaps.TuningZ.Command = cmd;
JSCAL.PitchTuning = m_AT.ActionMaps.TuningZ;
else {
nodeText = m_AT.FindText( "v_pitch - xi" );
if ( !String.IsNullOrWhiteSpace( nodeText ) ) {
dev = m_Gamepad;
}
}
// attach Roll command
cmd = m_AT.FindCommand( "v_roll - js" );
if ( cmd.ToLowerInvariant( ).EndsWith( "x" ) ) {
m_AT.ActionMaps.TuningX.Command = cmd;
JSCAL.RollTuning = m_AT.ActionMaps.TuningX;
if ( dev != null ) {
// JS commands that are supported
if ( nodeText.ToLowerInvariant( ).EndsWith( "_x" ) || nodeText.ToLowerInvariant( ).EndsWith( "_rotx" ) ) {
m_AT.ActionMaps.TuningX.JsDevice = dev;
m_AT.ActionMaps.TuningX.Command = nodeText;
JSCAL.PitchTuning = m_AT.ActionMaps.TuningX;
}
else if ( nodeText.ToLowerInvariant( ).EndsWith( "_y" ) || nodeText.ToLowerInvariant( ).EndsWith( "_roty" ) ) {
m_AT.ActionMaps.TuningY.JsDevice = dev;
m_AT.ActionMaps.TuningY.Command = nodeText;
JSCAL.PitchTuning = m_AT.ActionMaps.TuningY;
}
else if ( nodeText.ToLowerInvariant( ).EndsWith( "_z" ) || nodeText.ToLowerInvariant( ).EndsWith( "_rotz" ) ) {
m_AT.ActionMaps.TuningZ.JsDevice = dev;
m_AT.ActionMaps.TuningZ.Command = nodeText;
JSCAL.PitchTuning = m_AT.ActionMaps.TuningZ;
}
// GP commands that are supported - either Y
else if ( nodeText.ToLowerInvariant( ).Contains( "_thumbly" ) || nodeText.ToLowerInvariant( ).Contains( "_thumbry" ) ) {
m_AT.ActionMaps.TuningY.JsDevice = dev;
m_AT.ActionMaps.TuningY.Command = nodeText;
JSCAL.PitchTuning = m_AT.ActionMaps.TuningY;
}
}
else if ( cmd.ToLowerInvariant( ).EndsWith( "y" ) ) {
m_AT.ActionMaps.TuningY.Command = cmd;
JSCAL.RollTuning = m_AT.ActionMaps.TuningY;
// attach Roll command - cannot use gamepad here
dev = null;
nodeText = m_AT.FindText( "v_roll - js" );
if ( !String.IsNullOrWhiteSpace( nodeText ) ) {
dev = m_Joystick.Find_jsN( JoystickCls.JSNum( ActionTreeNode.CommandFromNodeText( nodeText ) ) );
}
else if ( cmd.ToLowerInvariant( ).EndsWith( "z" ) ) {
m_AT.ActionMaps.TuningZ.Command = cmd;
JSCAL.RollTuning = m_AT.ActionMaps.TuningZ;
if ( dev != null ) {
// JS commands that are supported
if ( nodeText.ToLowerInvariant( ).EndsWith( "_x" ) || nodeText.ToLowerInvariant( ).EndsWith( "_rotx" ) ) {
m_AT.ActionMaps.TuningX.JsDevice = dev;
m_AT.ActionMaps.TuningX.Command = nodeText;
JSCAL.RollTuning = m_AT.ActionMaps.TuningX;
}
else if ( nodeText.ToLowerInvariant( ).EndsWith( "_y" ) || nodeText.ToLowerInvariant( ).EndsWith( "_roty" ) ) {
m_AT.ActionMaps.TuningY.JsDevice = dev;
m_AT.ActionMaps.TuningY.Command = nodeText;
JSCAL.RollTuning = m_AT.ActionMaps.TuningY;
}
else if ( nodeText.ToLowerInvariant( ).EndsWith( "_z" ) || nodeText.ToLowerInvariant( ).EndsWith( "_rotz" ) ) {
m_AT.ActionMaps.TuningZ.JsDevice = dev;
m_AT.ActionMaps.TuningZ.Command = nodeText;
JSCAL.RollTuning = m_AT.ActionMaps.TuningZ;
}
}
// run

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

@ -22,7 +22,7 @@ namespace SCJMapper_V2
#region Static Items
public new const String DeviceName = "xboxpad"; // the device name used throughout this app
public new const String DeviceClass = "xboxpad"; // the device name used throughout this app
public const String JsUnknown = "xi_";
public new const String BlendedInput = "xi_reserved";
@ -39,11 +39,11 @@ namespace SCJMapper_V2
/// <summary>
/// Returns true if the devicename is a gamepad
/// </summary>
/// <param name="device"></param>
/// <param name="deviceClass"></param>
/// <returns></returns>
static public new Boolean IsDevice( String device )
static public new Boolean IsDeviceClass( String deviceClass )
{
return ( device == DeviceName );
return ( deviceClass == DeviceClass );
}
/// <summary>
@ -72,7 +72,7 @@ namespace SCJMapper_V2
#endregion
private Controller m_device;
private String m_devName = "Generic Gamepad";
private Capabilities m_gpCaps = new Capabilities( );
private State m_state = new State( );
@ -86,12 +86,23 @@ namespace SCJMapper_V2
internal int MyTabPageIndex = -1;
/// <summary>
/// The DeviceClass of this instance
/// </summary>
public override String DevClass { get { return GamepadCls.DeviceClass; } }
/// <summary>
/// The JS ProductName property
/// </summary>
public override String DevName { get { return "Generic Gamepad"; } }
public override String DevName { get { return m_devName; } }
/// <summary>
public void SetDeviceName( String devName )
{
m_devName = devName;
m_gPanel.Caption = DevName;
}
/// <summary>
/// Returns the mapping color for this device
/// </summary>
@ -350,6 +361,40 @@ namespace SCJMapper_V2
}
/// <summary>
/// Collect the current data from the device
/// </summary>
public override void GetCmdData( String cmd, out int data )
{
// Make sure there is a valid device.
if ( m_device == null ) {
data = 0;
return;
}
// Get the state of the device - retaining the previous state to find the lates change
m_prevState = m_state;
// Poll the device for info.
try {
m_state = m_device.GetState( );
switch ( cmd ) {
case "xi_thumblx": data = (int) ((float)m_state.Gamepad.LeftThumbX/32.767f); break; // data should be -1000..1000
case "xi_thumbly": data = (int) ((float)m_state.Gamepad.LeftThumbY/32.767f); break;
case "xi_thumbrx": data = (int) ((float)m_state.Gamepad.RightThumbX/32.767f); break;
case "xi_thumbry": data = ( int )( ( float )m_state.Gamepad.RightThumbY / 32.767f ); break;
default: data = 0; break;
}
}
catch ( SharpDXException e ) {
log.Error( "Gamepad-GetData: Unexpected Poll Exception", e );
data = 0;
return; // EXIT see ex code
}
}
/// <summary>
/// Collect the current data from the device

@ -28,9 +28,9 @@ namespace SCJMapper_V2
List<String> m_stringOptions = new List<String>( );
Options m_options = null;
JoystickTuningParameter m_tuningX = null;
JoystickTuningParameter m_tuningY = null;
JoystickTuningParameter m_tuningZ = null;
DeviceTuningParameter m_tuningX = null;
DeviceTuningParameter m_tuningY = null;
DeviceTuningParameter m_tuningZ = null;
// ctor
public Deviceoptions( Options options )

@ -22,7 +22,7 @@ namespace SCJMapper_V2
#region Static Items
public new const String DeviceName = "joystick"; // the device name used throughout this app
public new const String DeviceClass = "joystick"; // the device name used throughout this app
public const String JsUnknown = "jsx_";
public new const String BlendedInput = "jsx_reserved";
@ -69,14 +69,52 @@ namespace SCJMapper_V2
/// <summary>
/// Returns true if the devicename is a joystick
/// </summary>
/// <param name="device"></param>
/// <param name="deviceClass"></param>
/// <returns></returns>
static public new Boolean IsDevice( String device )
static public new Boolean IsDeviceClass( String deviceClass )
{
return ( device == DeviceName );
return ( deviceClass == DeviceClass );
}
public static void DecompJsCommand( String jsCmd, out String jsTag, out String sAction )
{
jsTag = ""; sAction = "";
String[] e = jsCmd.Split( new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries );
if ( e.Length > 1 ) {
jsTag = e[0].Trim( ) + "_";
sAction = e[1].Trim( );
}
}
/// <summary>
/// Returns the jsN part from a joystick command
/// i.e. js1_x returns js1
/// </summary>
/// <param name="jsCmd">The joystick command in 'jsN_command' notation</param>
/// <returns>the jsN part or an empty string</returns>
public static String JsTagFromJsCommand( String jsCmd )
{
String jsTag, sAction;
DecompJsCommand( jsCmd, out jsTag, out sAction );
return jsTag;
}
/// <summary>
/// Returns the stick action part from a node text
/// i.e. js1_x returns x
/// </summary>
/// <param name="jsCmd">The joystick command in 'jsN_command' notation</param>
/// <returns>the stick action part or an empty string</returns>
public static String ActionFromJsCommand( String jsCmd )
{
String jsTag, sAction;
DecompJsCommand( jsCmd, out jsTag, out sAction );
return sAction;
}
/// <summary>
/// Returns properly formatted jsn_ string (jsx_ if the input is UNKNOWN)
/// </summary>
@ -222,6 +260,10 @@ namespace SCJMapper_V2
}
/// <summary>
/// The DeviceClass of this instance
/// </summary>
public override String DevClass { get { return JoystickCls.DeviceClass; } }
/// <summary>
/// The JS ProductName property
/// </summary>
@ -629,7 +671,7 @@ namespace SCJMapper_V2
/// <summary>
/// Collect the current data from the device
/// </summary>
public void GetCmdData( String cmd, out int data )
public override void GetCmdData( String cmd, out int data )
{
// TODO: Expand this out into a joystick class (see commit for details)
Dictionary<string, string> axies = new Dictionary<string, string>( )

@ -9,13 +9,14 @@ namespace SCJMapper_V2
/// <summary>
/// set of parameters to tune the Joystick
/// </summary>
public class JoystickTuningParameter
public class DeviceTuningParameter
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
private String m_command = ""; // v_pitch - js1_x ..
private String m_cmdCtrl = ""; // x, y, rotz ...
private int m_jsN = 0; // jsN
private String m_type = ""; // joystick OR xboxpad
private int m_devInstanceNo = -1; // jsN - instance in XML
String m_option = ""; // the option name (level where it applies)
@ -36,31 +37,35 @@ namespace SCJMapper_V2
private List<String> m_PtsIn = new List<String>( );
private List<String> m_PtsOut = new List<String>( );
private JoystickList m_joystickList = null;
private JoystickCls m_js = null;
private DeviceCls m_device = null;
public JoystickTuningParameter( JoystickList jsList )
public DeviceTuningParameter( )
{
m_joystickList = jsList;
}
#region Properties
public JoystickCls JsDevice
public DeviceCls JsDevice
{
get { return m_js; }
get { return m_device; }
set { m_device = value;
m_type = "";
m_devInstanceNo = -1;
if ( JoystickCls.IsDeviceClass( m_device.DevClass ) ) {
m_type = m_device.DevClass;
m_devInstanceNo = (m_device as JoystickCls).JSAssignment;
}
else if ( GamepadCls.IsDeviceClass( m_device.DevClass ) ) {
m_type = m_device.DevClass;
m_devInstanceNo = 1; // supports ONE gamepad
}
}
}
public int JsN
public int DevInstanceNo
{
get { return m_jsN; }
set
{
m_jsN = value;
m_js = m_joystickList.Find_jsN( m_jsN );
m_deviceName = m_js.DevName;
}
get { return m_devInstanceNo; }
}
public String DeviceName
@ -151,15 +156,47 @@ namespace SCJMapper_V2
private void DecomposeCommand( )
{
// pobulate from input
String[] e = Command.Split( new Char[] { '-' } ); // v_pitch - js1_x
m_cmdCtrl = ""; m_jsN = 0;
if ( e.Length > 1 ) {
// get parts
m_cmdCtrl = e[1].Trim( ).Split( new Char[] { '_' } )[1]; //js1_x -> x
m_jsN = JoystickCls.JSNum( e[1].Trim( ) ); // get the right Joystick from jsN
m_js = m_joystickList.Find_jsN( m_jsN );
m_deviceName = m_js.DevName;
m_option = String.Format( "pilot_move_{0}", m_cmdCtrl ); // update from Command
// something like "v_pitch - js1_x" OR "v_pitch - xi_thumbl" OR "v_pitch - ximod+xi_thumbl+xi_mod"
String cmd = ActionTreeNode.CommandFromNodeText( Command );
String action = ActionTreeNode.ActionFromNodeText( Command );
m_cmdCtrl = "";
if ( !String.IsNullOrWhiteSpace(cmd) ) {
// decomp gamepad entries - could have modifiers so check for contains...
if ( cmd.Contains( "xi_thumblx" ) ) {
// gamepad
m_cmdCtrl = "xi_thumblx";
m_deviceName = m_device.DevName;
if ( action.Contains( "pitch" ) ) m_option = String.Format( "pilot_movepitch" );
else m_option = String.Format( "pilot_moveyaw" );
}
else if ( cmd.Contains( "xi_thumbly" ) ) {
// gamepad
m_cmdCtrl = "xi_thumbly";
m_deviceName = m_device.DevName;
if ( action.Contains( "pitch" ) ) m_option = String.Format( "pilot_movepitch" );
else m_option = String.Format( "pilot_moveyaw" );
}
else if ( cmd.Contains( "xi_thumbrx" ) ) {
// gamepad
m_cmdCtrl = "xi_thumbrx";
m_deviceName = m_device.DevName;
if ( action.Contains( "pitch" ) ) m_option = String.Format( "pilot_movepitch" );
else m_option = String.Format( "pilot_moveyaw" );
}
else if ( cmd.Contains( "xi_thumbry" ) ) {
// gamepad
m_cmdCtrl = "xi_thumbry";
m_deviceName = m_device.DevName;
if ( action.Contains( "pitch" ) ) m_option = String.Format( "pilot_movepitch" );
else m_option = String.Format( "pilot_moveyaw" );
}
// assume joystick
else {
// get parts
m_cmdCtrl = JoystickCls.ActionFromJsCommand( cmd ); //js1_x -> x; js2_rotz -> rotz
m_deviceName = m_device.DevName;
m_option = String.Format( "pilot_move_{0}", m_cmdCtrl ); // update from Command
}
}
}
@ -196,7 +233,7 @@ namespace SCJMapper_V2
if ( ( m_senseEnabled || m_expEnabled || m_invertEnabled || m_ptsEnabled ) == false ) return ""; // not used
String tmp = "";
tmp += String.Format( "\t<options type=\"joystick\" instance=\"{0}\">\n", m_jsN.ToString( ) );
tmp += String.Format( "\t<options type=\"{0}\" instance=\"{1}\">\n", m_type, m_devInstanceNo.ToString( ) );
tmp += String.Format( "\t\t<{0} ", m_option );
if ( InvertUsed ) {
@ -232,24 +269,26 @@ namespace SCJMapper_V2
/// <summary>
/// Read the options from the XML
/// can get only the 3 ones for Move X,Y,RotZ right now
/// can get only the 3 ones for Move X,Y,RotZ, pitch and yaq right now
/// </summary>
/// <param name="reader">A prepared XML reader</param>
/// <param name="instance">the Josyticj instance number</param>
/// <returns></returns>
public Boolean Options_fromXML( XmlReader reader, int instance )
public Boolean Options_fromXML( XmlReader reader, String type, int instance )
{
m_type = type;
String invert = "";
String sensitivity = "";
String exponent = "";
String instance_inv = "";
m_option = reader.Name;
JsN = instance;
m_devInstanceNo = instance;
// derive from pilot_move_x || pilot_move_rotx (nothing bad should arrive here)
// derive from pilot_move_x || pilot_move_rotx || pilot_moveyaw (nothing bad should arrive here)
String[] e = m_option.ToLowerInvariant( ).Split( new char[] { '_' } );
if ( e.Length >= 2 ) m_cmdCtrl = e[2];
if ( e.Length > 2 ) m_cmdCtrl = e[2]; // TODO - see if m_cmdCtrl is needed to be derived here
if ( reader.HasAttributes ) {

@ -28,16 +28,16 @@ namespace SCJMapper_V2
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
List<String> m_stringOptions = new List<String>( );
JoystickTuningParameter m_tuningX = null;
JoystickTuningParameter m_tuningY = null;
JoystickTuningParameter m_tuningZ = null;
DeviceTuningParameter m_tuningX = null;
DeviceTuningParameter m_tuningY = null;
DeviceTuningParameter m_tuningZ = null;
// ctor
public Options( JoystickList jsList )
{
m_tuningX = new JoystickTuningParameter( jsList ); // can be x or rotx
m_tuningY = new JoystickTuningParameter( jsList ); // can be y or roty
m_tuningZ = new JoystickTuningParameter( jsList ); // can be z or rotz
m_tuningX = new DeviceTuningParameter( ); // can be x or rotx
m_tuningY = new DeviceTuningParameter( ); // can be y or roty
m_tuningZ = new DeviceTuningParameter( ); // can be z or rotz
}
public int Count
@ -51,26 +51,26 @@ namespace SCJMapper_V2
/// <summary>
/// Returns the X-Tuning item
/// </summary>
public JoystickTuningParameter TuneX
public DeviceTuningParameter TuneX
{
get { return m_tuningX; }
}
/// <summary>
/// Returns the Y-Tuning item
/// </summary>
public JoystickTuningParameter TuneY
public DeviceTuningParameter TuneY
{
get { return m_tuningY; }
}
/// <summary>
/// Returns the Z-Tuning item
/// </summary>
public JoystickTuningParameter TuneZ
public DeviceTuningParameter TuneZ
{
get { return m_tuningZ; }
}
/*
/// <summary>
/// reassign the JsN Tag
/// </summary>
@ -83,7 +83,7 @@ namespace SCJMapper_V2
if ( m_tuningZ.JsN == kv.Key ) m_tuningZ.JsN = kv.Value;
}
}
*/
private String[] FormatXml( string xml )
{
@ -176,7 +176,7 @@ namespace SCJMapper_V2
if ( reader.HasAttributes ) {
type = reader["type"];
if ( type.ToLowerInvariant( ) != "joystick" ) {
if ( !(( type.ToLowerInvariant( ) == "joystick") || (type.ToLowerInvariant( ) == "xboxpad") ) ) {
// save as plain text
if ( !m_stringOptions.Contains( xml ) ) m_stringOptions.Add( xml );
return true;
@ -226,13 +226,20 @@ namespace SCJMapper_V2
while ( !reader.EOF ) {
if ( reader.Name == "pilot_move_x" || reader.Name == "pilot_move_rotx" ) {
m_tuningX.Options_fromXML( reader, int.Parse( instance ) );
m_tuningX.Options_fromXML( reader, type, int.Parse( instance ) );
}
else if ( reader.Name == "pilot_move_y" || reader.Name == "pilot_move_roty" ) {
m_tuningY.Options_fromXML( reader, int.Parse( instance ) );
m_tuningY.Options_fromXML( reader, type, int.Parse( instance ) );
}
else if ( reader.Name == "pilot_move_z" || reader.Name == "pilot_move_rotz" ) {
m_tuningZ.Options_fromXML( reader, int.Parse( instance ) );
m_tuningZ.Options_fromXML( reader, type, int.Parse( instance ) );
}
// fixed - get pitch as X and Yaw as Y
else if ( reader.Name == "pilot_movepitch" ) {
m_tuningX.Options_fromXML( reader, type, int.Parse( instance ) );
}
else if ( reader.Name == "pilot_moveyaw" ) {
m_tuningY.Options_fromXML( reader, type, int.Parse( instance ) );
}
else if ( reader.Name == "pilot_throttle" ) {

@ -18,7 +18,7 @@ namespace SCJMapper_V2
#region Static Items
public new const String DeviceName = "keyboard"; // the device name used throughout this app
public new const String DeviceClass = "keyboard"; // the device name used throughout this app
public new const String BlendedInput = " "; // the device name used throughout this app
@ -35,11 +35,11 @@ namespace SCJMapper_V2
/// <summary>
/// Returns true if the devicename is a joystick
/// </summary>
/// <param name="device"></param>
/// <param name="deviceClass"></param>
/// <returns></returns>
static new public Boolean IsDevice( String device )
static new public Boolean IsDeviceClass( String deviceClass )
{
return ( device == DeviceName );
return ( deviceClass == DeviceClass );
}
@ -164,6 +164,11 @@ namespace SCJMapper_V2
private Control m_hwnd;
private bool m_activated = false;
/// <summary>
/// The DeviceClass of this instance
/// </summary>
public override String DevClass { get { return KeyboardCls.DeviceClass; } }
/// <summary>
/// The JS ProductName property
/// </summary>
@ -243,6 +248,17 @@ namespace SCJMapper_V2
return DXKeyboardCmd( m_state.PressedKeys );
}
/// <summary>
/// Collect the current data from the device (DUMMY for Kbd)
/// </summary>
public override void GetCmdData( String cmd, out int data )
{
// Make sure there is a valid device.
data = 0;
}
/// <summary>
/// Collect the current data from the device
/// </summary>

@ -57,7 +57,7 @@ namespace SCJMapper_V2
private Int64 m_msElapsed = 0;
private Int64 m_ticks = 0;
private double DegPerMS = 360.0 / 3000.0;
private const Int64 m_frameTime = 25; // max Frametime msec 1/ = fps
// location / acceleration
private RK4Integrator m_flightModel = new RK4Integrator( );
private double m_damping = 5000; // range is around 3000 .. 30000
@ -137,9 +137,9 @@ namespace SCJMapper_V2
#region YAW - Interaction
private JoystickTuningParameter m_Ytuning = new JoystickTuningParameter( null );
private DeviceTuningParameter m_Ytuning = new DeviceTuningParameter( );
// live values
private JoystickCls m_Yjs = null;
private DeviceCls m_Ydev = null;
private String m_liveYawCommand ="";
private float m_liveYdeadzone = 0.0f;
private float m_liveYsense = 1.0f;
@ -150,7 +150,7 @@ namespace SCJMapper_V2
/// Submit the tuning parameters
/// </summary>
///
public JoystickTuningParameter YawTuning
public DeviceTuningParameter YawTuning
{
get
{
@ -163,7 +163,7 @@ namespace SCJMapper_V2
// populate from input
lblYCmd.Text = m_Ytuning.Command;
m_liveYawCommand = m_Ytuning.CommandCtrl;
m_Yjs = m_Ytuning.JsDevice;
m_Ydev = m_Ytuning.JsDevice;
log.Info( "FormJSCalCurve : Yaw Command is: " + value );
cbxYinvert.Checked = m_Ytuning.InvertUsed;
@ -213,9 +213,9 @@ namespace SCJMapper_V2
#region PITCH - Interaction
private JoystickTuningParameter m_Ptuning = new JoystickTuningParameter( null );
private DeviceTuningParameter m_Ptuning = new DeviceTuningParameter( );
// live values
private JoystickCls m_Pjs = null;
private DeviceCls m_Pdev = null;
private String m_livePitchCommand ="";
private float m_livePdeadzone = 0.0f;
private float m_livePsense = 1.0f;
@ -226,7 +226,7 @@ namespace SCJMapper_V2
/// Submit the tuning parameters
/// </summary>
///
public JoystickTuningParameter PitchTuning
public DeviceTuningParameter PitchTuning
{
get
{
@ -240,7 +240,7 @@ namespace SCJMapper_V2
// populate from input
lblPCmd.Text = m_Ptuning.Command; //
m_livePitchCommand = m_Ptuning.CommandCtrl;
m_Pjs = m_Ptuning.JsDevice;
m_Pdev = m_Ptuning.JsDevice;
log.Info( "FormJSCalCurve : Pitch Command is: " + value );
cbxPinvert.Checked = m_Ptuning.InvertUsed;
@ -290,9 +290,9 @@ namespace SCJMapper_V2
#region ROLL - Interaction
private JoystickTuningParameter m_Rtuning = new JoystickTuningParameter( null );
private DeviceTuningParameter m_Rtuning = new DeviceTuningParameter( );
// live values
private JoystickCls m_Rjs = null;
private DeviceCls m_Rdev = null;
private String m_liveRollCommand;
private float m_liveRdeadzone = 0.0f;
private float m_liveRsense = 1.0f;
@ -303,7 +303,7 @@ namespace SCJMapper_V2
/// Submit the tuning parameters
/// </summary>
///
public JoystickTuningParameter RollTuning
public DeviceTuningParameter RollTuning
{
get
{
@ -317,7 +317,7 @@ namespace SCJMapper_V2
// populate from input
lblRCmd.Text = m_Rtuning.Command; //
m_liveRollCommand = m_Rtuning.CommandCtrl;
m_Rjs = m_Rtuning.JsDevice;
m_Rdev = m_Rtuning.JsDevice;
log.Info( "FormJSCalCurve : Roll Command is: " + value );
cbxRinvert.Checked = m_Rtuning.InvertUsed;
@ -679,16 +679,20 @@ namespace SCJMapper_V2
// calculate the aim change while the user is handling the control (integrating the amount of control)
Int64 newTick = DateTime.Now.Ticks;
m_msElapsed = ( newTick - m_ticks ) / TimeSpan.TicksPerMillisecond;
if ( m_msElapsed < 20 ) continue; //pace updates with 20 ms minimum (50fps max)
if ( m_msElapsed < m_frameTime ) continue; //pace updates the max frametime allowed
// safeguard against locking (moving the window) so the integrator does not get crazy..
// if deltatime gets too big we fake a regular cycle for this round
if ( m_msElapsed > 200 ) m_msElapsed = m_frameTime;
m_ticks = newTick; // prep next run
int i_x = 0, i_y = 0, i_z = 0; // Joystick Input
int x = 0; int y = 0; int z = 0; // retain real input as i_xyz
// query the Josticks for the 3 controls
if ( m_Yjs != null ) m_Yjs.GetCmdData( m_liveYawCommand, out i_x ); // + = right
if ( m_Pjs != null ) m_Pjs.GetCmdData( m_livePitchCommand, out i_y ); // + = up
if ( m_Rjs != null ) m_Rjs.GetCmdData( m_liveRollCommand, out i_z ); // += twist right
if ( m_Ydev != null ) m_Ydev.GetCmdData( m_liveYawCommand, out i_x ); // + = right
if ( m_Pdev != null ) m_Pdev.GetCmdData( m_livePitchCommand, out i_y ); // + = up
if ( m_Rdev != null ) m_Rdev.GetCmdData( m_liveRollCommand, out i_z ); // += twist right
// apply the modifications of the control (deadzone, shape, sensitivity)
x = i_x; y = i_y; z = i_z; // retain real input as i_xyz
@ -761,7 +765,6 @@ namespace SCJMapper_V2
// finalize
m_flightModel.Velocity -= m; // new direction change vector
if ( m_msElapsed > 1000 ) m_msElapsed = 1000; // safeguard against locking (moving the window)
Vector3d deltaAngleV = m_flightModel.Integrate( ( double )m_msElapsed / 1000.0, m_damping, 100.0 ); // heuristic K and B ..
// rotate the view along the input
@ -1415,18 +1418,32 @@ namespace SCJMapper_V2
private void btCopyToAllAxis_Click( object sender, EventArgs e )
{
// just copy to all labels
lblYin1.Text = lblIn1.Text; lblYout1.Text = lblOut1.Text;
lblYin2.Text = lblIn2.Text; lblYout2.Text = lblOut2.Text;
lblYin3.Text = lblIn3.Text; lblYout3.Text = lblOut3.Text;
if ( m_liveYnonLinCurve != null ) {
m_liveYnonLinCurve.Curve( float.Parse( lblYin1.Text ), float.Parse( lblYout1.Text ),
float.Parse( lblYin2.Text ), float.Parse( lblYout2.Text ),
float.Parse( lblYin3.Text ), float.Parse( lblYout3.Text ) );
}
lblPin1.Text = lblIn1.Text; lblPout1.Text = lblOut1.Text;
lblPin2.Text = lblIn2.Text; lblPout2.Text = lblOut2.Text;
lblPin3.Text = lblIn3.Text; lblPout3.Text = lblOut3.Text;
if ( m_livePnonLinCurve != null ) {
m_livePnonLinCurve.Curve( float.Parse( lblPin1.Text ), float.Parse( lblPout1.Text ),
float.Parse( lblPin2.Text ), float.Parse( lblPout2.Text ),
float.Parse( lblPin3.Text ), float.Parse( lblPout3.Text ) );
}
lblRin1.Text = lblIn1.Text; lblRout1.Text = lblOut1.Text;
lblRin2.Text = lblIn2.Text; lblRout2.Text = lblOut2.Text;
lblRin3.Text = lblIn3.Text; lblRout3.Text = lblOut3.Text;
if ( m_liveRnonLinCurve != null ) {
m_liveRnonLinCurve.Curve( float.Parse( lblRin1.Text ), float.Parse( lblRout1.Text ),
float.Parse( lblRin2.Text ), float.Parse( lblRout2.Text ),
float.Parse( lblRin3.Text ), float.Parse( lblRout3.Text ) );
}
}
private void btDone_Click( object sender, EventArgs e )

@ -5,7 +5,7 @@ SC Joystick Mapper (.Net 4; using sharpDX/OpenTK wrapper)<br>
this should work with Win8.x out of the box<br>
<br>
<br>
using sharpDX 2.6.2 .net wrapper (http://sharpdx.org/)<br>
using sharpDX 2.6.3 .net wrapper (http://sharpdx.org/)<br>
<br>
Use References to:<br>
DirectX11-net40\SharpDX.dll<br>

@ -116,6 +116,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="actions\ActionTreeNode.cs" />
<Compile Include="appConfiguration.cs" />
<Compile Include="AppSettings.cs" />
<Compile Include="DeviceCls.cs" />

@ -27,8 +27,8 @@ namespace SCJMapper_V2
static public String DevID( String device )
{
switch ( device.ToLower( ) ) {
case KeyboardCls.DeviceName: return "K";
case JoystickCls.DeviceName: return "J";
case KeyboardCls.DeviceClass: return "K";
case JoystickCls.DeviceClass: return "J";
case "xboxpad": return "X";
case "ps3pad": return "P";
default: return "Z";
@ -43,8 +43,8 @@ namespace SCJMapper_V2
static public String DeviceFromID( String devID )
{
switch ( devID ) {
case "K": return KeyboardCls.DeviceName;
case "J": return JoystickCls.DeviceName;
case "K": return KeyboardCls.DeviceClass;
case "J": return JoystickCls.DeviceClass;
case "X": return "xboxpad";
case "P": return "ps3pad";
default: return "unknown";
@ -65,7 +65,7 @@ namespace SCJMapper_V2
/// </summary>
public ActionCls( )
{
device = JoystickCls.DeviceName;
device = JoystickCls.DeviceClass;
}
@ -84,7 +84,7 @@ namespace SCJMapper_V2
newAc.defBinding = this.defBinding;
newAc.input = this.input;
// reassign the jsX part for Joystick commands
if ( ( this.device == JoystickCls.DeviceName ) && ( newAc.device == JoystickCls.DeviceName ) ) {
if ( ( this.device == JoystickCls.DeviceClass ) && ( newAc.device == JoystickCls.DeviceClass ) ) {
int oldJsN = JoystickCls.JSNum( this.input );
if ( JoystickCls.IsJSValid( oldJsN ) ) {
if ( newJsList.ContainsKey( oldJsN ) ) newAc.input = JoystickCls.ReassignJSTag( this.input, newJsList[oldJsN] );

@ -78,21 +78,21 @@ namespace SCJMapper_V2
/// <summary>
/// Returns the X-Tuning item
/// </summary>
public JoystickTuningParameter TuningX
public DeviceTuningParameter TuningX
{
get { return m_options.TuneX; }
}
/// <summary>
/// Returns the Y-Tuning item
/// </summary>
public JoystickTuningParameter TuningY
public DeviceTuningParameter TuningY
{
get { return m_options.TuneY; }
}
/// <summary>
/// Returns the Z-Tuning item
/// </summary>
public JoystickTuningParameter TuningZ
public DeviceTuningParameter TuningZ
{
get { return m_options.TuneZ; }
}
@ -144,7 +144,7 @@ namespace SCJMapper_V2
newMaps.Add( am.ReassignJsN( newJsList ) );
}
m_options.ReassignJsN( newJsList );
//m_options.ReassignJsN( newJsList );
return newMaps;
}

@ -16,6 +16,7 @@ namespace SCJMapper_V2
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
public ActionMapsCls ActionMaps { get; set; } // the Action Maps and Actions
private TreeView m_MasterTree = new TreeView( ); // the master TreeView (mem only)
@ -88,35 +89,16 @@ namespace SCJMapper_V2
return nTree;
}
/// <summary>
/// Instantiates a copy of the node - copies only the needed properties
/// </summary>
/// <param name="srcNode">A source node</param>
/// <returns>A new TreeNode</returns>
private TreeNode TNCopy( TreeNode srcNode )
{
if ( srcNode == null ) return null;
TreeNode nn = new TreeNode( );
nn.Name = srcNode.Name;
nn.Text = srcNode.Text;
nn.BackColor = srcNode.BackColor;
nn.ForeColor = srcNode.ForeColor;
nn.NodeFont = srcNode.NodeFont;
nn.ImageKey = srcNode.ImageKey;
return nn;
}
private void UpdateMasterNode( TreeNode node )
private void UpdateMasterNode( ActionTreeNode node )
{
// copy to master node
TreeNode[] masterNode = m_MasterTree.Nodes.Find( node.Name, true ); // find the same node in master
if ( masterNode.Length == 0 ) throw new IndexOutOfRangeException( "ActionTree ERROR - cannot find synched node in master" ); // OUT OF SYNC
// could return more than one if the action is the same in different actionmaps
foreach ( TreeNode mtn in masterNode ) {
if ( mtn.Parent.Text == node.Parent.Text ) {
mtn.Text = node.Text;
mtn.BackColor = node.BackColor;
foreach ( ActionTreeNode mtn in masterNode ) {
if ( mtn.Parent.Name == node.Parent.Name ) {
mtn.Command = node.Command; mtn.BackColor = node.BackColor;
}
}
}
@ -129,24 +111,24 @@ namespace SCJMapper_V2
{
log.Debug( "ApplyFilter - Entry" );
TreeNode topNode = null; // allow to backup the view - will carry the first node items
ActionTreeNode topNode = null; // allow to backup the view - will carry the first node items
Ctrl.BeginUpdate( );
Ctrl.Nodes.Clear( ); // start over
// traverse the master tree and build the GUI tree from it
foreach ( TreeNode tn in m_MasterTree.Nodes ) {
TreeNode tnMap = TNCopy( tn ); Ctrl.Nodes.Add( tnMap ); // copy level 0 nodes
foreach ( ActionTreeNode tn in m_MasterTree.Nodes ) {
ActionTreeNode tnMap = new ActionTreeNode( tn ); Ctrl.Nodes.Add( tnMap ); // copy level 0 nodes
if ( topNode == null ) topNode = tnMap;
// have to search nodes of nodes
Boolean allHidden = true;
foreach ( TreeNode stn in tn.Nodes ) {
foreach ( ActionTreeNode stn in tn.Nodes ) {
if ( ( stn.Tag != null ) && ( ( Boolean )stn.Tag == true ) ) {
; // don't create it i.e hide it - though you cannot hide TreeViewNodes at all...
}
else {
TreeNode tnAction = TNCopy( stn ); tnMap.Nodes.Add( tnAction ); // copy level 1 nodes
ActionTreeNode tnAction = new ActionTreeNode( stn ); tnMap.Nodes.Add( tnAction ); // copy level 1 nodes
allHidden = false;
}
}
@ -167,9 +149,9 @@ namespace SCJMapper_V2
private void FilterTree( )
{
Boolean hidden = !String.IsNullOrEmpty( m_Filter ); // hide only if there is a find string
foreach ( TreeNode tn in m_MasterTree.Nodes ) {
foreach ( ActionTreeNode tn in m_MasterTree.Nodes ) {
// have to search nodes of nodes
foreach ( TreeNode stn in tn.Nodes ) {
foreach ( ActionTreeNode stn in tn.Nodes ) {
if ( !stn.Text.Contains( m_Filter ) ) stn.Tag = hidden;
else stn.Tag = null;
}
@ -198,10 +180,10 @@ namespace SCJMapper_V2
{
log.Debug( "LoadTree - Entry" );
TreeNode tn = null;
TreeNode[] cnl = { };
TreeNode cn = null;
TreeNode topNode = null;
ActionTreeNode tn = null;
ActionTreeNode[] cnl = { };
ActionTreeNode cn = null;
ActionTreeNode topNode = null;
ActionCls ac = null;
ActionMapCls acm = null;
@ -234,7 +216,7 @@ namespace SCJMapper_V2
// default assignments
String action = elem[ei].Substring( 1 );
String defBinding = elem[ei + 1].Substring( 0 );
cn = new TreeNode( action ); cn.Name = elem[ei]; cn.BackColor = Color.White; // name with the key it to find it..
cn = new ActionTreeNode( "UNDEF" ); cn.Name = elem[ei]; cn.Action = action; cn.BackColor = Color.White; // name with the key it to find it..
String devID = elem[ei].Substring( 0, 1 );
String device = ActionCls.DeviceFromID( devID );
cn.ImageKey = devID;
@ -246,52 +228,52 @@ namespace SCJMapper_V2
if ( applyDefaults ) {
// apply the default mappings
if ( JoystickCls.IsDevice( ac.device ) ) {
if ( JoystickCls.IsDeviceClass( ac.device ) ) {
int jNum = JoystickCls.JSNum( ac.defBinding );
if ( JoystickCls.IsJSValid( jNum ) ) {
ac.input = ac.defBinding;
cn.Text += " - " + ac.defBinding; cn.BackColor = JoystickCls.JsNColor( jNum );
cn.Command = ac.defBinding; cn.BackColor = JoystickCls.JsNColor( jNum );
}
else if ( BlendUnmappedJS ) {
// jsx_reserved gets here
ac.input = JoystickCls.BlendedInput;
cn.Text += " - " + JoystickCls.BlendedInput; cn.BackColor = MyColors.BlendedColor;
cn.Command = JoystickCls.BlendedInput; cn.BackColor = MyColors.BlendedColor;
}
}
else if ( GamepadCls.IsDevice( ac.device ) ) {
else if ( GamepadCls.IsDeviceClass( ac.device ) ) {
if ( GamepadCls.IsXiValid( ac.defBinding ) ) {
ac.input = ac.defBinding;
cn.Text += " - " + ac.defBinding; cn.BackColor = GamepadCls.XiColor( );
cn.Command = ac.defBinding; cn.BackColor = GamepadCls.XiColor( );
}
else if ( BlendUnmappedGP ) {
// xi_reserved gets here
ac.input = GamepadCls.BlendedInput;
cn.Text += " - " + GamepadCls.BlendedInput; cn.BackColor = MyColors.BlendedColor;
cn.Command = GamepadCls.BlendedInput; cn.BackColor = MyColors.BlendedColor;
}
}
else if ( KeyboardCls.IsDevice( ac.device ) ) {
else if ( KeyboardCls.IsDeviceClass( ac.device ) ) {
if ( !String.IsNullOrEmpty( ac.defBinding ) ) {
ac.input = ac.defBinding;
cn.Text += " - " + ac.defBinding; cn.BackColor = KeyboardCls.KbdColor( );
cn.Command = ac.defBinding; cn.BackColor = KeyboardCls.KbdColor( );
}
}
}
// Don't apply defaults - but blend if checked
else {
// init empty
if ( JoystickCls.IsDevice( ac.device ) && BlendUnmappedJS ) {
if ( JoystickCls.IsDeviceClass( ac.device ) && BlendUnmappedJS ) {
ac.input = JoystickCls.BlendedInput;
cn.Text += " - " + JoystickCls.BlendedInput; cn.BackColor = MyColors.BlendedColor;
cn.Command = JoystickCls.BlendedInput; cn.BackColor = MyColors.BlendedColor;
}
else if ( GamepadCls.IsDevice( ac.device ) && BlendUnmappedGP ) {
else if ( GamepadCls.IsDeviceClass( ac.device ) && BlendUnmappedGP ) {
ac.input = GamepadCls.BlendedInput;
cn.Text += " - " + GamepadCls.BlendedInput; cn.BackColor = MyColors.BlendedColor;
cn.Command = GamepadCls.BlendedInput; cn.BackColor = MyColors.BlendedColor;
}
}
}
}//for
tn = new TreeNode( acm.name, cnl ); tn.Name = acm.name; // name it to find it..
tn = new ActionTreeNode( acm.name, cnl ); tn.Name = acm.name; // name it to find it..
tn.ImageIndex = 0; tn.NodeFont = new Font( m_MasterTree.Font, FontStyle.Bold );
m_MasterTree.BackColor = Color.White; // fix for defect TreeView (cut off bold text)
m_MasterTree.Nodes.Add( tn ); // add to control
@ -304,7 +286,7 @@ namespace SCJMapper_V2
}//while
}
// fix for defect TreeView (cut off bold text at last element -despite the BackColor fix) add another and delete it
tn = new TreeNode( "DUMMY" ); tn.Name = "DUMMY";
tn = new ActionTreeNode( "DUMMY" ); tn.Name = "DUMMY";
tn.ImageIndex = 0; tn.NodeFont = new Font( m_MasterTree.Font, FontStyle.Bold );
m_MasterTree.BackColor = m_MasterTree.BackColor; // fix for defect TreeView (cut off bold text)
m_MasterTree.Nodes.Add( tn ); // add to control
@ -333,7 +315,7 @@ namespace SCJMapper_V2
ActionCls ac = FindAction( Ctrl.SelectedNode.Parent.Name, Ctrl.SelectedNode.Name );
UpdateActionFromInput( input, ac );
UpdateNodeFromAction( Ctrl.SelectedNode, ac, inKind );
UpdateNodeFromAction((ActionTreeNode)Ctrl.SelectedNode, ac, inKind );
}
/// <summary>
@ -371,8 +353,8 @@ namespace SCJMapper_V2
// Apply the input to the ActionTree
if ( String.IsNullOrEmpty( input ) ) {
// unmapped - handle the blended ones from setting
if ( JoystickCls.IsDevice( action.device ) && BlendUnmappedJS ) action.input = JoystickCls.BlendedInput;
else if ( GamepadCls.IsDevice( action.device ) && BlendUnmappedGP ) action.input = GamepadCls.BlendedInput;
if ( JoystickCls.IsDeviceClass( action.device ) && BlendUnmappedJS ) action.input = JoystickCls.BlendedInput;
else if ( GamepadCls.IsDeviceClass( action.device ) && BlendUnmappedGP ) action.input = GamepadCls.BlendedInput;
else action.input = "";
}
else {
@ -390,7 +372,7 @@ namespace SCJMapper_V2
/// <param name="node">The TreeNode to update</param>
/// <param name="action">The action that carries the update</param>
/// <param name="inKind">The input device</param>
private void UpdateNodeFromAction( TreeNode node, ActionCls action, DeviceCls.InputKind inKind )
private void UpdateNodeFromAction( ActionTreeNode node, ActionCls action, DeviceCls.InputKind inKind )
{
log.Debug( "UpdateNode - Entry" );
if ( action == null ) return;
@ -400,26 +382,22 @@ namespace SCJMapper_V2
// input is either "" or a valid mapping or a blended mapping
if ( String.IsNullOrEmpty( action.input ) ) {
// new unmapped
node.Text = action.name;
node.BackColor = MyColors.UnassignedColor;
node.Command = ""; node.BackColor = MyColors.UnassignedColor;
}
// blended mapped ones - can only get a Blend Background
else if ( JoystickCls.IsDevice( action.device ) && ( action.input == JoystickCls.BlendedInput ) ) {
node.Text = action.name + " - " + action.input;
node.BackColor = MyColors.BlendedColor;
else if ( JoystickCls.IsDeviceClass( action.device ) && ( action.input == JoystickCls.BlendedInput ) ) {
node.Command = action.input; node.BackColor = MyColors.BlendedColor;
}
else if ( GamepadCls.IsDevice( action.device ) && ( action.input == GamepadCls.BlendedInput ) ) {
node.Text = action.name + " - " + action.input;
node.BackColor = MyColors.BlendedColor;
else if ( GamepadCls.IsDeviceClass( action.device ) && ( action.input == GamepadCls.BlendedInput ) ) {
node.Command = action.input; node.BackColor = MyColors.BlendedColor;
}
else if ( action.input == DeviceCls.BlendedInput ) {
// Manually Blended input
node.Text = action.name + " - " + action.input;
node.BackColor = MyColors.BlendedColor;
node.Command = action.input; node.BackColor = MyColors.BlendedColor;
}
else {
// mapped ( regular ones )
node.Text = action.name + " - " + action.input;
node.Command = action.input;
// background is along the input
if ( inKind == DeviceCls.InputKind.Joystick ) {
int jNum = JoystickCls.JSNum( action.input );
@ -453,11 +431,11 @@ namespace SCJMapper_V2
foreach ( ActionMapCls acm in ActionMaps ) {
if ( IgnoreMaps.Contains( "," + acm.name + "," ) ) break; // next
try {
TreeNode amTn = m_MasterTree.Nodes[acm.name]; // get the map node
ActionTreeNode amTn = (ActionTreeNode)m_MasterTree.Nodes[acm.name]; // get the map node
// find the item to reload into the treeview
foreach ( ActionCls ac in acm ) {
try {
TreeNode tnl = amTn.Nodes[ac.key];
ActionTreeNode tnl = (ActionTreeNode)amTn.Nodes[ac.key];
UpdateActionFromInput(ac.input, ac ); // this may apply (un)Blending if needed
// input kind priority first
if ( JoystickCls.IsJsN( ac.input ) ) {
@ -467,13 +445,13 @@ namespace SCJMapper_V2
UpdateNodeFromAction( tnl, ac, DeviceCls.InputKind.Gamepad );
}
// device priority second
else if ( JoystickCls.IsDevice( ac.device ) ) {
else if ( JoystickCls.IsDeviceClass( ac.device ) ) {
UpdateNodeFromAction( tnl, ac, DeviceCls.InputKind.Joystick );
}
else if ( GamepadCls.IsDevice( ac.device ) ) {
else if ( GamepadCls.IsDeviceClass( ac.device ) ) {
UpdateNodeFromAction( tnl, ac, DeviceCls.InputKind.Gamepad );
}
else if ( KeyboardCls.IsDevice( ac.device ) ) {
else if ( KeyboardCls.IsDeviceClass( ac.device ) ) {
UpdateNodeFromAction( tnl, ac, DeviceCls.InputKind.Kbd );
}
else {
@ -507,9 +485,9 @@ namespace SCJMapper_V2
log.Debug( "FindCtrl - Entry" );
Boolean found = false;
foreach ( TreeNode tn in Ctrl.Nodes ) {
foreach ( ActionTreeNode tn in Ctrl.Nodes ) {
// have to search nodes of nodes
foreach ( TreeNode stn in tn.Nodes ) {
foreach ( ActionTreeNode stn in tn.Nodes ) {
if ( stn.Text.Contains( ctrl ) ) {
Ctrl.SelectedNode = stn;
Ctrl.SelectedNode.EnsureVisible( );
@ -523,18 +501,37 @@ namespace SCJMapper_V2
/// <summary>
/// Find a control that contains the string and mark it
/// this method is applied to the GUI TreeView only
/// Find a control that contains the Command
/// </summary>
/// <param name="m_MasterTree">The string to find</param>
public String FindCommand( String ctrl )
{
log.Debug( "FindCtrl - Entry" );
foreach ( TreeNode tn in Ctrl.Nodes ) {
foreach ( ActionTreeNode tn in Ctrl.Nodes ) {
// have to search nodes of nodes
foreach ( TreeNode stn in tn.Nodes ) {
if ( stn.Text.Contains( ctrl ) ) {
foreach ( ActionTreeNode stn in tn.Nodes ) {
if ( stn.Command.Contains( ctrl ) ) {
return stn.Text;
}
}
}
return "";
}
/// <summary>
/// Find a control that contains the Text
/// </summary>
/// <param name="m_MasterTree">The string to find</param>
public String FindText( String text )
{
log.Debug( "FindText - Entry" );
foreach ( ActionTreeNode tn in Ctrl.Nodes ) {
// have to search nodes of nodes
foreach ( ActionTreeNode stn in tn.Nodes ) {
if ( stn.Text.Contains( text ) ) {
return stn.Text;
}
}

@ -0,0 +1,141 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SCJMapper_V2
{
/// <summary>
/// Our TreeNode - inherits a regular one and adds some functionality
/// </summary>
class ActionTreeNode : TreeNode
{
public ActionTreeNode( )
: base( )
{
}
public ActionTreeNode( ActionTreeNode srcNode )
: base( )
{
if ( srcNode == null ) return;
this.Name = srcNode.Name;
this.Text = srcNode.Text;
this.BackColor = srcNode.BackColor;
this.ForeColor = srcNode.ForeColor;
this.NodeFont = srcNode.NodeFont;
this.ImageKey = srcNode.ImageKey;
this.Tag = srcNode.Tag;
this.m_action = srcNode.m_action;
this.m_command = srcNode.m_command;
}
public ActionTreeNode( string text )
: base( text )
{
}
public ActionTreeNode( string text, ActionTreeNode[] children )
: base( text, children )
{
}
/// <summary>
/// Instantiates a copy of the node - copies only the needed properties
/// </summary>
/// <param name="srcNode">A source node</param>
/// <returns>A new TreeNode</returns>
private ActionTreeNode TNCopy( ActionTreeNode srcNode )
{
if ( srcNode == null ) return null;
ActionTreeNode nn = new ActionTreeNode( );
nn.Name = srcNode.Name;
nn.Text = srcNode.Text;
nn.BackColor = srcNode.BackColor;
nn.ForeColor = srcNode.ForeColor;
nn.NodeFont = srcNode.NodeFont;
nn.ImageKey = srcNode.ImageKey;
return nn;
}
private String m_action = "";
private String m_command ="";
public String Action
{
get { return m_action; }
set
{
m_action = value;
this.Text = ComposeNodeText( m_action, m_command );
}
}
public String Command
{
get { return m_command; }
set
{
m_command = value;
this.Text = ComposeNodeText( m_action, m_command );
}
}
// Handle all text label composition and extraction here
private static String ComposeNodeText( String action, String cmd )
{
if ( String.IsNullOrEmpty( cmd ) ) {
return action;
}
else {
return action + " - " + cmd;
}
}
private static void DecompNodeText( String nodeText, out String action, out String cmd )
{
action = ""; cmd = "";
String[] e = nodeText.Split( new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries );
if ( e.Length > 1 ) {
action = e[0].Trim( );
cmd = e[1].Trim( );
}
}
/// <summary>
/// Returns the action part from a node text
/// i.e. v_pitch - js1_x returns v_pitch
/// </summary>
/// <param name="nodeText">The node text in 'action - command' notation</param>
/// <returns>the action part or an empty string</returns>
public static String ActionFromNodeText( String nodeText )
{
String action, cmd;
DecompNodeText( nodeText, out action, out cmd );
return action;
}
/// <summary>
/// Returns the command part from a node text
/// i.e. v_pitch - js1_x returns js1_x
/// </summary>
/// <param name="nodeText">The node text in 'action - command' notation</param>
/// <returns>the command part or an empty string</returns>
public static String CommandFromNodeText( String nodeText )
{
String action, cmd;
DecompNodeText( nodeText, out action, out cmd );
return cmd;
}
}
}
Loading…
Cancel
Save