mirror of
https://github.com/ppy/osu.git
synced 2025-01-06 07:42:55 +08:00
Enable/disable the view beatmap + ready buttons based on beatmap presence
This commit is contained in:
parent
28192aef90
commit
83bf37a302
@ -41,6 +41,8 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
AutoSizeAxes = Axes.Y;
|
AutoSizeAxes = Axes.Y;
|
||||||
|
|
||||||
|
ReadyButton readyButton;
|
||||||
|
ViewBeatmapButton viewBeatmapButton;
|
||||||
BeatmapTypeInfo beatmapTypeInfo;
|
BeatmapTypeInfo beatmapTypeInfo;
|
||||||
OsuSpriteText name;
|
OsuSpriteText name;
|
||||||
ModDisplay modDisplay;
|
ModDisplay modDisplay;
|
||||||
@ -103,8 +105,8 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
Direction = FillDirection.Horizontal,
|
Direction = FillDirection.Horizontal,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new ViewBeatmapButton(),
|
viewBeatmapButton = new ViewBeatmapButton(),
|
||||||
new ReadyButton
|
readyButton = new ReadyButton
|
||||||
{
|
{
|
||||||
Action = () => OnStart?.Invoke()
|
Action = () => OnStart?.Invoke()
|
||||||
}
|
}
|
||||||
@ -118,6 +120,9 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
beatmapTypeInfo.Type.BindTo(Type);
|
beatmapTypeInfo.Type.BindTo(Type);
|
||||||
modDisplay.Current.BindTo(Mods);
|
modDisplay.Current.BindTo(Mods);
|
||||||
|
|
||||||
|
viewBeatmapButton.Beatmap.BindTo(Beatmap);
|
||||||
|
readyButton.Beatmap.BindTo(Beatmap);
|
||||||
|
|
||||||
Availability.BindValueChanged(_ => updateAvailabilityStatus());
|
Availability.BindValueChanged(_ => updateAvailabilityStatus());
|
||||||
Status.BindValueChanged(_ => updateAvailabilityStatus());
|
Status.BindValueChanged(_ => updateAvailabilityStatus());
|
||||||
Name.BindValueChanged(n => name.Text = n);
|
Name.BindValueChanged(n => name.Text = n);
|
||||||
|
@ -1,13 +1,22 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// 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.Framework.Graphics;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Multi.Match.Components
|
namespace osu.Game.Screens.Multi.Match.Components
|
||||||
{
|
{
|
||||||
public class ReadyButton : HeaderButton
|
public class ReadyButton : HeaderButton
|
||||||
{
|
{
|
||||||
|
public readonly IBindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private BeatmapManager beatmaps { get; set; }
|
||||||
|
|
||||||
public ReadyButton()
|
public ReadyButton()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Y;
|
RelativeSizeAxes = Axes.Y;
|
||||||
@ -15,5 +24,37 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
|
|
||||||
Text = "Start";
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,21 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// 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.Framework.Graphics;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Multi.Match.Components
|
namespace osu.Game.Screens.Multi.Match.Components
|
||||||
{
|
{
|
||||||
public class ViewBeatmapButton : HeaderButton
|
public class ViewBeatmapButton : HeaderButton
|
||||||
{
|
{
|
||||||
|
public readonly IBindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
|
||||||
|
|
||||||
|
[Resolved(CanBeNull = true)]
|
||||||
|
private OsuGame osuGame { get; set; }
|
||||||
|
|
||||||
public ViewBeatmapButton()
|
public ViewBeatmapButton()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Y;
|
RelativeSizeAxes = Axes.Y;
|
||||||
@ -15,5 +23,24 @@ namespace osu.Game.Screens.Multi.Match.Components
|
|||||||
|
|
||||||
Text = "View beatmap";
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,6 +140,7 @@ namespace osu.Game.Screens.Multi.Match
|
|||||||
info.Beatmap.Value = item.Beatmap;
|
info.Beatmap.Value = item.Beatmap;
|
||||||
info.Mods.Value = item.RequiredMods;
|
info.Mods.Value = item.RequiredMods;
|
||||||
|
|
||||||
|
// Todo: item.Beatmap can be null here...
|
||||||
Beatmap.Value = beatmapManager.GetWorkingBeatmap(item.Beatmap);
|
Beatmap.Value = beatmapManager.GetWorkingBeatmap(item.Beatmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user