This commit is contained in:
Hakoyu 2024-03-28 23:15:42 +08:00
parent ce416a004c
commit 75951b92d6
49 changed files with 949 additions and 1203 deletions

View File

@ -38,48 +38,5 @@ public class I18nHelper : ObservableObjectX<I18nHelper>
/// <summary> /// <summary>
/// 文化列表 /// 文化列表
/// </summary> /// </summary>
public ObservableCollection<string> CultureNames { get; } = new(); public ObservableList<string> CultureNames { get; } = new();
public I18nHelper()
{
CultureNames.CollectionChanged += Cultures_CollectionChanged;
}
private void Cultures_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
// 替换
if (e.NewStartingIndex == e.OldStartingIndex)
{
ReplaceCulture?.Invoke((string)e.OldItems[0], (string)e.NewItems[0]);
return;
}
// 删除
if (e.OldItems is not null)
{
RemoveCulture?.Invoke((string)e.OldItems[0]);
}
// 新增
if (e.NewItems is not null)
{
AddCulture?.Invoke((string)e.NewItems[0]);
}
}
/// <summary>
/// 添加文化事件
/// </summary>
public event CultureEventHandler AddCulture;
/// <summary>
/// 删除文化事件
/// </summary>
public event CultureEventHandler RemoveCulture;
/// <summary>
/// 修改文化事件
/// </summary>
public event ReplaceCultureEventHandler ReplaceCulture;
public delegate void CultureEventHandler(string culture);
public delegate void ReplaceCultureEventHandler(string oldCulture, string newCulture);
} }

View File

@ -4,7 +4,9 @@ using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using HKW.HKWUtils.Extensions;
using HKW.HKWUtils.Observable; using HKW.HKWUtils.Observable;
using Mapster;
namespace VPet.ModMaker.Models; namespace VPet.ModMaker.Models;
@ -22,6 +24,7 @@ public class I18nModel<T> : ObservableObjectX<I18nModel<T>>
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private T _currentI18nData; private T _currentI18nData;
[AdaptIgnore]
public T CurrentI18nData public T CurrentI18nData
{ {
get => _currentI18nData; get => _currentI18nData;
@ -32,65 +35,63 @@ public class I18nModel<T> : ObservableObjectX<I18nModel<T>>
/// <summary> /// <summary>
/// 所有I18n数据 /// 所有I18n数据
/// </summary> /// </summary>
[AdaptIgnore]
public Dictionary<string, T> I18nDatas { get; } = new(); public Dictionary<string, T> I18nDatas { get; } = new();
public I18nModel() public I18nModel()
{ {
//TODO I18nHelper.Current.PropertyChangedX += Current_PropertyChangedX;
//I18nHelper.Current.CultureName.ValueChanged += CultureChanged; I18nHelper.Current.CultureNames.ListChanged += CultureNames_ListChanged;
I18nHelper.Current.AddCulture += AddCulture; if (I18nHelper.Current.CultureNames.HasValue() is false)
I18nHelper.Current.RemoveCulture += RemoveCulture;
I18nHelper.Current.ReplaceCulture += ReplaceCulture;
if (I18nHelper.Current.CultureNames.Count == 0)
return; return;
foreach (var item in I18nHelper.Current.CultureNames) foreach (var item in I18nHelper.Current.CultureNames)
{
I18nDatas.Add(item, new()); I18nDatas.Add(item, new());
}
CurrentI18nData = I18nDatas[I18nHelper.Current.CultureName]; CurrentI18nData = I18nDatas[I18nHelper.Current.CultureName];
} }
private void CultureNames_ListChanged(
IObservableList<string> sender,
NotifyListChangedEventArgs<string> e
)
{
if (e.Action is ListChangeAction.Add && e.NewItems is not null)
{
foreach (var item in e.NewItems)
I18nDatas.TryAdd(item, new());
}
else if (e.Action is ListChangeAction.Remove && e.OldItems is not null)
{
foreach (var item in e.OldItems)
I18nDatas.Remove(item);
}
else if (
e.Action is ListChangeAction.Add
&& e.NewItems is not null
&& e.OldItems is not null
)
{
var newItem = e.NewItems.First();
var oldItem = e.OldItems.First();
if (I18nDatas.ContainsKey(oldItem) is false)
return;
I18nDatas[newItem] = I18nDatas[oldItem];
I18nDatas.Remove(oldItem);
}
}
/// <summary> /// <summary>
/// 文化改变 /// 文化改变
/// </summary> /// </summary>
/// <param name="oldValue"></param> /// <param name="sender"></param>
/// <param name="newValue"></param> /// <param name="e"></param>
private void CultureChanged(ObservableValue<string> sender, ValueChangedEventArgs<string> e) private void Current_PropertyChangedX(I18nHelper sender, PropertyChangedXEventArgs e)
{ {
if (e.NewValue is null) if (e.PropertyName == nameof(I18nHelper.CultureName))
CurrentI18nData = null; {
else if (I18nDatas.TryGetValue(e.NewValue, out var result)) if (e.NewValue is null)
CurrentI18nData = result; CurrentI18nData = null!;
} else if (I18nDatas.TryGetValue((string)e.NewValue, out var result))
CurrentI18nData = result;
/// <summary> }
/// 添加文化
/// </summary>
/// <param name="culture">文化名称</param>
private void AddCulture(string culture)
{
if (I18nDatas.ContainsKey(culture) is false)
I18nDatas.Add(culture, new());
}
/// <summary>
/// 删除文化
/// </summary>
/// <param name="culture">文化名称</param>
private void RemoveCulture(string culture)
{
I18nDatas.Remove(culture);
}
/// <summary>
/// 替换文化
/// </summary>
/// <param name="oldCulture">旧文化名称</param>
/// <param name="newCulture">新文化名称</param>
private void ReplaceCulture(string oldCulture, string newCulture)
{
var item = I18nDatas[oldCulture];
I18nDatas.Remove(oldCulture);
I18nDatas.Add(newCulture, item);
} }
} }

View File

@ -1,90 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HKW.HKWUtils.Observable;
namespace VPet.ModMaker.Models;
/// <summary>
/// I18n模型
/// </summary>
/// <typeparam name="T">类型</typeparam>
public class I18nModelBase<T> : ObservableObjectX<I18nModelBase<T>>
where T : class, new()
{
/// <summary>
/// 当前I18n数据
/// </summary>
#region CurrentI18nData
private T _currentI18nData = new();
public T CurrentI18nData
{
get => _currentI18nData;
set => SetProperty(ref _currentI18nData, value);
}
#endregion
/// <summary>
/// 所有I18n数据
/// </summary>
public Dictionary<string, T> I18nDatas { get; } = new();
public I18nModelBase()
{
//TODO
//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];
}
/// <summary>
/// 文化改变
/// </summary>
/// <param name="oldValue"></param>
/// <param name="newValue"></param>
private void CultureChanged(ObservableValue<string> sender, ValueChangedEventArgs<string> e)
{
if (e.NewValue is null)
CurrentI18nData = null;
else if (I18nDatas.TryGetValue(e.NewValue, out var result))
CurrentI18nData = result;
}
/// <summary>
/// 添加文化
/// </summary>
/// <param name="culture">文化名称</param>
private void AddCulture(string culture)
{
if (I18nDatas.ContainsKey(culture) is false)
I18nDatas.Add(culture, new());
}
/// <summary>
/// 删除文化
/// </summary>
/// <param name="culture">文化名称</param>
private void RemoveCulture(string culture)
{
I18nDatas.Remove(culture);
}
/// <summary>
/// 替换文化
/// </summary>
/// <param name="oldCulture">旧文化名称</param>
/// <param name="newCulture">新文化名称</param>
private void ReplaceCulture(string oldCulture, string newCulture)
{
var item = I18nDatas[oldCulture];
I18nDatas.Remove(oldCulture);
I18nDatas.Add(newCulture, item);
}
}

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Frozen;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
@ -8,6 +9,7 @@ using System.Threading.Tasks;
using HKW.HKWUtils; using HKW.HKWUtils;
using HKW.HKWUtils.Observable; using HKW.HKWUtils.Observable;
using LinePutScript.Converter; using LinePutScript.Converter;
using Mapster;
using VPet_Simulator.Windows.Interface; using VPet_Simulator.Windows.Interface;
namespace VPet.ModMaker.Models; namespace VPet.ModMaker.Models;
@ -17,35 +19,102 @@ namespace VPet.ModMaker.Models;
/// </summary> /// </summary>
public class ClickTextModel : I18nModel<I18nClickTextModel> public class ClickTextModel : I18nModel<I18nClickTextModel>
{ {
public ClickTextModel() { }
public ClickTextModel(ClickTextModel clickText)
: this()
{
ID = clickText.ID;
Mode.Value = clickText.Mode.Value;
Working = clickText.Working;
WorkingState = clickText.WorkingState;
DayTime.Value = clickText.DayTime.Value;
Like = clickText.Like.Clone();
Health = clickText.Health.Clone();
Level = clickText.Level.Clone();
Money = clickText.Money.Clone();
Food = clickText.Food.Clone();
Drink = clickText.Drink.Clone();
Feel = clickText.Feel.Clone();
Strength = clickText.Strength.Clone();
foreach (var item in clickText.I18nDatas)
I18nDatas[item.Key] = item.Value.Clone();
CurrentI18nData = I18nDatas[I18nHelper.Current.CultureName];
}
public ClickTextModel(ClickText clickText)
: this()
{
ID = clickText.Text;
Mode.Value = clickText.Mode;
Working = clickText.Working;
WorkingState = clickText.State;
DayTime.Value = clickText.DaiTime;
Like = new(clickText.LikeMin, clickText.LikeMax);
Health = new(clickText.HealthMin, clickText.HealthMax);
Level = new(clickText.LevelMin, clickText.LevelMax);
Money = new(clickText.MoneyMin, clickText.MoneyMax);
Food = new(clickText.FoodMin, clickText.FoodMax);
Drink = new(clickText.DrinkMin, clickText.DrinkMax);
Feel = new(clickText.FeelMin, clickText.FeelMax);
Strength = new(clickText.StrengthMin, clickText.StrengthMax);
}
public ClickText ToClickText()
{
return new()
{
Text = ID,
Mode = Mode.Value,
Working = Working,
State = WorkingState,
DaiTime = DayTime.Value,
LikeMax = Like.Max,
LikeMin = Like.Min,
HealthMin = Health.Min,
HealthMax = Health.Max,
LevelMin = Level.Min,
LevelMax = Level.Max,
MoneyMin = Money.Min,
MoneyMax = Money.Max,
FoodMin = Food.Min,
FoodMax = Food.Max,
DrinkMin = Drink.Min,
DrinkMax = Drink.Max,
FeelMin = Feel.Min,
FeelMax = Feel.Max,
StrengthMin = Strength.Min,
StrengthMax = Strength.Max,
};
}
/// <summary> /// <summary>
/// 模式类型 /// 模式类型
/// </summary> /// </summary>
public static ObservableCollection<ClickText.ModeType> ModeTypes { get; } = public static FrozenSet<ClickText.ModeType> ModeTypes { get; } =
new(Enum.GetValues(typeof(ClickText.ModeType)).Cast<ClickText.ModeType>()); Enum.GetValues<ClickText.ModeType>().ToFrozenSet();
/// <summary> /// <summary>
/// 日期区间 /// 日期区间
/// </summary> /// </summary>
public static ObservableCollection<ClickText.DayTime> DayTimes { get; } = public static FrozenSet<ClickText.DayTime> DayTimes { get; } =
new(Enum.GetValues(typeof(ClickText.DayTime)).Cast<ClickText.DayTime>()); Enum.GetValues<ClickText.DayTime>().ToFrozenSet();
/// <summary> /// <summary>
/// 工作状态 /// 工作状态
/// </summary> /// </summary>
public static ObservableCollection<VPet_Simulator.Core.Main.WorkingState> WorkingStates { get; } = public static FrozenSet<VPet_Simulator.Core.Main.WorkingState> WorkingStates { get; } =
new( Enum.GetValues<VPet_Simulator.Core.Main.WorkingState>().ToFrozenSet();
Enum.GetValues(typeof(VPet_Simulator.Core.Main.WorkingState))
.Cast<VPet_Simulator.Core.Main.WorkingState>()
);
#region Id #region ID
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _id = string.Empty; private string _id = string.Empty;
/// <summary> /// <summary>
/// Id /// ID
/// </summary> /// </summary>
public string Id [AdaptMember(nameof(ClickText.Text))]
public string ID
{ {
get => _id; get => _id;
set => SetProperty(ref _id, value); set => SetProperty(ref _id, value);
@ -59,6 +128,7 @@ public class ClickTextModel : I18nModel<I18nClickTextModel>
/// <summary> /// <summary>
/// 指定工作 /// 指定工作
/// </summary> /// </summary>
[AdaptMember(nameof(ClickText.Working))]
public string Working public string Working
{ {
get => _working; get => _working;
@ -79,21 +149,23 @@ public class ClickTextModel : I18nModel<I18nClickTextModel>
#region WorkingState #region WorkingState
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private VPet_Simulator.Core.Main.WorkingState _WorkingState; private VPet_Simulator.Core.Main.WorkingState _workingState;
/// <summary> /// <summary>
/// 行动状态 /// 行动状态
/// </summary> /// </summary>
[AdaptMember(nameof(ClickText.State))]
public VPet_Simulator.Core.Main.WorkingState WorkingState public VPet_Simulator.Core.Main.WorkingState WorkingState
{ {
get => _WorkingState; get => _workingState;
set => SetProperty(ref _WorkingState, value); set => SetProperty(ref _workingState, value);
} }
#endregion #endregion
/// <summary> /// <summary>
/// 日期区间 /// 日期区间
/// </summary> /// </summary>
public ObservableEnumCommand<ClickText.DayTime> DayTime { get; } = public ObservableEnumCommand<ClickText.DayTime> DayTime { get; } =
new( new(
ClickText.DayTime.Morning ClickText.DayTime.Morning
@ -141,78 +213,11 @@ public class ClickTextModel : I18nModel<I18nClickTextModel>
/// 体力 /// 体力
/// </summary> /// </summary>
public ObservableRange<double> Strength { get; } = new(0, int.MaxValue); public ObservableRange<double> Strength { get; } = new(0, int.MaxValue);
public ClickTextModel() { }
public ClickTextModel(ClickTextModel clickText)
: this()
{
Id = clickText.Id;
Mode.Value = clickText.Mode.Value;
Working = clickText.Working;
WorkingState = clickText.WorkingState;
DayTime.Value = clickText.DayTime.Value;
Like = clickText.Like.Clone();
Health = clickText.Health.Clone();
Level = clickText.Level.Clone();
Money = clickText.Money.Clone();
Food = clickText.Food.Clone();
Drink = clickText.Drink.Clone();
Feel = clickText.Feel.Clone();
Strength = clickText.Strength.Clone();
foreach (var item in clickText.I18nDatas)
I18nDatas[item.Key] = item.Value.Copy();
CurrentI18nData = I18nDatas[I18nHelper.Current.CultureName];
}
public ClickTextModel(ClickText clickText)
: this()
{
Id = clickText.Text;
Mode.Value = clickText.Mode;
Working = clickText.Working;
WorkingState = clickText.State;
DayTime.Value = clickText.DaiTime;
Like = new(clickText.LikeMin, clickText.LikeMax);
Health = new(clickText.HealthMin, clickText.HealthMax);
Level = new(clickText.LevelMin, clickText.LevelMax);
Money = new(clickText.MoneyMin, clickText.MoneyMax);
Food = new(clickText.FoodMin, clickText.FoodMax);
Drink = new(clickText.DrinkMin, clickText.DrinkMax);
Feel = new(clickText.FeelMin, clickText.FeelMax);
Strength = new(clickText.StrengthMin, clickText.StrengthMax);
}
public ClickText ToClickText()
{
return new()
{
Text = Id,
Mode = Mode.Value,
Working = Working,
State = WorkingState,
DaiTime = DayTime.Value,
LikeMax = Like.Max,
LikeMin = Like.Min,
HealthMin = Health.Min,
HealthMax = Health.Max,
LevelMin = Level.Min,
LevelMax = Level.Max,
MoneyMin = Money.Min,
MoneyMax = Money.Max,
FoodMin = Food.Min,
FoodMax = Food.Max,
DrinkMin = Drink.Min,
DrinkMax = Drink.Max,
FeelMin = Feel.Min,
FeelMax = Feel.Max,
StrengthMin = Strength.Min,
StrengthMax = Strength.Max,
};
}
} }
public class I18nClickTextModel : ObservableObjectX<I18nClickTextModel> public class I18nClickTextModel
: ObservableObjectX<I18nClickTextModel>,
ICloneable<I18nClickTextModel>
{ {
#region Text #region Text
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
@ -225,10 +230,10 @@ public class I18nClickTextModel : ObservableObjectX<I18nClickTextModel>
} }
#endregion #endregion
public I18nClickTextModel Copy() public I18nClickTextModel Clone()
{ {
var result = new I18nClickTextModel(); return this.Adapt<I18nClickTextModel>();
result.Text = Text;
return result;
} }
object ICloneable.Clone() => Clone();
} }

View File

@ -9,9 +9,9 @@ using HKW.HKWUtils.Observable;
namespace VPet.ModMaker.Models.ModModel; namespace VPet.ModMaker.Models.ModModel;
/// <summary> /// <summary>
/// 食物图像模型 /// 食物图像位置模型
/// </summary> /// </summary>
public class FoodLocationModel : ObservableObjectX<FoodLocationModel> public class FoodAnimeLocationModel : ObservableObjectX<FoodAnimeLocationModel>
{ {
#region Duration #region Duration
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
@ -60,7 +60,7 @@ public class FoodLocationModel : ObservableObjectX<FoodLocationModel>
} }
#endregion #endregion
public FoodLocationModel() public FoodAnimeLocationModel()
{ {
Rect.PropertyChangedX += (s, e) => Rect.PropertyChangedX += (s, e) =>
{ {
@ -68,9 +68,9 @@ public class FoodLocationModel : ObservableObjectX<FoodLocationModel>
}; };
} }
public FoodLocationModel Copy() public FoodAnimeLocationModel Copy()
{ {
var model = new FoodLocationModel(); var model = new FoodAnimeLocationModel();
model.Duration = Duration; model.Duration = Duration;
model.Rect = new(Rect.X, Rect.Y, Rect.Width, Rect.Height); model.Rect = new(Rect.X, Rect.Y, Rect.Width, Rect.Height);
model.Rotate = Rotate; model.Rotate = Rotate;

View File

@ -41,7 +41,7 @@ public class FoodAnimeModel : ObservableObjectX<FoodAnimeModel>
/// <summary> /// <summary>
/// 食物定位列表 /// 食物定位列表
/// </summary> /// </summary>
public ObservableCollection<FoodLocationModel> FoodLocations { get; } = new(); public ObservableCollection<FoodAnimeLocationModel> FoodLocations { get; } = new();
public FoodAnimeModel() { } public FoodAnimeModel() { }
@ -52,7 +52,7 @@ public class FoodAnimeModel : ObservableObjectX<FoodAnimeModel>
{ {
//var index = int.Parse(item.Name.Substring(1)); //var index = int.Parse(item.Name.Substring(1));
var infos = item.Info.Split(','); var infos = item.Info.Split(',');
var foodLocationInfo = new FoodLocationModel(); var foodLocationInfo = new FoodAnimeLocationModel();
foodLocationInfo.Duration = int.Parse(infos[0]); foodLocationInfo.Duration = int.Parse(infos[0]);
if (infos.Length > 1) if (infos.Length > 1)
{ {

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Frozen;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
@ -7,9 +8,12 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using CommunityToolkit.Mvvm.Collections;
using CommunityToolkit.Mvvm.ComponentModel;
using HKW.HKWUtils.Observable; using HKW.HKWUtils.Observable;
using LinePutScript; using LinePutScript;
using LinePutScript.Converter; using LinePutScript.Converter;
using Mapster;
using VPet_Simulator.Windows.Interface; using VPet_Simulator.Windows.Interface;
namespace VPet.ModMaker.Models; namespace VPet.ModMaker.Models;
@ -19,210 +23,9 @@ namespace VPet.ModMaker.Models;
/// </summary> /// </summary>
public class FoodModel : I18nModel<I18nFoodModel> public class FoodModel : I18nModel<I18nFoodModel>
{ {
/// <summary>
/// 食物类型
/// </summary>
public static ObservableCollection<Food.FoodType> FoodTypes { get; } =
new(Enum.GetValues(typeof(Food.FoodType)).Cast<Food.FoodType>());
#region Id
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _id = string.Empty;
/// <summary>
/// Id
/// </summary>
public string Id
{
get => _id;
set => SetProperty(ref _id, value);
}
#endregion
#region DescriptionId
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _descriptionId = string.Empty;
/// <summary>
/// 详情Id
/// </summary>
public string DescriptionId
{
get => _descriptionId;
set => SetProperty(ref _descriptionId, value);
}
#endregion
#region Graph
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _graph = string.Empty;
/// <summary>
/// 指定动画
/// </summary>
public string Graph
{
get => _graph;
set => SetProperty(ref _graph, value);
}
#endregion
#region Type
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private Food.FoodType _type;
/// <summary>
/// 类型
/// </summary>
public Food.FoodType Type
{
get => _type;
set => SetProperty(ref _type, value);
}
#endregion
/// <summary>
/// 体力
/// </summary>
#region Strength
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double _Strength;
public double Strength
{
get => _Strength;
set => SetProperty(ref _Strength, value);
}
#endregion
/// <summary>
/// 饱食度
/// </summary>
#region StrengthFood
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double _StrengthFood;
public double StrengthFood
{
get => _StrengthFood;
set => SetProperty(ref _StrengthFood, value);
}
#endregion
/// <summary>
/// 口渴度
/// </summary>
#region StrengthDrink
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double _StrengthDrink;
public double StrengthDrink
{
get => _StrengthDrink;
set => SetProperty(ref _StrengthDrink, value);
}
#endregion
/// <summary>
/// 心情
/// </summary>
#region Feeling
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double _Feeling;
public double Feeling
{
get => _Feeling;
set => SetProperty(ref _Feeling, value);
}
#endregion
/// <summary>
/// 健康度
/// </summary>
#region Health
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double _Health;
public double Health
{
get => _Health;
set => SetProperty(ref _Health, value);
}
#endregion
/// <summary>
/// 好感度
/// </summary>
#region Likability
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double _Likability;
public double Likability
{
get => _Likability;
set => SetProperty(ref _Likability, value);
}
#endregion
/// <summary>
/// 价格
/// </summary>
#region Price
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double _Price;
public double Price
{
get => _Price;
set => SetProperty(ref _Price, value);
}
#endregion
/// <summary>
/// 经验
/// </summary>
#region Exp
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private int _Exp;
public int Exp
{
get => _Exp;
set => SetProperty(ref _Exp, value);
}
#endregion
/// <summary>
/// 图片
/// </summary>
#region Image
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private BitmapImage _Image;
public BitmapImage Image
{
get => _Image;
set => SetProperty(ref _Image, value);
}
#endregion
#region ReferencePrice
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double _ReferencePrice;
public double ReferencePrice
{
get => _ReferencePrice;
set => SetProperty(ref _ReferencePrice, value);
}
#endregion
private readonly Food _food = new();
public FoodModel() public FoodModel()
{ {
DescriptionId = $"{Id}_{nameof(DescriptionId)}"; //DescriptionId = $"{Id}_{nameof(DescriptionId)}";
//TODO //TODO
//Id.ValueChanged += (s, e) => //Id.ValueChanged += (s, e) =>
//{ //{
@ -241,91 +44,310 @@ public class FoodModel : I18nModel<I18nFoodModel>
//{ //{
// s.Value = Math.Floor(SetValueToFood(_food).RealPrice); // s.Value = Math.Floor(SetValueToFood(_food).RealPrice);
//}; //};
PropertyChangedX += FoodModel_PropertyChangedX;
}
private static FrozenSet<string> _notifyReferencePrice = FrozenSet.ToFrozenSet(
[
nameof(Strength),
nameof(StrengthFood),
nameof(StrengthDrink),
nameof(Feeling),
nameof(Health),
nameof(Likability),
nameof(Exp)
]
);
private void FoodModel_PropertyChangedX(
I18nModel<I18nFoodModel> sender,
PropertyChangedXEventArgs e
)
{
if (e.PropertyName == nameof(ID))
{
DescriptionID = $"{e.NewValue}_{nameof(DescriptionID)}";
}
else if (_notifyReferencePrice.Contains(e.PropertyName))
{
this.Adapt(_food);
ReferencePrice = Math.Floor(_food.RealPrice);
}
} }
public FoodModel(FoodModel model) public FoodModel(FoodModel model)
: this() : this()
{ {
Id = model.Id; model.Adapt(this);
DescriptionId = model.DescriptionId; Image = model.Image?.CloneStream();
Graph = model.Graph;
Type = model.Type;
Strength = model.Strength;
StrengthFood = model.StrengthFood;
StrengthDrink = model.StrengthDrink;
Feeling = model.Feeling;
Health = model.Health;
Likability = model.Likability;
Price = model.Price;
Exp = model.Exp;
Image = model.Image.Copy();
foreach (var item in model.I18nDatas) foreach (var item in model.I18nDatas)
I18nDatas[item.Key] = item.Value.Copy(); I18nDatas[item.Key] = item.Value.Clone();
CurrentI18nData = I18nDatas[I18nHelper.Current.CultureName]; CurrentI18nData = I18nDatas[I18nHelper.Current.CultureName];
} }
public FoodModel(Food food) public FoodModel(Food food)
: this() : this()
{ {
Id = food.Name; food.Adapt(this);
DescriptionId = food.Desc;
Graph = food.Graph;
Type = food.Type;
Strength = food.Strength;
StrengthDrink = food.StrengthDrink;
StrengthFood = food.StrengthFood;
Feeling = food.Feeling;
Health = food.Health;
Likability = food.Likability;
Price = food.Price;
Exp = food.Exp;
if (File.Exists(food.Image)) if (File.Exists(food.Image))
Image = NativeUtils.LoadImageToMemoryStream(food.Image); Image = NativeUtils.LoadImageToMemoryStream(food.Image);
} }
/// <summary>
/// 食物类型
/// </summary>
public static ObservableCollection<Food.FoodType> FoodTypes { get; } =
new(Enum.GetValues(typeof(Food.FoodType)).Cast<Food.FoodType>());
#region ID
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _id = string.Empty;
/// <summary>
/// ID
/// </summary>
[AdaptMember(nameof(Food.Name))]
public string ID
{
get => _id;
set
{
if (SetProperty(ref _id, value) is false)
return;
DescriptionID = $"{ID}_{nameof(DescriptionID)}";
}
}
#endregion
#region DescriptionID
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _descriptionID = string.Empty;
/// <summary>
/// 详情Id
/// </summary>
[AdaptMember(nameof(Food.Desc))]
public string DescriptionID
{
get => _descriptionID;
set => SetProperty(ref _descriptionID, value);
}
#endregion
#region Graph
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _graph = string.Empty;
/// <summary>
/// 指定动画
/// </summary>
[AdaptMember(nameof(Food.Graph))]
public string Graph
{
get => _graph;
set => SetProperty(ref _graph, value);
}
#endregion
#region Type
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private Food.FoodType _type;
/// <summary>
/// 类型
/// </summary>
[AdaptMember(nameof(Food.Type))]
public Food.FoodType Type
{
get => _type;
set => SetProperty(ref _type, value);
}
#endregion
#region Strength
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double _strength;
/// <summary>
/// 体力
/// </summary>
[AdaptMember(nameof(Food.Strength))]
public double Strength
{
get => _strength;
set => SetProperty(ref _strength, value);
}
#endregion
#region StrengthFood
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double _strengthFood;
/// <summary>
/// 饱食度
/// </summary>
[AdaptMember(nameof(Food.StrengthFood))]
public double StrengthFood
{
get => _strengthFood;
set => SetProperty(ref _strengthFood, value);
}
#endregion
#region StrengthDrink
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double _strengthDrink;
/// <summary>
/// 口渴度
/// </summary>
[AdaptMember(nameof(Food.StrengthDrink))]
public double StrengthDrink
{
get => _strengthDrink;
set => SetProperty(ref _strengthDrink, value);
}
#endregion
#region Feeling
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double _feeling;
/// <summary>
/// 心情
/// </summary>
[AdaptMember(nameof(Food.Feeling))]
public double Feeling
{
get => _feeling;
set => SetProperty(ref _feeling, value);
}
#endregion
#region Health
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double _health;
/// <summary>
/// 健康度
/// </summary>
[AdaptMember(nameof(Food.Health))]
public double Health
{
get => _health;
set => SetProperty(ref _health, value);
}
#endregion
#region Likability
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double _likability;
/// <summary>
/// 好感度
/// </summary>
[AdaptMember(nameof(Food.Likability))]
public double Likability
{
get => _likability;
set => SetProperty(ref _likability, value);
}
#endregion
#region Price
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double _price;
/// <summary>
/// 价格
/// </summary>
[AdaptMember(nameof(Food.Price))]
public double Price
{
get => _price;
set => SetProperty(ref _price, value);
}
#endregion
#region Exp
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private int _exp;
/// <summary>
/// 经验
/// </summary>
[AdaptMember(nameof(Food.Exp))]
public int Exp
{
get => _exp;
set => SetProperty(ref _exp, value);
}
#endregion
#region Image
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private BitmapImage? _image;
/// <summary>
/// 图片
/// </summary>
[AdaptIgnore]
public BitmapImage? Image
{
get => _image;
set => SetProperty(ref _image, value);
}
#endregion
#region ReferencePrice
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private double _ReferencePrice;
/// <summary>
/// 推荐价格
/// </summary>
[AdaptIgnore]
public double ReferencePrice
{
get => _ReferencePrice;
set => SetProperty(ref _ReferencePrice, value);
}
#endregion
private readonly Food _food = new();
public Food ToFood() public Food ToFood()
{ {
return new Food() return this.Adapt<Food>();
{ //return new Food()
Name = Id, //{
Desc = DescriptionId, // Name = ID,
Graph = Graph, // Desc = DescriptionID,
Type = Type, // Graph = Graph,
Strength = Strength, // Type = Type,
StrengthFood = StrengthFood, // Strength = Strength,
StrengthDrink = StrengthDrink, // StrengthFood = StrengthFood,
Feeling = Feeling, // StrengthDrink = StrengthDrink,
Health = Health, // Feeling = Feeling,
Likability = Likability, // Health = Health,
Price = Price, // Likability = Likability,
Exp = Exp, // Price = Price,
}; // Exp = Exp,
} //};
public Food SetValueToFood(Food food)
{
food.Strength = Strength;
food.StrengthFood = StrengthFood;
food.StrengthDrink = StrengthDrink;
food.Feeling = Feeling;
food.Health = Health;
food.Likability = Likability;
food.Exp = Exp;
return food;
} }
public void RefreshId() public void RefreshId()
{ {
DescriptionId = $"{Id}_{nameof(DescriptionId)}"; DescriptionID = $"{ID}_{nameof(DescriptionID)}";
} }
public void Close() public void Close()
{ {
Image.CloseStream(); Image?.CloseStream();
} }
} }
public class I18nFoodModel : ObservableObjectX<I18nFoodModel> public class I18nFoodModel : ObservableObjectX<I18nFoodModel>, ICloneable<I18nFoodModel>
{ {
#region Name #region Name
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
@ -337,6 +359,7 @@ public class I18nFoodModel : ObservableObjectX<I18nFoodModel>
set => SetProperty(ref _name, value); set => SetProperty(ref _name, value);
} }
#endregion #endregion
#region Description #region Description
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _description = string.Empty; private string _description = string.Empty;
@ -348,11 +371,7 @@ public class I18nFoodModel : ObservableObjectX<I18nFoodModel>
} }
#endregion #endregion
public I18nFoodModel Copy() public I18nFoodModel Clone() => this.Adapt<I18nFoodModel>();
{
var result = new I18nFoodModel(); object ICloneable.Clone() => Clone();
result.Name = Name;
result.Description = Description;
return result;
}
} }

View File

@ -51,7 +51,7 @@ public class ImageModel : ObservableObjectX<ImageModel>
public ImageModel Copy() public ImageModel Copy()
{ {
var model = new ImageModel(Image.Copy(), Duration); var model = new ImageModel(Image.CloneStream(), Duration);
return model; return model;
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Frozen;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
@ -7,6 +8,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Serialization; using System.Xml.Serialization;
using HKW.HKWUtils.Observable; using HKW.HKWUtils.Observable;
using Mapster;
using VPet_Simulator.Windows.Interface; using VPet_Simulator.Windows.Interface;
namespace VPet.ModMaker.Models; namespace VPet.ModMaker.Models;
@ -16,32 +18,51 @@ namespace VPet.ModMaker.Models;
/// </summary> /// </summary>
public class LowTextModel : I18nModel<I18nLowTextModel> public class LowTextModel : I18nModel<I18nLowTextModel>
{ {
public LowTextModel() { }
public LowTextModel(LowTextModel lowText)
: this()
{
lowText.Adapt(this);
foreach (var item in lowText.I18nDatas)
I18nDatas[item.Key] = item.Value.Clone();
CurrentI18nData = I18nDatas[I18nHelper.Current.CultureName];
}
public LowTextModel(LowText lowText)
: this()
{
lowText.Adapt(this);
}
/// <summary> /// <summary>
/// 状态类型 /// 状态类型
/// </summary> /// </summary>
public static ObservableCollection<LowText.ModeType> ModeTypes { get; } = public static FrozenSet<LowText.ModeType> ModeTypes { get; } =
new(Enum.GetValues(typeof(LowText.ModeType)).Cast<LowText.ModeType>()); Enum.GetValues<LowText.ModeType>().ToFrozenSet();
/// <summary> /// <summary>
/// 好感度类型 /// 好感度类型
/// </summary> /// </summary>
public static ObservableCollection<LowText.LikeType> LikeTypes { get; } = public static FrozenSet<LowText.LikeType> LikeTypes { get; } =
new(Enum.GetValues(typeof(LowText.LikeType)).Cast<LowText.LikeType>()); Enum.GetValues<LowText.LikeType>().ToFrozenSet();
/// <summary> /// <summary>
/// 体力类型 /// 体力类型
/// </summary> /// </summary>
public static ObservableCollection<LowText.StrengthType> StrengthTypes { get; } = public static FrozenSet<LowText.StrengthType> StrengthTypes { get; } =
new(Enum.GetValues(typeof(LowText.StrengthType)).Cast<LowText.StrengthType>()); 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;
/// <summary> /// <summary>
/// Id /// ID
/// </summary> /// </summary>
public string Id [AdaptMember(nameof(LowText.Text))]
public string ID
{ {
get => _id; get => _id;
set => SetProperty(ref _id, value); set => SetProperty(ref _id, value);
@ -55,6 +76,7 @@ public class LowTextModel : I18nModel<I18nLowTextModel>
/// <summary> /// <summary>
/// 状态 /// 状态
/// </summary> /// </summary>
[AdaptMember(nameof(LowText.Mode))]
public LowText.ModeType Mode public LowText.ModeType Mode
{ {
get => _mode; get => _mode;
@ -69,6 +91,7 @@ public class LowTextModel : I18nModel<I18nLowTextModel>
/// <summary> /// <summary>
/// 体力 /// 体力
/// </summary> /// </summary>
[AdaptMember(nameof(LowText.Strength))]
public LowText.StrengthType Strength public LowText.StrengthType Strength
{ {
get => _strength; get => _strength;
@ -83,7 +106,7 @@ public class LowTextModel : I18nModel<I18nLowTextModel>
/// <summary> /// <summary>
/// 好感度 /// 好感度
/// </summary> /// </summary>
[AdaptMember(nameof(LowText.Like))]
public LowText.LikeType Like public LowText.LikeType Like
{ {
get => _like; get => _like;
@ -91,45 +114,13 @@ public class LowTextModel : I18nModel<I18nLowTextModel>
} }
#endregion #endregion
public LowTextModel() { }
public LowTextModel(LowTextModel lowText)
: this()
{
Id = lowText.Id;
Mode = lowText.Mode;
Strength = lowText.Strength;
Like = lowText.Like;
foreach (var item in lowText.I18nDatas)
I18nDatas[item.Key] = item.Value.Copy();
CurrentI18nData = I18nDatas[I18nHelper.Current.CultureName];
}
public LowTextModel(LowText lowText)
: this()
{
Id = lowText.Text;
Mode = lowText.Mode;
Strength = lowText.Strength;
Like = lowText.Like;
}
public void Close() { }
public LowText ToLowText() public LowText ToLowText()
{ {
return new() return this.Adapt<LowText>();
{
Text = Id,
Mode = Mode,
Strength = Strength,
Like = Like,
};
} }
} }
public class I18nLowTextModel : ObservableObjectX<I18nLowTextModel> public class I18nLowTextModel : ObservableObjectX<I18nLowTextModel>, ICloneable<I18nLowTextModel>
{ {
#region Text #region Text
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
@ -142,10 +133,10 @@ public class I18nLowTextModel : ObservableObjectX<I18nLowTextModel>
} }
#endregion #endregion
public I18nLowTextModel Copy() public I18nLowTextModel Clone()
{ {
var result = new I18nLowTextModel(); return this.Adapt<I18nLowTextModel>();
result.Text = Text;
return result;
} }
object ICloneable.Clone() => Clone();
} }

View File

@ -450,9 +450,9 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
{ {
if (food.I18nDatas.TryGetValue(key, out var data) is false) if (food.I18nDatas.TryGetValue(key, out var data) is false)
continue; continue;
if (i18nData.TryGetValue(food.Id, out var name)) if (i18nData.TryGetValue(food.ID, out var name))
data.Name = name; data.Name = name;
if (i18nData.TryGetValue(food.DescriptionId, out var description)) if (i18nData.TryGetValue(food.DescriptionID, out var description))
data.Description = description; data.Description = description;
} }
} }
@ -463,7 +463,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
{ {
if (lowText.I18nDatas.TryGetValue(key, out var data) is false) if (lowText.I18nDatas.TryGetValue(key, out var data) is false)
continue; continue;
if (i18nData.TryGetValue(lowText.Id, out var text)) if (i18nData.TryGetValue(lowText.ID, out var text))
data.Text = text; data.Text = text;
} }
} }
@ -474,7 +474,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
{ {
if (clickText.I18nDatas.TryGetValue(key, out var data) is false) if (clickText.I18nDatas.TryGetValue(key, out var data) is false)
continue; continue;
if (i18nData.TryGetValue(clickText.Id, out var text)) if (i18nData.TryGetValue(clickText.ID, out var text))
data.Text = text; data.Text = text;
} }
} }
@ -485,9 +485,9 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
{ {
if (selectText.I18nDatas.TryGetValue(key, out var data) is false) if (selectText.I18nDatas.TryGetValue(key, out var data) is false)
continue; continue;
if (i18nData.TryGetValue(selectText.Id, out var text)) if (i18nData.TryGetValue(selectText.ID, out var text))
data.Text = text; data.Text = text;
if (i18nData.TryGetValue(selectText.ChooseId, out var choose)) if (i18nData.TryGetValue(selectText.ChooseID, out var choose))
data.Choose = choose; data.Choose = choose;
} }
} }
@ -519,7 +519,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
foreach (var food in Foods) foreach (var food in Foods)
food.RefreshId(); food.RefreshId();
foreach (var selectText in SelectTexts) foreach (var selectText in SelectTexts)
selectText.RefreshId(); selectText.RefreshID();
foreach (var pet in Pets) foreach (var pet in Pets)
pet.RefreshId(); pet.RefreshId();
} }
@ -635,9 +635,9 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
lps.Add(LPSConvert.SerializeObjectToLine<Line>(food.ToFood(), "food")); lps.Add(LPSConvert.SerializeObjectToLine<Line>(food.ToFood(), "food"));
foreach (var cultureName in I18nHelper.Current.CultureNames) foreach (var cultureName in I18nHelper.Current.CultureNames)
{ {
SaveI18nDatas[cultureName].TryAdd(food.Id, food.I18nDatas[cultureName].Name); SaveI18nDatas[cultureName].TryAdd(food.ID, food.I18nDatas[cultureName].Name);
SaveI18nDatas[cultureName] SaveI18nDatas[cultureName]
.TryAdd(food.DescriptionId, food.I18nDatas[cultureName].Description); .TryAdd(food.DescriptionID, food.I18nDatas[cultureName].Description);
} }
} }
File.WriteAllText(foodFile, lps.ToString()); File.WriteAllText(foodFile, lps.ToString());
@ -679,9 +679,9 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
lps.Add(LPSConvert.SerializeObjectToLine<Line>(text.ToSelectText(), "SelectText")); lps.Add(LPSConvert.SerializeObjectToLine<Line>(text.ToSelectText(), "SelectText"));
foreach (var cultureName in I18nHelper.Current.CultureNames) foreach (var cultureName in I18nHelper.Current.CultureNames)
{ {
SaveI18nDatas[cultureName].TryAdd(text.Id, text.I18nDatas[cultureName].Text); SaveI18nDatas[cultureName].TryAdd(text.ID, text.I18nDatas[cultureName].Text);
SaveI18nDatas[cultureName] SaveI18nDatas[cultureName]
.TryAdd(text.ChooseId, text.I18nDatas[cultureName].Choose); .TryAdd(text.ChooseID, text.I18nDatas[cultureName].Choose);
} }
} }
File.WriteAllText(textFile, lps.ToString()); File.WriteAllText(textFile, lps.ToString());
@ -703,7 +703,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
lps.Add(LPSConvert.SerializeObjectToLine<Line>(text.ToLowText(), "lowfoodtext")); lps.Add(LPSConvert.SerializeObjectToLine<Line>(text.ToLowText(), "lowfoodtext"));
foreach (var cultureName in I18nHelper.Current.CultureNames) foreach (var cultureName in I18nHelper.Current.CultureNames)
{ {
SaveI18nDatas[cultureName].TryAdd(text.Id, text.I18nDatas[cultureName].Text); SaveI18nDatas[cultureName].TryAdd(text.ID, text.I18nDatas[cultureName].Text);
} }
} }
File.WriteAllText(textFile, lps.ToString()); File.WriteAllText(textFile, lps.ToString());
@ -725,7 +725,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
lps.Add(LPSConvert.SerializeObjectToLine<Line>(text.ToClickText(), "clicktext")); lps.Add(LPSConvert.SerializeObjectToLine<Line>(text.ToClickText(), "clicktext"));
foreach (var cultureName in I18nHelper.Current.CultureNames) foreach (var cultureName in I18nHelper.Current.CultureNames)
{ {
SaveI18nDatas[cultureName].TryAdd(text.Id, text.I18nDatas[cultureName].Text); SaveI18nDatas[cultureName].TryAdd(text.ID, text.I18nDatas[cultureName].Text);
} }
} }
File.WriteAllText(textFile, lps.ToString()); File.WriteAllText(textFile, lps.ToString());
@ -768,7 +768,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
Directory.CreateDirectory(foodPath); Directory.CreateDirectory(foodPath);
foreach (var food in Foods) foreach (var food in Foods)
{ {
food.Image.SaveToPng(Path.Combine(foodPath, food.Id)); food.Image.SaveToPng(Path.Combine(foodPath, food.ID));
} }
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Frozen;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
@ -6,6 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using HKW.HKWUtils.Observable; using HKW.HKWUtils.Observable;
using Mapster;
using VPet.ModMaker.Models; using VPet.ModMaker.Models;
using VPet_Simulator.Windows.Interface; using VPet_Simulator.Windows.Interface;
@ -16,10 +18,53 @@ namespace VPet.ModMaker.Models;
/// </summary> /// </summary>
public class SelectTextModel : I18nModel<I18nSelectTextModel> public class SelectTextModel : I18nModel<I18nSelectTextModel>
{ {
public SelectTextModel() { }
public SelectTextModel(SelectTextModel model)
: this()
{
//model.Adapt(this);
//Like.Min = -100;
ID = model.ID;
Mode.Value = model.Mode.Value;
Tags = model.Tags;
ToTags = model.ToTags;
Like = model.Like.Clone();
Health = model.Health.Clone();
Level = model.Level.Clone();
Money = model.Money.Clone();
Food = model.Food.Clone();
Drink = model.Drink.Clone();
Feel = model.Feel.Clone();
Strength = model.Strength.Clone();
foreach (var item in model.I18nDatas)
I18nDatas[item.Key] = item.Value.Clone();
CurrentI18nData = I18nDatas[I18nHelper.Current.CultureName];
}
public SelectTextModel(SelectText text)
: this()
{
ID = text.Text;
ChooseID = text.Choose ?? string.Empty;
Mode.Value = text.Mode;
Tags = text.Tags is null ? string.Empty : string.Join(", ", text.Tags);
ToTags = text.ToTags is null ? string.Empty : string.Join(", ", text.ToTags);
Like = new(text.LikeMin, text.LikeMax);
Health = new(text.HealthMin, text.HealthMax);
Level = new(text.LevelMin, text.LevelMax);
Money = new(text.MoneyMin, text.MoneyMax);
Food = new(text.FoodMin, text.FoodMax);
Drink = new(text.DrinkMin, text.DrinkMax);
Feel = new(text.FeelMin, text.FeelMax);
Strength = new(text.StrengthMin, text.StrengthMax);
}
/// <summary> /// <summary>
/// 模式类型 /// 模式类型
/// </summary> /// </summary>
public static ObservableCollection<ClickText.ModeType> ModeTypes => ClickTextModel.ModeTypes; public static FrozenSet<ClickText.ModeType> ModeTypes => ClickTextModel.ModeTypes;
#region Tags #region Tags
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
@ -49,17 +94,21 @@ public class SelectTextModel : I18nModel<I18nSelectTextModel>
} }
#endregion #endregion
#region Id #region ID
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _id = string.Empty; private string _id = string.Empty;
/// <summary> /// <summary>
/// Id /// ID
/// </summary> /// </summary>
public string Id public string ID
{ {
get => _id; get => _id;
set => SetProperty(ref _id, value); set
{
SetProperty(ref _id, value);
RefreshID();
}
} }
#endregion #endregion
@ -71,7 +120,7 @@ public class SelectTextModel : I18nModel<I18nSelectTextModel>
/// 选择Id /// 选择Id
/// </summary> /// </summary>
public string ChooseId public string ChooseID
{ {
get => _chooseId; get => _chooseId;
set => SetProperty(ref _chooseId, value); set => SetProperty(ref _chooseId, value);
@ -129,68 +178,19 @@ public class SelectTextModel : I18nModel<I18nSelectTextModel>
/// </summary> /// </summary>
public ObservableRange<double> Strength { get; } = new(0, int.MaxValue); public ObservableRange<double> Strength { get; } = new(0, int.MaxValue);
public SelectTextModel() public void RefreshID()
{ {
ChooseId = $"{Id}_{nameof(ChooseId)}"; ChooseID = $"{ID}_{nameof(ChooseID)}";
//TODO
//Id.ValueChanged += (s, e) =>
//{
// ChooseId.Value = $"{e.NewValue}_{nameof(ChooseId)}";
//};
} }
public SelectTextModel(SelectTextModel model) private static readonly char[] rs_splitChar = [',', ' '];
: this()
{
Id = model.Id;
Mode.Value = model.Mode.Value;
Tags = model.Tags;
ToTags = model.ToTags;
Like = model.Like.Clone();
Health = model.Health.Clone();
Level = model.Level.Clone();
Money = model.Money.Clone();
Food = model.Food.Clone();
Drink = model.Drink.Clone();
Feel = model.Feel.Clone();
Strength = model.Strength.Clone();
foreach (var item in model.I18nDatas)
I18nDatas[item.Key] = item.Value.Copy();
CurrentI18nData = I18nDatas[I18nHelper.Current.CultureName];
}
public SelectTextModel(SelectText text)
: this()
{
Id = text.Text;
ChooseId = text.Choose ?? string.Empty;
Mode.Value = text.Mode;
Tags = text.Tags is null ? string.Empty : string.Join(", ", text.Tags);
ToTags = text.ToTags is null ? string.Empty : string.Join(", ", text.ToTags);
Like = new(text.LikeMin, text.LikeMax);
Health = new(text.HealthMin, text.HealthMax);
Level = new(text.LevelMin, text.LevelMax);
Money = new(text.MoneyMin, text.MoneyMax);
Food = new(text.FoodMin, text.FoodMax);
Drink = new(text.DrinkMin, text.DrinkMax);
Feel = new(text.FeelMin, text.FeelMax);
Strength = new(text.StrengthMin, text.StrengthMax);
}
public void RefreshId()
{
ChooseId = $"{Id}_{nameof(ChooseId)}";
}
private static readonly char[] rs_splitChar = { ',', ' ' };
public SelectText ToSelectText() public SelectText ToSelectText()
{ {
return new() return new()
{ {
Text = Id, Text = ID,
Choose = ChooseId, Choose = ChooseID,
Mode = Mode.Value, Mode = Mode.Value,
Tags = new(Tags.Split(rs_splitChar, StringSplitOptions.RemoveEmptyEntries)), Tags = new(Tags.Split(rs_splitChar, StringSplitOptions.RemoveEmptyEntries)),
ToTags = new(ToTags.Split(rs_splitChar, StringSplitOptions.RemoveEmptyEntries)), ToTags = new(ToTags.Split(rs_splitChar, StringSplitOptions.RemoveEmptyEntries)),
@ -214,7 +214,9 @@ public class SelectTextModel : I18nModel<I18nSelectTextModel>
} }
} }
public class I18nSelectTextModel : ObservableObjectX<I18nSelectTextModel> public class I18nSelectTextModel
: ObservableObjectX<I18nSelectTextModel>,
ICloneable<I18nSelectTextModel>
{ {
#region Choose #region Choose
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
@ -237,11 +239,10 @@ public class I18nSelectTextModel : ObservableObjectX<I18nSelectTextModel>
} }
#endregion #endregion
public I18nSelectTextModel Copy() public I18nSelectTextModel Clone()
{ {
var result = new I18nSelectTextModel(); return this.Adapt<I18nSelectTextModel>();
result.Text = Text;
result.Choose = Choose;
return result;
} }
object ICloneable.Clone() => Clone();
} }

View File

@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ll="clr-namespace:LinePutScript.Localization.WPF;assembly=LinePutScript.Localization.WPF" xmlns:ll="clr-namespace:LinePutScript.Localization.WPF;assembly=LinePutScript.Localization.WPF"
xmlns:pu="https://opensource.panuon.com/wpf-ui"> xmlns:pu="https://opensource.panuon.com/wpf-ui"
xmlns:vm="clr-namespace:VPet.ModMaker.ViewModels.ModEdit">
<ContextMenu x:Key="ContextMenu_DataGridRow" x:Shared="false"> <ContextMenu x:Key="ContextMenu_DataGridRow" x:Shared="false">
<MenuItem <MenuItem
Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource AncestorType=Page, Mode=FindAncestor}}" Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource AncestorType=Page, Mode=FindAncestor}}"
@ -47,7 +48,7 @@
<ListBox <ListBox
ItemsSource="{Binding I18nData.CultureNames}" ItemsSource="{Binding I18nData.CultureNames}"
ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"
SelectedItem="{Binding I18nData.CultureName.Value}"> SelectedItem="{Binding I18nData.CultureName}">
<ListBox.ItemContainerStyle> <ListBox.ItemContainerStyle>
<Style BasedOn="{StaticResource {x:Type ListBoxItem}}" TargetType="ListBoxItem"> <Style BasedOn="{StaticResource {x:Type ListBoxItem}}" TargetType="ListBoxItem">
<Setter Property="Content" Value="{Binding}" /> <Setter Property="Content" Value="{Binding}" />

View File

@ -54,7 +54,7 @@ public static class NativeExtensions
/// </summary> /// </summary>
/// <param name="image">图像</param> /// <param name="image">图像</param>
/// <returns>复制的图像</returns> /// <returns>复制的图像</returns>
public static BitmapImage Copy(this BitmapImage image) public static BitmapImage CloneStream(this BitmapImage image)
{ {
if (image is null) if (image is null)
return null; return null;
@ -64,10 +64,11 @@ public static class NativeExtensions
newImage.DecodePixelHeight = image.DecodePixelHeight; newImage.DecodePixelHeight = image.DecodePixelHeight;
try try
{ {
using var bitmap = new Bitmap(image.StreamSource);
var ms = new MemoryStream(); var ms = new MemoryStream();
bitmap.Save(ms, ImageFormat.Png); var position = image.StreamSource.Position;
image.StreamSource.Seek(0, SeekOrigin.Begin);
image.StreamSource.CopyTo(ms); image.StreamSource.CopyTo(ms);
image.StreamSource.Seek(position, SeekOrigin.Begin);
newImage.StreamSource = ms; newImage.StreamSource = ms;
} }
finally finally
@ -270,7 +271,7 @@ public static class NativeExtensions
yield return new(index++, item); yield return new(index++, item);
} }
public static void SetDataContext<T>(this Window window) public static void SetDataContext<T>(this Window window, Action? closedAction = null)
where T : new() where T : new()
{ {
window.DataContext = new T(); window.DataContext = new T();
@ -278,6 +279,7 @@ public static class NativeExtensions
{ {
try try
{ {
closedAction?.Invoke();
window.DataContext = null; window.DataContext = null;
} }
catch { } catch { }

View File

@ -16,18 +16,18 @@
<EmbeddedResource Include="Resources\food.png" /> <EmbeddedResource Include="Resources\food.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="VPet-Simulator.Core" Version="1.1.0" /> <PackageReference Include="VPet-Simulator.Core" Version="1.1.0.1" />
<PackageReference Include="VPet-Simulator.Windows.Interface" Version="1.1.0" /> <PackageReference Include="VPet-Simulator.Windows.Interface" Version="1.1.0.1" />
<PackageReference Include="LinePutScript" Version="1.11.6" /> <PackageReference Include="LinePutScript" Version="1.11.6" />
<PackageReference Include="LinePutScript.Localization.WPF" Version="1.0.6" /> <PackageReference Include="LinePutScript.Localization.WPF" Version="1.0.6" />
<PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" /> <PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" />
<PackageReference Include="Panuon.WPF" Version="1.1.0" /> <PackageReference Include="Panuon.WPF" Version="1.1.0" />
<PackageReference Include="Panuon.WPF.UI" Version="1.2.1" /> <PackageReference Include="Panuon.WPF.UI" Version="1.2.1.1" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" /> <PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
</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.2" /> <PackageReference Include="HKW.Utils" Version="1.2.4" />
<PackageReference Include="HKW.WPF" Version="1.0.3" /> <PackageReference Include="HKW.WPF" Version="1.0.3" />
<PackageReference Include="Mapster" Version="7.4.0" /> <PackageReference Include="Mapster" Version="7.4.0" />
</ItemGroup> </ItemGroup>

View File

@ -19,32 +19,50 @@ public class AddCultureWindowVM : ObservableObjectX<AddCultureWindowVM>
/// </summary> /// </summary>
#region ShowCultures #region ShowCultures
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableCollection<string> _showCultures; private ObservableFilterList<string, ObservableList<string>> _allCultures = null!;
public ObservableCollection<string> ShowCultures
{
get => _showCultures;
set => SetProperty(ref _showCultures, value);
}
#endregion
/// <summary> /// <summary>
/// 全部文化 /// 全部文化
/// </summary> /// </summary>
public static ObservableCollection<string> AllCultures { get; set; } = public ObservableFilterList<string, ObservableList<string>> AllCultures
new(LinePutScript.Localization.WPF.LocalizeCore.AvailableCultures); {
get => _allCultures;
set => SetProperty(ref _allCultures, value);
}
#endregion
/// <summary> /// <summary>
/// 当前文化 /// 当前文化
/// </summary> /// </summary>
#region Culture #region Culture
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _culture; private string _culture = string.Empty;
public string Culture public string Culture
{ {
get => _culture; get => _culture;
set => SetProperty(ref _culture, value); set
{
SetProperty(ref _culture, value);
if (string.IsNullOrWhiteSpace(Culture))
{
CultureFullName = UnknownCulture;
return;
}
CultureInfo info = null!;
try
{
info = CultureInfo.GetCultureInfo(Culture);
}
catch
{
CultureFullName = UnknownCulture;
}
if (info is not null)
{
CultureFullName = info.GetFullInfo();
}
}
} }
#endregion #endregion
@ -53,7 +71,7 @@ public class AddCultureWindowVM : ObservableObjectX<AddCultureWindowVM>
/// </summary> /// </summary>
#region CultureFullName #region CultureFullName
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _cultureFullName; private string _cultureFullName = string.Empty;
public string CultureFullName public string CultureFullName
{ {
@ -67,64 +85,27 @@ public class AddCultureWindowVM : ObservableObjectX<AddCultureWindowVM>
/// </summary> /// </summary>
#region Search #region Search
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _Search; private string _search = string.Empty;
public string Search public string Search
{ {
get => _Search; get => _search;
set => SetProperty(ref _Search, value); set
{
SetProperty(ref _search, value);
AllCultures.Refresh();
}
} }
#endregion #endregion
public static string UnknownCulture = "未知文化".Translate(); public static string UnknownCulture => "未知文化".Translate();
public AddCultureWindowVM() public AddCultureWindowVM()
{ {
//TODO AllCultures = new(LocalizeCore.AvailableCultures)
//ShowCultures = AllCultures;
//Search.ValueChanged += Search_ValueChanged;
//Culture.ValueChanged += Culture_ValueChanged;
}
private void Culture_ValueChanged(
ObservableValue<string> sender,
ValueChangedEventArgs<string> e
)
{
if (string.IsNullOrWhiteSpace(e.NewValue))
{ {
CultureFullName = UnknownCulture; Filter = c => c.Contains(Search, StringComparison.OrdinalIgnoreCase),
return; FilteredList = new()
} };
CultureInfo info = null!;
try
{
info = CultureInfo.GetCultureInfo(e.NewValue);
}
catch
{
CultureFullName = UnknownCulture;
}
if (info is not null)
{
CultureFullName = info.GetFullInfo();
}
}
private void Search_ValueChanged(
ObservableValue<string> sender,
ValueChangedEventArgs<string> e
)
{
if (string.IsNullOrWhiteSpace(e.NewValue))
{
ShowCultures = AllCultures;
}
else
{
ShowCultures = new(
AllCultures.Where(s => s.Contains(e.NewValue, StringComparison.OrdinalIgnoreCase))
);
}
} }
} }

View File

@ -99,12 +99,12 @@ public class FoodAnimeEditWindowVM : ObservableObjectX<FoodAnimeEditWindowVM>
#region CurrentFoodLocationModel #region CurrentFoodLocationModel
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private FoodLocationModel _currentFoodLocationModel; private FoodAnimeLocationModel _currentFoodLocationModel;
/// <summary> /// <summary>
/// 当前食物定位模型 /// 当前食物定位模型
/// </summary> /// </summary>
public FoodLocationModel CurrentFoodLocationModel public FoodAnimeLocationModel CurrentFoodLocationModel
{ {
get => _currentFoodLocationModel; get => _currentFoodLocationModel;
set => SetProperty(ref _currentFoodLocationModel, value); set => SetProperty(ref _currentFoodLocationModel, value);

View File

@ -13,13 +13,13 @@ namespace VPet.ModMaker.ViewModels.ModEdit.ClickTextEdit;
public class ClickTextEditWindowVM : ObservableObjectX<ClickTextEditWindowVM> public class ClickTextEditWindowVM : ObservableObjectX<ClickTextEditWindowVM>
{ {
public I18nHelper I18nData => I18nHelper.Current; public static I18nHelper I18nData => I18nHelper.Current;
#region Value #region Value
/// <summary> /// <summary>
/// 旧点击文本 /// 旧点击文本
/// </summary> /// </summary>
public ClickTextModel OldClickText { get; set; } public ClickTextModel? OldClickText { get; set; }
#region ClickText #region ClickText
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]

View File

@ -15,29 +15,37 @@ namespace VPet.ModMaker.ViewModels.ModEdit.ClickTextEdit;
public class ClickTextPageVM : ObservableObjectX<ClickTextPageVM> public class ClickTextPageVM : ObservableObjectX<ClickTextPageVM>
{ {
public ClickTextPageVM()
{
ClickTexts = new(ModInfoModel.Current.ClickTexts)
{
Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase),
FilteredList = new()
};
AddCommand.ExecuteCommand += AddCommand_ExecuteCommand;
EditCommand.ExecuteCommand += EditCommand_ExecuteCommand;
RemoveCommand.ExecuteCommand += RemoveCommand_ExecuteCommand;
}
#region Value #region Value
#region ShowClickTexts #region ShowClickTexts
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableCollection<ClickTextModel> _showClickTexts; private ObservableFilterList<ClickTextModel, ObservableList<ClickTextModel>> _clickTexts =
null!;
/// <summary> /// <summary>
/// 显示的点击文本 /// 显示的点击文本
/// </summary> /// </summary>
public ObservableCollection<ClickTextModel> ShowClickTexts public ObservableFilterList<ClickTextModel, ObservableList<ClickTextModel>> ClickTexts
{ {
get => _showClickTexts; get => _clickTexts;
set => SetProperty(ref _showClickTexts, value); set => SetProperty(ref _clickTexts, value);
} }
#endregion #endregion
/// <summary>
/// 点击文本
/// </summary>
public ObservableCollection<ClickTextModel> ClickTexts => ModInfoModel.Current.ClickTexts;
#region Search #region Search
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _search; private string _search = string.Empty;
/// <summary> /// <summary>
/// 搜索 /// 搜索
@ -45,7 +53,11 @@ public class ClickTextPageVM : ObservableObjectX<ClickTextPageVM>
public string Search public string Search
{ {
get => _search; get => _search;
set => SetProperty(ref _search, value); set
{
SetProperty(ref _search, value);
ClickTexts.Refresh();
}
} }
#endregion #endregion
#endregion #endregion
@ -66,37 +78,10 @@ public class ClickTextPageVM : ObservableObjectX<ClickTextPageVM>
public ObservableCommand<ClickTextModel> RemoveCommand { get; } = new(); public ObservableCommand<ClickTextModel> RemoveCommand { get; } = new();
#endregion #endregion
public ClickTextPageVM()
{
ShowClickTexts = ClickTexts;
//TODO
//Search.ValueChanged += Search_ValueChanged;
AddCommand.ExecuteCommand += Add;
EditCommand.ExecuteCommand += Edit;
RemoveCommand.ExecuteCommand += Remove;
}
private void Search_ValueChanged(
ObservableValue<string> sender,
ValueChangedEventArgs<string> e
)
{
if (string.IsNullOrWhiteSpace(e.NewValue))
{
ShowClickTexts = ClickTexts;
}
else
{
ShowClickTexts = new(
ClickTexts.Where(m => m.Id.Contains(e.NewValue, StringComparison.OrdinalIgnoreCase))
);
}
}
/// <summary> /// <summary>
/// 添加点击文本 /// 添加点击文本
/// </summary> /// </summary>
private void Add() private void AddCommand_ExecuteCommand()
{ {
var window = new ClickTextEditWindow(); var window = new ClickTextEditWindow();
var vm = window.ViewModel; var vm = window.ViewModel;
@ -110,7 +95,7 @@ public class ClickTextPageVM : ObservableObjectX<ClickTextPageVM>
/// 编辑点击文本 /// 编辑点击文本
/// </summary> /// </summary>
/// <param name="model">模型</param> /// <param name="model">模型</param>
public void Edit(ClickTextModel model) public void EditCommand_ExecuteCommand(ClickTextModel model)
{ {
var window = new ClickTextEditWindow(); var window = new ClickTextEditWindow();
var vm = window.ViewModel; var vm = window.ViewModel;
@ -120,26 +105,16 @@ public class ClickTextPageVM : ObservableObjectX<ClickTextPageVM>
if (window.IsCancel) if (window.IsCancel)
return; return;
ClickTexts[ClickTexts.IndexOf(model)] = newLowTest; ClickTexts[ClickTexts.IndexOf(model)] = newLowTest;
if (ShowClickTexts.Count != ClickTexts.Count)
ShowClickTexts[ShowClickTexts.IndexOf(model)] = newLowTest;
} }
/// <summary> /// <summary>
/// 删除点击文本 /// 删除点击文本
/// </summary> /// </summary>
/// <param name="model">模型</param> /// <param name="model">模型</param>
private void Remove(ClickTextModel model) private void RemoveCommand_ExecuteCommand(ClickTextModel model)
{ {
if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No)
return; return;
if (ShowClickTexts.Count == ClickTexts.Count) ClickTexts.Remove(model);
{
ClickTexts.Remove(model);
}
else
{
ShowClickTexts.Remove(model);
ClickTexts.Remove(model);
}
} }
} }

View File

@ -17,19 +17,43 @@ namespace VPet.ModMaker.ViewModels.ModEdit.FoodEdit;
public class FoodEditWindowVM : ObservableObjectX<FoodEditWindowVM> public class FoodEditWindowVM : ObservableObjectX<FoodEditWindowVM>
{ {
public FoodEditWindowVM()
{
AddImageCommand.ExecuteCommand += AddImageCommand_ExecuteCommand;
ChangeImageCommand.ExecuteCommand += ChangeImageCommand_ExecuteCommand;
SetReferencePriceCommand.ExecuteCommand += SetReferencePriceCommand_ExecuteCommand;
}
public static ModInfoModel ModInfo => ModInfoModel.Current; public static ModInfoModel ModInfo => ModInfoModel.Current;
public static I18nHelper I18nData => I18nHelper.Current; public static I18nHelper I18nData => I18nHelper.Current;
#region Value
public FoodModel OldFood { get; set; } #region Property
public FoodModel? OldFood { get; set; }
#region Food #region Food
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private FoodModel _food; private FoodModel _food = new();
public FoodModel Food public FoodModel Food
{ {
get => _food; get => _food;
set => SetProperty(ref _food, value); set
{
if (_food is not null)
_food.PropertyChangedX -= Food_PropertyChangedX;
if (SetProperty(ref _food!, value) is false)
return;
Food.PropertyChangedX += Food_PropertyChangedX;
}
}
private void Food_PropertyChangedX(I18nModel<I18nFoodModel> sender, PropertyChangedXEventArgs e)
{
if (e.PropertyName == nameof(FoodModel.ReferencePrice))
{
if (ModInfo.AutoSetFoodPrice)
SetReferencePriceCommand_ExecuteCommand((double)e.NewValue!);
}
} }
#endregion #endregion
#endregion #endregion
@ -40,27 +64,7 @@ public class FoodEditWindowVM : ObservableObjectX<FoodEditWindowVM>
public ObservableCommand<double> SetReferencePriceCommand { get; } = new(); public ObservableCommand<double> SetReferencePriceCommand { get; } = new();
#endregion #endregion
public FoodEditWindowVM() private void SetReferencePriceCommand_ExecuteCommand(double value)
{
AddImageCommand.ExecuteCommand += AddImage;
ChangeImageCommand.ExecuteCommand += ChangeImage;
SetReferencePriceCommand.ExecuteCommand += SetReferencePriceToPrice;
//TODO
//Food.Value.ReferencePrice.ValueChanged += ReferencePrice_ValueChanged;
}
private void ReferencePrice_ValueChanged(
ObservableValue<double> sender,
ValueChangedEventArgs<double> e
)
{
if (ModInfo.AutoSetFoodPrice)
{
SetReferencePriceToPrice(e.NewValue);
}
}
private void SetReferencePriceToPrice(double value)
{ {
Food.Price = value; Food.Price = value;
} }
@ -70,28 +74,26 @@ public class FoodEditWindowVM : ObservableObjectX<FoodEditWindowVM>
Food.Close(); Food.Close();
} }
private void AddImage() private void AddImageCommand_ExecuteCommand()
{ {
OpenFileDialog openFileDialog = var openFileDialog = new OpenFileDialog()
new() {
{ Title = "选择图片".Translate(),
Title = "选择图片".Translate(), Filter = $"图片|*.jpg;*.jpeg;*.png;*.bmp".Translate()
Filter = $"图片|*.jpg;*.jpeg;*.png;*.bmp".Translate() };
};
if (openFileDialog.ShowDialog() is true) if (openFileDialog.ShowDialog() is true)
{ {
Food.Image = NativeUtils.LoadImageToMemoryStream(openFileDialog.FileName); Food.Image = NativeUtils.LoadImageToMemoryStream(openFileDialog.FileName);
} }
} }
private void ChangeImage() private void ChangeImageCommand_ExecuteCommand()
{ {
OpenFileDialog openFileDialog = var openFileDialog = new OpenFileDialog()
new() {
{ Title = "选择图片".Translate(),
Title = "选择图片".Translate(), Filter = $"图片|*.jpg;*.jpeg;*.png;*.bmp".Translate()
Filter = $"图片|*.jpg;*.jpeg;*.png;*.bmp".Translate() };
};
if (openFileDialog.ShowDialog() is true) if (openFileDialog.ShowDialog() is true)
{ {
Food.Image?.StreamSource?.Close(); Food.Image?.StreamSource?.Close();

View File

@ -17,27 +17,46 @@ namespace VPet.ModMaker.ViewModels.ModEdit.FoodEdit;
public class FoodPageVM : ObservableObjectX<FoodPageVM> public class FoodPageVM : ObservableObjectX<FoodPageVM>
{ {
#region Value public FoodPageVM()
#region ShowFoods
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableCollection<FoodModel> _showFoods;
public ObservableCollection<FoodModel> ShowFoods
{ {
get => _showFoods; Foods = new(ModInfoModel.Current.Foods)
set => SetProperty(ref _showFoods, value); {
Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase),
FilteredList = new()
};
AddCommand.ExecuteCommand += AddCommand_ExecuteCommand;
EditCommand.ExecuteCommand += EditCommand_ExecuteCommand;
RemoveCommand.ExecuteCommand += RemoveCommand_ExecuteCommand;
}
#region Property
#region Foods
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableFilterList<FoodModel, ObservableList<FoodModel>> _foods = null!;
public ObservableFilterList<FoodModel, ObservableList<FoodModel>> Foods
{
get => _foods;
set => SetProperty(ref _foods, value);
} }
#endregion #endregion
public ObservableCollection<FoodModel> Foods => ModInfoModel.Current.Foods;
#region Search #region Search
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _search; private string _search = string.Empty;
public string Search public string Search
{ {
get => _search; get => _search;
set => SetProperty(ref _search, value); set
{
if (SetProperty(ref _search, value))
{
Foods.Refresh();
}
}
} }
#endregion #endregion
#endregion #endregion
@ -46,37 +65,8 @@ public class FoodPageVM : ObservableObjectX<FoodPageVM>
public ObservableCommand<FoodModel> EditCommand { get; } = new(); public ObservableCommand<FoodModel> EditCommand { get; } = new();
public ObservableCommand<FoodModel> RemoveCommand { get; } = new(); public ObservableCommand<FoodModel> RemoveCommand { get; } = new();
#endregion #endregion
public FoodPageVM()
{
ShowFoods = Foods;
//TODO
//Search.ValueChanged += Search_ValueChanged;
AddCommand.ExecuteCommand += Add; private void AddCommand_ExecuteCommand()
EditCommand.ExecuteCommand += Edit;
RemoveCommand.ExecuteCommand += Remove;
}
private void Search_ValueChanged(
ObservableValue<string> sender,
ValueChangedEventArgs<string> e
)
{
if (string.IsNullOrWhiteSpace(e.NewValue))
{
ShowFoods = Foods;
}
else
{
ShowFoods = new(
Foods.Where(m => m.Id.Contains(e.NewValue, StringComparison.OrdinalIgnoreCase))
);
}
}
public void Close() { }
private void Add()
{ {
var window = new FoodEditWindow(); var window = new FoodEditWindow();
var vm = window.ViewModel; var vm = window.ViewModel;
@ -86,7 +76,7 @@ public class FoodPageVM : ObservableObjectX<FoodPageVM>
Foods.Add(vm.Food); Foods.Add(vm.Food);
} }
public void Edit(FoodModel food) public void EditCommand_ExecuteCommand(FoodModel food)
{ {
var window = new FoodEditWindow(); var window = new FoodEditWindow();
var vm = window.ViewModel; var vm = window.ViewModel;
@ -96,23 +86,13 @@ public class FoodPageVM : ObservableObjectX<FoodPageVM>
if (window.IsCancel) if (window.IsCancel)
return; return;
Foods[Foods.IndexOf(food)] = newFood; Foods[Foods.IndexOf(food)] = newFood;
if (ShowFoods.Count != Foods.Count)
ShowFoods[ShowFoods.IndexOf(food)] = newFood;
food.Close(); food.Close();
} }
private void Remove(FoodModel food) private void RemoveCommand_ExecuteCommand(FoodModel food)
{ {
if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No)
return; return;
if (ShowFoods.Count == Foods.Count) Foods.Remove(food);
{
Foods.Remove(food);
}
else
{
ShowFoods.Remove(food);
Foods.Remove(food);
}
} }
} }

View File

@ -13,13 +13,13 @@ namespace VPet.ModMaker.ViewModels.ModEdit.LowTextEdit;
public class LowTextEditWindowVM : ObservableObjectX<LowTextEditWindowVM> public class LowTextEditWindowVM : ObservableObjectX<LowTextEditWindowVM>
{ {
public I18nHelper I18nData => I18nHelper.Current; public static I18nHelper I18nData => I18nHelper.Current;
#region Value #region Value
public LowTextModel OldLowText { get; set; } public LowTextModel? OldLowText { get; set; }
#region LowText #region LowText
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private LowTextModel _lowText; private LowTextModel _lowText = new();
public LowTextModel LowText public LowTextModel LowText
{ {

View File

@ -12,33 +12,48 @@ using HKW.HKWUtils.Observable;
using LinePutScript.Localization.WPF; using LinePutScript.Localization.WPF;
using VPet.ModMaker.Models; using VPet.ModMaker.Models;
using VPet.ModMaker.Views.ModEdit.LowTextEdit; using VPet.ModMaker.Views.ModEdit.LowTextEdit;
using Expression = System.Linq.Expressions.Expression;
namespace VPet.ModMaker.ViewModels.ModEdit.LowTextEdit; namespace VPet.ModMaker.ViewModels.ModEdit.LowTextEdit;
public class LowTextPageVM : ObservableObjectX<LowTextPageVM> public class LowTextPageVM : ObservableObjectX<LowTextPageVM>
{ {
#region Value public LowTextPageVM()
#region ShowLowTexts
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableCollection<LowTextModel> _showLowTexts;
public ObservableCollection<LowTextModel> ShowLowTexts
{ {
get => _showLowTexts; LowTexts = new(ModInfoModel.Current.LowTexts)
set => SetProperty(ref _showLowTexts, value); {
Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase),
FilteredList = new()
};
AddCommand.ExecuteCommand += AddCommand_ExecuteCommand;
EditCommand.ExecuteCommand += EditCommand_ExecuteCommand;
RemoveCommand.ExecuteCommand += RemoveCommand_ExecuteCommand;
}
#region Property
#region LowTexts
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableFilterList<LowTextModel, ObservableList<LowTextModel>> _lowTexts = null!;
public ObservableFilterList<LowTextModel, ObservableList<LowTextModel>> LowTexts
{
get => _lowTexts;
set => SetProperty(ref _lowTexts, value);
} }
#endregion #endregion
public ObservableCollection<LowTextModel> LowTexts => ModInfoModel.Current.LowTexts;
#region Search #region Search
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _search; private string _search = string.Empty;
public string Search public string Search
{ {
get => _search; get => _search;
set => SetProperty(ref _search, value); set
{
SetProperty(ref _search, value);
LowTexts.Refresh();
}
} }
#endregion #endregion
#endregion #endregion
@ -48,33 +63,7 @@ public class LowTextPageVM : ObservableObjectX<LowTextPageVM>
public ObservableCommand<LowTextModel> RemoveCommand { get; } = new(); public ObservableCommand<LowTextModel> RemoveCommand { get; } = new();
#endregion #endregion
public LowTextPageVM() private void AddCommand_ExecuteCommand()
{
ShowLowTexts = LowTexts;
//Search.ValueChanged += Search_ValueChanged;//TODO
AddCommand.ExecuteCommand += Add;
EditCommand.ExecuteCommand += Edit;
RemoveCommand.ExecuteCommand += Remove;
}
private void Search_ValueChanged(
ObservableValue<string> sender,
ValueChangedEventArgs<string> e
)
{
if (string.IsNullOrWhiteSpace(e.NewValue))
{
ShowLowTexts = LowTexts;
}
else
{
ShowLowTexts = new(
LowTexts.Where(m => m.Id.Contains(e.NewValue, StringComparison.OrdinalIgnoreCase))
);
}
}
private void Add()
{ {
var window = new LowTextEditWindow(); var window = new LowTextEditWindow();
var vm = window.ViewModel; var vm = window.ViewModel;
@ -84,7 +73,7 @@ public class LowTextPageVM : ObservableObjectX<LowTextPageVM>
LowTexts.Add(vm.LowText); LowTexts.Add(vm.LowText);
} }
public void Edit(LowTextModel model) public void EditCommand_ExecuteCommand(LowTextModel model)
{ {
var window = new LowTextEditWindow(); var window = new LowTextEditWindow();
var vm = window.ViewModel; var vm = window.ViewModel;
@ -94,22 +83,12 @@ public class LowTextPageVM : ObservableObjectX<LowTextPageVM>
if (window.IsCancel) if (window.IsCancel)
return; return;
LowTexts[LowTexts.IndexOf(model)] = newLowTest; LowTexts[LowTexts.IndexOf(model)] = newLowTest;
if (ShowLowTexts.Count != LowTexts.Count)
ShowLowTexts[ShowLowTexts.IndexOf(model)] = newLowTest;
} }
private void Remove(LowTextModel model) private void RemoveCommand_ExecuteCommand(LowTextModel model)
{ {
if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No)
return; return;
if (ShowLowTexts.Count == LowTexts.Count) LowTexts.Remove(model);
{
LowTexts.Remove(model);
}
else
{
ShowLowTexts.Remove(model);
LowTexts.Remove(model);
}
} }
} }

View File

@ -24,6 +24,22 @@ namespace VPet.ModMaker.ViewModels.ModEdit;
public class ModEditWindowVM : ObservableObjectX<ModEditWindowVM> public class ModEditWindowVM : ObservableObjectX<ModEditWindowVM>
{ {
public ModEditWindowVM(ModEditWindow window)
{
I18nEditWindow.Initialize();
ModEditWindow = window;
ChangeImageCommand.ExecuteCommand += ChangeImageCommand_ExecuteCommand;
AddCultureCommand.ExecuteCommand += AddCultureCommand_ExecuteCommand;
EditCultureCommand.ExecuteCommand += EditCultureCommand_ExecuteCommand;
RemoveCultureCommand.ExecuteCommand += RemoveCultureCommand_ExecuteCommand;
EditI18nCommand.ExecuteCommand += EditI18nCommand_ExecuteCommand;
SetMainCultureCommand.ExecuteCommand += SetMainCultureCommand_ExecuteCommand;
SaveCommand.ExecuteCommand += SaveCommand_ExecuteCommand;
SaveToCommand.ExecuteCommand += SaveToCommand_ExecuteCommand;
SaveAsTranslationModCommand.ExecuteCommand += SaveAsTranslationModCommand_ExecuteCommand;
}
public ModEditWindow ModEditWindow { get; } public ModEditWindow ModEditWindow { get; }
#region Value #region Value
@ -44,7 +60,7 @@ public class ModEditWindowVM : ObservableObjectX<ModEditWindowVM>
/// <summary> /// <summary>
/// I18n数据 /// I18n数据
/// </summary> /// </summary>
public I18nHelper I18nData => I18nHelper.Current; public static I18nHelper I18nData => I18nHelper.Current;
#endregion #endregion
#region Command #region Command
@ -95,23 +111,7 @@ public class ModEditWindowVM : ObservableObjectX<ModEditWindowVM>
public ObservableCommand SaveAsTranslationModCommand { get; } = new(); public ObservableCommand SaveAsTranslationModCommand { get; } = new();
#endregion #endregion
public ModEditWindowVM(ModEditWindow window) private void SaveAsTranslationModCommand_ExecuteCommand()
{
new I18nEditWindow();
ModEditWindow = window;
ChangeImageCommand.ExecuteCommand += ChangeImage;
AddCultureCommand.ExecuteCommand += AddCulture;
EditCultureCommand.ExecuteCommand += EditCulture;
RemoveCultureCommand.ExecuteCommand += RemoveCulture;
EditI18nCommand.ExecuteCommand += EditI18n;
SetMainCultureCommand.ExecuteCommand += SetMainCulture;
SaveCommand.ExecuteCommand += Save;
SaveToCommand.ExecuteCommand += SaveTo;
SaveAsTranslationModCommand.ExecuteCommand += SaveAsTranslationMod;
}
private void SaveAsTranslationMod()
{ {
if (ValidationData(ModInfo) is false) if (ValidationData(ModInfo) is false)
return; return;
@ -119,7 +119,7 @@ public class ModEditWindowVM : ObservableObjectX<ModEditWindowVM>
window.ShowDialog(); window.ShowDialog();
} }
private void EditI18n() private void EditI18nCommand_ExecuteCommand()
{ {
I18nEditWindow.Current.Visibility = Visibility.Visible; I18nEditWindow.Current.Visibility = Visibility.Visible;
I18nEditWindow.Current.Activate(); I18nEditWindow.Current.Activate();
@ -137,7 +137,7 @@ public class ModEditWindowVM : ObservableObjectX<ModEditWindowVM>
/// <summary> /// <summary>
/// 改变图片 /// 改变图片
/// </summary> /// </summary>
private void ChangeImage() private void ChangeImageCommand_ExecuteCommand()
{ {
OpenFileDialog openFileDialog = OpenFileDialog openFileDialog =
new() new()
@ -156,7 +156,7 @@ public class ModEditWindowVM : ObservableObjectX<ModEditWindowVM>
/// <summary> /// <summary>
/// 添加文化 /// 添加文化
/// </summary> /// </summary>
public void AddCulture() public void AddCultureCommand_ExecuteCommand()
{ {
var window = new AddCultureWindow(); var window = new AddCultureWindow();
window.ShowDialog(); window.ShowDialog();
@ -171,7 +171,7 @@ public class ModEditWindowVM : ObservableObjectX<ModEditWindowVM>
/// 编辑文化 /// 编辑文化
/// </summary> /// </summary>
/// <param name="oldCulture">旧文化</param> /// <param name="oldCulture">旧文化</param>
private void EditCulture(string oldCulture) private void EditCultureCommand_ExecuteCommand(string oldCulture)
{ {
var window = new AddCultureWindow(); var window = new AddCultureWindow();
window.ViewModel.Culture = oldCulture.Translate(); window.ViewModel.Culture = oldCulture.Translate();
@ -186,7 +186,7 @@ public class ModEditWindowVM : ObservableObjectX<ModEditWindowVM>
/// 删除文化 /// 删除文化
/// </summary> /// </summary>
/// <param name="oldCulture">旧文化</param> /// <param name="oldCulture">旧文化</param>
private void RemoveCulture(string oldCulture) private void RemoveCultureCommand_ExecuteCommand(string oldCulture)
{ {
if ( if (
MessageBox.Show( MessageBox.Show(
@ -199,7 +199,7 @@ public class ModEditWindowVM : ObservableObjectX<ModEditWindowVM>
I18nHelper.Current.CultureNames.Remove(oldCulture); I18nHelper.Current.CultureNames.Remove(oldCulture);
} }
public void SetMainCulture(string culture) public void SetMainCultureCommand_ExecuteCommand(string culture)
{ {
if ( if (
MessageBox.Show( MessageBox.Show(
@ -214,17 +214,17 @@ public class ModEditWindowVM : ObservableObjectX<ModEditWindowVM>
ModInfo.I18nDatas[culture].Description = ModInfo.DescriptionId; ModInfo.I18nDatas[culture].Description = ModInfo.DescriptionId;
foreach (var food in ModInfo.Foods) foreach (var food in ModInfo.Foods)
{ {
food.I18nDatas[culture].Name = food.Id; food.I18nDatas[culture].Name = food.ID;
food.I18nDatas[culture].Description = food.DescriptionId; food.I18nDatas[culture].Description = food.DescriptionID;
} }
foreach (var text in ModInfo.LowTexts) foreach (var text in ModInfo.LowTexts)
text.I18nDatas[culture].Text = text.Id; text.I18nDatas[culture].Text = text.ID;
foreach (var text in ModInfo.ClickTexts) foreach (var text in ModInfo.ClickTexts)
text.I18nDatas[culture].Text = text.Id; text.I18nDatas[culture].Text = text.ID;
foreach (var text in ModInfo.SelectTexts) foreach (var text in ModInfo.SelectTexts)
{ {
text.I18nDatas[culture].Text = text.Id; text.I18nDatas[culture].Text = text.ID;
text.I18nDatas[culture].Choose = text.ChooseId; text.I18nDatas[culture].Choose = text.ChooseID;
} }
foreach (var pet in ModInfo.Pets) foreach (var pet in ModInfo.Pets)
{ {
@ -241,7 +241,7 @@ public class ModEditWindowVM : ObservableObjectX<ModEditWindowVM>
/// <summary> /// <summary>
/// 保存 /// 保存
/// </summary> /// </summary>
private void Save() private void SaveCommand_ExecuteCommand()
{ {
if (ValidationData(ModInfo) is false) if (ValidationData(ModInfo) is false)
return; return;
@ -261,7 +261,7 @@ public class ModEditWindowVM : ObservableObjectX<ModEditWindowVM>
/// <summary> /// <summary>
/// 保存至 /// 保存至
/// </summary> /// </summary>
private void SaveTo() private void SaveToCommand_ExecuteCommand()
{ {
if (ValidationData(ModInfo) is false) if (ValidationData(ModInfo) is false)
return; return;

View File

@ -16,29 +16,45 @@ namespace VPet.ModMaker.ViewModels.ModEdit.PetEdit;
public class PetPageVM : ObservableObjectX<PetPageVM> public class PetPageVM : ObservableObjectX<PetPageVM>
{ {
public PetPageVM()
{
Pets = new(ModInfoModel.Current.Pets)
{
Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase),
FilteredList = new()
};
AddCommand.ExecuteCommand += Add;
EditCommand.ExecuteCommand += Edit;
RemoveCommand.ExecuteCommand += Remove;
}
public static ModInfoModel ModInfo => ModInfoModel.Current; public static ModInfoModel ModInfo => ModInfoModel.Current;
#region Value #region Property
#region ShowPets #region ShowPets
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableCollection<PetModel> _showPets; private ObservableFilterList<PetModel, ObservableList<PetModel>> _pets = null!;
public ObservableCollection<PetModel> ShowPets public ObservableFilterList<PetModel, ObservableList<PetModel>> Pets
{ {
get => _showPets; get => _pets;
set => SetProperty(ref _showPets, value); set => SetProperty(ref _pets, value);
} }
#endregion #endregion
public ObservableCollection<PetModel> Pets => ModInfoModel.Current.Pets;
#region Search #region Search
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _search; private string _search = string.Empty;
public string Search public string Search
{ {
get => _search; get => _search;
set => SetProperty(ref _search, value); set
{
SetProperty(ref _search, value);
Pets.Refresh();
}
} }
#endregion #endregion
#endregion #endregion
@ -47,33 +63,6 @@ public class PetPageVM : ObservableObjectX<PetPageVM>
public ObservableCommand<PetModel> EditCommand { get; } = new(); public ObservableCommand<PetModel> EditCommand { get; } = new();
public ObservableCommand<PetModel> RemoveCommand { get; } = new(); public ObservableCommand<PetModel> RemoveCommand { get; } = new();
#endregion #endregion
public PetPageVM()
{
//TODO
//ShowPets = Pets;
//Search.ValueChanged += Search_ValueChanged;
AddCommand.ExecuteCommand += Add;
EditCommand.ExecuteCommand += Edit;
RemoveCommand.ExecuteCommand += Remove;
}
private void Search_ValueChanged(
ObservableValue<string> sender,
ValueChangedEventArgs<string> e
)
{
if (string.IsNullOrWhiteSpace(e.NewValue))
{
ShowPets = Pets;
}
else
{
ShowPets = new(
Pets.Where(m => m.ID.Contains(e.NewValue, StringComparison.OrdinalIgnoreCase))
);
}
}
public void Close() { } public void Close() { }
@ -114,8 +103,6 @@ public class PetPageVM : ObservableObjectX<PetPageVM>
{ {
Pets[Pets.IndexOf(model)] = newPet; Pets[Pets.IndexOf(model)] = newPet;
} }
if (ShowPets.Count != Pets.Count)
ShowPets[ShowPets.IndexOf(model)] = newPet;
model.Close(); model.Close();
} }
@ -128,14 +115,6 @@ public class PetPageVM : ObservableObjectX<PetPageVM>
} }
if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No)
return; return;
if (ShowPets.Count == Pets.Count) Pets.Remove(model);
{
Pets.Remove(model);
}
else
{
ShowPets.Remove(model);
Pets.Remove(model);
}
} }
} }

View File

@ -11,9 +11,9 @@ namespace VPet.ModMaker.ViewModels.ModEdit.SelectTextEdit;
public class SelectTextEditWindowVM : ObservableObjectX<SelectTextEditWindowVM> public class SelectTextEditWindowVM : ObservableObjectX<SelectTextEditWindowVM>
{ {
public I18nHelper I18nData => I18nHelper.Current; public static I18nHelper I18nData => I18nHelper.Current;
#region Value #region Value
public SelectTextModel OldSelectText { get; set; } public SelectTextModel? OldSelectText { get; set; }
#region SelectText #region SelectText
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]

View File

@ -10,32 +10,49 @@ using HKW.HKWUtils.Observable;
using LinePutScript.Localization.WPF; using LinePutScript.Localization.WPF;
using VPet.ModMaker.Models; using VPet.ModMaker.Models;
using VPet.ModMaker.Views.ModEdit.SelectTextEdit; using VPet.ModMaker.Views.ModEdit.SelectTextEdit;
using VPet_Simulator.Windows.Interface;
namespace VPet.ModMaker.ViewModels.ModEdit.SelectTextEdit; namespace VPet.ModMaker.ViewModels.ModEdit.SelectTextEdit;
public class SelectTextPageVM : ObservableObjectX<SelectTextPageVM> public class SelectTextPageVM : ObservableObjectX<SelectTextPageVM>
{ {
#region Value public SelectTextPageVM()
#region ShowSelectTexts
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableCollection<SelectTextModel> _showSelectTexts;
public ObservableCollection<SelectTextModel> ShowSelectTexts
{ {
get => _showSelectTexts; SelectTexts = new(ModInfoModel.Current.SelectTexts)
set => SetProperty(ref _showSelectTexts, value); {
Filter = f => f.ID.Contains(Search, StringComparison.OrdinalIgnoreCase),
FilteredList = new()
};
AddCommand.ExecuteCommand += AddCommand_ExecuteCommand;
EditCommand.ExecuteCommand += EditCommand_ExecuteCommand;
RemoveCommand.ExecuteCommand += RemoveCommand_ExecuteCommand;
}
#region Property
#region SelectTexts
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableFilterList<SelectTextModel, ObservableList<SelectTextModel>> _selectTexts =
null!;
public ObservableFilterList<SelectTextModel, ObservableList<SelectTextModel>> SelectTexts
{
get => _selectTexts;
set => SetProperty(ref _selectTexts, value);
} }
#endregion #endregion
public ObservableCollection<SelectTextModel> SelectTexts => ModInfoModel.Current.SelectTexts;
#region Search #region Search
[DebuggerBrowsable(DebuggerBrowsableState.Never)] [DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _search; private string _search = string.Empty;
public string Search public string Search
{ {
get => _search; get => _search;
set => SetProperty(ref _search, value); set
{
SetProperty(ref _search, value);
SelectTexts.Refresh();
}
} }
#endregion #endregion
#endregion #endregion
@ -45,36 +62,7 @@ public class SelectTextPageVM : ObservableObjectX<SelectTextPageVM>
public ObservableCommand<SelectTextModel> RemoveCommand { get; } = new(); public ObservableCommand<SelectTextModel> RemoveCommand { get; } = new();
#endregion #endregion
public SelectTextPageVM() private void AddCommand_ExecuteCommand()
{
ShowSelectTexts = SelectTexts;
//TODO
//Search.ValueChanged += Search_ValueChanged;
AddCommand.ExecuteCommand += Add;
EditCommand.ExecuteCommand += Edit;
RemoveCommand.ExecuteCommand += Remove;
}
private void Search_ValueChanged(
ObservableValue<string> sender,
ValueChangedEventArgs<string> e
)
{
if (string.IsNullOrWhiteSpace(e.NewValue))
{
ShowSelectTexts = SelectTexts;
}
else
{
ShowSelectTexts = new(
SelectTexts.Where(m =>
m.Id.Contains(e.NewValue, StringComparison.OrdinalIgnoreCase)
)
);
}
}
private void Add()
{ {
var window = new SelectTextEditWindow(); var window = new SelectTextEditWindow();
var vm = window.ViewModel; var vm = window.ViewModel;
@ -84,32 +72,22 @@ public class SelectTextPageVM : ObservableObjectX<SelectTextPageVM>
SelectTexts.Add(vm.SelectText); SelectTexts.Add(vm.SelectText);
} }
public void Edit(SelectTextModel model) public void EditCommand_ExecuteCommand(SelectTextModel model)
{ {
var window = new SelectTextEditWindow(); var window = new SelectTextEditWindow();
var vm = window.ViewModel; var vm = window.ViewModel;
vm.OldSelectText = model; vm.OldSelectText = model;
var newLowTest = vm.SelectText = new(model); var newSelectText = vm.SelectText = new(model);
window.ShowDialog(); window.ShowDialog();
if (window.IsCancel) if (window.IsCancel)
return; return;
SelectTexts[SelectTexts.IndexOf(model)] = newLowTest; SelectTexts[SelectTexts.IndexOf(model)] = newSelectText;
if (ShowSelectTexts.Count != SelectTexts.Count)
ShowSelectTexts[ShowSelectTexts.IndexOf(model)] = newLowTest;
} }
private void Remove(SelectTextModel model) private void RemoveCommand_ExecuteCommand(SelectTextModel model)
{ {
if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No)
return; return;
if (ShowSelectTexts.Count == SelectTexts.Count) SelectTexts.Remove(model);
{
SelectTexts.Remove(model);
}
else
{
ShowSelectTexts.Remove(model);
SelectTexts.Remove(model);
}
} }
} }

View File

@ -88,7 +88,7 @@ public class ModMakerWindowVM : ObservableObjectX<ModMakerWindowVM>
LoadHistories(); LoadHistories();
ModMakerWindow = window; ModMakerWindow = window;
//TODO //TODO
//ShowHistories.Value = Histories; ShowHistories = Histories;
CreateNewModCommand.ExecuteCommand += CreateNewMod; CreateNewModCommand.ExecuteCommand += CreateNewMod;
LoadModFromFileCommand.ExecuteCommand += LoadModFromFile; LoadModFromFileCommand.ExecuteCommand += LoadModFromFile;
ClearHistoriesCommand.ExecuteCommand += ClearHistories; ClearHistoriesCommand.ExecuteCommand += ClearHistories;
@ -124,7 +124,8 @@ public class ModMakerWindowVM : ObservableObjectX<ModMakerWindowVM>
var lps = new LPS(File.ReadAllText(ModMakerInfo.HistoryFile)); var lps = new LPS(File.ReadAllText(ModMakerInfo.HistoryFile));
foreach (var line in lps) foreach (var line in lps)
{ {
var history = LPSConvert.DeserializeObject<ModMakeHistory>(line); if (LPSConvert.DeserializeObject<ModMakeHistory>(line) is not ModMakeHistory history)
continue;
if (Histories.All(h => h.InfoFile != history.InfoFile)) if (Histories.All(h => h.InfoFile != history.InfoFile))
Histories.Add(history); Histories.Add(history);
} }

View File

@ -40,14 +40,14 @@
Grid.Column="1" Grid.Column="1"
Margin="10,0,0,0" Margin="10,0,0,0"
VerticalAlignment="Center" VerticalAlignment="Center"
Text="{Binding CultureFullName.Value}" /> Text="{Binding CultureFullName}" />
</Grid> </Grid>
<TextBox <TextBox
x:Name="TextBox_Lang" x:Name="TextBox_Lang"
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.Value, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding Culture, 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 支持的语言/区域名称列表中的“语言标记”列}" />
@ -84,11 +84,11 @@
<TextBox <TextBox
pu:TextBoxHelper.Watermark="{ll:Str 搜索}" pu:TextBoxHelper.Watermark="{ll:Str 搜索}"
Style="{DynamicResource StandardTextBoxStyle}" Style="{DynamicResource StandardTextBoxStyle}"
Text="{Binding Search.Value, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding Search, UpdateSourceTrigger=PropertyChanged}" />
<ListBox <ListBox
Grid.Row="1" Grid.Row="1"
ItemsSource="{Binding ShowCultures.Value}" ItemsSource="{Binding AllCultures.FilteredList}"
SelectedItem="{Binding Culture.Value}" /> SelectedItem="{Binding Culture}" />
</Grid> </Grid>
</Grid> </Grid>
</pu:WindowX> </pu:WindowX>

View File

@ -33,12 +33,12 @@
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Label Content="Id" /> <Label Content="ID" />
<TextBox <TextBox
Grid.Column="1" Grid.Column="1"
pu:TextBoxHelper.Watermark="Id" pu:TextBoxHelper.Watermark="ID"
Style="{StaticResource TextBox_Wrap}" Style="{StaticResource TextBox_Wrap}"
Text="{Binding ClickText.Id, UpdateSourceTrigger=PropertyChanged}" Text="{Binding ClickText.ID, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" /> TextWrapping="Wrap" />
</Grid> </Grid>
<TextBox <TextBox
@ -89,12 +89,12 @@
SelectedIndex="0" /> SelectedIndex="0" />
<Button <Button
Grid.Column="2" Grid.Column="2"
Command="{Binding ClickText.Mode.AddCommand}" Command="{Binding ClickText.Mode.AddFlagCommand}"
CommandParameter="{Binding SelectedItem, ElementName=ComboBox_Mode}" CommandParameter="{Binding SelectedItem, ElementName=ComboBox_Mode}"
Content="+" /> Content="+" />
<Button <Button
Grid.Column="3" Grid.Column="3"
Command="{Binding ClickText.Mode.RemoveCommand}" Command="{Binding ClickText.Mode.RemoveFlagCommand}"
CommandParameter="{Binding SelectedItem, ElementName=ComboBox_Mode}" CommandParameter="{Binding SelectedItem, ElementName=ComboBox_Mode}"
Content="-" /> Content="-" />
</Grid> </Grid>
@ -120,12 +120,12 @@
SelectedIndex="0" /> SelectedIndex="0" />
<Button <Button
Grid.Column="2" Grid.Column="2"
Command="{Binding ClickText.DayTime.AddCommand}" Command="{Binding ClickText.DayTime.AddFlagCommand}"
CommandParameter="{Binding SelectedItem, ElementName=ComboBox_DayTime}" CommandParameter="{Binding SelectedItem, ElementName=ComboBox_DayTime}"
Content="+" /> Content="+" />
<Button <Button
Grid.Column="3" Grid.Column="3"
Command="{Binding ClickText.DayTime.RemoveCommand}" Command="{Binding ClickText.DayTime.RemoveFlagCommand}"
CommandParameter="{Binding SelectedItem, ElementName=ComboBox_DayTime}" CommandParameter="{Binding SelectedItem, ElementName=ComboBox_DayTime}"
Content="-" /> Content="-" />
</Grid> </Grid>

View File

@ -28,15 +28,7 @@ public partial class ClickTextEditWindow : Window
public ClickTextEditWindow() public ClickTextEditWindow()
{ {
InitializeComponent(); InitializeComponent();
DataContext = new ClickTextEditWindowVM(); this.SetDataContext<ClickTextEditWindowVM>();
Closed += (s, e) =>
{
try
{
DataContext = null;
}
catch { }
};
} }
private void Button_Cancel_Click(object sender, RoutedEventArgs e) private void Button_Cancel_Click(object sender, RoutedEventArgs e)
@ -46,17 +38,17 @@ public partial class ClickTextEditWindow : Window
private void Button_Yes_Click(object sender, RoutedEventArgs e) private void Button_Yes_Click(object sender, RoutedEventArgs e)
{ {
if (string.IsNullOrEmpty(ViewModel.ClickText.Id)) if (string.IsNullOrEmpty(ViewModel.ClickText.ID))
{ {
MessageBox.Show("Id不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); MessageBox.Show("ID不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning);
return; return;
} }
if ( if (
ViewModel.OldClickText?.Id != ViewModel.ClickText.Id ViewModel.OldClickText?.ID != ViewModel.ClickText.ID
&& ModInfoModel.Current.ClickTexts.Any(i => i.Id == ViewModel.ClickText.Id) && ModInfoModel.Current.ClickTexts.Any(i => i.ID == ViewModel.ClickText.ID)
) )
{ {
MessageBox.Show("此Id已存在".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); MessageBox.Show("此ID已存在".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning);
return; return;
} }
if (string.IsNullOrEmpty(ViewModel.ClickText.CurrentI18nData.Text)) if (string.IsNullOrEmpty(ViewModel.ClickText.CurrentI18nData.Text))

View File

@ -29,7 +29,7 @@
AutoGenerateColumns="False" AutoGenerateColumns="False"
CanUserAddRows="False" CanUserAddRows="False"
GridLinesVisibility="Horizontal" GridLinesVisibility="Horizontal"
ItemsSource="{Binding ShowClickTexts}" ItemsSource="{Binding ClickTexts.FilteredList}"
MouseDoubleClick="DataGrid_MouseDoubleClick" MouseDoubleClick="DataGrid_MouseDoubleClick"
RowDetailsVisibilityMode="Visible" RowDetailsVisibilityMode="Visible"
RowHeight="64" RowHeight="64"
@ -45,12 +45,12 @@
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn <DataGridTextColumn
MaxWidth="200" MaxWidth="200"
Binding="{Binding Id}" Binding="{Binding ID}"
CanUserSort="True" CanUserSort="True"
ElementStyle="{StaticResource TextBlock_Wrap}" ElementStyle="{StaticResource TextBlock_Wrap}"
Header="Id" Header="ID"
IsReadOnly="True" IsReadOnly="True"
SortMemberPath="Id" /> SortMemberPath="ID" />
<DataGridTextColumn <DataGridTextColumn
MaxWidth="300" MaxWidth="300"
Binding="{Binding CurrentI18nData.Text}" Binding="{Binding CurrentI18nData.Text}"

View File

@ -34,6 +34,6 @@ public partial class ClickTextPage : Page
{ {
if (sender is not DataGrid dataGrid || dataGrid.SelectedItem is not ClickTextModel model) if (sender is not DataGrid dataGrid || dataGrid.SelectedItem is not ClickTextModel model)
return; return;
ViewModel.Edit(model); ViewModel.EditCommand_ExecuteCommand(model);
} }
} }

View File

@ -62,8 +62,8 @@
<Label Content="Id" /> <Label Content="Id" />
<TextBox <TextBox
Grid.Column="1" Grid.Column="1"
pu:TextBoxHelper.Watermark="Id" pu:TextBoxHelper.Watermark="ID"
Text="{Binding Food.Id, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding Food.ID, UpdateSourceTrigger=PropertyChanged}" />
<Label Grid.Row="1" Content="{ll:Str 食物类型}" /> <Label Grid.Row="1" Content="{ll:Str 食物类型}" />
<ComboBox <ComboBox
x:Name="ComboBox_FoodType" x:Name="ComboBox_FoodType"

View File

@ -31,17 +31,11 @@ public partial class FoodEditWindow : Window
public FoodEditWindow() public FoodEditWindow()
{ {
InitializeComponent(); InitializeComponent();
DataContext = new FoodEditWindowVM(); this.SetDataContext<FoodEditWindowVM>(() =>
Closed += (s, e) =>
{ {
if (IsCancel) if (IsCancel)
ViewModel.Close(); ViewModel.Close();
try });
{
DataContext = null;
}
catch { }
};
} }
private void Button_Cancel_Click(object sender, RoutedEventArgs e) private void Button_Cancel_Click(object sender, RoutedEventArgs e)
@ -51,9 +45,9 @@ public partial class FoodEditWindow : Window
private void Button_Yes_Click(object sender, RoutedEventArgs e) private void Button_Yes_Click(object sender, RoutedEventArgs e)
{ {
if (string.IsNullOrWhiteSpace(ViewModel.Food.Id)) if (string.IsNullOrWhiteSpace(ViewModel.Food.ID))
{ {
MessageBox.Show("Id不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); MessageBox.Show("ID不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning);
return; return;
} }
if (ViewModel.Food.Image is null) if (ViewModel.Food.Image is null)
@ -62,11 +56,11 @@ public partial class FoodEditWindow : Window
return; return;
} }
if ( if (
ViewModel.OldFood?.Id != ViewModel.Food.Id ViewModel.OldFood?.ID != ViewModel.Food.ID
&& ModInfoModel.Current.Foods.Any(i => i.Id == ViewModel.Food.Id) && ModInfoModel.Current.Foods.Any(i => i.ID == ViewModel.Food.ID)
) )
{ {
MessageBox.Show("此Id已存在", "", MessageBoxButton.OK, MessageBoxImage.Warning); MessageBox.Show("此ID已存在", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return; return;
} }
IsCancel = false; IsCancel = false;

View File

@ -19,7 +19,7 @@
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBox <TextBox
pu:TextBoxHelper.Watermark="{ll:Str 搜索Id}" pu:TextBoxHelper.Watermark="{ll:Str 搜索ID}"
Style="{DynamicResource StandardTextBoxStyle}" Style="{DynamicResource StandardTextBoxStyle}"
Text="{Binding Search, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding Search, UpdateSourceTrigger=PropertyChanged}" />
<DataGrid <DataGrid
@ -29,7 +29,7 @@
AutoGenerateColumns="False" AutoGenerateColumns="False"
CanUserAddRows="False" CanUserAddRows="False"
GridLinesVisibility="Horizontal" GridLinesVisibility="Horizontal"
ItemsSource="{Binding ShowFoods}" ItemsSource="{Binding Foods.FilteredList}"
MouseDoubleClick="DataGrid_MouseDoubleClick" MouseDoubleClick="DataGrid_MouseDoubleClick"
RowDetailsVisibilityMode="Visible" RowDetailsVisibilityMode="Visible"
RowHeight="64" RowHeight="64"
@ -44,12 +44,12 @@
</DataGrid.RowStyle> </DataGrid.RowStyle>
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn <DataGridTextColumn
Binding="{Binding Id}" Binding="{Binding ID}"
CanUserSort="True" CanUserSort="True"
ElementStyle="{DynamicResource TextBlock_LeftCenter}" ElementStyle="{DynamicResource TextBlock_LeftCenter}"
Header="Id" Header="ID"
IsReadOnly="True" IsReadOnly="True"
SortMemberPath="Id" /> SortMemberPath="ID" />
<DataGridTemplateColumn Header="{ll:Str 食物图片}" IsReadOnly="True"> <DataGridTemplateColumn Header="{ll:Str 食物图片}" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>
<DataTemplate> <DataTemplate>

View File

@ -37,6 +37,6 @@ public partial class FoodPage : Page
{ {
if (sender is not DataGrid dataGrid || dataGrid.SelectedItem is not FoodModel model) if (sender is not DataGrid dataGrid || dataGrid.SelectedItem is not FoodModel model)
return; return;
ViewModel.Edit(model); ViewModel.EditCommand_ExecuteCommand(model);
} }
} }

View File

@ -26,7 +26,6 @@ public partial class I18nEditWindow : WindowX
public I18nEditWindow() public I18nEditWindow()
{ {
Current = this;
// 只隐藏, 不关闭 // 只隐藏, 不关闭
Closing += (s, e) => Closing += (s, e) =>
{ {
@ -47,10 +46,16 @@ public partial class I18nEditWindow : WindowX
}; };
InitializeComponent(); InitializeComponent();
DataContext = new I18nEditWindowVM(); DataContext = new I18nEditWindowVM();
//TODO
//ViewModel.CultureChanged += ViewModel_CultureChanged; //ViewModel.CultureChanged += ViewModel_CultureChanged;
//ViewModel.InitializeI18nData(ModInfoModel.Current); //ViewModel.InitializeI18nData(ModInfoModel.Current);
} }
public static void Initialize()
{
Current = new();
}
private bool _close = false; private bool _close = false;
public void Close(bool close) public void Close(bool close)

View File

@ -33,12 +33,12 @@
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Label Content="Id" /> <Label Content="ID" />
<TextBox <TextBox
Grid.Column="1" Grid.Column="1"
pu:TextBoxHelper.Watermark="Id" pu:TextBoxHelper.Watermark="ID"
Style="{StaticResource TextBox_Wrap}" Style="{StaticResource TextBox_Wrap}"
Text="{Binding LowText.Id, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding LowText.ID, UpdateSourceTrigger=PropertyChanged}" />
</Grid> </Grid>
<TextBox <TextBox
Grid.Row="1" Grid.Row="1"

View File

@ -29,15 +29,7 @@ public partial class LowTextEditWindow : Window
public LowTextEditWindow() public LowTextEditWindow()
{ {
InitializeComponent(); InitializeComponent();
DataContext = new LowTextEditWindowVM(); this.SetDataContext<LowTextEditWindowVM>();
Closed += (s, e) =>
{
try
{
DataContext = null;
}
catch { }
};
} }
private void Button_Cancel_Click(object sender, RoutedEventArgs e) private void Button_Cancel_Click(object sender, RoutedEventArgs e)
@ -47,17 +39,17 @@ public partial class LowTextEditWindow : Window
private void Button_Yes_Click(object sender, RoutedEventArgs e) private void Button_Yes_Click(object sender, RoutedEventArgs e)
{ {
if (string.IsNullOrEmpty(ViewModel.LowText.Id)) if (string.IsNullOrEmpty(ViewModel.LowText.ID))
{ {
MessageBox.Show("Id不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); MessageBox.Show("ID不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning);
return; return;
} }
if ( if (
ViewModel.OldLowText?.Id != ViewModel.LowText.Id ViewModel.OldLowText?.ID != ViewModel.LowText.ID
&& ModInfoModel.Current.LowTexts.Any(i => i.Id == ViewModel.LowText.Id) && ModInfoModel.Current.LowTexts.Any(i => i.ID == ViewModel.LowText.ID)
) )
{ {
MessageBox.Show("此Id已存在".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); MessageBox.Show("此ID已存在".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning);
return; return;
} }
if (string.IsNullOrEmpty(ViewModel.LowText.CurrentI18nData.Text)) if (string.IsNullOrEmpty(ViewModel.LowText.CurrentI18nData.Text))

View File

@ -19,7 +19,7 @@
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBox <TextBox
pu:TextBoxHelper.Watermark="{ll:Str 搜索Id}" pu:TextBoxHelper.Watermark="{ll:Str 搜索ID}"
Style="{DynamicResource StandardTextBoxStyle}" Style="{DynamicResource StandardTextBoxStyle}"
Text="{Binding Search, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding Search, UpdateSourceTrigger=PropertyChanged}" />
<DataGrid <DataGrid
@ -30,7 +30,7 @@
AutoGenerateColumns="False" AutoGenerateColumns="False"
CanUserAddRows="False" CanUserAddRows="False"
GridLinesVisibility="Horizontal" GridLinesVisibility="Horizontal"
ItemsSource="{Binding ShowLowTexts}" ItemsSource="{Binding LowTexts.FilteredList}"
MouseDoubleClick="DataGrid_LowText_MouseDoubleClick" MouseDoubleClick="DataGrid_LowText_MouseDoubleClick"
RowDetailsVisibilityMode="Visible" RowDetailsVisibilityMode="Visible"
RowHeight="64" RowHeight="64"
@ -46,12 +46,12 @@
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn <DataGridTextColumn
MaxWidth="200" MaxWidth="200"
Binding="{Binding Id}" Binding="{Binding ID}"
CanUserSort="True" CanUserSort="True"
ElementStyle="{StaticResource TextBlock_Wrap}" ElementStyle="{StaticResource TextBlock_Wrap}"
Header="Id" Header="ID"
IsReadOnly="True" IsReadOnly="True"
SortMemberPath="Id" /> SortMemberPath="ID" />
<DataGridTextColumn <DataGridTextColumn
MaxWidth="300" MaxWidth="300"
Binding="{Binding CurrentI18nData.Text}" Binding="{Binding CurrentI18nData.Text}"

View File

@ -37,6 +37,6 @@ public partial class LowTextPage : Page
{ {
if (sender is not DataGrid dataGrid || dataGrid.SelectedItem is not LowTextModel lowText) if (sender is not DataGrid dataGrid || dataGrid.SelectedItem is not LowTextModel lowText)
return; return;
ViewModel.Edit(lowText); ViewModel.EditCommand_ExecuteCommand(lowText);
} }
} }

View File

@ -88,10 +88,10 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Content="Id" /> <Label Content="ID" />
<TextBox <TextBox
Grid.Column="1" Grid.Column="1"
pu:TextBoxHelper.Watermark="Id" pu:TextBoxHelper.Watermark="ID"
Text="{Binding ModInfo.Id, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding ModInfo.Id, UpdateSourceTrigger=PropertyChanged}" />
<Label Grid.Row="1" Content="{ll:Str 作者}" /> <Label Grid.Row="1" Content="{ll:Str 作者}" />
<TextBox <TextBox

View File

@ -1,8 +1,4 @@
using LinePutScript.Localization.WPF; using System;
using Microsoft.Win32;
using Panuon.WPF;
using Panuon.WPF.UI;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Collections.Specialized; using System.Collections.Specialized;
@ -20,6 +16,10 @@ using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Shapes; using System.Windows.Shapes;
using LinePutScript.Localization.WPF;
using Microsoft.Win32;
using Panuon.WPF;
using Panuon.WPF.UI;
using VPet.ModMaker.Models; using VPet.ModMaker.Models;
using VPet.ModMaker.ViewModels.ModEdit; using VPet.ModMaker.ViewModels.ModEdit;
using VPet.ModMaker.Views.ModEdit.AnimeEdit; using VPet.ModMaker.Views.ModEdit.AnimeEdit;
@ -40,14 +40,14 @@ namespace VPet.ModMaker.Views.ModEdit;
public partial class ModEditWindow : WindowX public partial class ModEditWindow : WindowX
{ {
public ModEditWindowVM ViewModel => (ModEditWindowVM)DataContext; public ModEditWindowVM ViewModel => (ModEditWindowVM)DataContext;
public FoodPage FoodPage { get; } public FoodPage FoodPage { get; } = null!;
public LowTextPage LowTextPage { get; } public LowTextPage LowTextPage { get; } = null!;
public ClickTextPage ClickTextPage { get; } public ClickTextPage ClickTextPage { get; } = null!;
public SelectTextPage SelectTextPage { get; } public SelectTextPage SelectTextPage { get; } = null!;
public PetPage PetPage { get; } public PetPage PetPage { get; } = null!;
public WorkPage WorkPage { get; } public WorkPage WorkPage { get; } = null!;
public MovePage MovePage { get; } public MovePage MovePage { get; } = null!;
public AnimePage AnimePage { get; } public AnimePage AnimePage { get; } = null!;
public ModEditWindow() public ModEditWindow()
{ {
@ -60,9 +60,10 @@ public partial class ModEditWindow : WindowX
ClickTextPage = new(); ClickTextPage = new();
SelectTextPage = new(); SelectTextPage = new();
PetPage = new(); PetPage = new();
WorkPage = new(); //TODO
MovePage = new(); //WorkPage = new();
AnimePage = new(); //MovePage = new();
//AnimePage = new();
} }
/// <summary> /// <summary>
@ -77,7 +78,7 @@ public partial class ModEditWindow : WindowX
is not MessageBoxResult.Yes is not MessageBoxResult.Yes
) )
return; return;
ViewModel.AddCulture(); ViewModel.AddCultureCommand_ExecuteCommand();
if ( if (
I18nHelper.Current.CultureNames.Count == 0 I18nHelper.Current.CultureNames.Count == 0
|| MessageBox.Show( || MessageBox.Show(
@ -88,11 +89,11 @@ public partial class ModEditWindow : WindowX
is not MessageBoxResult.Yes is not MessageBoxResult.Yes
) )
return; return;
ViewModel.SetMainCulture(I18nHelper.Current.CultureNames.First()); ViewModel.SetMainCultureCommand_ExecuteCommand(I18nHelper.Current.CultureNames.First());
} }
} }
private void ModEditWindow_Closing(object sender, CancelEventArgs e) private void ModEditWindow_Closing(object? sender, CancelEventArgs e)
{ {
if ( if (
MessageBox.Show("确认退出吗?".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No MessageBox.Show("确认退出吗?".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No
@ -100,7 +101,7 @@ public partial class ModEditWindow : WindowX
e.Cancel = true; e.Cancel = true;
} }
private void ModEditWindow_Closed(object sender, EventArgs e) private void ModEditWindow_Closed(object? sender, EventArgs e)
{ {
ViewModel?.Close(); ViewModel?.Close();
try try

View File

@ -353,11 +353,11 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Content="Id" /> <Label Content="ID" />
<TextBox <TextBox
Grid.Column="1" Grid.Column="1"
pu:TextBoxHelper.Watermark="Id" pu:TextBoxHelper.Watermark="ID"
Text="{Binding Pet.Id, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding Pet.ID, UpdateSourceTrigger=PropertyChanged}" />
<!--<Label Grid.Row="1" Content="{ll:Str 名称}" /> <!--<Label Grid.Row="1" Content="{ll:Str 名称}" />
<TextBox <TextBox
Grid.Row="1" Grid.Row="1"

View File

@ -24,7 +24,7 @@
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBox <TextBox
pu:TextBoxHelper.Watermark="{ll:Str 搜索Id}" pu:TextBoxHelper.Watermark="{ll:Str 搜索ID}"
Style="{DynamicResource StandardTextBoxStyle}" Style="{DynamicResource StandardTextBoxStyle}"
Text="{Binding Search, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding Search, UpdateSourceTrigger=PropertyChanged}" />
<pu:Switch <pu:Switch
@ -39,7 +39,7 @@
AutoGenerateColumns="False" AutoGenerateColumns="False"
CanUserAddRows="False" CanUserAddRows="False"
GridLinesVisibility="Horizontal" GridLinesVisibility="Horizontal"
ItemsSource="{Binding ShowPets}" ItemsSource="{Binding Pets.FilteredList}"
MouseDoubleClick="DataGrid_MouseDoubleClick" MouseDoubleClick="DataGrid_MouseDoubleClick"
RowDetailsVisibilityMode="Visible" RowDetailsVisibilityMode="Visible"
RowHeight="64" RowHeight="64"
@ -66,13 +66,13 @@
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTemplateColumn <DataGridTemplateColumn
CanUserSort="True" CanUserSort="True"
Header="Id" Header="ID"
IsReadOnly="True" IsReadOnly="True"
SortMemberPath="Id"> SortMemberPath="ID">
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock Style="{DynamicResource TextBlock_LeftCenter}" Text="{Binding Id}" /> <TextBlock Style="{DynamicResource TextBlock_LeftCenter}" Text="{Binding ID}" />
<TextBlock <TextBlock
Style="{DynamicResource TextBlock_LeftCenter}" Style="{DynamicResource TextBlock_LeftCenter}"
Text="{ll:Str {} (来自本体)}" Text="{ll:Str {} (来自本体)}"

View File

@ -37,12 +37,12 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Label Content="Id" /> <Label Content="ID" />
<TextBox <TextBox
Grid.Column="1" Grid.Column="1"
pu:TextBoxHelper.Watermark="Id" pu:TextBoxHelper.Watermark="ID"
Style="{StaticResource TextBox_Wrap}" Style="{StaticResource TextBox_Wrap}"
Text="{Binding SelectText.Id, UpdateSourceTrigger=PropertyChanged}" Text="{Binding SelectText.ID, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" /> TextWrapping="Wrap" />
<Label Grid.Row="1" Content="{ll:Str 选项名}" /> <Label Grid.Row="1" Content="{ll:Str 选项名}" />
<TextBox <TextBox
@ -101,7 +101,7 @@
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Text="{Binding SelectText.Mode.Value}" /> <TextBlock Style="{DynamicResource TextBlock_LeftCenter}" Text="{Binding SelectText.Mode.Value}" />
<ComboBox <ComboBox
x:Name="ComboBox_Mode" x:Name="ComboBox_Mode"
Grid.Column="1" Grid.Column="1"

View File

@ -46,14 +46,14 @@ public partial class SelectTextEditWindow : Window
private void Button_Yes_Click(object sender, RoutedEventArgs e) private void Button_Yes_Click(object sender, RoutedEventArgs e)
{ {
if (string.IsNullOrWhiteSpace(ViewModel.SelectText.Id)) if (string.IsNullOrWhiteSpace(ViewModel.SelectText.ID))
{ {
MessageBox.Show("Id不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); MessageBox.Show("Id不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning);
return; return;
} }
if ( if (
ViewModel.OldSelectText?.Id != ViewModel.SelectText.Id ViewModel.OldSelectText?.ID != ViewModel.SelectText.ID
&& ModInfoModel.Current.SelectTexts.Any(i => i.Id == ViewModel.SelectText.Id) && ModInfoModel.Current.SelectTexts.Any(i => i.ID == ViewModel.SelectText.ID)
) )
{ {
MessageBox.Show("此Id已存在".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); MessageBox.Show("此Id已存在".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning);

View File

@ -19,7 +19,7 @@
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBox <TextBox
pu:TextBoxHelper.Watermark="{ll:Str 搜索Id}" pu:TextBoxHelper.Watermark="{ll:Str 搜索ID}"
Style="{DynamicResource StandardTextBoxStyle}" Style="{DynamicResource StandardTextBoxStyle}"
Text="{Binding Search, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding Search, UpdateSourceTrigger=PropertyChanged}" />
<DataGrid <DataGrid
@ -29,7 +29,7 @@
AutoGenerateColumns="False" AutoGenerateColumns="False"
CanUserAddRows="False" CanUserAddRows="False"
GridLinesVisibility="Horizontal" GridLinesVisibility="Horizontal"
ItemsSource="{Binding ShowSelectTexts}" ItemsSource="{Binding SelectTexts.FilteredList}"
MouseDoubleClick="DataGrid_MouseDoubleClick" MouseDoubleClick="DataGrid_MouseDoubleClick"
RowDetailsVisibilityMode="Visible" RowDetailsVisibilityMode="Visible"
RowHeight="64" RowHeight="64"
@ -45,12 +45,12 @@
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn <DataGridTextColumn
MaxWidth="200" MaxWidth="200"
Binding="{Binding Id}" Binding="{Binding ID}"
CanUserSort="True" CanUserSort="True"
ElementStyle="{StaticResource TextBlock_Wrap}" ElementStyle="{StaticResource TextBlock_Wrap}"
Header="Id" Header="ID"
IsReadOnly="True" IsReadOnly="True"
SortMemberPath="Id" /> SortMemberPath="ID" />
<DataGridTextColumn <DataGridTextColumn
MaxWidth="300" MaxWidth="300"
Binding="{Binding CurrentI18nData.Text}" Binding="{Binding CurrentI18nData.Text}"

View File

@ -34,6 +34,6 @@ public partial class SelectTextPage : Page
{ {
if (sender is not DataGrid dataGrid || dataGrid.SelectedItem is not SelectTextModel model) if (sender is not DataGrid dataGrid || dataGrid.SelectedItem is not SelectTextModel model)
return; return;
ViewModel.Edit(model); ViewModel.EditCommand_ExecuteCommand(model);
} }
} }