保存修改为文件夹对话框

修复载入模组错误时出现的问题
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">
<HintPath>..\packages\LinePutScript.Localization.WPF.1.0.6\lib\net462\LinePutScript.Localization.WPF.dll</HintPath>
</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">
<HintPath>..\packages\Panuon.WPF.1.0.3\lib\net462\Panuon.WPF.dll</HintPath>
</Reference>
<Reference Include="Panuon.WPF.UI, Version=1.1.16.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Panuon.WPF.UI.1.1.16.2\lib\net462\Panuon.WPF.UI.dll</HintPath>
<Reference Include="Panuon.WPF.UI, Version=1.1.16.3, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Panuon.WPF.UI.1.1.16.3\lib\net462\Panuon.WPF.UI.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Security" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />

View File

@ -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);
}
/// <summary>

View File

@ -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);
}
/// <summary>

View File

@ -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
/// </summary>
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

View File

@ -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)

View File

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

View File

@ -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;
/// <summary>
/// winModInfo.xaml 的交互逻辑
/// </summary>
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();
}
/// <summary>
@ -93,7 +102,7 @@ public partial class ModEditWindow : Window
private void ModEditWindow_Closed(object sender, EventArgs e)
{
ViewModel.Close();
ViewModel?.Close();
try
{
DataContext = null;

View File

@ -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)

View File

@ -2,8 +2,9 @@
<packages>
<package id="LinePutScript" version="1.9.2" 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.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.Windows.Interface" version="1.0.9" targetFramework="net462" />
</packages>