diff --git a/src/MaaWpfGui/Helper/StageManager.cs b/src/MaaWpfGui/Helper/StageManager.cs index c75b7499d6..1c7a0943fd 100644 --- a/src/MaaWpfGui/Helper/StageManager.cs +++ b/src/MaaWpfGui/Helper/StageManager.cs @@ -92,40 +92,6 @@ namespace MaaWpfGui // new StageInfo { Display = Localization.GetString("CurrentStage"), Value = string.Empty }, // new StageInfo { Display = Localization.GetString("LastBattle"), Value = "LastBattle" }, }; - - var language = ViewStatusStorage.Get("GUI.Localization", Localization.DefaultLanguage); - string filename = string.Empty; - if (language == "zh-cn") - { - filename = Directory.GetCurrentDirectory() + "\\resource\\item_index.json"; - } - else if (language == "pallas") - { - // DoNothing - } - else - { - Dictionary client = new Dictionary - { - { "zh-tw", "txwy" }, - { "en-us", "YoStarEN" }, - { "ja-jp", "YoStarJP" }, - { "ko-kr", "YoStarKR" }, - }; - filename = Directory.GetCurrentDirectory() + "\\resource\\global\\" + client[language] + "\\resource\\item_index.json"; - } - - if (File.Exists(filename)) - { - try - { - data = JsonConvert.DeserializeObject>>(File.ReadAllText(filename)); - } - catch - { - // DoNothing - } - } } /// @@ -150,8 +116,6 @@ namespace MaaWpfGui return GetStageInfo(stage)?.IsStageOpen(dayOfWeek) == true; } - private readonly Dictionary> data; - /// /// Gets open stage tips at specified day of week /// @@ -183,10 +147,7 @@ namespace MaaWpfGui if (!string.IsNullOrEmpty(item.Value.Drop)) { - if (data != null && data.ContainsKey(item.Value.Drop)) - { - builder.AppendLine(item.Value.Display + ": " + data[item.Value.Drop]["name"]); - } + builder.AppendLine(item.Value.Display + ": " + Utils.GetItemName(item.Value.Drop)); } } } diff --git a/src/MaaWpfGui/Helper/Utils.cs b/src/MaaWpfGui/Helper/Utils.cs index f7a29922ab..3f3bf858fd 100644 --- a/src/MaaWpfGui/Helper/Utils.cs +++ b/src/MaaWpfGui/Helper/Utils.cs @@ -12,11 +12,52 @@ // using System; +using System.Collections.Generic; +using System.IO; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace MaaWpfGui { public static class Utils { + static Utils() + { + var language = ViewStatusStorage.Get("GUI.Localization", Localization.DefaultLanguage); + string filename = string.Empty; + if (language == "zh-cn") + { + filename = Directory.GetCurrentDirectory() + "\\resource\\item_index.json"; + } + else if (language == "pallas") + { + // DoNothing + } + else + { + Dictionary client = new Dictionary + { + { "zh-tw", "txwy" }, + { "en-us", "YoStarEN" }, + { "ja-jp", "YoStarJP" }, + { "ko-kr", "YoStarKR" }, + }; + filename = Directory.GetCurrentDirectory() + "\\resource\\global\\" + client[language] + "\\resource\\item_index.json"; + } + + if (File.Exists(filename)) + { + try + { + _itemList = (JObject)JsonConvert.DeserializeObject(File.ReadAllText(filename)); + } + catch + { + // DoNothing + } + } + } + /// /// 获取yj历时间 /// @@ -62,5 +103,21 @@ namespace MaaWpfGui { return dt.AddHours(4); } + + private static readonly JObject _itemList = new JObject(); + + public static JObject GetItemList() => _itemList; + + public static string GetItemName(string id) + { + if (_itemList.ContainsKey(id)) + { + return _itemList[id]["name"].ToString(); + } + else + { + return id; + } + } } }