2014-12-22 00:34:09 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace SCJMapper_V2
|
|
|
|
|
{
|
2015-12-22 00:47:23 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Maintains one ActionCommand
|
|
|
|
|
/// AC2 style input is used i.e. with device tag in front
|
2015-12-22 21:30:57 +00:00
|
|
|
|
/// commands are a built from as devID_input where ..
|
|
|
|
|
/// devID: jsN, mo1, xi1, kb1, thumbl_down and modified ones: ralt+button1 (modifier+deviceinput)
|
|
|
|
|
/// input: x, mouse1, r, and ~ as internal blend (defined in DeviceCls)
|
2015-12-22 00:47:23 +00:00
|
|
|
|
/// </summary>
|
2014-12-22 00:34:09 +00:00
|
|
|
|
public class ActionCommandCls
|
|
|
|
|
{
|
|
|
|
|
|
2015-12-22 21:30:57 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The Input commands used incl. modifiers (mod+command)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public String Input { get; set; } // AC2 style: input command name AC2 e.g. x, mouse1, r, "~" to blend
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The device ID of the device (jsN, mo1, kb1, xi1)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public String DevID { get; set; } // the device ID (jsN, mo1, xi1, kb1)
|
2015-12-22 00:47:23 +00:00
|
|
|
|
|
2015-12-26 22:16:25 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The applied ActivationMode for this command
|
|
|
|
|
/// </summary>
|
2016-01-02 00:15:58 +00:00
|
|
|
|
public ActivationMode ActivationMode { get; set; } // "" or one of the defined ActivationModes
|
2015-12-26 22:16:25 +00:00
|
|
|
|
|
2015-12-22 21:30:57 +00:00
|
|
|
|
/// <summary>
|
2016-01-02 23:15:26 +00:00
|
|
|
|
/// Returns true if default ActivationMode is set
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Boolean DefaultActivationMode { get { return ActivationMode == ActivationMode.Default; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2015-12-22 21:30:57 +00:00
|
|
|
|
/// The complete input string (devID_input)
|
|
|
|
|
/// Assuming internally blended ones only (i.e. no space blends contained)
|
|
|
|
|
/// Can derive if a device tag is given
|
|
|
|
|
/// </summary>
|
2015-12-26 22:16:25 +00:00
|
|
|
|
public String DevInput
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2015-12-22 21:30:57 +00:00
|
|
|
|
if ( string.IsNullOrEmpty( Input ) )
|
|
|
|
|
return Input; // no Input - return empty
|
|
|
|
|
else if ( string.IsNullOrEmpty( DevID ) )
|
|
|
|
|
return Input; // no devID - return input only
|
|
|
|
|
else
|
|
|
|
|
return String.Format( "{0}_{1}", DevID, Input ); // fully qualified only if both exist
|
|
|
|
|
}
|
2015-12-26 22:16:25 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2015-12-22 21:30:57 +00:00
|
|
|
|
// decompose the deviceInput into parts
|
|
|
|
|
if ( string.IsNullOrEmpty( value ) ) { // no Input - insert input empty
|
|
|
|
|
Input = ""; // empty one
|
|
|
|
|
}
|
2016-03-06 16:22:16 +00:00
|
|
|
|
else if ( value.IndexOf( "_" ) == 3 ) { // fully qualified only if both exist single digit number
|
2015-12-22 21:30:57 +00:00
|
|
|
|
DevID = value.Substring( 0, 3 );
|
|
|
|
|
Input = value.Substring( 4 );
|
|
|
|
|
}
|
2016-03-06 16:22:16 +00:00
|
|
|
|
else if ( value.IndexOf( "_" ) == 4 ) { // fully qualified only if both exist 2 digit number
|
|
|
|
|
DevID = value.Substring( 0, 4 );
|
|
|
|
|
Input = value.Substring( 5 );
|
|
|
|
|
}
|
2015-12-22 21:30:57 +00:00
|
|
|
|
else { // no device - insert input empty
|
|
|
|
|
// treat as input only
|
|
|
|
|
Input = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-22 00:47:23 +00:00
|
|
|
|
|
|
|
|
|
|
2014-12-22 00:34:09 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The index of the visible child node (-1 -> shown in ActionNode)
|
|
|
|
|
/// </summary>
|
2015-12-22 21:30:57 +00:00
|
|
|
|
public int NodeIndex { get; set; } // index of the vis treenode
|
2014-12-22 00:34:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ctor
|
|
|
|
|
public ActionCommandCls( )
|
|
|
|
|
{
|
2015-12-22 21:30:57 +00:00
|
|
|
|
// init with something to debug if needed
|
|
|
|
|
Input = "UNDEF";
|
|
|
|
|
DevID = "NA0";
|
2016-01-02 23:15:26 +00:00
|
|
|
|
ActivationMode = new ActivationMode( ActivationMode.Default );
|
2015-12-22 21:30:57 +00:00
|
|
|
|
NodeIndex = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ctor
|
|
|
|
|
public ActionCommandCls( ActionCommandCls other )
|
|
|
|
|
{
|
|
|
|
|
Input = other.Input;
|
|
|
|
|
DevID = other.DevID;
|
2016-01-02 23:15:26 +00:00
|
|
|
|
ActivationMode = new ActivationMode( other.ActivationMode );
|
2015-12-22 21:30:57 +00:00
|
|
|
|
NodeIndex = other.NodeIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ctor
|
|
|
|
|
public ActionCommandCls( String devInp )
|
|
|
|
|
{
|
|
|
|
|
DevInput = devInp;
|
2016-01-02 23:15:26 +00:00
|
|
|
|
ActivationMode = new ActivationMode( ActivationMode.Default );
|
2015-12-22 21:30:57 +00:00
|
|
|
|
NodeIndex = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ctor
|
|
|
|
|
public ActionCommandCls( String devInp, int nodeIx )
|
|
|
|
|
{
|
|
|
|
|
DevInput = devInp;
|
2016-01-02 23:15:26 +00:00
|
|
|
|
ActivationMode = new ActivationMode( ActivationMode.Default );
|
2015-12-22 21:30:57 +00:00
|
|
|
|
NodeIndex = nodeIx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ctor
|
|
|
|
|
public ActionCommandCls( String dev, String inp )
|
|
|
|
|
{
|
|
|
|
|
Input = inp;
|
|
|
|
|
DevID = dev;
|
2016-01-02 23:15:26 +00:00
|
|
|
|
ActivationMode = new ActivationMode( ActivationMode.Default );
|
2015-12-22 21:30:57 +00:00
|
|
|
|
NodeIndex = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ctor
|
|
|
|
|
public ActionCommandCls( String dev, String inp, int nodeIx )
|
|
|
|
|
{
|
|
|
|
|
Input = inp;
|
|
|
|
|
DevID = dev;
|
2016-01-02 23:15:26 +00:00
|
|
|
|
ActivationMode = new ActivationMode( ActivationMode.Default );
|
2015-12-22 21:30:57 +00:00
|
|
|
|
NodeIndex = nodeIx;
|
2014-12-22 00:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Copy return the action while reassigning the JsN Tag
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="newJsList">The JsN reassign list</param>
|
|
|
|
|
/// <returns>The action copy with reassigned input</returns>
|
2015-01-01 19:40:01 +00:00
|
|
|
|
public ActionCommandCls ReassignJsN( JsReassingList newJsList )
|
2014-12-22 00:34:09 +00:00
|
|
|
|
{
|
|
|
|
|
// full copy from 'this'
|
2015-12-22 21:30:57 +00:00
|
|
|
|
ActionCommandCls newAc = new ActionCommandCls( this );
|
2015-12-26 22:16:25 +00:00
|
|
|
|
|
2015-12-22 21:30:57 +00:00
|
|
|
|
// reassign the jsX part for Joystick commands
|
|
|
|
|
if ( this.DevID.StartsWith( "js" ) ) {
|
|
|
|
|
int oldJsN = JoystickCls.JSNum( this.DevID );
|
2014-12-22 00:34:09 +00:00
|
|
|
|
if ( JoystickCls.IsJSValid( oldJsN ) ) {
|
2015-12-22 21:30:57 +00:00
|
|
|
|
if ( newJsList.ContainsOldJs( oldJsN ) ) newAc.DevID = JoystickCls.ReassignJSTag( this.DevID, newJsList.newJsFromOldJs( oldJsN ) );
|
2014-12-22 00:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newAc;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-27 22:40:25 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Strange behavior of SC - needs a proper multitap to accept ActivationModes
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="actMode"></param>
|
|
|
|
|
/// <returns></returns>
|
2016-01-02 00:15:58 +00:00
|
|
|
|
private String MutitapFudge( ActivationMode actMode )
|
2015-12-27 22:40:25 +00:00
|
|
|
|
{
|
2016-01-02 00:15:58 +00:00
|
|
|
|
if ( actMode.IsDoubleTap ) {
|
|
|
|
|
return "multiTap = \"2\"";
|
2015-12-27 22:40:25 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2016-01-02 00:15:58 +00:00
|
|
|
|
return "multiTap = \"1\"";
|
2015-12-27 22:40:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-22 00:34:09 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Dump the action as partial XML nicely formatted
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>the action as XML fragment</returns>
|
2015-12-22 21:30:57 +00:00
|
|
|
|
public String toXML( )
|
2014-12-22 00:34:09 +00:00
|
|
|
|
{
|
|
|
|
|
String r = "";
|
2015-12-26 22:16:25 +00:00
|
|
|
|
if ( !String.IsNullOrEmpty( Input ) ) {
|
2015-12-22 21:30:57 +00:00
|
|
|
|
// regular - apply XML formatting to internally blended items
|
2016-01-02 00:15:58 +00:00
|
|
|
|
r += String.Format( "input=\"{0}_{1}\" {2} ", DevID, DeviceCls.toXML( Input ), DeviceCls.toXMLBlendExtension(Input) ); // add multitap override if needed
|
|
|
|
|
if ( ! ActivationMode.Equals( ActivationMode.Default ) ) {
|
|
|
|
|
r += String.Format( "ActivationMode=\"{0}\" {1} ", ActivationMode.Name, MutitapFudge(ActivationMode) );
|
2015-12-26 22:16:25 +00:00
|
|
|
|
}
|
2014-12-22 00:34:09 +00:00
|
|
|
|
}
|
2015-12-27 22:40:25 +00:00
|
|
|
|
r += String.Format( " />\n" );
|
2014-12-22 00:34:09 +00:00
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|