2019-01-24 16:43:03 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-12-11 16:32:01 +08:00
|
|
|
|
2018-12-19 09:52:15 +08:00
|
|
|
using System;
|
2018-12-14 14:04:04 +08:00
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-12-14 14:04:04 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2020-02-20 17:39:10 +08:00
|
|
|
using osu.Game.Graphics;
|
2020-02-14 19:14:25 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-12-25 12:38:11 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2018-12-11 16:32:01 +08:00
|
|
|
|
2020-12-25 23:50:00 +08:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Components
|
2018-12-11 16:32:01 +08:00
|
|
|
{
|
2020-12-19 01:55:48 +08:00
|
|
|
public abstract class ReadyButton : TriangleButton
|
2018-12-11 16:32:01 +08:00
|
|
|
{
|
2020-02-14 19:18:53 +08:00
|
|
|
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
2018-12-14 14:04:04 +08:00
|
|
|
|
2020-12-19 01:55:48 +08:00
|
|
|
public new readonly BindableBool Enabled = new BindableBool();
|
2018-12-19 09:52:15 +08:00
|
|
|
|
|
|
|
[Resolved]
|
2020-12-19 01:55:48 +08:00
|
|
|
protected IBindable<WorkingBeatmap> GameBeatmap { get; private set; }
|
2018-12-19 09:52:15 +08:00
|
|
|
|
2018-12-14 14:04:04 +08:00
|
|
|
[Resolved]
|
|
|
|
private BeatmapManager beatmaps { get; set; }
|
|
|
|
|
2018-12-19 09:52:15 +08:00
|
|
|
private bool hasBeatmap;
|
|
|
|
|
2020-05-27 15:08:47 +08:00
|
|
|
private IBindable<WeakReference<BeatmapSetInfo>> managerUpdated;
|
2020-05-19 15:44:22 +08:00
|
|
|
private IBindable<WeakReference<BeatmapSetInfo>> managerRemoved;
|
|
|
|
|
2018-12-14 14:04:04 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2020-02-20 17:39:10 +08:00
|
|
|
private void load(OsuColour colours)
|
2018-12-14 14:04:04 +08:00
|
|
|
{
|
2020-05-27 15:08:47 +08:00
|
|
|
managerUpdated = beatmaps.ItemUpdated.GetBoundCopy();
|
|
|
|
managerUpdated.BindValueChanged(beatmapUpdated);
|
2020-05-19 15:44:22 +08:00
|
|
|
managerRemoved = beatmaps.ItemRemoved.GetBoundCopy();
|
|
|
|
managerRemoved.BindValueChanged(beatmapRemoved);
|
2018-12-14 14:04:04 +08:00
|
|
|
|
2020-02-14 19:18:53 +08:00
|
|
|
SelectedItem.BindValueChanged(item => updateSelectedItem(item.NewValue), true);
|
2018-12-14 14:04:04 +08:00
|
|
|
}
|
|
|
|
|
2021-01-04 15:27:08 +08:00
|
|
|
private void updateSelectedItem(PlaylistItem _) => Scheduler.AddOnce(updateBeatmapState);
|
|
|
|
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> _) => Scheduler.AddOnce(updateBeatmapState);
|
|
|
|
private void beatmapRemoved(ValueChangedEvent<WeakReference<BeatmapSetInfo>> _) => Scheduler.AddOnce(updateBeatmapState);
|
2018-12-19 09:52:15 +08:00
|
|
|
|
2021-01-04 13:51:37 +08:00
|
|
|
private void updateBeatmapState()
|
2020-06-02 13:03:50 +08:00
|
|
|
{
|
|
|
|
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID;
|
|
|
|
string checksum = SelectedItem.Value?.Beatmap.Value?.MD5Hash;
|
|
|
|
|
|
|
|
if (beatmapId == null || checksum == null)
|
2021-01-04 13:51:37 +08:00
|
|
|
return;
|
2020-06-02 13:03:50 +08:00
|
|
|
|
2021-01-04 13:51:37 +08:00
|
|
|
var databasedBeatmap = beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmapId && b.MD5Hash == checksum);
|
2021-01-04 15:28:41 +08:00
|
|
|
|
2021-01-05 13:54:59 +08:00
|
|
|
hasBeatmap = databasedBeatmap?.BeatmapSet?.DeletePending == false;
|
2020-06-02 13:03:50 +08:00
|
|
|
}
|
|
|
|
|
2018-12-19 09:52:15 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
updateEnabledState();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateEnabledState()
|
|
|
|
{
|
2020-12-19 01:55:48 +08:00
|
|
|
if (GameBeatmap.Value == null || SelectedItem.Value == null)
|
2018-12-19 09:52:15 +08:00
|
|
|
{
|
2020-12-19 01:55:48 +08:00
|
|
|
base.Enabled.Value = false;
|
2018-12-19 09:52:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-19 01:55:48 +08:00
|
|
|
base.Enabled.Value = hasBeatmap && Enabled.Value;
|
2018-12-14 14:04:04 +08:00
|
|
|
}
|
2018-12-11 16:32:01 +08:00
|
|
|
}
|
|
|
|
}
|