保存修改为文件夹对话框

修复载入模组错误时出现的问题
This commit is contained in:
Hakoyu 2023-11-27 22:18:03 +08:00
parent 24508f5766
commit 5a29c279e4
9 changed files with 84 additions and 48 deletions

View File

@ -61,15 +61,20 @@
<Reference Include="LinePutScript.Localization.WPF, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="LinePutScript.Localization.WPF, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\LinePutScript.Localization.WPF.1.0.6\lib\net462\LinePutScript.Localization.WPF.dll</HintPath> <HintPath>..\packages\LinePutScript.Localization.WPF.1.0.6\lib\net462\LinePutScript.Localization.WPF.dll</HintPath>
</Reference> </Reference>
<Reference Include="Ookii.Dialogs.Wpf, Version=5.0.0.0, Culture=neutral, PublicKeyToken=66aa232afad40158, processorArchitecture=MSIL">
<HintPath>..\packages\Ookii.Dialogs.Wpf.5.0.1\lib\net462\Ookii.Dialogs.Wpf.dll</HintPath>
</Reference>
<Reference Include="Panuon.WPF, Version=1.0.3.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Panuon.WPF, Version=1.0.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Panuon.WPF.1.0.3\lib\net462\Panuon.WPF.dll</HintPath> <HintPath>..\packages\Panuon.WPF.1.0.3\lib\net462\Panuon.WPF.dll</HintPath>
</Reference> </Reference>
<Reference Include="Panuon.WPF.UI, Version=1.1.16.1, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Panuon.WPF.UI, Version=1.1.16.3, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Panuon.WPF.UI.1.1.16.2\lib\net462\Panuon.WPF.UI.dll</HintPath> <HintPath>..\packages\Panuon.WPF.UI.1.1.16.3\lib\net462\Panuon.WPF.UI.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Security" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />

View File

@ -138,13 +138,21 @@ public class I18nEditWindowVM
AddCulture(culture); AddCulture(culture);
SearchTargets.Add(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;
I18nHelper.Current.CultureNames.CollectionChanged += CultureNames_CollectionChanged; I18nHelper.Current.CultureNames.CollectionChanged += CultureNames_CollectionChanged;
LoadFood(model);
LoadClickText(model);
LoadLowText(model);
LoadSelectText(model);
LoadPets(model);
} }
/// <summary> /// <summary>

View File

@ -17,6 +17,7 @@ using LinePutScript.Localization.WPF;
using Panuon.WPF.UI; using Panuon.WPF.UI;
using VPet.ModMaker.Views.ModEdit.I18nEdit; using VPet.ModMaker.Views.ModEdit.I18nEdit;
using System.Globalization; using System.Globalization;
using Ookii.Dialogs.Wpf;
namespace VPet.ModMaker.ViewModels.ModEdit; namespace VPet.ModMaker.ViewModels.ModEdit;
@ -86,8 +87,8 @@ public class ModEditWindowVM
public ModEditWindowVM(ModEditWindow window) public ModEditWindowVM(ModEditWindow window)
{ {
ModEditWindow = window;
new I18nEditWindow(); new I18nEditWindow();
ModEditWindow = window;
ChangeImageCommand.ExecuteEvent += ChangeImage; ChangeImageCommand.ExecuteEvent += ChangeImage;
AddCultureCommand.ExecuteEvent += AddCulture; AddCultureCommand.ExecuteEvent += AddCulture;
EditCultureCommand.ExecuteEvent += EditCulture; EditCultureCommand.ExecuteEvent += EditCulture;
@ -254,16 +255,10 @@ public class ModEditWindowVM
{ {
if (ValidationData(ModInfo.Value) is false) if (ValidationData(ModInfo.Value) is false)
return; return;
SaveFileDialog saveFileDialog = var dialog = new VistaFolderBrowserDialog();
new() if (dialog.ShowDialog() is not true)
{
Title = "保存模组信息文件,并在文件夹内保存模组数据".Translate(),
Filter = $"LPS文件|*.lps;".Translate(),
FileName = "info.lps".Translate()
};
if (saveFileDialog.ShowDialog() is not true)
return; return;
SaveTo(Path.GetDirectoryName(saveFileDialog.FileName)); SaveTo(dialog.SelectedPath);
} }
/// <summary> /// <summary>

View File

@ -15,6 +15,7 @@ using System.Windows;
using VPet.ModMaker.Models; using VPet.ModMaker.Models;
using VPet.ModMaker.Views; using VPet.ModMaker.Views;
using VPet.ModMaker.Views.ModEdit; using VPet.ModMaker.Views.ModEdit;
using VPet.ModMaker.Views.ModEdit.I18nEdit;
namespace VPet.ModMaker.ViewModels; namespace VPet.ModMaker.ViewModels;
@ -189,6 +190,7 @@ public class ModMakerWindowVM
/// </summary> /// </summary>
private void ShowEditWindow() private void ShowEditWindow()
{ {
GC.Collect();
ModMakerWindow.Hide(); ModMakerWindow.Hide();
// 将当前模组添加到历史 // 将当前模组添加到历史
if (string.IsNullOrEmpty(ModInfoModel.Current.SourcePath.Value) is false) if (string.IsNullOrEmpty(ModInfoModel.Current.SourcePath.Value) is false)
@ -196,6 +198,7 @@ public class ModMakerWindowVM
SaveHistories(); SaveHistories();
ModEditWindow = new(); ModEditWindow = new();
ModEditWindow.Show(); ModEditWindow.Show();
ModEditWindow.InitializeData();
ModEditWindow.Closed += (s, e) => ModEditWindow.Closed += (s, e) =>
{ {
var modInfo = ModInfoModel.Current; var modInfo = ModInfoModel.Current;
@ -204,9 +207,11 @@ public class ModMakerWindowVM
AddHistories(modInfo); AddHistories(modInfo);
SaveHistories(); SaveHistories();
} }
ModInfoModel.Current.Close(); ModInfoModel.Current?.Close();
I18nHelper.Current = new(); I18nHelper.Current = new();
ModMakerWindow.Show(); ModMakerWindow.Show();
ModMakerWindow.Activate();
GC.Collect();
}; };
} }
@ -238,33 +243,32 @@ public class ModMakerWindowVM
var pendingHandler = PendingBox.Show("载入中".Translate()); var pendingHandler = PendingBox.Show("载入中".Translate());
try try
{ {
loader = new ModLoader(new DirectoryInfo(path)); loader = new ModLoader(new(path));
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show("模组载入失败:\n{0}".Translate(ex)); MessageBox.Show(ModMakerWindow, "模组载入失败:\n{0}".Translate(ex));
pendingHandler.Close(); pendingHandler.Close();
} }
if (loader is null) if (loader is null)
return; return;
ModInfoModel? modInfo = null;
try try
{ {
modInfo = new ModInfoModel(loader); var modInfo = new ModInfoModel(loader);
EditMod(modInfo); EditMod(modInfo);
ModEditWindow.InitializeData(); pendingHandler.Close();
} }
catch (Exception ex) catch (Exception ex)
{ {
pendingHandler.Close(); pendingHandler.Close();
ModEditWindow?.Close(); ModEditWindow?.Close();
ModEditWindow = null;
ModInfoModel.Current?.Close();
I18nHelper.Current = new();
I18nEditWindow.Current?.Close(true);
ModMakerWindow.Show(); ModMakerWindow.Show();
MessageBox.Show("模组载入失败:\n{0}".Translate(ex)); ModMakerWindow.Activate();
ModInfoModel.Current = null; MessageBox.Show(ModMakerWindow, "模组载入失败:\n{0}".Translate(ex));
}
finally
{
pendingHandler.Close();
} }
} }
#endregion #endregion

View File

@ -26,15 +26,11 @@ public partial class I18nEditWindow : WindowX
public I18nEditWindow() public I18nEditWindow()
{ {
InitializeComponent();
DataContext = new I18nEditWindowVM();
ViewModel.CultureChanged += ViewModel_CultureChanged;
ViewModel.InitializeI18nData(ModInfoModel.Current);
Current = this; Current = this;
// 只隐藏, 不关闭 // 只隐藏, 不关闭
Closing += (s, e) => Closing += (s, e) =>
{ {
Visibility = Visibility.Hidden; Hide();
if (_close is false) if (_close is false)
e.Cancel = true; e.Cancel = true;
}; };
@ -48,6 +44,10 @@ public partial class I18nEditWindow : WindowX
} }
catch { } catch { }
}; };
InitializeComponent();
DataContext = new I18nEditWindowVM();
ViewModel.CultureChanged += ViewModel_CultureChanged;
ViewModel.InitializeI18nData(ModInfoModel.Current);
} }
private bool _close = false; private bool _close = false;
public void Close(bool close) public void Close(bool close)

View File

@ -1,4 +1,4 @@
<Window <pu:WindowX
x:Class="VPet.ModMaker.Views.ModEdit.ModEditWindow" x:Class="VPet.ModMaker.Views.ModEdit.ModEditWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@ -336,4 +336,4 @@
</StackPanel> </StackPanel>
</Grid> </Grid>
</Grid> </Grid>
</Window> </pu:WindowX>

View File

@ -1,6 +1,7 @@
using LinePutScript.Localization.WPF; using LinePutScript.Localization.WPF;
using Microsoft.Win32; using Microsoft.Win32;
using Panuon.WPF; using Panuon.WPF;
using Panuon.WPF.UI;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@ -36,17 +37,17 @@ namespace VPet.ModMaker.Views.ModEdit;
/// <summary> /// <summary>
/// winModInfo.xaml 的交互逻辑 /// winModInfo.xaml 的交互逻辑
/// </summary> /// </summary>
public partial class ModEditWindow : Window public partial class ModEditWindow : WindowX
{ {
public ModEditWindowVM ViewModel => (ModEditWindowVM)DataContext; public ModEditWindowVM ViewModel => (ModEditWindowVM)DataContext;
public FoodPage FoodPage { get; } = new(); public FoodPage FoodPage { get; }
public LowTextPage LowTextPage { get; } = new(); public LowTextPage LowTextPage { get; }
public ClickTextPage ClickTextPage { get; } = new(); public ClickTextPage ClickTextPage { get; }
public SelectTextPage SelectTextPage { get; } = new(); public SelectTextPage SelectTextPage { get; }
public PetPage PetPage { get; } = new(); public PetPage PetPage { get; }
public WorkPage WorkPage { get; } = new(); public WorkPage WorkPage { get; }
public MovePage MovePage { get; } = new(); public MovePage MovePage { get; }
public AnimePage AnimePage { get; } = new(); public AnimePage AnimePage { get; }
public ModEditWindow() public ModEditWindow()
{ {
@ -54,6 +55,14 @@ public partial class ModEditWindow : Window
DataContext = new ModEditWindowVM(this); DataContext = new ModEditWindowVM(this);
Closing += ModEditWindow_Closing; Closing += ModEditWindow_Closing;
Closed += ModEditWindow_Closed; Closed += ModEditWindow_Closed;
FoodPage = new();
LowTextPage = new();
ClickTextPage = new();
SelectTextPage = new();
PetPage = new();
WorkPage = new();
MovePage = new();
AnimePage = new();
} }
/// <summary> /// <summary>
@ -93,7 +102,7 @@ public partial class ModEditWindow : Window
private void ModEditWindow_Closed(object sender, EventArgs e) private void ModEditWindow_Closed(object sender, EventArgs e)
{ {
ViewModel.Close(); ViewModel?.Close();
try try
{ {
DataContext = null; DataContext = null;

View File

@ -30,16 +30,30 @@ namespace VPet.ModMaker.Views;
public partial class ModMakerWindow : WindowX public partial class ModMakerWindow : WindowX
{ {
public ModMakerWindowVM ViewModel => (ModMakerWindowVM)DataContext; public ModMakerWindowVM ViewModel => (ModMakerWindowVM)DataContext;
public ModEditWindow ModEditWindow { get; set; }
public Models.ModMaker ModMaker { get; internal set; } public Models.ModMaker ModMaker { get; internal set; }
public ModMakerWindow() public ModMakerWindow()
{ {
InitializeComponent(); InitializeComponent();
DataContext = new ModMakerWindowVM(this); DataContext = new ModMakerWindowVM(this);
Closed += ModMakerWindow_Closed;
//new AnimeEditWindow().Show(); //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) private void ListBoxItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{ {
if (sender is not ListBoxItem item) if (sender is not ListBoxItem item)

View File

@ -2,8 +2,9 @@
<packages> <packages>
<package id="LinePutScript" version="1.9.2" targetFramework="net462" /> <package id="LinePutScript" version="1.9.2" targetFramework="net462" />
<package id="LinePutScript.Localization.WPF" version="1.0.6" targetFramework="net462" /> <package id="LinePutScript.Localization.WPF" version="1.0.6" targetFramework="net462" />
<package id="Ookii.Dialogs.Wpf" version="5.0.1" targetFramework="net462" />
<package id="Panuon.WPF" version="1.0.3" targetFramework="net462" /> <package id="Panuon.WPF" version="1.0.3" targetFramework="net462" />
<package id="Panuon.WPF.UI" version="1.1.16.2" targetFramework="net462" /> <package id="Panuon.WPF.UI" version="1.1.16.3" targetFramework="net462" />
<package id="VPet-Simulator.Core" version="1.0.9" targetFramework="net462" /> <package id="VPet-Simulator.Core" version="1.0.9" targetFramework="net462" />
<package id="VPet-Simulator.Windows.Interface" version="1.0.9" targetFramework="net462" /> <package id="VPet-Simulator.Windows.Interface" version="1.0.9" targetFramework="net462" />
</packages> </packages>