1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 07:32:55 +08:00

Refactor ready button to support selected playlist item

This commit is contained in:
smoogipoo 2020-02-14 20:18:53 +09:00
parent c0dba63278
commit 80fd9485a9

View File

@ -15,7 +15,7 @@ namespace osu.Game.Screens.Multi.Match.Components
{
public class ReadyButton : OsuButton
{
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
[Resolved(typeof(Room), nameof(Room.EndDate))]
private Bindable<DateTimeOffset> endDate { get; set; }
@ -42,31 +42,37 @@ namespace osu.Game.Screens.Multi.Match.Components
beatmaps.ItemAdded += beatmapAdded;
beatmaps.ItemRemoved += beatmapRemoved;
Beatmap.BindValueChanged(b => updateBeatmap(b.NewValue), true);
SelectedItem.BindValueChanged(item => updateSelectedItem(item.NewValue), true);
}
private void updateBeatmap(BeatmapInfo beatmap)
private void updateSelectedItem(PlaylistItem item)
{
hasBeatmap = false;
if (beatmap?.OnlineBeatmapID == null)
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID;
if (beatmapId == null)
return;
hasBeatmap = beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmap.OnlineBeatmapID) != null;
hasBeatmap = beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmapId) != null;
}
private void beatmapAdded(BeatmapSetInfo model)
{
if (model.Beatmaps.Any(b => b.OnlineBeatmapID == Beatmap.Value.OnlineBeatmapID))
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID;
if (beatmapId == null)
return;
if (model.Beatmaps.Any(b => b.OnlineBeatmapID == beatmapId))
Schedule(() => hasBeatmap = true);
}
private void beatmapRemoved(BeatmapSetInfo model)
{
if (Beatmap.Value == null)
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID;
if (beatmapId == null)
return;
if (model.OnlineBeatmapSetID == Beatmap.Value.BeatmapSet.OnlineBeatmapSetID)
if (model.Beatmaps.Any(b => b.OnlineBeatmapID == beatmapId))
Schedule(() => hasBeatmap = false);
}
@ -79,7 +85,7 @@ namespace osu.Game.Screens.Multi.Match.Components
private void updateEnabledState()
{
if (gameBeatmap.Value == null)
if (gameBeatmap.Value == null || SelectedItem.Value == null)
{
Enabled.Value = false;
return;
@ -95,7 +101,10 @@ namespace osu.Game.Screens.Multi.Match.Components
base.Dispose(isDisposing);
if (beatmaps != null)
{
beatmaps.ItemAdded -= beatmapAdded;
beatmaps.ItemRemoved -= beatmapRemoved;
}
}
}
}