-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathMainMenu.cs
More file actions
510 lines (414 loc) · 18 KB
/
Copy pathMainMenu.cs
File metadata and controls
510 lines (414 loc) · 18 KB
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
// 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;
using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Framework.Screens;
using osu.Framework.Threading;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Input.Bindings;
using osu.Game.IO;
using osu.Game.Localisation;
using osu.Game.Online.API;
using osu.Game.Online.Matchmaking;
using osu.Game.Overlays;
using osu.Game.Overlays.Dialog;
using osu.Game.Overlays.SkinEditor;
using osu.Game.Rulesets;
using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Edit;
using osu.Game.Screens.OnlinePlay.DailyChallenge;
using osu.Game.Screens.OnlinePlay.Multiplayer;
using osu.Game.Screens.OnlinePlay.Playlists;
using osu.Game.Screens.Select;
using osu.Game.Seasonal;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Menu
{
public partial class MainMenu : OsuScreen, IHandlePresentBeatmap, IKeyBindingHandler<GlobalAction>, ISamplePlaybackDisabler
{
public const float FADE_IN_DURATION = 300;
public const float FADE_OUT_DURATION = 400;
public override bool HideOverlaysOnEnter => Buttons == null || Buttons.State == ButtonSystemState.Initial;
public override bool AllowUserExit => false;
public override bool AllowExternalScreenChange => true;
public override bool? AllowGlobalTrackControl => true;
private MenuSideFlashes sideFlashes;
protected ButtonSystem Buttons;
[Resolved]
private GameHost host { get; set; }
[Resolved]
private INotificationOverlay notifications { get; set; }
[Resolved]
private MusicController musicController { get; set; }
[Resolved]
private IAPIProvider api { get; set; }
[Resolved]
private Storage storage { get; set; }
[Resolved(canBeNull: true)]
private LoginOverlay login { get; set; }
[Resolved(canBeNull: true)]
private IDialogOverlay dialogOverlay { get; set; }
// used to stop kiai fountain samples when navigating to other screens
IBindable<bool> ISamplePlaybackDisabler.SamplePlaybackDisabled => samplePlaybackDisabled;
private readonly Bindable<bool> samplePlaybackDisabled = new Bindable<bool>();
protected override BackgroundScreen CreateBackground() => new BackgroundScreenDefault();
protected override bool PlayExitSound => false;
private Bindable<double> holdDelay;
private Bindable<bool> loginDisplayed;
private Bindable<bool> showMobileDisclaimer;
private HoldToExitGameOverlay holdToExitGameOverlay;
private bool exitConfirmedViaDialog;
private bool exitConfirmedViaHoldOrClick;
private ParallaxContainer buttonsContainer;
private SongTicker songTicker;
private Container logoTarget;
private OnlineMenuBanner onlineMenuBanner;
private MenuTipDisplay menuTipDisplay;
private FillFlowContainer bottomElementsFlow;
private SupporterDisplay supporterDisplay;
private Sample reappearSampleSwoosh;
[Resolved(canBeNull: true)]
private SkinEditorOverlay skinEditor { get; set; }
[CanBeNull]
private IDisposable logoProxy;
[BackgroundDependencyLoader(true)]
private void load(BeatmapListingOverlay beatmapListing, SettingsOverlay settings, OsuConfigManager config, SessionStatics statics, AudioManager audio)
{
holdDelay = config.GetBindable<double>(OsuSetting.UIHoldActivationDelay);
loginDisplayed = statics.GetBindable<bool>(Static.LoginOverlayDisplayed);
showMobileDisclaimer = config.GetBindable<bool>(OsuSetting.ShowMobileDisclaimer);
if (host.CanExit)
{
AddInternal(holdToExitGameOverlay = new HoldToExitGameOverlay
{
Action = () =>
{
exitConfirmedViaHoldOrClick = holdDelay.Value > 0;
this.Exit();
}
});
}
AddRangeInternal(new[]
{
SeasonalUIConfig.ENABLED ? new MainMenuSeasonalLighting() : Empty(),
buttonsContainer = new ParallaxContainer
{
ParallaxAmount = 0.01f,
Children = new Drawable[]
{
Buttons = new ButtonSystem
{
OnEditBeatmap = () =>
{
Beatmap.SetDefault();
this.Push(new EditorLoader());
},
OnEditSkin = () =>
{
skinEditor?.Show();
},
OnSolo = loadSongSelect,
OnMultiplayer = () => this.Push(new Multiplayer()),
OnQuickPlay = loadQuickPlay,
OnRankedPlay = loadRankedPlay,
OnPlaylists = () => this.Push(new Playlists()),
OnDailyChallenge = room =>
{
if (statics.Get<bool>(Static.DailyChallengeIntroPlayed))
this.Push(new DailyChallenge(room));
else
this.Push(new DailyChallengeIntro(room));
},
OnExit = e =>
{
exitConfirmedViaHoldOrClick = e is MouseEvent;
this.Exit();
}
}
}
},
logoTarget = new Container { RelativeSizeAxes = Axes.Both, },
sideFlashes = SeasonalUIConfig.ENABLED ? new SeasonalMenuSideFlashes() : new MenuSideFlashes(),
songTicker = new SongTicker
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Margin = new MarginPadding { Right = 15, Top = 5 }
},
// For now, this is too much alongside the seasonal lighting.
SeasonalUIConfig.ENABLED ? Empty() : new KiaiMenuFountains(),
bottomElementsFlow = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Spacing = new Vector2(5),
Children = new Drawable[]
{
menuTipDisplay = new MenuTipDisplay
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
},
onlineMenuBanner = new OnlineMenuBanner
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
}
}
},
supporterDisplay = new SupporterDisplay
{
Margin = new MarginPadding(5),
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
},
holdToExitGameOverlay?.CreateProxy() ?? Empty()
});
float baseDim = SeasonalUIConfig.ENABLED ? 0.84f : 1;
Buttons.StateChanged += state =>
{
switch (state)
{
case ButtonSystemState.Initial:
case ButtonSystemState.Exit:
ApplyToBackground(b => b.FadeColour(OsuColour.Gray(baseDim), 500, Easing.OutSine));
onlineMenuBanner.State.Value = Visibility.Hidden;
break;
default:
ApplyToBackground(b => b.FadeColour(OsuColour.Gray(baseDim * 0.8f), 500, Easing.OutSine));
onlineMenuBanner.State.Value = Visibility.Visible;
break;
}
};
Buttons.OnSettings = () => settings?.ToggleVisibility();
Buttons.OnBeatmapListing = () => beatmapListing?.ToggleVisibility();
reappearSampleSwoosh = audio.Samples.Get(@"Menu/reappear-swoosh");
}
protected override void LoadComplete()
{
base.LoadComplete();
GetContainingInputManager();
}
public void ReturnToOsuLogo() => Buttons.State = ButtonSystemState.Initial;
public override void OnEntering(ScreenTransitionEvent e)
{
base.OnEntering(e);
Buttons.FadeInFromZero(500);
if (e.Last is IntroScreen && musicController.TrackLoaded)
{
var track = musicController.CurrentTrack;
// presume the track is the current beatmap's track. not sure how correct this assumption is but it has worked until now.
if (!track.IsRunning)
{
Beatmap.Value.PrepareTrackForPreview(false);
track.Restart();
}
}
if (storage is OsuStorage osuStorage && osuStorage.Error != OsuStorageError.None)
dialogOverlay?.Push(new StorageErrorDialog(osuStorage, osuStorage.Error));
}
[CanBeNull]
private ScheduledDelegate mobileDisclaimerSchedule;
protected override void LogoArriving(OsuLogo logo, bool resuming)
{
base.LogoArriving(logo, resuming);
Buttons.SetOsuLogo(logo);
logo.FadeColour(Color4.White, 100, Easing.OutQuint);
logo.FadeIn(100, Easing.OutQuint);
logoProxy = logo.ProxyToContainer(logoTarget);
if (resuming)
{
Buttons.State = ButtonSystemState.TopLevel;
this.FadeIn(FADE_IN_DURATION, Easing.OutQuint);
buttonsContainer.MoveTo(new Vector2(0, 0), FADE_IN_DURATION, Easing.OutQuint);
sideFlashes.Delay(FADE_IN_DURATION).FadeIn(64, Easing.InQuint);
}
else
{
// copy out old action to avoid accidentally capturing logo.Action in closure, causing a self-reference loop.
var previousAction = logo.Action;
// we want to hook into logo.Action to display certain overlays, but also preserve the return value of the old action.
// therefore pass the old action to displayLogin, so that it can return that value.
// this ensures that the OsuLogo sample does not play when it is not desired.
logo.Action = () => onLogoClick(previousAction);
}
}
private bool onLogoClick(Func<bool> originalAction)
{
if (showMobileDisclaimer.Value)
{
mobileDisclaimerSchedule?.Cancel();
mobileDisclaimerSchedule = Scheduler.AddDelayed(() =>
{
dialogOverlay.Push(new MobileDisclaimerDialog(() =>
{
showMobileDisclaimer.Value = false;
displayLoginIfApplicable();
}));
}, 500);
}
else
displayLoginIfApplicable();
return originalAction.Invoke();
}
private void displayLoginIfApplicable()
{
if (loginDisplayed.Value) return;
if (!api.IsLoggedIn || api.State.Value == APIState.RequiresSecondFactorAuth)
{
Scheduler.AddDelayed(() => login?.Show(), 500);
loginDisplayed.Value = true;
}
}
protected override void LogoSuspending(OsuLogo logo)
{
var seq = logo.FadeOut(300, Easing.InSine)
.ScaleTo(0.2f, 300, Easing.InSine);
logoProxy?.Dispose();
logoProxy = null;
seq.OnComplete(_ => Buttons.SetOsuLogo(null));
seq.OnAbort(_ => Buttons.SetOsuLogo(null));
}
protected override void LogoExiting(OsuLogo logo)
{
base.LogoExiting(logo);
logoProxy?.Dispose();
logoProxy = null;
}
public override void OnSuspending(ScreenTransitionEvent e)
{
base.OnSuspending(e);
Buttons.State = ButtonSystemState.EnteringMode;
this.FadeOut(FADE_OUT_DURATION, Easing.InSine);
buttonsContainer.MoveTo(new Vector2(-800, 0), FADE_OUT_DURATION, Easing.InSine);
sideFlashes.FadeOut(64, Easing.OutQuint);
bottomElementsFlow
.ScaleTo(0.9f, 1000, Easing.OutQuint)
.FadeOut(500, Easing.OutQuint);
supporterDisplay
.FadeOut(500, Easing.OutQuint);
samplePlaybackDisabled.Value = true;
}
public override void OnResuming(ScreenTransitionEvent e)
{
base.OnResuming(e);
// Ensures any playing `ButtonSystem` samples are stopped when returning to MainMenu (as to not overlap with the 'back' sample)
Buttons.StopSamplePlayback();
reappearSampleSwoosh?.Play();
ApplyToBackground(b => (b as BackgroundScreenDefault)?.Next());
musicController.EnsurePlayingSomething();
// Cycle tip on resuming
menuTipDisplay.ShowNextTip();
bottomElementsFlow
.ScaleTo(1, 1000, Easing.OutQuint)
.FadeIn(1000, Easing.OutQuint);
samplePlaybackDisabled.Value = false;
}
public override bool OnExiting(ScreenExitEvent e)
{
bool requiresConfirmation =
// we need to have a dialog overlay to confirm in the first place.
dialogOverlay != null
// if the dialog has already displayed and been accepted by the user, we are good.
&& !exitConfirmedViaDialog
// Only require confirmation if there is either an ongoing operation or the user exited via a non-hold escape press.
&& (notifications.HasOngoingOperations || !exitConfirmedViaHoldOrClick);
if (requiresConfirmation)
{
if (dialogOverlay.CurrentDialog is ConfirmExitDialog exitDialog)
{
if (exitDialog.Buttons.OfType<PopupDialogOkButton>().FirstOrDefault() != null)
exitDialog.PerformOkAction();
else
exitDialog.Flash();
}
else
{
dialogOverlay.Push(new ConfirmExitDialog(() =>
{
exitConfirmedViaDialog = true;
this.Exit();
}, () =>
{
holdToExitGameOverlay.Abort();
Game.CancelRestartOnExit();
}));
}
return true;
}
Buttons.State = ButtonSystemState.Exit;
OverlayActivationMode.Value = OverlayActivation.Disabled;
songTicker.Hide();
this.FadeOut(3000);
bottomElementsFlow
.FadeOut(500, Easing.OutQuint);
supporterDisplay
.FadeOut(500, Easing.OutQuint);
return base.OnExiting(e);
}
public void PresentBeatmap(WorkingBeatmap beatmap, RulesetInfo ruleset)
{
Logger.Log($"{nameof(MainMenu)} completing {nameof(PresentBeatmap)} with beatmap {beatmap} ruleset {ruleset}");
Beatmap.Value = beatmap;
Ruleset.Value = ruleset;
Schedule(loadSongSelect);
}
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (e.Repeat)
return false;
switch (e.Action)
{
case GlobalAction.Back:
// In the case of a host being able to exit, the back action is handled by ExitConfirmOverlay.
Debug.Assert(!host.CanExit);
return host.SuspendToBackground();
}
return false;
}
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
private void loadSongSelect() => this.Push(new SoloSongSelect());
private void loadQuickPlay() => this.Push(new OnlinePlay.Matchmaking.Intro.ScreenIntro(MatchmakingPoolType.QuickPlay));
private void loadRankedPlay() => this.Push(new OnlinePlay.Matchmaking.Intro.ScreenIntro(MatchmakingPoolType.RankedPlay));
private partial class MobileDisclaimerDialog : PopupDialog
{
public MobileDisclaimerDialog(Action confirmed)
{
HeaderText = ButtonSystemStrings.MobileDisclaimerHeader;
BodyText = ButtonSystemStrings.MobileDisclaimerBody;
Icon = FontAwesome.Solid.SmileBeam;
Buttons = new PopupDialogButton[]
{
new PopupDialogOkButton
{
Text = ButtonSystemStrings.MobileDisclaimerOkButton,
Action = confirmed,
},
};
}
}
}
}