From cb609bbcc7fd9f2f093fb06adf19726bb311730d Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Fri, 29 Aug 2025 18:54:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=88=98=E6=96=97=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=82=96=E8=AE=BA=E6=A8=A1=E6=8B=9F=E5=85=B3=E5=8D=A1=E5=90=8D?= =?UTF-8?q?=E8=BD=AC=E4=B8=BA=E5=B9=B2=E5=91=98=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Helper/DataHelper.cs | 98 ++++++++++++++++--- .../ViewModels/UI/CopilotViewModel.cs | 29 +++--- 2 files changed, 104 insertions(+), 23 deletions(-) diff --git a/src/MaaWpfGui/Helper/DataHelper.cs b/src/MaaWpfGui/Helper/DataHelper.cs index c723b62a43..49b5340e53 100644 --- a/src/MaaWpfGui/Helper/DataHelper.cs +++ b/src/MaaWpfGui/Helper/DataHelper.cs @@ -46,11 +46,16 @@ namespace MaaWpfGui.Helper { "txwy", "zh-tw" }, }; - // 储存角色信息的字典 + /// + /// Gets 储存角色信息的字典 + /// public static Dictionary Characters { get; } = []; public static IReadOnlyDictionary Operators => Characters.Where(oper => oper.Value.IsOperator && !_virtuallyOpers.Contains(oper.Key)).ToDictionary(); + /// + /// Gets 当前语言与客户端类型下的干员名列表 + /// public static HashSet CharacterNames { get; } = []; public static Dictionary RecruitTags { get; private set; } = []; @@ -87,6 +92,7 @@ namespace MaaWpfGui.Helper CharacterNames.Clear(); foreach (var (key, value) in characterData) { + value.Id = key; Characters.Add(key, value); if (!key.StartsWith("char_")) { @@ -226,21 +232,35 @@ namespace MaaWpfGui.Helper return dict; } + /// + /// 通过任意服务器中对应的干员名获取干员信息 + /// + /// 任意服务器中的干员名 + /// 对应干员信息 public static CharacterInfo? GetCharacterByNameOrAlias(string characterName) { return _nameToCharacterMap.GetValueOrDefault(characterName); } + /// + /// 通过任意服务器中对应的干员名获取指定语言的干员名 + /// + /// 任意服务器中的干员名 + /// 指定语言,默认为当前语言 + /// 指定语言干员名 public static string? GetLocalizedCharacterName(string? characterName, string? language = null) { - if (string.IsNullOrEmpty(characterName)) - { - return null; - } - - return GetLocalizedCharacterName(GetCharacterByNameOrAlias(characterName), language); + return string.IsNullOrEmpty(characterName) + ? null + : GetLocalizedCharacterName(GetCharacterByNameOrAlias(characterName), language); } + /// + /// 通过干员信息获取指定语言的干员名 + /// + /// 干员信息 + /// 指定语言 + /// 指定语言干员名 public static string? GetLocalizedCharacterName(CharacterInfo? characterInfo, string? language = null) { if (characterInfo?.Name == null) @@ -260,6 +280,12 @@ namespace MaaWpfGui.Helper }; } + /// + /// 判断干员在指定客户端中是否可用 + /// + /// 干员信息 + /// 客户端类型 + /// 是否可用 public static bool IsCharacterAvailableInClient(CharacterInfo? character, string clientType) { if (character is null) @@ -277,14 +303,44 @@ namespace MaaWpfGui.Helper }; } + /// + /// 判断干员在指定客户端中是否可用 + /// + /// 干员名 + /// 客户端类型 + /// 是否可用 public static bool IsCharacterAvailableInClient(string characterName, string clientType) { var character = GetCharacterByNameOrAlias(characterName); return character != null && IsCharacterAvailableInClient(character, clientType); } + /// + /// 通过完整 ID 查询 + /// + /// 干员 id + /// 干员信息 + public static CharacterInfo? GetCharacterById(string id) + { + return Characters.GetValueOrDefault(id); + } + + /// + /// 通过代号查询(如 char_002_amiya 中的 amiya) + /// + /// 干员代号 + /// 干员信息 + public static CharacterInfo? GetCharacterByCodeName(string codeName) + { + return Characters.Values.FirstOrDefault(character => + character.CodeName.Equals(codeName, StringComparison.OrdinalIgnoreCase)); + } + public class CharacterInfo { + [JsonIgnore] + public string Id { get; set; } = string.Empty; + [JsonProperty("name")] public string? Name { get; set; } @@ -324,10 +380,15 @@ namespace MaaWpfGui.Helper [JsonProperty("rarity")] public int Rarity { get; set; } - public bool IsOperator => Profession == OperProfession.Caster || Profession == OperProfession.Medic - || Profession == OperProfession.Pioneer || Profession == OperProfession.Sniper - || Profession == OperProfession.Special || Profession == OperProfession.Support - || Profession == OperProfession.Tank || Profession == OperProfession.Warrior; + public bool IsOperator => Profession is + OperProfession.Caster or + OperProfession.Medic or + OperProfession.Pioneer or + OperProfession.Sniper or + OperProfession.Special or + OperProfession.Support or + OperProfession.Tank or + OperProfession.Warrior; public enum OperProfession { @@ -386,6 +447,21 @@ namespace MaaWpfGui.Helper /// Trap, } + + [JsonIgnore] + public string CodeName => ExtractCodeName(Id); + + private static string ExtractCodeName(string id) + { + if (string.IsNullOrEmpty(id)) + { + return string.Empty; + } + + // 从"char_002_amiya"中提取"amiya" + var parts = id.Split('_'); + return parts.Length >= 3 ? parts[2] : id; + } } public class MapInfo diff --git a/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs b/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs index 113b73d1bb..8b64c8f8f3 100644 --- a/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs @@ -1101,7 +1101,7 @@ namespace MaaWpfGui.ViewModels.UI cachePath = $"{CopilotJsonDir}/{fileName}_{DateTimeOffset.Now.ToUnixTimeMilliseconds()}.json"; if (CopilotItemViewModels.Any(i => i.FilePath == cachePath)) { - _logger.Error("Could not add copilot task with duplicate stage name: " + copilot.StageName); + _logger.Error("Could not add copilot task with duplicate stage name: {StageName}", copilot.StageName); _semaphore.Release(); return false; } @@ -1118,22 +1118,27 @@ namespace MaaWpfGui.ViewModels.UI return false; } - if (flags.HasFlag(CopilotModel.DifficultyFlags.Normal)) + if (ActiveTabIndex == 2) { - var item = new CopilotItemViewModel(stageName, cachePath, false, copilotId) - { - Index = CopilotItemViewModels.Count, - }; + var codeName = stageName![4..^2]; + var characterInfo = DataHelper.GetCharacterByCodeName(codeName); + var name = DataHelper.GetLocalizedCharacterName(characterInfo); + var item = new CopilotItemViewModel(name, cachePath, false, copilotId) { Index = CopilotItemViewModels.Count, }; CopilotItemViewModels.Add(item); } - - if (flags.HasFlag(CopilotModel.DifficultyFlags.Raid)) + else { - var item = new CopilotItemViewModel(stageName, cachePath, true, copilotId) + if (flags.HasFlag(CopilotModel.DifficultyFlags.Normal)) { - Index = CopilotItemViewModels.Count, - }; - CopilotItemViewModels.Add(item); + var item = new CopilotItemViewModel(stageName, cachePath, false, copilotId) { Index = CopilotItemViewModels.Count, }; + CopilotItemViewModels.Add(item); + } + + if (flags.HasFlag(CopilotModel.DifficultyFlags.Raid)) + { + var item = new CopilotItemViewModel(stageName, cachePath, true, copilotId) { Index = CopilotItemViewModels.Count, }; + CopilotItemViewModels.Add(item); + } } _semaphore.Release();