- 在文化添加界面输入错误文化会出错的问题
This commit is contained in:
Hakoyu 2024-04-26 22:52:26 +08:00
parent 53329f8c66
commit bf1f989a57
13 changed files with 74 additions and 66 deletions

View File

@ -139,7 +139,12 @@ public class ClickTextModel : ObservableObjectX
{ {
I18nResource?.I18nObjectInfos.Add( I18nResource?.I18nObjectInfos.Add(
this, this,
new(this, OnPropertyChanged, [(nameof(ID), ID, nameof(Text), true),]) new I18nObjectInfo<string, string>(this, OnPropertyChanged).AddPropertyInfo(
nameof(ID),
ID,
nameof(Text),
true
)
); );
} }

View File

@ -32,7 +32,7 @@ public class FoodAnimeLocationModel : ObservableObjectX, ICloneable<FoodAnimeLoc
/// <summary> /// <summary>
/// 矩形位置 /// 矩形位置
/// </summary> /// </summary>
public ObservableRectangleLocation<double> RectangleLocation { get; set; } = new(); public ObservableRectangle<double> RectangleLocation { get; set; } = new();
/// <summary> /// <summary>
/// 旋转角度 /// 旋转角度

View File

@ -127,13 +127,12 @@ public class FoodModel : ObservableObjectX
{ {
I18nResource?.I18nObjectInfos.Add( I18nResource?.I18nObjectInfos.Add(
this, this,
new( new I18nObjectInfo<string, string>(this, OnPropertyChanged).AddPropertyInfo(
this,
OnPropertyChanged,
[ [
(nameof(ID), ID, nameof(Name), true), (nameof(ID), ID, nameof(Name)),
(nameof(DescriptionID), DescriptionID, nameof(Description), true) (nameof(DescriptionID), DescriptionID, nameof(Description))
] ],
true
) )
); );
} }
@ -148,7 +147,7 @@ public class FoodModel : ObservableObjectX
[AdaptIgnore] [AdaptIgnore]
public string Description public string Description
{ {
get => I18nResource.GetCurrentCultureDataOrDefault(DescriptionID, string.Empty); get => I18nResource.GetCurrentCultureDataOrDefault(DescriptionID);
set => I18nResource.SetCurrentCultureData(DescriptionID, value); set => I18nResource.SetCurrentCultureData(DescriptionID, value);
} }
#endregion #endregion

View File

@ -87,7 +87,12 @@ public class LowTextModel : ObservableObjectX
{ {
I18nResource?.I18nObjectInfos.Add( I18nResource?.I18nObjectInfos.Add(
this, this,
new(this, OnPropertyChanged, [(nameof(ID), ID, nameof(Text), true)]) new I18nObjectInfo<string, string>(this, OnPropertyChanged).AddPropertyInfo(
nameof(ID),
ID,
nameof(Text),
true
)
); );
} }

View File

@ -38,13 +38,12 @@ public class ModInfoModel : ObservableObjectX
I18nResource.Cultures.SetChanged += Cultures_SetChanged; I18nResource.Cultures.SetChanged += Cultures_SetChanged;
I18nResource?.I18nObjectInfos.Add( I18nResource?.I18nObjectInfos.Add(
this, this,
new( new I18nObjectInfo<string, string>(this, OnPropertyChanged).AddPropertyInfo(
this,
OnPropertyChanged,
[ [
(nameof(ID), ID, nameof(Name), true), (nameof(ID), ID, nameof(Name)),
(nameof(DescriptionID), DescriptionID, nameof(Description), true) (nameof(DescriptionID), DescriptionID, nameof(Description))
] ],
true
) )
); );
foreach (var pet in ModMakerInfo.MainPets) foreach (var pet in ModMakerInfo.MainPets)

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -202,14 +203,13 @@ public class PetModel : ObservableObjectX
{ {
I18nResource.I18nObjectInfos.Add( I18nResource.I18nObjectInfos.Add(
this, this,
new( new I18nObjectInfo<string, string>(this, OnPropertyChanged).AddPropertyInfo(
this,
OnPropertyChanged,
[ [
(nameof(ID), ID, nameof(Name), true), (nameof(ID), ID, nameof(Name)),
(nameof(PetNameID), PetNameID, nameof(PetName), true), (nameof(PetNameID), PetNameID, nameof(PetName)),
(nameof(DescriptionID), DescriptionID, nameof(Description), true) (nameof(DescriptionID), DescriptionID, nameof(Description))
] ],
true
) )
); );
foreach (var work in Works) foreach (var work in Works)
@ -283,13 +283,12 @@ public class PetModel : ObservableObjectX
#region TouchHeadRect #region TouchHeadRect
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableRectangleLocation<double> _touchHeadRectangleLocation = private ObservableRectangle<double> _touchHeadRectangleLocation = new(159, 16, 189, 178);
new(159, 16, 189, 178);
/// <summary> /// <summary>
/// 头部点击区域 /// 头部点击区域
/// </summary> /// </summary>
public ObservableRectangleLocation<double> TouchHeadRectangleLocation public ObservableRectangle<double> TouchHeadRectangleLocation
{ {
get => _touchHeadRectangleLocation; get => _touchHeadRectangleLocation;
set => SetProperty(ref _touchHeadRectangleLocation, value); set => SetProperty(ref _touchHeadRectangleLocation, value);
@ -298,13 +297,12 @@ public class PetModel : ObservableObjectX
#region TouchBodyRect #region TouchBodyRect
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableRectangleLocation<double> _touchBodyRectangleLocation = private ObservableRectangle<double> _touchBodyRectangleLocation = new(166, 206, 163, 136);
new(166, 206, 163, 136);
/// <summary> /// <summary>
/// 身体区域 /// 身体区域
/// </summary> /// </summary>
public ObservableRectangleLocation<double> TouchBodyRectangleLocation public ObservableRectangle<double> TouchBodyRectangleLocation
{ {
get => _touchBodyRectangleLocation; get => _touchBodyRectangleLocation;
set => SetProperty(ref _touchBodyRectangleLocation, value); set => SetProperty(ref _touchBodyRectangleLocation, value);
@ -623,8 +621,8 @@ public class ObservableMultiStateRectangleLocation
{ {
#region Happy #region Happy
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableRectangleLocation<double> _happy = null!; private ObservableRectangle<double> _happy = null!;
public ObservableRectangleLocation<double> Happy public ObservableRectangle<double> Happy
{ {
get => _happy; get => _happy;
set => SetProperty(ref _happy, value); set => SetProperty(ref _happy, value);
@ -633,9 +631,9 @@ public class ObservableMultiStateRectangleLocation
#region Nomal #region Nomal
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableRectangleLocation<double> _nomal = null!; private ObservableRectangle<double> _nomal = null!;
public ObservableRectangleLocation<double> Nomal public ObservableRectangle<double> Nomal
{ {
get => _nomal; get => _nomal;
set => SetProperty(ref _nomal, value); set => SetProperty(ref _nomal, value);
@ -644,8 +642,8 @@ public class ObservableMultiStateRectangleLocation
#region PoorCondition #region PoorCondition
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableRectangleLocation<double> _poorCondition = null!; private ObservableRectangle<double> _poorCondition = null!;
public ObservableRectangleLocation<double> PoorCondition public ObservableRectangle<double> PoorCondition
{ {
get => _poorCondition; get => _poorCondition;
set => SetProperty(ref _poorCondition, value); set => SetProperty(ref _poorCondition, value);
@ -654,8 +652,8 @@ public class ObservableMultiStateRectangleLocation
#region Ill #region Ill
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableRectangleLocation<double> _ill = null!; private ObservableRectangle<double> _ill = null!;
public ObservableRectangleLocation<double> Ill public ObservableRectangle<double> Ill
{ {
get => _ill; get => _ill;
set => SetProperty(ref _ill, value); set => SetProperty(ref _ill, value);
@ -671,10 +669,10 @@ public class ObservableMultiStateRectangleLocation
} }
public ObservableMultiStateRectangleLocation( public ObservableMultiStateRectangleLocation(
ObservableRectangleLocation<double> happy, ObservableRectangle<double> happy,
ObservableRectangleLocation<double> nomal, ObservableRectangle<double> nomal,
ObservableRectangleLocation<double> poorCondition, ObservableRectangle<double> poorCondition,
ObservableRectangleLocation<double> ill ObservableRectangle<double> ill
) )
{ {
Happy = happy; Happy = happy;

View File

@ -143,13 +143,9 @@ public class SelectTextModel : ObservableObjectX
{ {
I18nResource?.I18nObjectInfos.Add( I18nResource?.I18nObjectInfos.Add(
this, this,
new( new I18nObjectInfo<string, string>(this, OnPropertyChanged).AddPropertyInfo(
this, [(nameof(ID), ID, nameof(Text)), (nameof(ChooseID), ChooseID, nameof(Choose))],
OnPropertyChanged, true
[
(nameof(ID), ID, nameof(Text), true),
(nameof(ChooseID), ChooseID, nameof(Choose), true)
]
) )
); );
} }
@ -164,7 +160,7 @@ public class SelectTextModel : ObservableObjectX
[AdaptIgnore] [AdaptIgnore]
public string Choose public string Choose
{ {
get => I18nResource.GetCurrentCultureDataOrDefault(ChooseID, string.Empty); get => I18nResource.GetCurrentCultureDataOrDefault(ChooseID);
set => I18nResource.SetCurrentCultureData(ChooseID, value); set => I18nResource.SetCurrentCultureData(ChooseID, value);
} }
#endregion #endregion

View File

@ -143,7 +143,12 @@ public class WorkModel : ObservableObjectX
{ {
I18nResource?.I18nObjectInfos.Add( I18nResource?.I18nObjectInfos.Add(
this, this,
new(this, OnPropertyChanged, [(nameof(ID), ID, nameof(Name), true),]) new I18nObjectInfo<string, string>(this, OnPropertyChanged).AddPropertyInfo(
nameof(ID),
ID,
nameof(Name),
true
)
); );
} }

View File

@ -35,7 +35,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(Configuration)'!='Test'"> <ItemGroup Condition="'$(Configuration)'!='Test'">
<PackageReference Include="HKW.WPF" Version="1.0.7" /> <PackageReference Include="HKW.WPF" Version="1.0.7" />
<PackageReference Include="HKW.Utils" Version="1.2.21" /> <PackageReference Include="HKW.Utils" Version="1.2.22" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="VPet-Simulator.Core" Version="1.1.0.14-beta" /> <PackageReference Include="VPet-Simulator.Core" Version="1.1.0.14-beta" />

View File

@ -38,13 +38,13 @@ public class AddCultureWindowVM : ObservableObjectX
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _culture = string.Empty; private string _culture = string.Empty;
public string Culture public string CultureName
{ {
get => _culture; get => _culture;
set set
{ {
SetProperty(ref _culture, value); SetProperty(ref _culture, value);
if (string.IsNullOrWhiteSpace(Culture)) if (string.IsNullOrWhiteSpace(CultureName))
{ {
CultureFullName = UnknownCulture; CultureFullName = UnknownCulture;
return; return;
@ -52,7 +52,7 @@ public class AddCultureWindowVM : ObservableObjectX
CultureInfo info = null!; CultureInfo info = null!;
try try
{ {
info = CultureInfo.GetCultureInfo(Culture); info = CultureInfo.GetCultureInfo(CultureName);
} }
catch catch
{ {

View File

@ -160,8 +160,8 @@ public class ModEditWindowVM : ObservableObjectX
window.ShowDialog(); window.ShowDialog();
if (window.IsCancel) if (window.IsCancel)
return; return;
I18nResource.AddCulture(window.ViewModel.Culture); I18nResource.AddCulture(window.ViewModel.CultureName);
I18nResource.SetCurrentCulture(window.ViewModel.Culture); I18nResource.SetCurrentCulture(window.ViewModel.CultureName);
} }
/// <summary> /// <summary>
@ -171,11 +171,11 @@ public class ModEditWindowVM : ObservableObjectX
private void EditCultureCommand_ExecuteCommand(string oldCulture) private void EditCultureCommand_ExecuteCommand(string oldCulture)
{ {
var window = new AddCultureWindow(); var window = new AddCultureWindow();
window.ViewModel.Culture = oldCulture.Translate(); window.ViewModel.CultureName = oldCulture.Translate();
window.ShowDialog(); window.ShowDialog();
if (window.IsCancel) if (window.IsCancel)
return; return;
I18nResource.ReplaceCulture(oldCulture, window.ViewModel.Culture); I18nResource.ReplaceCulture(oldCulture, window.ViewModel.CultureName);
} }
/// <summary> /// <summary>

View File

@ -47,7 +47,7 @@
Grid.Row="1" Grid.Row="1"
pu:TextBoxHelper.Watermark="{ll:Str 文化名称}" pu:TextBoxHelper.Watermark="{ll:Str 文化名称}"
Style="{DynamicResource StandardTextBoxStyle}" Style="{DynamicResource StandardTextBoxStyle}"
Text="{Binding Culture, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding CultureName, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Grid.Row="2"> <TextBlock Grid.Row="2">
<Hyperlink Click="Hyperlink_Click"> <Hyperlink Click="Hyperlink_Click">
<TextBlock Text="{ll:Str 详情请参阅 Windows 支持的语言/区域名称列表中的“语言标记”列}" /> <TextBlock Text="{ll:Str 详情请参阅 Windows 支持的语言/区域名称列表中的“语言标记”列}" />
@ -88,7 +88,7 @@
<ListBox <ListBox
Grid.Row="1" Grid.Row="1"
ItemsSource="{Binding AllCultures.FilteredList}" ItemsSource="{Binding AllCultures.FilteredList}"
SelectedItem="{Binding Culture}" /> SelectedItem="{Binding CultureName}" />
</Grid> </Grid>
</Grid> </Grid>
</pu:WindowX> </pu:WindowX>

View File

@ -47,16 +47,17 @@ public partial class AddCultureWindow : WindowX
private void Button_Yes_Click(object? sender, RoutedEventArgs e) 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); MessageBox.Show("文化不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning);
return; return;
} }
if ( if (CultureUtils.TryGetCultureInfo(ViewModel.CultureName, out var culture) is false)
ModInfoModel.Current.I18nResource.Cultures.Contains( {
CultureInfo.GetCultureInfo(ViewModel.Culture) MessageBox.Show("不支持的文化".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning);
) return;
) }
if (ModInfoModel.Current.I18nResource.Cultures.Contains(culture))
{ {
MessageBox.Show("此文化已存在".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); MessageBox.Show("此文化已存在".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning);
return; return;