2020-12-19 01:55:48 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System;
|
2024-11-13 21:39:01 +08:00
|
|
|
using System.ComponentModel;
|
2021-10-26 15:55:24 +08:00
|
|
|
using System.Linq;
|
2020-12-19 01:55:48 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2021-10-26 15:55:24 +08:00
|
|
|
using osu.Framework.Localisation;
|
2021-01-17 04:02:30 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2020-12-19 01:55:48 +08:00
|
|
|
using osu.Game.Graphics;
|
2020-12-25 12:38:11 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-12-25 23:50:00 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Components;
|
2020-12-19 01:55:48 +08:00
|
|
|
|
2020-12-25 23:50:00 +08:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Playlists
|
2020-12-19 01:55:48 +08:00
|
|
|
{
|
2020-12-25 12:11:21 +08:00
|
|
|
public partial class PlaylistsReadyButton : ReadyButton
|
2020-12-19 01:55:48 +08:00
|
|
|
{
|
2021-01-17 04:02:30 +08:00
|
|
|
[Resolved]
|
2024-11-13 19:20:14 +08:00
|
|
|
private IBindable<WorkingBeatmap> gameBeatmap { get; set; } = null!;
|
|
|
|
|
|
|
|
private readonly Room room;
|
2021-01-17 04:02:30 +08:00
|
|
|
|
2024-11-13 19:20:14 +08:00
|
|
|
public PlaylistsReadyButton(Room room)
|
2020-12-19 01:55:48 +08:00
|
|
|
{
|
2024-11-13 19:20:14 +08:00
|
|
|
this.room = room;
|
2020-12-19 01:55:48 +08:00
|
|
|
Text = "Start";
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
BackgroundColour = colours.Green;
|
|
|
|
}
|
|
|
|
|
2021-10-26 15:54:55 +08:00
|
|
|
private bool hasRemainingAttempts = true;
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2024-11-13 21:39:01 +08:00
|
|
|
room.PropertyChanged += onRoomPropertyChanged;
|
|
|
|
updateRoomUserScore();
|
|
|
|
}
|
2021-10-26 15:54:55 +08:00
|
|
|
|
2024-11-13 21:39:01 +08:00
|
|
|
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.PropertyName == nameof(Room.UserScore))
|
|
|
|
updateRoomUserScore();
|
|
|
|
}
|
2021-10-26 15:54:55 +08:00
|
|
|
|
2024-11-13 21:39:01 +08:00
|
|
|
private void updateRoomUserScore()
|
|
|
|
{
|
|
|
|
if (room.MaxAttempts == null || room.UserScore == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int remaining = room.MaxAttempts.Value - room.UserScore.PlaylistItemAttempts.Sum(a => a.Attempts);
|
|
|
|
|
|
|
|
hasRemainingAttempts = remaining > 0;
|
2021-10-26 15:54:55 +08:00
|
|
|
}
|
|
|
|
|
2020-12-19 01:55:48 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2021-10-26 15:54:55 +08:00
|
|
|
Enabled.Value = hasRemainingAttempts && enoughTimeLeft;
|
2020-12-19 01:55:48 +08:00
|
|
|
}
|
2021-10-26 15:54:55 +08:00
|
|
|
|
2021-10-26 15:55:24 +08:00
|
|
|
public override LocalisableString TooltipText
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (!enoughTimeLeft)
|
|
|
|
return "No time left!";
|
|
|
|
|
|
|
|
if (!hasRemainingAttempts)
|
|
|
|
return "Attempts exhausted!";
|
|
|
|
|
|
|
|
return base.TooltipText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-26 15:54:55 +08:00
|
|
|
private bool enoughTimeLeft =>
|
|
|
|
// This should probably consider the length of the currently selected item, rather than a constant 30 seconds.
|
2024-11-13 19:20:14 +08:00
|
|
|
room.EndDate != null && DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(gameBeatmap.Value.Track.Length) < room.EndDate;
|
2024-11-13 21:39:01 +08:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
room.PropertyChanged -= onRoomPropertyChanged;
|
|
|
|
}
|
2020-12-19 01:55:48 +08:00
|
|
|
}
|
|
|
|
}
|