1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 04:53:21 +08:00

Merge pull request #29347 from peppy/daily-challenge-intro-audio-auto-download

Start playing the daily challenge track during the intro (and automatically download)
This commit is contained in:
Bartłomiej Dach 2024-08-12 10:36:14 +02:00 committed by GitHub
commit 7b51ec8509
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 68 additions and 22 deletions

View File

@ -563,7 +563,7 @@ namespace osu.Game.Beatmaps
remove => workingBeatmapCache.OnInvalidated -= value; remove => workingBeatmapCache.OnInvalidated -= value;
} }
public override bool IsAvailableLocally(BeatmapSetInfo model) => Realm.Run(realm => realm.All<BeatmapSetInfo>().Any(s => s.OnlineID == model.OnlineID)); public override bool IsAvailableLocally(BeatmapSetInfo model) => Realm.Run(realm => realm.All<BeatmapSetInfo>().Any(s => s.OnlineID == model.OnlineID && !s.DeletePending));
#endregion #endregion

View File

@ -390,7 +390,7 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
base.LoadComplete(); base.LoadComplete();
beatmapAvailabilityTracker.SelectedItem.Value = playlistItem; beatmapAvailabilityTracker.SelectedItem.Value = playlistItem;
beatmapAvailabilityTracker.Availability.BindValueChanged(_ => trySetDailyChallengeBeatmap(), true); beatmapAvailabilityTracker.Availability.BindValueChanged(_ => TrySetDailyChallengeBeatmap(this, beatmapManager, rulesets, musicController, playlistItem), true);
userModsSelectOverlayRegistration = overlayManager?.RegisterBlockingOverlay(userModsSelectOverlay); userModsSelectOverlayRegistration = overlayManager?.RegisterBlockingOverlay(userModsSelectOverlay);
userModsSelectOverlay.SelectedItem.Value = playlistItem; userModsSelectOverlay.SelectedItem.Value = playlistItem;
@ -402,15 +402,6 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
dailyChallengeInfo.BindValueChanged(dailyChallengeChanged); dailyChallengeInfo.BindValueChanged(dailyChallengeChanged);
} }
private void trySetDailyChallengeBeatmap()
{
var beatmap = beatmapManager.QueryBeatmap(b => b.OnlineID == playlistItem.Beatmap.OnlineID);
Beatmap.Value = beatmapManager.GetWorkingBeatmap(beatmap); // this will gracefully fall back to dummy beatmap if missing locally.
Ruleset.Value = rulesets.GetRuleset(playlistItem.RulesetID);
applyLoopingToTrack();
}
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() => private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{ {
if (state.NewValue != APIState.Online) if (state.NewValue != APIState.Online)
@ -444,7 +435,7 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
waves.Show(); waves.Show();
roomManager.JoinRoom(room); roomManager.JoinRoom(room);
applyLoopingToTrack(); startLoopingTrack(this, musicController);
metadataClient.BeginWatchingMultiplayerRoom(room.RoomID.Value!.Value).ContinueWith(t => metadataClient.BeginWatchingMultiplayerRoom(room.RoomID.Value!.Value).ContinueWith(t =>
{ {
@ -466,15 +457,15 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
}); });
}, TaskContinuationOptions.OnlyOnRanToCompletion); }, TaskContinuationOptions.OnlyOnRanToCompletion);
beatmapAvailabilityTracker.SelectedItem.Value = playlistItem;
beatmapAvailabilityTracker.Availability.BindValueChanged(_ => trySetDailyChallengeBeatmap(), true);
userModsSelectOverlay.SelectedItem.Value = playlistItem; userModsSelectOverlay.SelectedItem.Value = playlistItem;
TrySetDailyChallengeBeatmap(this, beatmapManager, rulesets, musicController, playlistItem);
} }
public override void OnResuming(ScreenTransitionEvent e) public override void OnResuming(ScreenTransitionEvent e)
{ {
base.OnResuming(e); base.OnResuming(e);
applyLoopingToTrack(); startLoopingTrack(this, musicController);
// re-apply mods as they may have been changed by a child screen // re-apply mods as they may have been changed by a child screen
// (one known instance of this is showing a replay). // (one known instance of this is showing a replay).
updateMods(); updateMods();
@ -503,17 +494,30 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
return base.OnExiting(e); return base.OnExiting(e);
} }
private void applyLoopingToTrack() public static void TrySetDailyChallengeBeatmap(OsuScreen screen, BeatmapManager beatmaps, RulesetStore rulesets, MusicController music, PlaylistItem item)
{ {
if (!this.IsCurrentScreen()) if (!screen.IsCurrentScreen())
return; return;
var track = Beatmap.Value?.Track; var beatmap = beatmaps.QueryBeatmap(b => b.OnlineID == item.Beatmap.OnlineID);
screen.Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmap); // this will gracefully fall back to dummy beatmap if missing locally.
screen.Ruleset.Value = rulesets.GetRuleset(item.RulesetID);
startLoopingTrack(screen, music);
}
private static void startLoopingTrack(OsuScreen screen, MusicController music)
{
if (!screen.IsCurrentScreen())
return;
var track = screen.Beatmap.Value?.Track;
if (track != null) if (track != null)
{ {
Beatmap.Value?.PrepareTrackForPreview(true); screen.Beatmap.Value?.PrepareTrackForPreview(true);
musicController.EnsurePlayingSomething(); music.EnsurePlayingSomething();
} }
} }

View File

@ -12,8 +12,10 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables; using osu.Game.Beatmaps.Drawables;
using osu.Game.Configuration;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Rulesets; using osu.Game.Rulesets;
@ -26,6 +28,10 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
{ {
public partial class DailyChallengeIntro : OsuScreen public partial class DailyChallengeIntro : OsuScreen
{ {
public override bool DisallowExternalBeatmapRulesetChanges => true;
public override bool? ApplyModTrackAdjustments => true;
private readonly Room room; private readonly Room room;
private readonly PlaylistItem item; private readonly PlaylistItem item;
@ -48,6 +54,20 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
[Cached] [Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Plum); private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);
[Cached]
private readonly OnlinePlayBeatmapAvailabilityTracker beatmapAvailabilityTracker = new OnlinePlayBeatmapAvailabilityTracker();
private bool shouldBePlayingMusic;
[Resolved]
private BeatmapManager beatmapManager { get; set; } = null!;
[Resolved]
private RulesetStore rulesets { get; set; } = null!;
[Resolved]
private MusicController musicController { get; set; } = null!;
public DailyChallengeIntro(Room room) public DailyChallengeIntro(Room room)
{ {
this.room = room; this.room = room;
@ -59,7 +79,7 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
protected override BackgroundScreen CreateBackground() => new DailyChallengeIntroBackgroundScreen(colourProvider); protected override BackgroundScreen CreateBackground() => new DailyChallengeIntroBackgroundScreen(colourProvider);
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(BeatmapDifficultyCache difficultyCache) private void load(BeatmapDifficultyCache difficultyCache, BeatmapModelDownloader beatmapDownloader, OsuConfigManager config)
{ {
const float horizontal_info_size = 500f; const float horizontal_info_size = 500f;
@ -69,6 +89,7 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
beatmapAvailabilityTracker,
introContent = new Container introContent = new Container
{ {
Alpha = 0f, Alpha = 0f,
@ -296,11 +317,25 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
beatmapBackgroundLoaded = true; beatmapBackgroundLoaded = true;
updateAnimationState(); updateAnimationState();
}); });
if (config.Get<bool>(OsuSetting.AutomaticallyDownloadMissingBeatmaps))
{
if (!beatmapManager.IsAvailableLocally(new BeatmapSetInfo { OnlineID = item.Beatmap.BeatmapSet!.OnlineID }))
beatmapDownloader.Download(item.Beatmap.BeatmapSet!, config.Get<bool>(OsuSetting.PreferNoVideo));
}
} }
public override void OnEntering(ScreenTransitionEvent e) public override void OnEntering(ScreenTransitionEvent e)
{ {
base.OnEntering(e); base.OnEntering(e);
beatmapAvailabilityTracker.SelectedItem.Value = item;
beatmapAvailabilityTracker.Availability.BindValueChanged(availability =>
{
if (shouldBePlayingMusic && availability.NewValue.State == DownloadState.LocallyAvailable)
DailyChallenge.TrySetDailyChallengeBeatmap(this, beatmapManager, rulesets, musicController, item);
}, true);
this.FadeInFromZero(400, Easing.OutQuint); this.FadeInFromZero(400, Easing.OutQuint);
updateAnimationState(); updateAnimationState();
} }
@ -365,7 +400,14 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
beatmapContent.FadeInFromZero(280, Easing.InQuad); beatmapContent.FadeInFromZero(280, Easing.InQuad);
using (BeginDelayedSequence(300)) using (BeginDelayedSequence(300))
Schedule(() => ApplyToBackground(bs => ((RoomBackgroundScreen)bs).SelectedItem.Value = item)); {
Schedule(() =>
{
shouldBePlayingMusic = true;
DailyChallenge.TrySetDailyChallengeBeatmap(this, beatmapManager, rulesets, musicController, item);
ApplyToBackground(bs => ((RoomBackgroundScreen)bs).SelectedItem.Value = item);
});
}
using (BeginDelayedSequence(400)) using (BeginDelayedSequence(400))
flash.FadeOutFromOne(5000, Easing.OutQuint); flash.FadeOutFromOne(5000, Easing.OutQuint);