mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
feat: 记住主界面的位置和大小
同时VersionUpdateView相对主界面居中
This commit is contained in:
68
src/MaaWpfGui/Helper/WindowManager.cs
Normal file
68
src/MaaWpfGui/Helper/WindowManager.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
// <copyright file="WindowManager.cs" company="MaaAssistantArknights">
|
||||
// MaaWpfGui - A part of the MaaCoreArknights project
|
||||
// Copyright (C) 2021 MistEO and Contributors
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
using Stylet;
|
||||
|
||||
namespace MaaWpfGui
|
||||
{
|
||||
public class WindowManager : Stylet.WindowManager
|
||||
{
|
||||
private readonly double Left = double.Parse(ViewStatusStorage.Get("GUI.Position.Left", "NaN"));
|
||||
private readonly double Top = double.Parse(ViewStatusStorage.Get("GUI.Position.Top", "NaN"));
|
||||
|
||||
public WindowManager(IViewManager viewManager, Func<IMessageBoxViewModel> messageBoxViewModelFactory, IWindowManagerConfig config)
|
||||
: base(viewManager, messageBoxViewModelFactory, config)
|
||||
{
|
||||
// Change Left and Top after adjusting multiple displays
|
||||
Left = Left < SystemParameters.VirtualScreenWidth ? Left : double.NaN;
|
||||
Top = Top < SystemParameters.VirtualScreenHeight ? Top : double.NaN;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override Window CreateWindow(object viewModel, bool isDialog, IViewAware ownerViewModel)
|
||||
{
|
||||
Window window = base.CreateWindow(viewModel, isDialog, ownerViewModel);
|
||||
if (bool.Parse(ViewStatusStorage.Get("GUI.PositionAndSize.Load", bool.TrueString)))
|
||||
{
|
||||
if (isDialog || ownerViewModel != null || double.IsNaN(Left) || double.IsNaN(Top))
|
||||
{
|
||||
return window;
|
||||
}
|
||||
|
||||
// In Stylet, CreateWindow().WindowStartupLocation is CenterScreen or CenterOwner (if w.WSLoc == Manual && w.Left == NaN && w.Top == NaN && ...)
|
||||
window.WindowStartupLocation = WindowStartupLocation.Manual;
|
||||
|
||||
if (window.ToString() == "MaaWpfGui.RootView")
|
||||
{
|
||||
double width = double.Parse(ViewStatusStorage.Get("GUI.Size.Width", "NaN"));
|
||||
double height = double.Parse(ViewStatusStorage.Get("GUI.Size.Height", "NaN"));
|
||||
|
||||
window.Left = Left;
|
||||
window.Top = Top;
|
||||
window.Width = width;
|
||||
window.Height = height;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Center other windows in MaaWpfGui.RootView
|
||||
window.Left = Left + ((Application.Current.MainWindow.Width - window.Width) / 2);
|
||||
window.Top = Top + ((Application.Current.MainWindow.Height - window.Height) / 2);
|
||||
}
|
||||
}
|
||||
|
||||
return window;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,7 @@
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Helper\Utils.cs" />
|
||||
<Compile Include="Helper\WebService.cs" />
|
||||
<Compile Include="Helper\WindowManager.cs" />
|
||||
<Compile Include="Main\Bootstrapper.cs" />
|
||||
<Compile Include="GlobalSuppressions.cs" />
|
||||
<Compile Include="Main\AsstProxy.cs" />
|
||||
|
||||
@@ -126,6 +126,13 @@ namespace MaaWpfGui
|
||||
builder.Bind<IMainWindowManager>().To<MainWindowManager>().InSingletonScope();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void DisplayRootView(object rootViewModel)
|
||||
{
|
||||
var windowManager = (WindowManager)GetInstance(typeof(WindowManager));
|
||||
windowManager.ShowWindow(rootViewModel);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
/// <remarks>退出时执行啥自己加。</remarks>
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace MaaWpfGui
|
||||
|
||||
if (vuvm.IsFirstBootAfterUpdate)
|
||||
{
|
||||
_windowManager.ShowWindow(vuvm);
|
||||
_container.Get<WindowManager>().ShowWindow(vuvm);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -113,6 +113,11 @@ namespace MaaWpfGui
|
||||
MessageBoxButton.OK, MessageBoxImage.Hand);
|
||||
Hangover = false;
|
||||
}
|
||||
|
||||
if (LoadGUIParameters && SaveGUIParametersOnClosing)
|
||||
{
|
||||
Application.Current.MainWindow.Closing += SaveGUIParameters;
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> _listTitle = new List<string>();
|
||||
@@ -2107,6 +2112,76 @@ namespace MaaWpfGui
|
||||
}
|
||||
}
|
||||
|
||||
private bool _loadGUIParameters = Convert.ToBoolean(ViewStatusStorage.Get("GUI.PositionAndSize.Load", bool.TrueString));
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to load GUI parameters.
|
||||
/// </summary>
|
||||
public bool LoadGUIParameters
|
||||
{
|
||||
get => _loadGUIParameters;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _loadGUIParameters, value);
|
||||
ViewStatusStorage.Set("GUI.PositionAndSize.Load", value.ToString());
|
||||
if (value)
|
||||
{
|
||||
if (SaveGUIParametersOnClosing)
|
||||
{
|
||||
Application.Current.MainWindow.Closing += SaveGUIParameters;
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveGUIParameters();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _saveGUIParametersOnClosing = Convert.ToBoolean(ViewStatusStorage.Get("GUI.PositionAndSize.SaveOnClosing", bool.TrueString));
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to save GUI parameters on closing main window.
|
||||
/// </summary>
|
||||
public bool SaveGUIParametersOnClosing
|
||||
{
|
||||
get => _saveGUIParametersOnClosing;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _saveGUIParametersOnClosing, value);
|
||||
ViewStatusStorage.Set("GUI.PositionAndSize.SaveOnClosing", value.ToString());
|
||||
if (value)
|
||||
{
|
||||
Application.Current.MainWindow.Closing += SaveGUIParameters;
|
||||
}
|
||||
else
|
||||
{
|
||||
Application.Current.MainWindow.Closing -= SaveGUIParameters;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveGUIParameters(object sender, EventArgs e)
|
||||
{
|
||||
SaveGUIParameters();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save main window left edge, top edge, width and heigth.
|
||||
/// </summary>
|
||||
public void SaveGUIParameters()
|
||||
{
|
||||
// 请在配置文件中修改该部分配置,暂不支持从GUI设置
|
||||
// Please modify this part of configuration in the configuration file.
|
||||
ViewStatusStorage.Set("GUI.PositionAndSize.Load", LoadGUIParameters.ToString());
|
||||
ViewStatusStorage.Set("GUI.PositionAndSize.SaveOnClosing", SaveGUIParametersOnClosing.ToString());
|
||||
|
||||
ViewStatusStorage.Set("GUI.Position.Left", Application.Current.MainWindow.Left.ToString());
|
||||
ViewStatusStorage.Set("GUI.Position.Top", Application.Current.MainWindow.Top.ToString());
|
||||
ViewStatusStorage.Set("GUI.Size.Width", Application.Current.MainWindow.Width.ToString());
|
||||
ViewStatusStorage.Set("GUI.Size.Height", Application.Current.MainWindow.Height.ToString());
|
||||
}
|
||||
|
||||
private bool _useAlternateStage = Convert.ToBoolean(ViewStatusStorage.Get("GUI.UseAlternateStage", bool.FalseString));
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user