2020-12-20 22:40:19 +08:00
|
|
|
// 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;
|
2021-02-01 12:40:59 +08:00
|
|
|
using System.Collections.Generic;
|
2020-12-20 22:40:19 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2020-12-24 15:53:25 +08:00
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
2020-12-20 22:40:19 +08:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Game.Audio;
|
|
|
|
using osu.Game.Beatmaps;
|
2020-12-25 12:38:11 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-12-22 18:53:01 +08:00
|
|
|
using osu.Game.Overlays;
|
2020-12-20 22:40:19 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2020-12-24 15:53:25 +08:00
|
|
|
using osu.Game.Screens.Play;
|
2020-12-20 22:40:19 +08:00
|
|
|
|
2020-12-25 23:50:00 +08:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Match
|
2020-12-20 22:40:19 +08:00
|
|
|
{
|
|
|
|
[Cached(typeof(IPreviewTrackOwner))]
|
2020-12-26 00:02:35 +08:00
|
|
|
public abstract class RoomSubScreen : OnlinePlaySubScreen, IPreviewTrackOwner
|
2020-12-20 22:40:19 +08:00
|
|
|
{
|
2021-02-16 16:35:44 +08:00
|
|
|
[Cached(typeof(IBindable<PlaylistItem>))]
|
2020-12-20 22:40:19 +08:00
|
|
|
protected readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
|
|
|
|
|
|
|
public override bool DisallowExternalBeatmapRulesetChanges => true;
|
|
|
|
|
2021-01-19 16:11:40 +08:00
|
|
|
private Sample sampleStart;
|
2020-12-24 15:53:25 +08:00
|
|
|
|
2021-02-01 12:40:59 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Any mods applied by/to the local user.
|
|
|
|
/// </summary>
|
2021-02-01 16:57:32 +08:00
|
|
|
protected readonly Bindable<IReadOnlyList<Mod>> UserMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
2021-02-01 12:40:59 +08:00
|
|
|
|
2020-12-22 18:53:01 +08:00
|
|
|
[Resolved]
|
|
|
|
private MusicController music { get; set; }
|
|
|
|
|
2020-12-20 22:40:19 +08:00
|
|
|
[Resolved]
|
|
|
|
private BeatmapManager beatmapManager { get; set; }
|
|
|
|
|
2020-12-24 15:53:25 +08:00
|
|
|
[Resolved(canBeNull: true)]
|
2020-12-26 00:00:00 +08:00
|
|
|
protected OnlinePlayScreen ParentScreen { get; private set; }
|
2020-12-24 15:53:25 +08:00
|
|
|
|
2020-12-20 22:40:19 +08:00
|
|
|
private IBindable<WeakReference<BeatmapSetInfo>> managerUpdated;
|
|
|
|
|
2021-01-17 04:02:30 +08:00
|
|
|
[Cached]
|
2021-02-05 11:24:38 +08:00
|
|
|
protected OnlinePlayBeatmapAvailablilityTracker BeatmapAvailablilityTracker { get; }
|
2021-01-17 04:02:30 +08:00
|
|
|
|
2021-02-05 14:26:05 +08:00
|
|
|
protected IBindable<BeatmapAvailability> BeatmapAvailability => BeatmapAvailablilityTracker.Availability;
|
2021-01-18 15:49:38 +08:00
|
|
|
|
2021-01-17 04:02:30 +08:00
|
|
|
protected RoomSubScreen()
|
|
|
|
{
|
2021-02-05 13:39:25 +08:00
|
|
|
AddInternal(BeatmapAvailablilityTracker = new OnlinePlayBeatmapAvailablilityTracker
|
2021-01-17 04:02:30 +08:00
|
|
|
{
|
2021-02-05 13:39:25 +08:00
|
|
|
SelectedItem = { BindTarget = SelectedItem }
|
|
|
|
});
|
2021-01-17 04:02:30 +08:00
|
|
|
}
|
|
|
|
|
2021-02-05 13:39:25 +08:00
|
|
|
protected override void ClearInternal(bool disposeChildren = true) =>
|
|
|
|
throw new InvalidOperationException($"{nameof(RoomSubScreen)}'s children should not be cleared as it will remove required components");
|
2021-01-20 00:03:29 +08:00
|
|
|
|
2020-12-24 15:53:25 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
{
|
|
|
|
sampleStart = audio.Samples.Get(@"SongSelect/confirm-selection");
|
|
|
|
}
|
|
|
|
|
2020-12-20 22:40:19 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
SelectedItem.BindValueChanged(_ => Scheduler.AddOnce(selectedItemChanged));
|
|
|
|
|
|
|
|
managerUpdated = beatmapManager.ItemUpdated.GetBoundCopy();
|
|
|
|
managerUpdated.BindValueChanged(beatmapUpdated);
|
2021-02-01 12:40:59 +08:00
|
|
|
|
2021-02-11 15:00:35 +08:00
|
|
|
UserMods.BindValueChanged(_ => Scheduler.AddOnce(UpdateMods));
|
2020-12-22 18:53:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnEntering(IScreen last)
|
|
|
|
{
|
|
|
|
base.OnEntering(last);
|
2020-12-23 20:47:28 +08:00
|
|
|
beginHandlingTrack();
|
2020-12-22 18:53:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnSuspending(IScreen next)
|
|
|
|
{
|
2020-12-23 20:47:28 +08:00
|
|
|
endHandlingTrack();
|
2020-12-22 18:53:01 +08:00
|
|
|
base.OnSuspending(next);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnResuming(IScreen last)
|
|
|
|
{
|
|
|
|
base.OnResuming(last);
|
2020-12-23 20:47:28 +08:00
|
|
|
beginHandlingTrack();
|
2021-02-11 15:00:35 +08:00
|
|
|
Scheduler.AddOnce(UpdateMods);
|
2020-12-20 22:40:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool OnExiting(IScreen next)
|
|
|
|
{
|
|
|
|
RoomManager?.PartRoom();
|
|
|
|
Mods.Value = Array.Empty<Mod>();
|
|
|
|
|
2020-12-23 20:47:28 +08:00
|
|
|
endHandlingTrack();
|
2020-12-22 18:53:01 +08:00
|
|
|
|
2020-12-20 22:40:19 +08:00
|
|
|
return base.OnExiting(next);
|
|
|
|
}
|
2020-12-22 18:53:01 +08:00
|
|
|
|
2020-12-24 15:53:25 +08:00
|
|
|
protected void StartPlay(Func<Player> player)
|
|
|
|
{
|
|
|
|
sampleStart?.Play();
|
2020-12-26 00:00:00 +08:00
|
|
|
ParentScreen?.Push(new PlayerLoader(player));
|
2020-12-24 15:53:25 +08:00
|
|
|
}
|
|
|
|
|
2020-12-23 13:47:34 +08:00
|
|
|
private void selectedItemChanged()
|
2020-12-22 18:53:01 +08:00
|
|
|
{
|
2020-12-23 13:47:34 +08:00
|
|
|
updateWorkingBeatmap();
|
|
|
|
|
2021-02-01 12:40:59 +08:00
|
|
|
if (SelectedItem.Value == null)
|
|
|
|
return;
|
2020-12-23 13:47:34 +08:00
|
|
|
|
2021-02-01 17:50:32 +08:00
|
|
|
// Remove any user mods that are no longer allowed.
|
2021-02-01 16:57:32 +08:00
|
|
|
UserMods.Value = UserMods.Value
|
|
|
|
.Where(m => SelectedItem.Value.AllowedMods.Any(a => m.GetType() == a.GetType()))
|
|
|
|
.ToList();
|
2020-12-23 13:47:34 +08:00
|
|
|
|
2021-02-11 14:55:08 +08:00
|
|
|
UpdateMods();
|
2020-12-23 13:47:34 +08:00
|
|
|
|
2021-02-01 12:40:59 +08:00
|
|
|
Ruleset.Value = SelectedItem.Value.Ruleset.Value;
|
2020-12-23 13:47:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-02-11 14:55:08 +08:00
|
|
|
protected virtual void UpdateMods()
|
2021-02-01 12:40:59 +08:00
|
|
|
{
|
|
|
|
if (SelectedItem.Value == null)
|
|
|
|
return;
|
|
|
|
|
2021-02-01 16:57:32 +08:00
|
|
|
Mods.Value = UserMods.Value.Concat(SelectedItem.Value.RequiredMods).ToList();
|
2021-02-01 12:40:59 +08:00
|
|
|
}
|
|
|
|
|
2020-12-23 20:47:28 +08:00
|
|
|
private void beginHandlingTrack()
|
|
|
|
{
|
|
|
|
Beatmap.BindValueChanged(applyLoopingToTrack, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void endHandlingTrack()
|
|
|
|
{
|
|
|
|
Beatmap.ValueChanged -= applyLoopingToTrack;
|
|
|
|
cancelTrackLooping();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void applyLoopingToTrack(ValueChangedEvent<WorkingBeatmap> _ = null)
|
2020-12-23 13:47:34 +08:00
|
|
|
{
|
|
|
|
if (!this.IsCurrentScreen())
|
|
|
|
return;
|
|
|
|
|
2020-12-22 18:53:01 +08:00
|
|
|
var track = Beatmap.Value?.Track;
|
|
|
|
|
|
|
|
if (track != null)
|
|
|
|
{
|
|
|
|
track.RestartPoint = Beatmap.Value.Metadata.PreviewTime;
|
|
|
|
track.Looping = true;
|
2020-12-23 13:47:34 +08:00
|
|
|
|
|
|
|
music?.EnsurePlayingSomething();
|
2020-12-22 18:53:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-23 20:47:28 +08:00
|
|
|
private void cancelTrackLooping()
|
2020-12-22 18:53:01 +08:00
|
|
|
{
|
|
|
|
var track = Beatmap?.Value?.Track;
|
|
|
|
|
|
|
|
if (track != null)
|
|
|
|
{
|
|
|
|
track.Looping = false;
|
|
|
|
track.RestartPoint = 0;
|
|
|
|
}
|
|
|
|
}
|
2020-12-20 22:40:19 +08:00
|
|
|
}
|
|
|
|
}
|