1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 01:27:35 +08:00
osu-lazer/osu.Game/Screens/Menu/Intro.cs

168 lines
5.3 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-11-14 16:23:33 +08:00
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Audio.Track;
2017-04-15 01:42:42 +08:00
using osu.Framework.Configuration;
2017-02-17 17:59:30 +08:00
using osu.Framework.Screens;
2016-10-07 16:07:23 +08:00
using osu.Framework.Graphics;
2017-05-23 15:26:51 +08:00
using osu.Framework.MathUtils;
2017-07-26 12:22:46 +08:00
using osu.Game.Beatmaps;
2017-05-23 15:26:51 +08:00
using osu.Game.Beatmaps.IO;
2017-04-15 01:42:42 +08:00
using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
2016-11-14 16:23:33 +08:00
using osu.Game.Screens.Backgrounds;
2016-10-07 16:07:23 +08:00
using OpenTK.Graphics;
2016-11-14 16:23:33 +08:00
namespace osu.Game.Screens.Menu
{
2017-02-18 13:16:46 +08:00
public class Intro : OsuScreen
{
private readonly OsuLogo logo;
private const string menu_music_beatmap_hash = "715a09144f885d746644c1983e285044";
2017-05-23 15:26:51 +08:00
/// <summary>
/// Whether we have loaded the menu previously.
/// </summary>
internal bool DidLoadMenu;
2017-03-07 09:59:19 +08:00
private MainMenu mainMenu;
private SampleChannel welcome;
private SampleChannel seeya;
2016-11-01 22:24:14 +08:00
2017-03-16 22:58:36 +08:00
internal override bool HasLocalCursorDisplayed => true;
internal override bool ShowOverlays => false;
2017-02-17 17:59:30 +08:00
protected override BackgroundScreen CreateBackground() => new BackgroundScreenEmpty();
2016-11-01 22:24:14 +08:00
public Intro()
{
2016-10-07 16:07:23 +08:00
Children = new Drawable[]
{
new ParallaxContainer
2016-10-07 16:07:23 +08:00
{
ParallaxAmount = 0.01f,
Children = new Drawable[]
{
logo = new OsuLogo
{
Alpha = 0,
Triangles = false,
BlendingMode = BlendingMode.Additive,
Interactive = false,
Colour = Color4.DarkGray,
Ripple = false
}
}
2016-10-07 16:07:23 +08:00
}
};
2016-11-01 22:24:14 +08:00
}
2017-04-15 01:42:42 +08:00
private Bindable<bool> menuVoice;
2017-04-15 02:10:59 +08:00
private Bindable<bool> menuMusic;
2017-05-23 15:26:51 +08:00
private Track track;
2017-04-15 01:42:42 +08:00
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuConfigManager config, BeatmapManager beatmaps, Framework.Game game)
2016-11-01 22:24:14 +08:00
{
2017-05-15 09:56:27 +08:00
menuVoice = config.GetBindable<bool>(OsuSetting.MenuVoice);
menuMusic = config.GetBindable<bool>(OsuSetting.MenuMusic);
2017-04-15 01:42:42 +08:00
2017-05-23 15:26:51 +08:00
BeatmapSetInfo setInfo = null;
if (!menuMusic)
{
var sets = beatmaps.GetAllUsableBeatmapSets(false);
if (sets.Count > 0)
setInfo = beatmaps.QueryBeatmapSet(s => s.ID == sets[RNG.Next(0, sets.Count - 1)].ID);
2017-05-23 15:26:51 +08:00
}
if (setInfo == null)
{
setInfo = beatmaps.QueryBeatmapSet(b => b.Hash == menu_music_beatmap_hash);
2017-05-23 15:26:51 +08:00
if (setInfo == null)
{
// we need to import the default menu background beatmap
setInfo = beatmaps.Import(new OszArchiveReader(game.Resources.GetStream(@"Tracks/circles.osz")));
2017-05-23 15:26:51 +08:00
setInfo.Protected = true;
beatmaps.Delete(setInfo);
2017-05-23 15:26:51 +08:00
}
}
2017-07-19 12:32:16 +08:00
Beatmap.Value = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);
2017-05-23 15:26:51 +08:00
2017-07-19 12:32:16 +08:00
track = Beatmap.Value.Track;
2017-04-15 01:42:42 +08:00
2017-04-15 02:10:59 +08:00
welcome = audio.Sample.Get(@"welcome");
seeya = audio.Sample.Get(@"seeya");
2016-11-01 22:24:14 +08:00
}
2017-02-17 17:59:30 +08:00
protected override void OnEntering(Screen last)
2016-11-01 22:24:14 +08:00
{
base.OnEntering(last);
if (menuVoice)
2017-04-15 01:42:42 +08:00
welcome.Play();
2017-04-15 06:17:51 +08:00
2017-02-26 20:15:33 +08:00
Scheduler.AddDelayed(delegate
2016-10-07 16:07:23 +08:00
{
// Only start the current track if it is the menu music. A beatmap's track is started when entering the Main Manu.
if (menuMusic)
track.Start();
2017-02-26 20:15:33 +08:00
2017-04-02 14:56:12 +08:00
LoadComponentAsync(mainMenu = new MainMenu());
2016-10-07 16:07:23 +08:00
Scheduler.AddDelayed(delegate
{
2017-02-26 20:15:33 +08:00
DidLoadMenu = true;
Push(mainMenu);
}, 2300);
}, 600);
2016-10-07 16:07:23 +08:00
2016-11-01 22:24:14 +08:00
logo.ScaleTo(0.4f);
logo.FadeOut();
2017-07-23 02:50:25 +08:00
logo.ScaleTo(1, 4400, Easing.OutQuint);
logo.FadeIn(20000, Easing.OutQuint);
2016-10-07 16:07:23 +08:00
}
2017-02-17 17:59:30 +08:00
protected override void OnSuspending(Screen next)
2016-10-07 16:07:23 +08:00
{
Content.FadeOut(300);
base.OnSuspending(next);
}
2017-02-17 17:59:30 +08:00
protected override bool OnExiting(Screen next)
{
//cancel exiting if we haven't loaded the menu yet.
return !DidLoadMenu;
}
2017-02-17 17:59:30 +08:00
protected override void OnResuming(Screen last)
{
2017-02-17 14:33:08 +08:00
if (!(last is MainMenu))
Content.FadeIn(300);
2017-04-15 01:42:42 +08:00
double fadeOutTime = 2000;
//we also handle the exit transition.
2017-04-15 01:42:42 +08:00
if (menuVoice)
seeya.Play();
else
fadeOutTime = 500;
2017-04-15 01:42:42 +08:00
Scheduler.AddDelayed(Exit, fadeOutTime);
//don't want to fade out completely else we will stop running updates and shit will hit the fan.
2017-04-15 01:42:42 +08:00
Game.FadeTo(0.01f, fadeOutTime);
base.OnResuming(last);
}
}
}