From a227feecea3b4d9c92b9e17a583026358fe284d1 Mon Sep 17 00:00:00 2001 From: Scighost Date: Thu, 4 Jan 2024 00:45:02 +0800 Subject: [PATCH] after starting game action #527 --- src/Starward.Language/Lang.Designer.cs | 27 ++++++ src/Starward.Language/Lang.resx | 9 ++ src/Starward.Language/Lang.zh-CN.resx | 41 +++++---- src/Starward/AppConfig.cs | 7 ++ src/Starward/Models/AfterStartGameAction.cs | 12 +++ src/Starward/Pages/LauncherPage.xaml.cs | 14 +-- .../Pages/Setting/ExperienceSettingPage.xaml | 30 +++++- .../Setting/ExperienceSettingPage.xaml.cs | 91 +++++++++++++++---- 8 files changed, 187 insertions(+), 44 deletions(-) create mode 100644 src/Starward/Models/AfterStartGameAction.cs diff --git a/src/Starward.Language/Lang.Designer.cs b/src/Starward.Language/Lang.Designer.cs index f15967034..d724f7cdd 100644 --- a/src/Starward.Language/Lang.Designer.cs +++ b/src/Starward.Language/Lang.Designer.cs @@ -718,6 +718,15 @@ public static string DownloadGameService_TooManyRetries { } } + /// + /// 查找类似 After Starting Game 的本地化字符串。 + /// + public static string ExperienceSettingPage_AfterStartingGame { + get { + return ResourceManager.GetString("ExperienceSettingPage_AfterStartingGame", resourceCulture); + } + } + /// /// 查找类似 Close window but keep system tray 的本地化字符串。 /// @@ -745,6 +754,15 @@ public static string ExperienceSettingPage_DisableRedDotReminderForGameNotices { } } + /// + /// 查找类似 Do nothing 的本地化字符串。 + /// + public static string ExperienceSettingPage_DoNothing { + get { + return ResourceManager.GetString("ExperienceSettingPage_DoNothing", resourceCulture); + } + } + /// /// 查找类似 Exit completely 的本地化字符串。 /// @@ -781,6 +799,15 @@ public static string ExperienceSettingPage_MinimizeToSystemTray { } } + /// + /// 查找类似 Minimize to taskbar 的本地化字符串。 + /// + public static string ExperienceSettingPage_MinimizeToTaskbar { + get { + return ResourceManager.GetString("ExperienceSettingPage_MinimizeToTaskbar", resourceCulture); + } + } + /// /// 查找类似 Data Folder 的本地化字符串。 /// diff --git a/src/Starward.Language/Lang.resx b/src/Starward.Language/Lang.resx index 52063efb1..fbb268880 100644 --- a/src/Starward.Language/Lang.resx +++ b/src/Starward.Language/Lang.resx @@ -1253,4 +1253,13 @@ Do you accept the risk and continue to use it? Please select a folder to store your personal data, it is very important! + + Minimize to taskbar + + + Do nothing + + + After Starting Game + \ No newline at end of file diff --git a/src/Starward.Language/Lang.zh-CN.resx b/src/Starward.Language/Lang.zh-CN.resx index 3a7d42c6e..dc5d4be53 100644 --- a/src/Starward.Language/Lang.zh-CN.resx +++ b/src/Starward.Language/Lang.zh-CN.resx @@ -60,45 +60,45 @@ : and then encoded with base64 encoding. --> - + - + - - - - + + + + - - + + - - + + - - - - + + + + - + - + @@ -1253,4 +1253,13 @@ 请选择一个文件夹存储您的个人数据,它很重要! + + 游戏启动后 + + + 什么都不做 + + + 最小化到任务栏 + \ No newline at end of file diff --git a/src/Starward/AppConfig.cs b/src/Starward/AppConfig.cs index e1b7da82e..107ff0a5e 100644 --- a/src/Starward/AppConfig.cs +++ b/src/Starward/AppConfig.cs @@ -415,6 +415,13 @@ public static bool DisableGameNoticeRedHot } + public static AfterStartGameAction AfterStartGameAction + { + get => GetValue(); + set => SetValue(value); + } + + #endregion diff --git a/src/Starward/Models/AfterStartGameAction.cs b/src/Starward/Models/AfterStartGameAction.cs new file mode 100644 index 000000000..2bc61bc6b --- /dev/null +++ b/src/Starward/Models/AfterStartGameAction.cs @@ -0,0 +1,12 @@ +namespace Starward.Models; + +public enum AfterStartGameAction +{ + + Hide = 0, + + Minimize = 1, + + DoNothing = 2, + +} diff --git a/src/Starward/Pages/LauncherPage.xaml.cs b/src/Starward/Pages/LauncherPage.xaml.cs index 1a49c8dff..7129ea997 100644 --- a/src/Starward/Pages/LauncherPage.xaml.cs +++ b/src/Starward/Pages/LauncherPage.xaml.cs @@ -27,7 +27,6 @@ using System.Net.Http; using System.Threading.Tasks; using System.Timers; -using Vanara.PInvoke; using Windows.Storage; using Windows.System; @@ -608,15 +607,18 @@ private async Task StartGameAsync() else { MainPage.Current.PauseVideo(); - // todo - if (AppConfig.EnableSystemTrayIcon) + var action = AppConfig.AfterStartGameAction; + if (action is AfterStartGameAction.Minimize) { - User32.ShowWindow(MainWindow.Current.WindowHandle, ShowWindowCommand.SW_HIDE); - GC.Collect(); + MainWindow.Current.Minimize(); + } + else if (action is AfterStartGameAction.DoNothing) + { + // do nothing } else { - User32.ShowWindow(MainWindow.Current.WindowHandle, ShowWindowCommand.SW_SHOWMINIMIZED); + MainWindow.Current.Hide(); } _logger.LogInformation("Game started ({name}, {pid})", process1.ProcessName, process1.Id); if (AppConfig.IgnoreRunningGame) diff --git a/src/Starward/Pages/Setting/ExperienceSettingPage.xaml b/src/Starward/Pages/Setting/ExperienceSettingPage.xaml index fa210006e..e48d6fbaa 100644 --- a/src/Starward/Pages/Setting/ExperienceSettingPage.xaml +++ b/src/Starward/Pages/Setting/ExperienceSettingPage.xaml @@ -5,6 +5,7 @@ xmlns:lang="using:Starward.Language" xmlns:local="using:Starward.Pages.Setting" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:sm="using:Starward.Models" xmlns:sp="using:Starward.Pages" x:DefaultBindMode="OneWay" mc:Ignorable="d"> @@ -26,8 +27,33 @@ MinWidth="280" Padding="18.5,0,0,0" BorderThickness="0" - CornerRadius="8,18,18,8" - SelectionChanged="ComboBox_CloseWindowOption_SelectionChanged" /> + CornerRadius="8,18,18,8"> + + + + + + + + + + + + + + diff --git a/src/Starward/Pages/Setting/ExperienceSettingPage.xaml.cs b/src/Starward/Pages/Setting/ExperienceSettingPage.xaml.cs index fafe6e252..6923b8b8c 100644 --- a/src/Starward/Pages/Setting/ExperienceSettingPage.xaml.cs +++ b/src/Starward/Pages/Setting/ExperienceSettingPage.xaml.cs @@ -27,10 +27,25 @@ public ExperienceSettingPage() { this.InitializeComponent(); InitializeCloseWindowOption(); + InitializeAfterStartGameAction(); } + protected override void OnLoaded() + { + ComboBox_CloseWindowOption.SelectionChanged += ComboBox_CloseWindowOption_SelectionChanged; + ComboBox_AfterStartGameAction.SelectionChanged += ComboBox_AfterStartGameAction_SelectionChanged; + } + + + + protected override void OnUnloaded() + { + ComboBox_CloseWindowOption.SelectionChanged -= ComboBox_CloseWindowOption_SelectionChanged; + ComboBox_AfterStartGameAction.SelectionChanged -= ComboBox_AfterStartGameAction_SelectionChanged; + } + #region Close Window Option @@ -41,23 +56,6 @@ private void InitializeCloseWindowOption() { try { - var lang = AppConfig.Language; - ComboBox_CloseWindowOption.Items.Clear(); - ComboBox_CloseWindowOption.Items.Add(new ComboBoxItem - { - Content = Lang.ExperienceSettingPage_MinimizeToSystemTray, - Tag = "Hide", - }); - ComboBox_CloseWindowOption.Items.Add(new ComboBoxItem - { - Content = Lang.ExperienceSettingPage_ExitCompletely, - Tag = "Exit", - }); - ComboBox_CloseWindowOption.Items.Add(new ComboBoxItem - { - Content = Lang.ExperienceSettingPage_CloseWindowButKeepSystemTray, - Tag = "Close", - }); var option = AppConfig.CloseWindowOption; if (option is CloseWindowOption.Hide) { @@ -85,9 +83,7 @@ private void ComboBox_CloseWindowOption_SelectionChanged(object sender, Selectio { AppConfig.CloseWindowOption = item.Tag switch { - "Hide" => CloseWindowOption.Hide, - "Exit" => CloseWindowOption.Exit, - "Close" => CloseWindowOption.Close, + CloseWindowOption option => option, _ => CloseWindowOption.Undefined, }; } @@ -106,6 +102,61 @@ private void ComboBox_CloseWindowOption_SelectionChanged(object sender, Selectio + + #region After Start Game Action + + + + private void InitializeAfterStartGameAction() + { + try + { + var option = AppConfig.AfterStartGameAction; + if (option is AfterStartGameAction.Hide) + { + ComboBox_AfterStartGameAction.SelectedIndex = 0; + } + else if (option is AfterStartGameAction.Minimize) + { + ComboBox_AfterStartGameAction.SelectedIndex = 1; + } + else if (option is AfterStartGameAction.DoNothing) + { + ComboBox_AfterStartGameAction.SelectedIndex = 2; + } + } + catch { } + } + + + + private void ComboBox_AfterStartGameAction_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + try + { + if (ComboBox_AfterStartGameAction.SelectedItem is ComboBoxItem item) + { + AppConfig.AfterStartGameAction = item.Tag switch + { + AfterStartGameAction action => action, + _ => AfterStartGameAction.Hide, + }; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Change After Start Game Action"); + } + } + + + + + #endregion + + + + #region Features