mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 23:52:57 +08:00
Fix beatmap panel flickering multiple times
This commit is contained in:
parent
2a1bb2f578
commit
6ef235c4c5
@ -1,15 +1,12 @@
|
||||
// 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.
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Screens.OnlinePlay.Match.Components;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
@ -61,10 +58,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Debug.Assert(SelectedItem != null);
|
||||
SelectedItem.BindValueChanged(_ => updateBeatmap());
|
||||
Playlist.BindCollectionChanged((_, __) => updateBeatmap(), true);
|
||||
|
||||
SelectedItem.BindValueChanged(_ => updateBeatmap(), true);
|
||||
Host.BindValueChanged(host =>
|
||||
{
|
||||
if (RoomID.Value == null || host.NewValue?.Equals(api.LocalUser.Value) == true)
|
||||
@ -76,15 +70,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
|
||||
private void updateBeatmap()
|
||||
{
|
||||
Debug.Assert(SelectedItem != null);
|
||||
|
||||
// When the selected item is null, the match hasn't yet been created. Use the playlist directly, which is mutated by song selection.
|
||||
PlaylistItem item = SelectedItem.Value ?? Playlist.FirstOrDefault();
|
||||
|
||||
if (item == null)
|
||||
if (SelectedItem.Value == null)
|
||||
beatmapPanelContainer.Clear();
|
||||
else
|
||||
beatmapPanelContainer.Child = new DrawableRoomPlaylistItem(item, false, false);
|
||||
beatmapPanelContainer.Child = new DrawableRoomPlaylistItem(SelectedItem.Value, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -57,11 +59,44 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
protected Bindable<TimeSpan?> Duration { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The currently selected item in the <see cref="RoomSubScreen"/>.
|
||||
/// May be null if this <see cref="OnlinePlayComposite"/> is not inside a <see cref="RoomSubScreen"/>.
|
||||
/// The currently selected item in the <see cref="RoomSubScreen"/>, or the first item from <see cref="Playlist"/>
|
||||
/// if this <see cref="OnlinePlayComposite"/> is not within a <see cref="RoomSubScreen"/>.
|
||||
/// </summary>
|
||||
protected IBindable<PlaylistItem> SelectedItem => selectedItem;
|
||||
|
||||
private readonly Bindable<PlaylistItem> selectedItem = new Bindable<PlaylistItem>();
|
||||
|
||||
[CanBeNull]
|
||||
[Resolved(CanBeNull = true)]
|
||||
protected IBindable<PlaylistItem> SelectedItem { get; private set; }
|
||||
private IBindable<PlaylistItem> subScreenSelectedItem { get; set; }
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
if (subScreenSelectedItem != null)
|
||||
subScreenSelectedItem.BindValueChanged(onSelectedItemChanged, true);
|
||||
else
|
||||
Playlist.BindCollectionChanged(onPlaylistChanged, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the selected item from within a <see cref="RoomSubScreen"/> changes.
|
||||
/// Does not occur when this <see cref="OnlinePlayComposite"/> is outside a <see cref="RoomSubScreen"/>.
|
||||
/// </summary>
|
||||
private void onSelectedItemChanged(ValueChangedEvent<PlaylistItem> item)
|
||||
{
|
||||
// If the room hasn't been created yet, fall-back to the first item from the playlist.
|
||||
selectedItem.Value = RoomID.Value == null ? Playlist.FirstOrDefault() : item.NewValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the playlist changes.
|
||||
/// Does not occur when this <see cref="OnlinePlayComposite"/> is inside a <see cref="RoomSubScreen"/>.
|
||||
/// </summary>
|
||||
private void onPlaylistChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
selectedItem.Value = Playlist.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user