From 5a29c279e46f09536fe12d3084d4f1ea1d6d0022 Mon Sep 17 00:00:00 2001 From: Hakoyu Date: Mon, 27 Nov 2023 22:18:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E4=BF=AE=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9=E5=AF=B9=E8=AF=9D=E6=A1=86=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BD=BD=E5=85=A5=E6=A8=A1=E7=BB=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=97=B6=E5=87=BA=E7=8E=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VPet.ModMaker/VPet.ModMaker.csproj | 9 ++++-- .../ModEdit/I18nEdit/I18nEditWindowVM.cs | 18 ++++++++---- .../ViewModels/ModEdit/ModEditWindowVM.cs | 15 ++++------ VPet.ModMaker/ViewModels/ModMakerWindowVM.cs | 28 ++++++++++-------- .../ModEdit/I18nEdit/I18nEditWindow.xaml.cs | 10 +++---- .../Views/ModEdit/ModEditWindow.xaml | 4 +-- .../Views/ModEdit/ModEditWindow.xaml.cs | 29 ++++++++++++------- VPet.ModMaker/Views/ModMakerWindow.xaml.cs | 16 +++++++++- VPet.ModMaker/packages.config | 3 +- 9 files changed, 84 insertions(+), 48 deletions(-) diff --git a/VPet.ModMaker/VPet.ModMaker.csproj b/VPet.ModMaker/VPet.ModMaker.csproj index 5b43d23..3420104 100644 --- a/VPet.ModMaker/VPet.ModMaker.csproj +++ b/VPet.ModMaker/VPet.ModMaker.csproj @@ -61,15 +61,20 @@ ..\packages\LinePutScript.Localization.WPF.1.0.6\lib\net462\LinePutScript.Localization.WPF.dll + + ..\packages\Ookii.Dialogs.Wpf.5.0.1\lib\net462\Ookii.Dialogs.Wpf.dll + ..\packages\Panuon.WPF.1.0.3\lib\net462\Panuon.WPF.dll - - ..\packages\Panuon.WPF.UI.1.1.16.2\lib\net462\Panuon.WPF.UI.dll + + ..\packages\Panuon.WPF.UI.1.1.16.3\lib\net462\Panuon.WPF.UI.dll + + diff --git a/VPet.ModMaker/ViewModels/ModEdit/I18nEdit/I18nEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/I18nEdit/I18nEditWindowVM.cs index 629b3e8..930f034 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/I18nEdit/I18nEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/I18nEdit/I18nEditWindowVM.cs @@ -138,13 +138,21 @@ public class I18nEditWindowVM AddCulture(culture); SearchTargets.Add(culture); } + try + { + LoadFood(model); + LoadClickText(model); + LoadLowText(model); + LoadSelectText(model); + LoadPets(model); + } + catch + { + Close(); + throw; + } I18nHelper.Current.CultureNames.CollectionChanged -= CultureNames_CollectionChanged; I18nHelper.Current.CultureNames.CollectionChanged += CultureNames_CollectionChanged; - LoadFood(model); - LoadClickText(model); - LoadLowText(model); - LoadSelectText(model); - LoadPets(model); } /// diff --git a/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs index 04c2367..c3135d7 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs @@ -17,6 +17,7 @@ using LinePutScript.Localization.WPF; using Panuon.WPF.UI; using VPet.ModMaker.Views.ModEdit.I18nEdit; using System.Globalization; +using Ookii.Dialogs.Wpf; namespace VPet.ModMaker.ViewModels.ModEdit; @@ -86,8 +87,8 @@ public class ModEditWindowVM public ModEditWindowVM(ModEditWindow window) { - ModEditWindow = window; new I18nEditWindow(); + ModEditWindow = window; ChangeImageCommand.ExecuteEvent += ChangeImage; AddCultureCommand.ExecuteEvent += AddCulture; EditCultureCommand.ExecuteEvent += EditCulture; @@ -254,16 +255,10 @@ public class ModEditWindowVM { if (ValidationData(ModInfo.Value) is false) return; - SaveFileDialog saveFileDialog = - new() - { - Title = "保存模组信息文件,并在文件夹内保存模组数据".Translate(), - Filter = $"LPS文件|*.lps;".Translate(), - FileName = "info.lps".Translate() - }; - if (saveFileDialog.ShowDialog() is not true) + var dialog = new VistaFolderBrowserDialog(); + if (dialog.ShowDialog() is not true) return; - SaveTo(Path.GetDirectoryName(saveFileDialog.FileName)); + SaveTo(dialog.SelectedPath); } /// diff --git a/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs b/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs index 5433c2c..13c7d86 100644 --- a/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs @@ -15,6 +15,7 @@ using System.Windows; using VPet.ModMaker.Models; using VPet.ModMaker.Views; using VPet.ModMaker.Views.ModEdit; +using VPet.ModMaker.Views.ModEdit.I18nEdit; namespace VPet.ModMaker.ViewModels; @@ -189,6 +190,7 @@ public class ModMakerWindowVM /// private void ShowEditWindow() { + GC.Collect(); ModMakerWindow.Hide(); // 将当前模组添加到历史 if (string.IsNullOrEmpty(ModInfoModel.Current.SourcePath.Value) is false) @@ -196,6 +198,7 @@ public class ModMakerWindowVM SaveHistories(); ModEditWindow = new(); ModEditWindow.Show(); + ModEditWindow.InitializeData(); ModEditWindow.Closed += (s, e) => { var modInfo = ModInfoModel.Current; @@ -204,9 +207,11 @@ public class ModMakerWindowVM AddHistories(modInfo); SaveHistories(); } - ModInfoModel.Current.Close(); + ModInfoModel.Current?.Close(); I18nHelper.Current = new(); ModMakerWindow.Show(); + ModMakerWindow.Activate(); + GC.Collect(); }; } @@ -238,33 +243,32 @@ public class ModMakerWindowVM var pendingHandler = PendingBox.Show("载入中".Translate()); try { - loader = new ModLoader(new DirectoryInfo(path)); + loader = new ModLoader(new(path)); } catch (Exception ex) { - MessageBox.Show("模组载入失败:\n{0}".Translate(ex)); + MessageBox.Show(ModMakerWindow, "模组载入失败:\n{0}".Translate(ex)); pendingHandler.Close(); } if (loader is null) return; - ModInfoModel? modInfo = null; try { - modInfo = new ModInfoModel(loader); + var modInfo = new ModInfoModel(loader); EditMod(modInfo); - ModEditWindow.InitializeData(); + pendingHandler.Close(); } catch (Exception ex) { pendingHandler.Close(); ModEditWindow?.Close(); + ModEditWindow = null; + ModInfoModel.Current?.Close(); + I18nHelper.Current = new(); + I18nEditWindow.Current?.Close(true); ModMakerWindow.Show(); - MessageBox.Show("模组载入失败:\n{0}".Translate(ex)); - ModInfoModel.Current = null; - } - finally - { - pendingHandler.Close(); + ModMakerWindow.Activate(); + MessageBox.Show(ModMakerWindow, "模组载入失败:\n{0}".Translate(ex)); } } #endregion diff --git a/VPet.ModMaker/Views/ModEdit/I18nEdit/I18nEditWindow.xaml.cs b/VPet.ModMaker/Views/ModEdit/I18nEdit/I18nEditWindow.xaml.cs index 3d6d4e6..50c2e0b 100644 --- a/VPet.ModMaker/Views/ModEdit/I18nEdit/I18nEditWindow.xaml.cs +++ b/VPet.ModMaker/Views/ModEdit/I18nEdit/I18nEditWindow.xaml.cs @@ -26,15 +26,11 @@ public partial class I18nEditWindow : WindowX public I18nEditWindow() { - InitializeComponent(); - DataContext = new I18nEditWindowVM(); - ViewModel.CultureChanged += ViewModel_CultureChanged; - ViewModel.InitializeI18nData(ModInfoModel.Current); Current = this; // 只隐藏, 不关闭 Closing += (s, e) => { - Visibility = Visibility.Hidden; + Hide(); if (_close is false) e.Cancel = true; }; @@ -48,6 +44,10 @@ public partial class I18nEditWindow : WindowX } catch { } }; + InitializeComponent(); + DataContext = new I18nEditWindowVM(); + ViewModel.CultureChanged += ViewModel_CultureChanged; + ViewModel.InitializeI18nData(ModInfoModel.Current); } private bool _close = false; public void Close(bool close) diff --git a/VPet.ModMaker/Views/ModEdit/ModEditWindow.xaml b/VPet.ModMaker/Views/ModEdit/ModEditWindow.xaml index ff70b5a..7f173c7 100644 --- a/VPet.ModMaker/Views/ModEdit/ModEditWindow.xaml +++ b/VPet.ModMaker/Views/ModEdit/ModEditWindow.xaml @@ -1,4 +1,4 @@ - - + diff --git a/VPet.ModMaker/Views/ModEdit/ModEditWindow.xaml.cs b/VPet.ModMaker/Views/ModEdit/ModEditWindow.xaml.cs index 67cc590..3ee99df 100644 --- a/VPet.ModMaker/Views/ModEdit/ModEditWindow.xaml.cs +++ b/VPet.ModMaker/Views/ModEdit/ModEditWindow.xaml.cs @@ -1,6 +1,7 @@ using LinePutScript.Localization.WPF; using Microsoft.Win32; using Panuon.WPF; +using Panuon.WPF.UI; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -36,17 +37,17 @@ namespace VPet.ModMaker.Views.ModEdit; /// /// winModInfo.xaml 的交互逻辑 /// -public partial class ModEditWindow : Window +public partial class ModEditWindow : WindowX { public ModEditWindowVM ViewModel => (ModEditWindowVM)DataContext; - public FoodPage FoodPage { get; } = new(); - public LowTextPage LowTextPage { get; } = new(); - public ClickTextPage ClickTextPage { get; } = new(); - public SelectTextPage SelectTextPage { get; } = new(); - public PetPage PetPage { get; } = new(); - public WorkPage WorkPage { get; } = new(); - public MovePage MovePage { get; } = new(); - public AnimePage AnimePage { get; } = new(); + 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 ModEditWindow() { @@ -54,6 +55,14 @@ public partial class ModEditWindow : Window DataContext = new ModEditWindowVM(this); Closing += ModEditWindow_Closing; Closed += ModEditWindow_Closed; + FoodPage = new(); + LowTextPage = new(); + ClickTextPage = new(); + SelectTextPage = new(); + PetPage = new(); + WorkPage = new(); + MovePage = new(); + AnimePage = new(); } /// @@ -93,7 +102,7 @@ public partial class ModEditWindow : Window private void ModEditWindow_Closed(object sender, EventArgs e) { - ViewModel.Close(); + ViewModel?.Close(); try { DataContext = null; diff --git a/VPet.ModMaker/Views/ModMakerWindow.xaml.cs b/VPet.ModMaker/Views/ModMakerWindow.xaml.cs index aa4c214..21f9c56 100644 --- a/VPet.ModMaker/Views/ModMakerWindow.xaml.cs +++ b/VPet.ModMaker/Views/ModMakerWindow.xaml.cs @@ -30,16 +30,30 @@ namespace VPet.ModMaker.Views; public partial class ModMakerWindow : WindowX { public ModMakerWindowVM ViewModel => (ModMakerWindowVM)DataContext; - public ModEditWindow ModEditWindow { get; set; } public Models.ModMaker ModMaker { get; internal set; } public ModMakerWindow() { InitializeComponent(); DataContext = new ModMakerWindowVM(this); + Closed += ModMakerWindow_Closed; //new AnimeEditWindow().Show(); } + private void ModMakerWindow_Closed(object sender, EventArgs e) + { + foreach (var item in Application.Current.Windows) + { + if (item is ModEditWindow window) + window.Close(); + } + try + { + DataContext = null; + } + catch { } + } + private void ListBoxItem_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (sender is not ListBoxItem item) diff --git a/VPet.ModMaker/packages.config b/VPet.ModMaker/packages.config index 10f8760..33e83aa 100644 --- a/VPet.ModMaker/packages.config +++ b/VPet.ModMaker/packages.config @@ -2,8 +2,9 @@ + - + \ No newline at end of file