From 3daed8a02283c5771533416d6cd2f2719d584402 Mon Sep 17 00:00:00 2001 From: Hakoyu Date: Tue, 23 Apr 2024 23:46:53 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E4=BF=AE=E5=A4=8D=20-=20=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=97=B6=E6=9C=AC=E4=BD=93=E5=AE=A0=E7=89=A9=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=BD=BD=E5=85=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VPet.ModMaker/Converters.xaml | 2 +- VPet.ModMaker/Models/ModMaker.cs | 2 +- VPet.ModMaker/Models/ModMakerInfo.cs | 15 ++++++++ VPet.ModMaker/Models/ModModel/ModInfoModel.cs | 14 ++++---- VPet.ModMaker/Models/ModModel/PetModel.cs | 35 +++++++++++++++---- VPet.ModMaker/VPet.ModMaker.csproj | 26 +++++++------- .../ModEdit/AnimeEdit/AnimePageVM.cs | 15 ++++++++ .../ViewModels/ModEdit/PetEdit/PetPageVM.cs | 25 ++++++++++++- .../ViewModels/ModEdit/WorkEdit/WorkPageVM.cs | 15 ++++++++ .../Views/ModEdit/PetEdit/PetPage.xaml | 2 +- 10 files changed, 119 insertions(+), 32 deletions(-) diff --git a/VPet.ModMaker/Converters.xaml b/VPet.ModMaker/Converters.xaml index edc69e2..b471dc2 100644 --- a/VPet.ModMaker/Converters.xaml +++ b/VPet.ModMaker/Converters.xaml @@ -5,7 +5,7 @@ - + diff --git a/VPet.ModMaker/Models/ModMaker.cs b/VPet.ModMaker/Models/ModMaker.cs index 0110c0f..a2c2e52 100644 --- a/VPet.ModMaker/Models/ModMaker.cs +++ b/VPet.ModMaker/Models/ModMaker.cs @@ -40,7 +40,7 @@ public class ModMaker : MainPlugin Application.Current.Resources.MergedDictionaries.Add(ModMakerInfo.NativeStyles); } - public I18nResource I18nResource { get; } = + public static I18nResource I18nResource { get; } = new() { FillDefaultValueForNewCulture = true, DefaultValue = string.Empty }; public override void Setting() diff --git a/VPet.ModMaker/Models/ModMakerInfo.cs b/VPet.ModMaker/Models/ModMakerInfo.cs index 9fb59f1..44966b1 100644 --- a/VPet.ModMaker/Models/ModMakerInfo.cs +++ b/VPet.ModMaker/Models/ModMakerInfo.cs @@ -55,4 +55,19 @@ public static class ModMakerInfo { return AnimeTypeModel.HasNameAnimes.Contains(graphType); } + + static ModMakerInfo() + { + //#if DEBUG + // MainPets.TryAdd( + // "TestMainPet", + // new() + // { + // ID = "TestMainPet", + // FromMain = true, + // I18nResource = new() + // } + // ); + //#endif + } } diff --git a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs index c189347..083c341 100644 --- a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs +++ b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs @@ -47,6 +47,12 @@ public class ModInfoModel : ObservableObjectX ] ) ); + foreach (var pet in ModMakerInfo.MainPets) + { + // 确保ID不重复 + if (Pets.All(i => i.ID != pet.Key)) + Pets.Add(pet.Value); + } } public ModInfoModel(ModLoader loader) @@ -118,14 +124,6 @@ public class ModInfoModel : ObservableObjectX foreach (var p in pet.path) LoadAnime(petModel, p); } - - // 插入本体宠物 - foreach (var pet in ModMakerInfo.MainPets) - { - // 确保ID不重复 - if (Pets.All(i => i.ID != pet.Key)) - Pets.Insert(0, pet.Value); - } if (loader.I18nDatas.HasValue() is false) return; LoadI18nDatas(loader); diff --git a/VPet.ModMaker/Models/ModModel/PetModel.cs b/VPet.ModMaker/Models/ModModel/PetModel.cs index 219f16a..21282f4 100644 --- a/VPet.ModMaker/Models/ModModel/PetModel.cs +++ b/VPet.ModMaker/Models/ModModel/PetModel.cs @@ -112,12 +112,7 @@ public class PetModel : ObservableObjectX RaisePoint.Ill = new(loader.Config.RaisePoint[3].X, loader.Config.RaisePoint[3].Y); // 如果这个宠物数据来自本体, 则不载入 Work 和 Move if (FromMain = fromMain) - { - Name = ID.Translate(); - PetName = PetNameID.Translate(); - Description = DescriptionID.Translate(); return; - } foreach (var work in loader.Config.Works) Works.Add(new(work) { I18nResource = I18nResource! }); @@ -163,7 +158,7 @@ public class PetModel : ObservableObjectX private string _petNameID = string.Empty; /// - /// 名称Id + /// 名称ID /// public string PetNameID { @@ -177,7 +172,7 @@ public class PetModel : ObservableObjectX private string _descriptionID = string.Empty; /// - /// 描述Id + /// 描述ID /// public string DescriptionID { @@ -217,6 +212,32 @@ public class PetModel : ObservableObjectX ] ) ); + if (FromMain) + { + foreach (var cultureName in LocalizeCore.AvailableCultures) + { + if (LocalizeCore.Localizations.TryGetValue(cultureName, out var data) is false) + continue; + foreach (var line in data) + { + if (line?.Name == ID) + { + I18nResource.AddCultureData(cultureName, ID, line.Info); + } + else if (line?.Name == PetNameID) + { + I18nResource.AddCultureData(cultureName, PetNameID, line.Info); + } + else if (line?.Name == DescriptionID) + { + I18nResource.AddCultureData(cultureName, DescriptionID, line.Info); + } + } + I18nResource.AddCultureData(cultureName, ID, ID); + I18nResource.AddCultureData(cultureName, PetNameID, PetNameID); + I18nResource.AddCultureData(cultureName, DescriptionID, DescriptionID); + } + } } [AdaptIgnore] diff --git a/VPet.ModMaker/VPet.ModMaker.csproj b/VPet.ModMaker/VPet.ModMaker.csproj index 586afe8..4fa50e4 100644 --- a/VPet.ModMaker/VPet.ModMaker.csproj +++ b/VPet.ModMaker/VPet.ModMaker.csproj @@ -14,34 +14,34 @@ Debug;Release;Test - embedded + embedded - embedded + embedded - embedded + embedded - - ..\..\HKW.Utils\HKW.Utils\bin\Debug\net8.0\HKW.Utils.dll - - - ..\..\HKW.WPF\HKW.WPF\bin\Debug\net8.0-windows\HKW.WPF.dll - + + ..\..\HKW.Utils\HKW.Utils\bin\Debug\net8.0\HKW.Utils.dll + + + ..\..\HKW.WPF\HKW.WPF\bin\Debug\net8.0-windows\HKW.WPF.dll + - + - - + + - + diff --git a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimePageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimePageVM.cs index afbc64d..d4610f4 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimePageVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimePageVM.cs @@ -48,6 +48,21 @@ public class AnimePageVM : ObservableObjectX AddCommand.ExecuteCommand += AddCommand_ExecuteCommand; EditCommand.ExecuteCommand += EditCommand_ExecuteCommand; RemoveCommand.ExecuteCommand += RemoveCommand_ExecuteCommand; + ModInfo.PropertyChangedX += ModInfo_PropertyChangedX; + } + + private void ModInfo_PropertyChangedX(object? sender, PropertyChangedXEventArgs e) + { + if (e.PropertyName == nameof(ModInfoModel.ShowMainPet)) + { + if (e.NewValue is false) + { + if (CurrentPet.FromMain) + { + CurrentPet = null!; + } + } + } } private void AnimePageVM_PropertyChangedX(object? sender, PropertyChangedXEventArgs e) diff --git a/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetPageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetPageVM.cs index fc5bbfc..44458de 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetPageVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetPageVM.cs @@ -21,7 +21,12 @@ public class PetPageVM : ObservableObjectX { Pets = new(ModInfoModel.Current.Pets) { - Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase), + Filter = (f) => + { + if (ShowMainPet is false && f.FromMain) + return false; + return f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase); + }, FilteredList = new() }; Pets.BindingList(ModInfoModel.Current.Pets); @@ -59,6 +64,24 @@ public class PetPageVM : ObservableObjectX } } #endregion + + + #region ShowMainPet + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private bool _showMainPet; + + public bool ShowMainPet + { + get => _showMainPet; + set + { + SetProperty(ref _showMainPet, value); + ModInfo.ShowMainPet = value; + Pets.Refresh(); + } + } + #endregion + #endregion #region Command public ObservableCommand AddCommand { get; } = new(); diff --git a/VPet.ModMaker/ViewModels/ModEdit/WorkEdit/WorkPageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/WorkEdit/WorkPageVM.cs index 9bcd391..dda81ea 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/WorkEdit/WorkPageVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/WorkEdit/WorkPageVM.cs @@ -34,6 +34,21 @@ public class WorkPageVM : ObservableObjectX AddCommand.ExecuteCommand += AddCommand_ExecuteCommand; EditCommand.ExecuteCommand += EditCommand_ExecuteCommand; RemoveCommand.ExecuteCommand += RemoveCommand_ExecuteCommand; + ModInfo.PropertyChangedX += ModInfo_PropertyChangedX; + } + + private void ModInfo_PropertyChangedX(object? sender, PropertyChangedXEventArgs e) + { + if (e.PropertyName == nameof(ModInfoModel.ShowMainPet)) + { + if (e.NewValue is false) + { + if (CurrentPet.FromMain) + { + CurrentPet = null!; + } + } + } } public static ModInfoModel ModInfo => ModInfoModel.Current; diff --git a/VPet.ModMaker/Views/ModEdit/PetEdit/PetPage.xaml b/VPet.ModMaker/Views/ModEdit/PetEdit/PetPage.xaml index 1740f17..9186cd6 100644 --- a/VPet.ModMaker/Views/ModEdit/PetEdit/PetPage.xaml +++ b/VPet.ModMaker/Views/ModEdit/PetEdit/PetPage.xaml @@ -30,7 +30,7 @@ + IsChecked="{Binding ShowMainPet}" />