2019-07-09 16:59:40 +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.
|
|
|
|
|
2021-10-07 15:38:22 +08:00
|
|
|
using System;
|
2021-08-20 18:33:47 +08:00
|
|
|
using System.Linq;
|
2021-10-07 15:38:22 +08:00
|
|
|
using JetBrains.Annotations;
|
2019-07-09 16:59:40 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
2019-09-23 20:52:44 +08:00
|
|
|
using osu.Framework.Audio.Track;
|
2019-07-09 16:59:40 +08:00
|
|
|
using osu.Framework.Bindables;
|
2022-01-03 16:31:12 +08:00
|
|
|
using osu.Framework.Extensions;
|
2019-07-09 16:59:40 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Screens;
|
2021-10-07 15:38:22 +08:00
|
|
|
using osu.Framework.Utils;
|
2019-07-09 16:59:40 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Configuration;
|
2021-12-15 14:03:06 +08:00
|
|
|
using osu.Game.Database;
|
2019-09-23 20:52:44 +08:00
|
|
|
using osu.Game.IO.Archives;
|
2020-09-02 19:04:56 +08:00
|
|
|
using osu.Game.Overlays;
|
2019-07-09 16:59:40 +08:00
|
|
|
using osu.Game.Screens.Backgrounds;
|
2019-09-23 20:52:44 +08:00
|
|
|
using osu.Game.Skinning;
|
2019-07-09 16:59:40 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Menu
|
|
|
|
{
|
|
|
|
public abstract class IntroScreen : StartupScreen
|
|
|
|
{
|
2019-10-08 11:05:52 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether we have loaded the menu previously.
|
|
|
|
/// </summary>
|
|
|
|
public bool DidLoadMenu { get; private set; }
|
|
|
|
|
2019-10-08 10:52:16 +08:00
|
|
|
/// <summary>
|
|
|
|
/// A hash used to find the associated beatmap if already imported.
|
|
|
|
/// </summary>
|
2019-09-23 20:52:44 +08:00
|
|
|
protected abstract string BeatmapHash { get; }
|
|
|
|
|
2019-10-08 10:52:16 +08:00
|
|
|
/// <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>
|
2019-09-23 20:52:44 +08:00
|
|
|
protected abstract string BeatmapFile { get; }
|
|
|
|
|
2019-10-08 11:08:47 +08:00
|
|
|
protected IBindable<bool> MenuVoice { get; private set; }
|
2019-09-23 20:52:44 +08:00
|
|
|
|
2019-10-08 11:08:47 +08:00
|
|
|
protected IBindable<bool> MenuMusic { get; private set; }
|
2019-09-23 20:52:44 +08:00
|
|
|
|
2020-06-08 13:48:42 +08:00
|
|
|
private WorkingBeatmap initialBeatmap;
|
2019-10-08 11:05:52 +08:00
|
|
|
|
2020-08-06 17:54:08 +08:00
|
|
|
protected ITrack Track { get; private set; }
|
2019-09-23 20:52:44 +08:00
|
|
|
|
2019-10-08 11:05:52 +08:00
|
|
|
private const int exit_delay = 3000;
|
|
|
|
|
2021-01-19 16:11:40 +08:00
|
|
|
private Sample seeya;
|
2020-06-13 23:48:15 +08:00
|
|
|
|
|
|
|
protected virtual string SeeyaSampleName => "Intro/seeya";
|
2019-07-09 16:59:40 +08:00
|
|
|
|
2019-08-19 01:32:56 +08:00
|
|
|
private LeasedBindable<WorkingBeatmap> beatmap;
|
|
|
|
|
2021-10-07 15:38:22 +08:00
|
|
|
private OsuScreen nextScreen;
|
2019-07-09 16:59:40 +08:00
|
|
|
|
2019-10-08 11:05:52 +08:00
|
|
|
[Resolved]
|
|
|
|
private AudioManager audio { get; set; }
|
2019-10-08 11:03:42 +08:00
|
|
|
|
2020-09-02 19:04:56 +08:00
|
|
|
[Resolved]
|
|
|
|
private MusicController musicController { get; set; }
|
|
|
|
|
2021-10-07 15:38:22 +08:00
|
|
|
[CanBeNull]
|
|
|
|
private readonly Func<OsuScreen> createNextScreen;
|
|
|
|
|
2020-06-08 13:48:42 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether the <see cref="Track"/> is provided by osu! resources, rather than a user beatmap.
|
2020-08-21 14:50:14 +08:00
|
|
|
/// Only valid during or after <see cref="LogoArriving"/>.
|
2020-06-08 13:48:42 +08:00
|
|
|
/// </summary>
|
|
|
|
protected bool UsingThemedIntro { get; private set; }
|
|
|
|
|
2021-10-07 15:38:22 +08:00
|
|
|
protected IntroScreen([CanBeNull] Func<MainMenu> createNextScreen = null)
|
|
|
|
{
|
|
|
|
this.createNextScreen = createNextScreen;
|
|
|
|
}
|
|
|
|
|
2019-07-09 16:59:40 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2021-12-17 17:45:22 +08:00
|
|
|
private void load(OsuConfigManager config, SkinManager skinManager, BeatmapManager beatmaps, Framework.Game game, RealmContextFactory realmContextFactory)
|
2019-07-09 16:59:40 +08:00
|
|
|
{
|
2021-12-17 17:45:22 +08:00
|
|
|
// prevent user from changing beatmap while the intro is still running.
|
2019-10-08 11:04:13 +08:00
|
|
|
beatmap = Beatmap.BeginLease(false);
|
2019-08-19 01:32:56 +08:00
|
|
|
|
2019-09-23 20:52:44 +08:00
|
|
|
MenuVoice = config.GetBindable<bool>(OsuSetting.MenuVoice);
|
|
|
|
MenuMusic = config.GetBindable<bool>(OsuSetting.MenuMusic);
|
2020-06-13 23:48:15 +08:00
|
|
|
seeya = audio.Samples.Get(SeeyaSampleName);
|
2019-09-23 20:52:44 +08:00
|
|
|
|
2021-12-15 14:03:06 +08:00
|
|
|
ILive<BeatmapSetInfo> setInfo = null;
|
2019-09-23 20:52:44 +08:00
|
|
|
|
2020-06-08 13:48:42 +08:00
|
|
|
// if the user has requested not to play theme music, we should attempt to find a random beatmap from their collection.
|
2019-09-23 20:52:44 +08:00
|
|
|
if (!MenuMusic.Value)
|
|
|
|
{
|
2021-12-14 18:47:11 +08:00
|
|
|
var sets = beatmaps.GetAllUsableBeatmapSets();
|
2020-06-08 13:48:42 +08:00
|
|
|
|
2019-09-23 20:52:44 +08:00
|
|
|
if (sets.Count > 0)
|
2020-06-08 13:48:42 +08:00
|
|
|
{
|
2019-09-23 20:52:44 +08:00
|
|
|
setInfo = beatmaps.QueryBeatmapSet(s => s.ID == sets[RNG.Next(0, sets.Count - 1)].ID);
|
2021-12-17 17:45:22 +08:00
|
|
|
initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo?.PerformRead(s => s.Beatmaps[0].ToLive(realmContextFactory)));
|
2020-06-08 13:48:42 +08:00
|
|
|
}
|
2019-09-23 20:52:44 +08:00
|
|
|
}
|
|
|
|
|
2020-06-08 13:48:42 +08:00
|
|
|
// we generally want a song to be playing on startup, so use the intro music even if a user has specified not to if no other track is available.
|
2019-09-23 20:52:44 +08:00
|
|
|
if (setInfo == null)
|
|
|
|
{
|
2020-06-08 13:48:42 +08:00
|
|
|
if (!loadThemedIntro())
|
2019-09-23 20:52:44 +08:00
|
|
|
{
|
2020-06-08 13:48:42 +08:00
|
|
|
// if we detect that the theme track or beatmap is unavailable this is either first startup or things are in a bad state.
|
|
|
|
// this could happen if a user has nuked their files store. for now, reimport to repair this.
|
2022-01-06 21:54:43 +08:00
|
|
|
var import = beatmaps.Import(new ZipArchiveReader(game.Resources.GetStream($"Tracks/{BeatmapFile}"), BeatmapFile)).GetResultSafely();
|
2021-09-30 18:33:12 +08:00
|
|
|
|
2021-12-15 13:36:11 +08:00
|
|
|
import?.PerformWrite(b =>
|
2021-09-30 18:33:12 +08:00
|
|
|
{
|
|
|
|
b.Protected = true;
|
|
|
|
beatmaps.Update(b);
|
|
|
|
});
|
2019-09-23 20:52:44 +08:00
|
|
|
|
2020-06-08 13:48:42 +08:00
|
|
|
loadThemedIntro();
|
2019-09-23 20:52:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-08 13:48:42 +08:00
|
|
|
bool loadThemedIntro()
|
|
|
|
{
|
2021-12-14 18:47:11 +08:00
|
|
|
setInfo = beatmaps.QueryBeatmapSets(b => b.Hash == BeatmapHash).FirstOrDefault();
|
2020-06-08 13:48:42 +08:00
|
|
|
|
2021-02-17 18:19:49 +08:00
|
|
|
if (setInfo == null)
|
|
|
|
return false;
|
2020-06-08 13:48:42 +08:00
|
|
|
|
2021-12-17 17:45:22 +08:00
|
|
|
initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo.PerformRead(s => s.Beatmaps[0].ToLive(realmContextFactory)));
|
2021-09-09 21:04:16 +08:00
|
|
|
|
|
|
|
return UsingThemedIntro = initialBeatmap != null;
|
2020-06-08 13:48:42 +08:00
|
|
|
}
|
2019-09-23 20:52:44 +08:00
|
|
|
}
|
|
|
|
|
2019-07-09 16:59:40 +08:00
|
|
|
public override void OnResuming(IScreen last)
|
|
|
|
{
|
|
|
|
this.FadeIn(300);
|
|
|
|
|
2019-10-08 10:54:39 +08:00
|
|
|
double fadeOutTime = exit_delay;
|
2020-09-03 12:13:48 +08:00
|
|
|
|
2020-09-03 12:15:16 +08:00
|
|
|
var track = musicController.CurrentTrack;
|
|
|
|
|
|
|
|
// ensure the track doesn't change or loop as we are exiting.
|
|
|
|
track.Looping = false;
|
|
|
|
Beatmap.Disabled = true;
|
|
|
|
|
2020-05-05 09:31:11 +08:00
|
|
|
// we also handle the exit transition.
|
2019-09-23 20:52:44 +08:00
|
|
|
if (MenuVoice.Value)
|
2020-09-03 12:13:48 +08:00
|
|
|
{
|
2020-06-13 23:48:15 +08:00
|
|
|
seeya.Play();
|
2020-09-03 12:13:48 +08:00
|
|
|
|
|
|
|
// if playing the outro voice, we have more time to have fun with the background track.
|
|
|
|
// initially fade to almost silent then ramp out over the remaining time.
|
|
|
|
const double initial_fade = 200;
|
2020-09-03 12:15:16 +08:00
|
|
|
track
|
|
|
|
.VolumeTo(0.03f, initial_fade).Then()
|
|
|
|
.VolumeTo(0, fadeOutTime - initial_fade, Easing.In);
|
2020-09-03 12:13:48 +08:00
|
|
|
}
|
2019-07-09 16:59:40 +08:00
|
|
|
else
|
2020-09-03 12:13:48 +08:00
|
|
|
{
|
2019-07-09 16:59:40 +08:00
|
|
|
fadeOutTime = 500;
|
|
|
|
|
2020-09-03 12:13:48 +08:00
|
|
|
// if outro voice is turned off, just do a simple fade out.
|
2020-09-03 12:15:16 +08:00
|
|
|
track.VolumeTo(0, fadeOutTime, Easing.Out);
|
2020-09-03 12:13:48 +08:00
|
|
|
}
|
2019-07-09 16:59:40 +08:00
|
|
|
|
|
|
|
//don't want to fade out completely else we will stop running updates.
|
2020-09-03 12:13:48 +08:00
|
|
|
Game.FadeTo(0.01f, fadeOutTime).OnComplete(_ => this.Exit());
|
2019-07-09 16:59:40 +08:00
|
|
|
|
|
|
|
base.OnResuming(last);
|
|
|
|
}
|
|
|
|
|
2019-10-08 11:05:52 +08:00
|
|
|
public override void OnSuspending(IScreen next)
|
|
|
|
{
|
|
|
|
base.OnSuspending(next);
|
2020-06-08 13:48:42 +08:00
|
|
|
initialBeatmap = null;
|
2019-10-08 11:05:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBlack();
|
|
|
|
|
2021-09-09 00:21:19 +08:00
|
|
|
protected virtual void StartTrack()
|
2019-10-08 11:05:52 +08:00
|
|
|
{
|
|
|
|
// Only start the current track if it is the menu music. A beatmap's track is started when entering the Main Menu.
|
2020-06-29 07:41:47 +08:00
|
|
|
if (UsingThemedIntro)
|
2021-02-18 13:55:15 +08:00
|
|
|
Track.Start();
|
2019-10-08 11:05:52 +08:00
|
|
|
}
|
|
|
|
|
2019-07-09 16:59:40 +08:00
|
|
|
protected override void LogoArriving(OsuLogo logo, bool resuming)
|
|
|
|
{
|
|
|
|
base.LogoArriving(logo, resuming);
|
|
|
|
|
|
|
|
logo.Colour = Color4.White;
|
|
|
|
logo.Triangles = false;
|
|
|
|
logo.Ripple = false;
|
|
|
|
|
|
|
|
if (!resuming)
|
|
|
|
{
|
2020-06-08 13:48:42 +08:00
|
|
|
beatmap.Value = initialBeatmap;
|
2020-08-21 17:52:53 +08:00
|
|
|
Track = initialBeatmap.Track;
|
2019-10-08 11:03:42 +08:00
|
|
|
|
2020-09-02 19:04:56 +08:00
|
|
|
// ensure the track starts at maximum volume
|
|
|
|
musicController.CurrentTrack.FinishTransforms();
|
|
|
|
|
2019-07-09 16:59:40 +08:00
|
|
|
logo.MoveTo(new Vector2(0.5f));
|
|
|
|
logo.ScaleTo(Vector2.One);
|
|
|
|
logo.Hide();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const int quick_appear = 350;
|
2021-10-27 12:04:41 +08:00
|
|
|
int initialMovementTime = logo.Alpha > 0.2f ? quick_appear : 0;
|
2019-07-09 16:59:40 +08:00
|
|
|
|
|
|
|
logo.MoveTo(new Vector2(0.5f), initialMovementTime, Easing.OutQuint);
|
|
|
|
|
|
|
|
logo
|
|
|
|
.ScaleTo(1, initialMovementTime, Easing.OutQuint)
|
|
|
|
.FadeIn(quick_appear, Easing.OutQuint)
|
|
|
|
.Then()
|
2019-10-08 10:54:39 +08:00
|
|
|
.RotateTo(20, exit_delay * 1.5f)
|
|
|
|
.FadeOut(exit_delay);
|
2019-07-09 16:59:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-07 15:38:22 +08:00
|
|
|
protected void PrepareMenuLoad()
|
|
|
|
{
|
|
|
|
nextScreen = createNextScreen?.Invoke();
|
|
|
|
|
|
|
|
if (nextScreen != null)
|
|
|
|
LoadComponentAsync(nextScreen);
|
|
|
|
}
|
2019-07-09 16:59:40 +08:00
|
|
|
|
|
|
|
protected void LoadMenu()
|
|
|
|
{
|
2019-08-20 17:18:41 +08:00
|
|
|
beatmap.Return();
|
2019-08-19 01:32:56 +08:00
|
|
|
|
2019-08-21 13:01:07 +08:00
|
|
|
DidLoadMenu = true;
|
2021-10-07 15:38:22 +08:00
|
|
|
if (nextScreen != null)
|
|
|
|
this.Push(nextScreen);
|
2019-07-09 16:59:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|