2019-01-24 16:43:03 +08: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 17:19:50 +08:00
|
|
|
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Graphics;
|
2019-03-02 12:11:34 +08:00
|
|
|
using osu.Framework.Platform;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Game.Beatmaps;
|
2018-09-21 02:13:15 +08:00
|
|
|
using osu.Game.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2019-05-15 11:08:23 +08:00
|
|
|
using osu.Game.Overlays;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Game.Screens.Backgrounds;
|
|
|
|
using osu.Game.Screens.Charts;
|
|
|
|
using osu.Game.Screens.Edit;
|
2018-05-16 08:14:10 +08:00
|
|
|
using osu.Game.Screens.Multi;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Game.Screens.Select;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Menu
|
|
|
|
{
|
|
|
|
public class MainMenu : OsuScreen
|
|
|
|
{
|
2019-07-05 12:08:45 +08:00
|
|
|
public const float FADE_IN_DURATION = 300;
|
|
|
|
|
|
|
|
public const float FADE_OUT_DURATION = 400;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-06-19 12:16:19 +08:00
|
|
|
public override bool HideOverlaysOnEnter => buttons == null || buttons.State == ButtonSystemState.Initial;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-06-25 17:38:14 +08:00
|
|
|
public override bool AllowBackButton => false;
|
2018-05-15 03:09:09 +08:00
|
|
|
|
2018-11-29 16:18:59 +08:00
|
|
|
public override bool AllowExternalScreenChange => true;
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
private Screen songSelect;
|
|
|
|
|
2019-02-26 08:54:42 +08:00
|
|
|
private MenuSideFlashes sideFlashes;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-07-05 12:08:45 +08:00
|
|
|
private ButtonSystem buttons;
|
|
|
|
|
2019-02-25 09:42:36 +08:00
|
|
|
[Resolved]
|
|
|
|
private GameHost host { get; set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-07-10 23:20:01 +08:00
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
private MusicController music { get; set; }
|
2019-07-09 17:32:49 +08:00
|
|
|
|
2019-03-11 23:04:19 +08:00
|
|
|
private BackgroundScreenDefault background;
|
|
|
|
|
|
|
|
protected override BackgroundScreen CreateBackground() => background;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-02-26 08:54:42 +08:00
|
|
|
[BackgroundDependencyLoader(true)]
|
2019-05-13 16:10:25 +08:00
|
|
|
private void load(DirectOverlay direct, SettingsOverlay settings)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-02-26 08:54:42 +08:00
|
|
|
if (host.CanExit)
|
|
|
|
AddInternal(new ExitConfirmOverlay { Action = this.Exit });
|
2019-02-25 09:42:36 +08:00
|
|
|
|
2019-02-26 08:54:42 +08:00
|
|
|
AddRangeInternal(new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
new ParallaxContainer
|
|
|
|
{
|
|
|
|
ParallaxAmount = 0.01f,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
buttons = new ButtonSystem
|
|
|
|
{
|
2019-01-23 19:52:00 +08:00
|
|
|
OnChart = delegate { this.Push(new ChartListing()); },
|
2019-02-26 08:54:42 +08:00
|
|
|
OnEdit = delegate { this.Push(new Editor()); },
|
2018-07-11 00:32:10 +08:00
|
|
|
OnSolo = onSolo,
|
2019-02-26 08:54:42 +08:00
|
|
|
OnMulti = delegate { this.Push(new Multiplayer()); },
|
2019-01-23 19:52:00 +08:00
|
|
|
OnExit = this.Exit,
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
sideFlashes = new MenuSideFlashes(),
|
2019-02-26 08:54:42 +08:00
|
|
|
});
|
2018-09-21 02:13:15 +08:00
|
|
|
|
|
|
|
buttons.StateChanged += state =>
|
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case ButtonSystemState.Initial:
|
|
|
|
case ButtonSystemState.Exit:
|
2019-01-23 19:52:00 +08:00
|
|
|
Background.FadeColour(Color4.White, 500, Easing.OutSine);
|
2018-09-21 02:13:15 +08:00
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
2018-09-21 02:13:15 +08:00
|
|
|
default:
|
2019-01-23 19:52:00 +08:00
|
|
|
Background.FadeColour(OsuColour.Gray(0.8f), 500, Easing.OutSine);
|
2018-09-21 02:13:15 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-05-13 16:10:25 +08:00
|
|
|
buttons.OnSettings = () => settings?.ToggleVisibility();
|
|
|
|
buttons.OnDirect = () => direct?.ToggleVisibility();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-03-11 23:04:19 +08:00
|
|
|
LoadComponentAsync(background = new BackgroundScreenDefault());
|
2018-04-13 17:19:50 +08:00
|
|
|
preloadSongSelect();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void preloadSongSelect()
|
|
|
|
{
|
|
|
|
if (songSelect == null)
|
|
|
|
LoadComponentAsync(songSelect = new PlaySongSelect());
|
|
|
|
}
|
|
|
|
|
2018-07-11 00:32:10 +08:00
|
|
|
public void LoadToSolo() => Schedule(onSolo);
|
|
|
|
|
2019-02-25 18:19:28 +08:00
|
|
|
private void onSolo() => this.Push(consumeSongSelect());
|
2018-07-11 00:32:10 +08:00
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
private Screen consumeSongSelect()
|
|
|
|
{
|
|
|
|
var s = songSelect;
|
|
|
|
songSelect = null;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2019-01-23 19:52:00 +08:00
|
|
|
public override void OnEntering(IScreen last)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
base.OnEntering(last);
|
|
|
|
buttons.FadeInFromZero(500);
|
|
|
|
|
|
|
|
var track = Beatmap.Value.Track;
|
|
|
|
var metadata = Beatmap.Value.Metadata;
|
|
|
|
|
2019-07-09 16:59:40 +08:00
|
|
|
if (last is IntroScreen && track != null)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
if (!track.IsRunning)
|
|
|
|
{
|
|
|
|
track.Seek(metadata.PreviewTime != -1 ? metadata.PreviewTime : 0.4f * track.Length);
|
|
|
|
track.Start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Beatmap.ValueChanged += beatmap_ValueChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 17:18:04 +08:00
|
|
|
buttons.State = ButtonSystemState.TopLevel;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-07-05 12:08:45 +08:00
|
|
|
this.FadeIn(FADE_IN_DURATION, Easing.OutQuint);
|
|
|
|
this.MoveTo(new Vector2(0, 0), FADE_IN_DURATION, Easing.OutQuint);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-07-05 12:08:45 +08:00
|
|
|
sideFlashes.Delay(FADE_IN_DURATION).FadeIn(64, Easing.InQuint);
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LogoSuspending(OsuLogo logo)
|
|
|
|
{
|
2019-05-15 18:39:36 +08: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 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
private void beatmap_ValueChanged(ValueChangedEvent<WorkingBeatmap> e)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-01-23 19:52:00 +08:00
|
|
|
if (!this.IsCurrentScreen())
|
2018-04-13 17:19:50 +08:00
|
|
|
return;
|
|
|
|
|
2019-01-23 19:52:00 +08:00
|
|
|
((BackgroundScreenDefault)Background).Next();
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
2019-01-23 19:52:00 +08:00
|
|
|
public override void OnSuspending(IScreen next)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
base.OnSuspending(next);
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
buttons.State = ButtonSystemState.EnteringMode;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-07-05 12:08:45 +08:00
|
|
|
this.FadeOut(FADE_OUT_DURATION, Easing.InSine);
|
|
|
|
this.MoveTo(new Vector2(-800, 0), FADE_OUT_DURATION, Easing.InSine);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
sideFlashes.FadeOut(64, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
|
2019-01-23 19:52:00 +08:00
|
|
|
public override void OnResuming(IScreen last)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
base.OnResuming(last);
|
|
|
|
|
2019-02-25 18:19:28 +08:00
|
|
|
(Background as BackgroundScreenDefault)?.Next();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
//we may have consumed our preloaded instance, so let's make another.
|
|
|
|
preloadSongSelect();
|
2019-07-09 06:08:18 +08:00
|
|
|
|
2019-07-10 23:20:01 +08:00
|
|
|
if (Beatmap.Value.Track != null && music?.IsUserPaused != true)
|
2019-07-09 17:32:49 +08:00
|
|
|
Beatmap.Value.Track.Start();
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
2019-01-23 19:52:00 +08:00
|
|
|
public override bool OnExiting(IScreen next)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2018-07-03 17:18:04 +08:00
|
|
|
buttons.State = ButtonSystemState.Exit;
|
2019-01-23 19:52:00 +08:00
|
|
|
this.FadeOut(3000);
|
2018-04-13 17:19:50 +08:00
|
|
|
return base.OnExiting(next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|