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

Account for rate changing mods when disabling the "Ready" button #30929

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Changes from 2 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
25 changes: 20 additions & 5 deletions osu.Game/Screens/OnlinePlay/Playlists/PlaylistsReadyButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using osu.Framework.Allocation;
Expand All @@ -10,7 +11,9 @@
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Online.Rooms;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Utils;

namespace osu.Game.Screens.OnlinePlay.Playlists
{
Expand All @@ -19,6 +22,9 @@ public partial class PlaylistsReadyButton : ReadyButton
[Resolved]
private IBindable<WorkingBeatmap> gameBeatmap { get; set; } = null!;

[Resolved]
private IBindable<IReadOnlyList<Mod>> mods { get; set; } = null!;

private readonly Room room;

public PlaylistsReadyButton(Room room)
Expand Down Expand Up @@ -63,14 +69,14 @@ protected override void Update()
{
base.Update();

Enabled.Value = hasRemainingAttempts && enoughTimeLeft;
Enabled.Value = hasRemainingAttempts && enoughTimeLeft();
}

public override LocalisableString TooltipText
{
get
{
if (!enoughTimeLeft)
if (!enoughTimeLeft())
return "No time left!";

if (!hasRemainingAttempts)
Expand All @@ -80,9 +86,18 @@ public override LocalisableString TooltipText
}
}

private bool enoughTimeLeft =>
// This should probably consider the length of the currently selected item, rather than a constant 30 seconds.
room.EndDate != null && DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(gameBeatmap.Value.Track.Length) < room.EndDate;
private bool enoughTimeLeft()
{
// TODO: This doesn't consider mods which apply variable rates, yet.
double rate = ModUtils.CalculateRateWithMods(mods.Value);

// We want to avoid users not being able to submit scores if they chose to not skip,
// so track length is chosen over playable length.
double trackLength = Math.Round(gameBeatmap.Value.Track.Length / rate);

// Additional 30 second delay added to account for load and/or submit time.
return room.EndDate != null && DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(trackLength) < room.EndDate;
timschumi marked this conversation as resolved.
Show resolved Hide resolved
}

protected override void Dispose(bool isDisposing)
{
Expand Down