mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 20:07:29 +08:00
189 lines
5.8 KiB
C#
189 lines
5.8 KiB
C#
// 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.
|
|
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Audio;
|
|
using osu.Framework.Audio.Sample;
|
|
using osu.Framework.Audio.Track;
|
|
using osu.Framework.Bindables;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.MathUtils;
|
|
using osu.Framework.Screens;
|
|
using osu.Game.Beatmaps;
|
|
using osu.Game.Configuration;
|
|
using osu.Game.IO.Archives;
|
|
using osu.Game.Screens.Backgrounds;
|
|
using osu.Game.Skinning;
|
|
using osuTK;
|
|
using osuTK.Graphics;
|
|
|
|
namespace osu.Game.Screens.Menu
|
|
{
|
|
public abstract class IntroScreen : StartupScreen
|
|
{
|
|
/// <summary>
|
|
/// A hash used to find the associated beatmap if already imported.
|
|
/// </summary>
|
|
protected abstract string BeatmapHash { get; }
|
|
|
|
/// <summary>
|
|
/// A source file to use as an import source if the intro beatmap is not yet present.
|
|
/// Should be within the "Tracks" namespace of game resources.
|
|
/// </summary>
|
|
protected abstract string BeatmapFile { get; }
|
|
|
|
private readonly BindableDouble exitingVolumeFade = new BindableDouble(1);
|
|
|
|
private const int exit_delay = 3000;
|
|
|
|
[Resolved]
|
|
private AudioManager audio { get; set; }
|
|
|
|
protected SampleChannel Welcome;
|
|
|
|
private SampleChannel seeya;
|
|
|
|
protected Bindable<bool> MenuVoice;
|
|
|
|
protected Bindable<bool> MenuMusic;
|
|
|
|
protected Track Track { get; private set; }
|
|
|
|
protected WorkingBeatmap IntroBeatmap;
|
|
|
|
private LeasedBindable<WorkingBeatmap> beatmap;
|
|
|
|
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBlack();
|
|
|
|
protected void StartTrack()
|
|
{
|
|
// Only start the current track if it is the menu music. A beatmap's track is started when entering the Main Menu.
|
|
if (MenuMusic.Value)
|
|
Track.Restart();
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load(OsuConfigManager config, SkinManager skinManager, BeatmapManager beatmaps, Framework.Game game)
|
|
{
|
|
// prevent user from changing beatmap while the intro is still runnning.
|
|
beatmap = Beatmap.BeginLease(false);
|
|
|
|
MenuVoice = config.GetBindable<bool>(OsuSetting.MenuVoice);
|
|
MenuMusic = config.GetBindable<bool>(OsuSetting.MenuMusic);
|
|
|
|
seeya = audio.Samples.Get(@"seeya");
|
|
|
|
BeatmapSetInfo setInfo = null;
|
|
|
|
if (!MenuMusic.Value)
|
|
{
|
|
var sets = beatmaps.GetAllUsableBeatmapSets();
|
|
if (sets.Count > 0)
|
|
setInfo = beatmaps.QueryBeatmapSet(s => s.ID == sets[RNG.Next(0, sets.Count - 1)].ID);
|
|
}
|
|
|
|
if (setInfo == null)
|
|
{
|
|
setInfo = beatmaps.QueryBeatmapSet(b => b.Hash == BeatmapHash);
|
|
|
|
if (setInfo == null)
|
|
{
|
|
// we need to import the default menu background beatmap
|
|
setInfo = beatmaps.Import(new ZipArchiveReader(game.Resources.GetStream($"Tracks/{BeatmapFile}"), BeatmapFile)).Result;
|
|
|
|
setInfo.Protected = true;
|
|
beatmaps.Update(setInfo);
|
|
}
|
|
}
|
|
|
|
IntroBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);
|
|
Track = IntroBeatmap.Track;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Whether we have loaded the menu previously.
|
|
/// </summary>
|
|
public bool DidLoadMenu { get; private set; }
|
|
|
|
public override bool OnExiting(IScreen next)
|
|
{
|
|
//cancel exiting if we haven't loaded the menu yet.
|
|
return !DidLoadMenu;
|
|
}
|
|
|
|
public override void OnResuming(IScreen last)
|
|
{
|
|
this.FadeIn(300);
|
|
|
|
double fadeOutTime = exit_delay;
|
|
//we also handle the exit transition.
|
|
if (MenuVoice.Value)
|
|
seeya.Play();
|
|
else
|
|
fadeOutTime = 500;
|
|
|
|
audio.AddAdjustment(AdjustableProperty.Volume, exitingVolumeFade);
|
|
this.TransformBindableTo(exitingVolumeFade, 0, fadeOutTime).OnComplete(_ => this.Exit());
|
|
|
|
//don't want to fade out completely else we will stop running updates.
|
|
Game.FadeTo(0.01f, fadeOutTime);
|
|
|
|
base.OnResuming(last);
|
|
}
|
|
|
|
protected override void LogoArriving(OsuLogo logo, bool resuming)
|
|
{
|
|
base.LogoArriving(logo, resuming);
|
|
|
|
logo.Colour = Color4.White;
|
|
logo.Triangles = false;
|
|
logo.Ripple = false;
|
|
|
|
if (!resuming)
|
|
{
|
|
Beatmap.Value = IntroBeatmap;
|
|
IntroBeatmap = null;
|
|
|
|
logo.MoveTo(new Vector2(0.5f));
|
|
logo.ScaleTo(Vector2.One);
|
|
logo.Hide();
|
|
}
|
|
else
|
|
{
|
|
const int quick_appear = 350;
|
|
int initialMovementTime = logo.Alpha > 0.2f ? quick_appear : 0;
|
|
|
|
logo.MoveTo(new Vector2(0.5f), initialMovementTime, Easing.OutQuint);
|
|
|
|
logo
|
|
.ScaleTo(1, initialMovementTime, Easing.OutQuint)
|
|
.FadeIn(quick_appear, Easing.OutQuint)
|
|
.Then()
|
|
.RotateTo(20, exit_delay * 1.5f)
|
|
.FadeOut(exit_delay);
|
|
}
|
|
}
|
|
|
|
public override void OnSuspending(IScreen next)
|
|
{
|
|
base.OnSuspending(next);
|
|
Track = null;
|
|
}
|
|
|
|
private MainMenu mainMenu;
|
|
|
|
protected void PrepareMenuLoad()
|
|
{
|
|
LoadComponentAsync(mainMenu = new MainMenu());
|
|
}
|
|
|
|
protected void LoadMenu()
|
|
{
|
|
beatmap.Return();
|
|
|
|
DidLoadMenu = true;
|
|
this.Push(mainMenu);
|
|
}
|
|
}
|
|
}
|