2018-12-11 16:32:01 +08:00
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
2018-12-14 14:04:04 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Configuration;
|
2018-12-11 16:32:01 +08:00
|
|
|
using osu.Framework.Graphics;
|
2018-12-14 14:04:04 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2018-12-14 13:20:03 +08:00
|
|
|
using osuTK;
|
2018-12-11 16:32:01 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Multi.Match.Components
|
|
|
|
{
|
2018-12-14 13:20:03 +08:00
|
|
|
public class ReadyButton : HeaderButton
|
2018-12-11 16:32:01 +08:00
|
|
|
{
|
2018-12-14 14:04:04 +08:00
|
|
|
public readonly IBindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private BeatmapManager beatmaps { get; set; }
|
|
|
|
|
2018-12-14 13:20:03 +08:00
|
|
|
public ReadyButton()
|
2018-12-11 16:32:01 +08:00
|
|
|
{
|
2018-12-14 13:20:03 +08:00
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
Size = new Vector2(200, 1);
|
2018-12-11 16:32:01 +08:00
|
|
|
|
|
|
|
Text = "Start";
|
|
|
|
}
|
2018-12-14 14:04:04 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
beatmaps.ItemAdded += beatmapAdded;
|
|
|
|
|
|
|
|
Beatmap.BindValueChanged(updateEnabledState, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateEnabledState(BeatmapInfo beatmap)
|
|
|
|
{
|
|
|
|
if (beatmap?.OnlineBeatmapID == null)
|
|
|
|
{
|
|
|
|
Enabled.Value = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Enabled.Value = beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmap.OnlineBeatmapID) != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void beatmapAdded(BeatmapSetInfo model, bool existing, bool silent)
|
|
|
|
{
|
|
|
|
if (model.Beatmaps.Any(b => b.OnlineBeatmapID == Beatmap.Value.OnlineBeatmapID))
|
|
|
|
Schedule(() => Enabled.Value = true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
2018-12-18 17:09:54 +08:00
|
|
|
if (beatmaps != null)
|
|
|
|
beatmaps.ItemAdded -= beatmapAdded;
|
2018-12-14 14:04:04 +08:00
|
|
|
}
|
2018-12-11 16:32:01 +08:00
|
|
|
}
|
|
|
|
}
|