2021-04-08 21:07:00 +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.
|
|
|
|
|
2021-04-16 12:28:32 +08:00
|
|
|
using System;
|
2021-04-22 22:38:51 +08:00
|
|
|
using System.Collections.Generic;
|
2021-04-08 21:07:00 +08:00
|
|
|
using osu.Framework.Allocation;
|
2021-04-22 21:59:47 +08:00
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Bindables;
|
2021-04-08 21:07:00 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Beatmaps;
|
2021-04-16 12:28:32 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-04-22 22:38:51 +08:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2021-04-08 21:07:00 +08:00
|
|
|
using osu.Game.Scoring;
|
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|
|
|
{
|
2021-04-22 22:52:22 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Provides an area for and manages the hierarchy of a spectated player within a <see cref="MultiSpectatorScreen"/>.
|
|
|
|
/// </summary>
|
2021-04-26 18:01:30 +08:00
|
|
|
public partial class PlayerArea : CompositeDrawable
|
2021-04-08 21:07:00 +08:00
|
|
|
{
|
2021-08-11 17:16:25 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Raised after <see cref="Player.StartGameplay"/> is called on <see cref="Player"/>.
|
|
|
|
/// </summary>
|
2022-08-22 20:52:43 +08:00
|
|
|
public event Action? OnGameplayStarted;
|
2021-08-11 17:16:25 +08:00
|
|
|
|
2021-04-22 22:52:22 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether a <see cref="Player"/> is loaded in the area.
|
|
|
|
/// </summary>
|
2021-06-11 17:14:37 +08:00
|
|
|
public bool PlayerLoaded => (stack?.CurrentScreen as Player)?.IsLoaded == true;
|
2021-04-08 21:07:00 +08:00
|
|
|
|
2021-04-22 22:52:22 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The user id this <see cref="PlayerArea"/> corresponds to.
|
|
|
|
/// </summary>
|
2021-04-16 11:25:29 +08:00
|
|
|
public readonly int UserId;
|
2021-04-08 21:07:00 +08:00
|
|
|
|
2021-04-22 22:52:22 +08:00
|
|
|
/// <summary>
|
2022-08-24 15:43:26 +08:00
|
|
|
/// The <see cref="Spectate.SpectatorPlayerClock"/> used to control the gameplay running state of a loaded <see cref="Player"/>.
|
2021-04-22 22:52:22 +08:00
|
|
|
/// </summary>
|
2022-08-24 15:43:26 +08:00
|
|
|
public readonly SpectatorPlayerClock SpectatorPlayerClock;
|
2021-04-22 22:52:22 +08:00
|
|
|
|
2022-09-08 15:59:20 +08:00
|
|
|
/// <summary>
|
2022-09-08 16:14:06 +08:00
|
|
|
/// The clock adjustments applied by the <see cref="Player"/> loaded in this area.
|
2022-09-08 15:59:20 +08:00
|
|
|
/// </summary>
|
2022-09-08 16:37:02 +08:00
|
|
|
public IAggregateAudioAdjustment ClockAdjustmentsFromMods => clockAdjustmentsFromMods;
|
2022-09-08 15:59:20 +08:00
|
|
|
|
2021-04-22 22:52:22 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The currently-loaded score.
|
|
|
|
/// </summary>
|
2022-08-22 20:52:43 +08:00
|
|
|
public Score? Score { get; private set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
|
2021-04-08 21:07:00 +08:00
|
|
|
|
2022-09-08 16:37:02 +08:00
|
|
|
private readonly AudioAdjustments clockAdjustmentsFromMods = new AudioAdjustments();
|
2021-04-26 18:01:30 +08:00
|
|
|
private readonly BindableDouble volumeAdjustment = new BindableDouble();
|
2021-04-22 21:59:47 +08:00
|
|
|
private readonly Container gameplayContent;
|
2021-04-16 12:28:32 +08:00
|
|
|
private readonly LoadingLayer loadingLayer;
|
2022-08-22 20:52:43 +08:00
|
|
|
private OsuScreenStack? stack;
|
2021-04-08 21:07:00 +08:00
|
|
|
|
2022-08-24 14:07:04 +08:00
|
|
|
public PlayerArea(int userId, SpectatorPlayerClock clock)
|
2021-04-08 21:07:00 +08:00
|
|
|
{
|
2021-04-16 11:25:29 +08:00
|
|
|
UserId = userId;
|
2022-08-24 15:43:26 +08:00
|
|
|
SpectatorPlayerClock = clock;
|
2021-04-08 21:13:54 +08:00
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2021-04-16 12:28:32 +08:00
|
|
|
|
2021-04-26 18:01:30 +08:00
|
|
|
AudioContainer audioContainer;
|
2021-04-16 12:28:32 +08:00
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2021-04-22 21:59:47 +08:00
|
|
|
audioContainer = new AudioContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Child = gameplayContent = new DrawSizePreservingFillContainer { RelativeSizeAxes = Axes.Both },
|
|
|
|
},
|
2021-04-16 12:28:32 +08:00
|
|
|
loadingLayer = new LoadingLayer(true) { State = { Value = Visibility.Visible } }
|
|
|
|
};
|
2021-04-26 16:30:27 +08:00
|
|
|
|
2021-04-26 18:01:30 +08:00
|
|
|
audioContainer.AddAdjustment(AdjustableProperty.Volume, volumeAdjustment);
|
2021-04-08 21:07:00 +08:00
|
|
|
}
|
|
|
|
|
2022-08-22 20:52:43 +08:00
|
|
|
public void LoadScore(Score score)
|
2021-04-08 21:07:00 +08:00
|
|
|
{
|
2021-04-16 12:28:32 +08:00
|
|
|
if (Score != null)
|
2021-04-22 22:52:22 +08:00
|
|
|
throw new InvalidOperationException($"Cannot load a new score on a {nameof(PlayerArea)} that has an existing score.");
|
2021-04-16 12:28:32 +08:00
|
|
|
|
2021-04-16 11:25:29 +08:00
|
|
|
Score = score;
|
2021-04-08 21:07:00 +08:00
|
|
|
|
2022-07-11 01:57:44 +08:00
|
|
|
gameplayContent.Child = new PlayerIsolationContainer(beatmap.Value, Score.ScoreInfo.Ruleset, Score.ScoreInfo.Mods)
|
2021-04-08 21:07:00 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-12-20 17:24:14 +08:00
|
|
|
Child = stack = new OsuScreenStack
|
|
|
|
{
|
|
|
|
Name = nameof(PlayerArea),
|
|
|
|
}
|
2021-04-08 21:07:00 +08:00
|
|
|
};
|
|
|
|
|
2021-08-11 17:16:25 +08:00
|
|
|
stack.Push(new MultiSpectatorPlayerLoader(Score, () =>
|
|
|
|
{
|
2022-08-24 15:43:26 +08:00
|
|
|
var player = new MultiSpectatorPlayer(Score, SpectatorPlayerClock);
|
2022-09-08 16:41:23 +08:00
|
|
|
player.OnGameplayStarted += () => OnGameplayStarted?.Invoke();
|
2022-09-08 15:59:20 +08:00
|
|
|
|
2022-09-08 16:41:23 +08:00
|
|
|
clockAdjustmentsFromMods.BindAdjustments(player.ClockAdjustmentsFromMods);
|
2022-09-08 15:59:20 +08:00
|
|
|
|
2021-08-11 17:16:25 +08:00
|
|
|
return player;
|
|
|
|
}));
|
|
|
|
|
2021-04-16 12:28:32 +08:00
|
|
|
loadingLayer.Hide();
|
2021-04-09 18:58:24 +08:00
|
|
|
}
|
2021-04-13 19:52:20 +08:00
|
|
|
|
2021-04-26 18:01:30 +08:00
|
|
|
private bool mute = true;
|
2021-04-22 21:59:47 +08:00
|
|
|
|
2021-04-26 18:01:30 +08:00
|
|
|
public bool Mute
|
2021-04-22 21:59:47 +08:00
|
|
|
{
|
2021-04-26 18:01:30 +08:00
|
|
|
get => mute;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
mute = value;
|
|
|
|
volumeAdjustment.Value = value ? 0 : 1;
|
|
|
|
}
|
2021-04-22 21:59:47 +08:00
|
|
|
}
|
|
|
|
|
2021-04-26 18:01:30 +08:00
|
|
|
// Player interferes with global input, so disable input for now.
|
|
|
|
public override bool PropagatePositionalInputSubTree => false;
|
|
|
|
public override bool PropagateNonPositionalInputSubTree => false;
|
2021-04-22 22:38:51 +08:00
|
|
|
|
2021-05-03 13:41:55 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Isolates each player instance from the game-wide ruleset/beatmap/mods (to allow for different players having different settings).
|
|
|
|
/// </summary>
|
2021-04-22 22:38:51 +08:00
|
|
|
private partial class PlayerIsolationContainer : Container
|
|
|
|
{
|
|
|
|
[Cached]
|
|
|
|
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
|
|
|
|
|
|
|
[Cached]
|
|
|
|
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
|
|
|
|
|
|
|
[Cached]
|
|
|
|
private readonly Bindable<IReadOnlyList<Mod>> mods = new Bindable<IReadOnlyList<Mod>>();
|
|
|
|
|
|
|
|
public PlayerIsolationContainer(WorkingBeatmap beatmap, RulesetInfo ruleset, IReadOnlyList<Mod> mods)
|
|
|
|
{
|
|
|
|
this.beatmap.Value = beatmap;
|
|
|
|
this.ruleset.Value = ruleset;
|
|
|
|
this.mods.Value = mods;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
|
|
|
{
|
|
|
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
|
|
|
dependencies.CacheAs(ruleset.BeginLease(false));
|
|
|
|
dependencies.CacheAs(beatmap.BeginLease(false));
|
|
|
|
dependencies.CacheAs(mods.BeginLease(false));
|
|
|
|
return dependencies;
|
|
|
|
}
|
|
|
|
}
|
2021-04-08 21:07:00 +08:00
|
|
|
}
|
|
|
|
}
|