优化重启功能

This commit is contained in:
ZouJin 2023-03-07 19:11:23 +11:00
parent efefbe35eb
commit c5fdab3647
2 changed files with 28 additions and 2 deletions

View File

@ -81,6 +81,33 @@ namespace VPet_Simulator.Windows
}
Task.Run(GameLoad);
}
public new void Close()
{
if (Main == null)
{
base.Close();
}
else
{
Main.DisplayClose(() => Dispatcher.Invoke(base.Close));
}
}
public void Restart()
{
this.Closed -= Window_Closed;
this.Closed += Restart_Closed;
base.Close();
}
private void Restart_Closed(object sender, EventArgs e)
{
Save();
Main?.Dispose();
notifyIcon?.Dispose();
System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
System.Environment.Exit(0);
}
private List<string> rndtext = new List<string>
{
"你知道吗? 鼠标右键可以打开菜单栏",

View File

@ -440,8 +440,7 @@ namespace VPet_Simulator.Windows
{
if (MessageBoxX.Show("是否退出游戏<虚拟桌宠模拟器>?\n请注意保存游戏", "重启游戏", MessageBoxButton.YesNo, MessageBoxIcon.Warning) == MessageBoxResult.Yes)
{
mw.Close();
System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
mw.Restart();
}
}