diff --git a/CollapseLauncher/Classes/GameManagement/GameSettings/Universal/RegistryClass/CollapseMiscSetting.cs b/CollapseLauncher/Classes/GameManagement/GameSettings/Universal/RegistryClass/CollapseMiscSetting.cs index bac13eea7..37f66920a 100644 --- a/CollapseLauncher/Classes/GameManagement/GameSettings/Universal/RegistryClass/CollapseMiscSetting.cs +++ b/CollapseLauncher/Classes/GameManagement/GameSettings/Universal/RegistryClass/CollapseMiscSetting.cs @@ -18,7 +18,7 @@ internal class CollapseMiscSetting : IGameSettingsValue private bool _UseCustomArguments = true; - private bool _UseCustomRegionBG = true; + private bool _UseCustomRegionBG = false; private static bool _IsDeserializing; #endregion @@ -103,6 +103,14 @@ public bool UseCustomRegionBG if (!_IsDeserializing) Save(); } } + +#nullable enable + /// + /// The path of the custom BG for each region + /// + public string? CustomRegionBGPath { get; set; } +#nullable restore + #endregion #region Methods diff --git a/CollapseLauncher/XAMLs/MainApp/MainPage.xaml.cs b/CollapseLauncher/XAMLs/MainApp/MainPage.xaml.cs index d5289384d..23f369c39 100644 --- a/CollapseLauncher/XAMLs/MainApp/MainPage.xaml.cs +++ b/CollapseLauncher/XAMLs/MainApp/MainPage.xaml.cs @@ -10,6 +10,7 @@ using CollapseLauncher.Helper.Update; using CollapseLauncher.Interfaces; using CollapseLauncher.Pages; +using CollapseLauncher.Statics; using CommunityToolkit.WinUI; using CommunityToolkit.WinUI.Animations; using Hi3Helper; @@ -486,9 +487,12 @@ private void CustomBackgroundChanger_Event(object sender, BackgroundImgProperty internal async void ChangeBackgroundImageAsRegionAsync(bool ShowLoadingMsg = false) { + GamePresetProperty currentGameProperty = GetCurrentGameProperty(); + bool isUseCustomPerRegionBg = ((IGameSettingsUniversal)currentGameProperty?._GameSettings)?.SettingsCollapseMisc?.UseCustomRegionBG ?? false; + IsCustomBG = GetAppConfigValue("UseCustomBG").ToBool(); bool isAPIBackgroundAvailable = !string.IsNullOrEmpty(LauncherMetadataHelper.CurrentMetadataConfig?.GameLauncherApi?.GameBackgroundImg); - if (IsCustomBG) + if (IsCustomBG && !isUseCustomPerRegionBg) { string BGPath = GetAppConfigValue("CustomBGPath").ToString(); if (LauncherMetadataHelper.CurrentMetadataConfig?.GameLauncherApi != null) @@ -497,6 +501,25 @@ internal async void ChangeBackgroundImageAsRegionAsync(bool ShowLoadingMsg = fal string.IsNullOrEmpty(BGPath) ? AppDefaultBG : BGPath; } } + else if (isUseCustomPerRegionBg && IsCustomBG) + { + string regionBgPath = ((IGameSettingsUniversal)currentGameProperty?._GameSettings)?.SettingsCollapseMisc?.CustomRegionBGPath; + + if (!string.IsNullOrEmpty(regionBgPath) + && File.Exists(regionBgPath)) + { + LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal = regionBgPath; + } + else if (isAPIBackgroundAvailable) + { + await DownloadBackgroundImage(default); + if (((IGameSettingsUniversal)currentGameProperty?._GameSettings)?.SettingsCollapseMisc != null) + { + ((IGameSettingsUniversal)currentGameProperty._GameSettings).SettingsCollapseMisc.CustomRegionBGPath = + LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImg; + } + } + } else if (isAPIBackgroundAvailable) { try @@ -515,7 +538,9 @@ internal async void ChangeBackgroundImageAsRegionAsync(bool ShowLoadingMsg = fal if (!isAPIBackgroundAvailable && !IsCustomBG && LauncherMetadataHelper.CurrentMetadataConfig?.GameLauncherApi != null) LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal = AppDefaultBG; - if ((!IsCustomBG || IsFirstStartup) && LauncherMetadataHelper.CurrentMetadataConfig?.GameLauncherApi != null) + // If the custom per region is enabled, then execute below + if (((IsCustomBG || IsFirstStartup) && LauncherMetadataHelper.CurrentMetadataConfig?.GameLauncherApi != null) + || isUseCustomPerRegionBg) { BackgroundImgChanger.ChangeBackground(LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal, () => @@ -523,7 +548,7 @@ internal async void ChangeBackgroundImageAsRegionAsync(bool ShowLoadingMsg = fal IsFirstStartup = false; ColorPaletteUtility.ReloadPageTheme(this, CurrentAppTheme); }, - IsCustomBG); + IsCustomBG && !isUseCustomPerRegionBg); } } #endregion diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml b/CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml index 66d0317c1..93811051d 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml +++ b/CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml @@ -1920,17 +1920,15 @@ Margin="0,8,0,0" Style="{ThemeResource BodyStrongTextBlockStyle}" Text="{x:Bind helper:Locale.Lang._HomePage.GameSettings_Panel3CustomBGRegionSectionTitle}" /> -