Пример #1
0
        /// <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);
        }
Пример #2
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);
        }
Пример #3
0
        public void updateDataSet(DS_ActionMaps dsa, string actionID)
        {
            foreach (ActionMapCls am in this)
            {
                DS_ActionMaps.T_ActionMapRow amr = dsa.T_ActionMap.NewT_ActionMapRow();

                foreach (ActionCls ac in am)
                {
                    int ilIndex = 0;
                    while (ac.inputList.Count > ilIndex)
                    {
                        if (actionID == DS_ActionMap.ActionID(am.name, ac.key, ac.inputList[ilIndex].NodeIndex))
                        {
                            DS_ActionMaps.T_ActionRow ar = dsa.T_Action.FindByID_Action(actionID);
                            ar.Usr_Binding  = ac.inputList[ilIndex].DevInput;
                            ar.Usr_Modifier = ac.inputList[ilIndex].ActivationMode.Name;
                            ar.Disabled     = DeviceCls.IsBlendedInput(ac.inputList[ilIndex].Input);
                            ar.AcceptChanges( );
                            return;
                        }
                        ilIndex++;
                    }
                } // each Action
            }     // each ActionMap
        }
Пример #4
0
        public void toDataSet(DS_ActionMaps dsa)
        {
            dsa.Clear( );
            if (dsa.HasChanges( ))
            {
                dsa.T_ActionMap.AcceptChanges( );
            }

            int AMcount = 1;

            foreach (ActionMapCls am in this)
            {
                DS_ActionMaps.T_ActionMapRow amr = dsa.T_ActionMap.NewT_ActionMapRow();
                string amShown = DS_ActionMap.ActionMapShown(am.name, AMcount++);

                amr.ID_ActionMap = amShown;
                dsa.T_ActionMap.AddT_ActionMapRow(amr);

                foreach (ActionCls ac in am)
                {
                    int ilIndex = 0;
                    while (ac.inputList.Count > ilIndex)
                    {
                        DS_ActionMaps.T_ActionRow ar = dsa.T_Action.NewT_ActionRow();
                        ar.ID_Action     = DS_ActionMap.ActionID(am.name, ac.key, ac.inputList[ilIndex].NodeIndex); // make a unique key
                        ar.AddBind       = (ilIndex > 0);                                                           // all but the first are addbinds
                        ar.REF_ActionMap = amShown;
                        ar.ActionName    = ac.name;
                        ar.Device        = ac.device;
                        ar.Def_Binding   = ac.defBinding;
                        ar.Def_Modifier  = ac.defActivationMode.Name;
                        ar.Usr_Binding   = ac.inputList[ilIndex].DevInput;
                        ar.Usr_Modifier  = ac.inputList[ilIndex].ActivationMode.Name;
                        ar.Disabled      = DeviceCls.IsBlendedInput(ac.inputList[ilIndex].Input);
                        dsa.T_Action.AddT_ActionRow(ar);

                        ilIndex++;
                    }
                } // each Action
            }     // each ActionMap

            // finally
            if (dsa.HasChanges( ))
            {
                dsa.AcceptChanges( );
            }
        }
Пример #5
0
        /// <summary>
        /// Dump the action as partial XML nicely formatted
        /// </summary>
        /// <returns>the action as XML fragment</returns>
        public String toXML( )
        {
            String r = "";

            if (!String.IsNullOrEmpty(Input))
            {
                // regular - apply XML formatting to internally blended items
                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));
                }
            }
            r += String.Format(" />\n");

            return(r);
        }
Пример #6
0
        /// <summary>
        /// Blend the input using the device specific format of the input is generic Blind
        /// </summary>
        /// <param name="input">An input (generic blend or a valid command)</param>
        /// <param name="aDevice">A valid device</param>
        /// <returns>A device blend or the original input if it was not a blend</returns>
        static public String BlendInput(String input, ActionDevice aDevice)
        {
            if (DeviceCls.IsBlendedInput(input))
            {
                // was generic blind
                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
            }
        }
Пример #7
0
        /// <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);
        }