Ejemplo n.º 1
0
 public static MenuItem AddStringList(this Menu config, string name, string displayName, string[] stringList = null, int Index = 0)
 {
     if (config.Items.Any(m => m.Name == name))
     {
         DeBug.Write("创建菜单错误", $"已经包含了名为{name}的菜单!", DebugLevel.Warning);
     }
     return(config.AddItem(new MenuItem(name, MultiLanguage._(displayName)).SetValue(new StringList(stringList.Select(s => MultiLanguage._(s)).ToArray(), Index))));
 }
Ejemplo n.º 2
0
 public static MenuItem AddSlider(this Menu config, string name, string displayName, int Defaults = 0, int min = 0, int max = 100)
 {
     if (config.Items.Any(m => m.Name == name))
     {
         DeBug.Write("创建菜单错误", $"已经包含了名为{name}的菜单!", DebugLevel.Warning);
     }
     return(config.AddItem(new MenuItem(name, MultiLanguage._(displayName)).SetValue(new Slider(Defaults, min, max))));
 }
Ejemplo n.º 3
0
 public static MenuItem AddCircle(this Menu config, string name, string displayName, bool active = false, Color color = new Color())
 {
     if (config.Items.Any(m => m.Name == name))
     {
         DeBug.Write("创建菜单错误", $"已经包含了名为{name}的菜单!", DebugLevel.Warning);
     }
     return(config.AddItem(new MenuItem(name, MultiLanguage._(displayName)).SetValue(new Circle(active, color))));
 }
Ejemplo n.º 4
0
 public static MenuItem AddKeyBind(this Menu config, string name, string displayName, uint key, KeyBindType type, bool active = false)
 {
     if (config.Items.Any(m => m.Name == name))
     {
         DeBug.Write("创建菜单错误", $"已经包含了名为{name}的菜单!", DebugLevel.Warning);
     }
     return(config.AddItem(new MenuItem(name, MultiLanguage._(displayName)).SetValue(new KeyBind(key, type, active))));
 }
Ejemplo n.º 5
0
 public static void Load(Dictionary <string, Dictionary <string, string> > LanguageDictionary)
 {
     DeBug.Debug($"IsChinese{IsCN}");
     if (!IsCN)
     {
         Translations = LanguageDictionary["English"];
     }
 }
Ejemplo n.º 6
0
        public static MenuItem AddBool(this Menu config, string name, string displayName, bool Defaults = false)
        {
            if (config.Items.Any(m => m.Name == name))
            {
                DeBug.Debug("创建菜单错误", $"已经包含了名为{name}的菜单!", DebugLevel.Warning);
            }

            return(config.AddItem(new MenuItem(name, MultiLanguage._(displayName)).SetValue(Defaults)));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 添加子菜单
        /// </summary>
        /// <param name="config"></param>
        /// <param name="name"></param>
        /// <param name="displayName"></param>
        /// <returns></returns>
        public static Menu AddMenu(this Menu config, string name, string displayName)
        {
            if (config.Children.Any(m => m.Name == name))
            {
                DeBug.Write("创建菜单错误", $"已经包含了名为{name}的子菜单!", DebugLevel.Warning);
            }

            return(config.AddSubMenu(new Menu(MultiLanguage._(displayName), name)));
        }
Ejemplo n.º 8
0
        public string ReadFile()
        {
            var path = Path.Combine(StoragePath, StorageName + ".json");

            DeBug.Debug("[存储]", $"StorageName:{StorageName} 存储位置:{path}");
            if (File.Exists(path))
            {
                return(File.ReadAllText(path));
            }
            return(string.Empty);
        }
Ejemplo n.º 9
0
 public static StringList GetStringList(this Menu config, string name)
 {
     try
     {
         return(config.Item(name).GetValue <StringList>());
     }
     catch (Exception)
     {
         DeBug.WriteConsole("[菜单取值]", $"名为{name}的菜单项的值类型不是StringList", DebugLevel.Wrang);
     }
     return(new StringList());
 }
Ejemplo n.º 10
0
 public static KeyBind GetKeyBind(this Menu config, string name)
 {
     try
     {
         return(config.Item(name).GetValue <KeyBind>());
     }
     catch (Exception)
     {
         DeBug.WriteConsole("[菜单取值]", $"名为{name}的菜单项的值类型不是KeyBind", DebugLevel.Wrang);
     }
     return(new KeyBind());
 }
Ejemplo n.º 11
0
 public static bool GetKeyActive(this Menu config, string name)
 {
     try
     {
         return(config.Item(name).GetValue <KeyBind>().Active);
     }
     catch (Exception)
     {
         DeBug.WriteConsole("[菜单取值]", $"名为{name}的菜单项的值类型不是KeyActive", DebugLevel.Wrang);
     }
     return(false);
 }
Ejemplo n.º 12
0
 public static Color GetCircleColor(this Menu config, string name)
 {
     try
     {
         return(config.Item(name).GetValue <Circle>().Color);
     }
     catch (Exception)
     {
         DeBug.WriteConsole("[菜单取值]", $"名为{name}的菜单项的值类型不是CircleColor", DebugLevel.Wrang);
     }
     return(Color.White);
 }
Ejemplo n.º 13
0
 public static int GetSliderValue(this Menu config, string name)
 {
     try
     {
         return(config.Item(name).GetValue <Slider>().Value);
     }
     catch (Exception)
     {
         DeBug.WriteConsole("[菜单取值]", $"名为{name}的菜单项的值类型不是SliderValue", DebugLevel.Wrang);
     }
     return(0);
 }
Ejemplo n.º 14
0
 public static int GetStringIndex(this Menu config, string name)
 {
     try
     {
         return(config.Item(name).GetValue <StringList>().SelectedIndex);
     }
     catch (Exception)
     {
         DeBug.WriteConsole("[菜单取值]", $"名为{name}的菜单项的值类型不是StringIndex", DebugLevel.Wrang);
     }
     return(0);
 }
Ejemplo n.º 15
0
 public static bool GetBool(this Menu config, string name)
 {
     try
     {
         return(config.Item(name).GetValue <bool>());
     }
     catch (Exception ex)
     {
         DeBug.WriteConsole("[菜单取值]", $"名为{name}的菜单项的值类型不是bool", DebugLevel.Wrang);
     }
     return(false);
 }
Ejemplo n.º 16
0
        public void Save()
        {
            var path = Path.Combine(StoragePath, StorageName + ".json");

            DeBug.Debug("[存储]", $"StorageName:{StorageName} 存储位置:{path}");

            //DeBug.Debug("[存储]", $"============Instance.Contents内容===============");
            //foreach (var item in Contents)
            //{
            //	DeBug.Debug("[存储]", $"键:{item.key} 值:{item.value}");
            //}
            //DeBug.Debug("[存储]", $"============Instance.Contents内容===============");

            File.WriteAllText(path, JsonConvert.SerializeObject(this));
        }
Ejemplo n.º 17
0
        private static async void News()
        {
            try
            {
                using (var web = new WebClient())
                {
                    var rawFile = await web.DownloadStringTaskAsync(NewsUrl);

                    if (!string.IsNullOrEmpty(rawFile))
                    {
                        Game.PrintChat("[新闻]".ToHtml(Color.Gold, FontStlye.Bold)
                                       + " "
                                       + MenuConfig.DisplayName.ToHtml(Color.SkyBlue, FontStlye.Bold)
                                       + rawFile);
                    }
                }
            }
            catch (Exception ex)
            {
                DeBug.WriteConsole("[新闻]", MenuConfig.DisplayName + "获取新闻发生了异常\n" + ex.Message, DebugLevel.Warning);
            }
        }
Ejemplo n.º 18
0
        private static async void UpdateCheck()
        {
            try
            {
                using (var web = new WebClient())
                {
                    var rawFile = await web.DownloadStringTaskAsync(CheckUrl);

                    var checkFile =
                        new Regex(@"\[assembly\: AssemblyVersion\(""(\d{1,})\.(\d{1,})\.(\d{1,})\.(\d{1,})""\)\]").Match
                            (rawFile);
                    if (!checkFile.Success)
                    {
                        return;
                    }
                    var gitVersion =
                        new System.Version(
                            $"{checkFile.Groups[1]}.{checkFile.Groups[2]}.{checkFile.Groups[3]}.{checkFile.Groups[4]}");
                    if (gitVersion > Assembly.GetExecutingAssembly().GetName().Version)
                    {
                        Game.PrintChat("[版本检查]".ToHtml(Color.Gold, FontStlye.Bold)
                                       + " "
                                       + MenuConfig.DisplayName.ToHtml(Color.SkyBlue, FontStlye.Bold)
                                       + " "
                                       + "有新版本".ToHtml(Color.SkyBlue) + gitVersion.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Game.PrintChat("[版本检查]".ToHtml(Color.Gold, FontStlye.Bold)
                               + " "
                               + MenuConfig.DisplayName.ToHtml(Color.Red, FontStlye.Bold)
                               + " "
                               + "的版本检查发生了异常".ToHtml(Color.Red));

                DeBug.WriteConsole("[版本检查]", MenuConfig.DisplayName + "的版本检查发生了异常\n" + ex.Message, DebugLevel.Warning);
            }
        }
Ejemplo n.º 19
0
 private static bool IsChinese()
 {
     if (!string.IsNullOrEmpty(Config.SelectedLanguage))
     {
         if (Config.SelectedLanguage == "Chinese")
         {
             return(true);
         }
     }
     else
     {
         var CultureName = System.Globalization.CultureInfo.InstalledUICulture.Name;
         var lid         = CultureName.Contains("-")
                                         ? CultureName.Split('-')[0].ToUpperInvariant()
                                         : CultureName.ToUpperInvariant();
         DeBug.Debug($"lid:{System.Globalization.CultureInfo.InstalledUICulture.Name}");
         DeBug.Debug($"lid:{lid}");
         if (lid == "ZH")
         {
             return(true);
         }
     }
     return(false);
 }