2020-10-26 10:47:39 +00: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.
|
|
|
|
|
2020-11-11 04:39:42 +00:00
|
|
|
using System.Diagnostics;
|
2020-10-26 10:47:39 +00:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
2020-10-27 10:23:35 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-10-28 09:35:20 +00:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2020-10-26 11:59:46 +00:00
|
|
|
using osu.Framework.Screens;
|
2021-04-02 12:27:20 +00:00
|
|
|
using osu.Framework.Threading;
|
2020-11-14 16:08:27 +00:00
|
|
|
using osu.Game.Audio;
|
2020-10-26 11:59:46 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2021-10-24 17:44:32 +00:00
|
|
|
using osu.Game.Beatmaps.Drawables.Cards;
|
2020-10-28 10:03:01 +00:00
|
|
|
using osu.Game.Configuration;
|
2020-10-27 10:23:35 +00:00
|
|
|
using osu.Game.Graphics;
|
2020-10-26 10:47:39 +00:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2020-10-28 09:01:55 +00:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-10-27 10:23:35 +00:00
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.API.Requests;
|
2021-11-04 03:30:19 +00:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2020-10-26 11:59:46 +00:00
|
|
|
using osu.Game.Online.Spectator;
|
2021-10-24 17:44:32 +00:00
|
|
|
using osu.Game.Overlays;
|
2020-10-28 10:03:01 +00:00
|
|
|
using osu.Game.Overlays.Settings;
|
2020-12-25 15:50:00 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay.Match.Components;
|
2021-04-01 13:09:51 +00:00
|
|
|
using osu.Game.Screens.Spectate;
|
2020-10-26 10:47:39 +00:00
|
|
|
using osu.Game.Users;
|
2020-10-27 10:23:35 +00:00
|
|
|
using osuTK;
|
2020-10-26 10:47:39 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
{
|
2020-11-14 16:08:27 +00:00
|
|
|
[Cached(typeof(IPreviewTrackOwner))]
|
2021-04-01 13:09:51 +00:00
|
|
|
public class SoloSpectator : SpectatorScreen, IPreviewTrackOwner
|
2020-10-26 10:47:39 +00:00
|
|
|
{
|
2021-04-01 13:09:51 +00:00
|
|
|
[NotNull]
|
2021-11-04 09:02:44 +00:00
|
|
|
private readonly APIUser targetUser;
|
2020-10-26 10:47:39 +00:00
|
|
|
|
2020-10-27 10:23:35 +00:00
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; }
|
|
|
|
|
2020-10-26 11:59:46 +00:00
|
|
|
[Resolved]
|
2021-04-01 13:09:51 +00:00
|
|
|
private PreviewTrackManager previewTrackManager { get; set; }
|
2020-10-26 11:59:46 +00:00
|
|
|
|
2020-11-14 16:08:27 +00:00
|
|
|
[Resolved]
|
2021-04-01 13:09:51 +00:00
|
|
|
private BeatmapManager beatmaps { get; set; }
|
2020-10-26 11:59:46 +00:00
|
|
|
|
2021-11-25 08:23:46 +00:00
|
|
|
[Resolved]
|
|
|
|
private BeatmapModelDownloader beatmapDownloader { get; set; }
|
|
|
|
|
2021-10-24 17:44:32 +00:00
|
|
|
[Cached]
|
|
|
|
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
|
|
|
|
|
2020-10-27 10:23:35 +00:00
|
|
|
private Container beatmapPanelContainer;
|
2020-10-28 09:01:55 +00:00
|
|
|
private TriangleButton watchButton;
|
2020-10-28 10:03:01 +00:00
|
|
|
private SettingsCheckbox automaticDownload;
|
|
|
|
|
2020-10-28 13:50:45 +00:00
|
|
|
/// <summary>
|
2021-04-01 13:09:51 +00:00
|
|
|
/// The player's immediate online gameplay state.
|
2021-04-02 12:27:20 +00:00
|
|
|
/// This doesn't always reflect the gameplay state being watched.
|
2021-04-01 13:09:51 +00:00
|
|
|
/// </summary>
|
2021-10-01 17:08:56 +00:00
|
|
|
private SpectatorGameplayState immediateSpectatorGameplayState;
|
2021-04-01 13:09:51 +00:00
|
|
|
|
|
|
|
private GetBeatmapSetRequest onlineBeatmapRequest;
|
2020-10-28 13:50:45 +00:00
|
|
|
|
2021-11-04 04:33:54 +00:00
|
|
|
private APIBeatmapSet beatmapSet;
|
|
|
|
|
2021-11-04 09:02:44 +00:00
|
|
|
public SoloSpectator([NotNull] APIUser targetUser)
|
2021-04-01 13:09:51 +00:00
|
|
|
: base(targetUser.Id)
|
2020-10-26 10:47:39 +00:00
|
|
|
{
|
2021-04-01 13:09:51 +00:00
|
|
|
this.targetUser = targetUser;
|
2020-10-26 10:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-10-24 17:44:32 +00:00
|
|
|
private void load(OsuConfigManager config)
|
2020-10-26 10:47:39 +00:00
|
|
|
{
|
2020-10-28 09:35:20 +00:00
|
|
|
InternalChild = new Container
|
2020-10-26 10:47:39 +00:00
|
|
|
{
|
2020-10-28 09:35:20 +00:00
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 20,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
AutoSizeDuration = 500,
|
|
|
|
AutoSizeEasing = Easing.OutQuint,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Children = new Drawable[]
|
2020-10-26 10:47:39 +00:00
|
|
|
{
|
2020-10-28 09:35:20 +00:00
|
|
|
new Box
|
2020-10-27 10:23:35 +00:00
|
|
|
{
|
2021-10-24 17:44:32 +00:00
|
|
|
Colour = colourProvider.Background5,
|
2020-10-28 09:35:20 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Margin = new MarginPadding(20),
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Spacing = new Vector2(15),
|
|
|
|
Children = new Drawable[]
|
2020-10-28 09:01:55 +00:00
|
|
|
{
|
2020-10-28 09:35:20 +00:00
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = "Spectator Mode",
|
|
|
|
Font = OsuFont.Default.With(size: 30),
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Spacing = new Vector2(15),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new UserGridPanel(targetUser)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Height = 145,
|
|
|
|
Width = 290,
|
|
|
|
},
|
|
|
|
new SpriteIcon
|
|
|
|
{
|
|
|
|
Size = new Vector2(40),
|
|
|
|
Icon = FontAwesome.Solid.ArrowRight,
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
},
|
|
|
|
beatmapPanelContainer = new Container
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2020-10-28 10:03:01 +00:00
|
|
|
automaticDownload = new SettingsCheckbox
|
|
|
|
{
|
|
|
|
LabelText = "Automatically download beatmaps",
|
|
|
|
Current = config.GetBindable<bool>(OsuSetting.AutomaticallyDownloadWhenSpectating),
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
},
|
2020-10-28 09:35:20 +00:00
|
|
|
watchButton = new PurpleTriangleButton
|
|
|
|
{
|
|
|
|
Text = "Start Watching",
|
|
|
|
Width = 250,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2021-10-01 17:08:56 +00:00
|
|
|
Action = () => scheduleStart(immediateSpectatorGameplayState),
|
2020-11-03 11:06:42 +00:00
|
|
|
Enabled = { Value = false }
|
2020-10-28 09:35:20 +00:00
|
|
|
}
|
2020-10-28 09:01:55 +00:00
|
|
|
}
|
2020-10-27 10:23:35 +00:00
|
|
|
}
|
2020-10-28 09:35:20 +00:00
|
|
|
}
|
2020-10-26 10:47:39 +00:00
|
|
|
};
|
2020-10-27 05:57:00 +00:00
|
|
|
}
|
2020-10-26 11:59:46 +00:00
|
|
|
|
2020-10-27 05:57:00 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2020-10-28 10:03:01 +00:00
|
|
|
automaticDownload.Current.BindValueChanged(_ => checkForAutomaticDownload());
|
2020-10-27 10:23:35 +00:00
|
|
|
}
|
|
|
|
|
2022-02-09 03:20:07 +00:00
|
|
|
protected override void OnNewPlayingUserState(int userId, SpectatorState spectatorState)
|
2020-10-27 10:23:35 +00:00
|
|
|
{
|
2021-04-01 13:09:51 +00:00
|
|
|
clearDisplay();
|
|
|
|
showBeatmapPanel(spectatorState);
|
2021-04-02 12:27:20 +00:00
|
|
|
}
|
2020-10-26 11:59:46 +00:00
|
|
|
|
2021-10-01 17:08:56 +00:00
|
|
|
protected override void StartGameplay(int userId, SpectatorGameplayState spectatorGameplayState)
|
2020-10-26 11:59:46 +00:00
|
|
|
{
|
2021-10-01 17:08:56 +00:00
|
|
|
immediateSpectatorGameplayState = spectatorGameplayState;
|
2021-04-01 13:09:51 +00:00
|
|
|
watchButton.Enabled.Value = true;
|
2020-11-11 04:39:42 +00:00
|
|
|
|
2021-10-01 17:08:56 +00:00
|
|
|
scheduleStart(spectatorGameplayState);
|
2021-04-02 12:27:20 +00:00
|
|
|
}
|
|
|
|
|
2022-02-03 12:50:15 +00:00
|
|
|
protected override void EndGameplay(int userId, SpectatorState state)
|
2020-10-26 11:59:46 +00:00
|
|
|
{
|
2021-04-02 12:27:20 +00:00
|
|
|
scheduledStart?.Cancel();
|
2021-10-01 17:08:56 +00:00
|
|
|
immediateSpectatorGameplayState = null;
|
2021-04-01 13:09:51 +00:00
|
|
|
watchButton.Enabled.Value = false;
|
2020-10-28 13:50:45 +00:00
|
|
|
|
2021-04-02 12:27:20 +00:00
|
|
|
clearDisplay();
|
2020-10-28 07:11:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 09:35:20 +00:00
|
|
|
private void clearDisplay()
|
2020-10-27 10:23:35 +00:00
|
|
|
{
|
2020-10-28 09:16:19 +00:00
|
|
|
watchButton.Enabled.Value = false;
|
2021-04-01 13:09:51 +00:00
|
|
|
onlineBeatmapRequest?.Cancel();
|
2020-10-28 09:35:20 +00:00
|
|
|
beatmapPanelContainer.Clear();
|
2020-11-14 16:08:27 +00:00
|
|
|
previewTrackManager.StopAnyPlaying(this);
|
2020-10-28 09:35:20 +00:00
|
|
|
}
|
2020-10-28 09:16:19 +00:00
|
|
|
|
2021-04-02 12:27:20 +00:00
|
|
|
private ScheduledDelegate scheduledStart;
|
|
|
|
|
2021-10-01 17:08:56 +00:00
|
|
|
private void scheduleStart(SpectatorGameplayState spectatorGameplayState)
|
2020-10-28 09:35:20 +00:00
|
|
|
{
|
2021-04-02 12:27:20 +00:00
|
|
|
// This function may be called multiple times in quick succession once the screen becomes current again.
|
|
|
|
scheduledStart?.Cancel();
|
|
|
|
scheduledStart = Schedule(() =>
|
|
|
|
{
|
|
|
|
if (this.IsCurrentScreen())
|
|
|
|
start();
|
|
|
|
else
|
2021-10-01 17:08:56 +00:00
|
|
|
scheduleStart(spectatorGameplayState);
|
2021-04-02 12:27:20 +00:00
|
|
|
});
|
2020-10-26 11:59:46 +00:00
|
|
|
|
2021-04-02 12:27:20 +00:00
|
|
|
void start()
|
|
|
|
{
|
2021-10-01 17:08:56 +00:00
|
|
|
Beatmap.Value = spectatorGameplayState.Beatmap;
|
|
|
|
Ruleset.Value = spectatorGameplayState.Ruleset.RulesetInfo;
|
2020-10-26 11:59:46 +00:00
|
|
|
|
2021-10-01 17:08:56 +00:00
|
|
|
this.Push(new SpectatorPlayerLoader(spectatorGameplayState.Score, () => new SoloSpectatorPlayer(spectatorGameplayState.Score)));
|
2021-04-02 12:27:20 +00:00
|
|
|
}
|
2020-10-26 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 09:16:19 +00:00
|
|
|
private void showBeatmapPanel(SpectatorState state)
|
2020-10-27 10:23:35 +00:00
|
|
|
{
|
2021-04-01 13:09:51 +00:00
|
|
|
Debug.Assert(state.BeatmapID != null);
|
2020-10-28 09:16:19 +00:00
|
|
|
|
2021-04-01 13:09:51 +00:00
|
|
|
onlineBeatmapRequest = new GetBeatmapSetRequest(state.BeatmapID.Value, BeatmapSetLookupType.BeatmapId);
|
2021-11-04 04:33:54 +00:00
|
|
|
onlineBeatmapRequest.Success += beatmapSet => Schedule(() =>
|
2020-10-27 10:23:35 +00:00
|
|
|
{
|
2021-11-04 04:33:54 +00:00
|
|
|
this.beatmapSet = beatmapSet;
|
2021-12-21 07:25:52 +00:00
|
|
|
beatmapPanelContainer.Child = new BeatmapCardNormal(this.beatmapSet, allowExpansion: false);
|
2020-10-28 10:03:01 +00:00
|
|
|
checkForAutomaticDownload();
|
2020-10-27 10:23:35 +00:00
|
|
|
});
|
|
|
|
|
2021-04-01 13:09:51 +00:00
|
|
|
api.Queue(onlineBeatmapRequest);
|
2020-10-27 10:23:35 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 10:03:01 +00:00
|
|
|
private void checkForAutomaticDownload()
|
|
|
|
{
|
2021-11-04 04:33:54 +00:00
|
|
|
if (beatmapSet == null)
|
2020-10-28 10:03:01 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!automaticDownload.Current.Value)
|
|
|
|
return;
|
|
|
|
|
2021-11-12 08:50:31 +00:00
|
|
|
if (beatmaps.IsAvailableLocally(new BeatmapSetInfo { OnlineID = beatmapSet.OnlineID }))
|
2020-10-28 10:03:01 +00:00
|
|
|
return;
|
|
|
|
|
2021-11-25 08:23:46 +00:00
|
|
|
beatmapDownloader.Download(beatmapSet);
|
2020-10-28 10:03:01 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 16:08:27 +00:00
|
|
|
public override bool OnExiting(IScreen next)
|
|
|
|
{
|
|
|
|
previewTrackManager.StopAnyPlaying(this);
|
|
|
|
return base.OnExiting(next);
|
|
|
|
}
|
2020-10-26 10:47:39 +00:00
|
|
|
}
|
|
|
|
}
|