1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 21:07:33 +08:00

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

@ -41,6 +41,8 @@ namespace osu.Game.Screens.Multi.Match.Components
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
ReadyButton readyButton;
ViewBeatmapButton viewBeatmapButton;
BeatmapTypeInfo beatmapTypeInfo;
OsuSpriteText name;
ModDisplay modDisplay;
@ -103,8 +105,8 @@ namespace osu.Game.Screens.Multi.Match.Components
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
new ViewBeatmapButton(),
new ReadyButton
viewBeatmapButton = new ViewBeatmapButton(),
readyButton = new ReadyButton
{
Action = () => OnStart?.Invoke()
}
@ -118,6 +120,9 @@ namespace osu.Game.Screens.Multi.Match.Components
beatmapTypeInfo.Type.BindTo(Type);
modDisplay.Current.BindTo(Mods);
viewBeatmapButton.Beatmap.BindTo(Beatmap);
readyButton.Beatmap.BindTo(Beatmap);
Availability.BindValueChanged(_ => updateAvailabilityStatus());
Status.BindValueChanged(_ => updateAvailabilityStatus());
Name.BindValueChanged(n => name.Text = n);

View File

@ -1,13 +1,22 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
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 ReadyButton : HeaderButton
{
public readonly IBindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
[Resolved]
private BeatmapManager beatmaps { get; set; }
public ReadyButton()
{
RelativeSizeAxes = Axes.Y;
@ -15,5 +24,37 @@ namespace osu.Game.Screens.Multi.Match.Components
Text = "Start";
}
[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);
beatmaps.ItemAdded -= beatmapAdded;
}
}
}

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;
}
}
}

View File

@ -140,6 +140,7 @@ namespace osu.Game.Screens.Multi.Match
info.Beatmap.Value = item.Beatmap;
info.Mods.Value = item.RequiredMods;
// Todo: item.Beatmap can be null here...
Beatmap.Value = beatmapManager.GetWorkingBeatmap(item.Beatmap);
}