Enable/disable the view beatmap + ready buttons based on beatmap presence

This commit is contained in:
smoogipoo
2018-12-14 15:04:04 +09:00
parent 28192aef90
commit 83bf37a302
4 changed files with 76 additions and 2 deletions

View File

@ -1,13 +1,21 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osuTK;
namespace osu.Game.Screens.Multi.Match.Components
{
public class ViewBeatmapButton : HeaderButton
{
public readonly IBindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
[Resolved(CanBeNull = true)]
private OsuGame osuGame { get; set; }
public ViewBeatmapButton()
{
RelativeSizeAxes = Axes.Y;
@ -15,5 +23,24 @@ namespace osu.Game.Screens.Multi.Match.Components
Text = "View beatmap";
}
[BackgroundDependencyLoader]
private void load()
{
if (osuGame != null)
Beatmap.BindValueChanged(updateAction, true);
}
private void updateAction(BeatmapInfo beatmap)
{
if (beatmap == null)
{
Enabled.Value = false;
return;
}
Action = () => osuGame.ShowBeatmap(beatmap.OnlineBeatmapID ?? 0);
Enabled.Value = true;
}
}
}