From 80fd9485a9681b5c092860be6625c7495b111f22 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 14 Feb 2020 20:18:53 +0900 Subject: [PATCH] Refactor ready button to support selected playlist item --- .../Multi/Match/Components/ReadyButton.cs | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/osu.Game/Screens/Multi/Match/Components/ReadyButton.cs b/osu.Game/Screens/Multi/Match/Components/ReadyButton.cs index cec5b2f855..a62572a851 100644 --- a/osu.Game/Screens/Multi/Match/Components/ReadyButton.cs +++ b/osu.Game/Screens/Multi/Match/Components/ReadyButton.cs @@ -15,7 +15,7 @@ namespace osu.Game.Screens.Multi.Match.Components { public class ReadyButton : OsuButton { - public readonly Bindable Beatmap = new Bindable(); + public readonly Bindable SelectedItem = new Bindable(); [Resolved(typeof(Room), nameof(Room.EndDate))] private Bindable 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; + } } } }