From ba74693de06df65551d45eb50046e90d4b576011 Mon Sep 17 00:00:00 2001 From: Hakoyu Date: Fri, 6 Oct 2023 17:31:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VPet.ModMaker/VPet.ModMaker.csproj | 4 +- .../ViewModels/ModEdit/AddCultureWindowVM.cs | 14 ++ .../ViewModels/ModEdit/ModEditWindowVM.cs | 116 +++++++++----- VPet.ModMaker/ViewModels/ModMakerWindowVM.cs | 147 ++++++++++++------ .../Views/ModEdit/AddCultureWindow.xaml | 10 +- .../Views/ModEdit/AddCultureWindow.xaml.cs | 11 +- .../ModEdit/AnimeEdit/AnimeEditWindow.xaml | 4 +- .../Views/ModEdit/AnimeEdit/AnimePage.xaml | 4 +- .../ClickTextEdit/ClickTextEditWindow.xaml | 4 +- .../ModEdit/ClickTextEdit/ClickTextPage.xaml | 4 +- .../ModEdit/FoodEdit/FoodEditWindow.xaml | 6 +- .../Views/ModEdit/FoodEdit/FoodPage.xaml | 6 +- .../LowTextEdit/LowTextEditWindow.xaml | 6 +- .../ModEdit/LowTextEdit/LowTextPage.xaml | 6 +- .../Views/ModEdit/ModEditWindow.xaml | 38 +++-- .../ModEdit/MoveEdit/MoveEditWindow.xaml | 4 +- .../Views/ModEdit/MoveEdit/MovePage.xaml | 5 +- .../Views/ModEdit/PetEdit/PetEditWindow.xaml | 4 +- .../Views/ModEdit/PetEdit/PetPage.xaml | 4 +- .../SelectTextEdit/SelectTextEditWindow.xaml | 6 +- .../SelectTextEdit/SelectTextPage.xaml | 4 +- .../ModEdit/WorkEdit/WorkEditWindow.xaml | 4 +- .../Views/ModEdit/WorkEdit/WorkPage.xaml | 4 +- VPet.ModMaker/Views/ModMakerWindow.xaml | 4 +- VPet.ModMaker/packages.config | 4 +- 25 files changed, 251 insertions(+), 172 deletions(-) diff --git a/VPet.ModMaker/VPet.ModMaker.csproj b/VPet.ModMaker/VPet.ModMaker.csproj index 7aff785..9357f37 100644 --- a/VPet.ModMaker/VPet.ModMaker.csproj +++ b/VPet.ModMaker/VPet.ModMaker.csproj @@ -78,10 +78,10 @@ 4.0 - ..\packages\VPet-Simulator.Core.1.0.7\lib\net462\VPet-Simulator.Core.dll + ..\packages\VPet-Simulator.Core.1.0.8\lib\net462\VPet-Simulator.Core.dll - ..\packages\VPet-Simulator.Windows.Interface.1.0.7\lib\net462\VPet-Simulator.Windows.Interface.dll + ..\packages\VPet-Simulator.Windows.Interface.1.0.8\lib\net462\VPet-Simulator.Windows.Interface.dll diff --git a/VPet.ModMaker/ViewModels/ModEdit/AddCultureWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/AddCultureWindowVM.cs index cceab00..154a316 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/AddCultureWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/AddCultureWindowVM.cs @@ -11,11 +11,25 @@ namespace VPet.ModMaker.ViewModels.ModEdit; public class AddCultureWindowVM { + /// + /// 显示的文化 + /// public ObservableValue> ShowCultures { get; } = new(); + + /// + /// 全部文化 + /// public static ObservableCollection AllCultures { get; set; } = new(LinePutScript.Localization.WPF.LocalizeCore.AvailableCultures); + + /// + /// 当前文化 + /// public ObservableValue Culture { get; } = new(); + /// + /// 搜索文化 + /// public ObservableValue Search { get; } = new(); public AddCultureWindowVM() diff --git a/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs index b91086d..5eff170 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs @@ -23,65 +23,74 @@ public class ModEditWindowVM public ModEditWindow ModEditWindow { get; } #region Value + /// + /// 当前模组信息 + /// public ObservableValue ModInfo { get; } = new(ModInfoModel.Current); - public ObservableValue CurrentLang { get; } = new(); + + /// + /// I18n数据 + /// public I18nHelper I18nData => I18nHelper.Current; #endregion #region Command - public ObservableCommand AddImageCommand { get; } = new(); + + /// + /// 改变图片命令 + /// public ObservableCommand ChangeImageCommand { get; } = new(); + + /// + /// 添加文化命令 + /// public ObservableCommand AddCultureCommand { get; } = new(); + /// + /// 编辑文化命令 + /// public ObservableCommand EditCultureCommand { get; } = new(); + + /// + /// 删除文化命令 + /// public ObservableCommand RemoveCultureCommand { get; } = new(); + /// + /// 保存命令 + /// public ObservableCommand SaveCommand { get; } = new(); + + /// + /// 保存至命令 + /// public ObservableCommand SaveToCommand { get; } = new(); #endregion - public ModEditWindowVM() { } - public ModEditWindowVM(ModEditWindow window) { ModEditWindow = window; - CurrentLang.ValueChanged += CurrentLang_ValueChanged; - AddImageCommand.ExecuteEvent += AddImage; ChangeImageCommand.ExecuteEvent += ChangeImage; AddCultureCommand.ExecuteEvent += AddCulture; EditCultureCommand.ExecuteEvent += EditCulture; - RemoveCultureCommand.ExecuteEvent += RemoveLang; + RemoveCultureCommand.ExecuteEvent += RemoveCulture; + SaveCommand.ExecuteEvent += Save; SaveToCommand.ExecuteEvent += SaveTo; } - private void CurrentLang_ValueChanged(string oldValue, string newValue) - { - if (newValue is null) - return; - ModInfo.Value.CurrentI18nData.Value = ModInfo.Value.I18nDatas[newValue]; - } - + /// + /// 关闭 + /// public void Close() { ModInfo.Value.Image.Value?.StreamSource?.Close(); } - private void AddImage() - { - OpenFileDialog openFileDialog = - new() - { - Title = "选择图片".Translate(), - Filter = $"图片|*.jpg;*.jpeg;*.png;*.bmp".Translate() - }; - if (openFileDialog.ShowDialog() is true) - { - ModInfo.Value.Image.Value = Utils.LoadImageToMemoryStream(openFileDialog.FileName); - } - } - + /// + /// 改变图片 + /// private void ChangeImage() { OpenFileDialog openFileDialog = @@ -97,6 +106,10 @@ public class ModEditWindowVM } } + #region Culture + /// + /// 添加文化 + /// public void AddCulture() { var window = new AddCultureWindow(); @@ -108,32 +121,48 @@ public class ModEditWindowVM I18nHelper.Current.CultureName.Value = window.ViewModel.Culture.Value; } - private void EditCulture(string oldLang) + /// + /// 编辑文化 + /// + /// 旧文化 + private void EditCulture(string oldCulture) { var window = new AddCultureWindow(); - window.ViewModel.Culture.Value = oldLang.Translate(); + window.ViewModel.Culture.Value = oldCulture.Translate(); window.ShowDialog(); if (window.IsCancel) return; - I18nHelper.Current.CultureNames[I18nHelper.Current.CultureNames.IndexOf(oldLang)] = window - .ViewModel - .Culture - .Value; - CurrentLang.Value = window.ViewModel.Culture.Value; + I18nHelper.Current.CultureNames[I18nHelper.Current.CultureNames.IndexOf(oldCulture)] = + window.ViewModel.Culture.Value; } - private void RemoveLang(string oldLang) + /// + /// 删除文化 + /// + /// 旧文化 + private void RemoveCulture(string oldCulture) { if ( - MessageBox.Show("确定删除吗".Translate(), "".Translate(), MessageBoxButton.YesNo) - is MessageBoxResult.No + MessageBox.Show( + "确定删除文化 {0} 吗".Translate(oldCulture), + "".Translate(), + MessageBoxButton.YesNo + ) is MessageBoxResult.No ) return; - I18nHelper.Current.CultureNames.Remove(oldLang); + I18nHelper.Current.CultureNames.Remove(oldCulture); } + #endregion + #region Save + /// + /// 保存 + /// private void Save() { + if (MessageBox.Show("确定保存吗".Translate()) is not MessageBoxResult.Yes) + return; + if (string.IsNullOrEmpty(ModInfo.Value.SourcePath.Value)) { MessageBox.Show("源路径为空, 请使用 保存至".Translate()); @@ -151,6 +180,9 @@ public class ModEditWindowVM MessageBox.Show("保存成功".Translate()); } + /// + /// 保存至 + /// private void SaveTo() { if (ValidationData(ModInfo.Value) is false) @@ -183,6 +215,11 @@ public class ModEditWindowVM } } + /// + /// 验证数据 + /// + /// 模型 + /// 成功为 失败为 private bool ValidationData(ModInfoModel model) { if (I18nHelper.Current.CultureNames.Count == 0) @@ -207,4 +244,5 @@ public class ModEditWindowVM } return true; } + #endregion } diff --git a/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs b/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs index 00d9946..732e11f 100644 --- a/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs @@ -25,19 +25,42 @@ public class ModMakerWindowVM public ModEditWindow ModEditWindow { get; private set; } + /// + /// 历史搜索文本 + /// public ObservableValue HistoriesSearchText { get; } = new(); - public ObservableCollection Mods { get; } = new(); + /// + /// 显示的历史 + /// public ObservableValue> ShowHistories { get; } = new(); + + /// + /// 历史 + /// public ObservableCollection Histories { get; } = new(); #endregion #region Command + /// + /// 创建新模组命令 + /// public ObservableCommand CreateNewModCommand { get; } = new(); + + /// + /// 从文件载入模组命令 + /// public ObservableCommand LoadModFromFileCommand { get; } = new(); + + /// + /// 清除历史命令 + /// public ObservableCommand ClearHistoriesCommand { get; } = new(); + + /// + /// 删除历史命令 + /// public ObservableCommand RemoveHistoryCommand { get; } = new(); #endregion - public ModMakerWindowVM() { } public ModMakerWindowVM(ModMakerWindow window) { @@ -48,15 +71,27 @@ public class ModMakerWindowVM LoadModFromFileCommand.ExecuteEvent += LoadModFromFile; ClearHistoriesCommand.ExecuteEvent += ClearHistories; RemoveHistoryCommand.ExecuteEvent += RemoveHistory; - HistoriesSearchText.ValueChanged += ModSearchText_ValueChanged; + HistoriesSearchText.ValueChanged += HistoriesSearchText_ValueChanged; } + private void HistoriesSearchText_ValueChanged(string oldValue, string newValue) + { + if (string.IsNullOrEmpty(newValue)) + ShowHistories.Value = Histories; + else + ShowHistories.Value = new(Histories.Where(i => i.Id.Contains(newValue))); + } + + #region History private void RemoveHistory(ModMakerHistory value) { Histories.Remove(value); SaveHistories(); } + /// + /// 载入历史 + /// private void LoadHistories() { if (File.Exists(ModMakerInfo.HistoryFile) is false) @@ -70,6 +105,9 @@ public class ModMakerWindowVM } } + /// + /// 保存历史 + /// private void SaveHistories() { Directory.CreateDirectory(nameof(ModMaker)); @@ -77,6 +115,7 @@ public class ModMakerWindowVM File.Create(ModMakerInfo.HistoryFile).Close(); var lps = new LPS(); foreach (var history in Histories) + { lps.Add( new Line(nameof(history)) { @@ -85,9 +124,14 @@ public class ModMakerWindowVM new Sub("LastTime", history.LastTime.ToString("yyyy/MM/dd HH:mm")) } ); + } File.WriteAllText(ModMakerInfo.HistoryFile, lps.ToString()); } + /// + /// 添加历史 + /// + /// 模组信息 private void AddHistories(ModInfoModel modInfo) { if ( @@ -112,47 +156,6 @@ public class ModMakerWindowVM } } - private void ModSearchText_ValueChanged(string oldValue, string newValue) - { - if (string.IsNullOrEmpty(newValue)) - ShowHistories.Value = Histories; - else - ShowHistories.Value = new(Histories.Where(i => i.Id.Contains(newValue))); - } - - public void CreateNewMod() - { - ModInfoModel.Current = new(); - ShowEditWindow(); - } - - public void EditMod(ModInfoModel modInfo) - { - ModInfoModel.Current = modInfo; - ShowEditWindow(); - } - - private void ShowEditWindow() - { - if (string.IsNullOrEmpty(ModInfoModel.Current.SourcePath.Value) is false) - AddHistories(ModInfoModel.Current); - SaveHistories(); - ModEditWindow = new(); - ModEditWindow.Show(); - ModMakerWindow.Hide(); - ModEditWindow.Closed += (s, e) => - { - var modInfo = ModInfoModel.Current; - if (string.IsNullOrEmpty(modInfo.SourcePath.Value) is false) - AddHistories(modInfo); - SaveHistories(); - ModInfoModel.Current.Close(); - ModInfoModel.Current = null; - I18nHelper.Current = new(); - ModMakerWindow.Show(); - }; - } - private void ClearHistories() { if ( @@ -164,7 +167,58 @@ public class ModMakerWindowVM Histories.Clear(); File.WriteAllText(ModMakerInfo.HistoryFile, string.Empty); } + #endregion + #region Mod + /// + /// 创建新模组 + /// + public void CreateNewMod() + { + ModInfoModel.Current = new(); + ShowEditWindow(); + } + + /// + /// 编辑模组 + /// + /// 模组信息 + public void EditMod(ModInfoModel modInfo) + { + ModInfoModel.Current = modInfo; + ShowEditWindow(); + } + + /// + /// 显示模组编辑窗口 + /// + private void ShowEditWindow() + { + ModMakerWindow.Hide(); + // 将当前模组添加到历史 + if (string.IsNullOrEmpty(ModInfoModel.Current.SourcePath.Value) is false) + AddHistories(ModInfoModel.Current); + SaveHistories(); + ModEditWindow = new(); + ModEditWindow.Show(); + ModEditWindow.Closed += (s, e) => + { + var modInfo = ModInfoModel.Current; + if (string.IsNullOrEmpty(modInfo.SourcePath.Value) is false) + { + AddHistories(modInfo); + SaveHistories(); + } + ModInfoModel.Current.Close(); + ModInfoModel.Current = null; + I18nHelper.Current = new(); + ModMakerWindow.Show(); + }; + } + + /// + /// 从文件载入模组 + /// public void LoadModFromFile() { OpenFileDialog openFileDialog = @@ -180,6 +234,10 @@ public class ModMakerWindowVM } } + /// + /// 载入模组 + /// + /// 位置 public void LoadMod(string path) { try @@ -200,4 +258,5 @@ public class ModMakerWindowVM MessageBox.Show("模组载入失败:\n{0}".Translate(ex)); } } + #endregion } diff --git a/VPet.ModMaker/Views/ModEdit/AddCultureWindow.xaml b/VPet.ModMaker/Views/ModEdit/AddCultureWindow.xaml index b5729bc..a7363d6 100644 --- a/VPet.ModMaker/Views/ModEdit/AddCultureWindow.xaml +++ b/VPet.ModMaker/Views/ModEdit/AddCultureWindow.xaml @@ -1,4 +1,4 @@ - + Content="{ll:Str 取消}" + IsCancel="True" />