mirror of
https://github.com/ppy/osu.git
synced 2024-11-12 10:17:32 +08:00
75 lines
2.4 KiB
C#
75 lines
2.4 KiB
C#
// 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;
|
|
using System.Linq;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Bindables;
|
|
using osu.Framework.Screens;
|
|
using osu.Game.Audio;
|
|
using osu.Game.Beatmaps;
|
|
using osu.Game.Online.Multiplayer;
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
namespace osu.Game.Screens.Multi.Match
|
|
{
|
|
[Cached(typeof(IPreviewTrackOwner))]
|
|
public abstract class RoomSubScreen : MultiplayerSubScreen, IPreviewTrackOwner
|
|
{
|
|
protected readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
|
|
|
public override bool DisallowExternalBeatmapRulesetChanges => true;
|
|
|
|
[Resolved(typeof(Room), nameof(Room.Playlist))]
|
|
protected BindableList<PlaylistItem> Playlist { get; private set; }
|
|
|
|
[Resolved]
|
|
private BeatmapManager beatmapManager { get; set; }
|
|
|
|
private IBindable<WeakReference<BeatmapSetInfo>> managerUpdated;
|
|
|
|
protected override void LoadComplete()
|
|
{
|
|
base.LoadComplete();
|
|
|
|
SelectedItem.BindValueChanged(_ => Scheduler.AddOnce(selectedItemChanged));
|
|
SelectedItem.Value = Playlist.FirstOrDefault();
|
|
|
|
managerUpdated = beatmapManager.ItemUpdated.GetBoundCopy();
|
|
managerUpdated.BindValueChanged(beatmapUpdated);
|
|
}
|
|
|
|
private void selectedItemChanged()
|
|
{
|
|
updateWorkingBeatmap();
|
|
|
|
var item = SelectedItem.Value;
|
|
|
|
Mods.Value = item?.RequiredMods?.ToArray() ?? Array.Empty<Mod>();
|
|
|
|
if (item?.Ruleset != null)
|
|
Ruleset.Value = item.Ruleset.Value;
|
|
}
|
|
|
|
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet) => Schedule(updateWorkingBeatmap);
|
|
|
|
private void updateWorkingBeatmap()
|
|
{
|
|
var beatmap = SelectedItem.Value?.Beatmap.Value;
|
|
|
|
// Retrieve the corresponding local beatmap, since we can't directly use the playlist's beatmap info
|
|
var localBeatmap = beatmap == null ? null : beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == beatmap.OnlineBeatmapID);
|
|
|
|
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
|
|
}
|
|
|
|
public override bool OnExiting(IScreen next)
|
|
{
|
|
RoomManager?.PartRoom();
|
|
Mods.Value = Array.Empty<Mod>();
|
|
|
|
return base.OnExiting(next);
|
|
}
|
|
}
|
|
}
|