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

Start playing the daily challenge track during the intro (and automatically download) #29347

Merged
merged 8 commits into from
Aug 12, 2024
2 changes: 1 addition & 1 deletion osu.Game/Beatmaps/BeatmapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ public event Action<WorkingBeatmap>? OnInvalidated
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

Expand Down
42 changes: 23 additions & 19 deletions osu.Game/Screens/OnlinePlay/DailyChallenge/DailyChallenge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ protected override void LoadComplete()
base.LoadComplete();

beatmapAvailabilityTracker.SelectedItem.Value = playlistItem;
beatmapAvailabilityTracker.Availability.BindValueChanged(_ => trySetDailyChallengeBeatmap(), true);
beatmapAvailabilityTracker.Availability.BindValueChanged(_ => TrySetDailyChallengeBeatmap(this, beatmapManager, rulesets, musicController, playlistItem), true);

userModsSelectOverlayRegistration = overlayManager?.RegisterBlockingOverlay(userModsSelectOverlay);
userModsSelectOverlay.SelectedItem.Value = playlistItem;
Expand All @@ -402,15 +402,6 @@ protected override void LoadComplete()
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(() =>
{
if (state.NewValue != APIState.Online)
Expand Down Expand Up @@ -444,7 +435,7 @@ public override void OnEntering(ScreenTransitionEvent e)

waves.Show();
roomManager.JoinRoom(room);
applyLoopingToTrack();
startLoopingTrack(this, musicController);

metadataClient.BeginWatchingMultiplayerRoom(room.RoomID.Value!.Value).ContinueWith(t =>
{
Expand All @@ -466,15 +457,15 @@ public override void OnEntering(ScreenTransitionEvent e)
});
}, TaskContinuationOptions.OnlyOnRanToCompletion);

beatmapAvailabilityTracker.SelectedItem.Value = playlistItem;
beatmapAvailabilityTracker.Availability.BindValueChanged(_ => trySetDailyChallengeBeatmap(), true);
userModsSelectOverlay.SelectedItem.Value = playlistItem;

TrySetDailyChallengeBeatmap(this, beatmapManager, rulesets, musicController, playlistItem);
}

public override void OnResuming(ScreenTransitionEvent e)
{
base.OnResuming(e);
applyLoopingToTrack();
startLoopingTrack(this, musicController);
// re-apply mods as they may have been changed by a child screen
// (one known instance of this is showing a replay).
updateMods();
Expand Down Expand Up @@ -503,17 +494,30 @@ public override bool OnExiting(ScreenExitEvent e)
return base.OnExiting(e);
}

private void applyLoopingToTrack()
public static void TrySetDailyChallengeBeatmap(OsuScreen screen, BeatmapManager beatmaps, RulesetStore rulesets, MusicController music, PlaylistItem item)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight teeth pain at this method's public-static-dependency-accepting shape but I guess it's localised so probably fine. Likely better than weird inheritance anyhow

{
if (!this.IsCurrentScreen())
if (!screen.IsCurrentScreen())
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)
{
Beatmap.Value?.PrepareTrackForPreview(true);
musicController.EnsurePlayingSomething();
screen.Beatmap.Value?.PrepareTrackForPreview(true);
music.EnsurePlayingSomething();
}
}

Expand Down
46 changes: 44 additions & 2 deletions osu.Game/Screens/OnlinePlay/DailyChallenge/DailyChallengeIntro.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online;
using osu.Game.Online.Rooms;
using osu.Game.Overlays;
using osu.Game.Rulesets;
Expand All @@ -26,6 +28,10 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
{
public partial class DailyChallengeIntro : OsuScreen
{
public override bool DisallowExternalBeatmapRulesetChanges => true;

public override bool? ApplyModTrackAdjustments => true;

private readonly Room room;
private readonly PlaylistItem item;

Expand All @@ -48,6 +54,20 @@ public partial class DailyChallengeIntro : OsuScreen
[Cached]
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)
{
this.room = room;
Expand All @@ -59,7 +79,7 @@ public DailyChallengeIntro(Room room)
protected override BackgroundScreen CreateBackground() => new DailyChallengeIntroBackgroundScreen(colourProvider);

[BackgroundDependencyLoader]
private void load(BeatmapDifficultyCache difficultyCache)
private void load(BeatmapDifficultyCache difficultyCache, BeatmapModelDownloader beatmapDownloader, OsuConfigManager config)
{
const float horizontal_info_size = 500f;

Expand All @@ -69,6 +89,7 @@ private void load(BeatmapDifficultyCache difficultyCache)

InternalChildren = new Drawable[]
{
beatmapAvailabilityTracker,
introContent = new Container
{
Alpha = 0f,
Expand Down Expand Up @@ -296,11 +317,25 @@ private void load(BeatmapDifficultyCache difficultyCache)
beatmapBackgroundLoaded = true;
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)
{
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);
updateAnimationState();
}
Expand Down Expand Up @@ -365,7 +400,14 @@ private void beginAnimation()
beatmapContent.FadeInFromZero(280, Easing.InQuad);

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))
flash.FadeOutFromOne(5000, Easing.OutQuint);
Expand Down
Loading