Skip to content

Commit

Permalink
[ZZZ GSP] Fix default resolution logic
Browse files Browse the repository at this point in the history
holy shit
  • Loading branch information
bagusnl committed Dec 24, 2024
1 parent da6570d commit 6b0d925
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
{
Expand All @@ -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", ""));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private string[] GetFilesRelativePaths(string gameDir, string relativePath)
return relativeFilePath;
}).ToArray();
}

private void RegistryImportClick(object sender, RoutedEventArgs e)
{
try
Expand All @@ -153,15 +153,19 @@ 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)
{
try
{
BackgroundImgChanger.ToggleBackground(true);

var resList = new List<string>();
resList.Add(Lang._SettingsPage.AppThemes_Default);
var resList = new List<string>();
SizeProp = WindowUtility.CurrentScreenProp.GetScreenSize();
//SizeProp = new System.Drawing.Size(2560, 1600);
List<string> resFullscreen = GetResPairs_Fullscreen();
List<string> resWindowed = GetResPairs_Windowed();
ScreenResolutionIsFullscreenIdx.AddRange(Enumerable.Range(0, resFullscreen.Count).Select(_ => true));
Expand All @@ -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)
{
Expand Down Expand Up @@ -209,11 +220,11 @@ private void InitializeSettings(object sender, RoutedEventArgs e)

private List<string> 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<string> resPairs = new List<string>();

Expand All @@ -228,19 +239,18 @@ private List<string> GetResPairs_Fullscreen()

private List<string> 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<string> resPairs = new List<string>();

// 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)
{
Expand Down

0 comments on commit 6b0d925

Please sign in to comment.