コード例 #1
0
        /// <summary>
        /// Read all from an Action XElement
        /// </summary>
        /// <param name="action">The action XElement</param>
        /// <returns>True if successfull</returns>
        private bool ReadAction(XElement action)
        {
            /* A variety exists here...
             *            <action  name="v_eject_cinematic"  onPress="0"  onHold="1"  onRelease="1"  keyboard="ralt+l"  xboxpad="shoulderl+shoulderr+y"  joystick=" "  />
             *            <action  name="v_exit"  onPress="1"  onHold="0"  onRelease="1"  multiTap="1"  multiTapBlock="1"  pressTriggerThreshold="1.0"  releaseTriggerThreshold="-1"  releaseTriggerDelay="0"  keyboard="f"  xboxpad="y"  UILabel="@ui_CIExit"  UIDescription="@ui_CIExitDesc"  >
             *                    <joystick  ActivationMode="press"  input=" "  />
             *            </action>
             *            <action  name="v_throttle_100"  onPress="1"  xboxpad=" "  joystick=" "  UILabel="@ui_CIThrottleMax"  UIDescription="@ui_CIThrottleMaxDesc"  >
             *                    <xboxpad  multiTap="2"  input="thumbl_up"  />
             *                    <keyboard  multiTap="2"  input=" "  />
             *            </action>
             *
             * <action  name="v_target_deselect_component"  ActivationMode="delayed_press"  pressTriggerThreshold="0.75"  joystick=""  >
             *                    <keyboard  >
             *                            <inputdata  input="lbracket"  />
             *                            <inputdata  input="rbracket"  />
             *                    </keyboard>
             *            </action>
             *
             */
            log.Debug("DProfileReader.ReadAction - Entry");
            // a complete actionmap arrives here
            bool retVal = true;

            string name    = (string)action.Attribute("name");
            string uiLabel = (string)action.Attribute("UILabel");

            if (string.IsNullOrEmpty(uiLabel))
            {
                uiLabel = name;                   // subst if not found in Action node
            }
            SCUiText.Instance.Add(name, uiLabel); // Register item for translation

            // prep all kinds
            var jAC = new ProfileAction( )
            {
                Name = name, UILabel = uiLabel, DevID = Act.DevTag(JoystickCls.DeviceClass)
            };
            var kAC = new ProfileAction( )
            {
                Name = name, UILabel = uiLabel, DevID = Act.DevTag(KeyboardCls.DeviceClass)
            };
            var mAC = new ProfileAction( )
            {
                Name = name, UILabel = uiLabel, DevID = Act.DevTag(MouseCls.DeviceClass)
            };
            var xAC = new ProfileAction( )
            {
                Name = name, UILabel = uiLabel, DevID = Act.DevTag(GamepadCls.DeviceClass)
            };

            // process element items
            JInput(ref jAC, action, (string)action.Attribute(JoystickCls.DeviceClass));
            KInput(ref kAC, action, (string)action.Attribute(KeyboardCls.DeviceClass));
            MInput(ref mAC, action, (string)action.Attribute(MouseCls.DeviceClass));
            XInput(ref xAC, action, (string)action.Attribute(GamepadCls.DeviceClass));

            // then nested ones - they may or may not exist from the initial scan
            foreach (XElement l1action in action.Elements( ))
            {
                // comes with the name of the device class
                switch (l1action.Name.LocalName)
                {
                case JoystickCls.DeviceClass: {
                    JInput(ref jAC, l1action, (string)l1action.Attribute("input")); // may have attributed ones
                    foreach (XElement l2action in l1action.Elements( ))
                    {
                        if (l2action.Name.LocalName == "inputdata")
                        {
                            JInput(ref jAC, l2action, (string)l2action.Attribute("input")); // or in the inputdata nesting
                        }
                    }
                }
                break;

                case KeyboardCls.DeviceClass: {
                    KInput(ref kAC, l1action, (string)l1action.Attribute("input")); // may have attributed ones
                    foreach (XElement l2action in l1action.Elements( ))
                    {
                        if (l2action.Name.LocalName == "inputdata")
                        {
                            KInput(ref kAC, l2action, (string)l2action.Attribute("input")); // or in the inputdata nesting
                        }
                    }
                }
                break;

                case MouseCls.DeviceClass: {
                    MInput(ref mAC, l1action, (string)l1action.Attribute("input")); // may have attributed ones
                    foreach (XElement l2action in l1action.Elements( ))
                    {
                        if (l2action.Name.LocalName == "inputdata")
                        {
                            MInput(ref mAC, l2action, (string)l2action.Attribute("input")); // or in the inputdata nesting
                        }
                    }
                }
                break;

                case GamepadCls.DeviceClass: {
                    XInput(ref xAC, l1action, (string)l1action.Attribute("input")); // may have attributed ones
                    foreach (XElement l2action in l1action.Elements( ))
                    {
                        if (l2action.Name.LocalName == "inputdata")
                        {
                            XInput(ref xAC, l2action, (string)l2action.Attribute("input")); // or in the inputdata nesting
                        }
                    }
                }
                break;

                default: break;
                }
            }

            if (!string.IsNullOrEmpty(jAC.DefBinding))
            {
                m_currentMap.Add(jAC);                                         // finally add it to the current map if it was bound
            }
            if (!string.IsNullOrEmpty(kAC.DefBinding))
            {
                m_currentMap.Add(kAC);                                         // finally add it to the current map if it was bound
            }
            if (!string.IsNullOrEmpty(mAC.DefBinding))
            {
                m_currentMap.Add(mAC);                                         // finally add it to the current map if it was bound
            }
            if (!string.IsNullOrEmpty(xAC.DefBinding))
            {
                m_currentMap.Add(xAC);                                         // finally add it to the current map if it was bound
            }
            return(retVal);
        }