From a0f69792a75f8bc1d22f3994b35549b810334ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=AB=E9=9B=A8?= <737345039@qq.com> Date: Wed, 19 Apr 2023 01:42:08 +0800 Subject: [PATCH 1/4] =?UTF-8?q?chore:=20=E8=B0=83=E6=95=B4=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=90=8E=E7=AA=97=E5=8F=A3=E7=9A=84=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F=E3=80=81Bootstrapper=E4=B8=AD=E5=8F=96?= =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Main/Bootstrapper.cs | 41 +++++++------------ src/MaaWpfGui/ViewModels/UI/RootViewModel.cs | 26 ------------ .../ViewModels/UI/VersionUpdateViewModel.cs | 22 ++++++++++ 3 files changed, 36 insertions(+), 53 deletions(-) diff --git a/src/MaaWpfGui/Main/Bootstrapper.cs b/src/MaaWpfGui/Main/Bootstrapper.cs index 63fef7897e..fc8264f884 100644 --- a/src/MaaWpfGui/Main/Bootstrapper.cs +++ b/src/MaaWpfGui/Main/Bootstrapper.cs @@ -39,33 +39,9 @@ namespace MaaWpfGui.Main public class Bootstrapper : Bootstrapper { private static SettingsViewModel _settingsViewModel; - private static TrayIcon _trayIconInSettingsViewModel; - - private static readonly FieldInfo _settingsViewModelIContainerFiled = - typeof(SettingsViewModel).GetField("_container", BindingFlags.NonPublic | BindingFlags.Instance); - + private static TrayIcon _trayIcon; private static ILogger _logger = Logger.None; - /// - /// Sets tray icon in . - /// - /// The instance. - /// - /// 应当只能是 在构造时调用这个函数。用反射拿 只是为了不额外修改 的定义, - /// 并顺便检查传入的 不为空(即不是随便 出来的一个 )。 - /// - internal static void SetTrayIconInSettingsViewModel(SettingsViewModel settingsViewModel) - { - _settingsViewModel = settingsViewModel; - var container = (IContainer)_settingsViewModelIContainerFiled.GetValue(settingsViewModel); - if (container != null) - { - _trayIconInSettingsViewModel = container.Get(); - } - - // TODO:出现不符合要求的settingsViewModel应当Log一下,等一个有缘人 - } - /// /// 初始化些啥自己加。 protected override void OnStart() @@ -164,10 +140,21 @@ namespace MaaWpfGui.Main /// protected override void DisplayRootView(object rootViewModel) { - var windowManager = (Helper.WindowManager)GetInstance(typeof(Helper.WindowManager)); + var windowManager = (IWindowManager)GetInstance(typeof(Helper.WindowManager)); windowManager.ShowWindow(rootViewModel); } + /// + protected override void OnLaunch() + { + var versionUpdateViewModel = (VersionUpdateViewModel)GetInstance(typeof(VersionUpdateViewModel)); + versionUpdateViewModel.ShowUpdateOrDownload(); + + // TrayIcon应该在显示rootViewModel之后再加载 + _trayIcon = (TrayIcon)GetInstance(typeof(TrayIcon)); + _settingsViewModel = (SettingsViewModel)GetInstance(typeof(SettingsViewModel)); + } + /// /// 退出时执行啥自己加。 protected override void OnExit(ExitEventArgs e) @@ -183,7 +170,7 @@ namespace MaaWpfGui.Main } // 注销任务栏图标 - _trayIconInSettingsViewModel.Close(); + _trayIcon.Close(); ConfigurationHelper.Release(); _logger.Information("MaaAssistantArknights GUI exited"); diff --git a/src/MaaWpfGui/ViewModels/UI/RootViewModel.cs b/src/MaaWpfGui/ViewModels/UI/RootViewModel.cs index 4f7bb4a9b5..e01acf0620 100644 --- a/src/MaaWpfGui/ViewModels/UI/RootViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/RootViewModel.cs @@ -24,8 +24,6 @@ namespace MaaWpfGui.ViewModels.UI /// public class RootViewModel : Conductor.Collection.OneActive { - private readonly IWindowManager _windowManager; - private readonly AsstProxy _asstProxy; private readonly TaskQueueViewModel _taskQueueViewModel; private readonly RecognizerViewModel _recognizerViewModel; @@ -39,8 +37,6 @@ namespace MaaWpfGui.ViewModels.UI /// The IoC container. public RootViewModel(IContainer container) { - _windowManager = container.Get(); - _asstProxy = container.Get(); _taskQueueViewModel = container.Get(); _recognizerViewModel = container.Get(); @@ -55,7 +51,6 @@ namespace MaaWpfGui.ViewModels.UI CheckAndUpdateNow(); InitViewModels(); InitProxy(); - ShowUpdateOrDownload(); } private async void InitProxy() @@ -79,24 +74,6 @@ namespace MaaWpfGui.ViewModels.UI return _versionUpdateViewModel.CheckAndUpdateNow(); } - private async void ShowUpdateOrDownload() - { - if (_versionUpdateViewModel.IsFirstBootAfterUpdate) - { - _versionUpdateViewModel.IsFirstBootAfterUpdate = false; - _windowManager.ShowWindow(_versionUpdateViewModel); - } - else - { - var ret = await _versionUpdateViewModel.CheckAndDownloadUpdate(); - - if (ret == VersionUpdateViewModel.CheckUpdateRetT.OK) - { - _versionUpdateViewModel.AskToRestart(); - } - } - } - private string _windowTitle = "MAA"; /// @@ -111,9 +88,6 @@ namespace MaaWpfGui.ViewModels.UI protected override void OnInitialActivate() { base.OnInitialActivate(); - - // TrayIcon应该在显示rootViewModel之后再加载 - Bootstrapper.SetTrayIconInSettingsViewModel(_settingsViewModel); } /// diff --git a/src/MaaWpfGui/ViewModels/UI/VersionUpdateViewModel.cs b/src/MaaWpfGui/ViewModels/UI/VersionUpdateViewModel.cs index 3817b94c10..a8d5ba149c 100644 --- a/src/MaaWpfGui/ViewModels/UI/VersionUpdateViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/VersionUpdateViewModel.cs @@ -43,6 +43,7 @@ namespace MaaWpfGui.ViewModels.UI /// public class VersionUpdateViewModel : Screen { + private readonly IWindowManager _windowManager; private readonly SettingsViewModel _settingsViewModel; private readonly TaskQueueViewModel _taskQueueViewModel; private readonly IHttpService _httpService; @@ -53,6 +54,7 @@ namespace MaaWpfGui.ViewModels.UI /// The IoC container. public VersionUpdateViewModel(IContainer container) { + _windowManager = container.Get(); _settingsViewModel = container.Get(); _taskQueueViewModel = container.Get(); _httpService = container.Get(); @@ -353,6 +355,26 @@ namespace MaaWpfGui.ViewModels.UI Native, } + /// + /// 如果是在更新后第一次启动,显示ReleaseNote弹窗,否则检查更新并下载更新包。 + /// + public async void ShowUpdateOrDownload() + { + if (IsFirstBootAfterUpdate) + { + IsFirstBootAfterUpdate = false; + _windowManager.ShowWindow(this); + } + else + { + var ret = await CheckAndDownloadUpdate(); + if (ret == CheckUpdateRetT.OK) + { + AskToRestart(); + } + } + } + /// /// 检查更新,并下载更新包。 /// From 1b7305057d327ad0ba0cbad975cf20ab3130772e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=AB=E9=9B=A8?= <737345039@qq.com> Date: Tue, 18 Apr 2023 22:28:05 +0800 Subject: [PATCH 2/4] =?UTF-8?q?perf:=20=E7=BA=B5=E5=90=91=E4=B8=9D?= =?UTF-8?q?=E6=BB=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Views/UI/CopilotView.xaml | 5 +++-- src/MaaWpfGui/Views/UI/RecognizerView.xaml | 11 +++++++---- src/MaaWpfGui/Views/UI/SettingsView.xaml | 6 ++++-- src/MaaWpfGui/Views/UI/TaskQueueView.xaml | 5 +++-- src/MaaWpfGui/Views/UI/VersionUpdateView.xaml | 5 ++++- .../Views/UserControl/FightSettingsUserControl.xaml | 5 +++-- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/MaaWpfGui/Views/UI/CopilotView.xaml b/src/MaaWpfGui/Views/UI/CopilotView.xaml index 9064592603..d4ce34a5f5 100644 --- a/src/MaaWpfGui/Views/UI/CopilotView.xaml +++ b/src/MaaWpfGui/Views/UI/CopilotView.xaml @@ -118,9 +118,10 @@ - @@ -138,7 +139,7 @@ - + - - + - - + - - + diff --git a/src/MaaWpfGui/Views/UI/TaskQueueView.xaml b/src/MaaWpfGui/Views/UI/TaskQueueView.xaml index c163fad1d2..4f42fda4c9 100644 --- a/src/MaaWpfGui/Views/UI/TaskQueueView.xaml +++ b/src/MaaWpfGui/Views/UI/TaskQueueView.xaml @@ -187,9 +187,10 @@ - - + diff --git a/src/MaaWpfGui/Views/UI/VersionUpdateView.xaml b/src/MaaWpfGui/Views/UI/VersionUpdateView.xaml index f787ab2068..96c7714641 100644 --- a/src/MaaWpfGui/Views/UI/VersionUpdateView.xaml +++ b/src/MaaWpfGui/Views/UI/VersionUpdateView.xaml @@ -57,7 +57,10 @@ BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Focusable="False"> - + + diff --git a/src/MaaWpfGui/Views/UserControl/FightSettingsUserControl.xaml b/src/MaaWpfGui/Views/UserControl/FightSettingsUserControl.xaml index 2cb661dd95..fea1e382b1 100644 --- a/src/MaaWpfGui/Views/UserControl/FightSettingsUserControl.xaml +++ b/src/MaaWpfGui/Views/UserControl/FightSettingsUserControl.xaml @@ -16,7 +16,8 @@ d:DataContext="{d:DesignInstance {x:Type ui:TaskQueueViewModel}}" d:DesignWidth="250" mc:Ignorable="d"> - + @@ -294,5 +295,5 @@ - + From 987368ba73721d8a7e00d3622195835a5ce08225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=AB=E9=9B=A8?= <737345039@qq.com> Date: Wed, 19 Apr 2023 15:09:13 +0800 Subject: [PATCH 3/4] chore: use TabItem instead buttons in RecognizerView --- src/MaaWpfGui/Res/Themes/Dark.xaml | 1 + src/MaaWpfGui/Res/Themes/Light.xaml | 2 +- .../ViewModels/UI/RecognizerViewModel.cs | 18 - src/MaaWpfGui/Views/UI/RecognizerView.xaml | 325 +++++++++--------- src/MaaWpfGui/Views/UI/VersionUpdateView.xaml | 2 +- 5 files changed, 159 insertions(+), 189 deletions(-) diff --git a/src/MaaWpfGui/Res/Themes/Dark.xaml b/src/MaaWpfGui/Res/Themes/Dark.xaml index 05bb215bd1..73f9d85517 100644 --- a/src/MaaWpfGui/Res/Themes/Dark.xaml +++ b/src/MaaWpfGui/Res/Themes/Dark.xaml @@ -4,6 +4,7 @@ + diff --git a/src/MaaWpfGui/Res/Themes/Light.xaml b/src/MaaWpfGui/Res/Themes/Light.xaml index 1276b5fa7d..b6ac4bcdbc 100644 --- a/src/MaaWpfGui/Res/Themes/Light.xaml +++ b/src/MaaWpfGui/Res/Themes/Light.xaml @@ -4,7 +4,7 @@ - + diff --git a/src/MaaWpfGui/ViewModels/UI/RecognizerViewModel.cs b/src/MaaWpfGui/ViewModels/UI/RecognizerViewModel.cs index eee2eba60e..868d9fdc4e 100644 --- a/src/MaaWpfGui/ViewModels/UI/RecognizerViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/RecognizerViewModel.cs @@ -53,24 +53,6 @@ namespace MaaWpfGui.ViewModels.UI _asstProxy = _container.Get(); } - private int _displayId = 0; - - public int DisplayId - { - get => _displayId; - set => SetAndNotify(ref _displayId, value); - } - - public void ChangeButtenRecruit() - { - DisplayId = 0; - } - - public void ChangeButtenDepot() - { - DisplayId = 1; - } - #region Recruit private string _recruitInfo = LocalizationHelper.GetString("RecruitmentRecognitionTip"); diff --git a/src/MaaWpfGui/Views/UI/RecognizerView.xaml b/src/MaaWpfGui/Views/UI/RecognizerView.xaml index fb1feaae52..33f05ac65d 100644 --- a/src/MaaWpfGui/Views/UI/RecognizerView.xaml +++ b/src/MaaWpfGui/Views/UI/RecognizerView.xaml @@ -16,178 +16,165 @@ d:DesignHeight="1200" d:DesignWidth="800" mc:Ignorable="d"> - - -