1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 16:12:53 +08:00
osu-lazer/osu.Game/Screens/Menu/MainMenu.cs

211 lines
6.2 KiB
C#
Raw Normal View History

// 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;
using osuTK.Input;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
2018-10-02 11:02:47 +08:00
using osu.Framework.Input.Events;
2018-04-13 17:19:50 +08:00
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics.Containers;
using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Charts;
using osu.Game.Screens.Direct;
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;
using osu.Game.Screens.Tournament;
namespace osu.Game.Screens.Menu
{
public class MainMenu : OsuScreen
{
private readonly ButtonSystem buttons;
public override bool HideOverlaysOnEnter => buttons.State == ButtonSystemState.Initial;
2018-04-13 17:19:50 +08:00
protected override bool AllowBackButton => buttons.State != ButtonSystemState.Initial;
public override bool AllowExternalScreenChange => true;
2018-04-13 17:19:50 +08:00
private Screen songSelect;
private readonly MenuSideFlashes sideFlashes;
2019-01-23 19:52:00 +08:00
protected override BackgroundScreen CreateBackground() => new BackgroundScreenDefault();
2018-04-13 17:19:50 +08:00
public MainMenu()
{
2019-01-23 19:52:00 +08:00
InternalChildren = new Drawable[]
2018-04-13 17:19:50 +08:00
{
new ExitConfirmOverlay
{
2019-01-23 19:52:00 +08:00
Action = this.Exit,
},
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()); },
OnDirect = delegate {this.Push(new OnlineListing()); },
OnEdit = delegate {this.Push(new Editor()); },
OnSolo = onSolo,
2019-01-23 19:52:00 +08:00
OnMulti = delegate {this.Push(new Multiplayer()); },
OnExit = this.Exit,
2018-04-13 17:19:50 +08:00
}
}
},
sideFlashes = new MenuSideFlashes(),
};
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);
break;
default:
2019-01-23 19:52:00 +08:00
Background.FadeColour(OsuColour.Gray(0.8f), 500, Easing.OutSine);
break;
}
};
2018-04-13 17:19:50 +08:00
}
[BackgroundDependencyLoader(true)]
private void load(OsuGame game = null)
{
if (game != null)
{
buttons.OnSettings = game.ToggleSettings;
buttons.OnDirect = game.ToggleDirect;
}
preloadSongSelect();
}
private void preloadSongSelect()
{
if (songSelect == null)
LoadComponentAsync(songSelect = new PlaySongSelect());
}
public void LoadToSolo() => Schedule(onSolo);
2019-01-23 19:52:00 +08:00
private void onSolo() =>this.Push(consumeSongSelect());
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;
if (last is Intro && track != null)
{
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)
{
buttons.State = ButtonSystemState.TopLevel;
2018-04-13 17:19:50 +08:00
const float length = 300;
2019-01-23 19:52:00 +08:00
this.FadeIn(length, Easing.OutQuint);
this.MoveTo(new Vector2(0, 0), length, Easing.OutQuint);
2018-04-13 17:19:50 +08:00
sideFlashes.Delay(length).FadeIn(64, Easing.InQuint);
}
}
protected override void LogoSuspending(OsuLogo logo)
{
logo.FadeOut(300, Easing.InSine)
.ScaleTo(0.2f, 300, Easing.InSine)
.OnComplete(l => buttons.SetOsuLogo(null));
}
private void beatmap_ValueChanged(WorkingBeatmap newValue)
{
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);
const float length = 400;
buttons.State = ButtonSystemState.EnteringMode;
2018-04-13 17:19:50 +08:00
2019-01-23 19:52:00 +08:00
this.FadeOut(length, Easing.InSine);
this.MoveTo(new Vector2(-800, 0), length, 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-01-23 19:52:00 +08:00
((BackgroundScreenDefault)Background).Next();
2018-04-13 17:19:50 +08:00
//we may have consumed our preloaded instance, so let's make another.
preloadSongSelect();
}
2019-01-23 19:52:00 +08:00
public override bool OnExiting(IScreen next)
2018-04-13 17:19:50 +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);
}
2018-10-02 11:02:47 +08:00
protected override bool OnKeyDown(KeyDownEvent e)
2018-04-13 17:19:50 +08:00
{
if (!e.Repeat && e.ControlPressed && e.ShiftPressed && e.Key == Key.D)
2018-04-13 17:19:50 +08:00
{
2019-01-23 19:52:00 +08:00
this.Push(new Drawings());
2018-04-13 17:19:50 +08:00
return true;
}
2018-10-02 11:02:47 +08:00
return base.OnKeyDown(e);
2018-04-13 17:19:50 +08:00
}
}
}