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-04-13 09:19:50 +00:00
|
|
|
|
2021-11-10 13:03:29 +00:00
|
|
|
using System;
|
2022-02-24 20:11:49 +00:00
|
|
|
using System.Diagnostics;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Framework.Graphics;
|
2022-02-23 13:06:22 +00:00
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
using osu.Framework.Input.Events;
|
2019-03-02 04:11:34 +00:00
|
|
|
using osu.Framework.Platform;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Framework.Screens;
|
2021-03-03 05:06:39 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2019-09-19 07:26:22 +00:00
|
|
|
using osu.Game.Configuration;
|
2018-09-20 18:13:15 +00:00
|
|
|
using osu.Game.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Game.Graphics.Containers;
|
2022-02-23 13:06:22 +00:00
|
|
|
using osu.Game.Input.Bindings;
|
2020-07-06 13:03:09 +00:00
|
|
|
using osu.Game.IO;
|
2019-09-08 05:36:58 +00:00
|
|
|
using osu.Game.Online.API;
|
2019-05-15 03:08:23 +00:00
|
|
|
using osu.Game.Overlays;
|
2021-03-03 05:06:39 +00:00
|
|
|
using osu.Game.Rulesets;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Game.Screens.Backgrounds;
|
|
|
|
using osu.Game.Screens.Edit;
|
2020-12-25 15:50:00 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
|
|
|
using osu.Game.Screens.OnlinePlay.Playlists;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Game.Screens.Select;
|
2021-05-19 07:27:38 +00:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Menu
|
|
|
|
{
|
2022-02-23 13:06:22 +00:00
|
|
|
public class MainMenu : OsuScreen, IHandlePresentBeatmap, IKeyBindingHandler<GlobalAction>
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2019-07-05 04:08:45 +00:00
|
|
|
public const float FADE_IN_DURATION = 300;
|
|
|
|
|
|
|
|
public const float FADE_OUT_DURATION = 400;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2019-06-19 04:16:19 +00:00
|
|
|
public override bool HideOverlaysOnEnter => buttons == null || buttons.State == ButtonSystemState.Initial;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2019-06-25 09:38:14 +00:00
|
|
|
public override bool AllowBackButton => false;
|
2018-05-14 19:09:09 +00:00
|
|
|
|
2018-11-29 08:18:59 +00:00
|
|
|
public override bool AllowExternalScreenChange => true;
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
private Screen songSelect;
|
|
|
|
|
2019-02-26 00:54:42 +00:00
|
|
|
private MenuSideFlashes sideFlashes;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2019-07-05 04:08:45 +00:00
|
|
|
private ButtonSystem buttons;
|
|
|
|
|
2019-02-25 01:42:36 +00:00
|
|
|
[Resolved]
|
|
|
|
private GameHost host { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-08-11 03:40:58 +00:00
|
|
|
[Resolved]
|
2020-08-16 14:04:49 +00:00
|
|
|
private MusicController musicController { get; set; }
|
2019-07-09 09:32:49 +00:00
|
|
|
|
2019-09-08 05:36:58 +00:00
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
private LoginOverlay login { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; }
|
|
|
|
|
2019-09-19 08:40:46 +00:00
|
|
|
[Resolved(canBeNull: true)]
|
2019-09-19 07:26:22 +00:00
|
|
|
private DialogOverlay dialogOverlay { get; set; }
|
|
|
|
|
2019-03-11 15:04:19 +00:00
|
|
|
private BackgroundScreenDefault background;
|
|
|
|
|
|
|
|
protected override BackgroundScreen CreateBackground() => background;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2022-03-04 03:21:05 +00:00
|
|
|
private Bindable<double> holdDelay;
|
2019-09-25 12:56:47 +00:00
|
|
|
private Bindable<bool> loginDisplayed;
|
2019-09-19 07:26:22 +00:00
|
|
|
|
2019-09-19 11:17:58 +00:00
|
|
|
private ExitConfirmOverlay exitConfirmOverlay;
|
|
|
|
|
2020-01-11 04:08:00 +00:00
|
|
|
private ParallaxContainer buttonsContainer;
|
2020-01-11 04:17:13 +00:00
|
|
|
private SongTicker songTicker;
|
2020-01-11 04:08:00 +00:00
|
|
|
|
2019-02-26 00:54:42 +00:00
|
|
|
[BackgroundDependencyLoader(true)]
|
2022-01-15 00:06:39 +00:00
|
|
|
private void load(BeatmapListingOverlay beatmapListing, SettingsOverlay settings, OsuConfigManager config, SessionStatics statics)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2022-03-04 03:21:05 +00:00
|
|
|
holdDelay = config.GetBindable<double>(OsuSetting.UIHoldActivationDelay);
|
2019-09-28 12:21:51 +00:00
|
|
|
loginDisplayed = statics.GetBindable<bool>(Static.LoginOverlayDisplayed);
|
2019-09-19 07:26:22 +00:00
|
|
|
|
2020-01-24 07:34:13 +00:00
|
|
|
if (host.CanExit)
|
|
|
|
{
|
|
|
|
AddInternal(exitConfirmOverlay = new ExitConfirmOverlay
|
|
|
|
{
|
|
|
|
Action = () =>
|
|
|
|
{
|
|
|
|
if (holdDelay.Value > 0)
|
|
|
|
confirmAndExit();
|
|
|
|
else
|
|
|
|
this.Exit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
AddRangeInternal(new[]
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-01-11 04:08:00 +00:00
|
|
|
buttonsContainer = new ParallaxContainer
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
ParallaxAmount = 0.01f,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
buttons = new ButtonSystem
|
|
|
|
{
|
2020-08-24 10:38:05 +00:00
|
|
|
OnEdit = delegate
|
|
|
|
{
|
|
|
|
Beatmap.SetDefault();
|
2021-09-05 14:59:28 +00:00
|
|
|
this.Push(new EditorLoader());
|
2020-08-24 10:38:05 +00:00
|
|
|
},
|
2021-03-03 05:06:39 +00:00
|
|
|
OnSolo = loadSoloSongSelect,
|
2020-12-25 04:38:11 +00:00
|
|
|
OnMultiplayer = () => this.Push(new Multiplayer()),
|
2020-12-25 14:45:44 +00:00
|
|
|
OnPlaylists = () => this.Push(new Playlists()),
|
2019-09-19 13:46:21 +00:00
|
|
|
OnExit = confirmAndExit,
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
sideFlashes = new MenuSideFlashes(),
|
2020-01-24 07:23:41 +00:00
|
|
|
songTicker = new SongTicker
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
Margin = new MarginPadding { Right = 15, Top = 5 }
|
2020-01-24 07:34:13 +00:00
|
|
|
},
|
2021-05-19 07:27:38 +00:00
|
|
|
exitConfirmOverlay?.CreateProxy() ?? Empty()
|
2019-02-26 00:54:42 +00:00
|
|
|
});
|
2018-09-20 18:13:15 +00:00
|
|
|
|
|
|
|
buttons.StateChanged += state =>
|
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case ButtonSystemState.Initial:
|
|
|
|
case ButtonSystemState.Exit:
|
2021-01-04 09:32:23 +00:00
|
|
|
ApplyToBackground(b => b.FadeColour(Color4.White, 500, Easing.OutSine));
|
2018-09-20 18:13:15 +00:00
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
2018-09-20 18:13:15 +00:00
|
|
|
default:
|
2021-01-04 09:32:23 +00:00
|
|
|
ApplyToBackground(b => b.FadeColour(OsuColour.Gray(0.8f), 500, Easing.OutSine));
|
2018-09-20 18:13:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2019-05-13 08:10:25 +00:00
|
|
|
buttons.OnSettings = () => settings?.ToggleVisibility();
|
2020-04-21 07:00:00 +00:00
|
|
|
buttons.OnBeatmapListing = () => beatmapListing?.ToggleVisibility();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2019-03-11 15:04:19 +00:00
|
|
|
LoadComponentAsync(background = new BackgroundScreenDefault());
|
2018-04-13 09:19:50 +00:00
|
|
|
preloadSongSelect();
|
|
|
|
}
|
|
|
|
|
2020-03-25 06:12:19 +00:00
|
|
|
[Resolved(canBeNull: true)]
|
2020-02-11 13:37:38 +00:00
|
|
|
private OsuGame game { get; set; }
|
|
|
|
|
2019-09-19 13:46:21 +00:00
|
|
|
private void confirmAndExit()
|
|
|
|
{
|
2019-12-22 12:52:00 +00:00
|
|
|
if (exitConfirmed) return;
|
|
|
|
|
2019-09-19 13:46:21 +00:00
|
|
|
exitConfirmed = true;
|
2020-03-25 06:12:19 +00:00
|
|
|
game?.PerformFromScreen(menu => menu.Exit());
|
2019-09-19 13:46:21 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
private void preloadSongSelect()
|
|
|
|
{
|
|
|
|
if (songSelect == null)
|
|
|
|
LoadComponentAsync(songSelect = new PlaySongSelect());
|
|
|
|
}
|
|
|
|
|
2021-03-03 05:06:39 +00:00
|
|
|
private void loadSoloSongSelect() => this.Push(consumeSongSelect());
|
2018-07-10 16:32:10 +00:00
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
private Screen consumeSongSelect()
|
|
|
|
{
|
|
|
|
var s = songSelect;
|
|
|
|
songSelect = null;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2020-07-06 13:03:09 +00:00
|
|
|
[Resolved]
|
|
|
|
private Storage storage { get; set; }
|
|
|
|
|
2019-01-23 11:52:00 +00:00
|
|
|
public override void OnEntering(IScreen last)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
base.OnEntering(last);
|
|
|
|
buttons.FadeInFromZero(500);
|
|
|
|
|
2020-08-16 14:04:49 +00:00
|
|
|
if (last is IntroScreen && musicController.TrackLoaded)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2021-02-18 06:01:11 +00:00
|
|
|
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)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2021-02-18 06:01:11 +00:00
|
|
|
Beatmap.Value.PrepareTrackForPreviewLooping();
|
|
|
|
track.Restart();
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-06 13:03:09 +00:00
|
|
|
|
|
|
|
if (storage is OsuStorage osuStorage && osuStorage.Error != OsuStorageError.None)
|
|
|
|
dialogOverlay?.Push(new StorageErrorDialog(osuStorage, osuStorage.Error));
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 07:26:22 +00:00
|
|
|
private bool exitConfirmed;
|
2019-09-09 16:17:58 +00:00
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
if (resuming)
|
|
|
|
{
|
2018-07-03 09:18:04 +00:00
|
|
|
buttons.State = ButtonSystemState.TopLevel;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2019-07-05 04:08:45 +00:00
|
|
|
this.FadeIn(FADE_IN_DURATION, Easing.OutQuint);
|
2020-01-11 04:08:00 +00:00
|
|
|
buttonsContainer.MoveTo(new Vector2(0, 0), FADE_IN_DURATION, Easing.OutQuint);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2019-07-05 04:08:45 +00:00
|
|
|
sideFlashes.Delay(FADE_IN_DURATION).FadeIn(64, Easing.InQuint);
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
2019-09-09 16:12:30 +00:00
|
|
|
else if (!api.IsLoggedIn)
|
|
|
|
{
|
2021-11-10 13:03:29 +00:00
|
|
|
// 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 the login overlay, 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 = () => displayLogin(previousAction);
|
2019-09-09 16:17:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-10 13:03:29 +00:00
|
|
|
bool displayLogin(Func<bool> originalAction)
|
2019-09-09 16:17:58 +00:00
|
|
|
{
|
2019-09-25 12:56:47 +00:00
|
|
|
if (!loginDisplayed.Value)
|
2019-09-09 16:12:30 +00:00
|
|
|
{
|
|
|
|
Scheduler.AddDelayed(() => login?.Show(), 500);
|
2019-09-25 12:56:47 +00:00
|
|
|
loginDisplayed.Value = true;
|
2019-09-09 16:17:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-10 13:03:29 +00:00
|
|
|
return originalAction.Invoke();
|
2019-09-09 16:12:30 +00:00
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LogoSuspending(OsuLogo logo)
|
|
|
|
{
|
2019-05-15 10:39:36 +00:00
|
|
|
var seq = logo.FadeOut(300, Easing.InSine)
|
|
|
|
.ScaleTo(0.2f, 300, Easing.InSine);
|
|
|
|
|
|
|
|
seq.OnComplete(_ => buttons.SetOsuLogo(null));
|
|
|
|
seq.OnAbort(_ => buttons.SetOsuLogo(null));
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
2019-01-23 11:52:00 +00:00
|
|
|
public override void OnSuspending(IScreen next)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
base.OnSuspending(next);
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
buttons.State = ButtonSystemState.EnteringMode;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2019-07-05 04:08:45 +00:00
|
|
|
this.FadeOut(FADE_OUT_DURATION, Easing.InSine);
|
2020-01-11 04:08:00 +00:00
|
|
|
buttonsContainer.MoveTo(new Vector2(-800, 0), FADE_OUT_DURATION, Easing.InSine);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
sideFlashes.FadeOut(64, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
|
2019-01-23 11:52:00 +00:00
|
|
|
public override void OnResuming(IScreen last)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
base.OnResuming(last);
|
2020-01-11 15:27:22 +00:00
|
|
|
|
2021-01-04 09:32:23 +00:00
|
|
|
ApplyToBackground(b => (b as BackgroundScreenDefault)?.Next());
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-05-05 01:31:11 +00:00
|
|
|
// we may have consumed our preloaded instance, so let's make another.
|
2018-04-13 09:19:50 +00:00
|
|
|
preloadSongSelect();
|
2019-07-08 22:08:18 +00:00
|
|
|
|
2020-08-16 14:04:49 +00:00
|
|
|
musicController.EnsurePlayingSomething();
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
2019-01-23 11:52:00 +00:00
|
|
|
public override bool OnExiting(IScreen next)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2019-12-22 13:20:55 +00:00
|
|
|
if (!exitConfirmed && dialogOverlay != null)
|
2019-09-19 07:26:22 +00:00
|
|
|
{
|
2019-12-22 13:39:25 +00:00
|
|
|
if (dialogOverlay.CurrentDialog is ConfirmExitDialog exitDialog)
|
2021-05-19 07:27:38 +00:00
|
|
|
exitDialog.PerformOkAction();
|
2019-12-22 13:39:25 +00:00
|
|
|
else
|
2019-12-22 13:20:55 +00:00
|
|
|
dialogOverlay.Push(new ConfirmExitDialog(confirmAndExit, () => exitConfirmOverlay.Abort()));
|
2021-05-19 07:27:38 +00:00
|
|
|
|
|
|
|
return true;
|
2019-12-22 12:52:00 +00:00
|
|
|
}
|
|
|
|
|
2018-07-03 09:18:04 +00:00
|
|
|
buttons.State = ButtonSystemState.Exit;
|
2020-08-28 07:55:14 +00:00
|
|
|
OverlayActivationMode.Value = OverlayActivation.Disabled;
|
2020-01-24 07:23:41 +00:00
|
|
|
|
2020-01-11 04:17:13 +00:00
|
|
|
songTicker.Hide();
|
2020-01-24 07:23:41 +00:00
|
|
|
|
|
|
|
this.FadeOut(3000);
|
2018-04-13 09:19:50 +00:00
|
|
|
return base.OnExiting(next);
|
|
|
|
}
|
2021-03-03 05:06:39 +00:00
|
|
|
|
|
|
|
public void PresentBeatmap(WorkingBeatmap beatmap, RulesetInfo ruleset)
|
|
|
|
{
|
|
|
|
Beatmap.Value = beatmap;
|
|
|
|
Ruleset.Value = ruleset;
|
|
|
|
|
|
|
|
Schedule(loadSoloSongSelect);
|
|
|
|
}
|
2022-02-23 13:06:22 +00:00
|
|
|
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
|
|
|
{
|
|
|
|
if (e.Repeat)
|
|
|
|
return false;
|
|
|
|
|
2022-02-24 20:11:49 +00:00
|
|
|
switch (e.Action)
|
2022-02-23 13:06:22 +00:00
|
|
|
{
|
2022-02-24 20:11:49 +00:00
|
|
|
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();
|
2022-02-23 13:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
|
|
|
{
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
}
|