From 83bf37a302395fa3cee5112afe3b628f88fd0f9c Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 14 Dec 2018 15:04:04 +0900 Subject: [PATCH] Enable/disable the view beatmap + ready buttons based on beatmap presence --- .../Screens/Multi/Match/Components/Info.cs | 9 +++- .../Multi/Match/Components/ReadyButton.cs | 41 +++++++++++++++++++ .../Match/Components/ViewBeatmapButton.cs | 27 ++++++++++++ osu.Game/Screens/Multi/Match/MatchScreen.cs | 1 + 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Multi/Match/Components/Info.cs b/osu.Game/Screens/Multi/Match/Components/Info.cs index 4912c95327..1750323486 100644 --- a/osu.Game/Screens/Multi/Match/Components/Info.cs +++ b/osu.Game/Screens/Multi/Match/Components/Info.cs @@ -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); diff --git a/osu.Game/Screens/Multi/Match/Components/ReadyButton.cs b/osu.Game/Screens/Multi/Match/Components/ReadyButton.cs index ec07b5ec09..c52a3be7cb 100644 --- a/osu.Game/Screens/Multi/Match/Components/ReadyButton.cs +++ b/osu.Game/Screens/Multi/Match/Components/ReadyButton.cs @@ -1,13 +1,22 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // 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 Beatmap = new Bindable(); + + [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; + } } } diff --git a/osu.Game/Screens/Multi/Match/Components/ViewBeatmapButton.cs b/osu.Game/Screens/Multi/Match/Components/ViewBeatmapButton.cs index e9cff656c2..82d0761fbf 100644 --- a/osu.Game/Screens/Multi/Match/Components/ViewBeatmapButton.cs +++ b/osu.Game/Screens/Multi/Match/Components/ViewBeatmapButton.cs @@ -1,13 +1,21 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // 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 Beatmap = new Bindable(); + + [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; + } } } diff --git a/osu.Game/Screens/Multi/Match/MatchScreen.cs b/osu.Game/Screens/Multi/Match/MatchScreen.cs index 82b234e9c8..dba9c8c14e 100644 --- a/osu.Game/Screens/Multi/Match/MatchScreen.cs +++ b/osu.Game/Screens/Multi/Match/MatchScreen.cs @@ -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); }