From e53acb283ab784f166d4786dd2e7c07f3981d410 Mon Sep 17 00:00:00 2001 From: Hakoyu Date: Thu, 14 Dec 2023 23:27:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20-=20=E5=9C=A8=E5=AE=A0?= =?UTF-8?q?=E7=89=A9=E5=88=97=E8=A1=A8=E9=A1=B5=E9=9D=A2=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20`=E4=B8=8D=E6=98=BE=E7=A4=BA=E6=9C=AC=E4=BD=93=E5=AE=A0?= =?UTF-8?q?=E7=89=A9`=20=E6=8C=89=E9=92=AE=20(=E9=BB=98=E8=AE=A4=E5=BC=80?= =?UTF-8?q?=E5=90=AF)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新: - *自动设置食物推荐价格* 可在当前模组编辑时继承 - 历史编辑按最后编辑时间倒序排序 --- VPet.ModMaker/Converters.xaml | 1 + .../Converters/AllTrueToCollapsedConverter.cs | 33 +++++++ .../Converters/AnyFalseToVisibleConverter.cs | 28 ++++++ VPet.ModMaker/Models/I18nHelper.cs | 7 +- VPet.ModMaker/Models/I18nModelBase.cs | 89 +++++++++++++++++++ VPet.ModMaker/Models/ModModel/ModInfoModel.cs | 43 ++++++++- VPet.ModMaker/Templates.xaml | 4 +- VPet.ModMaker/Usings.cs | 1 + VPet.ModMaker/VPet.ModMaker.csproj | 3 + .../ModEdit/AnimeEdit/AnimePageVM.cs | 2 + .../ModEdit/FoodEdit/FoodEditWindowVM.cs | 19 +--- .../ViewModels/ModEdit/MoveEdit/MovePageVM.cs | 1 + .../ViewModels/ModEdit/PetEdit/PetPageVM.cs | 1 + .../ModEdit/WorkEdit/WorkEditWindowVM.cs | 3 +- .../ViewModels/ModEdit/WorkEdit/WorkPageVM.cs | 1 + VPet.ModMaker/ViewModels/ModMakerWindowVM.cs | 3 +- .../Views/ModEdit/AnimeEdit/AnimePage.xaml | 8 ++ .../ModEdit/ClickTextEdit/ClickTextPage.xaml | 84 +++++++++++++---- .../ModEdit/FoodEdit/FoodEditWindow.xaml | 2 +- .../Views/ModEdit/ModEditWindow.xaml | 2 +- .../Views/ModEdit/MoveEdit/MovePage.xaml | 8 ++ .../Views/ModEdit/PetEdit/PetPage.xaml | 26 +++++- .../SelectTextEdit/SelectTextPage.xaml | 80 +++++++++++++---- .../Views/ModEdit/WorkEdit/WorkPage.xaml | 8 ++ 24 files changed, 391 insertions(+), 66 deletions(-) create mode 100644 VPet.ModMaker/Converters/AllTrueToCollapsedConverter.cs create mode 100644 VPet.ModMaker/Converters/AnyFalseToVisibleConverter.cs create mode 100644 VPet.ModMaker/Models/I18nModelBase.cs diff --git a/VPet.ModMaker/Converters.xaml b/VPet.ModMaker/Converters.xaml index 7656ef2..fc11c66 100644 --- a/VPet.ModMaker/Converters.xaml +++ b/VPet.ModMaker/Converters.xaml @@ -13,4 +13,5 @@ + \ No newline at end of file diff --git a/VPet.ModMaker/Converters/AllTrueToCollapsedConverter.cs b/VPet.ModMaker/Converters/AllTrueToCollapsedConverter.cs new file mode 100644 index 0000000..3ab2a07 --- /dev/null +++ b/VPet.ModMaker/Converters/AllTrueToCollapsedConverter.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; + +namespace VPet.ModMaker.Converters; + +/// +/// 全部为真时设置隐藏转换器 +/// +public class AllTrueToCollapsedConverter : IMultiValueConverter +{ + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Length == 0) + throw new ArgumentException("No values", nameof(values)); + return values.All(i => i is true) ? Visibility.Collapsed : Visibility.Visible; + } + + public object[] ConvertBack( + object value, + Type[] targetTypes, + object parameter, + CultureInfo culture + ) + { + throw new NotImplementedException(); + } +} diff --git a/VPet.ModMaker/Converters/AnyFalseToVisibleConverter.cs b/VPet.ModMaker/Converters/AnyFalseToVisibleConverter.cs new file mode 100644 index 0000000..298c839 --- /dev/null +++ b/VPet.ModMaker/Converters/AnyFalseToVisibleConverter.cs @@ -0,0 +1,28 @@ +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +namespace VPet.ModMaker.Converters; + +/// +/// 任意为假时设置显示转换器 +/// +public class AnyFalseToVisibleConverter : IMultiValueConverter +{ + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Length == 0) + throw new ArgumentException("No values", nameof(values)); + return values.Any(i => i is not true) ? Visibility.Visible : Visibility.Collapsed; + } + + public object[] ConvertBack( + object value, + Type[] targetTypes, + object parameter, + CultureInfo culture + ) + { + throw new NotImplementedException(); + } +} diff --git a/VPet.ModMaker/Models/I18nHelper.cs b/VPet.ModMaker/Models/I18nHelper.cs index eb23bdc..cb85819 100644 --- a/VPet.ModMaker/Models/I18nHelper.cs +++ b/VPet.ModMaker/Models/I18nHelper.cs @@ -2,12 +2,14 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Collections.Specialized; using System.Linq; using System.Text; using System.Threading.Tasks; namespace VPet.ModMaker.Models; +// TODO: 更新事件 /// /// I18n助手 /// @@ -33,10 +35,7 @@ public class I18nHelper CultureNames.CollectionChanged += Cultures_CollectionChanged; } - private void Cultures_CollectionChanged( - object sender, - System.Collections.Specialized.NotifyCollectionChangedEventArgs e - ) + private void Cultures_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { // 替换 if (e.NewStartingIndex == e.OldStartingIndex) diff --git a/VPet.ModMaker/Models/I18nModelBase.cs b/VPet.ModMaker/Models/I18nModelBase.cs new file mode 100644 index 0000000..48a4b20 --- /dev/null +++ b/VPet.ModMaker/Models/I18nModelBase.cs @@ -0,0 +1,89 @@ +using HKW.HKWUtils.Observable; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VPet.ModMaker.Models; + +/// +/// I18n模型 +/// +/// 类型 +public class I18nModelBase : ObservableClass> + where T : class, new() +{ + /// + /// 当前I18n数据 + /// + + private T _CurrentI18nData = new(); + public T CurrentI18nData + { + get => _CurrentI18nData; + set => SetProperty(ref _CurrentI18nData, value); + } + + /// + /// 所有I18n数据 + /// + public Dictionary I18nDatas { get; } = new(); + + public I18nModelBase() + { + I18nHelper.Current.CultureName.ValueChanged += CultureChanged; + I18nHelper.Current.AddCulture += AddCulture; + I18nHelper.Current.RemoveCulture += RemoveCulture; + I18nHelper.Current.ReplaceCulture += ReplaceCulture; + if (I18nHelper.Current.CultureNames.Count == 0) + return; + foreach (var item in I18nHelper.Current.CultureNames) + I18nDatas.Add(item, new()); + CurrentI18nData = I18nDatas[I18nHelper.Current.CultureName.Value]; + } + + /// + /// 文化改变 + /// + /// + /// + private void CultureChanged(ObservableValue sender, ValueChangedEventArgs e) + { + if (e.NewValue is null) + CurrentI18nData = null; + else if (I18nDatas.TryGetValue(e.NewValue, out var result)) + CurrentI18nData = result; + } + + /// + /// 添加文化 + /// + /// 文化名称 + private void AddCulture(string culture) + { + if (I18nDatas.ContainsKey(culture) is false) + I18nDatas.Add(culture, new()); + } + + /// + /// 删除文化 + /// + /// 文化名称 + private void RemoveCulture(string culture) + { + I18nDatas.Remove(culture); + } + + /// + /// 替换文化 + /// + /// 旧文化名称 + /// 新文化名称 + private void ReplaceCulture(string oldCulture, string newCulture) + { + var item = I18nDatas[oldCulture]; + I18nDatas.Remove(oldCulture); + I18nDatas.Add(newCulture, item); + } +} diff --git a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs index 5e0765d..7fcdd17 100644 --- a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs +++ b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs @@ -21,12 +21,22 @@ using VPet_Simulator.Windows.Interface; namespace VPet.ModMaker.Models; -// TODO: 本体模组显示开关 /// /// 模组信息模型 /// public class ModInfoModel : I18nModel { + /// + /// 自动设置食物推荐价格 + /// + public ObservableValue AutoSetFoodPrice { get; } = new(); + + /// + /// 不显示本体宠物 + /// + public ObservableValue DontShowMainPet { get; } = new(true); + + #region ModInfo /// /// 作者Id /// @@ -77,6 +87,9 @@ public class ModInfoModel : I18nModel /// public ObservableValue SourcePath { get; } = new(); + #endregion + + #region ModDatas /// /// 食物 /// @@ -102,6 +115,11 @@ public class ModInfoModel : I18nModel /// public ObservableCollection Pets { get; } = new(); + /// + /// 宠物实际数量 + /// + public ObservableValue PetDisplayedCount { get; } = new(); + /// /// 其它I18n数据 /// @@ -111,7 +129,7 @@ public class ModInfoModel : I18nModel /// 需要保存的I18n数据 /// public static Dictionary> SaveI18nDatas { get; } = new(); - + #endregion public ModInfoModel() { DescriptionId.Value = $"{Id.Value}_{nameof(DescriptionId)}"; @@ -119,6 +137,24 @@ public class ModInfoModel : I18nModel { DescriptionId.Value = $"{n}_{nameof(DescriptionId)}"; }; + Pets.CollectionChanged += Pets_CollectionChanged; + DontShowMainPet.ValueChanged += ShowMainPet_ValueChanged; + } + + private void ShowMainPet_ValueChanged( + ObservableValue sender, + ValueChangedEventArgs e + ) + { + Pets_CollectionChanged(null, null); + } + + private void Pets_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + if (DontShowMainPet.Value) + PetDisplayedCount.Value = Pets.Count - Pets.Count(m => m.FromMain.Value); + else + PetDisplayedCount.Value = Pets.Count; } public ModInfoModel(ModLoader loader) @@ -178,6 +214,9 @@ public class ModInfoModel : I18nModel LoadAnime(petModel, p); } + loader.Pets.First().Name = "TestMainPet"; + Pets.Insert(0, new(loader.Pets.First(), true)); + // 插入本体宠物 foreach (var pet in ModMakerInfo.MainPets) { diff --git a/VPet.ModMaker/Templates.xaml b/VPet.ModMaker/Templates.xaml index ac14da7..43083a8 100644 --- a/VPet.ModMaker/Templates.xaml +++ b/VPet.ModMaker/Templates.xaml @@ -33,13 +33,13 @@ + Value="{Binding DataContext.Min, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" />