From 6b0d925bb011d11f9c50e429d4887e0445dd46bc Mon Sep 17 00:00:00 2001 From: Bagus Nur Listiyono Date: Tue, 24 Dec 2024 23:01:09 +0700 Subject: [PATCH] [ZZZ GSP] Fix default resolution logic holy shit --- .../ZenlessGameSettingsPage.Ext.cs | 36 ++++++++++++------- .../ZenlessGameSettingsPage.xaml.cs | 30 ++++++++++------ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/ZenlessGameSettingsPage.Ext.cs b/CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/ZenlessGameSettingsPage.Ext.cs index 8dd0d6dfe..41563cfe1 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/ZenlessGameSettingsPage.Ext.cs +++ b/CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/ZenlessGameSettingsPage.Ext.cs @@ -1,5 +1,6 @@ using CollapseLauncher.GameSettings.Zenless.Enums; using CollapseLauncher.Helper; +using Hi3Helper.Win32.Screen; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using System.Collections.Generic; @@ -287,16 +288,18 @@ public int ResolutionIndexSelected get { int res = Settings.GeneralData?.ResolutionIndex ?? -1; - if (res > 0) + if (res < 0) { - // ReSharper disable once SimplifyConditionalTernaryExpression - bool isFullscreen = res + 1 < ScreenResolutionIsFullscreenIdx.Count ? ScreenResolutionIsFullscreenIdx[res] : false; - IsFullscreenEnabled = isFullscreen; - - return res + 1; + IsFullscreenEnabled = true; + return 0; } + // ReSharper disable once SimplifyConditionalTernaryExpression + bool isFullscreen = res + 1 < ScreenResolutionIsFullscreenIdx.Count ? ScreenResolutionIsFullscreenIdx[res] : false; + IsFullscreenEnabled = isFullscreen; + + var retVal = res; - return 0; // Return 0 if res value is -1 (default resolution) or 0 (practically default) + return retVal; } set { @@ -305,20 +308,29 @@ public int ResolutionIndexSelected // -1 is default resolution // but our method was 0 based index too without the default res // so uh, yeah + if (HasWeirdResolution && value == 0) + { + Settings.GeneralData.ResolutionIndex = -1; + Settings.SettingsScreen.width = SizeProp.Width; + Settings.SettingsScreen.height = SizeProp.Height; + return; + } + + Settings.GeneralData.ResolutionIndex = value; + + var innerValue = value - (HasWeirdResolution ? 1 : 0); + if (innerValue < 0) innerValue = 0; - var innerValue = value - 1; - if (innerValue < 0) return; - Settings.GeneralData.ResolutionIndex = value - 1; // ReSharper disable once SimplifyConditionalTernaryExpression bool isFullscreen = innerValue + 1 < ScreenResolutionIsFullscreenIdx.Count ? ScreenResolutionIsFullscreenIdx[innerValue] : false; IsFullscreenEnabled = isFullscreen; Settings.SettingsScreen.width = - int.Parse(Regex.Replace(GameResolutionSelector.Items[value > 0 ? value : 1].ToString().Split('x')[0], + int.Parse(Regex.Replace(GameResolutionSelector.Items[value].ToString().Split('x')[0], @"\D", "")); Settings.SettingsScreen.height = - int.Parse(Regex.Replace(GameResolutionSelector.Items[value > 0 ? value : 1].ToString().Split('x')[1], + int.Parse(Regex.Replace(GameResolutionSelector.Items[value].ToString().Split('x')[1], @"\D", "")); } } diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/ZenlessGameSettingsPage.xaml.cs b/CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/ZenlessGameSettingsPage.xaml.cs index 4e699ce3e..943e69977 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/ZenlessGameSettingsPage.xaml.cs +++ b/CollapseLauncher/XAMLs/MainApp/Pages/GameSettingsPages/ZenlessGameSettingsPage.xaml.cs @@ -126,7 +126,7 @@ private string[] GetFilesRelativePaths(string gameDir, string relativePath) return relativeFilePath; }).ToArray(); } - + private void RegistryImportClick(object sender, RoutedEventArgs e) { try @@ -153,6 +153,9 @@ private void RegistryImportClick(object sender, RoutedEventArgs e) ToggleRegistrySubscribe(true); } } + + private bool HasWeirdResolution { get; set; } + private System.Drawing.Size SizeProp { get; set; } private void InitializeSettings(object sender, RoutedEventArgs e) { @@ -160,8 +163,9 @@ private void InitializeSettings(object sender, RoutedEventArgs e) { BackgroundImgChanger.ToggleBackground(true); - var resList = new List(); - resList.Add(Lang._SettingsPage.AppThemes_Default); + var resList = new List(); + SizeProp = WindowUtility.CurrentScreenProp.GetScreenSize(); + //SizeProp = new System.Drawing.Size(2560, 1600); List resFullscreen = GetResPairs_Fullscreen(); List resWindowed = GetResPairs_Windowed(); ScreenResolutionIsFullscreenIdx.AddRange(Enumerable.Range(0, resFullscreen.Count).Select(_ => true)); @@ -170,7 +174,14 @@ private void InitializeSettings(object sender, RoutedEventArgs e) resList.AddRange(GetResPairs_Fullscreen()); resList.AddRange(GetResPairs_Windowed()); - GameResolutionSelector.ItemsSource = resList; + var nativeRes = $"{SizeProp.Width}x{SizeProp.Height}"; + if (!resList[0].StartsWith(nativeRes)) + { + resList.Insert(0, $"{Lang._SettingsPage.FileDownloadSettings_BurstDownloadHelp1} {string.Format(Lang._GameSettingsPage.Graphics_ResPrefixFullscreen, SizeProp.Width, SizeProp.Height)}"); + HasWeirdResolution = true; + } + GameResolutionSelector.ItemsSource = resList; + GameResolutionSelector.SelectedIndex = ResolutionIndexSelected; // Refresh if (CurrentGameProperty.IsGameRunning) { @@ -209,11 +220,11 @@ private void InitializeSettings(object sender, RoutedEventArgs e) private List GetResPairs_Fullscreen() { - var displayProp = WindowUtility.CurrentScreenProp.GetScreenSize(); - var nativeAspRatio = (double)displayProp.Width / displayProp.Height; + var nativeAspRatio = (double)SizeProp.Width / SizeProp.Height; var acH = acceptableHeight; acH.RemoveAll(h => h > WindowUtility.CurrentScreenProp.GetMaxHeight()); + //acH.RemoveAll(h => h > 1600); List resPairs = new List(); @@ -228,19 +239,18 @@ private List GetResPairs_Fullscreen() private List GetResPairs_Windowed() { - var displayProp = WindowUtility.CurrentScreenProp.GetScreenSize(); - var nativeAspRatio = (double)displayProp.Width / displayProp.Height; + var nativeAspRatio = (double)SizeProp.Width / SizeProp.Height; var wideRatio = (double)16 / 9; var ulWideRatio = (double)21 / 9; var acH = acceptableHeight; acH.RemoveAll(h => h > WindowUtility.CurrentScreenProp.GetMaxHeight()); - + //acH.RemoveAll(h => h > 1600); List resPairs = new List(); // If res is 21:9 then add proper native to the list if (Math.Abs(nativeAspRatio - ulWideRatio) < 0.01) - resPairs.Add($"{displayProp.Width}x{displayProp.Height}"); + resPairs.Add($"{SizeProp.Width}x{SizeProp.Height}"); foreach (var h in acH) {