mirror of
https://github.com/ppy/osu
synced 2025-01-09 23:59:44 +00:00
Merge pull request #6219 from LeNitrous/cleanup-intros
Move common logic to IntroScreen
This commit is contained in:
commit
11c0071429
@ -2,87 +2,42 @@
|
||||
// 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.Screens;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.MathUtils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.IO.Archives;
|
||||
|
||||
namespace osu.Game.Screens.Menu
|
||||
{
|
||||
public class IntroCircles : IntroScreen
|
||||
{
|
||||
private const string menu_music_beatmap_hash = "3c8b1fcc9434dbb29e2fb613d3b9eada9d7bb6c125ceb32396c3b53437280c83";
|
||||
protected override string BeatmapHash => "3c8b1fcc9434dbb29e2fb613d3b9eada9d7bb6c125ceb32396c3b53437280c83";
|
||||
|
||||
private SampleChannel welcome;
|
||||
|
||||
private Bindable<bool> menuMusic;
|
||||
|
||||
private Track track;
|
||||
|
||||
private WorkingBeatmap introBeatmap;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config, BeatmapManager beatmaps, Framework.Game game, ISampleStore samples)
|
||||
{
|
||||
menuMusic = config.GetBindable<bool>(OsuSetting.MenuMusic);
|
||||
|
||||
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 == menu_music_beatmap_hash);
|
||||
|
||||
if (setInfo == null)
|
||||
{
|
||||
// we need to import the default menu background beatmap
|
||||
setInfo = beatmaps.Import(new ZipArchiveReader(game.Resources.GetStream(@"Tracks/circles.osz"), "circles.osz")).Result;
|
||||
|
||||
setInfo.Protected = true;
|
||||
beatmaps.Update(setInfo);
|
||||
}
|
||||
}
|
||||
|
||||
introBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);
|
||||
track = introBeatmap.Track;
|
||||
|
||||
if (config.Get<bool>(OsuSetting.MenuVoice))
|
||||
welcome = samples.Get(@"welcome");
|
||||
}
|
||||
protected override string BeatmapFile => "circles.osz";
|
||||
|
||||
private const double delay_step_one = 2300;
|
||||
private const double delay_step_two = 600;
|
||||
|
||||
private SampleChannel welcome;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio)
|
||||
{
|
||||
if (MenuVoice.Value)
|
||||
welcome = audio.Samples.Get(@"welcome");
|
||||
}
|
||||
|
||||
protected override void LogoArriving(OsuLogo logo, bool resuming)
|
||||
{
|
||||
base.LogoArriving(logo, resuming);
|
||||
|
||||
if (!resuming)
|
||||
{
|
||||
Beatmap.Value = introBeatmap;
|
||||
introBeatmap = null;
|
||||
|
||||
welcome?.Play();
|
||||
|
||||
Scheduler.AddDelayed(delegate
|
||||
{
|
||||
// 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();
|
||||
track = null;
|
||||
}
|
||||
StartTrack();
|
||||
|
||||
PrepareMenuLoad();
|
||||
|
||||
@ -97,8 +52,6 @@ namespace osu.Game.Screens.Menu
|
||||
|
||||
public override void OnSuspending(IScreen next)
|
||||
{
|
||||
track = null;
|
||||
|
||||
this.FadeOut(300);
|
||||
base.OnSuspending(next);
|
||||
}
|
||||
|
@ -4,12 +4,16 @@
|
||||
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;
|
||||
|
||||
@ -17,51 +21,90 @@ namespace osu.Game.Screens.Menu
|
||||
{
|
||||
public abstract class IntroScreen : StartupScreen
|
||||
{
|
||||
private readonly BindableDouble exitingVolumeFade = new BindableDouble(1);
|
||||
|
||||
public const int EXIT_DELAY = 3000;
|
||||
|
||||
[Resolved]
|
||||
private AudioManager audio { get; set; }
|
||||
|
||||
private SampleChannel seeya;
|
||||
|
||||
private Bindable<bool> menuVoice;
|
||||
|
||||
private LeasedBindable<WorkingBeatmap> beatmap;
|
||||
|
||||
public new Bindable<WorkingBeatmap> Beatmap => beatmap;
|
||||
|
||||
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBlack();
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config, BeatmapManager beatmaps, Framework.Game game)
|
||||
{
|
||||
// prevent user from changing beatmap while the intro is still runnning.
|
||||
beatmap = base.Beatmap.BeginLease(false);
|
||||
|
||||
menuVoice = config.GetBindable<bool>(OsuSetting.MenuVoice);
|
||||
seeya = audio.Samples.Get(@"seeya");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether we have loaded the menu previously.
|
||||
/// </summary>
|
||||
public bool DidLoadMenu { get; private set; }
|
||||
|
||||
public override bool OnExiting(IScreen next)
|
||||
/// <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; }
|
||||
|
||||
protected IBindable<bool> MenuVoice { get; private set; }
|
||||
|
||||
protected IBindable<bool> MenuMusic { get; private set; }
|
||||
|
||||
private WorkingBeatmap introBeatmap;
|
||||
|
||||
protected Track Track { get; private set; }
|
||||
|
||||
private readonly BindableDouble exitingVolumeFade = new BindableDouble(1);
|
||||
|
||||
private const int exit_delay = 3000;
|
||||
|
||||
private SampleChannel seeya;
|
||||
|
||||
private LeasedBindable<WorkingBeatmap> beatmap;
|
||||
|
||||
private MainMenu mainMenu;
|
||||
|
||||
[Resolved]
|
||||
private AudioManager audio { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config, SkinManager skinManager, BeatmapManager beatmaps, Framework.Game game)
|
||||
{
|
||||
//cancel exiting if we haven't loaded the menu yet.
|
||||
return !DidLoadMenu;
|
||||
// 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;
|
||||
}
|
||||
|
||||
public override bool OnExiting(IScreen next) => !DidLoadMenu;
|
||||
|
||||
public override void OnResuming(IScreen last)
|
||||
{
|
||||
this.FadeIn(300);
|
||||
|
||||
double fadeOutTime = EXIT_DELAY;
|
||||
double fadeOutTime = exit_delay;
|
||||
//we also handle the exit transition.
|
||||
if (menuVoice.Value)
|
||||
if (MenuVoice.Value)
|
||||
seeya.Play();
|
||||
else
|
||||
fadeOutTime = 500;
|
||||
@ -75,6 +118,21 @@ namespace osu.Game.Screens.Menu
|
||||
base.OnResuming(last);
|
||||
}
|
||||
|
||||
public override void OnSuspending(IScreen next)
|
||||
{
|
||||
base.OnSuspending(next);
|
||||
Track = null;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
protected override void LogoArriving(OsuLogo logo, bool resuming)
|
||||
{
|
||||
base.LogoArriving(logo, resuming);
|
||||
@ -85,6 +143,9 @@ namespace osu.Game.Screens.Menu
|
||||
|
||||
if (!resuming)
|
||||
{
|
||||
beatmap.Value = introBeatmap;
|
||||
introBeatmap = null;
|
||||
|
||||
logo.MoveTo(new Vector2(0.5f));
|
||||
logo.ScaleTo(Vector2.One);
|
||||
logo.Hide();
|
||||
@ -92,7 +153,7 @@ namespace osu.Game.Screens.Menu
|
||||
else
|
||||
{
|
||||
const int quick_appear = 350;
|
||||
int initialMovementTime = logo.Alpha > 0.2f ? quick_appear : 0;
|
||||
var initialMovementTime = logo.Alpha > 0.2f ? quick_appear : 0;
|
||||
|
||||
logo.MoveTo(new Vector2(0.5f), initialMovementTime, Easing.OutQuint);
|
||||
|
||||
@ -100,17 +161,12 @@ namespace osu.Game.Screens.Menu
|
||||
.ScaleTo(1, initialMovementTime, Easing.OutQuint)
|
||||
.FadeIn(quick_appear, Easing.OutQuint)
|
||||
.Then()
|
||||
.RotateTo(20, EXIT_DELAY * 1.5f)
|
||||
.FadeOut(EXIT_DELAY);
|
||||
.RotateTo(20, exit_delay * 1.5f)
|
||||
.FadeOut(exit_delay);
|
||||
}
|
||||
}
|
||||
|
||||
private MainMenu mainMenu;
|
||||
|
||||
protected void PrepareMenuLoad()
|
||||
{
|
||||
LoadComponentAsync(mainMenu = new MainMenu());
|
||||
}
|
||||
protected void PrepareMenuLoad() => LoadComponentAsync(mainMenu = new MainMenu());
|
||||
|
||||
protected void LoadMenu()
|
||||
{
|
||||
|
@ -7,8 +7,6 @@ using System.IO;
|
||||
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.Screens;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -17,12 +15,9 @@ using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Graphics.Video;
|
||||
using osu.Framework.MathUtils;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.IO.Archives;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.Backgrounds;
|
||||
using osuTK;
|
||||
@ -32,9 +27,9 @@ namespace osu.Game.Screens.Menu
|
||||
{
|
||||
public class IntroTriangles : IntroScreen
|
||||
{
|
||||
private const string menu_music_beatmap_hash = "a1556d0801b3a6b175dda32ef546f0ec812b400499f575c44fccbe9c67f9b1e5";
|
||||
protected override string BeatmapHash => "a1556d0801b3a6b175dda32ef546f0ec812b400499f575c44fccbe9c67f9b1e5";
|
||||
|
||||
private SampleChannel welcome;
|
||||
protected override string BeatmapFile => "triangles.osz";
|
||||
|
||||
protected override BackgroundScreen CreateBackground() => background = new BackgroundScreenDefault(false)
|
||||
{
|
||||
@ -44,47 +39,14 @@ namespace osu.Game.Screens.Menu
|
||||
[Resolved]
|
||||
private AudioManager audio { get; set; }
|
||||
|
||||
private Bindable<bool> menuMusic;
|
||||
private Track track;
|
||||
private WorkingBeatmap introBeatmap;
|
||||
|
||||
private BackgroundScreenDefault background;
|
||||
|
||||
private SampleChannel welcome;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config, BeatmapManager beatmaps, Framework.Game game)
|
||||
private void load(AudioManager audio)
|
||||
{
|
||||
menuMusic = config.GetBindable<bool>(OsuSetting.MenuMusic);
|
||||
|
||||
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 == menu_music_beatmap_hash);
|
||||
|
||||
if (setInfo == null)
|
||||
{
|
||||
// we need to import the default menu background beatmap
|
||||
setInfo = beatmaps.Import(new ZipArchiveReader(game.Resources.GetStream(@"Tracks/triangles.osz"), "triangles.osz")).Result;
|
||||
|
||||
setInfo.Protected = true;
|
||||
beatmaps.Update(setInfo);
|
||||
}
|
||||
}
|
||||
|
||||
introBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);
|
||||
|
||||
track = introBeatmap.Track;
|
||||
track.Reset();
|
||||
|
||||
if (config.Get<bool>(OsuSetting.MenuVoice) && !menuMusic.Value)
|
||||
// triangles has welcome sound included in the track. only play this if the user doesn't want menu music.
|
||||
if (MenuVoice.Value && !MenuMusic.Value)
|
||||
welcome = audio.Samples.Get(@"welcome");
|
||||
}
|
||||
|
||||
@ -96,24 +58,19 @@ namespace osu.Game.Screens.Menu
|
||||
|
||||
if (!resuming)
|
||||
{
|
||||
Beatmap.Value = introBeatmap;
|
||||
introBeatmap = null;
|
||||
|
||||
PrepareMenuLoad();
|
||||
|
||||
LoadComponentAsync(new TrianglesIntroSequence(logo, background)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Clock = new FramedClock(menuMusic.Value ? track : null),
|
||||
Clock = new FramedClock(MenuMusic.Value ? Track : null),
|
||||
LoadMenu = LoadMenu
|
||||
}, t =>
|
||||
{
|
||||
AddInternal(t);
|
||||
welcome?.Play();
|
||||
|
||||
// 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.Start();
|
||||
StartTrack();
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -124,12 +81,6 @@ namespace osu.Game.Screens.Menu
|
||||
background.FadeOut(100);
|
||||
}
|
||||
|
||||
public override void OnSuspending(IScreen next)
|
||||
{
|
||||
track = null;
|
||||
base.OnSuspending(next);
|
||||
}
|
||||
|
||||
private class TrianglesIntroSequence : CompositeDrawable
|
||||
{
|
||||
private readonly OsuLogo logo;
|
||||
|
Loading…
Reference in New Issue
Block a user