-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathOnlinePlayScreen.cs
235 lines (182 loc) · 7.98 KB
/
OnlinePlayScreen.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// 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.
#nullable disable
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Logging;
using osu.Framework.Screens;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Overlays;
using osu.Game.Screens.Menu;
using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Screens.OnlinePlay.Lounge;
using osu.Game.Users;
namespace osu.Game.Screens.OnlinePlay
{
[Cached]
public abstract partial class OnlinePlayScreen : OsuScreen, IHasSubScreenStack
{
[Cached]
protected readonly OverlayColourProvider ColourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);
public IScreen CurrentSubScreen => screenStack.CurrentScreen;
public override bool CursorVisible => (screenStack?.CurrentScreen as IOnlinePlaySubScreen)?.CursorVisible ?? true;
// this is required due to PlayerLoader eventually being pushed to the main stack
// while leases may be taken out by a subscreen.
public override bool DisallowExternalBeatmapRulesetChanges => true;
protected LoungeSubScreen Lounge { get; private set; }
private OnlinePlayScreenWaveContainer waves;
private ScreenStack screenStack;
[Cached(Type = typeof(IRoomManager))]
protected RoomManager RoomManager { get; private set; }
[Cached]
private readonly OngoingOperationTracker ongoingOperationTracker = new OngoingOperationTracker();
[Resolved]
protected IAPIProvider API { get; private set; }
protected OnlinePlayScreen()
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
RelativeSizeAxes = Axes.Both;
Padding = new MarginPadding { Horizontal = -HORIZONTAL_OVERFLOW_PADDING };
RoomManager = CreateRoomManager();
}
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[BackgroundDependencyLoader]
private void load()
{
InternalChild = waves = new OnlinePlayScreenWaveContainer
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
screenStack = new OnlinePlaySubScreenStack { RelativeSizeAxes = Axes.Both },
new Header(ScreenTitle, screenStack),
RoomManager,
ongoingOperationTracker,
}
};
}
private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{
if (state.NewValue != APIState.Online)
Schedule(forcefullyExit);
});
protected override void LoadComplete()
{
base.LoadComplete();
screenStack.ScreenPushed += screenPushed;
screenStack.ScreenExited += screenExited;
screenStack.Push(Lounge = CreateLounge());
apiState.BindTo(API.State);
apiState.BindValueChanged(onlineStateChanged, true);
}
private void forcefullyExit()
{
Logger.Log($"{this} forcefully exiting due to loss of API connection");
// This is temporary since we don't currently have a way to force screens to be exited
// See also: `DailyChallenge.forcefullyExit()`
if (this.IsCurrentScreen())
{
while (this.IsCurrentScreen())
this.Exit();
}
// Also handle the case where a child screen is current (ie. gameplay).
else if (this.GetChildScreen() != null)
{
this.MakeCurrent();
Schedule(forcefullyExit);
}
}
public override void OnEntering(ScreenTransitionEvent e)
{
this.FadeIn();
waves.Show();
Mods.SetDefault();
if (Lounge.IsCurrentScreen())
Lounge.OnEntering(e);
else
Lounge.MakeCurrent();
}
public override void OnResuming(ScreenTransitionEvent e)
{
this.FadeIn(250);
this.ScaleTo(1, 250, Easing.OutSine);
Debug.Assert(screenStack.CurrentScreen != null);
// if a subscreen was pushed to the nested stack while the stack was not present, this path will proxy `OnResuming()`
// 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)
screenStack.CurrentScreen.OnResuming(e);
base.OnResuming(e);
}
public override void OnSuspending(ScreenTransitionEvent e)
{
this.ScaleTo(1.1f, 250, Easing.InSine);
this.FadeOut(250);
Debug.Assert(screenStack.CurrentScreen != null);
// 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)
screenStack.CurrentScreen.OnSuspending(e);
}
public override bool OnExiting(ScreenExitEvent e)
{
while (screenStack.CurrentScreen != null && screenStack.CurrentScreen is not LoungeSubScreen)
{
var subScreen = (Screen)screenStack.CurrentScreen;
if (subScreen.IsLoaded && subScreen.OnExiting(e))
return true;
subScreen.Exit();
}
RoomManager.PartRoom();
waves.Hide();
this.Delay(WaveContainer.DISAPPEAR_DURATION).FadeOut();
base.OnExiting(e);
return false;
}
public override bool OnBackButton()
{
if (!(screenStack.CurrentScreen is IOnlinePlaySubScreen onlineSubScreen))
return false;
if (((Drawable)onlineSubScreen).IsLoaded && onlineSubScreen.AllowBackButton && onlineSubScreen.OnBackButton())
return true;
if (screenStack.CurrentScreen != null && !(screenStack.CurrentScreen is LoungeSubScreen))
{
screenStack.Exit();
return true;
}
return false;
}
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();
}
private void screenPushed(IScreen lastScreen, IScreen newScreen)
{
subScreenChanged(lastScreen, newScreen);
}
private void screenExited(IScreen lastScreen, IScreen newScreen)
{
subScreenChanged(lastScreen, newScreen);
if (screenStack.CurrentScreen == null && this.IsCurrentScreen())
this.Exit();
}
private void subScreenChanged(IScreen lastScreen, IScreen newScreen)
{
if (lastScreen is IOsuScreen lastOsuScreen)
Activity.UnbindFrom(lastOsuScreen.Activity);
if (newScreen is IOsuScreen newOsuScreen)
((IBindable<UserActivity>)Activity).BindTo(newOsuScreen.Activity);
}
protected abstract string ScreenTitle { get; }
protected virtual RoomManager CreateRoomManager() => new RoomManager();
protected abstract LoungeSubScreen CreateLounge();
ScreenStack IHasSubScreenStack.SubScreenStack => screenStack;
}
}