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>
public ObservableCollection<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);
public ObservableList<string> CultureNames { get; } = new();
}

View File

@ -4,7 +4,9 @@ using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HKW.HKWUtils.Extensions;
using HKW.HKWUtils.Observable;
using Mapster;
namespace VPet.ModMaker.Models;
@ -22,6 +24,7 @@ public class I18nModel<T> : ObservableObjectX<I18nModel<T>>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private T _currentI18nData;
[AdaptIgnore]
public T CurrentI18nData
{
get => _currentI18nData;
@ -32,65 +35,63 @@ public class I18nModel<T> : ObservableObjectX<I18nModel<T>>
/// <summary>
/// 所有I18n数据
/// </summary>
[AdaptIgnore]
public Dictionary<string, T> I18nDatas { get; } = new();
public I18nModel()
{
//TODO
//I18nHelper.Current.CultureName.ValueChanged += CultureChanged;
I18nHelper.Current.AddCulture += AddCulture;
I18nHelper.Current.RemoveCulture += RemoveCulture;
I18nHelper.Current.ReplaceCulture += ReplaceCulture;
if (I18nHelper.Current.CultureNames.Count == 0)
I18nHelper.Current.PropertyChangedX += Current_PropertyChangedX;
I18nHelper.Current.CultureNames.ListChanged += CultureNames_ListChanged;
if (I18nHelper.Current.CultureNames.HasValue() is false)
return;
foreach (var item in I18nHelper.Current.CultureNames)
{
I18nDatas.Add(item, new());
}
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>
/// <param name="oldValue"></param>
/// <param name="newValue"></param>
private void CultureChanged(ObservableValue<string> sender, ValueChangedEventArgs<string> e)
/// <param name="sender"></param>
/// <param name="e"></param>
private void Current_PropertyChangedX(I18nHelper sender, PropertyChangedXEventArgs 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);
if (e.PropertyName == nameof(I18nHelper.CultureName))
{
if (e.NewValue is null)
CurrentI18nData = null!;
else if (I18nDatas.TryGetValue((string)e.NewValue, out var result))
CurrentI18nData = result;
}
}
}

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.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
@ -8,6 +9,7 @@ using System.Threading.Tasks;
using HKW.HKWUtils;
using HKW.HKWUtils.Observable;
using LinePutScript.Converter;
using Mapster;
using VPet_Simulator.Windows.Interface;
namespace VPet.ModMaker.Models;
@ -17,35 +19,102 @@ namespace VPet.ModMaker.Models;
/// </summary>
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>
public static ObservableCollection<ClickText.ModeType> ModeTypes { get; } =
new(Enum.GetValues(typeof(ClickText.ModeType)).Cast<ClickText.ModeType>());
public static FrozenSet<ClickText.ModeType> ModeTypes { get; } =
Enum.GetValues<ClickText.ModeType>().ToFrozenSet();
/// <summary>
/// 日期区间
/// </summary>
public static ObservableCollection<ClickText.DayTime> DayTimes { get; } =
new(Enum.GetValues(typeof(ClickText.DayTime)).Cast<ClickText.DayTime>());
public static FrozenSet<ClickText.DayTime> DayTimes { get; } =
Enum.GetValues<ClickText.DayTime>().ToFrozenSet();
/// <summary>
/// 工作状态
/// </summary>
public static ObservableCollection<VPet_Simulator.Core.Main.WorkingState> WorkingStates { get; } =
new(
Enum.GetValues(typeof(VPet_Simulator.Core.Main.WorkingState))
.Cast<VPet_Simulator.Core.Main.WorkingState>()
);
public static FrozenSet<VPet_Simulator.Core.Main.WorkingState> WorkingStates { get; } =
Enum.GetValues<VPet_Simulator.Core.Main.WorkingState>().ToFrozenSet();
#region Id
#region ID
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _id = string.Empty;
/// <summary>
/// Id
/// ID
/// </summary>
public string Id
[AdaptMember(nameof(ClickText.Text))]
public string ID
{
get => _id;
set => SetProperty(ref _id, value);
@ -59,6 +128,7 @@ public class ClickTextModel : I18nModel<I18nClickTextModel>
/// <summary>
/// 指定工作
/// </summary>
[AdaptMember(nameof(ClickText.Working))]
public string Working
{
get => _working;
@ -79,21 +149,23 @@ public class ClickTextModel : I18nModel<I18nClickTextModel>
#region WorkingState
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private VPet_Simulator.Core.Main.WorkingState _WorkingState;
private VPet_Simulator.Core.Main.WorkingState _workingState;
/// <summary>
/// 行动状态
/// </summary>
[AdaptMember(nameof(ClickText.State))]
public VPet_Simulator.Core.Main.WorkingState WorkingState
{
get => _WorkingState;
set => SetProperty(ref _WorkingState, value);
get => _workingState;
set => SetProperty(ref _workingState, value);
}
#endregion
/// <summary>
/// 日期区间
/// </summary>
public ObservableEnumCommand<ClickText.DayTime> DayTime { get; } =
new(
ClickText.DayTime.Morning
@ -141,78 +213,11 @@ public class ClickTextModel : I18nModel<I18nClickTextModel>
/// 体力
/// </summary>
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
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
@ -225,10 +230,10 @@ public class I18nClickTextModel : ObservableObjectX<I18nClickTextModel>
}
#endregion
public I18nClickTextModel Copy()
public I18nClickTextModel Clone()
{
var result = new I18nClickTextModel();
result.Text = Text;
return result;
return this.Adapt<I18nClickTextModel>();
}
object ICloneable.Clone() => Clone();
}

View File

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

View File

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

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
@ -7,9 +8,12 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using CommunityToolkit.Mvvm.Collections;
using CommunityToolkit.Mvvm.ComponentModel;
using HKW.HKWUtils.Observable;
using LinePutScript;
using LinePutScript.Converter;
using Mapster;
using VPet_Simulator.Windows.Interface;
namespace VPet.ModMaker.Models;
@ -19,210 +23,9 @@ namespace VPet.ModMaker.Models;
/// </summary>
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()
{
DescriptionId = $"{Id}_{nameof(DescriptionId)}";
//DescriptionId = $"{Id}_{nameof(DescriptionId)}";
//TODO
//Id.ValueChanged += (s, e) =>
//{
@ -241,91 +44,310 @@ public class FoodModel : I18nModel<I18nFoodModel>
//{
// 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)
: this()
{
Id = model.Id;
DescriptionId = model.DescriptionId;
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();
model.Adapt(this);
Image = model.Image?.CloneStream();
foreach (var item in model.I18nDatas)
I18nDatas[item.Key] = item.Value.Copy();
I18nDatas[item.Key] = item.Value.Clone();
CurrentI18nData = I18nDatas[I18nHelper.Current.CultureName];
}
public FoodModel(Food food)
: this()
{
Id = food.Name;
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;
food.Adapt(this);
if (File.Exists(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()
{
return new Food()
{
Name = Id,
Desc = DescriptionId,
Graph = Graph,
Type = Type,
Strength = Strength,
StrengthFood = StrengthFood,
StrengthDrink = StrengthDrink,
Feeling = Feeling,
Health = Health,
Likability = Likability,
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;
return this.Adapt<Food>();
//return new Food()
//{
// Name = ID,
// Desc = DescriptionID,
// Graph = Graph,
// Type = Type,
// Strength = Strength,
// StrengthFood = StrengthFood,
// StrengthDrink = StrengthDrink,
// Feeling = Feeling,
// Health = Health,
// Likability = Likability,
// Price = Price,
// Exp = Exp,
//};
}
public void RefreshId()
{
DescriptionId = $"{Id}_{nameof(DescriptionId)}";
DescriptionID = $"{ID}_{nameof(DescriptionID)}";
}
public void Close()
{
Image.CloseStream();
Image?.CloseStream();
}
}
public class I18nFoodModel : ObservableObjectX<I18nFoodModel>
public class I18nFoodModel : ObservableObjectX<I18nFoodModel>, ICloneable<I18nFoodModel>
{
#region Name
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
@ -337,6 +359,7 @@ public class I18nFoodModel : ObservableObjectX<I18nFoodModel>
set => SetProperty(ref _name, value);
}
#endregion
#region Description
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _description = string.Empty;
@ -348,11 +371,7 @@ public class I18nFoodModel : ObservableObjectX<I18nFoodModel>
}
#endregion
public I18nFoodModel Copy()
{
var result = new I18nFoodModel();
result.Name = Name;
result.Description = Description;
return result;
}
public I18nFoodModel Clone() => this.Adapt<I18nFoodModel>();
object ICloneable.Clone() => Clone();
}

View File

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

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
@ -7,6 +8,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using HKW.HKWUtils.Observable;
using Mapster;
using VPet_Simulator.Windows.Interface;
namespace VPet.ModMaker.Models;
@ -16,32 +18,51 @@ namespace VPet.ModMaker.Models;
/// </summary>
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>
public static ObservableCollection<LowText.ModeType> ModeTypes { get; } =
new(Enum.GetValues(typeof(LowText.ModeType)).Cast<LowText.ModeType>());
public static FrozenSet<LowText.ModeType> ModeTypes { get; } =
Enum.GetValues<LowText.ModeType>().ToFrozenSet();
/// <summary>
/// 好感度类型
/// </summary>
public static ObservableCollection<LowText.LikeType> LikeTypes { get; } =
new(Enum.GetValues(typeof(LowText.LikeType)).Cast<LowText.LikeType>());
public static FrozenSet<LowText.LikeType> LikeTypes { get; } =
Enum.GetValues<LowText.LikeType>().ToFrozenSet();
/// <summary>
/// 体力类型
/// </summary>
public static ObservableCollection<LowText.StrengthType> StrengthTypes { get; } =
new(Enum.GetValues(typeof(LowText.StrengthType)).Cast<LowText.StrengthType>());
public static FrozenSet<LowText.StrengthType> StrengthTypes { get; } =
Enum.GetValues<LowText.StrengthType>().ToFrozenSet();
#region Id
#region ID
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _id = string.Empty;
/// <summary>
/// Id
/// ID
/// </summary>
public string Id
[AdaptMember(nameof(LowText.Text))]
public string ID
{
get => _id;
set => SetProperty(ref _id, value);
@ -55,6 +76,7 @@ public class LowTextModel : I18nModel<I18nLowTextModel>
/// <summary>
/// 状态
/// </summary>
[AdaptMember(nameof(LowText.Mode))]
public LowText.ModeType Mode
{
get => _mode;
@ -69,6 +91,7 @@ public class LowTextModel : I18nModel<I18nLowTextModel>
/// <summary>
/// 体力
/// </summary>
[AdaptMember(nameof(LowText.Strength))]
public LowText.StrengthType Strength
{
get => _strength;
@ -83,7 +106,7 @@ public class LowTextModel : I18nModel<I18nLowTextModel>
/// <summary>
/// 好感度
/// </summary>
[AdaptMember(nameof(LowText.Like))]
public LowText.LikeType Like
{
get => _like;
@ -91,45 +114,13 @@ public class LowTextModel : I18nModel<I18nLowTextModel>
}
#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()
{
return new()
{
Text = Id,
Mode = Mode,
Strength = Strength,
Like = Like,
};
return this.Adapt<LowText>();
}
}
public class I18nLowTextModel : ObservableObjectX<I18nLowTextModel>
public class I18nLowTextModel : ObservableObjectX<I18nLowTextModel>, ICloneable<I18nLowTextModel>
{
#region Text
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
@ -142,10 +133,10 @@ public class I18nLowTextModel : ObservableObjectX<I18nLowTextModel>
}
#endregion
public I18nLowTextModel Copy()
public I18nLowTextModel Clone()
{
var result = new I18nLowTextModel();
result.Text = Text;
return result;
return this.Adapt<I18nLowTextModel>();
}
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)
continue;
if (i18nData.TryGetValue(food.Id, out var name))
if (i18nData.TryGetValue(food.ID, out var name))
data.Name = name;
if (i18nData.TryGetValue(food.DescriptionId, out var description))
if (i18nData.TryGetValue(food.DescriptionID, out var description))
data.Description = description;
}
}
@ -463,7 +463,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
{
if (lowText.I18nDatas.TryGetValue(key, out var data) is false)
continue;
if (i18nData.TryGetValue(lowText.Id, out var text))
if (i18nData.TryGetValue(lowText.ID, out var text))
data.Text = text;
}
}
@ -474,7 +474,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
{
if (clickText.I18nDatas.TryGetValue(key, out var data) is false)
continue;
if (i18nData.TryGetValue(clickText.Id, out var text))
if (i18nData.TryGetValue(clickText.ID, out var text))
data.Text = text;
}
}
@ -485,9 +485,9 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
{
if (selectText.I18nDatas.TryGetValue(key, out var data) is false)
continue;
if (i18nData.TryGetValue(selectText.Id, out var text))
if (i18nData.TryGetValue(selectText.ID, out var text))
data.Text = text;
if (i18nData.TryGetValue(selectText.ChooseId, out var choose))
if (i18nData.TryGetValue(selectText.ChooseID, out var choose))
data.Choose = choose;
}
}
@ -519,7 +519,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
foreach (var food in Foods)
food.RefreshId();
foreach (var selectText in SelectTexts)
selectText.RefreshId();
selectText.RefreshID();
foreach (var pet in Pets)
pet.RefreshId();
}
@ -635,9 +635,9 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
lps.Add(LPSConvert.SerializeObjectToLine<Line>(food.ToFood(), "food"));
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]
.TryAdd(food.DescriptionId, food.I18nDatas[cultureName].Description);
.TryAdd(food.DescriptionID, food.I18nDatas[cultureName].Description);
}
}
File.WriteAllText(foodFile, lps.ToString());
@ -679,9 +679,9 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
lps.Add(LPSConvert.SerializeObjectToLine<Line>(text.ToSelectText(), "SelectText"));
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]
.TryAdd(text.ChooseId, text.I18nDatas[cultureName].Choose);
.TryAdd(text.ChooseID, text.I18nDatas[cultureName].Choose);
}
}
File.WriteAllText(textFile, lps.ToString());
@ -703,7 +703,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
lps.Add(LPSConvert.SerializeObjectToLine<Line>(text.ToLowText(), "lowfoodtext"));
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());
@ -725,7 +725,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
lps.Add(LPSConvert.SerializeObjectToLine<Line>(text.ToClickText(), "clicktext"));
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());
@ -768,7 +768,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
Directory.CreateDirectory(foodPath);
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.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
@ -6,6 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HKW.HKWUtils.Observable;
using Mapster;
using VPet.ModMaker.Models;
using VPet_Simulator.Windows.Interface;
@ -16,10 +18,53 @@ namespace VPet.ModMaker.Models;
/// </summary>
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>
public static ObservableCollection<ClickText.ModeType> ModeTypes => ClickTextModel.ModeTypes;
public static FrozenSet<ClickText.ModeType> ModeTypes => ClickTextModel.ModeTypes;
#region Tags
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
@ -49,17 +94,21 @@ public class SelectTextModel : I18nModel<I18nSelectTextModel>
}
#endregion
#region Id
#region ID
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _id = string.Empty;
/// <summary>
/// Id
/// ID
/// </summary>
public string Id
public string ID
{
get => _id;
set => SetProperty(ref _id, value);
set
{
SetProperty(ref _id, value);
RefreshID();
}
}
#endregion
@ -71,7 +120,7 @@ public class SelectTextModel : I18nModel<I18nSelectTextModel>
/// 选择Id
/// </summary>
public string ChooseId
public string ChooseID
{
get => _chooseId;
set => SetProperty(ref _chooseId, value);
@ -129,68 +178,19 @@ public class SelectTextModel : I18nModel<I18nSelectTextModel>
/// </summary>
public ObservableRange<double> Strength { get; } = new(0, int.MaxValue);
public SelectTextModel()
public void RefreshID()
{
ChooseId = $"{Id}_{nameof(ChooseId)}";
//TODO
//Id.ValueChanged += (s, e) =>
//{
// ChooseId.Value = $"{e.NewValue}_{nameof(ChooseId)}";
//};
ChooseID = $"{ID}_{nameof(ChooseID)}";
}
public SelectTextModel(SelectTextModel model)
: 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 = { ',', ' ' };
private static readonly char[] rs_splitChar = [',', ' '];
public SelectText ToSelectText()
{
return new()
{
Text = Id,
Choose = ChooseId,
Text = ID,
Choose = ChooseID,
Mode = Mode.Value,
Tags = new(Tags.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
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
@ -237,11 +239,10 @@ public class I18nSelectTextModel : ObservableObjectX<I18nSelectTextModel>
}
#endregion
public I18nSelectTextModel Copy()
public I18nSelectTextModel Clone()
{
var result = new I18nSelectTextModel();
result.Text = Text;
result.Choose = Choose;
return result;
return this.Adapt<I18nSelectTextModel>();
}
object ICloneable.Clone() => Clone();
}

View File

@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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">
<MenuItem
Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource AncestorType=Page, Mode=FindAncestor}}"
@ -47,7 +48,7 @@
<ListBox
ItemsSource="{Binding I18nData.CultureNames}"
ScrollViewer.VerticalScrollBarVisibility="Auto"
SelectedItem="{Binding I18nData.CultureName.Value}">
SelectedItem="{Binding I18nData.CultureName}">
<ListBox.ItemContainerStyle>
<Style BasedOn="{StaticResource {x:Type ListBoxItem}}" TargetType="ListBoxItem">
<Setter Property="Content" Value="{Binding}" />

View File

@ -54,7 +54,7 @@ public static class NativeExtensions
/// </summary>
/// <param name="image">图像</param>
/// <returns>复制的图像</returns>
public static BitmapImage Copy(this BitmapImage image)
public static BitmapImage CloneStream(this BitmapImage image)
{
if (image is null)
return null;
@ -64,10 +64,11 @@ public static class NativeExtensions
newImage.DecodePixelHeight = image.DecodePixelHeight;
try
{
using var bitmap = new Bitmap(image.StreamSource);
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.Seek(position, SeekOrigin.Begin);
newImage.StreamSource = ms;
}
finally
@ -270,7 +271,7 @@ public static class NativeExtensions
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()
{
window.DataContext = new T();
@ -278,6 +279,7 @@ public static class NativeExtensions
{
try
{
closedAction?.Invoke();
window.DataContext = null;
}
catch { }

View File

@ -16,18 +16,18 @@
<EmbeddedResource Include="Resources\food.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="VPet-Simulator.Core" Version="1.1.0" />
<PackageReference Include="VPet-Simulator.Windows.Interface" Version="1.1.0" />
<PackageReference Include="VPet-Simulator.Core" Version="1.1.0.1" />
<PackageReference Include="VPet-Simulator.Windows.Interface" Version="1.1.0.1" />
<PackageReference Include="LinePutScript" Version="1.11.6" />
<PackageReference Include="LinePutScript.Localization.WPF" Version="1.0.6" />
<PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" />
<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" />
</ItemGroup>
<ItemGroup>
<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="Mapster" Version="7.4.0" />
</ItemGroup>

View File

@ -19,32 +19,50 @@ public class AddCultureWindowVM : ObservableObjectX<AddCultureWindowVM>
/// </summary>
#region ShowCultures
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableCollection<string> _showCultures;
public ObservableCollection<string> ShowCultures
{
get => _showCultures;
set => SetProperty(ref _showCultures, value);
}
#endregion
private ObservableFilterList<string, ObservableList<string>> _allCultures = null!;
/// <summary>
/// 全部文化
/// </summary>
public static ObservableCollection<string> AllCultures { get; set; } =
new(LinePutScript.Localization.WPF.LocalizeCore.AvailableCultures);
public ObservableFilterList<string, ObservableList<string>> AllCultures
{
get => _allCultures;
set => SetProperty(ref _allCultures, value);
}
#endregion
/// <summary>
/// 当前文化
/// </summary>
#region Culture
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _culture;
private string _culture = string.Empty;
public string 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
@ -53,7 +71,7 @@ public class AddCultureWindowVM : ObservableObjectX<AddCultureWindowVM>
/// </summary>
#region CultureFullName
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _cultureFullName;
private string _cultureFullName = string.Empty;
public string CultureFullName
{
@ -67,64 +85,27 @@ public class AddCultureWindowVM : ObservableObjectX<AddCultureWindowVM>
/// </summary>
#region Search
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _Search;
private string _search = string.Empty;
public string Search
{
get => _Search;
set => SetProperty(ref _Search, value);
get => _search;
set
{
SetProperty(ref _search, value);
AllCultures.Refresh();
}
}
#endregion
public static string UnknownCulture = "未知文化".Translate();
public static string UnknownCulture => "未知文化".Translate();
public AddCultureWindowVM()
{
//TODO
//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))
AllCultures = new(LocalizeCore.AvailableCultures)
{
CultureFullName = UnknownCulture;
return;
}
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))
);
}
Filter = c => c.Contains(Search, StringComparison.OrdinalIgnoreCase),
FilteredList = new()
};
}
}

View File

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

View File

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

View File

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

View File

@ -17,19 +17,43 @@ namespace VPet.ModMaker.ViewModels.ModEdit.FoodEdit;
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 I18nHelper I18nData => I18nHelper.Current;
#region Value
public FoodModel OldFood { get; set; }
#region Property
public FoodModel? OldFood { get; set; }
#region Food
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private FoodModel _food;
private FoodModel _food = new();
public FoodModel 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
@ -40,27 +64,7 @@ public class FoodEditWindowVM : ObservableObjectX<FoodEditWindowVM>
public ObservableCommand<double> SetReferencePriceCommand { get; } = new();
#endregion
public FoodEditWindowVM()
{
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)
private void SetReferencePriceCommand_ExecuteCommand(double value)
{
Food.Price = value;
}
@ -70,28 +74,26 @@ public class FoodEditWindowVM : ObservableObjectX<FoodEditWindowVM>
Food.Close();
}
private void AddImage()
private void AddImageCommand_ExecuteCommand()
{
OpenFileDialog openFileDialog =
new()
{
Title = "选择图片".Translate(),
Filter = $"图片|*.jpg;*.jpeg;*.png;*.bmp".Translate()
};
var openFileDialog = new OpenFileDialog()
{
Title = "选择图片".Translate(),
Filter = $"图片|*.jpg;*.jpeg;*.png;*.bmp".Translate()
};
if (openFileDialog.ShowDialog() is true)
{
Food.Image = NativeUtils.LoadImageToMemoryStream(openFileDialog.FileName);
}
}
private void ChangeImage()
private void ChangeImageCommand_ExecuteCommand()
{
OpenFileDialog openFileDialog =
new()
{
Title = "选择图片".Translate(),
Filter = $"图片|*.jpg;*.jpeg;*.png;*.bmp".Translate()
};
var openFileDialog = new OpenFileDialog()
{
Title = "选择图片".Translate(),
Filter = $"图片|*.jpg;*.jpeg;*.png;*.bmp".Translate()
};
if (openFileDialog.ShowDialog() is true)
{
Food.Image?.StreamSource?.Close();

View File

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

View File

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

View File

@ -12,33 +12,48 @@ using HKW.HKWUtils.Observable;
using LinePutScript.Localization.WPF;
using VPet.ModMaker.Models;
using VPet.ModMaker.Views.ModEdit.LowTextEdit;
using Expression = System.Linq.Expressions.Expression;
namespace VPet.ModMaker.ViewModels.ModEdit.LowTextEdit;
public class LowTextPageVM : ObservableObjectX<LowTextPageVM>
{
#region Value
#region ShowLowTexts
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableCollection<LowTextModel> _showLowTexts;
public ObservableCollection<LowTextModel> ShowLowTexts
public LowTextPageVM()
{
get => _showLowTexts;
set => SetProperty(ref _showLowTexts, value);
LowTexts = new(ModInfoModel.Current.LowTexts)
{
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
public ObservableCollection<LowTextModel> LowTexts => ModInfoModel.Current.LowTexts;
#region Search
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _search;
private string _search = string.Empty;
public string Search
{
get => _search;
set => SetProperty(ref _search, value);
set
{
SetProperty(ref _search, value);
LowTexts.Refresh();
}
}
#endregion
#endregion
@ -48,33 +63,7 @@ public class LowTextPageVM : ObservableObjectX<LowTextPageVM>
public ObservableCommand<LowTextModel> RemoveCommand { get; } = new();
#endregion
public LowTextPageVM()
{
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()
private void AddCommand_ExecuteCommand()
{
var window = new LowTextEditWindow();
var vm = window.ViewModel;
@ -84,7 +73,7 @@ public class LowTextPageVM : ObservableObjectX<LowTextPageVM>
LowTexts.Add(vm.LowText);
}
public void Edit(LowTextModel model)
public void EditCommand_ExecuteCommand(LowTextModel model)
{
var window = new LowTextEditWindow();
var vm = window.ViewModel;
@ -94,22 +83,12 @@ public class LowTextPageVM : ObservableObjectX<LowTextPageVM>
if (window.IsCancel)
return;
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)
return;
if (ShowLowTexts.Count == LowTexts.Count)
{
LowTexts.Remove(model);
}
else
{
ShowLowTexts.Remove(model);
LowTexts.Remove(model);
}
LowTexts.Remove(model);
}
}

View File

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

View File

@ -16,29 +16,45 @@ namespace VPet.ModMaker.ViewModels.ModEdit.PetEdit;
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;
#region Value
#region Property
#region ShowPets
[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;
set => SetProperty(ref _showPets, value);
get => _pets;
set => SetProperty(ref _pets, value);
}
#endregion
public ObservableCollection<PetModel> Pets => ModInfoModel.Current.Pets;
#region Search
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _search;
private string _search = string.Empty;
public string Search
{
get => _search;
set => SetProperty(ref _search, value);
set
{
SetProperty(ref _search, value);
Pets.Refresh();
}
}
#endregion
#endregion
@ -47,33 +63,6 @@ public class PetPageVM : ObservableObjectX<PetPageVM>
public ObservableCommand<PetModel> EditCommand { get; } = new();
public ObservableCommand<PetModel> RemoveCommand { get; } = new();
#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() { }
@ -114,8 +103,6 @@ public class PetPageVM : ObservableObjectX<PetPageVM>
{
Pets[Pets.IndexOf(model)] = newPet;
}
if (ShowPets.Count != Pets.Count)
ShowPets[ShowPets.IndexOf(model)] = newPet;
model.Close();
}
@ -128,14 +115,6 @@ public class PetPageVM : ObservableObjectX<PetPageVM>
}
if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No)
return;
if (ShowPets.Count == Pets.Count)
{
Pets.Remove(model);
}
else
{
ShowPets.Remove(model);
Pets.Remove(model);
}
Pets.Remove(model);
}
}

View File

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

View File

@ -10,32 +10,49 @@ using HKW.HKWUtils.Observable;
using LinePutScript.Localization.WPF;
using VPet.ModMaker.Models;
using VPet.ModMaker.Views.ModEdit.SelectTextEdit;
using VPet_Simulator.Windows.Interface;
namespace VPet.ModMaker.ViewModels.ModEdit.SelectTextEdit;
public class SelectTextPageVM : ObservableObjectX<SelectTextPageVM>
{
#region Value
#region ShowSelectTexts
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private ObservableCollection<SelectTextModel> _showSelectTexts;
public ObservableCollection<SelectTextModel> ShowSelectTexts
public SelectTextPageVM()
{
get => _showSelectTexts;
set => SetProperty(ref _showSelectTexts, value);
SelectTexts = new(ModInfoModel.Current.SelectTexts)
{
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
public ObservableCollection<SelectTextModel> SelectTexts => ModInfoModel.Current.SelectTexts;
#region Search
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string _search;
private string _search = string.Empty;
public string Search
{
get => _search;
set => SetProperty(ref _search, value);
set
{
SetProperty(ref _search, value);
SelectTexts.Refresh();
}
}
#endregion
#endregion
@ -45,36 +62,7 @@ public class SelectTextPageVM : ObservableObjectX<SelectTextPageVM>
public ObservableCommand<SelectTextModel> RemoveCommand { get; } = new();
#endregion
public SelectTextPageVM()
{
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()
private void AddCommand_ExecuteCommand()
{
var window = new SelectTextEditWindow();
var vm = window.ViewModel;
@ -84,32 +72,22 @@ public class SelectTextPageVM : ObservableObjectX<SelectTextPageVM>
SelectTexts.Add(vm.SelectText);
}
public void Edit(SelectTextModel model)
public void EditCommand_ExecuteCommand(SelectTextModel model)
{
var window = new SelectTextEditWindow();
var vm = window.ViewModel;
vm.OldSelectText = model;
var newLowTest = vm.SelectText = new(model);
var newSelectText = vm.SelectText = new(model);
window.ShowDialog();
if (window.IsCancel)
return;
SelectTexts[SelectTexts.IndexOf(model)] = newLowTest;
if (ShowSelectTexts.Count != SelectTexts.Count)
ShowSelectTexts[ShowSelectTexts.IndexOf(model)] = newLowTest;
SelectTexts[SelectTexts.IndexOf(model)] = newSelectText;
}
private void Remove(SelectTextModel model)
private void RemoveCommand_ExecuteCommand(SelectTextModel model)
{
if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No)
return;
if (ShowSelectTexts.Count == SelectTexts.Count)
{
SelectTexts.Remove(model);
}
else
{
ShowSelectTexts.Remove(model);
SelectTexts.Remove(model);
}
SelectTexts.Remove(model);
}
}

View File

@ -88,7 +88,7 @@ public class ModMakerWindowVM : ObservableObjectX<ModMakerWindowVM>
LoadHistories();
ModMakerWindow = window;
//TODO
//ShowHistories.Value = Histories;
ShowHistories = Histories;
CreateNewModCommand.ExecuteCommand += CreateNewMod;
LoadModFromFileCommand.ExecuteCommand += LoadModFromFile;
ClearHistoriesCommand.ExecuteCommand += ClearHistories;
@ -124,7 +124,8 @@ public class ModMakerWindowVM : ObservableObjectX<ModMakerWindowVM>
var lps = new LPS(File.ReadAllText(ModMakerInfo.HistoryFile));
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))
Histories.Add(history);
}

View File

@ -40,14 +40,14 @@
Grid.Column="1"
Margin="10,0,0,0"
VerticalAlignment="Center"
Text="{Binding CultureFullName.Value}" />
Text="{Binding CultureFullName}" />
</Grid>
<TextBox
x:Name="TextBox_Lang"
Grid.Row="1"
pu:TextBoxHelper.Watermark="{ll:Str 文化名称}"
Style="{DynamicResource StandardTextBoxStyle}"
Text="{Binding Culture.Value, UpdateSourceTrigger=PropertyChanged}" />
Text="{Binding Culture, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Grid.Row="2">
<Hyperlink Click="Hyperlink_Click">
<TextBlock Text="{ll:Str 详情请参阅 Windows 支持的语言/区域名称列表中的“语言标记”列}" />
@ -84,11 +84,11 @@
<TextBox
pu:TextBoxHelper.Watermark="{ll:Str 搜索}"
Style="{DynamicResource StandardTextBoxStyle}"
Text="{Binding Search.Value, UpdateSourceTrigger=PropertyChanged}" />
Text="{Binding Search, UpdateSourceTrigger=PropertyChanged}" />
<ListBox
Grid.Row="1"
ItemsSource="{Binding ShowCultures.Value}"
SelectedItem="{Binding Culture.Value}" />
ItemsSource="{Binding AllCultures.FilteredList}"
SelectedItem="{Binding Culture}" />
</Grid>
</Grid>
</pu:WindowX>

View File

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

View File

@ -28,15 +28,7 @@ public partial class ClickTextEditWindow : Window
public ClickTextEditWindow()
{
InitializeComponent();
DataContext = new ClickTextEditWindowVM();
Closed += (s, e) =>
{
try
{
DataContext = null;
}
catch { }
};
this.SetDataContext<ClickTextEditWindowVM>();
}
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)
{
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;
}
if (
ViewModel.OldClickText?.Id != ViewModel.ClickText.Id
&& ModInfoModel.Current.ClickTexts.Any(i => i.Id == ViewModel.ClickText.Id)
ViewModel.OldClickText?.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;
}
if (string.IsNullOrEmpty(ViewModel.ClickText.CurrentI18nData.Text))

View File

@ -29,7 +29,7 @@
AutoGenerateColumns="False"
CanUserAddRows="False"
GridLinesVisibility="Horizontal"
ItemsSource="{Binding ShowClickTexts}"
ItemsSource="{Binding ClickTexts.FilteredList}"
MouseDoubleClick="DataGrid_MouseDoubleClick"
RowDetailsVisibilityMode="Visible"
RowHeight="64"
@ -45,12 +45,12 @@
<DataGrid.Columns>
<DataGridTextColumn
MaxWidth="200"
Binding="{Binding Id}"
Binding="{Binding ID}"
CanUserSort="True"
ElementStyle="{StaticResource TextBlock_Wrap}"
Header="Id"
Header="ID"
IsReadOnly="True"
SortMemberPath="Id" />
SortMemberPath="ID" />
<DataGridTextColumn
MaxWidth="300"
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)
return;
ViewModel.Edit(model);
ViewModel.EditCommand_ExecuteCommand(model);
}
}

View File

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

View File

@ -31,17 +31,11 @@ public partial class FoodEditWindow : Window
public FoodEditWindow()
{
InitializeComponent();
DataContext = new FoodEditWindowVM();
Closed += (s, e) =>
this.SetDataContext<FoodEditWindowVM>(() =>
{
if (IsCancel)
ViewModel.Close();
try
{
DataContext = null;
}
catch { }
};
});
}
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)
{
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;
}
if (ViewModel.Food.Image is null)
@ -62,11 +56,11 @@ public partial class FoodEditWindow : Window
return;
}
if (
ViewModel.OldFood?.Id != ViewModel.Food.Id
&& ModInfoModel.Current.Foods.Any(i => i.Id == ViewModel.Food.Id)
ViewModel.OldFood?.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;
}
IsCancel = false;

View File

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

View File

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

View File

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

View File

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

View File

@ -29,15 +29,7 @@ public partial class LowTextEditWindow : Window
public LowTextEditWindow()
{
InitializeComponent();
DataContext = new LowTextEditWindowVM();
Closed += (s, e) =>
{
try
{
DataContext = null;
}
catch { }
};
this.SetDataContext<LowTextEditWindowVM>();
}
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)
{
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;
}
if (
ViewModel.OldLowText?.Id != ViewModel.LowText.Id
&& ModInfoModel.Current.LowTexts.Any(i => i.Id == ViewModel.LowText.Id)
ViewModel.OldLowText?.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;
}
if (string.IsNullOrEmpty(ViewModel.LowText.CurrentI18nData.Text))

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -46,14 +46,14 @@ public partial class SelectTextEditWindow : Window
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);
return;
}
if (
ViewModel.OldSelectText?.Id != ViewModel.SelectText.Id
&& ModInfoModel.Current.SelectTexts.Any(i => i.Id == ViewModel.SelectText.Id)
ViewModel.OldSelectText?.ID != ViewModel.SelectText.ID
&& ModInfoModel.Current.SelectTexts.Any(i => i.ID == ViewModel.SelectText.ID)
)
{
MessageBox.Show("此Id已存在".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning);

View File

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