Skip to content

Commit

Permalink
after starting game action #527
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Jan 3, 2024
1 parent 7ae593a commit a227fee
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 44 deletions.
27 changes: 27 additions & 0 deletions src/Starward.Language/Lang.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/Starward.Language/Lang.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1253,4 +1253,13 @@ Do you accept the risk and continue to use it?</value>
<data name="SelectDirectoryPage_PleaseSelectAFolderToStoreYourPersonalData" xml:space="preserve">
<value>Please select a folder to store your personal data, it is very important!</value>
</data>
<data name="ExperienceSettingPage_MinimizeToTaskbar" xml:space="preserve">
<value>Minimize to taskbar</value>
</data>
<data name="ExperienceSettingPage_DoNothing" xml:space="preserve">
<value>Do nothing</value>
</data>
<data name="ExperienceSettingPage_AfterStartingGame" xml:space="preserve">
<value>After Starting Game</value>
</data>
</root>
41 changes: 25 additions & 16 deletions src/Starward.Language/Lang.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -60,45 +60,45 @@
: and then encoded with base64 encoding.
-->
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0"/>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string"/>
<xsd:attribute name="type" type="xsd:string"/>
<xsd:attribute name="mimetype" type="xsd:string"/>
<xsd:attribute ref="xml:space"/>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string"/>
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2"/>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1"/>
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"/>
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4"/>
<xsd:attribute ref="xml:space"/>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
Expand Down Expand Up @@ -1253,4 +1253,13 @@
<data name="SelectDirectoryPage_PleaseSelectAFolderToStoreYourPersonalData" xml:space="preserve">
<value>请选择一个文件夹存储您的个人数据,它很重要!</value>
</data>
<data name="ExperienceSettingPage_AfterStartingGame" xml:space="preserve">
<value>游戏启动后</value>
</data>
<data name="ExperienceSettingPage_DoNothing" xml:space="preserve">
<value>什么都不做</value>
</data>
<data name="ExperienceSettingPage_MinimizeToTaskbar" xml:space="preserve">
<value>最小化到任务栏</value>
</data>
</root>
7 changes: 7 additions & 0 deletions src/Starward/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,13 @@ public static bool DisableGameNoticeRedHot
}


public static AfterStartGameAction AfterStartGameAction
{
get => GetValue<AfterStartGameAction>();
set => SetValue(value);
}



#endregion

Expand Down
12 changes: 12 additions & 0 deletions src/Starward/Models/AfterStartGameAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Starward.Models;

public enum AfterStartGameAction
{

Hide = 0,

Minimize = 1,

DoNothing = 2,

}
14 changes: 8 additions & 6 deletions src/Starward/Pages/LauncherPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
using System.Net.Http;
using System.Threading.Tasks;
using System.Timers;
using Vanara.PInvoke;
using Windows.Storage;
using Windows.System;

Expand Down Expand Up @@ -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)
Expand Down
30 changes: 28 additions & 2 deletions src/Starward/Pages/Setting/ExperienceSettingPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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">
<ComboBoxItem Content="{x:Bind lang:Lang.ExperienceSettingPage_MinimizeToSystemTray}" Tag="{x:Bind sm:CloseWindowOption.Hide}" />
<ComboBoxItem Content="{x:Bind lang:Lang.ExperienceSettingPage_ExitCompletely}" Tag="{x:Bind sm:CloseWindowOption.Exit}" />
<ComboBoxItem Content="{x:Bind lang:Lang.ExperienceSettingPage_CloseWindowButKeepSystemTray}" Tag="{x:Bind sm:CloseWindowOption.Close}" />
</ComboBox>
</Border>

<!-- after start game action -->
<TextBlock Margin="0,20,0,0"
FontSize="20"
FontWeight="SemiBold"
Text="{x:Bind lang:Lang.ExperienceSettingPage_AfterStartingGame}" />
<Border Height="36"
Margin="0,12,0,0"
HorizontalAlignment="Left"
Background="{ThemeResource CustomOverlayAcrylicBrush}"
CornerRadius="8,18,18,8">
<ComboBox Name="ComboBox_AfterStartGameAction"
Height="36"
MinWidth="280"
Padding="18.5,0,0,0"
BorderThickness="0"
CornerRadius="8,18,18,8">
<ComboBoxItem Content="{x:Bind lang:Lang.ExperienceSettingPage_MinimizeToSystemTray}" Tag="{x:Bind sm:AfterStartGameAction.Hide}" />
<ComboBoxItem Content="{x:Bind lang:Lang.ExperienceSettingPage_MinimizeToTaskbar}" Tag="{x:Bind sm:AfterStartGameAction.Minimize}" />
<ComboBoxItem Content="{x:Bind lang:Lang.ExperienceSettingPage_DoNothing}" Tag="{x:Bind sm:AfterStartGameAction.DoNothing}" />
</ComboBox>
</Border>


Expand Down
91 changes: 71 additions & 20 deletions src/Starward/Pages/Setting/ExperienceSettingPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
{
Expand Down Expand Up @@ -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,
};
}
Expand All @@ -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


Expand Down

0 comments on commit a227fee

Please sign in to comment.