Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Background Enhancements Part 1 #560

Merged
merged 30 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2b63d85
add i18n for new btn
Cryotechnic May 30, 2024
b77233d
replicate change background function in quick-settings
Cryotechnic May 30, 2024
fa54432
add new dialog i18n
Cryotechnic May 30, 2024
1e04350
add basic dialog for custom region support in quick settings
Cryotechnic May 30, 2024
0abee0b
hide button if box is unchecked
Cryotechnic May 30, 2024
7811d9d
Merge branch 'main' into custom-game-bg
Cryotechnic Jul 8, 2024
658c73c
update branch submodules
Cryotechnic Jul 8, 2024
173c3ff
more submodule updates
Cryotechnic Jul 8, 2024
047858d
add dialog spawn on btn click
Cryotechnic Jul 8, 2024
64361b2
add supported file extension list
Cryotechnic Jul 8, 2024
94a1638
Merge branch 'main' into custom-game-bg
Cryotechnic Aug 18, 2024
f8daf08
bump submodule ref commits
Cryotechnic Aug 18, 2024
485069c
remove dialog for custom region bg
Cryotechnic Aug 18, 2024
ae084ca
re-enable picker functionality without dialog
Cryotechnic Aug 18, 2024
7ebe568
Remove unused code
Cryotechnic Aug 18, 2024
26b38b5
Split title & section description in XAML
Cryotechnic Aug 18, 2024
e8df9fb
Fix toggle state not reflecting after new region load
Cryotechnic Aug 20, 2024
02d9631
Merge remote-tracking branch 'origin/main' into custom-game-bg
Cryotechnic Aug 24, 2024
2b3b850
[skip ci] change bg on button click
Cryotechnic Aug 25, 2024
18693e4
Adding string store to background path
neon-nyan Aug 25, 2024
d08e264
[StarRail GSP] Stop graphics settings saving if A/B test flag is found
bagusnl Aug 25, 2024
51bc33c
[GSP] Use nullable directive when saving GSP values
bagusnl Aug 25, 2024
f68cf82
Fix things
neon-nyan Aug 25, 2024
403b54c
wtf
bagusnl Aug 25, 2024
7a48b1e
Untie regional background to custom app background
bagusnl Aug 25, 2024
8cdb8fb
Fix video to image opacity bug
neon-nyan Aug 25, 2024
b299794
Revert Background supported format for region bg
neon-nyan Aug 25, 2024
4e8f096
CodeQA
bagusnl Aug 25, 2024
7c431c8
Add notice in app settings about regional bg
bagusnl Aug 25, 2024
fef0815
XamlStyler run
bagusnl Aug 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ public override void ReloadSettings()
InitializeSettings();
}

#nullable enable
public override void SaveSettings()
{
// Save Settings
base.SaveSettings();
SettingsScreen.Save();
SettingsGeneralData.Save();
SettingVisibleBackground.Save();
SettingsWindowsHDR.Save();
SettingsScreen?.Save();
SettingsGeneralData?.Save();
SettingVisibleBackground?.Save();
SettingsWindowsHDR?.Save();
}

public override IGameSettingsUniversal AsIGameSettingsUniversal() => this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CollapseLauncher.GameSettings.StarRail.Context;
using CollapseLauncher.Interfaces;
using CollapseLauncher.Pages;
using Hi3Helper;
using Hi3Helper.EncTool;
using Microsoft.Win32;
Expand Down Expand Up @@ -329,6 +330,13 @@ public void Save()
try
{
if (RegistryRoot == null) throw new NullReferenceException($"Cannot save {_ValueName} since RegistryKey is unexpectedly not initialized!");

if (StarRailGameSettingsPage.CheckAbTest())
{
LogWriteLine("[StarRailGameSettings::Model] Graphics settings could not be saved due to A/B test flag is found!",
LogType.Error, true);
return;
}

RegistryRoot.SetValue(_GraphicsQuality, Quality.Custom, RegistryValueKind.DWord);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,19 @@ public override void ReloadSettings()
InitializeSettings();
}

#nullable enable
public override void SaveSettings()
{
// Save Settings
base.SaveSettings();
GraphicsSettings.Save();
SettingsScreen.Save();
AudioSettings_BGM.Save();
AudioSettings_Master.Save();
AudioSettings_SFX.Save();
AudioSettings_VO.Save();
AudioLanguage.Save();
TextLanguage.Save();
GraphicsSettings?.Save();
SettingsScreen?.Save();
AudioSettings_BGM?.Save();
AudioSettings_Master?.Save();
AudioSettings_SFX?.Save();
AudioSettings_VO?.Save();
AudioLanguage?.Save();
TextLanguage?.Save();
}

public override IGameSettingsUniversal AsIGameSettingsUniversal() => this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
private const string _ValueName = "CollapseLauncher_Misc";

private bool _UseCustomArguments = true;

private bool _UseCustomRegionBG = false;

private static bool _IsDeserializing;
#endregion
Expand Down Expand Up @@ -88,10 +90,30 @@
/// Use mobile layout. Currently only available for Genshin and StarRail.
/// </summary>
public bool LaunchMobileMode { get; set; } = false;

/// <summary>
/// Set custom background for given region for given game.
/// </summary>
public bool UseCustomRegionBG
{
get => _UseCustomRegionBG;
set
{
_UseCustomRegionBG = value;
if (!_IsDeserializing) Save();
}
}

#nullable enable
/// <summary>
/// The path of the custom BG for each region
/// </summary>
public string? CustomRegionBGPath { get; set; }

#endregion

#region Methods
#nullable enable

Check warning on line 116 in CollapseLauncher/Classes/GameManagement/GameSettings/Universal/RegistryClass/CollapseMiscSetting.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant nullable directive

Redundant nullable directive
public static CollapseMiscSetting Load()
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal enum MediaType
private Grid? _parentBgImageBackgroundGrid;
private Grid? _parentBgMediaPlayerBackgroundGrid;

internal MediaType CurrentAppliedMediaType = MediaType.Unknown;
internal static MediaType CurrentAppliedMediaType = MediaType.Unknown;

private CancellationTokenSourceWrapper? _cancellationToken;
private IBackgroundMediaLoader? _loaderStillImage;
Expand Down Expand Up @@ -150,8 +150,6 @@ public void Dispose()
_alternativeFileStream?.Dispose();
_alternativeFileStream = null;

CurrentAppliedMediaType = MediaType.Unknown;

_isCurrentRegistered = false;
GC.SuppressFinalize(this);
}
Expand Down Expand Up @@ -349,7 +347,7 @@ private async Task LoadBackgroundInner(string mediaPath, bool
_loaderMediaPlayer?.Show();
break;
case MediaType.StillImage:
_loaderStillImage?.Show();
_loaderStillImage?.Show(CurrentAppliedMediaType == MediaType.Media);
_loaderMediaPlayer?.Hide();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal interface IBackgroundMediaLoader : IDisposable
Task LoadAsync(string filePath, bool isForceRecreateCache = false, bool isRequestInit = false, CancellationToken token = default);
void Dimm();
void Undimm();
void Show();
void Show(bool isForceShow = false);
void Hide();
void Mute();
void Unmute();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using CollapseLauncher.Extension;
using CollapseLauncher.Helper.Animation;
using CommunityToolkit.WinUI.Animations;
using Hi3Helper;
#if USEFFMPEGFORVIDEOBG
using FFmpegInteropX;
using Hi3Helper;

#endif
using Hi3Helper.Shared.Region;
using Microsoft.UI.Composition;
Expand All @@ -18,6 +18,7 @@
using Windows.Media.Playback;
using Windows.Storage;
using Windows.Storage.FileProperties;
using static Hi3Helper.Logger;

#if USEDYNAMICVIDEOPALETTE
using CollapseLauncher.Extension;
Expand Down Expand Up @@ -101,9 +102,32 @@ public void Dispose()
CanvasDevice?.Dispose();
CurrentFrameBitmap?.Dispose();
#endif
CurrentMediaPlayer?.Dispose();
InnerCancellationToken?.Dispose();
CurrentMediaStream?.Dispose();
try
{
CurrentMediaPlayer?.Dispose();
}
catch (Exception ex)
{
LogWriteLine($"Error disposing CurrentMediaPlayer: {ex.Message}", LogType.Error, true);
}

try
{
InnerCancellationToken?.Dispose();
}
catch (Exception ex)
{
LogWriteLine($"Error disposing InnerCancellationToken: {ex.Message}", LogType.Error, true);
}

try
{
CurrentMediaStream?.Dispose();
}
catch (Exception ex)
{
LogWriteLine($"Error disposing CurrentMediaStream: {ex.Message}", LogType.Error, true);
}

GC.SuppressFinalize(this);
}
Expand Down Expand Up @@ -387,7 +411,7 @@ await Task.WhenAll(
);
}

public void Show()
public void Show(bool isForceShow = false)
{
BackgroundMediaUtility.SharedActionBlockQueue?.Post(ShowInner());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ internal class StillImageLoader : IBackgroundMediaLoader
private Grid AcrylicMask { get; }
private Grid OverlayTitleBar { get; }
private double AnimationDuration { get; }
public bool IsBackgroundDimm { get; set; }

public bool IsBackgroundDimm
{
get;
set;
}

internal StillImageLoader(
FrameworkElement parentUI,
Expand All @@ -39,6 +44,7 @@ internal StillImageLoader(
ImageUI? imageBackCurrent, ImageUI? imageBackLast,
double animationDuration = BackgroundMediaUtility.TransitionDuration)
{
GC.SuppressFinalize(this);
ParentUI = parentUI;
CurrentCompositor = parentUI.GetElementCompositor();

Expand All @@ -56,7 +62,7 @@ internal StillImageLoader(

public void Dispose()
{
GC.SuppressFinalize(this);
GC.Collect();
}

public async Task LoadAsync(string filePath, bool isImageLoadForFirstTime,
Expand Down Expand Up @@ -85,11 +91,11 @@ await Task.WhenAll(
isImageLoadForFirstTime, false),
ApplyAndSwitchImage(AnimationDuration, bitmapImage)
);

}
finally
{
GC.Collect();
GC.WaitForPendingFinalizers();
}
}

Expand All @@ -107,9 +113,11 @@ private async Task ApplyAndSwitchImage(double duration, BitmapImage imageToApply
await Task.WhenAll(
ImageBackCurrent.StartAnimation(timeSpan,
CurrentCompositor
.CreateScalarKeyFrameAnimation("Opacity", 1, 0)),
.CreateScalarKeyFrameAnimation("Opacity",
1, 0)),
ImageBackLast.StartAnimation(timeSpan,
CurrentCompositor.CreateScalarKeyFrameAnimation("Opacity",
CurrentCompositor
.CreateScalarKeyFrameAnimation("Opacity",
0, 1, timeSpan * 0.8))
);
}
Expand All @@ -124,10 +132,18 @@ public void Undimm()
BackgroundMediaUtility.SharedActionBlockQueue?.Post(ToggleImageVisibility(false));
}

private async Task ToggleImageVisibility(bool hideImage, bool completeInvisible = false)
private async Task ToggleImageVisibility(bool hideImage, bool completeInvisible = false, bool isForceShow = false)
{
if (IsBackgroundDimm == hideImage) return;
IsBackgroundDimm = hideImage;
if (isForceShow)
{
hideImage = false;
completeInvisible = false;
}
else
{
if (IsBackgroundDimm == hideImage) return;
IsBackgroundDimm = hideImage;
}

TimeSpan duration = TimeSpan.FromSeconds(hideImage
? BackgroundMediaUtility.TransitionDuration
Expand All @@ -141,7 +157,26 @@ private async Task ToggleImageVisibility(bool hideImage, bool completeInvisible
Vector3 toTranslate = new Vector3(-((float)(ImageBackParentGrid?.ActualWidth ?? 0) * (toScale - 1f) / 2),
-((float)(ImageBackParentGrid?.ActualHeight ?? 0) * (toScale - 1f) / 2), 0);

if (completeInvisible)
if (isForceShow)
{
await Task.WhenAll(
AcrylicMask.StartAnimation(
duration,
CurrentCompositor.CreateScalarKeyFrameAnimation("Opacity", hideImage ? 1f : 0f, hideImage ? 0f : 1f)
),
OverlayTitleBar.StartAnimation(
duration,
CurrentCompositor.CreateScalarKeyFrameAnimation("Opacity", hideImage ? 0f : 1f, hideImage ? 1f : 0f)
),
ImageBackParentGrid.StartAnimation(
duration,
CurrentCompositor.CreateVector3KeyFrameAnimation("Scale", new Vector3(hideImage ? toScale : fromScale), new Vector3(!hideImage ? toScale : fromScale)),
CurrentCompositor.CreateVector3KeyFrameAnimation("Translation", hideImage ? toTranslate : fromTranslate, !hideImage ? toTranslate : fromTranslate),
CurrentCompositor.CreateScalarKeyFrameAnimation("Opacity", 1f, 0f)
)
);
}
else if (completeInvisible)
{
await Task.WhenAll(
ImageBackParentGrid.StartAnimation(
Expand Down Expand Up @@ -170,10 +205,10 @@ await Task.WhenAll(
}
}

public void Show()
public void Show(bool isForceShow = false)
{
if (ImageBackParentGrid?.Opacity > 0f) return;
BackgroundMediaUtility.SharedActionBlockQueue?.Post(ToggleImageVisibility(false, true));
BackgroundMediaUtility.SharedActionBlockQueue?.Post(ToggleImageVisibility(false, true, isForceShow));
}

public void Hide()
Expand Down
Loading
Loading