2019-01-24 17:43:03 +09: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-15 21:14:10 -03:00
|
|
|
|
|
2021-07-20 15:44:32 +09:00
|
|
|
|
using System.Diagnostics;
|
2018-12-11 17:32:01 +09:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 19:04:31 +09:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-05-15 21:14:10 -03:00
|
|
|
|
using osu.Framework.Graphics;
|
2020-12-29 16:47:36 +09:00
|
|
|
|
using osu.Framework.Logging;
|
2018-05-15 21:14:10 -03:00
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-12-26 16:46:50 +09:00
|
|
|
|
using osu.Game.Online.API;
|
2020-08-03 22:41:22 +09:00
|
|
|
|
using osu.Game.Overlays;
|
2018-05-28 12:28:11 +09:00
|
|
|
|
using osu.Game.Screens.Menu;
|
2020-12-25 16:50:00 +01:00
|
|
|
|
using osu.Game.Screens.OnlinePlay.Components;
|
|
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge;
|
2020-11-08 13:16:27 +01:00
|
|
|
|
using osu.Game.Users;
|
2018-05-15 21:14:10 -03:00
|
|
|
|
|
2020-12-25 16:50:00 +01:00
|
|
|
|
namespace osu.Game.Screens.OnlinePlay
|
2018-05-15 21:14:10 -03:00
|
|
|
|
{
|
2018-12-11 17:32:01 +09:00
|
|
|
|
[Cached]
|
2021-02-19 17:58:04 +09:00
|
|
|
|
public abstract partial class OnlinePlayScreen : OsuScreen, IHasSubScreenStack
|
2018-05-15 21:14:10 -03:00
|
|
|
|
{
|
2021-08-12 17:02:55 +09:00
|
|
|
|
[Cached]
|
|
|
|
|
protected readonly OverlayColourProvider ColourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);
|
|
|
|
|
|
2023-10-12 17:42:02 +09:00
|
|
|
|
public IScreen CurrentSubScreen => screenStack.CurrentScreen;
|
|
|
|
|
|
2024-11-21 20:26:44 +09:00
|
|
|
|
public override bool CursorVisible => (screenStack.CurrentScreen as IOnlinePlaySubScreen)?.CursorVisible ?? true;
|
2018-05-15 21:14:10 -03:00
|
|
|
|
|
2020-02-06 14:22:01 +09: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 11:19:34 +09:00
|
|
|
|
public override bool DisallowExternalBeatmapRulesetChanges => true;
|
2019-01-25 20:25:55 +09:00
|
|
|
|
|
2024-11-21 20:26:44 +09:00
|
|
|
|
protected LoungeSubScreen Lounge { get; private set; } = null!;
|
2023-10-03 01:31:30 +02:00
|
|
|
|
|
2024-11-21 20:52:34 +09:00
|
|
|
|
private readonly ScreenStack screenStack = new OnlinePlaySubScreenStack { RelativeSizeAxes = Axes.Both };
|
2024-11-21 20:26:44 +09:00
|
|
|
|
private OnlinePlayScreenWaveContainer waves = null!;
|
2018-12-14 17:35:18 +09:00
|
|
|
|
|
2020-12-19 00:15:41 +09:00
|
|
|
|
[Cached(Type = typeof(IRoomManager))]
|
2020-12-20 17:42:23 +09:00
|
|
|
|
protected RoomManager RoomManager { get; private set; }
|
2020-12-19 00:15:41 +09:00
|
|
|
|
|
2020-12-28 21:39:11 +01:00
|
|
|
|
[Cached]
|
2021-07-20 16:38:39 +09:00
|
|
|
|
private readonly OngoingOperationTracker ongoingOperationTracker = new OngoingOperationTracker();
|
2020-12-28 21:39:11 +01:00
|
|
|
|
|
2018-12-26 16:46:50 +09:00
|
|
|
|
[Resolved]
|
2024-11-21 20:26:44 +09:00
|
|
|
|
protected IAPIProvider API { get; private set; } = null!;
|
2018-12-26 16:46:50 +09:00
|
|
|
|
|
2020-12-25 17:00:00 +01:00
|
|
|
|
protected OnlinePlayScreen()
|
2018-05-15 21:14:10 -03:00
|
|
|
|
{
|
2019-01-25 20:47:31 +09:00
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
2019-01-25 20:25:55 +09:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2019-02-12 13:02:33 +09:00
|
|
|
|
Padding = new MarginPadding { Horizontal = -HORIZONTAL_OVERFLOW_PADDING };
|
2019-01-25 20:25:55 +09:00
|
|
|
|
|
2021-07-20 16:38:39 +09:00
|
|
|
|
RoomManager = CreateRoomManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2024-05-30 11:51:09 +02:00
|
|
|
|
InternalChild = waves = new OnlinePlayScreenWaveContainer
|
2018-05-15 21:14:10 -03:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-12-20 17:42:23 +09:00
|
|
|
|
Children = new Drawable[]
|
2018-05-15 21:14:10 -03:00
|
|
|
|
{
|
2024-11-21 20:52:34 +09:00
|
|
|
|
screenStack,
|
2020-12-24 16:18:35 +01:00
|
|
|
|
new Header(ScreenTitle, screenStack),
|
2021-08-03 20:38:50 +09:00
|
|
|
|
RoomManager,
|
2023-11-21 14:39:33 +09:00
|
|
|
|
ongoingOperationTracker,
|
2019-02-12 13:02:33 +09:00
|
|
|
|
}
|
|
|
|
|
};
|
2018-12-27 20:06:07 +09:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 14:19:12 +09:00
|
|
|
|
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
if (state.NewValue != APIState.Online)
|
|
|
|
|
Schedule(forcefullyExit);
|
|
|
|
|
});
|
|
|
|
|
|
2018-12-27 20:06:07 +09:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2021-07-20 16:38:39 +09:00
|
|
|
|
|
|
|
|
|
screenStack.ScreenPushed += screenPushed;
|
|
|
|
|
screenStack.ScreenExited += screenExited;
|
|
|
|
|
|
2023-10-04 08:37:22 +02:00
|
|
|
|
screenStack.Push(Lounge = CreateLounge());
|
2021-07-20 16:38:39 +09:00
|
|
|
|
|
|
|
|
|
apiState.BindTo(API.State);
|
|
|
|
|
apiState.BindValueChanged(onlineStateChanged, true);
|
2018-12-27 20:06:07 +09:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-27 17:12:47 +09:00
|
|
|
|
private void forcefullyExit()
|
|
|
|
|
{
|
2021-12-21 15:07:06 +09:00
|
|
|
|
Logger.Log($"{this} forcefully exiting due to loss of API connection");
|
|
|
|
|
|
2018-12-27 17:12:47 +09:00
|
|
|
|
// This is temporary since we don't currently have a way to force screens to be exited
|
2024-07-24 09:15:32 +02:00
|
|
|
|
// See also: `DailyChallenge.forcefullyExit()`
|
2019-01-23 20:52:00 +09:00
|
|
|
|
if (this.IsCurrentScreen())
|
2019-10-31 13:42:11 +09:00
|
|
|
|
{
|
|
|
|
|
while (this.IsCurrentScreen())
|
|
|
|
|
this.Exit();
|
|
|
|
|
}
|
2022-09-27 17:52:29 +09:00
|
|
|
|
// Also handle the case where a child screen is current (ie. gameplay).
|
|
|
|
|
else if (this.GetChildScreen() != null)
|
2018-12-27 17:12:47 +09:00
|
|
|
|
{
|
2019-01-23 20:52:00 +09:00
|
|
|
|
this.MakeCurrent();
|
2018-12-27 17:12:47 +09:00
|
|
|
|
Schedule(forcefullyExit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 00:52:44 +09:00
|
|
|
|
public override void OnEntering(ScreenTransitionEvent e)
|
2018-05-15 21:14:10 -03:00
|
|
|
|
{
|
2019-01-23 20:52:00 +09:00
|
|
|
|
this.FadeIn();
|
2018-05-15 21:14:10 -03:00
|
|
|
|
waves.Show();
|
2020-12-24 15:07:03 +01:00
|
|
|
|
|
2022-03-21 22:42:17 -04:00
|
|
|
|
Mods.SetDefault();
|
|
|
|
|
|
2023-10-04 08:37:22 +02:00
|
|
|
|
if (Lounge.IsCurrentScreen())
|
|
|
|
|
Lounge.OnEntering(e);
|
2020-12-24 15:07:03 +01:00
|
|
|
|
else
|
2023-10-04 08:37:22 +02:00
|
|
|
|
Lounge.MakeCurrent();
|
2019-06-19 13:15:58 +09:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 00:52:44 +09:00
|
|
|
|
public override void OnResuming(ScreenTransitionEvent e)
|
2019-06-19 13:15:58 +09:00
|
|
|
|
{
|
|
|
|
|
this.FadeIn(250);
|
|
|
|
|
this.ScaleTo(1, 250, Easing.OutSine);
|
|
|
|
|
|
2021-07-20 15:44:32 +09:00
|
|
|
|
Debug.Assert(screenStack.CurrentScreen != null);
|
2023-05-25 20:39:11 +09:00
|
|
|
|
|
2023-05-30 21:54:56 +02:00
|
|
|
|
// if a subscreen was pushed to the nested stack while the stack was not present, this path will proxy `OnResuming()`
|
2023-05-30 18:38:28 +09:00
|
|
|
|
// to the subscreen before `OnEntering()` can even be called for the subscreen, breaking ordering expectations.
|
|
|
|
|
// to work around this, do not proxy resume to screens that haven't loaded yet.
|
|
|
|
|
if ((screenStack.CurrentScreen as Drawable)?.IsLoaded == true)
|
2023-05-25 20:39:11 +09:00
|
|
|
|
screenStack.CurrentScreen.OnResuming(e);
|
2021-07-20 15:44:32 +09:00
|
|
|
|
|
2022-04-22 00:52:44 +09:00
|
|
|
|
base.OnResuming(e);
|
2019-06-19 13:15:58 +09:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 00:52:44 +09:00
|
|
|
|
public override void OnSuspending(ScreenTransitionEvent e)
|
2019-06-19 13:15:58 +09:00
|
|
|
|
{
|
|
|
|
|
this.ScaleTo(1.1f, 250, Easing.InSine);
|
|
|
|
|
this.FadeOut(250);
|
|
|
|
|
|
2021-07-20 15:44:32 +09:00
|
|
|
|
Debug.Assert(screenStack.CurrentScreen != null);
|
2023-05-25 20:39:11 +09:00
|
|
|
|
|
2023-05-30 21:54:56 +02:00
|
|
|
|
// if a subscreen was pushed to the nested stack while the stack was not present, this path will proxy `OnSuspending()`
|
|
|
|
|
// to the subscreen before `OnEntering()` can even be called for the subscreen, breaking ordering expectations.
|
|
|
|
|
// to work around this, do not proxy suspend to screens that haven't loaded yet.
|
|
|
|
|
if ((screenStack.CurrentScreen as Drawable)?.IsLoaded == true)
|
2023-05-25 20:39:11 +09:00
|
|
|
|
screenStack.CurrentScreen.OnSuspending(e);
|
2018-05-15 21:14:10 -03:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 00:52:44 +09:00
|
|
|
|
public override bool OnExiting(ScreenExitEvent e)
|
2018-05-15 21:14:10 -03:00
|
|
|
|
{
|
2023-10-04 08:37:22 +02:00
|
|
|
|
while (screenStack.CurrentScreen != null && screenStack.CurrentScreen is not LoungeSubScreen)
|
2022-08-01 07:52:07 -07:00
|
|
|
|
{
|
2022-12-25 21:56:22 -08:00
|
|
|
|
var subScreen = (Screen)screenStack.CurrentScreen;
|
|
|
|
|
if (subScreen.IsLoaded && subScreen.OnExiting(e))
|
2022-12-24 20:04:45 -08:00
|
|
|
|
return true;
|
2022-08-01 07:52:07 -07:00
|
|
|
|
|
2022-12-25 21:56:22 -08:00
|
|
|
|
subScreen.Exit();
|
2022-08-01 07:52:07 -07:00
|
|
|
|
}
|
2021-06-21 20:20:43 -07:00
|
|
|
|
|
2020-12-19 00:15:41 +09:00
|
|
|
|
RoomManager.PartRoom();
|
2019-10-30 14:42:14 +09:00
|
|
|
|
|
2018-05-15 21:14:10 -03:00
|
|
|
|
waves.Hide();
|
2018-12-18 17:07:47 +09:00
|
|
|
|
|
2019-01-23 20:52:00 +09:00
|
|
|
|
this.Delay(WaveContainer.DISAPPEAR_DURATION).FadeOut();
|
2018-12-26 20:05:57 +09:00
|
|
|
|
|
2022-04-22 00:52:44 +09:00
|
|
|
|
base.OnExiting(e);
|
2019-01-25 20:25:55 +09:00
|
|
|
|
return false;
|
2018-05-15 21:14:10 -03:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-14 00:02:01 -07:00
|
|
|
|
public override bool OnBackButton()
|
|
|
|
|
{
|
2021-06-08 17:54:54 +09:00
|
|
|
|
if (!(screenStack.CurrentScreen is IOnlinePlaySubScreen onlineSubScreen))
|
|
|
|
|
return false;
|
|
|
|
|
|
2024-11-26 16:50:23 -05:00
|
|
|
|
if (((Drawable)onlineSubScreen).IsLoaded && onlineSubScreen.AllowUserExit && onlineSubScreen.OnBackButton())
|
2020-07-14 00:29:57 -07:00
|
|
|
|
return true;
|
|
|
|
|
|
2020-07-14 00:02:01 -07:00
|
|
|
|
if (screenStack.CurrentScreen != null && !(screenStack.CurrentScreen is LoungeSubScreen))
|
|
|
|
|
{
|
|
|
|
|
screenStack.Exit();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-12 13:29:41 +09: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 19:42:25 +09:00
|
|
|
|
private void screenPushed(IScreen lastScreen, IScreen newScreen)
|
|
|
|
|
{
|
2020-11-08 13:16:27 +01:00
|
|
|
|
subScreenChanged(lastScreen, newScreen);
|
2020-02-19 19:42:25 +09:00
|
|
|
|
}
|
2019-06-19 13:15:58 +09:00
|
|
|
|
|
|
|
|
|
private void screenExited(IScreen lastScreen, IScreen newScreen)
|
2018-05-15 21:14:10 -03:00
|
|
|
|
{
|
2020-11-08 13:16:27 +01:00
|
|
|
|
subScreenChanged(lastScreen, newScreen);
|
2018-12-11 17:32:01 +09:00
|
|
|
|
|
2019-06-19 13:15:58 +09:00
|
|
|
|
if (screenStack.CurrentScreen == null && this.IsCurrentScreen())
|
|
|
|
|
this.Exit();
|
2018-05-15 21:14:10 -03:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-08 13:16:27 +01:00
|
|
|
|
private void subScreenChanged(IScreen lastScreen, IScreen newScreen)
|
2018-12-26 22:37:09 +09:00
|
|
|
|
{
|
2020-11-08 13:16:27 +01:00
|
|
|
|
if (lastScreen is IOsuScreen lastOsuScreen)
|
|
|
|
|
Activity.UnbindFrom(lastOsuScreen.Activity);
|
|
|
|
|
|
|
|
|
|
if (newScreen is IOsuScreen newOsuScreen)
|
|
|
|
|
((IBindable<UserActivity>)Activity).BindTo(newOsuScreen.Activity);
|
2018-12-26 22:37:09 +09:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-24 16:18:35 +01:00
|
|
|
|
protected abstract string ScreenTitle { get; }
|
|
|
|
|
|
2021-08-13 17:39:09 +09:00
|
|
|
|
protected virtual RoomManager CreateRoomManager() => new RoomManager();
|
2020-12-19 00:15:41 +09:00
|
|
|
|
|
2020-12-20 23:36:56 +09:00
|
|
|
|
protected abstract LoungeSubScreen CreateLounge();
|
|
|
|
|
|
2021-02-19 17:58:04 +09:00
|
|
|
|
ScreenStack IHasSubScreenStack.SubScreenStack => screenStack;
|
2018-05-15 21:14:10 -03:00
|
|
|
|
}
|
|
|
|
|
}
|