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

Exit daily challenge screen when going offline #29037

Merged
merged 1 commit into from
Jul 24, 2024
Merged
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
28 changes: 28 additions & 0 deletions osu.Game/Screens/OnlinePlay/DailyChallenge/DailyChallenge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Metadata;
using osu.Game.Online.Multiplayer;
Expand Down Expand Up @@ -48,6 +49,8 @@ public partial class DailyChallenge : OsuScreen
/// </summary>
private readonly Bindable<IReadOnlyList<Mod>> userMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());

private readonly IBindable<APIState> apiState = new Bindable<APIState>();

private OnlinePlayScreenWaveContainer waves = null!;
private DailyChallengeLeaderboard leaderboard = null!;
private RoomModSelectOverlay userModsSelectOverlay = null!;
Expand Down Expand Up @@ -84,6 +87,9 @@ public partial class DailyChallenge : OsuScreen
[Resolved]
private UserLookupCache userLookupCache { get; set; } = null!;

[Resolved]
protected IAPIProvider API { get; private set; } = null!;

public override bool DisallowExternalBeatmapRulesetChanges => true;

public DailyChallenge(Room room)
Expand Down Expand Up @@ -358,6 +364,9 @@ protected override void LoadComplete()
userModsSelectOverlayRegistration = overlayManager?.RegisterBlockingOverlay(userModsSelectOverlay);
userModsSelectOverlay.SelectedItem.Value = playlistItem;
userMods.BindValueChanged(_ => Scheduler.AddOnce(updateMods), true);

apiState.BindTo(API.State);
apiState.BindValueChanged(onlineStateChanged, true);
}

private void trySetDailyChallengeBeatmap()
Expand All @@ -368,6 +377,25 @@ private void trySetDailyChallengeBeatmap()
applyLoopingToTrack();
}

private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{
if (state.NewValue != APIState.Online)
Schedule(forcefullyExit);
});

private void forcefullyExit()
{
Logger.Log($"{this} forcefully exiting due to loss of API connection");

// This is temporary since we don't currently have a way to force screens to be exited
// See also: `OnlinePlayScreen.forcefullyExit()`
if (this.IsCurrentScreen())
{
while (this.IsCurrentScreen())
this.Exit();
}
}

public override void OnEntering(ScreenTransitionEvent e)
{
base.OnEntering(e);
Expand Down
1 change: 1 addition & 0 deletions osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private void forcefullyExit()
Logger.Log($"{this} forcefully exiting due to loss of API connection");

// This is temporary since we don't currently have a way to force screens to be exited
// See also: `DailyChallenge.forcefullyExit()`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Readers will note that this copy of this logic contains an else branch that claims that it is "[handling] the case where a child screen is current (ie. gameplay)."

Dear reader, it does not, because the invocation of this method is copiously scheduled:

private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{
if (state.NewValue != APIState.Online)
Schedule(forcefullyExit);
});

which means it will not get called if the screen is not current. So this just doesn't work. This particular oopsie blames back to 5b405ab which means I am not touching it with a ten foot pole here. (Unless you'd like me to remove it?)

if (this.IsCurrentScreen())
{
while (this.IsCurrentScreen())
Expand Down
Loading