2019-01-24 08:43:03 +00: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.
|
2018-12-11 08:32:01 +00:00
|
|
|
|
2018-12-19 01:52:15 +00:00
|
|
|
using System;
|
2018-12-14 06:04:04 +00:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
using osu.Framework.Bindables;
|
2018-12-14 06:04:04 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2020-02-20 09:39:10 +00:00
|
|
|
using osu.Game.Graphics;
|
2020-02-14 11:14:25 +00:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-12-19 01:52:15 +00:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2018-12-11 08:32:01 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Multi.Match.Components
|
|
|
|
{
|
2020-02-20 09:39:10 +00:00
|
|
|
public class ReadyButton : TriangleButton
|
2018-12-11 08:32:01 +00:00
|
|
|
{
|
2020-02-14 11:18:53 +00:00
|
|
|
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
2018-12-14 06:04:04 +00:00
|
|
|
|
2019-02-05 10:00:01 +00:00
|
|
|
[Resolved(typeof(Room), nameof(Room.EndDate))]
|
|
|
|
private Bindable<DateTimeOffset> endDate { get; set; }
|
2018-12-19 01:52:15 +00:00
|
|
|
|
|
|
|
[Resolved]
|
2019-02-01 06:42:15 +00:00
|
|
|
private IBindable<WorkingBeatmap> gameBeatmap { get; set; }
|
2018-12-19 01:52:15 +00:00
|
|
|
|
2018-12-14 06:04:04 +00:00
|
|
|
[Resolved]
|
|
|
|
private BeatmapManager beatmaps { get; set; }
|
|
|
|
|
2018-12-19 01:52:15 +00:00
|
|
|
private bool hasBeatmap;
|
|
|
|
|
2019-02-05 10:00:01 +00:00
|
|
|
public ReadyButton()
|
2018-12-11 08:32:01 +00:00
|
|
|
{
|
|
|
|
Text = "Start";
|
|
|
|
}
|
2018-12-14 06:04:04 +00:00
|
|
|
|
2020-05-19 07:44:22 +00:00
|
|
|
private IBindable<WeakReference<BeatmapSetInfo>> managerAdded;
|
|
|
|
private IBindable<WeakReference<BeatmapSetInfo>> managerRemoved;
|
|
|
|
|
2018-12-14 06:04:04 +00:00
|
|
|
[BackgroundDependencyLoader]
|
2020-02-20 09:39:10 +00:00
|
|
|
private void load(OsuColour colours)
|
2018-12-14 06:04:04 +00:00
|
|
|
{
|
2020-05-19 07:44:22 +00:00
|
|
|
managerAdded = beatmaps.ItemAdded.GetBoundCopy();
|
|
|
|
managerAdded.BindValueChanged(beatmapAdded);
|
|
|
|
managerRemoved = beatmaps.ItemRemoved.GetBoundCopy();
|
|
|
|
managerRemoved.BindValueChanged(beatmapRemoved);
|
2018-12-14 06:04:04 +00:00
|
|
|
|
2020-02-14 11:18:53 +00:00
|
|
|
SelectedItem.BindValueChanged(item => updateSelectedItem(item.NewValue), true);
|
2020-02-20 09:39:10 +00:00
|
|
|
|
|
|
|
BackgroundColour = colours.Green;
|
|
|
|
Triangles.ColourDark = colours.Green;
|
|
|
|
Triangles.ColourLight = colours.GreenLight;
|
2018-12-14 06:04:04 +00:00
|
|
|
}
|
|
|
|
|
2020-02-14 11:18:53 +00:00
|
|
|
private void updateSelectedItem(PlaylistItem item)
|
2018-12-14 06:04:04 +00:00
|
|
|
{
|
2018-12-19 01:52:15 +00:00
|
|
|
hasBeatmap = false;
|
|
|
|
|
2020-02-14 11:18:53 +00:00
|
|
|
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID;
|
|
|
|
if (beatmapId == null)
|
2018-12-14 06:04:04 +00:00
|
|
|
return;
|
|
|
|
|
2020-02-14 11:18:53 +00:00
|
|
|
hasBeatmap = beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmapId) != null;
|
2018-12-14 06:04:04 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 07:44:22 +00:00
|
|
|
private void beatmapAdded(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet)
|
2018-12-14 06:04:04 +00:00
|
|
|
{
|
2020-05-19 07:44:22 +00:00
|
|
|
if (weakSet.NewValue.TryGetTarget(out var set))
|
|
|
|
{
|
|
|
|
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID;
|
|
|
|
if (beatmapId == null)
|
|
|
|
return;
|
2020-02-14 11:18:53 +00:00
|
|
|
|
2020-05-19 07:44:22 +00:00
|
|
|
if (set.Beatmaps.Any(b => b.OnlineBeatmapID == beatmapId))
|
|
|
|
Schedule(() => hasBeatmap = true);
|
|
|
|
}
|
2018-12-19 01:52:15 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 07:44:22 +00:00
|
|
|
private void beatmapRemoved(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet)
|
2019-02-22 11:26:06 +00:00
|
|
|
{
|
2020-05-19 07:44:22 +00:00
|
|
|
if (weakSet.NewValue.TryGetTarget(out var set))
|
|
|
|
{
|
|
|
|
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID;
|
|
|
|
if (beatmapId == null)
|
|
|
|
return;
|
2019-02-22 11:26:06 +00:00
|
|
|
|
2020-05-19 07:44:22 +00:00
|
|
|
if (set.Beatmaps.Any(b => b.OnlineBeatmapID == beatmapId))
|
|
|
|
Schedule(() => hasBeatmap = false);
|
|
|
|
}
|
2019-02-22 11:26:06 +00:00
|
|
|
}
|
|
|
|
|
2018-12-19 01:52:15 +00:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
updateEnabledState();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateEnabledState()
|
|
|
|
{
|
2020-02-14 11:18:53 +00:00
|
|
|
if (gameBeatmap.Value == null || SelectedItem.Value == null)
|
2018-12-19 01:52:15 +00:00
|
|
|
{
|
|
|
|
Enabled.Value = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
bool hasEnoughTime = DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(gameBeatmap.Value.Track.Length) < endDate.Value;
|
2018-12-19 01:52:15 +00:00
|
|
|
|
|
|
|
Enabled.Value = hasBeatmap && hasEnoughTime;
|
2018-12-14 06:04:04 +00:00
|
|
|
}
|
2018-12-11 08:32:01 +00:00
|
|
|
}
|
|
|
|
}
|