2014-11-18 22:50:35 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
|
2014-11-19 22:58:05 +00:00
|
|
|
|
#region Static items
|
|
|
|
|
|
2016-01-02 23:15:26 +00:00
|
|
|
|
public const char RegDiv = '-';
|
|
|
|
|
public const char ModDiv = '#';
|
|
|
|
|
|
2014-11-19 22:58:05 +00:00
|
|
|
|
// Handle all text label composition and extraction here
|
|
|
|
|
|
2016-01-02 23:15:26 +00:00
|
|
|
|
public static String ComposeNodeText( String action, String cmd, Boolean modified = false )
|
2014-11-19 22:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( String.IsNullOrEmpty( cmd ) ) {
|
2016-01-02 23:15:26 +00:00
|
|
|
|
return action; // v_eject
|
2014-11-19 22:58:05 +00:00
|
|
|
|
}
|
2015-01-13 23:04:04 +00:00
|
|
|
|
else if ( String.IsNullOrEmpty( action ) ) {
|
2016-01-02 23:15:26 +00:00
|
|
|
|
return cmd; // js1_button1
|
2015-01-13 23:04:04 +00:00
|
|
|
|
}
|
2014-11-19 22:58:05 +00:00
|
|
|
|
else {
|
2016-01-02 23:15:26 +00:00
|
|
|
|
if ( modified )
|
|
|
|
|
return string.Format( "{0} {2} {1} {3}", action, cmd, RegDiv, ModDiv ); // v_eject - js1_button1 #
|
|
|
|
|
else
|
|
|
|
|
return string.Format( "{0} {2} {1}", action, cmd, RegDiv ); // v_eject - js1_button1
|
2014-11-19 22:58:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-12-22 00:34:09 +00:00
|
|
|
|
public static void DecompNodeText( String nodeText, out String action, out String cmd )
|
2014-11-19 22:58:05 +00:00
|
|
|
|
{
|
2014-12-22 00:34:09 +00:00
|
|
|
|
action = ""; cmd = "";
|
2016-01-02 23:15:26 +00:00
|
|
|
|
String[] e = nodeText.Split( new char[] { RegDiv, ModDiv }, StringSplitOptions.RemoveEmptyEntries );
|
2014-11-19 22:58:05 +00:00
|
|
|
|
if ( e.Length > 1 ) {
|
2014-11-30 23:23:31 +00:00
|
|
|
|
action = e[0].TrimEnd( );
|
2016-01-02 23:15:26 +00:00
|
|
|
|
if ( e[1].Trim() == DeviceCls.BlendedInput ) {
|
2014-11-30 23:23:31 +00:00
|
|
|
|
cmd = e[1];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
cmd = e[1].Trim( );
|
|
|
|
|
}
|
2014-11-19 22:58:05 +00:00
|
|
|
|
}
|
|
|
|
|
else if ( e.Length > 0 ) {
|
2014-11-30 23:23:31 +00:00
|
|
|
|
action = e[0].TrimEnd( );
|
2014-11-19 22:58:05 +00:00
|
|
|
|
cmd = "";
|
2015-01-13 23:04:04 +00:00
|
|
|
|
// consider if the single item is not an action but a command (from ActionTreeInputNode)
|
|
|
|
|
// it is then starting with the tag $ (that must be removed)
|
|
|
|
|
if ( action.StartsWith( "$" ) ) {
|
|
|
|
|
cmd = action.Substring( 1 );
|
|
|
|
|
action = "";
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-19 22:58:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <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 )
|
|
|
|
|
{
|
2014-12-22 00:34:09 +00:00
|
|
|
|
String action, cmd;
|
2015-01-04 00:56:04 +00:00
|
|
|
|
ActionTreeNode.DecompNodeText( nodeText, out action, out cmd );
|
2014-11-19 22:58:05 +00:00
|
|
|
|
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 )
|
|
|
|
|
{
|
2014-12-22 00:34:09 +00:00
|
|
|
|
String action, cmd;
|
2015-01-04 00:56:04 +00:00
|
|
|
|
ActionTreeNode.DecompNodeText( nodeText, out action, out cmd );
|
2014-11-19 22:58:05 +00:00
|
|
|
|
return cmd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
2014-11-30 23:23:31 +00:00
|
|
|
|
// Object defs
|
2014-11-19 22:58:05 +00:00
|
|
|
|
|
2014-11-30 23:23:31 +00:00
|
|
|
|
// ctor
|
2014-11-18 22:50:35 +00:00
|
|
|
|
public ActionTreeNode( )
|
|
|
|
|
: base( )
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 23:23:31 +00:00
|
|
|
|
// ctor
|
2014-11-18 22:50:35 +00:00
|
|
|
|
public ActionTreeNode( ActionTreeNode srcNode )
|
|
|
|
|
: base( )
|
|
|
|
|
{
|
|
|
|
|
if ( srcNode == null ) return;
|
2016-01-02 23:15:26 +00:00
|
|
|
|
// properties set once for a node
|
2014-11-18 22:50:35 +00:00
|
|
|
|
this.Name = srcNode.Name;
|
|
|
|
|
this.Text = srcNode.Text;
|
|
|
|
|
this.ForeColor = srcNode.ForeColor;
|
|
|
|
|
this.NodeFont = srcNode.NodeFont;
|
|
|
|
|
this.ImageKey = srcNode.ImageKey;
|
|
|
|
|
this.Tag = srcNode.Tag;
|
|
|
|
|
this.m_action = srcNode.m_action;
|
2014-11-30 23:23:31 +00:00
|
|
|
|
this.m_actionDevice = srcNode.m_actionDevice;
|
2016-01-02 23:15:26 +00:00
|
|
|
|
|
|
|
|
|
// these are changing while using it
|
|
|
|
|
this.Update( srcNode );
|
2014-11-18 22:50:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 23:23:31 +00:00
|
|
|
|
// ctor
|
2014-11-18 22:50:35 +00:00
|
|
|
|
public ActionTreeNode( string text )
|
|
|
|
|
{
|
2014-11-19 22:58:05 +00:00
|
|
|
|
this.Text = text;
|
2014-11-18 22:50:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 23:23:31 +00:00
|
|
|
|
// ctor
|
2014-11-18 22:50:35 +00:00
|
|
|
|
public ActionTreeNode( string text, ActionTreeNode[] children )
|
|
|
|
|
: base( text, children )
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-02 23:15:26 +00:00
|
|
|
|
// our own properties
|
2014-11-18 22:50:35 +00:00
|
|
|
|
private String m_action = "";
|
2015-01-04 00:56:04 +00:00
|
|
|
|
protected String m_command ="";
|
2016-01-02 23:15:26 +00:00
|
|
|
|
protected bool m_modified = false; // any modifier applied? (ActivationMode)
|
2014-11-30 23:23:31 +00:00
|
|
|
|
private ActionCls.ActionDevice m_actionDevice = ActionCls.ActionDevice.AD_Unknown;
|
2014-11-19 22:58:05 +00:00
|
|
|
|
|
2016-01-02 23:15:26 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Update this node from the other node
|
|
|
|
|
/// applies dynamic props only
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="other">The node to update from</param>
|
|
|
|
|
public void Update( ActionTreeNode other )
|
|
|
|
|
{
|
|
|
|
|
this.BackColor = other.BackColor;
|
|
|
|
|
this.Command = other.Command;
|
|
|
|
|
this.Modified = other.Modified;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-11-19 22:58:05 +00:00
|
|
|
|
public new String Text
|
|
|
|
|
{
|
|
|
|
|
get { return base.Text; }
|
|
|
|
|
set
|
|
|
|
|
{
|
2015-01-04 00:56:04 +00:00
|
|
|
|
ActionTreeNode.DecompNodeText( value, out m_action, out m_command );
|
2016-01-02 23:15:26 +00:00
|
|
|
|
base.Text = ActionTreeNode.ComposeNodeText( m_action, m_command, m_modified );
|
2014-11-19 22:58:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-18 22:50:35 +00:00
|
|
|
|
|
|
|
|
|
public String Action
|
|
|
|
|
{
|
|
|
|
|
get { return m_action; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
m_action = value;
|
2016-01-02 23:15:26 +00:00
|
|
|
|
base.Text = ActionTreeNode.ComposeNodeText( m_action, m_command, m_modified );
|
2014-11-18 22:50:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String Command
|
|
|
|
|
{
|
|
|
|
|
get { return m_command; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
m_command = value;
|
2016-01-02 23:15:26 +00:00
|
|
|
|
base.Text = ActionTreeNode.ComposeNodeText( m_action, m_command, m_modified );
|
2014-11-18 22:50:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 23:23:31 +00:00
|
|
|
|
public ActionCls.ActionDevice ActionDevice
|
|
|
|
|
{
|
|
|
|
|
get { return m_actionDevice; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
m_actionDevice = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-02 23:15:26 +00:00
|
|
|
|
public Boolean Modified
|
|
|
|
|
{
|
|
|
|
|
get { return m_modified; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
m_modified = value;
|
|
|
|
|
base.Text = ActionTreeNode.ComposeNodeText( m_action, m_command, m_modified );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-11-30 23:23:31 +00:00
|
|
|
|
public Boolean IsJoystickAction
|
|
|
|
|
{
|
|
|
|
|
get { return ( m_actionDevice == ActionCls.ActionDevice.AD_Joystick ); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Boolean IsGamepadAction
|
|
|
|
|
{
|
|
|
|
|
get { return ( m_actionDevice == ActionCls.ActionDevice.AD_Gamepad ); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Boolean IsKeyboardAction
|
|
|
|
|
{
|
|
|
|
|
get { return ( m_actionDevice == ActionCls.ActionDevice.AD_Keyboard ); }
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-22 00:47:23 +00:00
|
|
|
|
public Boolean IsMouseAction // 20151220BM: add mouse device (from AC 2.0 defaultProfile usage)
|
|
|
|
|
{
|
|
|
|
|
get { return ( m_actionDevice == ActionCls.ActionDevice.AD_Mouse ); }
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 23:23:31 +00:00
|
|
|
|
public Boolean IsMappedAction
|
|
|
|
|
{
|
2015-12-22 21:30:57 +00:00
|
|
|
|
get {
|
|
|
|
|
return !( string.IsNullOrEmpty( m_command ) || ActionCls.IsBlendedInput( m_command ) );
|
2014-11-30 23:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-18 22:50:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|