1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 18:32:55 +08:00

Fix selected item potentially changing during gameplay

This commit is contained in:
smoogipoo 2021-02-17 21:38:01 +09:00
parent 8930ff4465
commit 2a1bb2f578

View File

@ -46,7 +46,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
private MultiplayerMatchSettingsOverlay settingsOverlay;
private Drawable userModsSection;
private IBindable<bool> isConnected;
private readonly IBindable<bool> isConnected = new Bindable<bool>();
private readonly IBindable<PlaylistItem> matchCurrentItem = new Bindable<PlaylistItem>();
[CanBeNull]
private IDisposable readyClickOperation;
@ -268,8 +269,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
{
base.LoadComplete();
SelectedItem.BindValueChanged(onSelectedItemChanged);
SelectedItem.BindTo(client.CurrentMatchPlayingItem);
matchCurrentItem.BindTo(client.CurrentMatchPlayingItem);
matchCurrentItem.BindValueChanged(onCurrentItemChanged, true);
BeatmapAvailability.BindValueChanged(updateBeatmapAvailability, true);
UserMods.BindValueChanged(onUserModsChanged);
@ -277,7 +278,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
client.LoadRequested += onLoadRequested;
client.RoomUpdated += onRoomUpdated;
isConnected = client.IsConnected.GetBoundCopy();
isConnected.BindTo(client.IsConnected);
isConnected.BindValueChanged(connected =>
{
if (!connected.NewValue)
@ -285,6 +286,33 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
}, true);
}
private void onCurrentItemChanged(ValueChangedEvent<PlaylistItem> item)
{
if (client?.LocalUser == null)
return;
// If we're about to enter gameplay, schedule the item to be set at a later time.
if (client.LocalUser.State > MultiplayerUserState.Ready)
{
Schedule(() => onCurrentItemChanged(item));
return;
}
SelectedItem.Value = item.NewValue;
if (item.NewValue?.AllowedMods.Any() != true)
{
userModsSection.Hide();
userModsSelectOverlay.Hide();
userModsSelectOverlay.IsValidMod = _ => false;
}
else
{
userModsSection.Show();
userModsSelectOverlay.IsValidMod = m => item.NewValue.AllowedMods.Any(a => a.GetType() == m.GetType());
}
}
protected override void UpdateMods()
{
if (SelectedItem.Value == null || client.LocalUser == null)
@ -313,21 +341,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
return base.OnBackButton();
}
private void onSelectedItemChanged(ValueChangedEvent<PlaylistItem> item)
{
if (item.NewValue?.AllowedMods.Any() != true)
{
userModsSection.Hide();
userModsSelectOverlay.Hide();
userModsSelectOverlay.IsValidMod = _ => false;
}
else
{
userModsSection.Show();
userModsSelectOverlay.IsValidMod = m => item.NewValue.AllowedMods.Any(a => a.GetType() == m.GetType());
}
}
private ModSettingChangeTracker modSettingChangeTracker;
private ScheduledDelegate debouncedModSettingsUpdate;