mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 04:02:59 +08:00
Re-simplify code by removing BeatmapManager event instead
This commit is contained in:
parent
c097dc8048
commit
70045494ba
@ -15,7 +15,6 @@ using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Audio;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Mods;
|
||||
@ -68,7 +67,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
protected OnlinePlayScreen ParentScreen { get; private set; }
|
||||
|
||||
[Cached]
|
||||
private OnlinePlayBeatmapAvailabilityTracker beatmapAvailabilityTracker { get; set; }
|
||||
private readonly OnlinePlayBeatmapAvailabilityTracker beatmapAvailabilityTracker = new OnlinePlayBeatmapAvailabilityTracker();
|
||||
|
||||
protected IBindable<BeatmapAvailability> BeatmapAvailability => beatmapAvailabilityTracker.Availability;
|
||||
|
||||
@ -91,11 +90,6 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
|
||||
Padding = new MarginPadding { Top = Header.HEIGHT };
|
||||
|
||||
beatmapAvailabilityTracker = new OnlinePlayBeatmapAvailabilityTracker
|
||||
{
|
||||
SelectedItem = { BindTarget = SelectedItem }
|
||||
};
|
||||
|
||||
RoomId.BindTo(room.RoomID);
|
||||
}
|
||||
|
||||
@ -248,10 +242,10 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
}, true);
|
||||
|
||||
SelectedItem.BindValueChanged(_ => Scheduler.AddOnce(selectedItemChanged));
|
||||
|
||||
beatmapManager.ItemUpdated += beatmapUpdated;
|
||||
|
||||
UserMods.BindValueChanged(_ => Scheduler.AddOnce(UpdateMods));
|
||||
|
||||
beatmapAvailabilityTracker.SelectedItem.BindTo(SelectedItem);
|
||||
beatmapAvailabilityTracker.Availability.BindValueChanged(_ => updateWorkingBeatmap());
|
||||
}
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||
@ -303,7 +297,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
public override void OnResuming(IScreen last)
|
||||
{
|
||||
base.OnResuming(last);
|
||||
UpdateWorkingBeatmap();
|
||||
updateWorkingBeatmap();
|
||||
beginHandlingTrack();
|
||||
Scheduler.AddOnce(UpdateMods);
|
||||
}
|
||||
@ -346,7 +340,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
|
||||
private void selectedItemChanged()
|
||||
{
|
||||
UpdateWorkingBeatmap();
|
||||
updateWorkingBeatmap();
|
||||
|
||||
var selected = SelectedItem.Value;
|
||||
|
||||
@ -375,16 +369,8 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
}
|
||||
}
|
||||
|
||||
private void beatmapUpdated(BeatmapSetInfo set) => Schedule(UpdateWorkingBeatmap);
|
||||
|
||||
protected virtual void UpdateWorkingBeatmap()
|
||||
private void updateWorkingBeatmap()
|
||||
{
|
||||
if (BeatmapAvailability.Value.State != DownloadState.LocallyAvailable)
|
||||
{
|
||||
Beatmap.Value = beatmapManager.GetWorkingBeatmap(null);
|
||||
return;
|
||||
}
|
||||
|
||||
var beatmap = SelectedItem.Value?.Beatmap.Value;
|
||||
|
||||
// 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>
|
||||
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
|
||||
{
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ using osu.Framework.Screens;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Extensions;
|
||||
using osu.Game.Online;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Rooms;
|
||||
@ -327,27 +326,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
if (client.LocalUser?.State == MultiplayerUserState.Ready)
|
||||
client.ChangeState(MultiplayerUserState.Idle);
|
||||
}
|
||||
|
||||
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))
|
||||
else if (client.LocalUser?.State == MultiplayerUserState.Spectating
|
||||
&& (client.Room?.State == MultiplayerRoomState.WaitingForLoad || client.Room?.State == MultiplayerRoomState.Playing))
|
||||
{
|
||||
onLoadRequested();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user