Skip to content

Commit

Permalink
optimize change window size method
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Dec 31, 2023
1 parent 4b40de0 commit 2d5925b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/Starward/Messages/WindowSizeModeChangedMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Starward.Messages;

public record WindowSizeModeChangedMessage(int Mode);

16 changes: 3 additions & 13 deletions src/Starward/MyWindows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void InitializeMainWindow()
AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
AppWindow.TitleBar.IconShowOptions = IconShowOptions.ShowIconAndSystemMenu;
AppWindow.Closing += AppWindow_Closing;
ChangeWindowSize(center: true);
ChangeWindowSize();
AdaptTitleBarButtonColorToActuallTheme();
SetDragRectangles(new RectInt32(0, 0, 100000, (int)(48 * UIScale)));
AppWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, @"Assets\logo.ico"));
Expand All @@ -89,7 +89,7 @@ private void InitializeMainWindow()



public void ChangeWindowSize(int width = 0, int height = 0, bool center = false)
public void ChangeWindowSize(int width = 0, int height = 0)
{
try
{
Expand All @@ -103,17 +103,7 @@ public void ChangeWindowSize(int width = 0, int height = 0, bool center = false)
(_, false) => (1064, 648),
};
}
if (center)
{
CenterInScreen(width, height);
}
else
{
double scale = UIScale;
width = (int)(width * scale);
height = (int)(height * scale);
AppWindow.Resize(new SizeInt32(width, height));
}
CenterInScreen(width, height);
}
catch { }
}
Expand Down
21 changes: 16 additions & 5 deletions src/Starward/Pages/LauncherPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ public LauncherPage()
Lang.GameSettingPage_StartArgumentDesc,
("{Unity Standalone Player Command Line Arguments}", "https://docs.unity3d.com/Manual/PlayerCommandLineArguments.html"));

if (AppConfig.WindowSizeMode > 0)
{
Grid_BannerAndPost.Width = 364;
RowDefinition_BannerAndPost.Height = new GridLength(168);
}
InitializeBannerSize();

_timer = DispatcherQueue.CreateTimer();
_timer.Interval = TimeSpan.FromSeconds(5);
Expand All @@ -88,6 +84,7 @@ public LauncherPage()
_ = GetGameNoticesAlertAsync();
});
WeakReferenceMessenger.Default.Register<GameNoticeRedHotDisabledChanged>(this, (_, _) => _ = GetGameNoticesAlertAsync());
WeakReferenceMessenger.Default.Register<WindowSizeModeChangedMessage>(this, (_, _) => InitializeBannerSize());
}


Expand Down Expand Up @@ -155,6 +152,20 @@ private void InitializeGameBiz()



private void InitializeBannerSize()
{
if (AppConfig.WindowSizeMode == 0)
{
Grid_BannerAndPost.Width = 432;
RowDefinition_BannerAndPost.Height = new GridLength(200);
}
else
{
Grid_BannerAndPost.Width = 364;
RowDefinition_BannerAndPost.Height = new GridLength(168);
}
}




Expand Down
1 change: 1 addition & 0 deletions src/Starward/Pages/Setting/AppearanceSettingPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private void RadioButton_WindowSize_Click(object sender, RoutedEventArgs e)
};
AppConfig.WindowSizeMode = index;
MainWindow.Current.ChangeWindowSize();
WeakReferenceMessenger.Default.Send(new WindowSizeModeChangedMessage(index));
}
}
catch { }
Expand Down

0 comments on commit 2d5925b

Please sign in to comment.