2014-06-22 12:31:57 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace SCJMapper_V2
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Maintains an action - something like:
|
|
|
|
|
///
|
|
|
|
|
/// <action name="v_view_cycle_fwd">
|
|
|
|
|
/// <rebind device="joystick" input="js2_button2" />
|
|
|
|
|
/// </action>
|
2014-12-20 20:15:45 +00:00
|
|
|
|
///
|
|
|
|
|
///
|
|
|
|
|
/// AC1.0
|
|
|
|
|
/// <action name="v_roll">
|
|
|
|
|
/// <rebind device="joystick" input="js1_rotz" />
|
|
|
|
|
/// <addbind device="joystick" input="js2_x" />
|
|
|
|
|
/// </action>
|
|
|
|
|
///
|
2015-04-26 21:14:56 +00:00
|
|
|
|
/// AC1.1
|
|
|
|
|
/// <action name="v_roll">
|
|
|
|
|
/// <rebind device="joystick" input="rctrl+js1_rotz" />
|
|
|
|
|
/// </action>
|
|
|
|
|
///
|
2015-12-22 00:47:23 +00:00
|
|
|
|
/// AC2.0
|
|
|
|
|
/// <action name="v_roll">
|
|
|
|
|
/// <rebind input="js1_rotz" /> // jsN, moN, kbN (gamepad ?)
|
|
|
|
|
/// <addbind input="js1_rotz" /> // jsN, moN, kbN (gamepad ?) still possible together with rebind?
|
|
|
|
|
/// </action>
|
|
|
|
|
///
|
2014-06-22 12:31:57 +00:00
|
|
|
|
/// </summary>
|
2014-12-22 00:34:09 +00:00
|
|
|
|
public class ActionCls
|
2014-06-22 12:31:57 +00:00
|
|
|
|
{
|
2014-07-05 20:46:58 +00:00
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
|
|
|
|
|
|
2014-11-30 23:23:31 +00:00
|
|
|
|
|
|
|
|
|
public enum ActionDevice
|
|
|
|
|
{
|
|
|
|
|
AD_Unknown = -1,
|
|
|
|
|
AD_Joystick = 0,
|
|
|
|
|
AD_Gamepad,
|
|
|
|
|
AD_Keyboard,
|
2015-12-22 00:47:23 +00:00
|
|
|
|
AD_Mouse, // 20151220BM: add mouse device (from AC 2.0 defaultProfile usage)
|
2014-11-30 23:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-22 00:34:09 +00:00
|
|
|
|
#region Static Items
|
|
|
|
|
|
2014-11-30 23:23:31 +00:00
|
|
|
|
static public ActionDevice ADevice( String device )
|
|
|
|
|
{
|
|
|
|
|
switch ( device.ToLower( ) ) {
|
|
|
|
|
case KeyboardCls.DeviceClass: return ActionDevice.AD_Keyboard;
|
|
|
|
|
case JoystickCls.DeviceClass: return ActionDevice.AD_Joystick;
|
|
|
|
|
case GamepadCls.DeviceClass: return ActionDevice.AD_Gamepad;
|
2015-12-22 00:47:23 +00:00
|
|
|
|
case MouseCls.DeviceClass: return ActionDevice.AD_Mouse; // 20151220BM: add mouse device (from AC 2.0 defaultProfile usage)
|
2014-11-30 23:23:31 +00:00
|
|
|
|
case "ps3pad": return ActionDevice.AD_Gamepad;
|
|
|
|
|
default: return ActionDevice.AD_Unknown;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-22 12:31:57 +00:00
|
|
|
|
// Static items to have this mapping in only one place
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the Device ID i.e. the single letter to tag a device
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="device">The device name from the CryFile</param>
|
|
|
|
|
/// <returns>The single UCase device ID letter</returns>
|
|
|
|
|
static public String DevID( String device )
|
|
|
|
|
{
|
|
|
|
|
switch ( device.ToLower( ) ) {
|
2014-11-18 22:50:35 +00:00
|
|
|
|
case KeyboardCls.DeviceClass: return "K";
|
|
|
|
|
case JoystickCls.DeviceClass: return "J";
|
2014-11-30 23:23:31 +00:00
|
|
|
|
case GamepadCls.DeviceClass: return "X";
|
2015-12-22 00:47:23 +00:00
|
|
|
|
case MouseCls.DeviceClass: return "M"; // 20151220BM: add mouse device (from AC 2.0 defaultProfile usage)
|
2014-06-22 12:31:57 +00:00
|
|
|
|
case "ps3pad": return "P";
|
|
|
|
|
default: return "Z";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the Device name from the ID
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="device">The single UCase device ID letter</param>
|
|
|
|
|
/// <returns>The device name from the CryFile</returns>
|
|
|
|
|
static public String DeviceFromID( String devID )
|
|
|
|
|
{
|
|
|
|
|
switch ( devID ) {
|
2014-11-18 22:50:35 +00:00
|
|
|
|
case "K": return KeyboardCls.DeviceClass;
|
|
|
|
|
case "J": return JoystickCls.DeviceClass;
|
2014-11-30 23:23:31 +00:00
|
|
|
|
case "X": return GamepadCls.DeviceClass;
|
2015-12-22 00:47:23 +00:00
|
|
|
|
case "M": return MouseCls.DeviceClass; // 20151220BM: add mouse device (from AC 2.0 defaultProfile usage)
|
2014-06-22 12:31:57 +00:00
|
|
|
|
case "P": return "ps3pad";
|
|
|
|
|
default: return "unknown";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-22 00:47:23 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Try to derive the device class from the input string
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">The input command string</param>
|
|
|
|
|
/// <returns>A proper DeviceClass string</returns>
|
|
|
|
|
static public String DeviceClassFromInput( String input )
|
|
|
|
|
{
|
|
|
|
|
String deviceClass = DeviceCls.DeviceClass;
|
|
|
|
|
|
2015-12-22 21:30:57 +00:00
|
|
|
|
deviceClass = JoystickCls.DeviceClassFromInput( input );
|
2015-12-22 00:47:23 +00:00
|
|
|
|
if ( !DeviceCls.IsUndefined( deviceClass ) ) return deviceClass;
|
|
|
|
|
deviceClass = GamepadCls.DeviceClassFromInput( input );
|
|
|
|
|
if ( !DeviceCls.IsUndefined( deviceClass ) ) return deviceClass;
|
|
|
|
|
deviceClass = KeyboardCls.DeviceClassFromInput( input );
|
|
|
|
|
if ( !DeviceCls.IsUndefined( deviceClass ) ) return deviceClass;
|
|
|
|
|
deviceClass = MouseCls.DeviceClassFromInput( input );
|
|
|
|
|
if ( !DeviceCls.IsUndefined( deviceClass ) ) return deviceClass;
|
|
|
|
|
// others..
|
|
|
|
|
return deviceClass;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Query the devices if the input is blended
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">The input command</param>
|
|
|
|
|
/// <returns>True if blended input</returns>
|
2015-12-22 21:30:57 +00:00
|
|
|
|
static public Boolean IsBlendedInput( String input )
|
2015-12-22 00:47:23 +00:00
|
|
|
|
{
|
|
|
|
|
Boolean blendedInput = false;
|
|
|
|
|
|
|
|
|
|
blendedInput = JoystickCls.IsBlendedInput( input );
|
|
|
|
|
if ( blendedInput ) return blendedInput;
|
|
|
|
|
blendedInput = GamepadCls.IsBlendedInput( input );
|
|
|
|
|
if ( blendedInput ) return blendedInput;
|
|
|
|
|
blendedInput = KeyboardCls.IsBlendedInput( input );
|
|
|
|
|
if ( blendedInput ) return blendedInput;
|
|
|
|
|
blendedInput = MouseCls.IsBlendedInput( input );
|
|
|
|
|
if ( blendedInput ) return blendedInput;
|
|
|
|
|
// others..
|
|
|
|
|
return blendedInput;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static public String BlendInput( String input, ActionDevice aDevice )
|
|
|
|
|
{
|
|
|
|
|
if ( DeviceCls.IsBlendedInput( input ) ) {
|
|
|
|
|
switch ( aDevice ) {
|
|
|
|
|
case ActionDevice.AD_Gamepad: return GamepadCls.BlendedInput;
|
|
|
|
|
case ActionDevice.AD_Joystick: return JoystickCls.BlendedInput;
|
|
|
|
|
case ActionDevice.AD_Keyboard: return KeyboardCls.BlendedInput;
|
|
|
|
|
case ActionDevice.AD_Mouse: return MouseCls.BlendedInput;
|
|
|
|
|
default: return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return input; // just return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-22 00:34:09 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2014-06-22 12:31:57 +00:00
|
|
|
|
|
2015-12-22 00:47:23 +00:00
|
|
|
|
// **************** Class items **********************
|
2014-06-22 12:31:57 +00:00
|
|
|
|
|
2015-12-22 00:47:23 +00:00
|
|
|
|
public String key { get; set; } // the key is the "Daction" formatted item (as we can have the same name multiple times)
|
2014-12-22 00:34:09 +00:00
|
|
|
|
public String name { get; set; } // the plain action name e.g. v_yaw
|
|
|
|
|
public ActionDevice actionDevice { get; set; } // the enum of the device
|
|
|
|
|
public String device { get; set; } // name of the device (uses DeviceClass)
|
|
|
|
|
public String defBinding { get; set; } // the default binding
|
2015-12-26 22:16:25 +00:00
|
|
|
|
public String defActivationMode { get; set; } // the default binding ActivationMode (can be "" if not used)
|
|
|
|
|
public List<ActionCommandCls> inputList { get; set; } // regular bind is the 0-element, addbinds are added to the list
|
2014-12-22 00:34:09 +00:00
|
|
|
|
|
2014-06-22 12:31:57 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// ctor
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ActionCls( )
|
|
|
|
|
{
|
2014-11-19 22:58:05 +00:00
|
|
|
|
key = "";
|
2014-12-22 00:34:09 +00:00
|
|
|
|
actionDevice = ActionDevice.AD_Unknown;
|
|
|
|
|
device = JoystickCls.DeviceClass;
|
2014-11-19 22:58:05 +00:00
|
|
|
|
name = "";
|
|
|
|
|
defBinding = "";
|
2015-12-26 22:16:25 +00:00
|
|
|
|
defActivationMode = "";
|
2014-12-22 00:34:09 +00:00
|
|
|
|
inputList = new List<ActionCommandCls>( ); // empty list
|
2014-06-22 12:31:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-31 13:05:56 +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 ActionCls ReassignJsN( JsReassingList newJsList )
|
2014-08-31 13:05:56 +00:00
|
|
|
|
{
|
|
|
|
|
ActionCls newAc = new ActionCls( );
|
|
|
|
|
// full copy from 'this'
|
|
|
|
|
newAc.key = this.key;
|
2014-12-22 00:34:09 +00:00
|
|
|
|
newAc.actionDevice = this.actionDevice;
|
2014-08-31 13:05:56 +00:00
|
|
|
|
newAc.device = this.device;
|
2014-12-22 00:34:09 +00:00
|
|
|
|
newAc.name = this.name;
|
2014-08-31 13:05:56 +00:00
|
|
|
|
newAc.defBinding = this.defBinding;
|
2015-12-26 22:16:25 +00:00
|
|
|
|
newAc.defActivationMode = this.defActivationMode;
|
2014-12-22 00:34:09 +00:00
|
|
|
|
|
2015-12-22 21:30:57 +00:00
|
|
|
|
// creates a copy of the list with reassigned jsN devs
|
2014-12-22 00:34:09 +00:00
|
|
|
|
foreach ( ActionCommandCls acc in inputList ) {
|
|
|
|
|
newAc.inputList.Add( acc.ReassignJsN( newJsList ) );
|
2014-08-31 13:05:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newAc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-12-22 00:47:23 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Created and adds the inputCommand list with given input string
|
|
|
|
|
/// AC2 style input is used i.e. with device tag in front
|
2015-12-26 22:16:25 +00:00
|
|
|
|
/// apply given ActivationMode - can be "~" to indicate DONT APPLY
|
2015-12-22 00:47:23 +00:00
|
|
|
|
/// </summary>
|
2015-12-22 21:30:57 +00:00
|
|
|
|
/// <param name="devInput"></param>
|
2015-12-22 00:47:23 +00:00
|
|
|
|
/// <returns>Returns the ActionCommand created</returns>
|
2015-12-26 22:16:25 +00:00
|
|
|
|
public ActionCommandCls AddCommand( String devInput, String activationMode )
|
2015-01-13 23:04:04 +00:00
|
|
|
|
{
|
2015-12-22 21:30:57 +00:00
|
|
|
|
ActionCommandCls acc = new ActionCommandCls( devInput, inputList.Count - 1 ); // starts from -1 ...
|
2015-12-26 22:16:25 +00:00
|
|
|
|
if ( activationMode == "~" ) {
|
|
|
|
|
// not assigned
|
|
|
|
|
acc.ActivationMode = "";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
acc.ActivationMode = activationMode;
|
|
|
|
|
}
|
2015-12-22 21:30:57 +00:00
|
|
|
|
inputList.Add( acc );
|
2015-01-13 23:04:04 +00:00
|
|
|
|
return acc;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-26 22:16:25 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Add an ActionCommand with Input at nodeindex
|
|
|
|
|
/// apply default ActivationMode
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="devInput"></param>
|
|
|
|
|
/// <param name="index"></param>
|
|
|
|
|
/// <returns></returns>
|
2015-12-22 21:30:57 +00:00
|
|
|
|
public ActionCommandCls AddCommand( String devInput, int index )
|
2014-12-22 00:34:09 +00:00
|
|
|
|
{
|
2015-12-22 21:30:57 +00:00
|
|
|
|
ActionCommandCls acc = new ActionCommandCls( devInput, index );
|
2015-12-26 22:16:25 +00:00
|
|
|
|
acc.ActivationMode = defActivationMode;
|
2014-12-22 00:34:09 +00:00
|
|
|
|
inputList.Add( acc );
|
|
|
|
|
return acc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DelCommand( int index )
|
|
|
|
|
{
|
|
|
|
|
int removeIt = -1;
|
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < inputList.Count; i++ ) {
|
2015-12-22 21:30:57 +00:00
|
|
|
|
if ( inputList[i].NodeIndex == index ) removeIt = i;
|
|
|
|
|
if ( inputList[i].NodeIndex > index ) inputList[i].NodeIndex -= 1; // reorder trailing ones
|
2014-12-22 00:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
if ( removeIt >= 0 ) inputList.RemoveAt( removeIt );
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-22 21:30:57 +00:00
|
|
|
|
|
2014-06-22 12:31:57 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Merge action is simply copying the new input control
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="newAc"></param>
|
2014-06-28 13:59:35 +00:00
|
|
|
|
public void Merge( ActionCls newAc )
|
2014-06-22 12:31:57 +00:00
|
|
|
|
{
|
2014-12-22 00:34:09 +00:00
|
|
|
|
this.inputList.Clear( );
|
|
|
|
|
foreach ( ActionCommandCls acc in newAc.inputList ) {
|
|
|
|
|
this.inputList.Add( acc );
|
|
|
|
|
}
|
2014-06-22 12:31:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-22 21:30:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates an actionCommand with a new input (command)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="devInput">The input command</param>
|
|
|
|
|
/// <param name="actionCmd">The actionCommand to update</param>
|
|
|
|
|
public void UpdateCommandFromInput( String devInput, ActionCommandCls actionCmd )
|
|
|
|
|
{
|
|
|
|
|
//log.Debug( "UpdateCommandFromInput - Entry" );
|
|
|
|
|
if ( actionCmd == null ) return;
|
|
|
|
|
|
|
|
|
|
// Apply the input to the ActionTree
|
|
|
|
|
actionCmd.DevInput = BlendInput( devInput, this.actionDevice );
|
2015-12-26 22:16:25 +00:00
|
|
|
|
if ( string.IsNullOrEmpty( actionCmd.Input)) {
|
|
|
|
|
actionCmd.ActivationMode = defActivationMode; // reset activation mode if the input is empty
|
|
|
|
|
}
|
2015-12-22 21:30:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Find an ActionCommand with input in an Action
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">The input</param>
|
|
|
|
|
/// <returns>An actionCommand or null if not found</returns>
|
|
|
|
|
public ActionCommandCls FindActionInputObject( String devInput )
|
|
|
|
|
{
|
|
|
|
|
log.Debug( "FindActionInputObject - Entry" );
|
|
|
|
|
// Apply the input to the ActionTree
|
|
|
|
|
ActionCommandCls acc = null;
|
|
|
|
|
acc = this.inputList.Find( delegate ( ActionCommandCls _ACC ) { return _ACC.DevInput == devInput; } );
|
|
|
|
|
if ( acc == null ) {
|
|
|
|
|
log.Error( "FindActionInputObject - Action Input not found in Action" );
|
|
|
|
|
return null; // ERROR - Action Input not found in tree
|
|
|
|
|
}
|
|
|
|
|
return acc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Find an ActionCommand with index in an Action
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">The input</param>
|
|
|
|
|
/// <returns>An actionCommand or null if not found</returns>
|
|
|
|
|
public ActionCommandCls FindActionInputObject( int index )
|
|
|
|
|
{
|
|
|
|
|
log.Debug( "FindActionInputObject - Entry" );
|
|
|
|
|
// Apply the input to the ActionTree
|
|
|
|
|
ActionCommandCls acc = null;
|
|
|
|
|
acc = this.inputList.Find( delegate ( ActionCommandCls _ACC ) { return _ACC.NodeIndex == index; } );
|
|
|
|
|
if ( acc == null ) {
|
|
|
|
|
log.Error( "FindActionInputObject - Action Input not found in Action" );
|
|
|
|
|
return null; // ERROR - Action Input not found in tree
|
|
|
|
|
}
|
|
|
|
|
return acc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-06-22 12:31:57 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Dump the action as partial XML nicely formatted
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>the action as XML fragment</returns>
|
|
|
|
|
public String toXML( )
|
|
|
|
|
{
|
2015-12-22 21:30:57 +00:00
|
|
|
|
String r = ""; String
|
2014-12-22 00:34:09 +00:00
|
|
|
|
bindCmd = "rebind";
|
|
|
|
|
if ( inputList.Count > 0 ) {
|
2015-12-22 21:30:57 +00:00
|
|
|
|
if ( !String.IsNullOrEmpty( inputList[0].Input ) ) {
|
2014-12-22 00:34:09 +00:00
|
|
|
|
r = String.Format( "\t<action name=\"{0}\">\n", name );
|
|
|
|
|
foreach ( ActionCommandCls acc in inputList ) {
|
2015-12-22 21:30:57 +00:00
|
|
|
|
if ( !String.IsNullOrEmpty( acc.Input ) ) {
|
2015-12-22 00:47:23 +00:00
|
|
|
|
// r += String.Format( "\t\t\t<{0} device=\"{1}\" {2}", bindCmd, device, acc.toXML( ) ); // OLD style
|
2015-12-22 21:30:57 +00:00
|
|
|
|
r += String.Format( "\t\t\t<{0} {1}", bindCmd, acc.toXML( ) ); // 20151220BM: format for AC2 style
|
2015-12-22 00:47:23 +00:00
|
|
|
|
bindCmd = "addbind"; // switch to addbind
|
2014-12-22 00:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
r += String.Format( "\t\t</action>\n" );
|
|
|
|
|
}
|
2014-11-19 22:58:05 +00:00
|
|
|
|
}
|
2014-12-22 00:34:09 +00:00
|
|
|
|
|
2014-06-22 12:31:57 +00:00
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Read an action from XML - do some sanity check
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="xml">the XML action fragment</param>
|
|
|
|
|
/// <returns>True if an action was decoded</returns>
|
|
|
|
|
public Boolean fromXML( String xml )
|
|
|
|
|
{
|
|
|
|
|
XmlReaderSettings settings = new XmlReaderSettings( );
|
|
|
|
|
settings.ConformanceLevel = ConformanceLevel.Fragment;
|
|
|
|
|
settings.IgnoreWhitespace = true;
|
|
|
|
|
settings.IgnoreComments = true;
|
2014-06-28 13:59:35 +00:00
|
|
|
|
XmlReader reader = XmlReader.Create( new StringReader( xml ), settings );
|
2014-06-22 12:31:57 +00:00
|
|
|
|
|
|
|
|
|
reader.Read( );
|
|
|
|
|
|
2015-12-22 00:47:23 +00:00
|
|
|
|
if ( reader.Name.ToLowerInvariant( ) == "action" ) {
|
2014-06-22 12:31:57 +00:00
|
|
|
|
if ( reader.HasAttributes ) {
|
|
|
|
|
name = reader["name"];
|
2014-12-22 00:34:09 +00:00
|
|
|
|
reader.ReadStartElement( "action" ); // Checks that the current content node is an element with the given Name and advances the reader to the next node
|
2014-06-22 12:31:57 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-22 00:34:09 +00:00
|
|
|
|
do {
|
2015-12-22 00:47:23 +00:00
|
|
|
|
// support AC2 and AC1 i.e. without and with device attribute
|
|
|
|
|
if ( reader.Name.ToLowerInvariant( ) == "rebind" ) {
|
2014-12-22 00:34:09 +00:00
|
|
|
|
if ( reader.HasAttributes ) {
|
|
|
|
|
device = reader["device"];
|
2015-01-13 23:04:04 +00:00
|
|
|
|
String input = reader["input"];
|
2015-12-22 00:47:23 +00:00
|
|
|
|
if ( String.IsNullOrEmpty( input ) ) return false; // ERROR exit
|
|
|
|
|
input = DeviceCls.fromXML( input ); // move from external to internal blend
|
|
|
|
|
if ( String.IsNullOrEmpty( device ) ) {
|
|
|
|
|
// AC2 style - derive the device (Device.DeviceClass)
|
|
|
|
|
device = DeviceClassFromInput( input );
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// AC1 style - need to reformat mouse and keyboard according to AC2 style now
|
|
|
|
|
if ( KeyboardCls.IsDeviceClass( device ) ) input = KeyboardCls.FromAC1( input );
|
|
|
|
|
else if ( MouseCls.IsDeviceClass( device ) ) input = MouseCls.FromAC1( input );
|
|
|
|
|
else if ( GamepadCls.IsDeviceClass( device ) ) input = GamepadCls.FromAC1( input );
|
|
|
|
|
}
|
2015-12-26 22:16:25 +00:00
|
|
|
|
// Get default ActivationMode
|
|
|
|
|
String activationMode = reader["ActivationMode"];
|
|
|
|
|
if ( string.IsNullOrEmpty(activationMode)) activationMode = ActivationModes.Default; // MARK AS NOT USED
|
|
|
|
|
|
2014-12-22 00:34:09 +00:00
|
|
|
|
key = DevID( device ) + name; // unique id of the action
|
|
|
|
|
actionDevice = ADevice( device ); // get the enum of the input device
|
2015-12-26 22:16:25 +00:00
|
|
|
|
AddCommand( input, activationMode );
|
2014-12-22 00:34:09 +00:00
|
|
|
|
// advances the reader to the next node
|
|
|
|
|
reader.ReadStartElement( "rebind" );
|
2014-11-19 22:58:05 +00:00
|
|
|
|
}
|
2014-12-22 00:34:09 +00:00
|
|
|
|
}
|
2015-12-22 00:47:23 +00:00
|
|
|
|
else if ( reader.Name.ToLowerInvariant( ) == "addbind" ) {
|
2014-12-22 00:34:09 +00:00
|
|
|
|
if ( reader.HasAttributes ) {
|
|
|
|
|
device = reader["device"];
|
2015-01-13 23:04:04 +00:00
|
|
|
|
String input = reader["input"];
|
2015-12-22 00:47:23 +00:00
|
|
|
|
if ( String.IsNullOrEmpty( input ) ) return false; // ERROR exit
|
|
|
|
|
input = DeviceCls.fromXML( input ); // move from external to internal blend
|
|
|
|
|
if ( String.IsNullOrEmpty( device ) ) {
|
|
|
|
|
// AC2 style - derive the device (Device.DeviceClass)
|
|
|
|
|
device = DeviceClassFromInput( input );
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// AC1 style - need to reformat according to AC2 style now
|
|
|
|
|
if ( KeyboardCls.IsDeviceClass( device ) ) input = KeyboardCls.FromAC1( input );
|
|
|
|
|
else if ( MouseCls.IsDeviceClass( device ) ) input = MouseCls.FromAC1( input );
|
|
|
|
|
else if ( GamepadCls.IsDeviceClass( device ) ) input = GamepadCls.FromAC1( input );
|
|
|
|
|
}
|
2015-12-26 22:16:25 +00:00
|
|
|
|
String activationMode = reader["ActivationMode"];
|
|
|
|
|
if ( string.IsNullOrEmpty( activationMode ) ) activationMode = ActivationModes.Default; // MARK AS NOT USED
|
|
|
|
|
AddCommand( input, activationMode );
|
2014-12-22 00:34:09 +00:00
|
|
|
|
// advances the reader to the next node
|
|
|
|
|
reader.ReadStartElement( "addbind" );
|
2014-11-19 22:58:05 +00:00
|
|
|
|
}
|
2014-06-22 12:31:57 +00:00
|
|
|
|
}
|
2014-12-22 00:34:09 +00:00
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} while ( reader.Name == "addbind" );
|
2014-06-22 12:31:57 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|