示例#1
0
        private void ReadKeySettingFromXml(string fileName)
        {
            var reader = XmlReader.Create(fileName, new XmlReaderSettings());

            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    switch (reader.LocalName)
                    {
                    case "KeyConfigs":
                        keyConfigs.Clear();
                        break;

                    case "KeyConfig":
                        var keyConfig = new KeyConfig
                        {
                            Name = reader.GetAttribute("Name")
                        };
                        keyConfigs.Add(keyConfig);
                        ReadKeySetting(reader.ReadSubtree(), keyConfig);
                        break;
                    }
                }
            }
            reader.Close();

            if (keyConfigs.Count == 0)
            {
                keyConfigs.Add(new KeyConfig());
            }
        }
示例#2
0
 private void WriteSetting(XmlWriter writer, KeyConfig keyConfig)
 {
     foreach (ButtonType buttonType in ButtonUtility.Array)
     {
         writer.WriteStartElement("Config");
         writer.WriteAttributeString("Type", buttonType.ToString());
         writer.WriteAttributeString("Key", ((int)keyConfig.GetKeyMap(buttonType)).ToString());
         writer.WriteAttributeString("Button", keyConfig.GetButtonMap(buttonType).ToString());
         writer.WriteEndElement();
     }
 }
示例#3
0
        private void ReadKeySettingFromIni(string fileName)
        {
            var keyConfig = new KeyConfig();
            var sr        = new StreamReader(fileName);
            var s         = sr.ReadToEnd().Replace("\r\n", "\n").Replace("\r", "\n");

            sr.Close();
            var sp = s.Split('\n');

            for (int i = 0; i < Math.Min(sp.Length, ButtonUtility.Array.Length); i++)
            {
                var secondsp = sp[i].Split(':');
                if (secondsp.Length >= 2)
                {
                    keyConfig.SetKeyMap(ButtonUtility.Array[i], (Key)int.Parse(secondsp[0]));
                    keyConfig.SetButtonMap(ButtonUtility.Array[i], int.Parse(secondsp[1]));
                }
            }
            keyConfigs.Add(keyConfig);
        }
示例#4
0
 private void ReadKeySetting(XmlReader reader, KeyConfig keyConfig)
 {
     while (reader.Read())
     {
         if (reader.IsStartElement())
         {
             switch (reader.LocalName)
             {
             case "Config":
                 var key = (Key)int.Parse(reader.GetAttribute("Key"));
                 int button = int.Parse(reader.GetAttribute("Button")), index = FindIndex(reader.GetAttribute("Type"));
                 if (index >= 0)
                 {
                     keyConfig.SetKeyMap(ButtonUtility.Array[index], key);
                     keyConfig.SetButtonMap(ButtonUtility.Array[index], button);
                 }
                 break;
             }
         }
     }
     reader.Close();
 }