From 479d995c84458ff9bc122ff0cc23a9fc2d8add4a Mon Sep 17 00:00:00 2001 From: Hakoyu Date: Mon, 11 Dec 2023 02:21:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VPet.ModMaker/Models/ModModel/FoodModel.cs | 4 +-- VPet.ModMaker/Models/ModModel/ModInfoModel.cs | 5 ++-- VPet.ModMaker/Models/ModModel/PetModel.cs | 20 ++++++++++++--- .../Models/ModModel/SelectTextModel.cs | 4 +-- .../ModEdit/I18nEdit/I18nEditWindowVM.cs | 4 ++- .../ViewModels/ModEdit/PetEdit/PetPageVM.cs | 25 ++++++++++++++----- .../Views/ModEdit/AnimeEdit/AnimePage.xaml | 2 +- .../Views/ModEdit/MoveEdit/MovePage.xaml | 2 +- .../Views/ModEdit/PetEdit/PetPage.xaml | 18 ++++++++++--- .../Views/ModEdit/WorkEdit/WorkPage.xaml | 2 +- 10 files changed, 62 insertions(+), 24 deletions(-) diff --git a/VPet.ModMaker/Models/ModModel/FoodModel.cs b/VPet.ModMaker/Models/ModModel/FoodModel.cs index 407eb6f..8c03954 100644 --- a/VPet.ModMaker/Models/ModModel/FoodModel.cs +++ b/VPet.ModMaker/Models/ModModel/FoodModel.cs @@ -97,9 +97,9 @@ public class FoodModel : I18nModel public FoodModel() { DescriptionId.Value = $"{Id.Value}_{nameof(DescriptionId)}"; - Id.ValueChanged += (o, n) => + Id.ValueChanged += (s, e) => { - DescriptionId.Value = $"{n}_{nameof(DescriptionId)}"; + DescriptionId.Value = $"{e.NewValue}_{nameof(DescriptionId)}"; }; ReferencePrice.AddNotifySender( Strength, diff --git a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs index 8b98542..ca3b32a 100644 --- a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs +++ b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs @@ -149,10 +149,11 @@ public class ModInfoModel : I18nModel { var petModel = new PetModel(pet); Pets.Add(petModel); + ModMakerInfo.MainPets.Add(petModel.Id.Value, new(pet, true)); foreach (var p in pet.path) LoadAnime(petModel, p); } - + Pets.Clear(); // 插入本体宠物 foreach (var pet in ModMakerInfo.MainPets) { @@ -392,7 +393,7 @@ public class ModInfoModel : I18nModel private void SavePets(string path) { var petPath = Path.Combine(path, "pet"); - if (Pets.Count == 0) + if (Pets.Count == 0 || Pets.All(m => m.CanSave() is false)) { if (Directory.Exists(petPath)) Directory.Delete(petPath, true); diff --git a/VPet.ModMaker/Models/ModModel/PetModel.cs b/VPet.ModMaker/Models/ModModel/PetModel.cs index 70e3674..b562eab 100644 --- a/VPet.ModMaker/Models/ModModel/PetModel.cs +++ b/VPet.ModMaker/Models/ModModel/PetModel.cs @@ -25,7 +25,7 @@ public class PetModel : I18nModel /// /// 来自本体 /// - public ObservableValue FromMain { get; set; } = new(false); + public ObservableValue FromMain { get; } = new(false); /// /// Id @@ -99,10 +99,10 @@ public class PetModel : I18nModel { PetNameId.Value = $"{Id.Value}_{nameof(PetNameId)}"; DescriptionId.Value = $"{Id.Value}_{nameof(DescriptionId)}"; - Id.ValueChanged += (o, n) => + Id.ValueChanged += (s, e) => { - PetNameId.Value = $"{n}_{nameof(PetNameId)}"; - DescriptionId.Value = $"{n}_{nameof(DescriptionId)}"; + PetNameId.Value = $"{e.NewValue}_{nameof(PetNameId)}"; + DescriptionId.Value = $"{e.NewValue}_{nameof(DescriptionId)}"; }; AnimeCount.AddNotifySender(Animes); AnimeCount.AddNotifySender(FoodAnimes); @@ -201,6 +201,18 @@ public class PetModel : I18nModel } #region Save + + /// + /// 能被保存 + /// + /// + public bool CanSave() + { + if (FromMain.Value && Works.Count == 0 && Animes.Count == 0 && FoodAnimes.Count == 0) + return false; + return true; + } + /// /// 保存宠物 /// diff --git a/VPet.ModMaker/Models/ModModel/SelectTextModel.cs b/VPet.ModMaker/Models/ModModel/SelectTextModel.cs index 3fb1a80..022ad17 100644 --- a/VPet.ModMaker/Models/ModModel/SelectTextModel.cs +++ b/VPet.ModMaker/Models/ModModel/SelectTextModel.cs @@ -95,9 +95,9 @@ public class SelectTextModel : I18nModel public SelectTextModel() { ChooseId.Value = $"{Id.Value}_{nameof(ChooseId)}"; - Id.ValueChanged += (o, n) => + Id.ValueChanged += (s, e) => { - ChooseId.Value = $"{n}_{nameof(ChooseId)}"; + ChooseId.Value = $"{e.NewValue}_{nameof(ChooseId)}"; }; } diff --git a/VPet.ModMaker/ViewModels/ModEdit/I18nEdit/I18nEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/I18nEdit/I18nEditWindowVM.cs index 02834a5..207be12 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/I18nEdit/I18nEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/I18nEdit/I18nEditWindowVM.cs @@ -292,7 +292,7 @@ public class I18nEditWindowVM /// 载入宠物 /// /// - private void LoadPets(ModInfoModel model) + public void LoadPets(ModInfoModel model) { foreach (var pet in model.Pets) { @@ -317,6 +317,8 @@ public class I18nEditWindowVM else if (e.Action is NotifyCollectionChangedAction.Remove) { var oldModel = (PetModel)e.OldItems[0]; + if (oldModel.FromMain.Value) + return; RemoveData(oldModel.Id, oldModel, (m) => m.Name); RemoveData(oldModel.DescriptionId, oldModel, (m) => m.Description); foreach (var work in oldModel.Works) diff --git a/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetPageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetPageVM.cs index 6b5c3a3..0f9dab0 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetPageVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetPageVM.cs @@ -9,6 +9,8 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using VPet.ModMaker.Models; +using VPet.ModMaker.ViewModels.ModEdit.I18nEdit; +using VPet.ModMaker.Views.ModEdit.I18nEdit; using VPet.ModMaker.Views.ModEdit.PetEdit; namespace VPet.ModMaker.ViewModels.ModEdit.PetEdit; @@ -66,12 +68,14 @@ public class PetPageVM public void Edit(PetModel model) { - if ( - model.FromMain.Value - && MessageBox.Show("这是本体自带的宠物, 确定要编辑吗".Translate(), "", MessageBoxButton.YesNo) + if (model.FromMain.Value) + { + if ( + MessageBox.Show("这是本体自带的宠物, 确定要编辑吗".Translate(), "", MessageBoxButton.YesNo) is not MessageBoxResult.Yes - ) - return; + ) + return; + } var window = new PetEditWindow(); var vm = window.ViewModel; vm.OldPet = model; @@ -79,7 +83,16 @@ public class PetPageVM window.ShowDialog(); if (window.IsCancel) return; - Pets[Pets.IndexOf(model)] = newPet; + if (model.FromMain.Value) + { + var index = Pets.IndexOf(model); + Pets.Remove(model); + Pets.Insert(index, newPet); + } + else + { + Pets[Pets.IndexOf(model)] = newPet; + } if (ShowPets.Value.Count != Pets.Count) ShowPets.Value[ShowPets.Value.IndexOf(model)] = newPet; model.Close(); diff --git a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimePage.xaml b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimePage.xaml index 4a22cea..d91bbf6 100644 --- a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimePage.xaml +++ b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimePage.xaml @@ -51,7 +51,7 @@ - + diff --git a/VPet.ModMaker/Views/ModEdit/MoveEdit/MovePage.xaml b/VPet.ModMaker/Views/ModEdit/MoveEdit/MovePage.xaml index 790eca5..fc97e29 100644 --- a/VPet.ModMaker/Views/ModEdit/MoveEdit/MovePage.xaml +++ b/VPet.ModMaker/Views/ModEdit/MoveEdit/MovePage.xaml @@ -51,7 +51,7 @@ - + diff --git a/VPet.ModMaker/Views/ModEdit/PetEdit/PetPage.xaml b/VPet.ModMaker/Views/ModEdit/PetEdit/PetPage.xaml index c8d6db8..b4222f4 100644 --- a/VPet.ModMaker/Views/ModEdit/PetEdit/PetPage.xaml +++ b/VPet.ModMaker/Views/ModEdit/PetEdit/PetPage.xaml @@ -43,13 +43,23 @@ - + SortMemberPath="Id.Value"> + + + + + + + + + - +