1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 08:12:56 +08:00

Re-simplify code by removing BeatmapManager event instead

This commit is contained in:
Dan Balasescu 2021-12-13 16:09:53 +09:00
parent c097dc8048
commit 70045494ba
2 changed files with 9 additions and 51 deletions

View File

@ -15,7 +15,6 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Online;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Mods; using osu.Game.Overlays.Mods;
@ -68,7 +67,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
protected OnlinePlayScreen ParentScreen { get; private set; } protected OnlinePlayScreen ParentScreen { get; private set; }
[Cached] [Cached]
private OnlinePlayBeatmapAvailabilityTracker beatmapAvailabilityTracker { get; set; } private readonly OnlinePlayBeatmapAvailabilityTracker beatmapAvailabilityTracker = new OnlinePlayBeatmapAvailabilityTracker();
protected IBindable<BeatmapAvailability> BeatmapAvailability => beatmapAvailabilityTracker.Availability; protected IBindable<BeatmapAvailability> BeatmapAvailability => beatmapAvailabilityTracker.Availability;
@ -91,11 +90,6 @@ namespace osu.Game.Screens.OnlinePlay.Match
Padding = new MarginPadding { Top = Header.HEIGHT }; Padding = new MarginPadding { Top = Header.HEIGHT };
beatmapAvailabilityTracker = new OnlinePlayBeatmapAvailabilityTracker
{
SelectedItem = { BindTarget = SelectedItem }
};
RoomId.BindTo(room.RoomID); RoomId.BindTo(room.RoomID);
} }
@ -248,10 +242,10 @@ namespace osu.Game.Screens.OnlinePlay.Match
}, true); }, true);
SelectedItem.BindValueChanged(_ => Scheduler.AddOnce(selectedItemChanged)); SelectedItem.BindValueChanged(_ => Scheduler.AddOnce(selectedItemChanged));
beatmapManager.ItemUpdated += beatmapUpdated;
UserMods.BindValueChanged(_ => Scheduler.AddOnce(UpdateMods)); UserMods.BindValueChanged(_ => Scheduler.AddOnce(UpdateMods));
beatmapAvailabilityTracker.SelectedItem.BindTo(SelectedItem);
beatmapAvailabilityTracker.Availability.BindValueChanged(_ => updateWorkingBeatmap());
} }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
@ -303,7 +297,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
public override void OnResuming(IScreen last) public override void OnResuming(IScreen last)
{ {
base.OnResuming(last); base.OnResuming(last);
UpdateWorkingBeatmap(); updateWorkingBeatmap();
beginHandlingTrack(); beginHandlingTrack();
Scheduler.AddOnce(UpdateMods); Scheduler.AddOnce(UpdateMods);
} }
@ -346,7 +340,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
private void selectedItemChanged() private void selectedItemChanged()
{ {
UpdateWorkingBeatmap(); updateWorkingBeatmap();
var selected = SelectedItem.Value; var selected = SelectedItem.Value;
@ -375,16 +369,8 @@ namespace osu.Game.Screens.OnlinePlay.Match
} }
} }
private void beatmapUpdated(BeatmapSetInfo set) => Schedule(UpdateWorkingBeatmap); private void updateWorkingBeatmap()
protected virtual void UpdateWorkingBeatmap()
{ {
if (BeatmapAvailability.Value.State != DownloadState.LocallyAvailable)
{
Beatmap.Value = beatmapManager.GetWorkingBeatmap(null);
return;
}
var beatmap = SelectedItem.Value?.Beatmap.Value; var beatmap = SelectedItem.Value?.Beatmap.Value;
// Retrieve the corresponding local beatmap, since we can't directly use the playlist's beatmap info // Retrieve the corresponding local beatmap, since we can't directly use the playlist's beatmap info
@ -450,14 +436,6 @@ namespace osu.Game.Screens.OnlinePlay.Match
/// <param name="room">The room to change the settings of.</param> /// <param name="room">The room to change the settings of.</param>
protected abstract RoomSettingsOverlay CreateRoomSettingsOverlay(Room room); protected abstract RoomSettingsOverlay CreateRoomSettingsOverlay(Room room);
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (beatmapManager != null)
beatmapManager.ItemUpdated -= beatmapUpdated;
}
public class UserModSelectButton : PurpleTriangleButton public class UserModSelectButton : PurpleTriangleButton
{ {
} }

View File

@ -15,7 +15,6 @@ using osu.Framework.Screens;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Extensions;
using osu.Game.Online; using osu.Game.Online;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
@ -327,26 +326,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
if (client.LocalUser?.State == MultiplayerUserState.Ready) if (client.LocalUser?.State == MultiplayerUserState.Ready)
client.ChangeState(MultiplayerUserState.Idle); client.ChangeState(MultiplayerUserState.Idle);
} }
else if (client.LocalUser?.State == MultiplayerUserState.Spectating
UpdateWorkingBeatmap();
}
protected override void UpdateWorkingBeatmap()
{
var lastBeatmap = Beatmap.Value;
base.UpdateWorkingBeatmap();
// Nothing to do if the beatmap hasn't changed.
if (Beatmap.Value.BeatmapInfo.MatchesOnlineID(lastBeatmap.BeatmapInfo))
return;
// The selected item is nulled during the beatmap query. During this, the working beatmap will be the dummy beatmap.
// We don't want to enter spectate mode with the dummy beatmap.
if (!Beatmap.Value.BeatmapInfo.MatchesOnlineID(SelectedItem.Value?.Beatmap.Value))
return;
if (client.LocalUser?.State == MultiplayerUserState.Spectating
&& (client.Room?.State == MultiplayerRoomState.WaitingForLoad || client.Room?.State == MultiplayerRoomState.Playing)) && (client.Room?.State == MultiplayerRoomState.WaitingForLoad || client.Room?.State == MultiplayerRoomState.Playing))
{ {
onLoadRequested(); onLoadRequested();