/// <summary> /// Query the devices if the input is blended /// </summary> /// <param name="input">The input command</param> /// <returns>True if blended input</returns> static public Boolean IsBlendedInput(String input) { Boolean blendedInput = false; blendedInput = DeviceCls.IsBlendedInput(input); // generic if (blendedInput) { return(blendedInput); } 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); }
/// <summary> /// Try to derive the device class from the devInput string (mo1_, kb1_, xi1_, jsN_) /// </summary> /// <param name="devInput">The input command string dev_input format</param> /// <returns>A proper DeviceClass string</returns> static public String DeviceClassFromInput(String devInput) { String deviceClass = DeviceCls.DeviceClass; deviceClass = JoystickCls.DeviceClassFromInput(devInput); if (!DeviceCls.IsUndefined(deviceClass)) { return(deviceClass); } deviceClass = GamepadCls.DeviceClassFromInput(devInput); if (!DeviceCls.IsUndefined(deviceClass)) { return(deviceClass); } deviceClass = KeyboardCls.DeviceClassFromInput(devInput); if (!DeviceCls.IsUndefined(deviceClass)) { return(deviceClass); } deviceClass = MouseCls.DeviceClassFromInput(devInput); if (!DeviceCls.IsUndefined(deviceClass)) { return(deviceClass); } // others.. return(deviceClass); }
/// <summary> /// ctor /// </summary> public ActionTree( Boolean blendUnmappedJS, Boolean blendUnmappedGP, JoystickList jsList, GamepadCls gamepad ) { BlendUnmappedJS = blendUnmappedJS; BlendUnmappedGP = blendUnmappedGP; m_jsList = jsList; m_gamepad = gamepad; IgnoreMaps = ""; // nothing to ignore }
/// <summary> /// Extends the input to a device input if not already done /// </summary> /// <param name="input">An input</param> /// <param name="aDevice">The ActionDevice</param> /// <returns>A valid devInput (dev_input) format</returns> static public String DevInput(string input, ActionDevice aDevice) { switch (aDevice) { case ActionDevice.AD_Gamepad: return(GamepadCls.DevInput(input)); case ActionDevice.AD_Joystick: return(JoystickCls.DevInput(input)); case ActionDevice.AD_Keyboard: return(KeyboardCls.DevInput(input)); case ActionDevice.AD_Mouse: return(MouseCls.DevInput(input)); default: return(input); } }
/// <summary> /// Return the color of a device /// </summary> /// <param name="devInput">The devinput (determine JS colors)</param> /// <param name="aDevice">The ActionDevice</param> /// <returns>The device color</returns> static public System.Drawing.Color DeviceColor(string devInput) { // background is along the input ActionDevice aDevice = ADeviceFromInput(devInput); switch (aDevice) { case ActionDevice.AD_Gamepad: return(GamepadCls.XiColor( )); case ActionDevice.AD_Joystick: { int jNum = JoystickCls.JSNum(devInput); // need to know which JS return(JoystickCls.JsNColor(jNum)); } case ActionDevice.AD_Keyboard: return(KeyboardCls.KbdColor( )); case ActionDevice.AD_Mouse: return(MouseCls.MouseColor( )); default: return(MyColors.UnassignedColor); } }
/// <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; XmlReader reader = XmlReader.Create(new StringReader(xml), settings); reader.Read( ); if (reader.Name.ToLowerInvariant( ) == "action") { if (reader.HasAttributes) { name = reader["name"]; reader.ReadStartElement("action"); // Checks that the current content node is an element with the given Name and advances the reader to the next node } else { return(false); } } do { // support AC2 and AC1 i.e. without and with device attribute if (reader.Name.ToLowerInvariant( ) == "rebind") { if (reader.HasAttributes) { device = reader["device"]; String input = reader["input"]; 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); } } //first find an ActivationMode if there is - applies to all actions // this can be an Activation Mode OR a multitap // if there is an activationMode - copy the one from our List // if no ActivationMode is given, create one with multitap 1 or may be 2... string actModeName = reader["ActivationMode"]; ActivationMode actMode = null; if (!string.IsNullOrEmpty(actModeName)) { actMode = ActivationModes.Instance.ActivationModeByName(actModeName); // should be a valid ActivationMode for this action } else { actMode = new ActivationMode(ActivationMode.Default); // no specific name given, use default string multiTap = reader["multiTap"]; if (!string.IsNullOrEmpty(multiTap)) { actMode.MultiTap = int.Parse(multiTap); // modify with given multiTap } } key = DevTag(device) + name; // unique id of the action actionDevice = ADevice(device); // get the enum of the input device AddCommand(input, actMode); // advances the reader to the next node reader.ReadStartElement("rebind"); } } else if (reader.Name.ToLowerInvariant( ) == "addbind") { if (reader.HasAttributes) { device = reader["device"]; String input = reader["input"]; 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); } } //first find an ActivationMode if there is - applies to all actions // this can be an Activation Mode OR a multitap // if there is an activationMode - copy the one from our List // if no ActivationMode is given, create one with multitap 1 or may be 2... string actModeName = reader["ActivationMode"]; ActivationMode actMode = null; if (!string.IsNullOrEmpty(actModeName)) { actMode = ActivationModes.Instance.ActivationModeByName(actModeName); // should be a valid ActivationMode for this action } else { actMode = new ActivationMode(ActivationMode.Default); // no specific name given, use default string multiTap = reader["multiTap"]; if (!string.IsNullOrEmpty(multiTap)) { actMode.MultiTap = int.Parse(multiTap); // modify with given multiTap } } AddCommand(input, actMode); // advances the reader to the next node reader.ReadStartElement("addbind"); } } else { return(false); } } while (reader.Name == "addbind"); return(true); }
/// <summary> /// Aquire the DInput joystick devices /// </summary> /// <returns></returns> public bool InitDirectInput( ) { log.Debug( "Entry" ); // Enumerate joysticks in the system. int tabs = 0; SharpDX.XInput.UserIndex gpDeviceIndex = SharpDX.XInput.UserIndex.Any; try { // Initialize DirectInput log.Debug( "Instantiate DirectInput" ); var directInput = new DirectInput( ); log.Debug( "Get Keyboard device" ); m_Keyboard = new KeyboardCls( new Keyboard( directInput ), this ); // scan the Input for attached devices log.Debug( "Scan GameControl devices" ); int nJs = 1; // number the Joystick Tabs foreach ( DeviceInstance instance in directInput.GetDevices( DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly ) ) { log.InfoFormat( "GameControl: #{0} Type:{1} Device:{2}", tabs, instance.Type.ToString( ), instance.ProductName ); // Create the device interface log.Debug( "Create the device interface" ); SharpDX.DirectInput.Joystick jsDevice = null; SharpDX.XInput.Controller gpDevice = null; JoystickCls js = null; GamepadCls gs = null; if ( m_AppSettings.DetectGamepad && ( instance.Usage == SharpDX.Multimedia.UsageId.GenericGamepad ) ) { // detect Gamepad only if the user wishes to do so for ( SharpDX.XInput.UserIndex i = SharpDX.XInput.UserIndex.One; i < SharpDX.XInput.UserIndex.Four; i++ ) { gpDevice = new SharpDX.XInput.Controller( i ); if ( gpDevice.IsConnected ) { log.InfoFormat( "Scan Input {0} for gamepad - {1}", i, gpDevice.GetCapabilities( SharpDX.XInput.DeviceQueryType.Gamepad ).ToString( ) ); gpDeviceIndex = i; break; } } } else { jsDevice = new Joystick( directInput, instance.InstanceGuid ); log.DebugFormat( "Create the device interface for: {0}", jsDevice.Information.ProductName ); } // we have the first tab made as reference so TabPage[0] already exists if ( tabs == 0 ) { // first panel - The Tab content exists already if ( gpDevice != null ) { log.Debug( "Add first Gamepad panel" ); tc1.TabPages[tabs].Text = "Gamepad "; UC_GpadPanel uUC_GpadPanelNew = new UC_GpadPanel( ); tc1.TabPages[tabs].Controls.Add( uUC_GpadPanelNew ); uUC_GpadPanelNew.Size = UC_JoyPanel.Size; uUC_GpadPanelNew.Location = UC_JoyPanel.Location; 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 ); tc1.TabPages[tabs].ToolTipText = String.Format( "{0}\n{1}", gs.DevName, " " ); toolTip1.SetToolTip( tc1.TabPages[tabs], tc1.TabPages[tabs].ToolTipText ); } else { log.Debug( "Add first Joystick panel" ); log.Debug( "Create Joystick instance" ); tc1.TabPages[tabs].Text = String.Format( "Joystick {0}", nJs++ ); js = new JoystickCls( jsDevice, this, tabs + 1, UC_JoyPanel, tabs ); // does all device related activities for that particular item tc1.TabPages[tabs].ToolTipText = String.Format( "{0}\n{1}", js.DevName, js.DevInstanceGUID ); toolTip1.SetToolTip( tc1.TabPages[tabs], tc1.TabPages[tabs].ToolTipText ); } } else { if ( gpDevice != null ) { log.Debug( "Add next Gamepad panel" ); tc1.TabPages.Add( "Gamepad " ); UC_GpadPanel uUC_GpadPanelNew = new UC_GpadPanel( ); tc1.TabPages[tabs].Controls.Add( uUC_GpadPanelNew ); uUC_GpadPanelNew.Size = UC_JoyPanel.Size; uUC_GpadPanelNew.Location = UC_JoyPanel.Location; 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 ); tc1.TabPages[tabs].ToolTipText = String.Format( "{0}\n{1}", gs.DevName, " " ); toolTip1.SetToolTip( tc1.TabPages[tabs], tc1.TabPages[tabs].ToolTipText ); } else { log.Debug( "Add next Joystick panel" ); // setup the further tab contents along the reference one in TabPage[0] (the control named UC_JoyPanel) tc1.TabPages.Add( String.Format( "Joystick {0}", nJs++ ) ); UC_JoyPanel uUC_JoyPanelNew = new UC_JoyPanel( ); tc1.TabPages[tabs].Controls.Add( uUC_JoyPanelNew ); uUC_JoyPanelNew.Size = UC_JoyPanel.Size; uUC_JoyPanelNew.Location = UC_JoyPanel.Location; log.Debug( "Create Joystick instance" ); js = new JoystickCls( jsDevice, this, tabs + 1, uUC_JoyPanelNew, tabs ); // does all device related activities for that particular item tc1.TabPages[tabs].ToolTipText = String.Format( "{0}\n{1}", js.DevName, js.DevInstanceGUID ); toolTip1.SetToolTip( tc1.TabPages[tabs], tc1.TabPages[tabs].ToolTipText ); } } if ( gpDevice != null ) { m_Gamepad = gs; SetGamepadTab( tc1.TabPages[tabs] ); // indicates the gamepad tab (murks..) MyColors.GamepadColor = MyColors.TabColor[tabs]; // save it for future use } else if ( js != null ) { m_Joystick.Add( js ); // add to joystick list tc1.TabPages[tabs].Tag = ( m_Joystick.Count - 1 ); // used to find the tab for polling } tc1.TabPages[tabs].BackColor = MyColors.TabColor[tabs]; // each tab has its own color // next tab tabs++; if ( tabs >= JoystickCls.JSnum_MAX ) break; // cannot load more JSticks than predefined Tabs } log.DebugFormat( "Added {0} GameControl devices", tabs ); if ( tabs == 0 ) { log.Warn( "Unable to find and/or create any joystick devices." ); MessageBox.Show( "Unable to create a joystick device. Program will exit.", "No joystick found", MessageBoxButtons.OK, MessageBoxIcon.Information ); return false; } // load the profile items from the XML log.Debug( "Init ActionTree" ); InitActionTree( true ); } catch ( Exception ex ) { log.Debug( "InitDirectInput failed unexpectedly", ex ); return false; } return true; }