From b34d44194f07e27cfb781c38c90be77f65e921d2 Mon Sep 17 00:00:00 2001 From: Hakoyu Date: Sat, 16 Sep 2023 02:57:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Converters/CalculatorConverter.cs | 57 ++++--- VPet.ModMaker/Models/EnumFlagsVM.cs | 6 +- VPet.ModMaker/Models/ModLoader.cs | 6 +- VPet.ModMaker/Models/ModModel/AnimeModel.cs | 149 ++++++++++++++++-- .../Models/ModModel/ClickTextModel.cs | 16 +- VPet.ModMaker/Models/ModModel/ImageModel.cs | 6 +- VPet.ModMaker/Models/ModModel/ModInfoModel.cs | 44 +++++- VPet.ModMaker/Models/ModModel/MoveModel.cs | 6 +- VPet.ModMaker/Models/ModModel/PetModel.cs | 17 +- .../Models/ModModel/SelectTextModel.cs | 8 +- VPet.ModMaker/Models/ModModel/WorkModel.cs | 19 ++- .../SimpleObservable/ObservableValue.cs | 2 +- VPet.ModMaker/Templates.xaml | 12 ++ VPet.ModMaker/VPet.ModMaker.csproj | 5 +- .../ModEdit/AnimeEdit/AnimePageVM.cs | 109 +++++++++++++ .../ClickTextEdit/ClickTextEditWindowVM.cs | 2 + .../ModEdit/FoodEdit/FoodEditWindowVM.cs | 1 + .../LowTextEdit/LowTextEditWindowVM.cs | 1 + .../ViewModels/ModEdit/ModEditWindowVM.cs | 29 ++++ .../ModEdit/PetEdit/PetEditWindowVM.cs | 3 +- .../SelectTextEdit/SelectTextEditWindowVM.cs | 1 + .../ModEdit/WorkEdit/WorkEditWindowVM.cs | 3 +- VPet.ModMaker/ViewModels/ModMakerWindowVM.cs | 15 +- .../Views/ModEdit/AddLangWindow.xaml | 2 +- .../ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs | 8 + .../ClickTextEdit/ClickTextEditWindow.xaml | 65 ++++++-- .../ClickTextEdit/ClickTextEditWindow.xaml.cs | 8 + .../ModEdit/ClickTextEdit/ClickTextPage.xaml | 8 +- .../ModEdit/FoodEdit/FoodEditWindow.xaml | 9 +- .../ModEdit/FoodEdit/FoodEditWindow.xaml.cs | 10 +- .../LowTextEdit/LowTextEditWindow.xaml | 5 +- .../LowTextEdit/LowTextEditWindow.xaml.cs | 8 + .../Views/ModEdit/ModEditWindow.xaml | 2 +- .../Views/ModEdit/ModEditWindow.xaml.cs | 12 ++ .../ModEdit/MoveEdit/MoveEditWindow.xaml | 1 + .../ModEdit/MoveEdit/MoveEditWindow.xaml.cs | 5 + .../Views/ModEdit/PetEdit/PetEditWindow.xaml | 36 ++--- .../ModEdit/PetEdit/PetEditWindow.xaml.cs | 5 + .../SelectTextEdit/SelectTextEditWindow.xaml | 53 ++++--- .../SelectTextEditWindow.xaml.cs | 8 + .../ModEdit/WorkEdit/WorkEditWindow.xaml | 17 +- .../ModEdit/WorkEdit/WorkEditWindow.xaml.cs | 5 + .../Views/ModEdit/WorkEdit/WorkPage.xaml | 9 ++ VPet.ModMaker/Views/ModMakerWindow.xaml | 1 + 44 files changed, 632 insertions(+), 162 deletions(-) create mode 100644 VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimePageVM.cs diff --git a/VPet.ModMaker/Converters/CalculatorConverter.cs b/VPet.ModMaker/Converters/CalculatorConverter.cs index 3ecd371..c87c747 100644 --- a/VPet.ModMaker/Converters/CalculatorConverter.cs +++ b/VPet.ModMaker/Converters/CalculatorConverter.cs @@ -23,6 +23,14 @@ namespace VPet.ModMaker.Converters; /// /// /// +/// // +/// +/// +/// +/// +/// +/// +/// /// ]]> /// /// 绑定的数量不正确 @@ -30,28 +38,40 @@ public class CalculatorConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { - if (System.Convert.ToBoolean(values.Length & 1) is false) - throw new Exception("Parameter error: Incorrect quantity"); if (values.Length == 1) return values[0]; - bool isNumber = false; - double result = (double)values[0]; - char currentOperator = '0'; - for (int i = 1; i < values.Length - 1; i++) + double result = System.Convert.ToDouble(values[0]); + if (parameter is string operators) { - if (isNumber is false) - { - currentOperator = ((string)values[i])[0]; - isNumber = true; - } - else - { - var value = System.Convert.ToDouble(values[i]); - result = Operation(result, currentOperator, value); - isNumber = false; - } + if (operators.Length != values.Length - 1) + throw new Exception("Parameter error: operator must be one more than parameter"); + for (int i = 1; i < values.Length - 1; i++) + result = Operation(result, operators[i - 1], System.Convert.ToDouble(values[i])); + result = Operation(result, operators.Last(), System.Convert.ToDouble(values.Last())); } - return Operation(result, currentOperator, System.Convert.ToDouble(values.Last())); + else + { + if (System.Convert.ToBoolean(values.Length & 1) is false) + throw new Exception("Parameter error: Incorrect quantity"); + bool isNumber = false; + char currentOperator = '0'; + for (int i = 1; i < values.Length - 1; i++) + { + if (isNumber is false) + { + currentOperator = ((string)values[i])[0]; + isNumber = true; + } + else + { + var value = System.Convert.ToDouble(values[i]); + result = Operation(result, currentOperator, value); + isNumber = false; + } + } + result = Operation(result, currentOperator, System.Convert.ToDouble(values.Last())); + } + return result; } public static double Operation(double value1, char operatorChar, double value2) @@ -62,6 +82,7 @@ public class CalculatorConverter : IMultiValueConverter '-' => value1 - value2, '*' => value1 * value2, '/' => value1 / value2, + '%' => value1 % value2, _ => throw new NotImplementedException(), }; } diff --git a/VPet.ModMaker/Models/EnumFlagsVM.cs b/VPet.ModMaker/Models/EnumFlagsVM.cs index 02e6c25..f711b0b 100644 --- a/VPet.ModMaker/Models/EnumFlagsVM.cs +++ b/VPet.ModMaker/Models/EnumFlagsVM.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace VPet.ModMaker.Models; -public class EnumFlagsVM +public class ObservableEnumFlagsVM where T : Enum { public ObservableValue EnumValue { get; } = new(); @@ -18,13 +18,13 @@ public class EnumFlagsVM public Type EnumType = typeof(T); public Type UnderlyingType { get; } = Enum.GetUnderlyingType(typeof(T)); - public EnumFlagsVM() + public ObservableEnumFlagsVM() { AddCommand.ExecuteEvent += AddCommand_ExecuteEvent; RemoveCommand.ExecuteEvent += RemoveCommand_ExecuteEvent; } - public EnumFlagsVM(T value) + public ObservableEnumFlagsVM(T value) : this() { EnumValue.Value = value; diff --git a/VPet.ModMaker/Models/ModLoader.cs b/VPet.ModMaker/Models/ModLoader.cs index e966aaf..a1ac26b 100644 --- a/VPet.ModMaker/Models/ModLoader.cs +++ b/VPet.ModMaker/Models/ModLoader.cs @@ -94,14 +94,12 @@ public class ModLoader var name = lps.First().Info; var pet = new PetLoader(lps, di); Pets.Add(pet); - // 此方法会导致 LoadImageToStream 无法使用 + // TODO : 此方法会导致 LoadImageToStream 无法使用 //var graphCore = new GraphCore(0); //foreach (var p in pet.path) // PetLoader.LoadGraph(graphCore, di, p); //MultiGraphs.Add(pet.Name, graphCore); - - //var p = mw.Pets.FirstOrDefault(x => x.Id == name); //if (p == null) // mw.Pets.Add(new PetLoader(lps, di)); @@ -202,7 +200,7 @@ public class ModLoader foreach (var item in lps) { if (OtherI18nDatas[dis.Name].ContainsKey(item.Name) is false) - OtherI18nDatas[dis.Name].Add(item.Name, item.Info); + OtherI18nDatas[dis.Name].TryAdd(item.Name, item.Info); } } } diff --git a/VPet.ModMaker/Models/ModModel/AnimeModel.cs b/VPet.ModMaker/Models/ModModel/AnimeModel.cs index 8bf8f15..7bba9d8 100644 --- a/VPet.ModMaker/Models/ModModel/AnimeModel.cs +++ b/VPet.ModMaker/Models/ModModel/AnimeModel.cs @@ -14,24 +14,149 @@ namespace VPet.ModMaker.Models.ModModel; public class AnimeModel { - public ObservableValue Id { get; } = new(); - public ObservableValue AnimeType { get; } = new(); + public static ObservableCollection GraphTypes { get; } = + new(Enum.GetValues(typeof(GraphInfo.GraphType)).Cast()); + public static ObservableCollection AnimatTypes { get; } = + new(Enum.GetValues(typeof(GraphInfo.AnimatType)).Cast()); - public ObservableCollection> MultiHappyImageModels = new(); - public ObservableCollection> MultiNomalImageModels = new(); - public ObservableCollection> MultiPoorConditionImageModels = - new(); - public ObservableCollection> MultiIllImageModels = new(); + public static ObservableCollection ModeTypes { get; } = + new(Enum.GetValues(typeof(GameSave.ModeType)).Cast()); + + public ObservableValue Id { get; } = new(); + + public ObservableValue GraphType { get; } = new(); + public ObservableValue AnimeType { get; } = new(); + public ObservableValue ModeType { get; } = new(); + + public ObservableCollection MultiHappyImageModels = new(); + public ObservableCollection MultiNomalImageModels = new(); + public ObservableCollection MultiPoorConditionImageModels = new(); + public ObservableCollection MultiIllImageModels = new(); public AnimeModel() { } - public AnimeModel(string name, AnimatType animatType, IList graphList) + //public AnimeModel() + //{ + + //} + + public static AnimeModel? Load(string path) { - Id.Value = name; - AnimeType.Value = animatType; - foreach (IGraph graph in graphList) + var model = new AnimeModel(); + var infoFile = Path.Combine(path, ModMakerInfo.InfoFile); + + if ( + Enum.TryParse(Path.GetFileName(path), true, out var graphType) + is false + ) + return null; + if (graphType is GraphInfo.GraphType.Default) { - //if(graph.) + foreach (var dir in Directory.EnumerateDirectories(path)) + { + var dirName = Path.GetFileName(dir); + if ( + dirName.Contains( + nameof(GameSave.ModeType.Happy), + StringComparison.OrdinalIgnoreCase + ) + ) + { + if (Directory.GetFiles(dir).Length == 0) + { + foreach (var imageDir in Directory.EnumerateDirectories(dir)) + { + model.MultiHappyImageModels.Add(new(imageDir)); + } + } + else + { + model.MultiHappyImageModels.Add(new(dir)); + } + } + else if ( + dirName.Contains( + nameof(GameSave.ModeType.Nomal), + StringComparison.OrdinalIgnoreCase + ) + ) + { + if (Directory.GetFiles(dir).Length == 0) + { + foreach (var imageDir in Directory.EnumerateDirectories(dir)) + { + model.MultiNomalImageModels.Add(new(imageDir)); + } + } + else + { + model.MultiNomalImageModels.Add(new(dir)); + } + } + else if ( + dirName.Contains( + nameof(GameSave.ModeType.PoorCondition), + StringComparison.OrdinalIgnoreCase + ) + ) + { + if (Directory.GetFiles(dir).Length == 0) + { + foreach (var imageDir in Directory.EnumerateDirectories(dir)) + { + model.MultiPoorConditionImageModels.Add(new(imageDir)); + } + } + else + { + model.MultiPoorConditionImageModels.Add(new(dir)); + } + } + else if ( + dirName.Contains( + nameof(GameSave.ModeType.Ill), + StringComparison.OrdinalIgnoreCase + ) + ) + { + if (Directory.GetFiles(dir).Length == 0) + { + foreach (var imageDir in Directory.EnumerateDirectories(dir)) + { + model.MultiIllImageModels.Add(new(imageDir)); + } + } + else + { + model.MultiIllImageModels.Add(new(dir)); + } + } + } + } + else + return null; + + return model; + } +} + +public class ImageModels : ObservableCollection +{ + private static readonly char[] _splits = new char[] { '_' }; + + public ImageModels(string imagePath) + { + foreach (var file in Directory.EnumerateFiles(imagePath)) + { + var info = Path.GetFileNameWithoutExtension(file) + .Split(_splits, StringSplitOptions.RemoveEmptyEntries); + var id = info[0]; + var duration = info.Last(); + var imageModel = new ImageModel(); + imageModel.Id.Value = id; + imageModel.Image.Value = Utils.LoadImageToMemoryStream(file); + imageModel.Duration.Value = int.Parse(duration); + Add(imageModel); } } } diff --git a/VPet.ModMaker/Models/ModModel/ClickTextModel.cs b/VPet.ModMaker/Models/ModModel/ClickTextModel.cs index a5d690e..89f6ec4 100644 --- a/VPet.ModMaker/Models/ModModel/ClickTextModel.cs +++ b/VPet.ModMaker/Models/ModModel/ClickTextModel.cs @@ -24,9 +24,9 @@ public class ClickTextModel : I18nModel public ObservableValue Id { get; } = new(); public ObservableValue Working { get; } = new(); - public ObservableValue Mode { get; } = new(); + public ObservableEnumFlagsVM Mode { get; } = new(); public ObservableValue WorkingState { get; } = new(); - public ObservableValue DayTime { get; } = new(); + public ObservableEnumFlagsVM DayTime { get; } = new(); public ObservableRange Like { get; } = new(0, int.MaxValue); public ObservableRange Health { get; } = new(0, int.MaxValue); @@ -43,10 +43,10 @@ public class ClickTextModel : I18nModel : this() { Id.Value = clickText.Id.Value; - Mode.Value = clickText.Mode.Value; + Mode.EnumValue.Value = clickText.Mode.EnumValue.Value; Working.Value = clickText.Working.Value; WorkingState.Value = clickText.WorkingState.Value; - DayTime.Value = clickText.DayTime.Value; + DayTime.EnumValue.Value = clickText.DayTime.EnumValue.Value; Like = clickText.Like.Copy(); Health = clickText.Health.Copy(); Level = clickText.Level.Copy(); @@ -64,10 +64,10 @@ public class ClickTextModel : I18nModel : this() { Id.Value = clickText.Text; - Mode.Value = clickText.Mode; + Mode.EnumValue.Value = clickText.Mode; Working.Value = clickText.Working; WorkingState.Value = clickText.State; - DayTime.Value = clickText.DaiTime; + DayTime.EnumValue.Value = clickText.DaiTime; Like.SetValue(clickText.LikeMin, clickText.LikeMax); Health.SetValue(clickText.HealthMin, clickText.HealthMax); Level.SetValue(clickText.LevelMin, clickText.LevelMax); @@ -83,10 +83,10 @@ public class ClickTextModel : I18nModel return new() { Text = Id.Value, - Mode = Mode.Value, + Mode = Mode.EnumValue.Value, Working = Working.Value, State = WorkingState.Value, - DaiTime = DayTime.Value, + DaiTime = DayTime.EnumValue.Value, LikeMax = Like.Max.Value, LikeMin = Like.Min.Value, HealthMin = Health.Min.Value, diff --git a/VPet.ModMaker/Models/ModModel/ImageModel.cs b/VPet.ModMaker/Models/ModModel/ImageModel.cs index 657572d..c543215 100644 --- a/VPet.ModMaker/Models/ModModel/ImageModel.cs +++ b/VPet.ModMaker/Models/ModModel/ImageModel.cs @@ -10,12 +10,8 @@ namespace VPet.ModMaker.Models.ModModel; public class ImageModel { + public ObservableValue Id { get; } = new(); public ObservableValue Image { get; } = new(); public ObservableValue Duration { get; } = new(100); - - public ImageModel(BitmapImage image) - { - Image.Value = image; - } } diff --git a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs index 412eb9b..8922942 100644 --- a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs +++ b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs @@ -12,6 +12,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Media.Imaging; +using VPet.ModMaker.Models.ModModel; using VPet_Simulator.Windows.Interface; namespace VPet.ModMaker.Models; @@ -58,8 +59,6 @@ public class ModInfoModel : I18nModel GameVersion.Value = loader.GameVer.ToString(); ModVersion.Value = loader.Ver.ToString(); var imagePath = Path.Combine(loader.ModPath.FullName, "icon.png"); - Thread.Sleep(1000); - GC.Collect(); if (File.Exists(imagePath)) Image.Value = Utils.LoadImageToStream(imagePath); foreach (var food in loader.Foods) @@ -71,7 +70,22 @@ public class ModInfoModel : I18nModel foreach (var selectText in loader.SelectTexts) SelectTexts.Add(new(selectText)); foreach (var pet in loader.Pets) - Pets.Add(new(pet)); + { + var petModel = new PetModel(pet); + Pets.Add(petModel); + // TODO: 动画加载 + //foreach (var p in pet.path) + //{ + // foreach (var dir in Directory.EnumerateDirectories(p)) + // { + // var animeModel = AnimeModel.Load(dir); + // if (animeModel != null) + // { + // petModel.Animes.TryAdd(animeModel.GraphType.Value, animeModel); + // } + // } + //} + } foreach (var lang in loader.I18nDatas) I18nDatas.Add(lang.Key, lang.Value); @@ -214,6 +228,21 @@ public class ModInfoModel : I18nModel GetWorksInfo(lps, pet); GetMoveInfo(lps, pet); File.WriteAllText(petFile, lps.ToString()); + foreach (var cultureName in I18nHelper.Current.CultureNames) + { + _saveI18nDatas[cultureName].TryAdd( + pet.Id.Value, + pet.I18nDatas[cultureName].Name.Value + ); + _saveI18nDatas[cultureName].TryAdd( + pet.PetNameId.Value, + pet.I18nDatas[cultureName].PetName.Value + ); + _saveI18nDatas[cultureName].TryAdd( + pet.DescriptionId.Value, + pet.I18nDatas[cultureName].Description.Value + ); + } } } @@ -458,6 +487,15 @@ public class ModInfoModel : I18nModel } } } + + public void Close() + { + Image.Value.CloseStream(); + foreach (var food in Foods) + food.Close(); + //foreach (var pet in Pets) + // pet.Close(); + } } public class I18nModInfoModel diff --git a/VPet.ModMaker/Models/ModModel/MoveModel.cs b/VPet.ModMaker/Models/ModModel/MoveModel.cs index e0d8237..307d1ac 100644 --- a/VPet.ModMaker/Models/ModModel/MoveModel.cs +++ b/VPet.ModMaker/Models/ModModel/MoveModel.cs @@ -36,12 +36,12 @@ public class MoveModel public ObservableValue TriggerTop { get; } = new(100); public ObservableValue TriggerBottom { get; } = new(100); - public EnumFlagsVM LocateType { get; } = + public ObservableEnumFlagsVM LocateType { get; } = new(GraphHelper.Move.DirectionType.None); - public EnumFlagsVM TriggerType { get; } = + public ObservableEnumFlagsVM TriggerType { get; } = new(GraphHelper.Move.DirectionType.None); - public EnumFlagsVM ModeType { get; } = + public ObservableEnumFlagsVM ModeType { get; } = new(GraphHelper.Move.ModeType.Nomal); public MoveModel() { } diff --git a/VPet.ModMaker/Models/ModModel/PetModel.cs b/VPet.ModMaker/Models/ModModel/PetModel.cs index 37ec374..a94f3fe 100644 --- a/VPet.ModMaker/Models/ModModel/PetModel.cs +++ b/VPet.ModMaker/Models/ModModel/PetModel.cs @@ -26,8 +26,7 @@ public class PetModel : I18nModel public ObservableCollection Moves { get; } = new(); public ObservableValue CurrentAnime { get; } = new(); - public Dictionary> Animes { get; } = - new(); + public Dictionary Animes { get; } = new(); public PetModel() { @@ -117,20 +116,6 @@ public class PetModel : I18nModel Moves.Add(new(move)); } - public void LoadAnime(GraphCore core) - { - foreach (var info in core.GraphsName) - { - var list = new ObservableCollection(); - foreach (var name in info.Value) - { - foreach (var graph in core.GraphsList[name]) - list.Add(new AnimeModel(name, graph.Key, graph.Value)); - } - Animes.Add(info.Key, list); - } - } - public void Close() { } } diff --git a/VPet.ModMaker/Models/ModModel/SelectTextModel.cs b/VPet.ModMaker/Models/ModModel/SelectTextModel.cs index 36f764e..629a446 100644 --- a/VPet.ModMaker/Models/ModModel/SelectTextModel.cs +++ b/VPet.ModMaker/Models/ModModel/SelectTextModel.cs @@ -28,7 +28,7 @@ public class SelectTextModel : I18nModel public ObservableValue Id { get; } = new(); public ObservableValue ChooseId { get; } = new(); - public ObservableValue Mode { get; } = new(); + public ObservableEnumFlagsVM Mode { get; } = new(); //public ObservableValue Working { get; } = new(); //public ObservableValue WorkingState { get; } = new(); @@ -56,7 +56,7 @@ public class SelectTextModel : I18nModel : this() { Id.Value = model.Id.Value; - Mode.Value = model.Mode.Value; + Mode.EnumValue.Value = model.Mode.EnumValue.Value; Tags.Value = model.Tags.Value; ToTags.Value = model.ToTags.Value; //Working.EnumValue = model.Working.EnumValue; @@ -81,7 +81,7 @@ public class SelectTextModel : I18nModel { Id.Value = text.Text; ChooseId.Value = text.Choose ?? string.Empty; - Mode.Value = text.Mode; + Mode.EnumValue.Value = text.Mode; Tags.Value = text.Tags is null ? string.Empty : string.Join(", ", text.Tags); ToTags.Value = text.ToTags is null ? string.Empty : string.Join(", ", text.ToTags); //Working.EnumValue = text.Working; @@ -105,7 +105,7 @@ public class SelectTextModel : I18nModel { Text = Id.Value, Choose = ChooseId.Value, - Mode = Mode.Value, + Mode = Mode.EnumValue.Value, Tags = new(Tags.Value.Split(rs_splitChar, StringSplitOptions.RemoveEmptyEntries)), ToTags = new(ToTags.Value.Split(rs_splitChar, StringSplitOptions.RemoveEmptyEntries)), //Working = Working.EnumValue, diff --git a/VPet.ModMaker/Models/ModModel/WorkModel.cs b/VPet.ModMaker/Models/ModModel/WorkModel.cs index 673e92f..3e000de 100644 --- a/VPet.ModMaker/Models/ModModel/WorkModel.cs +++ b/VPet.ModMaker/Models/ModModel/WorkModel.cs @@ -31,6 +31,7 @@ public class WorkModel : I18nModel public ObservableValue LevelLimit { get; } = new(); public ObservableValue Time { get; } = new(); public ObservableValue FinishBonus { get; } = new(); + public ObservableValue IsOverLoad { get; } = new(); public ObservableValue BorderBrush { get; } = new(new((Color)ColorConverter.ConvertFromString("#FF0290D5"))); @@ -47,7 +48,23 @@ public class WorkModel : I18nModel public ObservableValue Top { get; } = new(160); public ObservableValue Width { get; } = new(300); - public WorkModel() { } + public WorkModel() + { + IsOverLoad.AddNotifyReceiver( + WorkType, + MoneyBase, + MoneyLevel, + StrengthFood, + StrengthDrink, + Feeling, + LevelLimit, + FinishBonus + ); + IsOverLoad.NotifyReceived += (ref bool v) => + { + v = VPet_Simulator.Windows.Interface.ExtensionFunction.IsOverLoad(ToWork()); + }; + } public WorkModel(WorkModel model) : this() diff --git a/VPet.ModMaker/SimpleObservable/ObservableValue.cs b/VPet.ModMaker/SimpleObservable/ObservableValue.cs index 0511539..c1a152a 100644 --- a/VPet.ModMaker/SimpleObservable/ObservableValue.cs +++ b/VPet.ModMaker/SimpleObservable/ObservableValue.cs @@ -12,7 +12,7 @@ namespace HKW.HKWViewModels.SimpleObservable; /// 可观察值 /// /// -[DebuggerDisplay("{EnumValue}")] +[DebuggerDisplay("{Value}")] public class ObservableValue : INotifyPropertyChanging, INotifyPropertyChanged { [DebuggerBrowsable(DebuggerBrowsableState.Never)] diff --git a/VPet.ModMaker/Templates.xaml b/VPet.ModMaker/Templates.xaml index aade582..ac14da7 100644 --- a/VPet.ModMaker/Templates.xaml +++ b/VPet.ModMaker/Templates.xaml @@ -43,4 +43,16 @@ + + + + + + + \ No newline at end of file diff --git a/VPet.ModMaker/VPet.ModMaker.csproj b/VPet.ModMaker/VPet.ModMaker.csproj index 7b06b7c..1cf123c 100644 --- a/VPet.ModMaker/VPet.ModMaker.csproj +++ b/VPet.ModMaker/VPet.ModMaker.csproj @@ -14,6 +14,8 @@ 4 latest true + false + enable publish\ true Disk @@ -26,10 +28,8 @@ true 0 1.0.0.%2a - false false true - enable true @@ -117,6 +117,7 @@ + diff --git a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimePageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimePageVM.cs new file mode 100644 index 0000000..c980cc1 --- /dev/null +++ b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimePageVM.cs @@ -0,0 +1,109 @@ +using HKW.HKWViewModels.SimpleObservable; +using LinePutScript.Localization.WPF; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using VPet.ModMaker.Models; +using VPet.ModMaker.Models.ModModel; +using VPet.ModMaker.Views.ModEdit.AnimeEdit; + +namespace VPet.ModMaker.ViewModels.ModEdit.AnimeEdit; + +public class AnimePageVM +{ + //#region Value + //public ObservableValue> ShowAnimes { get; } = new(); + //public ObservableCollection Works => CurrentPet.Value.Works; + + //public ObservableCollection Pets => ModInfoModel.Current.Pets; + //public ObservableValue CurrentPet { get; } = new(new()); + //public ObservableValue Filter { get; } = new(); + //#endregion + //#region Command + //public ObservableCommand AddCommand { get; } = new(); + //public ObservableCommand EditCommand { get; } = new(); + //public ObservableCommand RemoveCommand { get; } = new(); + //#endregion + //public AnimePageVM() + //{ + // ShowAnimes.Value = Works; + // CurrentPet.ValueChanged += CurrentPet_ValueChanged; + // Filter.ValueChanged += Filter_ValueChanged; + + // AddCommand.ExecuteEvent += Add; + // EditCommand.ExecuteEvent += Edit; + // RemoveCommand.ExecuteEvent += Remove; + //} + + //private void CurrentPet_ValueChanged(PetModel oldValue, PetModel newValue) + //{ + // //ShowAnimes.Value = newValue.Animes; + //} + + //private void Filter_ValueChanged(string oldValue, string newValue) + //{ + // if (string.IsNullOrWhiteSpace(newValue)) + // { + // ShowAnimes.Value = Works; + // } + // else + // { + // ShowAnimes.Value = new( + // Works.Where(m => m.Id.Value.Contains(newValue, StringComparison.OrdinalIgnoreCase)) + // ); + // } + //} + + //public void Close() { } + + //private void Add() + //{ + // var window = new AnimeEditWindow(); + // var vm = window.ViewModel; + // vm.CurrentPet = CurrentPet.Value; + // window.ShowDialog(); + // if (window.IsCancel) + // return; + // Works.Add(vm.Work.Value); + //} + + //public void Edit(AnimeModel model) + //{ + // var window = new AnimeEditWindow(); + // var vm = window.ViewModel; + // vm.CurrentPet = CurrentPet.Value; + // vm.OldWork = model; + // var newWork = vm.Work.Value = new(model); + // window.ShowDialog(); + // if (window.IsCancel) + // return; + // if (ShowAnimes.Value.Count == Works.Count) + // { + // Works[Works.IndexOf(model)] = newWork; + // } + // else + // { + // Works[Works.IndexOf(model)] = newWork; + // ShowAnimes.Value[ShowAnimes.Value.IndexOf(model)] = newWork; + // } + //} + + //private void Remove(AnimeModel food) + //{ + // if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) + // return; + // if (ShowAnimes.Value.Count == Works.Count) + // { + // Works.Remove(food); + // } + // else + // { + // ShowAnimes.Value.Remove(food); + // Works.Remove(food); + // } + //} +} diff --git a/VPet.ModMaker/ViewModels/ModEdit/ClickTextEdit/ClickTextEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/ClickTextEdit/ClickTextEditWindowVM.cs index 5515aac..ef6a73d 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/ClickTextEdit/ClickTextEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/ClickTextEdit/ClickTextEditWindowVM.cs @@ -12,6 +12,8 @@ namespace VPet.ModMaker.ViewModels.ModEdit.ClickTextEdit; public class ClickTextEditWindowVM { + public I18nHelper I18nData => I18nHelper.Current; + #region Value public ClickTextModel OldClickText { get; set; } diff --git a/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodEditWindowVM.cs index 7056fd1..71de35a 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodEditWindowVM.cs @@ -16,6 +16,7 @@ namespace VPet.ModMaker.ViewModels.ModEdit.FoodEdit; public class FoodEditWindowVM { + public I18nHelper I18nData => I18nHelper.Current; #region Value public FoodModel OldFood { get; set; } public ObservableValue Food { get; } = new(new()); diff --git a/VPet.ModMaker/ViewModels/ModEdit/LowTextEdit/LowTextEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/LowTextEdit/LowTextEditWindowVM.cs index e3a32b3..c180d35 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/LowTextEdit/LowTextEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/LowTextEdit/LowTextEditWindowVM.cs @@ -12,6 +12,7 @@ namespace VPet.ModMaker.ViewModels.ModEdit.LowTextEdit; public class LowTextEditWindowVM { + public I18nHelper I18nData => I18nHelper.Current; #region Value public LowTextModel OldLowText { get; set; } public ObservableValue LowText { get; } = new(new()); diff --git a/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs index 5af6034..65a5e2a 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs @@ -103,6 +103,8 @@ public class ModEditWindowVM if (window.IsCancel) return; I18nHelper.Current.CultureNames.Add(window.Lang.Value); + if (I18nHelper.Current.CultureNames.Count == 1) + I18nHelper.Current.CultureName.Value = window.Lang.Value; } private void EditLang(string oldLang) @@ -149,6 +151,8 @@ public class ModEditWindowVM private void SaveTo() { + if (ValidationData(ModInfo.Value) is false) + return; SaveFileDialog saveFileDialog = new() { @@ -173,4 +177,29 @@ public class ModEditWindowVM MessageBox.Show("保存成功".Translate()); } } + + private bool ValidationData(ModInfoModel model) + { + if (I18nHelper.Current.CultureNames.Count == 0) + { + MessageBox.Show( + "未添加任何语言".Translate(), + "", + MessageBoxButton.OK, + MessageBoxImage.Warning + ); + return false; + } + if (string.IsNullOrWhiteSpace(model.Id.Value)) + { + MessageBox.Show("Id不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); + return false; + } + if (string.IsNullOrWhiteSpace(model.Author.Value)) + { + MessageBox.Show("作者不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); + return false; + } + return true; + } } diff --git a/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetEditWindowVM.cs index 6a0d616..ed14508 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetEditWindowVM.cs @@ -14,6 +14,7 @@ namespace VPet.ModMaker.ViewModels.ModEdit.PetEdit; public class PetEditWindowVM { + public I18nHelper I18nData => I18nHelper.Current; public PetModel OldPet { get; set; } public ObservableValue Pet { get; } = new(new()); @@ -38,7 +39,7 @@ public class PetEditWindowVM public void Close() { - Image.Value?.StreamSource?.Close(); + Image.Value?.CloseStream(); } private void AddImage() diff --git a/VPet.ModMaker/ViewModels/ModEdit/SelectTextEdit/SelectTextEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/SelectTextEdit/SelectTextEditWindowVM.cs index 23e1e65..bfc544e 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/SelectTextEdit/SelectTextEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/SelectTextEdit/SelectTextEditWindowVM.cs @@ -10,6 +10,7 @@ namespace VPet.ModMaker.ViewModels.ModEdit.SelectTextEdit; public class SelectTextEditWindowVM { + public I18nHelper I18nData => I18nHelper.Current; #region Value public SelectTextModel OldSelectText { get; set; } public ObservableValue SelectText { get; } = new(new()); diff --git a/VPet.ModMaker/ViewModels/ModEdit/WorkEdit/WorkEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/WorkEdit/WorkEditWindowVM.cs index e4cae5c..8d4a24b 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/WorkEdit/WorkEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/WorkEdit/WorkEditWindowVM.cs @@ -13,6 +13,7 @@ namespace VPet.ModMaker.ViewModels.ModEdit.WorkEdit; public class WorkEditWindowVM { + public I18nHelper I18nData => I18nHelper.Current; #region Value public PetModel CurrentPet { get; set; } public WorkModel OldWork { get; set; } @@ -39,7 +40,7 @@ public class WorkEditWindowVM public void Close() { - Image.Value?.StreamSource?.Close(); + Image.Value?.CloseStream(); } private void AddImage() diff --git a/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs b/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs index 4323cab..c2b73a1 100644 --- a/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs @@ -81,8 +81,12 @@ public class ModMakerWindowVM private void AddHistories(ModInfoModel modInfo) { - if (Histories.FirstOrDefault(h => h.Id == modInfo.Id.Value) is ModMakerHistory history) + if ( + Histories.FirstOrDefault(h => h.SourcePath == modInfo.SourcePath.Value) + is ModMakerHistory history + ) { + history.Id = modInfo.Id.Value; history.SourcePath = modInfo.SourcePath.Value; history.LastTime = DateTime.Now; } @@ -121,6 +125,9 @@ public class ModMakerWindowVM private void ShowEditWindow() { + if (string.IsNullOrEmpty(ModInfoModel.Current.SourcePath.Value) is false) + AddHistories(ModInfoModel.Current); + SaveHistories(); ModEditWindow = new(); ModEditWindow.Show(); ModMakerWindow.Hide(); @@ -130,7 +137,10 @@ public class ModMakerWindowVM if (string.IsNullOrEmpty(modInfo.SourcePath.Value) is false) AddHistories(modInfo); SaveHistories(); - ModMakerWindow.Close(); + ModInfoModel.Current.Close(); + ModInfoModel.Current = null; + I18nHelper.Current = new(); + ModMakerWindow.Show(); }; } @@ -138,6 +148,7 @@ public class ModMakerWindowVM { ShowHistories.Value.Clear(); Histories.Clear(); + File.WriteAllText(ModMakerInfo.HistoryFile, string.Empty); } public void LoadModFromFile() diff --git a/VPet.ModMaker/Views/ModEdit/AddLangWindow.xaml b/VPet.ModMaker/Views/ModEdit/AddLangWindow.xaml index 2d58696..32e837c 100644 --- a/VPet.ModMaker/Views/ModEdit/AddLangWindow.xaml +++ b/VPet.ModMaker/Views/ModEdit/AddLangWindow.xaml @@ -11,7 +11,7 @@ Title="Window_AddLang" Width="400" Height="300" - WindowStartupLocation="CenterOwner" + WindowStartupLocation="CenterScreen" mc:Ignorable="d"> diff --git a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs index ec79224..20dd493 100644 --- a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs +++ b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs @@ -24,6 +24,14 @@ public partial class AnimeEditWindow : Window { InitializeComponent(); DataContext = new AnimeEditWindowVM(); + Closed += (s, e) => + { + try + { + DataContext = null; + } + catch { } + }; } public AnimeEditWindowVM ViewModel => (AnimeEditWindowVM)DataContext; diff --git a/VPet.ModMaker/Views/ModEdit/ClickTextEdit/ClickTextEditWindow.xaml b/VPet.ModMaker/Views/ModEdit/ClickTextEdit/ClickTextEditWindow.xaml index 50a6022..e677759 100644 --- a/VPet.ModMaker/Views/ModEdit/ClickTextEdit/ClickTextEditWindow.xaml +++ b/VPet.ModMaker/Views/ModEdit/ClickTextEdit/ClickTextEditWindow.xaml @@ -11,14 +11,16 @@ Title="ClickTextWindow" Width="800" Height="450" + WindowStartupLocation="CenterScreen" mc:Ignorable="d"> - - + + + @@ -71,11 +73,30 @@ pu:TextBoxHelper.Watermark="{ll:Str 非必要}" Text="{Binding ClickText.Value.Working.Value, UpdateSourceTrigger=PropertyChanged}" />