Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions src/Starward.Language/Lang.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Starward.Language/Lang.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,9 @@ Do you accept the risk and continue to use it?</value>
<data name="SettingPage_RegistryBasedGameAccountSwitchingFeature" xml:space="preserve">
<value>Registry-based Game Account Switching Feature</value>
</data>
<data name="SettingPage_AutoPlayVideoBackground" xml:space="preserve">
<value>Automatically play the video background</value>
</data>
<data name="ToolboxSetting_ZZZGachaItemImages" xml:space="preserve">
<value>ZZZ Gacha Item Images</value>
</data>
Expand Down
21 changes: 21 additions & 0 deletions src/Starward/AppConfig.Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ public static int VideoBgVolume
set => SetValue(value);
}

public static bool VideoBgAutoPlay
{
get => GetValue(true);
set => SetValue(value);
}

[Obsolete("已不用", true)]
public static bool UseOneBg
{
Expand Down Expand Up @@ -598,6 +604,21 @@ public static void SetGameBackgroundIds(GameBiz biz, string? value)
SetValue(value, $"game_background_ids_{biz}");
}

/// <summary>
/// 视频背景是否播放,null 表示未手动设置,跟随全局开关 <see cref="VideoBgAutoPlay"/>
/// </summary>
public static bool? GetVideoBgManualStop(GameBiz biz)
{
return GetValue<bool?>(default, $"bg_video_stopped_{biz}");
}

/// <summary>
/// 视频背景是否播放,null 表示未手动设置,跟随全局开关 <see cref="VideoBgAutoPlay"/>
/// </summary>
public static void SetVideoBgManualStop(GameBiz biz, bool? value)
{
SetValue(value, $"bg_video_stopped_{biz}");
}

/// <summary>
/// 启用 DX12
Expand Down
6 changes: 5 additions & 1 deletion src/Starward/Features/Background/AppBackground.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,11 @@ public async Task UpdateBackgroundAsync(GameBackground? background = null)
CurrentGameBackground = gameBackground;
if (!apiCancelled && gameBackground?.Type is not GameBackground.BACKGROUND_TYPE_CUSTOM)
{
AppConfig.SetBg(CurrentGameId.GameBiz, Path.GetFileName(filePath));
// 视频背景即使因暂停而渲染为静态图,仍持久化视频文件名,以保证恢复播放时能正确匹配
string persistName = gameBackground?.Type is GameBackground.BACKGROUND_TYPE_VIDEO
? Path.GetFileName(gameBackground.Video.Url)
: Path.GetFileName(filePath);
AppConfig.SetBg(CurrentGameId.GameBiz, persistName);
var list = await _backgroundService.GetGameBackgroundsAsync(CurrentGameId);
AppConfig.SetGameBackgroundIds(CurrentGameId.GameBiz, string.Join(',', list.Select(x => x.Id)));
}
Expand Down
18 changes: 8 additions & 10 deletions src/Starward/Features/Background/BackgroundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,16 @@ public async Task<List<GameBackground>> GetGameBackgroundsAsync(GameId gameId, C
string firstBgId = backgrounds.FirstOrDefault()?.Id ?? string.Empty;
if (!string.IsNullOrWhiteSpace(lastBg) && (lastBgIds?.StartsWith(firstBgId) ?? false))
{
// 没有新背景
if (backgrounds.FirstOrDefault(x => Path.GetFileName(x.Background.Url) == lastBg) is GameBackground bg1)
{
bg1.StopVideo = true;
bg = bg1;
}
else if (backgrounds.Where(x => x.Video != null).FirstOrDefault(x => Path.GetFileName(x.Video.Url) == lastBg) is GameBackground bg2)
{
bg = bg2;
}
// 没有新背景,沿用上次选择的背景
bg = backgrounds.FirstOrDefault(x => Path.GetFileName(x.Background.Url) == lastBg)
?? backgrounds.Where(x => x.Video != null).FirstOrDefault(x => Path.GetFileName(x.Video.Url) == lastBg);
}
bg ??= backgrounds.FirstOrDefault();
// 视频背景是否播放,未手动设置时跟随全局开关
if (bg is not null && bg.Type is GameBackground.BACKGROUND_TYPE_VIDEO)
{
bg.StopVideo = AppConfig.GetVideoBgManualStop(gameId.GameBiz) ?? !AppConfig.VideoBgAutoPlay;
}
return bg;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Starward/Features/GameLauncher/GameLauncherPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -990,12 +990,14 @@ private void ChangeBackgroundImageIndex(int index)
return;
}
GameBackground current = BackgroundImages[index];
WeakReferenceMessenger.Default.Send(new BackgroundChangedMessage(current));
CanStopVideo = current.Type is GameBackground.BACKGROUND_TYPE_VIDEO;
if (CanStopVideo)
{
// 视频背景是否播放,在未手动设置时跟随全局开关
current.StopVideo = AppConfig.GetVideoBgManualStop(CurrentGameId.GameBiz) ?? !AppConfig.VideoBgAutoPlay;
StartStopButtonIcon = current.StopVideo ? PlayIcon : PauseIcon;
}
WeakReferenceMessenger.Default.Send(new BackgroundChangedMessage(current));
}
catch { }
}
Expand Down Expand Up @@ -1131,6 +1133,8 @@ private void StartOrStopVideoBackground()
if (current.Type is GameBackground.BACKGROUND_TYPE_VIDEO)
{
current.StopVideo = !current.StopVideo;
// 记录用户对该游戏视频背景是否播放的手动选择,覆盖全局开关的默认行为
AppConfig.SetVideoBgManualStop(CurrentGameId.GameBiz, current.StopVideo);
StartStopButtonIcon = current.StopVideo ? PlayIcon : PauseIcon;
WeakReferenceMessenger.Default.Send(new BackgroundChangedMessage(current));
}
Expand Down
5 changes: 5 additions & 0 deletions src/Starward/Features/Setting/GeneralSetting.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
OffContent="{x:Bind lang:Lang.SettingPage_RegistryBasedGameAccountSwitchingFeature}"
OnContent="{x:Bind lang:Lang.SettingPage_RegistryBasedGameAccountSwitchingFeature}" />

<ToggleSwitch Margin="0,12,0,0"
IsOn="{x:Bind VideoBgAutoPlay, Mode=TwoWay}"
OffContent="{x:Bind lang:Lang.SettingPage_AutoPlayVideoBackground}"
OnContent="{x:Bind lang:Lang.SettingPage_AutoPlayVideoBackground}" />


<MenuFlyoutSeparator Margin="0,20,0,0" />

Expand Down
23 changes: 23 additions & 0 deletions src/Starward/Features/Setting/GeneralSetting.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Starward.Features.Background;
using Starward.Features.ViewHost;
using Starward.Frameworks;
using System;
Expand Down Expand Up @@ -197,6 +198,28 @@ public bool EnableGameAccountSwitcher



#region 自动播放视频背景



public bool VideoBgAutoPlay
{
get; set
{
if (SetProperty(ref field, value))
{
AppConfig.VideoBgAutoPlay = value;
WeakReferenceMessenger.Default.Send(new BackgroundChangedMessage());
}
}
} = AppConfig.VideoBgAutoPlay;



#endregion



#region 系统视觉效果


Expand Down