From bf1f989a5790c4e8d7e2adbf6c7d1d1370a0a8e2 Mon Sep 17 00:00:00 2001 From: Hakoyu Date: Fri, 26 Apr 2024 22:52:26 +0800 Subject: [PATCH] =?UTF-8?q?#=E4=BF=AE=E5=A4=8D=20-=20=E5=9C=A8=E6=96=87?= =?UTF-8?q?=E5=8C=96=E6=B7=BB=E5=8A=A0=E7=95=8C=E9=9D=A2=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=96=87=E5=8C=96=E4=BC=9A=E5=87=BA=E9=94=99?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/ModModel/ClickTextModel.cs | 7 ++- .../Models/ModModel/FoodAnimeLocationModel.cs | 2 +- VPet.ModMaker/Models/ModModel/FoodModel.cs | 13 +++-- VPet.ModMaker/Models/ModModel/LowTextModel.cs | 7 ++- VPet.ModMaker/Models/ModModel/ModInfoModel.cs | 11 ++--- VPet.ModMaker/Models/ModModel/PetModel.cs | 48 +++++++++---------- .../Models/ModModel/SelectTextModel.cs | 12 ++--- VPet.ModMaker/Models/ModModel/WorkModel.cs | 7 ++- VPet.ModMaker/VPet.ModMaker.csproj | 2 +- .../ViewModels/ModEdit/AddCultureWindowVM.cs | 6 +-- .../ViewModels/ModEdit/ModEditWindowVM.cs | 8 ++-- .../Views/ModEdit/AddCultureWindow.xaml | 4 +- .../Views/ModEdit/AddCultureWindow.xaml.cs | 13 ++--- 13 files changed, 74 insertions(+), 66 deletions(-) diff --git a/VPet.ModMaker/Models/ModModel/ClickTextModel.cs b/VPet.ModMaker/Models/ModModel/ClickTextModel.cs index b5801e7..c735ce4 100644 --- a/VPet.ModMaker/Models/ModModel/ClickTextModel.cs +++ b/VPet.ModMaker/Models/ModModel/ClickTextModel.cs @@ -139,7 +139,12 @@ public class ClickTextModel : ObservableObjectX { I18nResource?.I18nObjectInfos.Add( this, - new(this, OnPropertyChanged, [(nameof(ID), ID, nameof(Text), true),]) + new I18nObjectInfo(this, OnPropertyChanged).AddPropertyInfo( + nameof(ID), + ID, + nameof(Text), + true + ) ); } diff --git a/VPet.ModMaker/Models/ModModel/FoodAnimeLocationModel.cs b/VPet.ModMaker/Models/ModModel/FoodAnimeLocationModel.cs index be4cf38..87d3f96 100644 --- a/VPet.ModMaker/Models/ModModel/FoodAnimeLocationModel.cs +++ b/VPet.ModMaker/Models/ModModel/FoodAnimeLocationModel.cs @@ -32,7 +32,7 @@ public class FoodAnimeLocationModel : ObservableObjectX, ICloneable /// 矩形位置 /// - public ObservableRectangleLocation RectangleLocation { get; set; } = new(); + public ObservableRectangle RectangleLocation { get; set; } = new(); /// /// 旋转角度 diff --git a/VPet.ModMaker/Models/ModModel/FoodModel.cs b/VPet.ModMaker/Models/ModModel/FoodModel.cs index 99b406d..f2ef81a 100644 --- a/VPet.ModMaker/Models/ModModel/FoodModel.cs +++ b/VPet.ModMaker/Models/ModModel/FoodModel.cs @@ -127,13 +127,12 @@ public class FoodModel : ObservableObjectX { I18nResource?.I18nObjectInfos.Add( this, - new( - this, - OnPropertyChanged, + new I18nObjectInfo(this, OnPropertyChanged).AddPropertyInfo( [ - (nameof(ID), ID, nameof(Name), true), - (nameof(DescriptionID), DescriptionID, nameof(Description), true) - ] + (nameof(ID), ID, nameof(Name)), + (nameof(DescriptionID), DescriptionID, nameof(Description)) + ], + true ) ); } @@ -148,7 +147,7 @@ public class FoodModel : ObservableObjectX [AdaptIgnore] public string Description { - get => I18nResource.GetCurrentCultureDataOrDefault(DescriptionID, string.Empty); + get => I18nResource.GetCurrentCultureDataOrDefault(DescriptionID); set => I18nResource.SetCurrentCultureData(DescriptionID, value); } #endregion diff --git a/VPet.ModMaker/Models/ModModel/LowTextModel.cs b/VPet.ModMaker/Models/ModModel/LowTextModel.cs index e45aa62..3d60894 100644 --- a/VPet.ModMaker/Models/ModModel/LowTextModel.cs +++ b/VPet.ModMaker/Models/ModModel/LowTextModel.cs @@ -87,7 +87,12 @@ public class LowTextModel : ObservableObjectX { I18nResource?.I18nObjectInfos.Add( this, - new(this, OnPropertyChanged, [(nameof(ID), ID, nameof(Text), true)]) + new I18nObjectInfo(this, OnPropertyChanged).AddPropertyInfo( + nameof(ID), + ID, + nameof(Text), + true + ) ); } diff --git a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs index 5f5c760..d07155b 100644 --- a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs +++ b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs @@ -38,13 +38,12 @@ public class ModInfoModel : ObservableObjectX I18nResource.Cultures.SetChanged += Cultures_SetChanged; I18nResource?.I18nObjectInfos.Add( this, - new( - this, - OnPropertyChanged, + new I18nObjectInfo(this, OnPropertyChanged).AddPropertyInfo( [ - (nameof(ID), ID, nameof(Name), true), - (nameof(DescriptionID), DescriptionID, nameof(Description), true) - ] + (nameof(ID), ID, nameof(Name)), + (nameof(DescriptionID), DescriptionID, nameof(Description)) + ], + true ) ); foreach (var pet in ModMakerInfo.MainPets) diff --git a/VPet.ModMaker/Models/ModModel/PetModel.cs b/VPet.ModMaker/Models/ModModel/PetModel.cs index d369d5d..2211ea7 100644 --- a/VPet.ModMaker/Models/ModModel/PetModel.cs +++ b/VPet.ModMaker/Models/ModModel/PetModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Linq; using System.Text; @@ -202,14 +203,13 @@ public class PetModel : ObservableObjectX { I18nResource.I18nObjectInfos.Add( this, - new( - this, - OnPropertyChanged, + new I18nObjectInfo(this, OnPropertyChanged).AddPropertyInfo( [ - (nameof(ID), ID, nameof(Name), true), - (nameof(PetNameID), PetNameID, nameof(PetName), true), - (nameof(DescriptionID), DescriptionID, nameof(Description), true) - ] + (nameof(ID), ID, nameof(Name)), + (nameof(PetNameID), PetNameID, nameof(PetName)), + (nameof(DescriptionID), DescriptionID, nameof(Description)) + ], + true ) ); foreach (var work in Works) @@ -283,13 +283,12 @@ public class PetModel : ObservableObjectX #region TouchHeadRect [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private ObservableRectangleLocation _touchHeadRectangleLocation = - new(159, 16, 189, 178); + private ObservableRectangle _touchHeadRectangleLocation = new(159, 16, 189, 178); /// /// 头部点击区域 /// - public ObservableRectangleLocation TouchHeadRectangleLocation + public ObservableRectangle TouchHeadRectangleLocation { get => _touchHeadRectangleLocation; set => SetProperty(ref _touchHeadRectangleLocation, value); @@ -298,13 +297,12 @@ public class PetModel : ObservableObjectX #region TouchBodyRect [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private ObservableRectangleLocation _touchBodyRectangleLocation = - new(166, 206, 163, 136); + private ObservableRectangle _touchBodyRectangleLocation = new(166, 206, 163, 136); /// /// 身体区域 /// - public ObservableRectangleLocation TouchBodyRectangleLocation + public ObservableRectangle TouchBodyRectangleLocation { get => _touchBodyRectangleLocation; set => SetProperty(ref _touchBodyRectangleLocation, value); @@ -623,8 +621,8 @@ public class ObservableMultiStateRectangleLocation { #region Happy [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private ObservableRectangleLocation _happy = null!; - public ObservableRectangleLocation Happy + private ObservableRectangle _happy = null!; + public ObservableRectangle Happy { get => _happy; set => SetProperty(ref _happy, value); @@ -633,9 +631,9 @@ public class ObservableMultiStateRectangleLocation #region Nomal [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private ObservableRectangleLocation _nomal = null!; + private ObservableRectangle _nomal = null!; - public ObservableRectangleLocation Nomal + public ObservableRectangle Nomal { get => _nomal; set => SetProperty(ref _nomal, value); @@ -644,8 +642,8 @@ public class ObservableMultiStateRectangleLocation #region PoorCondition [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private ObservableRectangleLocation _poorCondition = null!; - public ObservableRectangleLocation PoorCondition + private ObservableRectangle _poorCondition = null!; + public ObservableRectangle PoorCondition { get => _poorCondition; set => SetProperty(ref _poorCondition, value); @@ -654,8 +652,8 @@ public class ObservableMultiStateRectangleLocation #region Ill [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private ObservableRectangleLocation _ill = null!; - public ObservableRectangleLocation Ill + private ObservableRectangle _ill = null!; + public ObservableRectangle Ill { get => _ill; set => SetProperty(ref _ill, value); @@ -671,10 +669,10 @@ public class ObservableMultiStateRectangleLocation } public ObservableMultiStateRectangleLocation( - ObservableRectangleLocation happy, - ObservableRectangleLocation nomal, - ObservableRectangleLocation poorCondition, - ObservableRectangleLocation ill + ObservableRectangle happy, + ObservableRectangle nomal, + ObservableRectangle poorCondition, + ObservableRectangle ill ) { Happy = happy; diff --git a/VPet.ModMaker/Models/ModModel/SelectTextModel.cs b/VPet.ModMaker/Models/ModModel/SelectTextModel.cs index 8070c4a..dd79ab8 100644 --- a/VPet.ModMaker/Models/ModModel/SelectTextModel.cs +++ b/VPet.ModMaker/Models/ModModel/SelectTextModel.cs @@ -143,13 +143,9 @@ public class SelectTextModel : ObservableObjectX { I18nResource?.I18nObjectInfos.Add( this, - new( - this, - OnPropertyChanged, - [ - (nameof(ID), ID, nameof(Text), true), - (nameof(ChooseID), ChooseID, nameof(Choose), true) - ] + new I18nObjectInfo(this, OnPropertyChanged).AddPropertyInfo( + [(nameof(ID), ID, nameof(Text)), (nameof(ChooseID), ChooseID, nameof(Choose))], + true ) ); } @@ -164,7 +160,7 @@ public class SelectTextModel : ObservableObjectX [AdaptIgnore] public string Choose { - get => I18nResource.GetCurrentCultureDataOrDefault(ChooseID, string.Empty); + get => I18nResource.GetCurrentCultureDataOrDefault(ChooseID); set => I18nResource.SetCurrentCultureData(ChooseID, value); } #endregion diff --git a/VPet.ModMaker/Models/ModModel/WorkModel.cs b/VPet.ModMaker/Models/ModModel/WorkModel.cs index 0f6417d..3702f8a 100644 --- a/VPet.ModMaker/Models/ModModel/WorkModel.cs +++ b/VPet.ModMaker/Models/ModModel/WorkModel.cs @@ -143,7 +143,12 @@ public class WorkModel : ObservableObjectX { I18nResource?.I18nObjectInfos.Add( this, - new(this, OnPropertyChanged, [(nameof(ID), ID, nameof(Name), true),]) + new I18nObjectInfo(this, OnPropertyChanged).AddPropertyInfo( + nameof(ID), + ID, + nameof(Name), + true + ) ); } diff --git a/VPet.ModMaker/VPet.ModMaker.csproj b/VPet.ModMaker/VPet.ModMaker.csproj index 9606bef..58806fd 100644 --- a/VPet.ModMaker/VPet.ModMaker.csproj +++ b/VPet.ModMaker/VPet.ModMaker.csproj @@ -35,7 +35,7 @@ - + diff --git a/VPet.ModMaker/ViewModels/ModEdit/AddCultureWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/AddCultureWindowVM.cs index 75744b0..ef2d2af 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/AddCultureWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/AddCultureWindowVM.cs @@ -38,13 +38,13 @@ public class AddCultureWindowVM : ObservableObjectX [DebuggerBrowsable(DebuggerBrowsableState.Never)] private string _culture = string.Empty; - public string Culture + public string CultureName { get => _culture; set { SetProperty(ref _culture, value); - if (string.IsNullOrWhiteSpace(Culture)) + if (string.IsNullOrWhiteSpace(CultureName)) { CultureFullName = UnknownCulture; return; @@ -52,7 +52,7 @@ public class AddCultureWindowVM : ObservableObjectX CultureInfo info = null!; try { - info = CultureInfo.GetCultureInfo(Culture); + info = CultureInfo.GetCultureInfo(CultureName); } catch { diff --git a/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs index d21dd64..ab0c3a5 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs @@ -160,8 +160,8 @@ public class ModEditWindowVM : ObservableObjectX window.ShowDialog(); if (window.IsCancel) return; - I18nResource.AddCulture(window.ViewModel.Culture); - I18nResource.SetCurrentCulture(window.ViewModel.Culture); + I18nResource.AddCulture(window.ViewModel.CultureName); + I18nResource.SetCurrentCulture(window.ViewModel.CultureName); } /// @@ -171,11 +171,11 @@ public class ModEditWindowVM : ObservableObjectX private void EditCultureCommand_ExecuteCommand(string oldCulture) { var window = new AddCultureWindow(); - window.ViewModel.Culture = oldCulture.Translate(); + window.ViewModel.CultureName = oldCulture.Translate(); window.ShowDialog(); if (window.IsCancel) return; - I18nResource.ReplaceCulture(oldCulture, window.ViewModel.Culture); + I18nResource.ReplaceCulture(oldCulture, window.ViewModel.CultureName); } /// diff --git a/VPet.ModMaker/Views/ModEdit/AddCultureWindow.xaml b/VPet.ModMaker/Views/ModEdit/AddCultureWindow.xaml index 80a7beb..dcc0ad0 100644 --- a/VPet.ModMaker/Views/ModEdit/AddCultureWindow.xaml +++ b/VPet.ModMaker/Views/ModEdit/AddCultureWindow.xaml @@ -47,7 +47,7 @@ Grid.Row="1" pu:TextBoxHelper.Watermark="{ll:Str 文化名称}" Style="{DynamicResource StandardTextBoxStyle}" - Text="{Binding Culture, UpdateSourceTrigger=PropertyChanged}" /> + Text="{Binding CultureName, UpdateSourceTrigger=PropertyChanged}" /> @@ -88,7 +88,7 @@ + SelectedItem="{Binding CultureName}" /> diff --git a/VPet.ModMaker/Views/ModEdit/AddCultureWindow.xaml.cs b/VPet.ModMaker/Views/ModEdit/AddCultureWindow.xaml.cs index 3215c60..1181acd 100644 --- a/VPet.ModMaker/Views/ModEdit/AddCultureWindow.xaml.cs +++ b/VPet.ModMaker/Views/ModEdit/AddCultureWindow.xaml.cs @@ -47,16 +47,17 @@ public partial class AddCultureWindow : WindowX private void Button_Yes_Click(object? sender, RoutedEventArgs e) { - if (string.IsNullOrWhiteSpace(ViewModel.Culture)) + if (string.IsNullOrWhiteSpace(ViewModel.CultureName)) { MessageBox.Show("文化不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); return; } - if ( - ModInfoModel.Current.I18nResource.Cultures.Contains( - CultureInfo.GetCultureInfo(ViewModel.Culture) - ) - ) + if (CultureUtils.TryGetCultureInfo(ViewModel.CultureName, out var culture) is false) + { + MessageBox.Show("不支持的文化".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); + return; + } + if (ModInfoModel.Current.I18nResource.Cultures.Contains(culture)) { MessageBox.Show("此文化已存在".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); return;