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-11 08:32:01 +00:00
|
|
|
using osu.Framework.Graphics;
|
2018-12-14 06:04:04 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2018-12-19 01:52:15 +00:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2018-12-14 05:20:03 +00:00
|
|
|
using osuTK;
|
2018-12-11 08:32:01 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Multi.Match.Components
|
|
|
|
{
|
2018-12-14 05:20:03 +00:00
|
|
|
public class ReadyButton : HeaderButton
|
2018-12-11 08:32:01 +00:00
|
|
|
{
|
2019-02-11 10:11:34 +00:00
|
|
|
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
|
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
|
|
|
{
|
2018-12-14 05:20:03 +00:00
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
Size = new Vector2(200, 1);
|
2018-12-11 08:32:01 +00:00
|
|
|
|
|
|
|
Text = "Start";
|
|
|
|
}
|
2018-12-14 06:04:04 +00:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
beatmaps.ItemAdded += beatmapAdded;
|
2019-02-22 11:26:06 +00:00
|
|
|
beatmaps.ItemRemoved += beatmapRemoved;
|
2018-12-14 06:04:04 +00:00
|
|
|
|
2019-02-22 11:13:38 +00:00
|
|
|
Beatmap.BindValueChanged(b => updateBeatmap(b.NewValue), true);
|
2018-12-14 06:04:04 +00:00
|
|
|
}
|
|
|
|
|
2018-12-19 01:52:15 +00:00
|
|
|
private void updateBeatmap(BeatmapInfo beatmap)
|
2018-12-14 06:04:04 +00:00
|
|
|
{
|
2018-12-19 01:52:15 +00:00
|
|
|
hasBeatmap = false;
|
|
|
|
|
2018-12-14 06:04:04 +00:00
|
|
|
if (beatmap?.OnlineBeatmapID == null)
|
|
|
|
return;
|
|
|
|
|
2018-12-19 01:52:15 +00:00
|
|
|
hasBeatmap = beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmap.OnlineBeatmapID) != null;
|
2018-12-14 06:04:04 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 09:24:06 +00:00
|
|
|
private void beatmapAdded(BeatmapSetInfo model, bool existing)
|
2018-12-14 06:04:04 +00:00
|
|
|
{
|
2019-02-08 08:53:01 +00:00
|
|
|
if (Beatmap.Value == null)
|
|
|
|
return;
|
|
|
|
|
2018-12-14 06:04:04 +00:00
|
|
|
if (model.Beatmaps.Any(b => b.OnlineBeatmapID == Beatmap.Value.OnlineBeatmapID))
|
2018-12-19 01:52:15 +00:00
|
|
|
Schedule(() => hasBeatmap = true);
|
|
|
|
}
|
|
|
|
|
2019-02-22 11:26:06 +00:00
|
|
|
private void beatmapRemoved(BeatmapSetInfo model)
|
|
|
|
{
|
|
|
|
if (Beatmap.Value == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (model.OnlineBeatmapSetID == Beatmap.Value.BeatmapSet.OnlineBeatmapSetID)
|
|
|
|
Schedule(() => hasBeatmap = false);
|
|
|
|
}
|
|
|
|
|
2018-12-19 01:52:15 +00:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
updateEnabledState();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateEnabledState()
|
|
|
|
{
|
|
|
|
if (gameBeatmap.Value == null)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
2018-12-18 09:09:54 +00:00
|
|
|
if (beatmaps != null)
|
|
|
|
beatmaps.ItemAdded -= beatmapAdded;
|
2018-12-14 06:04:04 +00:00
|
|
|
}
|
2018-12-11 08:32:01 +00:00
|
|
|
}
|
|
|
|
}
|