Example #1
0
        /// <summary>
        /// Read the defaultProfile.xml - do some sanity check
        /// </summary>
        /// <param name="xml">the XML action defaultProfile Content</param>
        /// <returns>True if an action was decoded</returns>
        public Boolean fromXML(String xml)
        {
            log.Debug("DProfileReader.fromXML - Entry");

            if (ActionMapsCls.ActionMaps.Length == 0)
            {
                ActionMapsCls.LoadSupportedActionMaps(ActionMapList(xml));                                       // make sure we have them loaded ( refactoring to get a singleton or so...)
            }
            XmlReaderSettings settings = new XmlReaderSettings( );

            settings.ConformanceLevel = ConformanceLevel.Fragment;
            settings.IgnoreWhitespace = true;
            settings.IgnoreComments   = true;
            XmlReader reader = XmlReader.Create(new StringReader(xml), settings);


            m_nodeNameStack = new Stack <String>( );
            m_aMap          = new Dictionary <String, ActionMap>( );
            // init the activation modes singleton
            ActivationModes.Instance.Clear( );
            ActivationModes.Instance.Add(ActivationMode.Default);

            ValidContent = true; // init
            reader.Read( );
            ValidContent &= ReadActivationModes(reader);

            m_nodeNameStack.Push("profile"); // we are already in the XML now

            ValidContent &= ReadXML(reader);

            return(ValidContent);
        }
        /// <summary>
        /// Read the defaultProfile.xml - do some sanity check
        /// </summary>
        /// <param name="xml">the XML action defaultProfile Content</param>
        /// <returns>True if an action was decoded</returns>
        public bool fromXML(string xml)
        {
            log.Debug("DProfileReader.fromXML - Entry");

            // make sure we have them loaded ( refactoring to get a singleton or so...)
            if (ActionMapsCls.ActionMaps.Length == 0)
            {
                ActionMapsCls.LoadSupportedActionMaps(ActionMapList(xml));
            }

            // read the content of the xml
            XmlReaderSettings settings = new XmlReaderSettings {
                ConformanceLevel = ConformanceLevel.Fragment,
                IgnoreWhitespace = true,
                IgnoreComments   = true
            };

            using (XmlReader reader = XmlReader.Create(new StringReader(xml), settings)) {
                m_aMap = new Dictionary <string, ActionMap>( );
                // init the activation modes singleton
                ActivationModes.Instance.Clear( );
                ActivationModes.Instance.Add(ActivationMode.Default);

                ValidContent = true; // init

                reader.MoveToContent( );
                if (XNode.ReadFrom(reader) is XElement el)
                {
                    IEnumerable <XElement> activationModes = from x in el.Elements( )
                                                             where (x.Name == "ActivationModes")
                                                             select x;
                    foreach (XElement activationMode in activationModes)
                    {
                        ValidContent &= ReadActivationModes(activationMode);
                    }


                    Modifiers.Instance.Clear( );
                    IEnumerable <XElement> modifiers = from x in el.Elements( )
                                                       where (x.Name == "modifiers")
                                                       select x;
                    foreach (XElement modifier in modifiers)
                    {
                        ValidContent &= Modifiers.Instance.FromXML(modifier, true);
                    }

                    OptionTree.InitOptionReader( );
                    IEnumerable <XElement> optiontrees = from x in el.Elements( )
                                                         where (x.Name == "optiontree")
                                                         select x;
                    foreach (XElement optiontree in optiontrees)
                    {
                        ValidContent &= OptionTree.fromProfileXML(optiontree);
                    }

                    IEnumerable <XElement> actionmaps = from x in el.Elements( )
                                                        where (x.Name == "actionmap")
                                                        select x;
                    foreach (XElement actionmap in actionmaps)
                    {
                        ValidContent &= ReadActionmap(actionmap);
                    }
                }
            }
            return(ValidContent);
        }
Example #3
0
        /// <summary>
        /// Load Mappings into the ActionList and create the Master TreeView 
        /// </summary>
        /// <param name="defaultProfileName">The name of the profile to load (w/o extension)</param>
        /// <param name="applyDefaults">True if default mappings should be carried on</param>
        public void LoadProfileTree( String defaultProfileName, Boolean applyDefaults )
        {
            log.Debug( "LoadProfileTree - Entry" );

              ActionTreeNode tn = null;
              ActionTreeNode[] cnl = { };
              ActionTreeNode cn = null;
              ActionTreeNode topNode = null;

              ActionMapCls acm = null;
              ActionCls ac = null;
              ActionCommandCls acc = null;

              ActionMaps = new ActionMapsCls( m_jsList );
              m_MasterTree.Nodes.Clear( );

              // read the action items into the TreeView
              DProfileReader dpReader = new DProfileReader( ); // we may read a profile
              TextReader txReader = null;

              dpReader.fromXML( SCDefaultProfile.DefaultProfile( defaultProfileName + ".xml" ) );
              if ( dpReader.ValidContent ) {
            txReader = new StringReader( dpReader.CSVMap );
              }

              // we assume no addbind items in the profile
              //  so all actions are shown in the ActionTreeNode and no ActionTreeNode childs must be created here
              //  however we create the ActionCommand for each entry that is supported - even if it is not mapped (input= "")
              using ( TextReader sr = txReader ) {
            String buf = sr.ReadLine( );
            while ( !String.IsNullOrEmpty( buf ) ) {
              String[] elem = buf.Split( new char[] { ';', ',' } );
              if ( elem.Length > 1 ) {
            if ( !IgnoreMaps.Contains( "," + elem[0] + "," ) ) {
              // must have 2 elements min
              Array.Resize( ref cnl, 0 );
              acm = new ActionMapCls( ); acm.name = elem[0]; // get actionmap name
              // process items
              for ( int ei=1; ei < elem.Length; ei += 2 ) { // step 2  - action;defaultBinding come in pairs
                if ( !String.IsNullOrEmpty( elem[ei] ) ) {
                  // default assignments
                  String action = elem[ei].Substring( 1 );
                  String defBinding = elem[ei + 1].Substring( 0 );
                  String devID = elem[ei].Substring( 0, 1 );
                  String device = ActionCls.DeviceFromID( devID );

                  // visual item for the action
                  cn = new ActionTreeNode( "UNDEF" ); cn.Name = elem[ei]; cn.Action = action; cn.BackColor = Color.White; // name with the key it to find it..
                  cn.ImageKey = devID; cn.BackColor = Color.White; // some stuff does not work properly...
                  Array.Resize( ref cnl, cnl.Length + 1 ); cnl[cnl.Length - 1] = cn;

                  // derive content tree
                  ac = new ActionCls( ); ac.key = cn.Name; ac.name = action; ac.device = device; ac.actionDevice = ActionCls.ADevice( device ); ac.defBinding = defBinding;
                  acm.Add( ac ); // add to our map
                  cn.ActionDevice = ac.actionDevice; // should be known now
                  // create just an unmapped ActionCommand item
                  acc = new ActionCommandCls( ); acc.input = ""; acc.nodeIndex = -1; // profile items are shown in the ActionTreeNode (not in a child)
                  ac.inputList.Add( acc );// add to our Action

                  // modify defaults and blendings
                  if ( applyDefaults ) {
                    // apply the default mappings
                    if ( ac.actionDevice == ActionCls.ActionDevice.AD_Joystick ) {
                      int jNum = JoystickCls.JSNum( ac.defBinding );
                      if ( JoystickCls.IsJSValid( jNum ) ) {
                        acc.input = ac.defBinding;
                        cn.Command = ac.defBinding; cn.BackColor = JoystickCls.JsNColor( jNum );
                      }
                      else if ( BlendUnmappedJS ) {
                        // jsx_reserved gets here
                        acc.input = JoystickCls.BlendedInput;
                        cn.Command = JoystickCls.BlendedInput; cn.BackColor = MyColors.BlendedColor;
                      }
                    }
                    else if ( ac.actionDevice == ActionCls.ActionDevice.AD_Gamepad ) {
                      if ( GamepadCls.IsXiValid( ac.defBinding ) ) {
                        acc.input = ac.defBinding;
                        cn.Command = ac.defBinding; cn.BackColor = GamepadCls.XiColor( );
                      }
                      else if ( BlendUnmappedGP ) {
                        // xi_reserved gets here
                        acc.input = GamepadCls.BlendedInput;
                        cn.Command = GamepadCls.BlendedInput; cn.BackColor = MyColors.BlendedColor;
                      }
                    }
                    else if ( ac.actionDevice == ActionCls.ActionDevice.AD_Keyboard ) {
                      if ( !String.IsNullOrEmpty( ac.defBinding ) ) {
                        acc.input = ac.defBinding;
                        cn.Command = ac.defBinding; cn.BackColor = KeyboardCls.KbdColor( );
                      }
                    }
                  }
                  // Don't apply defaults - but blend if checked
                  else {
                    if ( ( ac.actionDevice == ActionCls.ActionDevice.AD_Joystick ) && BlendUnmappedJS ) {
                      cn.Command = JoystickCls.BlendedInput; cn.BackColor = MyColors.BlendedColor;
                      acc.input = JoystickCls.BlendedInput;
                    }
                    else if ( ( ac.actionDevice == ActionCls.ActionDevice.AD_Gamepad ) && BlendUnmappedGP ) {
                      cn.Command = GamepadCls.BlendedInput; cn.BackColor = MyColors.BlendedColor;
                      acc.input = GamepadCls.BlendedInput;
                    }
                  }
                }
              }//for

              tn = new ActionTreeNode( acm.name, cnl ); tn.Name = acm.name;  // name it to find it..
              tn.ImageIndex = 0; tn.NodeFont = new Font( m_MasterTree.Font, FontStyle.Bold );
              m_MasterTree.BackColor = Color.White; // fix for defect TreeView (cut off bold text)
              m_MasterTree.Nodes.Add( tn ); // add to control
              if ( topNode == null ) topNode = tn; // once to keep the start of list
              ActionMaps.Add( acm ); // add to our map
            }//not ignored

              }// if valid line
              buf = sr.ReadLine( );
            }//while
              }
              // fix for defect TreeView (cut off bold text at last element -despite the BackColor fix) add another and delete it
              tn = new ActionTreeNode( "DUMMY" ); tn.Name = "DUMMY";
              tn.ImageIndex = 0; tn.NodeFont = new Font( m_MasterTree.Font, FontStyle.Bold );
              m_MasterTree.BackColor = m_MasterTree.BackColor; // fix for defect TreeView (cut off bold text)
              m_MasterTree.Nodes.Add( tn ); // add to control
              m_MasterTree.Nodes.RemoveByKey( "DUMMY" );
              // fix for defect TreeView (cut off bold text)

              txReader = null;
              Dirty = false;

              // finally apply the filter and make it visible
              FilterTree( );
        }