2019-01-24 08:43:03 +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.
|
2018-05-16 00:14:10 +00:00
|
|
|
|
|
2021-07-20 06:44:32 +00:00
|
|
|
|
using System.Diagnostics;
|
2018-12-11 08:32:01 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2020-02-19 10:42:25 +00:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2018-05-16 00:14:10 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2020-12-29 07:47:36 +00:00
|
|
|
|
using osu.Framework.Logging;
|
2018-05-16 00:14:10 +00:00
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-12-26 07:46:50 +00:00
|
|
|
|
using osu.Game.Online.API;
|
2020-08-03 13:41:22 +00:00
|
|
|
|
using osu.Game.Overlays;
|
2018-05-28 03:28:11 +00:00
|
|
|
|
using osu.Game.Screens.Menu;
|
2020-12-25 15:50:00 +00:00
|
|
|
|
using osu.Game.Screens.OnlinePlay.Components;
|
|
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge;
|
2020-11-08 12:16:27 +00:00
|
|
|
|
using osu.Game.Users;
|
2018-05-16 00:14:10 +00:00
|
|
|
|
|
2020-12-25 15:50:00 +00:00
|
|
|
|
namespace osu.Game.Screens.OnlinePlay
|
2018-05-16 00:14:10 +00:00
|
|
|
|
{
|
2018-12-11 08:32:01 +00:00
|
|
|
|
[Cached]
|
2021-02-19 08:58:04 +00:00
|
|
|
|
public abstract class OnlinePlayScreen : OsuScreen, IHasSubScreenStack
|
2018-05-16 00:14:10 +00:00
|
|
|
|
{
|
2021-08-12 08:02:55 +00:00
|
|
|
|
[Cached]
|
|
|
|
|
protected readonly OverlayColourProvider ColourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);
|
|
|
|
|
|
2021-07-20 07:38:39 +00:00
|
|
|
|
public override bool CursorVisible => (screenStack?.CurrentScreen as IOnlinePlaySubScreen)?.CursorVisible ?? true;
|
2018-05-16 00:14:10 +00:00
|
|
|
|
|
2020-02-06 05:22:01 +00:00
|
|
|
|
// this is required due to PlayerLoader eventually being pushed to the main stack
|
|
|
|
|
// while leases may be taken out by a subscreen.
|
2019-02-12 02:19:34 +00:00
|
|
|
|
public override bool DisallowExternalBeatmapRulesetChanges => true;
|
2019-01-25 11:25:55 +00:00
|
|
|
|
|
2021-07-20 07:38:39 +00:00
|
|
|
|
private MultiplayerWaveContainer waves;
|
|
|
|
|
private LoungeSubScreen loungeSubScreen;
|
2021-08-03 11:02:31 +00:00
|
|
|
|
private ScreenStack screenStack;
|
2018-12-14 08:35:18 +00:00
|
|
|
|
|
2020-12-18 15:15:41 +00:00
|
|
|
|
[Cached(Type = typeof(IRoomManager))]
|
2020-12-20 08:42:23 +00:00
|
|
|
|
protected RoomManager RoomManager { get; private set; }
|
2020-12-18 15:15:41 +00:00
|
|
|
|
|
2020-12-28 20:39:11 +00:00
|
|
|
|
[Cached]
|
2021-07-20 07:38:39 +00:00
|
|
|
|
private readonly OngoingOperationTracker ongoingOperationTracker = new OngoingOperationTracker();
|
2020-12-28 20:39:11 +00:00
|
|
|
|
|
2018-12-26 07:46:50 +00:00
|
|
|
|
[Resolved]
|
2020-12-24 12:59:10 +00:00
|
|
|
|
protected IAPIProvider API { get; private set; }
|
2018-12-26 07:46:50 +00:00
|
|
|
|
|
2020-12-25 16:00:00 +00:00
|
|
|
|
protected OnlinePlayScreen()
|
2018-05-16 00:14:10 +00:00
|
|
|
|
{
|
2019-01-25 11:47:31 +00:00
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
2019-01-25 11:25:55 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2019-02-12 04:02:33 +00:00
|
|
|
|
Padding = new MarginPadding { Horizontal = -HORIZONTAL_OVERFLOW_PADDING };
|
2019-01-25 11:25:55 +00:00
|
|
|
|
|
2021-07-20 07:38:39 +00:00
|
|
|
|
RoomManager = CreateRoomManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2019-01-23 11:52:00 +00:00
|
|
|
|
InternalChild = waves = new MultiplayerWaveContainer
|
2018-05-16 00:14:10 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-12-20 08:42:23 +00:00
|
|
|
|
Children = new Drawable[]
|
2018-05-16 00:14:10 +00:00
|
|
|
|
{
|
2021-08-20 08:02:55 +00:00
|
|
|
|
screenStack = new OnlinePlaySubScreenStack { RelativeSizeAxes = Axes.Both },
|
2020-12-24 15:18:35 +00:00
|
|
|
|
new Header(ScreenTitle, screenStack),
|
2021-08-03 11:38:50 +00:00
|
|
|
|
RoomManager,
|
2021-08-03 11:02:31 +00:00
|
|
|
|
ongoingOperationTracker
|
2019-02-12 04:02:33 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
2018-12-27 11:06:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 05:19:12 +00:00
|
|
|
|
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
if (state.NewValue != APIState.Online)
|
2020-12-29 07:47:36 +00:00
|
|
|
|
{
|
|
|
|
|
Logger.Log("API connection was lost, can't continue with online play", LoggingTarget.Network, LogLevel.Important);
|
2020-10-22 05:19:12 +00:00
|
|
|
|
Schedule(forcefullyExit);
|
2020-12-29 07:47:36 +00:00
|
|
|
|
}
|
2020-10-22 05:19:12 +00:00
|
|
|
|
});
|
|
|
|
|
|
2018-12-27 11:06:07 +00:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2021-07-20 07:38:39 +00:00
|
|
|
|
|
|
|
|
|
screenStack.ScreenPushed += screenPushed;
|
|
|
|
|
screenStack.ScreenExited += screenExited;
|
|
|
|
|
|
2021-07-22 05:33:05 +00:00
|
|
|
|
screenStack.Push(loungeSubScreen = CreateLounge());
|
2021-07-20 07:38:39 +00:00
|
|
|
|
|
|
|
|
|
apiState.BindTo(API.State);
|
|
|
|
|
apiState.BindValueChanged(onlineStateChanged, true);
|
2018-12-27 11:06:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-27 08:12:47 +00:00
|
|
|
|
private void forcefullyExit()
|
|
|
|
|
{
|
2021-12-21 06:07:06 +00:00
|
|
|
|
Logger.Log($"{this} forcefully exiting due to loss of API connection");
|
|
|
|
|
|
2018-12-27 08:12:47 +00:00
|
|
|
|
// This is temporary since we don't currently have a way to force screens to be exited
|
2019-01-23 11:52:00 +00:00
|
|
|
|
if (this.IsCurrentScreen())
|
2019-10-31 04:42:11 +00:00
|
|
|
|
{
|
|
|
|
|
while (this.IsCurrentScreen())
|
|
|
|
|
this.Exit();
|
|
|
|
|
}
|
2018-12-27 08:12:47 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2019-01-23 11:52:00 +00:00
|
|
|
|
this.MakeCurrent();
|
2018-12-27 08:12:47 +00:00
|
|
|
|
Schedule(forcefullyExit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-11 10:11:34 +00:00
|
|
|
|
public override void OnEntering(IScreen last)
|
2018-05-16 00:14:10 +00:00
|
|
|
|
{
|
2019-01-23 11:52:00 +00:00
|
|
|
|
this.FadeIn();
|
2018-05-16 00:14:10 +00:00
|
|
|
|
waves.Show();
|
2020-12-24 14:07:03 +00:00
|
|
|
|
|
|
|
|
|
if (loungeSubScreen.IsCurrentScreen())
|
|
|
|
|
loungeSubScreen.OnEntering(last);
|
|
|
|
|
else
|
|
|
|
|
loungeSubScreen.MakeCurrent();
|
2019-06-19 04:15:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnResuming(IScreen last)
|
|
|
|
|
{
|
|
|
|
|
this.FadeIn(250);
|
|
|
|
|
this.ScaleTo(1, 250, Easing.OutSine);
|
|
|
|
|
|
2021-07-20 06:44:32 +00:00
|
|
|
|
Debug.Assert(screenStack.CurrentScreen != null);
|
|
|
|
|
screenStack.CurrentScreen.OnResuming(last);
|
|
|
|
|
|
2019-06-19 04:15:58 +00:00
|
|
|
|
base.OnResuming(last);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnSuspending(IScreen next)
|
|
|
|
|
{
|
|
|
|
|
this.ScaleTo(1.1f, 250, Easing.InSine);
|
|
|
|
|
this.FadeOut(250);
|
|
|
|
|
|
2021-07-20 06:44:32 +00:00
|
|
|
|
Debug.Assert(screenStack.CurrentScreen != null);
|
|
|
|
|
screenStack.CurrentScreen.OnSuspending(next);
|
2018-05-16 00:14:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-11 10:11:34 +00:00
|
|
|
|
public override bool OnExiting(IScreen next)
|
2018-05-16 00:14:10 +00:00
|
|
|
|
{
|
2021-07-20 06:44:32 +00:00
|
|
|
|
var subScreen = screenStack.CurrentScreen as Drawable;
|
|
|
|
|
if (subScreen?.IsLoaded == true && screenStack.CurrentScreen.OnExiting(next))
|
2021-06-22 03:20:43 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
2020-12-18 15:15:41 +00:00
|
|
|
|
RoomManager.PartRoom();
|
2019-10-30 05:42:14 +00:00
|
|
|
|
|
2018-05-16 00:14:10 +00:00
|
|
|
|
waves.Hide();
|
2018-12-18 08:07:47 +00:00
|
|
|
|
|
2019-01-23 11:52:00 +00:00
|
|
|
|
this.Delay(WaveContainer.DISAPPEAR_DURATION).FadeOut();
|
2018-12-26 11:05:57 +00:00
|
|
|
|
|
2019-02-12 04:29:41 +00:00
|
|
|
|
base.OnExiting(next);
|
2019-01-25 11:25:55 +00:00
|
|
|
|
return false;
|
2018-05-16 00:14:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-14 07:02:01 +00:00
|
|
|
|
public override bool OnBackButton()
|
|
|
|
|
{
|
2021-06-08 08:54:54 +00:00
|
|
|
|
if (!(screenStack.CurrentScreen is IOnlinePlaySubScreen onlineSubScreen))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (((Drawable)onlineSubScreen).IsLoaded && onlineSubScreen.AllowBackButton && onlineSubScreen.OnBackButton())
|
2020-07-14 07:29:57 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
2020-07-14 07:02:01 +00:00
|
|
|
|
if (screenStack.CurrentScreen != null && !(screenStack.CurrentScreen is LoungeSubScreen))
|
|
|
|
|
{
|
|
|
|
|
screenStack.Exit();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-12 04:29:41 +00:00
|
|
|
|
protected override void LogoExiting(OsuLogo logo)
|
|
|
|
|
{
|
|
|
|
|
base.LogoExiting(logo);
|
|
|
|
|
|
|
|
|
|
// the wave overlay transition takes longer than expected to run.
|
|
|
|
|
logo.Delay(WaveContainer.DISAPPEAR_DURATION / 2).FadeOut();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-19 10:42:25 +00:00
|
|
|
|
private void screenPushed(IScreen lastScreen, IScreen newScreen)
|
|
|
|
|
{
|
2020-11-08 12:16:27 +00:00
|
|
|
|
subScreenChanged(lastScreen, newScreen);
|
2020-02-19 10:42:25 +00:00
|
|
|
|
}
|
2019-06-19 04:15:58 +00:00
|
|
|
|
|
|
|
|
|
private void screenExited(IScreen lastScreen, IScreen newScreen)
|
2018-05-16 00:14:10 +00:00
|
|
|
|
{
|
2020-11-08 12:16:27 +00:00
|
|
|
|
subScreenChanged(lastScreen, newScreen);
|
2018-12-11 08:32:01 +00:00
|
|
|
|
|
2019-06-19 04:15:58 +00:00
|
|
|
|
if (screenStack.CurrentScreen == null && this.IsCurrentScreen())
|
|
|
|
|
this.Exit();
|
2018-05-16 00:14:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-08 12:16:27 +00:00
|
|
|
|
private void subScreenChanged(IScreen lastScreen, IScreen newScreen)
|
2018-12-26 13:37:09 +00:00
|
|
|
|
{
|
2020-11-08 12:16:27 +00:00
|
|
|
|
if (lastScreen is IOsuScreen lastOsuScreen)
|
|
|
|
|
Activity.UnbindFrom(lastOsuScreen.Activity);
|
|
|
|
|
|
|
|
|
|
if (newScreen is IOsuScreen newOsuScreen)
|
|
|
|
|
((IBindable<UserActivity>)Activity).BindTo(newOsuScreen.Activity);
|
2018-12-26 13:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 06:44:48 +00:00
|
|
|
|
public IScreen CurrentSubScreen => screenStack.CurrentScreen;
|
2020-12-18 15:15:41 +00:00
|
|
|
|
|
2020-12-24 15:18:35 +00:00
|
|
|
|
protected abstract string ScreenTitle { get; }
|
|
|
|
|
|
2021-08-13 08:39:09 +00:00
|
|
|
|
protected virtual RoomManager CreateRoomManager() => new RoomManager();
|
2020-12-18 15:15:41 +00:00
|
|
|
|
|
2020-12-20 14:36:56 +00:00
|
|
|
|
protected abstract LoungeSubScreen CreateLounge();
|
|
|
|
|
|
2018-05-16 00:14:10 +00:00
|
|
|
|
private class MultiplayerWaveContainer : WaveContainer
|
|
|
|
|
{
|
|
|
|
|
protected override bool StartHidden => true;
|
|
|
|
|
|
|
|
|
|
public MultiplayerWaveContainer()
|
|
|
|
|
{
|
2020-03-11 01:18:41 +00:00
|
|
|
|
FirstWaveColour = Color4Extensions.FromHex(@"654d8c");
|
|
|
|
|
SecondWaveColour = Color4Extensions.FromHex(@"554075");
|
|
|
|
|
ThirdWaveColour = Color4Extensions.FromHex(@"44325e");
|
|
|
|
|
FourthWaveColour = Color4Extensions.FromHex(@"392850");
|
2018-05-16 00:14:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-19 10:42:25 +00:00
|
|
|
|
|
2021-02-19 08:58:04 +00:00
|
|
|
|
ScreenStack IHasSubScreenStack.SubScreenStack => screenStack;
|
2018-05-16 00:14:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|