Exemplo n.º 1
0
 /// <summary>
 /// Create a tuningOptionID from devClass and xmlInstance (jsN for joysticks, 1 for gamepad)
 /// </summary>
 /// <param name="deviceClass">Joysstick or Gamepad class name</param>
 /// <param name="instance">The xml instance number or 1 for gamepad</param>
 /// <returns>An ID or a dummy ID if the instance is not found</returns>
 public static string TuneOptionIDfromJsN(string deviceClass, int instance)
 {
     // only search for joysticks
     if (JoystickCls.IsDeviceClass(deviceClass))
     {
         for (int i = 0; i < m_jsMap.Length; i++)
         {
             if (m_jsMap[i] == instance)
             {
                 return(string.Format("{0}{1}{2}", deviceClass, ID_Delimiter, i.ToString( )));
             }
         }
         // not found return
         return(string.Format("{0}{1}{2}", deviceClass, ID_Delimiter, -1)); // will not be found in the collection
     }
     else if (GamepadCls.IsDeviceClass(deviceClass))
     {
         // gamepad
         return(string.Format("{0}{1}{2}", deviceClass, ID_Delimiter, instance));
     }
     else if (MouseCls.IsDeviceClass(deviceClass))
     {
         // mouse
         return(string.Format("{0}{1}{2}", deviceClass, ID_Delimiter, instance));
     }
     else
     {
         return(string.Format("{0}{1}{2}", deviceClass, ID_Delimiter, instance));
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Create a DeviceOption ID from dev Name and the command
        /// </summary>
        /// <param name="devName">The game device name as retrieved from XInput</param>
        /// <param name="cmdCtrl">A device control that supports devOptions (all ananlog controls)</param>
        /// <returns></returns>
        public static string DevOptionID(string deviceClass, string devName, string cmdCtrl)
        {
            // cmdCtrl can be anything
            //    v_flight_throttle_abs - js1_throttlez
            //    v_strafe_longitudinal - js1_y
            //    v_strafe_longitudinal - js1_roty
            //    v_strafe_longitudinal - xi1_shoulderl+thumbly
            //    v_strafe_longitudinal - xi1_thumbly

            string cmd = cmdCtrl.Trim( );

            // messy...
            if (cmd.Contains("throttle"))
            {
                cmd = cmd.Replace("throttle", "");                           // this is not suitable for the devOption
            }
            if (cmd.Contains("_"))
            {
                int l = cmd.LastIndexOf("_");
                cmd = cmd.Substring(l + 1); // assuming it is never the last one..
            }
            if (cmd.Contains("+"))
            {
                int l = cmd.LastIndexOf("+");
                cmd = cmd.Substring(l + 1); // assuming it is never the last one..
            }
            //   we have to trick the gamepad name here to CIG generic
            return(string.Format("{0}{1}{2}", (GamepadCls.IsDeviceClass(deviceClass)) ? GamepadCls.DevNameCIG : devName, ID_Delimiter, cmd));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Query the devices if the input is disabled
        /// </summary>
        /// <param name="input">The input command</param>
        /// <returns>True if disabled input</returns>
        static public bool IsDisabledInput(string input)
        {
            bool disabledInput = false;

            disabledInput = DeviceCls.IsDisabledInput(input); // generic
            if (disabledInput)
            {
                return(disabledInput);
            }

            disabledInput = JoystickCls.IsDisabledInput(input);
            if (disabledInput)
            {
                return(disabledInput);
            }
            disabledInput = GamepadCls.IsDisabledInput(input);
            if (disabledInput)
            {
                return(disabledInput);
            }
            disabledInput = KeyboardCls.IsDisabledInput(input);
            if (disabledInput)
            {
                return(disabledInput);
            }
            disabledInput = MouseCls.IsDisabledInput(input);
            if (disabledInput)
            {
                return(disabledInput);
            }
            // others..
            return(disabledInput);
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Read an action from XML - do some sanity checks
 /// </summary>
 /// <param name="xml">the XML action fragment</param>
 /// <returns>True if an action was decoded</returns>
 public bool fromXML(XElement actionNode)
 {
     ActionName = (string)actionNode.Attribute("name"); // mandadory
     foreach (XElement bindingNode in actionNode.Nodes( ))
     {
         string binding = bindingNode.Name.ToString( );
         string input = "", actModeName = "", multi = "";
         input = (string)bindingNode.Attribute("input"); // mandadory
         if (string.IsNullOrEmpty(input))
         {
             input = "";
         }
         actModeName = (string)bindingNode.Attribute("ActivationMode");
         multi       = (string)bindingNode.Attribute("multiTap");
         string device = (string)bindingNode.Attribute("device");
         //process
         input = DeviceCls.fromXML(input); // move from external to internal blend
         if (!string.IsNullOrEmpty(device))
         {
             // 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);
             }
         }
         Device = Act.DeviceClassFromInput(input);
         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
             if (!string.IsNullOrEmpty(multi))
             {
                 actMode.MultiTap = int.Parse(multi); // modify with given multiTap
             }
         }
         if (binding == "rebind")
         {
             Key          = Act.DevTag(Device) + ActionName; // unique id of the action
             ActionDevice = Act.ADevice(Device);             // get the enum of the input device
         }
         AddCommand(input, actMode);
     }//foreach
     return(true);
 }
Exemplo n.º 6
0
        /// <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);
            }
        }
Exemplo n.º 7
0
        /// <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: return(JoystickCls.JsNColor(JoystickCls.JSNum(devInput)));// need to know which JS

            case ActionDevice.AD_Keyboard: return(KeyboardCls.KbdColor( ));

            case ActionDevice.AD_Mouse: return(MouseCls.MouseColor( ));

            default: return(MyColors.UnassignedColor);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Read an Options from XML - do some sanity check
        /// </summary>
        /// <param name="xml">the XML action fragment</param>
        /// <returns>True if an action was decoded</returns>
        public bool fromXML(XElement options)
        {
            /*
             * This can be a lot of the following options
             * try to do our best....
             *
             *  <options type="joystick" instance="1">
             *  ..
             *  </options>
             *
             *
             *   <options type="joystick" instance="1">
             *   ..
             *   </options>
             *
             */
            string instance = (string)options.Attribute("instance"); // mandadory
            string type     = (string)options.Attribute("type");     // mandadory

            if (!int.TryParse(instance, out int nInstance))
            {
                nInstance = 0;
            }

            // now dispatch to the instance to capture the content
            if (JoystickCls.IsDeviceClass(type))
            {
                string toID = TuneOptionIDfromJsN(JoystickCls.DeviceClass, nInstance);
                // now this might not be availabe if devices have been changed
                if (this.ContainsKey(toID))
                {
                    this[toID].fromXML(options);
                }
                else
                {
                    log.InfoFormat("Read XML Options - joystick instance {0} is not available - dropped this content", nInstance);
                }
            }
            else if (GamepadCls.IsDeviceClass(type))
            {
                string toID = TuneOptionID(GamepadCls.DeviceClass, nInstance);
                if (this.ContainsKey(toID))// 20170513: bugfix if gamepad is in the XML but not connected right now - ignore
                {
                    this[toID].fromXML(options);
                }
                else
                {
                    log.InfoFormat("Read XML Options - xboxpad instance {0} is not available - dropped this content", nInstance);
                }
            }
            else if (KeyboardCls.IsDeviceClass(type)) // CIG names mouse - keyboard
            {
                string toID = TuneOptionID(MouseCls.DeviceClass, nInstance);
                if (this.ContainsKey(toID))
                {
                    this[toID].fromXML(options);
                }
                else
                {
                    log.InfoFormat("Read XML Options - keyboard(mouse) instance {0} is not available - dropped this content", nInstance);
                }
            }
            return(true);
        }