This commit is contained in:
Hakoyu 2024-04-17 21:35:55 +08:00
parent 3a349aa0b4
commit c307d50674
37 changed files with 556 additions and 351 deletions

View File

@ -1,4 +1,3 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308 VisualStudioVersion = 17.4.33213.308
@ -9,12 +8,15 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
Test|Any CPU = Test|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8F804A27-A57E-4799-801C-4DE96BA153BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8F804A27-A57E-4799-801C-4DE96BA153BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F804A27-A57E-4799-801C-4DE96BA153BC}.Debug|Any CPU.Build.0 = Debug|Any CPU {8F804A27-A57E-4799-801C-4DE96BA153BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F804A27-A57E-4799-801C-4DE96BA153BC}.Release|Any CPU.ActiveCfg = Release|Any CPU {8F804A27-A57E-4799-801C-4DE96BA153BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F804A27-A57E-4799-801C-4DE96BA153BC}.Release|Any CPU.Build.0 = Release|Any CPU {8F804A27-A57E-4799-801C-4DE96BA153BC}.Release|Any CPU.Build.0 = Release|Any CPU
{8F804A27-A57E-4799-801C-4DE96BA153BC}.Test|Any CPU.ActiveCfg = Test|Any CPU
{8F804A27-A57E-4799-801C-4DE96BA153BC}.Test|Any CPU.Build.0 = Test|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -50,7 +50,10 @@ public class ModMaker : MainPlugin
ModMakerInfo.GameVersion = MW.version; ModMakerInfo.GameVersion = MW.version;
// 载入本体宠物 // 载入本体宠物
foreach (var pet in MW.Pets) foreach (var pet in MW.Pets)
ModMakerInfo.MainPets.TryAdd(pet.Name, new(pet, true)); ModMakerInfo.MainPets.TryAdd(
pet.Name,
new(pet, true) { I18nResource = ModInfoModel.Current.I18nResource }
);
//Maker.ModMaker = this; //Maker.ModMaker = this;
Maker.Show(); Maker.Show();
Maker.Closed += Maker_Closed; Maker.Closed += Maker_Closed;

View File

@ -36,7 +36,7 @@ public static class ModMakerInfo
/// <summary> /// <summary>
/// 本体的宠物 /// 本体的宠物
/// <para> /// <para>
/// (PetId, PetModel) /// (PetID, PetModel)
/// </para> /// </para>
/// </summary> /// </summary>
public static Dictionary<string, PetModel> MainPets { get; } = new(); public static Dictionary<string, PetModel> MainPets { get; } = new();

View File

@ -19,12 +19,7 @@ namespace VPet.ModMaker.Models;
/// </summary> /// </summary>
public class ClickTextModel : ObservableObjectX public class ClickTextModel : ObservableObjectX
{ {
public ClickTextModel() public ClickTextModel() { }
{
ModInfoModel.Current.I18nResource.I18nObjectInfos.Add(
new(this, OnPropertyChanged, [(nameof(ID), ID, nameof(Text), true)])
);
}
public ClickTextModel(ClickTextModel clickText) public ClickTextModel(ClickTextModel clickText)
: this() : this()
@ -124,11 +119,35 @@ public class ClickTextModel : ObservableObjectX
#endregion #endregion
#region I18nData #region I18nData
[AdaptIgnore]
private I18nResource<string, string> _i18nResource = null!;
[AdaptIgnore]
public required I18nResource<string, string> I18nResource
{
get => _i18nResource;
set
{
if (_i18nResource is not null)
I18nResource.I18nObjectInfos.Remove(this);
_i18nResource = value;
InitializeI18nResource();
}
}
public void InitializeI18nResource()
{
I18nResource.I18nObjectInfos.Add(
this,
new(this, OnPropertyChanged, [(nameof(ID), ID, nameof(Text), true),])
);
}
[AdaptIgnore] [AdaptIgnore]
public string Text public string Text
{ {
get => ModInfoModel.Current.I18nResource.GetCurrentCultureDataOrDefault(ID); get => I18nResource.GetCurrentCultureDataOrDefault(ID);
set => ModInfoModel.Current.I18nResource.SetCurrentCultureData(ID, value); set => I18nResource.SetCurrentCultureData(ID, value);
} }
#endregion #endregion
@ -224,25 +243,9 @@ public class ClickTextModel : ObservableObjectX
/// 体力 /// 体力
/// </summary> /// </summary>
public ObservableRange<double> Strength { get; } = new(0, int.MaxValue); public ObservableRange<double> Strength { get; } = new(0, int.MaxValue);
}
public class I18nClickTextModel : ObservableObjectX, ICloneable<I18nClickTextModel> public void Close()
{
#region Text
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _text = string.Empty;
public string Text
{ {
get => _text; I18nResource.I18nObjectInfos.Remove(this);
set => SetProperty(ref _text, value);
} }
#endregion
public I18nClickTextModel Clone()
{
return this.Adapt<I18nClickTextModel>();
}
object ICloneable.Clone() => Clone();
} }

View File

@ -26,19 +26,9 @@ public class FoodModel : ObservableObjectX
public FoodModel() public FoodModel()
{ {
PropertyChangedX += FoodModel_PropertyChangedX; PropertyChangedX += FoodModel_PropertyChangedX;
ModInfoModel.Current.I18nResource.I18nObjectInfos.Add(
new(
this,
OnPropertyChanged,
[
(nameof(ID), ID, nameof(Name), true),
(nameof(DescriptionID), DescriptionID, nameof(Description), true)
]
)
);
} }
private static FrozenSet<string> _notifyReferencePrice = FrozenSet.ToFrozenSet( private static readonly FrozenSet<string> _notifyReferencePrice = FrozenSet.ToFrozenSet(
[ [
nameof(Strength), nameof(Strength),
nameof(StrengthFood), nameof(StrengthFood),
@ -116,22 +106,50 @@ public class FoodModel : ObservableObjectX
#endregion #endregion
#region I18nData #region I18nData
[AdaptIgnore]
private I18nResource<string, string> _i18nResource = null!;
[AdaptIgnore]
public required I18nResource<string, string> I18nResource
{
get => _i18nResource;
set
{
if (_i18nResource is not null)
I18nResource.I18nObjectInfos.Remove(this);
_i18nResource = value;
InitializeI18nResource();
}
}
public void InitializeI18nResource()
{
I18nResource.I18nObjectInfos.Add(
this,
new(
this,
OnPropertyChanged,
[
(nameof(ID), ID, nameof(Name), true),
(nameof(DescriptionID), DescriptionID, nameof(Description), true)
]
)
);
}
[AdaptIgnore] [AdaptIgnore]
public string Name public string Name
{ {
get => ModInfoModel.Current.I18nResource.GetCurrentCultureDataOrDefault(ID); get => I18nResource.GetCurrentCultureDataOrDefault(ID);
set => ModInfoModel.Current.I18nResource.SetCurrentCultureData(ID, value); set => I18nResource.SetCurrentCultureData(ID, value);
} }
[AdaptIgnore] [AdaptIgnore]
public string Description public string Description
{ {
get => get => I18nResource.GetCurrentCultureDataOrDefault(DescriptionID, string.Empty);
ModInfoModel.Current.I18nResource.GetCurrentCultureDataOrDefault( set => I18nResource.SetCurrentCultureData(DescriptionID, value);
DescriptionID,
string.Empty
);
set => ModInfoModel.Current.I18nResource.SetCurrentCultureData(DescriptionID, value);
} }
#endregion #endregion
@ -345,10 +363,6 @@ public class FoodModel : ObservableObjectX
public void Close() public void Close()
{ {
Image?.CloseStream(); Image?.CloseStream();
var item = ModInfoModel.Current.I18nResource.I18nObjectInfos.FirstOrDefault(i => I18nResource.I18nObjectInfos.Remove(this);
i.Source == this
);
if (item is not null)
ModInfoModel.Current.I18nResource.I18nObjectInfos.Remove(item);
} }
} }

View File

@ -18,12 +18,7 @@ namespace VPet.ModMaker.Models;
/// </summary> /// </summary>
public class LowTextModel : ObservableObjectX public class LowTextModel : ObservableObjectX
{ {
public LowTextModel() public LowTextModel() { }
{
ModInfoModel.Current.I18nResource.I18nObjectInfos.Add(
new(this, OnPropertyChanged, [(nameof(ID), ID, nameof(Text), true)])
);
}
public LowTextModel(LowTextModel lowText) public LowTextModel(LowTextModel lowText)
: this() : this()
@ -56,6 +51,7 @@ public class LowTextModel : ObservableObjectX
Enum.GetValues<LowText.StrengthType>().ToFrozenSet(); Enum.GetValues<LowText.StrengthType>().ToFrozenSet();
#region ID #region ID
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _id = string.Empty; private string _id = string.Empty;
@ -71,11 +67,35 @@ public class LowTextModel : ObservableObjectX
#endregion #endregion
#region I18nData #region I18nData
[AdaptIgnore]
private I18nResource<string, string> _i18nResource = null!;
[AdaptIgnore]
public required I18nResource<string, string> I18nResource
{
get => _i18nResource;
set
{
if (_i18nResource is not null)
I18nResource.I18nObjectInfos.Remove(this);
_i18nResource = value;
InitializeI18nResource();
}
}
public void InitializeI18nResource()
{
I18nResource.I18nObjectInfos.Add(
this,
new(this, OnPropertyChanged, [(nameof(ID), ID, nameof(Text), true)])
);
}
[AdaptIgnore] [AdaptIgnore]
public string Text public string Text
{ {
get => ModInfoModel.Current.I18nResource.GetCurrentCultureDataOrDefault(ID); get => I18nResource.GetCurrentCultureDataOrDefault(ID);
set => ModInfoModel.Current.I18nResource.SetCurrentCultureData(ID, value); set => I18nResource.SetCurrentCultureData(ID, value);
} }
#endregion #endregion
@ -128,4 +148,9 @@ public class LowTextModel : ObservableObjectX
{ {
return this.Adapt<LowText>(); return this.Adapt<LowText>();
} }
public void Close()
{
I18nResource.I18nObjectInfos.Remove(this);
}
} }

View File

@ -34,6 +34,19 @@ public class ModInfoModel : ObservableObjectX
Current = this; Current = this;
PropertyChanged += ModInfoModel_PropertyChanged; PropertyChanged += ModInfoModel_PropertyChanged;
Pets.CollectionChanged += Pets_CollectionChanged; Pets.CollectionChanged += Pets_CollectionChanged;
I18nResource.PropertyChanged += I18nResource_PropertyChanged;
I18nResource.Cultures.SetChanged += Cultures_SetChanged;
I18nResource.I18nObjectInfos.Add(
this,
new(
this,
OnPropertyChanged,
[
(nameof(ID), ID, nameof(Name), true),
(nameof(DescriptionID), DescriptionID, nameof(Description), true)
]
)
);
} }
public ModInfoModel(ModLoader loader) public ModInfoModel(ModLoader loader)
@ -51,28 +64,28 @@ public class ModInfoModel : ObservableObjectX
if (File.Exists(imagePath)) if (File.Exists(imagePath))
Image = NativeUtils.LoadImageToMemoryStream(imagePath); Image = NativeUtils.LoadImageToMemoryStream(imagePath);
foreach (var food in loader.Foods.Where(m => string.IsNullOrWhiteSpace(m.Name) is false)) foreach (var food in loader.Foods.Where(m => string.IsNullOrWhiteSpace(m.Name) is false))
Foods.Add(new(food)); Foods.Add(new(food) { I18nResource = I18nResource });
foreach ( foreach (
var clickText in loader.ClickTexts.Where(m => var clickText in loader.ClickTexts.Where(m =>
string.IsNullOrWhiteSpace(m.Text) is false string.IsNullOrWhiteSpace(m.Text) is false
) )
) )
ClickTexts.Add(new(clickText)); ClickTexts.Add(new(clickText) { I18nResource = I18nResource });
foreach ( foreach (
var lowText in loader.LowTexts.Where(m => string.IsNullOrWhiteSpace(m.Text) is false) var lowText in loader.LowTexts.Where(m => string.IsNullOrWhiteSpace(m.Text) is false)
) )
LowTexts.Add(new(lowText)); LowTexts.Add(new(lowText) { I18nResource = I18nResource });
foreach ( foreach (
var selectText in loader.SelectTexts.Where(m => var selectText in loader.SelectTexts.Where(m =>
string.IsNullOrWhiteSpace(m.Text) is false string.IsNullOrWhiteSpace(m.Text) is false
) )
) )
SelectTexts.Add(new(selectText)); SelectTexts.Add(new(selectText) { I18nResource = I18nResource });
// 载入模组宠物 // 载入模组宠物
foreach (var pet in loader.Pets) foreach (var pet in loader.Pets)
{ {
var petModel = new PetModel(pet); var petModel = new PetModel(pet) { I18nResource = I18nResource };
// 如果检测到本体存在同名宠物 // 如果检测到本体存在同名宠物
if (ModMakerInfo.MainPets.TryGetValue(petModel.ID, out var mainPet)) if (ModMakerInfo.MainPets.TryGetValue(petModel.ID, out var mainPet))
{ {
@ -113,12 +126,8 @@ public class ModInfoModel : ObservableObjectX
if (Pets.All(i => i.ID != pet.Key)) if (Pets.All(i => i.ID != pet.Key))
Pets.Insert(0, pet.Value); Pets.Insert(0, pet.Value);
} }
if (loader.I18nDatas.HasValue() is false)
// 载入本地化模组信息 return;
//foreach (var lang in loader.I18nDatas)
// I18nDatas.Add(lang.Key, lang.Value);
//OtherI18nDatas = loader.I18nDatas;
LoadI18nDatas(loader); LoadI18nDatas(loader);
RefreshAllID(); RefreshAllID();
if (I18nResource.CultureDatas.HasValue()) if (I18nResource.CultureDatas.HasValue())
@ -143,9 +152,18 @@ public class ModInfoModel : ObservableObjectX
/// </summary> /// </summary>
public static ModInfoModel Current { get; set; } = new(); public static ModInfoModel Current { get; set; } = new();
/// <summary>
/// I18n资源
/// </summary>
public I18nResource<string, string> I18nResource { get; } = public I18nResource<string, string> I18nResource { get; } =
new() { FillDefaultValueForNewCulture = true, DefaultValue = string.Empty }; new() { FillDefaultValueForNewCulture = true, DefaultValue = string.Empty };
/// <summary>
/// 临时I18n资源, 用于新建的项目
/// </summary>
public I18nResource<string, string> TempI18nResource { get; } =
new() { FillDefaultValueForNewCulture = true, DefaultValue = string.Empty };
#region I18nData #region I18nData
public string Name public string Name
{ {
@ -339,6 +357,41 @@ public class ModInfoModel : ObservableObjectX
#endregion #endregion
#endregion #endregion
private void I18nResource_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(I18nResource.CurrentCulture))
{
TempI18nResource.CurrentCulture = I18nResource.CurrentCulture;
}
}
private void Cultures_SetChanged(
IObservableSet<CultureInfo> sender,
NotifySetChangeEventArgs<CultureInfo> e
)
{
if (e.Action is SetChangeAction.Clear)
{
TempI18nResource.ClearCulture();
}
else
{
if (e.OldItems is not null)
{
foreach (var item in e.OldItems)
{
TempI18nResource.RemoveCulture(item);
}
}
if (e.NewItems is not null)
{
foreach (var item in e.NewItems)
{
TempI18nResource.AddCulture(item);
}
}
}
}
private void Pets_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) private void Pets_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{ {
@ -448,9 +501,6 @@ public class ModInfoModel : ObservableObjectX
/// </summary> /// </summary>
private void LoadI18nDatas(ModLoader modLoader) private void LoadI18nDatas(ModLoader modLoader)
{ {
if (modLoader.I18nDatas.HasValue() is false)
return;
foreach (var cultureDatas in modLoader.I18nDatas) foreach (var cultureDatas in modLoader.I18nDatas)
{ {
var culture = CultureInfo.GetCultureInfo(cultureDatas.Key); var culture = CultureInfo.GetCultureInfo(cultureDatas.Key);
@ -460,106 +510,11 @@ public class ModInfoModel : ObservableObjectX
} }
if (I18nResource.SetCurrentCulture(CultureInfo.CurrentCulture) is false) if (I18nResource.SetCurrentCulture(CultureInfo.CurrentCulture) is false)
I18nResource.SetCurrentCulture(I18nResource.Cultures.First()); I18nResource.SetCurrentCulture(I18nResource.Cultures.First());
I18nResource.I18nObjectInfos.Add(
new(
this,
OnPropertyChanged,
[
(nameof(ID), ID, nameof(Name), true),
(nameof(DescriptionID), DescriptionID, nameof(Description), true)
]
)
);
//foreach (var lang in I18nDatas.Keys.Union(OtherI18nDatas.Keys))
//{
// if (I18nHelper.Current.CultureNames.Contains(lang) is false)
// I18nHelper.Current.CultureNames.Add(lang);
//}
//if (I18nHelper.Current.CultureNames.Count == 0)
// return;
//I18nHelper.Current.CultureName = I18nHelper.Current.CultureNames.First();
//foreach (var i18nData in OtherI18nDatas)
//{
// LoadFoodI18nData(i18nData.Key, i18nData.Value);
// LoadLowTextI18nData(i18nData.Key, i18nData.Value);
// LoadClickTextI18nData(i18nData.Key, i18nData.Value);
// LoadSelectTextI18nData(i18nData.Key, i18nData.Value);
// LoadPetI18nData(i18nData.Key, i18nData.Value);
//}
} }
//private void LoadFoodI18nData(string key, Dictionary<string, string> i18nData) public void RefreshAllID()
//{
// foreach (var food in Foods)
// {
// if (food.I18nDatas.TryGetValue(key, out var data) is false)
// continue;
// if (i18nData.TryGetValue(food.ID, out var name))
// data.Name = name;
// if (i18nData.TryGetValue(food.DescriptionID, out var description))
// data.Description = description;
// }
//}
//private void LoadLowTextI18nData(string key, Dictionary<string, string> i18nData)
//{
// foreach (var lowText in LowTexts)
// {
// if (lowText.I18nDatas.TryGetValue(key, out var data) is false)
// continue;
// if (i18nData.TryGetValue(lowText.ID, out var text))
// data.Text = text;
// }
//}
//private void LoadClickTextI18nData(string key, Dictionary<string, string> i18nData)
//{
// foreach (var clickText in ClickTexts)
// {
// if (clickText.I18nDatas.TryGetValue(key, out var data) is false)
// continue;
// if (i18nData.TryGetValue(clickText.ID, out var text))
// data.Text = text;
// }
//}
//private void LoadSelectTextI18nData(string key, Dictionary<string, string> i18nData)
//{
// foreach (var selectText in SelectTexts)
// {
// if (selectText.I18nDatas.TryGetValue(key, out var data) is false)
// continue;
// if (i18nData.TryGetValue(selectText.ID, out var text))
// data.Text = text;
// if (i18nData.TryGetValue(selectText.ChooseID, out var choose))
// data.Choose = choose;
// }
//}
//private void LoadPetI18nData(string key, Dictionary<string, string> i18nData)
//{
// foreach (var pet in Pets)
// {
// if (pet.I18nDatas.TryGetValue(key, out var data) is false)
// continue;
// if (i18nData.TryGetValue(pet.ID, out var name))
// data.Name = name;
// if (i18nData.TryGetValue(pet.PetNameID, out var petName))
// data.PetName = petName;
// if (i18nData.TryGetValue(pet.DescriptionID, out var description))
// data.Description = description;
// foreach (var work in pet.Works)
// {
// if (work.I18nDatas.TryGetValue(key, out var workData) is false)
// continue;
// if (i18nData.TryGetValue(work.ID, out var workName))
// workData.Name = workName;
// }
// }
//}
private void RefreshAllID()
{ {
RefreshID();
foreach (var food in Foods) foreach (var food in Foods)
food.RefreshID(); food.RefreshID();
foreach (var selectText in SelectTexts) foreach (var selectText in SelectTexts)

View File

@ -27,7 +27,7 @@ public static class ModUpdataHelper
/// <returns>可以升级为 <see langword="true"/> 不可以为 <see langword="false"/></returns> /// <returns>可以升级为 <see langword="true"/> 不可以为 <see langword="false"/></returns>
public static bool CanUpdata(ModInfoModel mod) public static bool CanUpdata(ModInfoModel mod)
{ {
if (mod.ModVersion >= LastVersion) if (mod.GameVersion >= LastVersion)
return false; return false;
return true; return true;
} }
@ -44,7 +44,7 @@ public static class ModUpdataHelper
return false; return false;
foreach (var action in UpdataAction) foreach (var action in UpdataAction)
{ {
if (mod.ModVersion >= action.Key) if (mod.GameVersion >= action.Key)
continue; continue;
try try
{ {

View File

@ -30,17 +30,6 @@ public class PetModel : ObservableObjectX
PropertyChanged += PetModel_PropertyChanged; PropertyChanged += PetModel_PropertyChanged;
Animes.PropertyChanged += Animes_PropertyChanged; Animes.PropertyChanged += Animes_PropertyChanged;
FoodAnimes.PropertyChanged += FoodAnimes_PropertyChanged; FoodAnimes.PropertyChanged += FoodAnimes_PropertyChanged;
ModInfoModel.Current.I18nResource.I18nObjectInfos.Add(
new(
this,
OnPropertyChanged,
[
(nameof(ID), ID, nameof(Name), true),
(nameof(PetNameID), PetNameID, nameof(Name), true),
(nameof(DescriptionID), DescriptionID, nameof(Description), true)
]
)
);
} }
private void PetModel_PropertyChanged(object? sender, PropertyChangedEventArgs e) private void PetModel_PropertyChanged(object? sender, PropertyChangedEventArgs e)
@ -126,12 +115,12 @@ public class PetModel : ObservableObjectX
return; return;
foreach (var work in loader.Config.Works) foreach (var work in loader.Config.Works)
Works.Add(new(work)); Works.Add(new(work) { I18nResource = ModInfoModel.Current.I18nResource });
foreach (var move in loader.Config.Moves) foreach (var move in loader.Config.Moves)
Moves.Add(new(move)); Moves.Add(new(move));
} }
public static PetModel Current { get; } = new(); public static PetModel Current { get; } = null!;
#region FromMain #region FromMain
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
@ -164,7 +153,7 @@ public class PetModel : ObservableObjectX
} }
} }
#endregion #endregion
#region PetNameId #region PetNameID
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _petNameID = string.Empty; private string _petNameID = string.Empty;
@ -178,7 +167,7 @@ public class PetModel : ObservableObjectX
} }
#endregion #endregion
#region DescriptionId #region DescriptionID
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _descriptionID = string.Empty; private string _descriptionID = string.Empty;
@ -193,33 +182,57 @@ public class PetModel : ObservableObjectX
#endregion #endregion
#region I18nData #region I18nData
[AdaptIgnore]
private I18nResource<string, string> _i18nResource = null!;
[AdaptIgnore]
public required I18nResource<string, string> I18nResource
{
get => _i18nResource;
set
{
if (_i18nResource is not null)
I18nResource.I18nObjectInfos.Remove(this);
_i18nResource = value;
InitializeI18nResource();
}
}
public void InitializeI18nResource()
{
I18nResource.I18nObjectInfos.Add(
this,
new(
this,
OnPropertyChanged,
[
(nameof(ID), ID, nameof(Name), true),
(nameof(PetNameID), PetNameID, nameof(PetName), true),
(nameof(DescriptionID), DescriptionID, nameof(Description), true)
]
)
);
}
[AdaptIgnore] [AdaptIgnore]
public string Name public string Name
{ {
get => ModInfoModel.Current.I18nResource.GetCurrentCultureDataOrDefault(ID); get => I18nResource.GetCurrentCultureDataOrDefault(ID);
set => ModInfoModel.Current.I18nResource.SetCurrentCultureData(ID, value); set => I18nResource.SetCurrentCultureData(ID, value);
} }
[AdaptIgnore] [AdaptIgnore]
public string PetName public string PetName
{ {
get => get => I18nResource.GetCurrentCultureDataOrDefault(PetNameID);
ModInfoModel.Current.I18nResource.GetCurrentCultureDataOrDefault( set => I18nResource.SetCurrentCultureData(PetNameID, value);
PetNameID,
string.Empty
);
set => ModInfoModel.Current.I18nResource.SetCurrentCultureData(PetNameID, value);
} }
[AdaptIgnore] [AdaptIgnore]
public string Description public string Description
{ {
get => get => I18nResource.GetCurrentCultureDataOrDefault(DescriptionID);
ModInfoModel.Current.I18nResource.GetCurrentCultureDataOrDefault( set => I18nResource.SetCurrentCultureData(DescriptionID, value);
DescriptionID,
string.Empty
);
set => ModInfoModel.Current.I18nResource.SetCurrentCultureData(DescriptionID, value);
} }
#endregion #endregion
@ -357,6 +370,11 @@ public class PetModel : ObservableObjectX
anime.Close(); anime.Close();
} }
public void CloseI18nResource()
{
I18nResource.I18nObjectInfos.Remove(this);
}
#region Save #region Save
/// <summary> /// <summary>
@ -382,17 +400,6 @@ public class PetModel : ObservableObjectX
/// <param name="path">路径</param> /// <param name="path">路径</param>
public void Save(string path) public void Save(string path)
{ {
// TODO
//foreach (var cultureName in I18nHelper.Current.CultureNames)
//{
// ModInfoModel.SaveI18nDatas[cultureName].TryAdd(ID, I18nDatas[cultureName].Name);
// ModInfoModel
// .SaveI18nDatas[cultureName]
// .TryAdd(PetNameID, I18nDatas[cultureName].PetName);
// ModInfoModel
// .SaveI18nDatas[cultureName]
// .TryAdd(DescriptionID, I18nDatas[cultureName].Description);
//}
var petFile = Path.Combine(path, $"{ID}.lps"); var petFile = Path.Combine(path, $"{ID}.lps");
if (File.Exists(petFile) is false) if (File.Exists(petFile) is false)
File.Create(petFile).Close(); File.Create(petFile).Close();
@ -439,14 +446,7 @@ public class PetModel : ObservableObjectX
{ {
foreach (var work in Works) foreach (var work in Works)
{ {
//TODO lps.Add(LPSConvert.SerializeObjectToLine<Line>(work.ToWork(), "work"));
//lps.Add(LPSConvert.SerializeObjectToLine<Line>(work.ToWork(), "work"));
//foreach (var cultureName in I18nHelper.Current.CultureNames)
//{
// ModInfoModel
// .SaveI18nDatas[cultureName]
// .TryAdd(work.ID, work.I18nDatas[cultureName].Name);
//}
} }
} }
@ -505,7 +505,8 @@ public class PetModel : ObservableObjectX
new Sub("petname", PetNameID) new Sub("petname", PetNameID)
} }
); );
lps.Add(new Line("tag", Tags)); if (string.IsNullOrWhiteSpace(Tags) is false)
lps.Add(new Line("tag", Tags));
} }
private void SavePetTouchHeadInfo(LPS lps) private void SavePetTouchHeadInfo(LPS lps)

View File

@ -18,19 +18,7 @@ namespace VPet.ModMaker.Models;
/// </summary> /// </summary>
public class SelectTextModel : ObservableObjectX public class SelectTextModel : ObservableObjectX
{ {
public SelectTextModel() public SelectTextModel() { }
{
ModInfoModel.Current.I18nResource.I18nObjectInfos.Add(
new(
this,
OnPropertyChanged,
[
(nameof(ID), ID, nameof(Text), true),
(nameof(ChooseID), ChooseID, nameof(Choose), true)
]
)
);
}
public SelectTextModel(SelectTextModel model) public SelectTextModel(SelectTextModel model)
: this() : this()
@ -120,37 +108,64 @@ public class SelectTextModel : ObservableObjectX
} }
#endregion #endregion
#region ChooseId #region ChooseID
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _chooseId = string.Empty; private string _chooseID = string.Empty;
/// <summary> /// <summary>
/// 选择Id /// 选择Id
/// </summary> /// </summary>
public string ChooseID public string ChooseID
{ {
get => _chooseId; get => _chooseID;
set => SetProperty(ref _chooseId, value); set => SetProperty(ref _chooseID, value);
} }
#endregion #endregion
#region I18nData #region I18nData
[AdaptIgnore]
private I18nResource<string, string> _i18nResource = null!;
[AdaptIgnore]
public required I18nResource<string, string> I18nResource
{
get => _i18nResource;
set
{
if (_i18nResource is not null)
I18nResource.I18nObjectInfos.Remove(this);
_i18nResource = value;
InitializeI18nResource();
}
}
public void InitializeI18nResource()
{
I18nResource.I18nObjectInfos.Add(
this,
new(
this,
OnPropertyChanged,
[
(nameof(ID), ID, nameof(Text), true),
(nameof(ChooseID), ChooseID, nameof(Choose), true)
]
)
);
}
[AdaptIgnore] [AdaptIgnore]
public string Text public string Text
{ {
get => ModInfoModel.Current.I18nResource.GetCurrentCultureDataOrDefault(ID); get => I18nResource.GetCurrentCultureDataOrDefault(ID);
set => ModInfoModel.Current.I18nResource.SetCurrentCultureData(ID, value); set => I18nResource.SetCurrentCultureData(ID, value);
} }
[AdaptIgnore] [AdaptIgnore]
public string Choose public string Choose
{ {
get => get => I18nResource.GetCurrentCultureDataOrDefault(ChooseID, string.Empty);
ModInfoModel.Current.I18nResource.GetCurrentCultureDataOrDefault( set => I18nResource.SetCurrentCultureData(ChooseID, value);
ChooseID,
string.Empty
);
set => ModInfoModel.Current.I18nResource.SetCurrentCultureData(ChooseID, value);
} }
#endregion #endregion
@ -239,4 +254,9 @@ public class SelectTextModel : ObservableObjectX
StrengthMax = Strength.Max, StrengthMax = Strength.Max,
}; };
} }
public void Close()
{
I18nResource.I18nObjectInfos.Remove(this);
}
} }

View File

@ -23,9 +23,6 @@ public class WorkModel : ObservableObjectX
public WorkModel() public WorkModel()
{ {
PropertyChanged += WorkModel_PropertyChanged; PropertyChanged += WorkModel_PropertyChanged;
ModInfoModel.Current.I18nResource.I18nObjectInfos.Add(
new(this, OnPropertyChanged, [(nameof(ID), ID, nameof(Name), true)])
);
} }
private static readonly FrozenSet<string> _notifyIsOverLoad = FrozenSet.ToFrozenSet( private static readonly FrozenSet<string> _notifyIsOverLoad = FrozenSet.ToFrozenSet(
@ -126,11 +123,35 @@ public class WorkModel : ObservableObjectX
#endregion #endregion
#region I18nData #region I18nData
[AdaptIgnore]
private I18nResource<string, string> _i18nResource = null!;
[AdaptIgnore]
public required I18nResource<string, string> I18nResource
{
get => _i18nResource;
set
{
if (_i18nResource is not null)
I18nResource.I18nObjectInfos.Remove(this);
_i18nResource = value;
InitializeI18nResource();
}
}
public void InitializeI18nResource()
{
I18nResource.I18nObjectInfos.Add(
this,
new(this, OnPropertyChanged, [(nameof(ID), ID, nameof(Name), true),])
);
}
[AdaptIgnore] [AdaptIgnore]
public string Name public string Name
{ {
get => ModInfoModel.Current.I18nResource.GetCurrentCultureDataOrDefault(ID); get => I18nResource.GetCurrentCultureDataOrDefault(ID);
set => ModInfoModel.Current.I18nResource.SetCurrentCultureData(ID, value); set => I18nResource.SetCurrentCultureData(ID, value);
} }
#endregion #endregion
@ -459,10 +480,6 @@ public class WorkModel : ObservableObjectX
public void Close() public void Close()
{ {
//Image?.CloseStream(); //Image?.CloseStream();
var item = ModInfoModel.Current.I18nResource.I18nObjectInfos.FirstOrDefault(i => I18nResource.I18nObjectInfos.Remove(this);
i.Source == this
);
if (item is not null)
ModInfoModel.Current.I18nResource.I18nObjectInfos.Remove(item);
} }
} }

View File

@ -11,11 +11,23 @@
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
<LangVersion>preview</LangVersion> <LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Configurations>Debug;Release;Test</Configurations>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Resources\food.png" /> <EmbeddedResource Include="Resources\food.png" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Test'">
<Reference Include="HKW.Utils">
<HintPath>..\..\HKW.Utils\HKW.Utils\bin\Debug\net8.0\HKW.Utils.dll</HintPath>
</Reference>
<Reference Include="HKW.WPF">
<HintPath>..\..\HKW.WPF\HKW.WPF\bin\Debug\net8.0-windows\HKW.WPF.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'!='Test'">
<PackageReference Include="HKW.WPF" Version="1.0.6" />
<PackageReference Include="HKW.Utils" Version="1.2.21" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="VPet-Simulator.Core" Version="1.1.0.4" /> <PackageReference Include="VPet-Simulator.Core" Version="1.1.0.4" />
<PackageReference Include="VPet-Simulator.Windows.Interface" Version="1.1.0.5" /> <PackageReference Include="VPet-Simulator.Windows.Interface" Version="1.1.0.5" />
@ -28,8 +40,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" /> <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="HKW.Utils" Version="1.2.19" />
<PackageReference Include="HKW.WPF" Version="1.0.5" />
<PackageReference Include="Mapster" Version="7.4.0" /> <PackageReference Include="Mapster" Version="7.4.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -142,6 +142,8 @@ public class AnimePageVM : ObservableObjectX
private void InitializeAllAnimes() private void InitializeAllAnimes()
{ {
AllAnimes.Clear(); AllAnimes.Clear();
if (CurrentPet is null)
return;
foreach (var item in Animes) foreach (var item in Animes)
AllAnimes.Add(item); AllAnimes.Add(item);
foreach (var item in FoodAnimes) foreach (var item in FoodAnimes)

View File

@ -26,7 +26,7 @@ public class ClickTextEditWindowVM : ObservableObjectX
#region ClickText #region ClickText
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ClickTextModel _clickText = new(); private ClickTextModel _clickText = new() { I18nResource = ModInfoModel.Current.I18nResource };
/// <summary> /// <summary>
/// 点击文本 /// 点击文本

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using HKW.HKWUtils.Extensions;
using HKW.HKWUtils.Observable; using HKW.HKWUtils.Observable;
using LinePutScript.Localization.WPF; using LinePutScript.Localization.WPF;
using VPet.ModMaker.Models; using VPet.ModMaker.Models;
@ -22,6 +23,7 @@ public class ClickTextPageVM : ObservableObjectX
Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase), Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase),
FilteredList = new() FilteredList = new()
}; };
ClickTexts.BindingList(ModInfoModel.Current.ClickTexts);
AddCommand.ExecuteCommand += AddCommand_ExecuteCommand; AddCommand.ExecuteCommand += AddCommand_ExecuteCommand;
EditCommand.ExecuteCommand += EditCommand_ExecuteCommand; EditCommand.ExecuteCommand += EditCommand_ExecuteCommand;
RemoveCommand.ExecuteCommand += RemoveCommand_ExecuteCommand; RemoveCommand.ExecuteCommand += RemoveCommand_ExecuteCommand;
@ -100,11 +102,22 @@ public class ClickTextPageVM : ObservableObjectX
var window = new ClickTextEditWindow(); var window = new ClickTextEditWindow();
var vm = window.ViewModel; var vm = window.ViewModel;
vm.OldClickText = model; vm.OldClickText = model;
var newLowTest = vm.ClickText = new(model); var newModel = vm.ClickText = new(model)
{
I18nResource = ModInfoModel.Current.TempI18nResource
};
model.I18nResource.CopyDataTo(newModel.I18nResource, model.ID, true);
window.ShowDialog(); window.ShowDialog();
if (window.IsCancel) if (window.IsCancel)
{
newModel.I18nResource.ClearCultureData();
newModel.Close();
return; return;
ClickTexts[ClickTexts.IndexOf(model)] = newLowTest; }
newModel.I18nResource.CopyDataTo(ModInfoModel.Current.I18nResource, true);
newModel.I18nResource = ModInfoModel.Current.I18nResource;
ClickTexts[ClickTexts.IndexOf(model)] = newModel;
model.Close();
} }
/// <summary> /// <summary>
@ -116,5 +129,6 @@ public class ClickTextPageVM : ObservableObjectX
if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No)
return; return;
ClickTexts.Remove(model); ClickTexts.Remove(model);
model.Close();
} }
} }

View File

@ -36,7 +36,7 @@ public class FoodEditWindowVM : ObservableObjectX
#region Food #region Food
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private FoodModel _food = new(); private FoodModel _food = new() { I18nResource = ModInfoModel.Current.I18nResource };
public FoodModel Food public FoodModel Food
{ {

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using HKW.HKWUtils.Extensions;
using HKW.HKWUtils.Observable; using HKW.HKWUtils.Observable;
using LinePutScript.Localization.WPF; using LinePutScript.Localization.WPF;
using VPet.ModMaker.Models; using VPet.ModMaker.Models;
@ -24,6 +25,7 @@ public class FoodPageVM : ObservableObjectX
Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase), Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase),
FilteredList = new() FilteredList = new()
}; };
Foods.BindingList(ModInfoModel.Current.Foods);
AddCommand.ExecuteCommand += AddCommand_ExecuteCommand; AddCommand.ExecuteCommand += AddCommand_ExecuteCommand;
EditCommand.ExecuteCommand += EditCommand_ExecuteCommand; EditCommand.ExecuteCommand += EditCommand_ExecuteCommand;
@ -76,23 +78,34 @@ public class FoodPageVM : ObservableObjectX
Foods.Add(vm.Food); Foods.Add(vm.Food);
} }
public void EditCommand_ExecuteCommand(FoodModel food) public void EditCommand_ExecuteCommand(FoodModel model)
{ {
var window = new FoodEditWindow(); var window = new FoodEditWindow();
var vm = window.ViewModel; var vm = window.ViewModel;
vm.OldFood = food; vm.OldFood = model;
var newFood = vm.Food = new(food); var newModel = vm.Food = new(model)
{
I18nResource = ModInfoModel.Current.TempI18nResource
};
model.I18nResource.CopyDataTo(newModel.I18nResource, [model.ID, model.DescriptionID], true);
window.ShowDialog(); window.ShowDialog();
if (window.IsCancel) if (window.IsCancel)
{
newModel.I18nResource.ClearCultureData();
newModel.Close();
return; return;
Foods[Foods.IndexOf(food)] = newFood; }
food.Close(); newModel.I18nResource.CopyDataTo(ModInfoModel.Current.I18nResource, true);
newModel.I18nResource = ModInfoModel.Current.I18nResource;
Foods[Foods.IndexOf(model)] = newModel;
model.Close();
} }
private void RemoveCommand_ExecuteCommand(FoodModel food) private void RemoveCommand_ExecuteCommand(FoodModel model)
{ {
if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No)
return; return;
Foods.Remove(food); Foods.Remove(model);
model.Close();
} }
} }

View File

@ -23,16 +23,27 @@ public class I18nEditWindowVM : ObservableObjectX
SearchTarget = SearchTargets.First(); SearchTarget = SearchTargets.First();
PropertyChanged += I18nEditWindowVM_PropertyChanged; PropertyChanged += I18nEditWindowVM_PropertyChanged;
ModInfoModel.Current.I18nResource.Cultures.SetChanged -= Cultures_SetChanged; I18nResource.Cultures.SetChanged -= Cultures_SetChanged;
ModInfoModel.Current.I18nResource.Cultures.SetChanged += Cultures_SetChanged; I18nResource.Cultures.SetChanged += Cultures_SetChanged;
I18nResource.CultureDatas.DictionaryChanged -= CultureDatas_DictionaryChanged;
I18nResource.CultureDatas.DictionaryChanged += CultureDatas_DictionaryChanged;
I18nDatas = new() { Filter = DataFilter, FilteredList = [] }; I18nDatas = new() { Filter = DataFilter, FilteredList = [] };
foreach (var data in ModInfoModel.Current.I18nResource.CultureDatas.Values) foreach (var data in I18nResource.CultureDatas.Values)
{
I18nDatas.Add(data); I18nDatas.Add(data);
foreach (var culture in ModInfoModel.Current.I18nResource.Cultures) data.DictionaryChanged += Data_DictionaryChanged;
}
foreach (var culture in I18nResource.Cultures)
SearchTargets.Add(culture.Name); SearchTargets.Add(culture.Name);
} }
public I18nResource<string, string> I18nResource { get; set; } =
ModInfoModel.Current.I18nResource;
public bool CellEdit { get; set; } = false;
#region Search #region Search
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _search = string.Empty; private string _search = string.Empty;
@ -97,7 +108,7 @@ public class I18nEditWindowVM : ObservableObjectX
private void Cultures_SetChanged( private void Cultures_SetChanged(
IObservableSet<CultureInfo> sender, IObservableSet<CultureInfo> sender,
NotifySetChangedEventArgs<CultureInfo> e NotifySetChangeEventArgs<CultureInfo> e
) )
{ {
if (e.Action is SetChangeAction.Add) if (e.Action is SetChangeAction.Add)
@ -122,6 +133,46 @@ public class I18nEditWindowVM : ObservableObjectX
} }
} }
private void CultureDatas_DictionaryChanged(
IObservableDictionary<string, ObservableCultureDataDictionary<string, string>> sender,
NotifyDictionaryChangeEventArgs<string, ObservableCultureDataDictionary<string, string>> e
)
{
if (e.Action is DictionaryChangeAction.Add)
{
if (e.TryGetNewPair(out var newPair) is false)
return;
I18nDatas.Add(newPair.Value);
newPair.Value.DictionaryChanged -= Data_DictionaryChanged;
newPair.Value.DictionaryChanged += Data_DictionaryChanged;
}
else if (e.Action is DictionaryChangeAction.Remove)
{
if (e.TryGetOldPair(out var oldPair) is false)
return;
I18nDatas.Remove(oldPair.Value);
oldPair.Value.DictionaryChanged -= Data_DictionaryChanged;
}
else if (e.Action is DictionaryChangeAction.Replace)
{
if (e.TryGetNewPair(out var newPair) is false)
return;
if (e.TryGetOldPair(out var oldPair) is false)
return;
if (I18nDatas.TryFind(0, i => i.Key == newPair.Key, out var itemInfo) is false)
return;
I18nDatas.RemoveAt(itemInfo.Index);
I18nDatas.Insert(itemInfo.Index, newPair.Value);
oldPair.Value.DictionaryChanged -= Data_DictionaryChanged;
newPair.Value.DictionaryChanged -= Data_DictionaryChanged;
newPair.Value.DictionaryChanged += Data_DictionaryChanged;
}
else if (e.Action is DictionaryChangeAction.Clear)
{
I18nDatas.Clear();
}
}
private void I18nEditWindowVM_PropertyChanged(object? sender, PropertyChangedEventArgs e) private void I18nEditWindowVM_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{ {
if (e.PropertyName == nameof(Search)) if (e.PropertyName == nameof(Search))
@ -134,6 +185,29 @@ public class I18nEditWindowVM : ObservableObjectX
} }
} }
private void Data_DictionaryChanged(
IObservableDictionary<CultureInfo, string> sender,
NotifyDictionaryChangeEventArgs<CultureInfo, string> e
)
{
if (sender is not ObservableCultureDataDictionary<string, string> cultureDatas)
return;
// 刷新修改后的数据
if (e.Action is DictionaryChangeAction.Replace)
{
if (CellEdit)
{
// 防止在编辑单元格时重复响应
CellEdit = false;
return;
}
if (I18nDatas.TryFind(0, i => i.Key == cultureDatas.Key, out var itemInfo) is false)
return;
I18nDatas.RemoveAt(itemInfo.Index);
I18nDatas.Insert(itemInfo.Index, cultureDatas);
}
}
#region Event #region Event
private void AddCulture(string culture) private void AddCulture(string culture)
{ {
@ -145,10 +219,10 @@ public class I18nEditWindowVM : ObservableObjectX
CultureChanged?.Invoke(culture, string.Empty); CultureChanged?.Invoke(culture, string.Empty);
} }
private void ReplaceCulture(string oldCulture, string newCulture) //private void ReplaceCulture(string oldCulture, string newCulture)
{ //{
CultureChanged?.Invoke(oldCulture, newCulture); // CultureChanged?.Invoke(oldCulture, newCulture);
} //}
public event CultureChangedEventHandler? CultureChanged; public event CultureChangedEventHandler? CultureChanged;
#endregion #endregion

View File

@ -22,7 +22,7 @@ public class LowTextEditWindowVM : ObservableObjectX
#region LowText #region LowText
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private LowTextModel _lowText = new(); private LowTextModel _lowText = new() { I18nResource = ModInfoModel.Current.I18nResource };
public LowTextModel LowText public LowTextModel LowText
{ {

View File

@ -8,6 +8,7 @@ using System.Linq.Expressions;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using HKW.HKWUtils.Extensions;
using HKW.HKWUtils.Observable; using HKW.HKWUtils.Observable;
using LinePutScript.Localization.WPF; using LinePutScript.Localization.WPF;
using VPet.ModMaker.Models; using VPet.ModMaker.Models;
@ -24,6 +25,7 @@ public class LowTextPageVM : ObservableObjectX
Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase), Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase),
FilteredList = new() FilteredList = new()
}; };
LowTexts.BindingList(ModInfoModel.Current.LowTexts);
AddCommand.ExecuteCommand += AddCommand_ExecuteCommand; AddCommand.ExecuteCommand += AddCommand_ExecuteCommand;
EditCommand.ExecuteCommand += EditCommand_ExecuteCommand; EditCommand.ExecuteCommand += EditCommand_ExecuteCommand;
@ -78,11 +80,22 @@ public class LowTextPageVM : ObservableObjectX
var window = new LowTextEditWindow(); var window = new LowTextEditWindow();
var vm = window.ViewModel; var vm = window.ViewModel;
vm.OldLowText = model; vm.OldLowText = model;
var newLowTest = vm.LowText = new(model); var newModel = vm.LowText = new(model)
{
I18nResource = ModInfoModel.Current.TempI18nResource
};
model.I18nResource.CopyDataTo(newModel.I18nResource, model.ID, true);
window.ShowDialog(); window.ShowDialog();
if (window.IsCancel) if (window.IsCancel)
{
newModel.I18nResource.ClearCultureData();
newModel.Close();
return; return;
LowTexts[LowTexts.IndexOf(model)] = newLowTest; }
newModel.I18nResource.CopyDataTo(ModInfoModel.Current.I18nResource, true);
newModel.I18nResource = ModInfoModel.Current.I18nResource;
LowTexts[LowTexts.IndexOf(model)] = newModel;
model.Close();
} }
private void RemoveCommand_ExecuteCommand(LowTextModel model) private void RemoveCommand_ExecuteCommand(LowTextModel model)
@ -90,5 +103,6 @@ public class LowTextPageVM : ObservableObjectX
if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No)
return; return;
LowTexts.Remove(model); LowTexts.Remove(model);
model.Close();
} }
} }

View File

@ -160,8 +160,8 @@ public class ModEditWindowVM : ObservableObjectX
window.ShowDialog(); window.ShowDialog();
if (window.IsCancel) if (window.IsCancel)
return; return;
ModInfoModel.Current.I18nResource.AddCulture(window.ViewModel.Culture); I18nResource.AddCulture(window.ViewModel.Culture);
ModInfoModel.Current.I18nResource.SetCurrentCulture(window.ViewModel.Culture); I18nResource.SetCurrentCulture(window.ViewModel.Culture);
} }
/// <summary> /// <summary>
@ -175,7 +175,7 @@ public class ModEditWindowVM : ObservableObjectX
window.ShowDialog(); window.ShowDialog();
if (window.IsCancel) if (window.IsCancel)
return; return;
ModInfoModel.Current.I18nResource.ReplaceCulture(oldCulture, window.ViewModel.Culture); I18nResource.ReplaceCulture(oldCulture, window.ViewModel.Culture);
} }
/// <summary> /// <summary>
@ -192,7 +192,7 @@ public class ModEditWindowVM : ObservableObjectX
) is MessageBoxResult.No ) is MessageBoxResult.No
) )
return; return;
ModInfoModel.Current.I18nResource.RemoveCulture(oldCulture); I18nResource.RemoveCulture(oldCulture);
} }
public void SetMainCultureCommand_ExecuteCommand(string culture) public void SetMainCultureCommand_ExecuteCommand(string culture)
@ -207,31 +207,11 @@ public class ModEditWindowVM : ObservableObjectX
is not MessageBoxResult.Yes is not MessageBoxResult.Yes
) )
return; return;
// TODO foreach (var datas in I18nResource.CultureDatas)
//ModInfo.I18nDatas[culture].Name = ModInfo.ID; {
//ModInfo.I18nDatas[culture].Description = ModInfo.DescriptionID; I18nResource.SetCurrentCultureData(datas.Key, datas.Key);
//foreach (var food in ModInfo.Foods) }
//{ ModInfo.RefreshAllID();
// food.I18nDatas[culture].Name = food.ID;
// food.I18nDatas[culture].Description = food.DescriptionID;
//}
//foreach (var text in ModInfo.LowTexts)
// text.I18nDatas[culture].Text = text.ID;
//foreach (var text in ModInfo.ClickTexts)
// text.I18nDatas[culture].Text = text.ID;
//foreach (var text in ModInfo.SelectTexts)
//{
// text.I18nDatas[culture].Text = text.ID;
// text.I18nDatas[culture].Choose = text.ChooseID;
//}
//foreach (var pet in ModInfo.Pets)
//{
// pet.I18nDatas[culture].Name = pet.ID;
// pet.I18nDatas[culture].PetName = pet.PetNameID;
// pet.I18nDatas[culture].Description = pet.DescriptionID;
// foreach (var work in pet.Works)
// work.I18nDatas[culture].Name = work.ID;
//}
} }
#endregion #endregion
@ -299,7 +279,7 @@ public class ModEditWindowVM : ObservableObjectX
/// <returns>成功为 <see langword="true"/> 失败为 <see langword="false"/></returns> /// <returns>成功为 <see langword="true"/> 失败为 <see langword="false"/></returns>
private bool ValidationData(ModInfoModel model) private bool ValidationData(ModInfoModel model)
{ {
if (ModInfoModel.Current.I18nResource.CultureDatas.HasValue() is false) if (I18nResource.CultureDatas.HasValue() is false)
{ {
MessageBox.Show( MessageBox.Show(
ModEditWindow, ModEditWindow,

View File

@ -24,7 +24,9 @@ public class MovePageVM : ObservableObjectX
Filter = f => f.Graph.Contains(Search, StringComparison.OrdinalIgnoreCase), Filter = f => f.Graph.Contains(Search, StringComparison.OrdinalIgnoreCase),
FilteredList = new() FilteredList = new()
}; };
PropertyChanged += MovePageVM_PropertyChanged;
PropertyChangedX += MovePageVM_PropertyChangedX;
;
if (Pets.HasValue()) if (Pets.HasValue())
CurrentPet = Pets.FirstOrDefault( CurrentPet = Pets.FirstOrDefault(
m => m.FromMain is false && m.Moves.HasValue(), m => m.FromMain is false && m.Moves.HasValue(),
@ -78,12 +80,18 @@ public class MovePageVM : ObservableObjectX
public ObservableCommand<MoveModel> EditCommand { get; } = new(); public ObservableCommand<MoveModel> EditCommand { get; } = new();
public ObservableCommand<MoveModel> RemoveCommand { get; } = new(); public ObservableCommand<MoveModel> RemoveCommand { get; } = new();
#endregion #endregion
private void MovePageVM_PropertyChanged(object? sender, PropertyChangedEventArgs e)
private void MovePageVM_PropertyChangedX(object? sender, PropertyChangedXEventArgs e)
{ {
if (e.PropertyName == nameof(CurrentPet)) if (e.PropertyName == nameof(CurrentPet))
{ {
Moves.Clear(); Moves.Clear();
if (e.OldValue is PetModel pet)
Moves.BindingList(pet.Moves, true);
if (e.NewValue is null)
return;
Moves.AddRange(CurrentPet.Moves); Moves.AddRange(CurrentPet.Moves);
Moves.BindingList(CurrentPet.Moves);
} }
else if (e.PropertyName == nameof(Search)) else if (e.PropertyName == nameof(Search))
{ {

View File

@ -31,7 +31,7 @@ public class PetEditWindowVM : ObservableObjectX
#region Pet #region Pet
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private PetModel _pet = new(); private PetModel _pet = new() { I18nResource = ModInfoModel.Current.I18nResource };
public PetModel Pet public PetModel Pet
{ {

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using HKW.HKWUtils.Extensions;
using HKW.HKWUtils.Observable; using HKW.HKWUtils.Observable;
using LinePutScript.Localization.WPF; using LinePutScript.Localization.WPF;
using VPet.ModMaker.Models; using VPet.ModMaker.Models;
@ -23,6 +24,7 @@ public class PetPageVM : ObservableObjectX
Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase), Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase),
FilteredList = new() FilteredList = new()
}; };
Pets.BindingList(ModInfoModel.Current.Pets);
AddCommand.ExecuteCommand += AddCommand_ExecuteCommand; AddCommand.ExecuteCommand += AddCommand_ExecuteCommand;
EditCommand.ExecuteCommand += EditCommand_ExecuteCommand; EditCommand.ExecuteCommand += EditCommand_ExecuteCommand;
@ -89,21 +91,32 @@ public class PetPageVM : ObservableObjectX
var window = new PetEditWindow(); var window = new PetEditWindow();
var vm = window.ViewModel; var vm = window.ViewModel;
vm.OldPet = model; vm.OldPet = model;
var newPet = vm.Pet = new(model); var newModel = vm.Pet = new(model) { I18nResource = ModInfoModel.Current.TempI18nResource };
model.I18nResource.CopyDataTo(
newModel.I18nResource,
[model.ID, model.PetNameID, model.DescriptionID],
true
);
window.ShowDialog(); window.ShowDialog();
if (window.IsCancel) if (window.IsCancel)
{
newModel.I18nResource.ClearCultureData();
newModel.CloseI18nResource();
return; return;
}
newModel.I18nResource.CopyDataTo(ModInfoModel.Current.I18nResource, true);
newModel.I18nResource = ModInfoModel.Current.I18nResource;
if (model.FromMain) if (model.FromMain)
{ {
var index = Pets.IndexOf(model); var index = Pets.IndexOf(model);
Pets.Remove(model); Pets.Remove(model);
Pets.Insert(index, newPet); Pets.Insert(index, newModel);
} }
else else
{ {
Pets[Pets.IndexOf(model)] = newPet; Pets[Pets.IndexOf(model)] = newModel;
} }
model.Close(); model.CloseI18nResource();
} }
private void RemoveCommand_ExecuteCommand(PetModel model) private void RemoveCommand_ExecuteCommand(PetModel model)
@ -116,5 +129,6 @@ public class PetPageVM : ObservableObjectX
if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No)
return; return;
Pets.Remove(model); Pets.Remove(model);
model.CloseI18nResource();
} }
} }

View File

@ -20,7 +20,8 @@ public class SelectTextEditWindowVM : ObservableObjectX
#region SelectText #region SelectText
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private SelectTextModel _selectText = new(); private SelectTextModel _selectText =
new() { I18nResource = ModInfoModel.Current.I18nResource };
public SelectTextModel SelectText public SelectTextModel SelectText
{ {

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using HKW.HKWUtils.Extensions;
using HKW.HKWUtils.Observable; using HKW.HKWUtils.Observable;
using LinePutScript.Localization.WPF; using LinePutScript.Localization.WPF;
using VPet.ModMaker.Models; using VPet.ModMaker.Models;
@ -23,6 +24,8 @@ public class SelectTextPageVM : ObservableObjectX
Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase), Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase),
FilteredList = new() FilteredList = new()
}; };
SelectTexts.BindingList(ModInfoModel.Current.SelectTexts);
AddCommand.ExecuteCommand += AddCommand_ExecuteCommand; AddCommand.ExecuteCommand += AddCommand_ExecuteCommand;
EditCommand.ExecuteCommand += EditCommand_ExecuteCommand; EditCommand.ExecuteCommand += EditCommand_ExecuteCommand;
RemoveCommand.ExecuteCommand += RemoveCommand_ExecuteCommand; RemoveCommand.ExecuteCommand += RemoveCommand_ExecuteCommand;
@ -77,11 +80,22 @@ public class SelectTextPageVM : ObservableObjectX
var window = new SelectTextEditWindow(); var window = new SelectTextEditWindow();
var vm = window.ViewModel; var vm = window.ViewModel;
vm.OldSelectText = model; vm.OldSelectText = model;
var newSelectText = vm.SelectText = new(model); var newModel = vm.SelectText = new(model)
{
I18nResource = ModInfoModel.Current.I18nResource
};
model.I18nResource.CopyDataTo(newModel.I18nResource, [model.ID, model.ChooseID], true);
window.ShowDialog(); window.ShowDialog();
if (window.IsCancel) if (window.IsCancel)
{
newModel.I18nResource.ClearCultureData();
newModel.Close();
return; return;
SelectTexts[SelectTexts.IndexOf(model)] = newSelectText; }
newModel.I18nResource.CopyDataTo(ModInfoModel.Current.I18nResource, true);
newModel.I18nResource = ModInfoModel.Current.I18nResource;
SelectTexts[SelectTexts.IndexOf(model)] = newModel;
model.Close();
} }
private void RemoveCommand_ExecuteCommand(SelectTextModel model) private void RemoveCommand_ExecuteCommand(SelectTextModel model)
@ -89,5 +103,6 @@ public class SelectTextPageVM : ObservableObjectX
if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No)
return; return;
SelectTexts.Remove(model); SelectTexts.Remove(model);
model.Close();
} }
} }

View File

@ -102,7 +102,7 @@ public class WorkEditWindowVM : ObservableObjectX
#region Work #region Work
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private WorkModel _work = new(); private WorkModel _work = new() { I18nResource = ModInfoModel.Current.I18nResource };
public WorkModel Work public WorkModel Work
{ {

View File

@ -24,7 +24,8 @@ public class WorkPageVM : ObservableObjectX
Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase), Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase),
FilteredList = new() FilteredList = new()
}; };
PropertyChanged += WorkPageVM_PropertyChanged; PropertyChangedX += WorkPageVM_PropertyChangedX;
if (Pets.HasValue()) if (Pets.HasValue())
CurrentPet = Pets.FirstOrDefault( CurrentPet = Pets.FirstOrDefault(
m => m.FromMain is false && m.Works.HasValue(), m => m.FromMain is false && m.Works.HasValue(),
@ -40,7 +41,7 @@ public class WorkPageVM : ObservableObjectX
#region Property #region Property
#region Works #region Works
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableFilterList<WorkModel, ObservableList<WorkModel>> _works; private ObservableFilterList<WorkModel, ObservableList<WorkModel>> _works = null!;
public ObservableFilterList<WorkModel, ObservableList<WorkModel>> Works public ObservableFilterList<WorkModel, ObservableList<WorkModel>> Works
{ {
@ -53,7 +54,7 @@ public class WorkPageVM : ObservableObjectX
#region CurrentPet #region CurrentPet
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private PetModel _currentPet; private PetModel _currentPet = null!;
public PetModel CurrentPet public PetModel CurrentPet
{ {
@ -78,12 +79,18 @@ public class WorkPageVM : ObservableObjectX
public ObservableCommand<WorkModel> EditCommand { get; } = new(); public ObservableCommand<WorkModel> EditCommand { get; } = new();
public ObservableCommand<WorkModel> RemoveCommand { get; } = new(); public ObservableCommand<WorkModel> RemoveCommand { get; } = new();
#endregion #endregion
private void WorkPageVM_PropertyChanged(object? sender, PropertyChangedEventArgs e)
private void WorkPageVM_PropertyChangedX(object? sender, PropertyChangedXEventArgs e)
{ {
if (e.PropertyName == nameof(CurrentPet)) if (e.PropertyName == nameof(CurrentPet))
{ {
Works.Clear(); Works.Clear();
if (e.OldValue is PetModel pet)
Works.BindingList(pet.Works, true);
if (e.NewValue is null)
return;
Works.AddRange(CurrentPet.Works); Works.AddRange(CurrentPet.Works);
Works.BindingList(CurrentPet.Works);
} }
else if (e.PropertyName == nameof(Search)) else if (e.PropertyName == nameof(Search))
{ {
@ -108,11 +115,21 @@ public class WorkPageVM : ObservableObjectX
var vm = window.ViewModel; var vm = window.ViewModel;
vm.CurrentPet = CurrentPet; vm.CurrentPet = CurrentPet;
vm.OldWork = model; vm.OldWork = model;
var newWork = vm.Work = new(model); var newModel = vm.Work = new(model)
{
I18nResource = ModInfoModel.Current.TempI18nResource
};
model.I18nResource.CopyDataTo(newModel.I18nResource, model.ID, true);
window.ShowDialog(); window.ShowDialog();
if (window.IsCancel) if (window.IsCancel)
{
newModel.I18nResource.ClearCultureData();
newModel.Close();
return; return;
Works[Works.IndexOf(model)] = newWork; }
newModel.I18nResource.CopyDataTo(ModInfoModel.Current.I18nResource, true);
newModel.I18nResource = ModInfoModel.Current.I18nResource;
Works[Works.IndexOf(model)] = newModel;
model.Close(); model.Close();
} }

View File

@ -79,7 +79,7 @@ public partial class AddCultureWindow : WindowX
if ( if (
MessageBoxX.Show( MessageBoxX.Show(
this, this,
"无法正确打开链接,需要复制自行访问吗", "无法打开链接,需要复制自行访问吗",
"", "",
MessageBoxButton.YesNo, MessageBoxButton.YesNo,
MessageBoxIcon.Warning MessageBoxIcon.Warning

View File

@ -27,8 +27,8 @@ public partial class AnimeEditWindow : Window
{ {
public AnimeEditWindow() public AnimeEditWindow()
{ {
DataContext = new AnimeEditWindowVM();
InitializeComponent(); InitializeComponent();
DataContext = new AnimeEditWindowVM();
Closed += (s, e) => Closed += (s, e) =>
{ {
try try
@ -77,12 +77,12 @@ public partial class AnimeEditWindow : Window
RoutedEvent = MouseWheelEvent, RoutedEvent = MouseWheelEvent,
Source = sender Source = sender
}; };
var parent = ((Control)sender).Parent as UIElement; var parent = ((Control)sender!).Parent as UIElement;
parent.RaiseEvent(eventArg); parent.RaiseEvent(eventArg);
e.Handled = true; e.Handled = true;
} }
private object _dropSender; private object _dropSender = null!;
private void ListBox_PreviewMouseMove(object? sender, MouseEventArgs e) private void ListBox_PreviewMouseMove(object? sender, MouseEventArgs e)
{ {

View File

@ -28,8 +28,8 @@ public partial class FoodAnimeEditWindow : Window
{ {
public FoodAnimeEditWindow() public FoodAnimeEditWindow()
{ {
DataContext = new FoodAnimeEditWindowVM();
InitializeComponent(); InitializeComponent();
DataContext = new FoodAnimeEditWindowVM();
Closed += (s, e) => Closed += (s, e) =>
{ {
try try

View File

@ -43,6 +43,7 @@
CanUserAddRows="False" CanUserAddRows="False"
CanUserDeleteRows="False" CanUserDeleteRows="False"
CanUserReorderColumns="False" CanUserReorderColumns="False"
CellEditEnding="DataGrid_Datas_CellEditEnding"
ItemsSource="{Binding I18nDatas.FilteredList}" ItemsSource="{Binding I18nDatas.FilteredList}"
ScrollViewer.IsDeferredScrollingEnabled="True" ScrollViewer.IsDeferredScrollingEnabled="True"
VirtualizingStackPanel.VirtualizationMode="Recycling"> VirtualizingStackPanel.VirtualizationMode="Recycling">

View File

@ -87,8 +87,6 @@ public partial class I18nEditWindow : WindowX
/// <param name="newCultureName"></param> /// <param name="newCultureName"></param>
public void ReplaceCulture(string oldCultureName, string newCultureName) public void ReplaceCulture(string oldCultureName, string newCultureName)
{ {
//if (_dataGridI18nColumns.ContainsKey(newCultureName))
// throw new();
var column = _dataGridI18nColumns[oldCultureName]; var column = _dataGridI18nColumns[oldCultureName];
column.Header = newCultureName; column.Header = newCultureName;
_dataGridI18nColumns.Remove(oldCultureName); _dataGridI18nColumns.Remove(oldCultureName);
@ -111,4 +109,9 @@ public partial class I18nEditWindow : WindowX
} }
#endregion #endregion
private void DataGrid_Datas_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
ViewModel.CellEdit = true;
}
} }

View File

@ -76,7 +76,7 @@ public partial class ModEditWindow : WindowX
/// </summary> /// </summary>
public void InitializeData() public void InitializeData()
{ {
if (ModInfoModel.Current.I18nResource.CultureDatas.HasValue() is false) if (ModInfoModel.Current.I18nResource.Cultures.HasValue() is false)
{ {
if ( if (
MessageBox.Show("未添加任何文化,确定要添加文化吗?".Translate(), "", MessageBoxButton.YesNo) MessageBox.Show("未添加任何文化,确定要添加文化吗?".Translate(), "", MessageBoxButton.YesNo)
@ -84,8 +84,10 @@ public partial class ModEditWindow : WindowX
) )
return; return;
ViewModel.AddCultureCommand_ExecuteCommand(); ViewModel.AddCultureCommand_ExecuteCommand();
if (string.IsNullOrWhiteSpace(ViewModel.ModInfo.ID))
return;
if ( if (
ModInfoModel.Current.I18nResource.CultureDatas.HasValue() is false ModInfoModel.Current.I18nResource.Cultures.HasValue() is false
|| MessageBox.Show( || MessageBox.Show(
"需要将文化 {0} 设为主要文化吗?".Translate( "需要将文化 {0} 设为主要文化吗?".Translate(
ModInfoModel.Current.I18nResource.Cultures.First().Name ModInfoModel.Current.I18nResource.Cultures.First().Name

View File

@ -27,8 +27,8 @@ public partial class PetEditWindow : Window
public PetEditWindow() public PetEditWindow()
{ {
DataContext = new PetEditWindowVM();
InitializeComponent(); InitializeComponent();
DataContext = new PetEditWindowVM();
Closed += (s, e) => Closed += (s, e) =>
{ {
ViewModel.Close(); ViewModel.Close();

View File

@ -28,10 +28,7 @@ public partial class WorkEditWindow : Window
public WorkEditWindow() public WorkEditWindow()
{ {
InitializeComponent(); InitializeComponent();
this.SetDataContext<WorkEditWindowVM>(() => { this.SetDataContext<WorkEditWindowVM>();
//TODO
//ViewModel.Close();
});
} }
private void Button_Cancel_Click(object? sender, RoutedEventArgs e) private void Button_Cancel_Click(object? sender, RoutedEventArgs e)
@ -41,15 +38,15 @@ public partial class WorkEditWindow : Window
private void Button_Yes_Click(object? sender, RoutedEventArgs e) private void Button_Yes_Click(object? sender, RoutedEventArgs e)
{ {
if (string.IsNullOrEmpty(ViewModel.Work.ID)) if (string.IsNullOrWhiteSpace(ViewModel.Work.ID))
{ {
MessageBox.Show("Id不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); MessageBox.Show("ID不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning);
return; return;
} }
if (string.IsNullOrEmpty(ViewModel.Work.Graph)) if (string.IsNullOrWhiteSpace(ViewModel.Work.Graph))
{ {
MessageBox.Show( MessageBox.Show(
"指定动画Id不可为空".Translate(), "指定动画ID不可为空".Translate(),
"", "",
MessageBoxButton.OK, MessageBoxButton.OK,
MessageBoxImage.Warning MessageBoxImage.Warning
@ -61,7 +58,7 @@ public partial class WorkEditWindow : Window
&& ViewModel.CurrentPet.Works.Any(i => i.ID == ViewModel.Work.ID) && ViewModel.CurrentPet.Works.Any(i => i.ID == ViewModel.Work.ID)
) )
{ {
MessageBox.Show("此Id已存在".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); MessageBox.Show("此ID已存在".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning);
return; return;
} }
IsCancel = false; IsCancel = false;

View File

@ -84,7 +84,7 @@ public partial class ModMakerWindow : WindowX
if ( if (
MessageBoxX.Show( MessageBoxX.Show(
this, this,
"无法正确打开链接,需要复制自行访问吗".Translate(), "无法打开链接,需要复制自行访问吗".Translate(),
"", "",
MessageBoxButton.YesNo, MessageBoxButton.YesNo,
MessageBoxIcon.Warning MessageBoxIcon.Warning