2019-07-09 08:59:40 +00: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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2021-10-07 07:38:22 +00:00
|
|
|
using System;
|
2021-08-20 10:33:47 +00:00
|
|
|
using System.Linq;
|
2021-10-07 07:38:22 +00:00
|
|
|
using JetBrains.Annotations;
|
2019-07-09 08:59:40 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
2019-09-23 12:52:44 +00:00
|
|
|
using osu.Framework.Audio.Track;
|
2019-07-09 08:59:40 +00:00
|
|
|
using osu.Framework.Bindables;
|
2022-01-03 08:31:12 +00:00
|
|
|
using osu.Framework.Extensions;
|
2019-07-09 08:59:40 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Screens;
|
2021-10-07 07:38:22 +00:00
|
|
|
using osu.Framework.Utils;
|
2022-03-10 02:52:20 +00:00
|
|
|
using osu.Game.Audio;
|
2019-07-09 08:59:40 +00:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Configuration;
|
2021-12-15 06:03:06 +00:00
|
|
|
using osu.Game.Database;
|
2019-09-23 12:52:44 +00:00
|
|
|
using osu.Game.IO.Archives;
|
2022-03-10 02:52:20 +00:00
|
|
|
using osu.Game.Online.API;
|
2020-09-02 11:04:56 +00:00
|
|
|
using osu.Game.Overlays;
|
2022-01-30 09:37:00 +00:00
|
|
|
using osu.Game.Overlays.Notifications;
|
2022-02-21 07:21:36 +00:00
|
|
|
using osu.Game.Rulesets;
|
2019-07-09 08:59:40 +00:00
|
|
|
using osu.Game.Screens.Backgrounds;
|
2022-03-10 02:52:20 +00:00
|
|
|
using osu.Game.Skinning;
|
2019-07-09 08:59:40 +00:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2022-01-21 08:55:27 +00:00
|
|
|
using Realms;
|
2019-07-09 08:59:40 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Menu
|
|
|
|
{
|
|
|
|
public abstract class IntroScreen : StartupScreen
|
|
|
|
{
|
2019-10-08 03:05:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Whether we have loaded the menu previously.
|
|
|
|
/// </summary>
|
|
|
|
public bool DidLoadMenu { get; private set; }
|
|
|
|
|
2019-10-08 02:52:16 +00:00
|
|
|
/// <summary>
|
|
|
|
/// A hash used to find the associated beatmap if already imported.
|
|
|
|
/// </summary>
|
2019-09-23 12:52:44 +00:00
|
|
|
protected abstract string BeatmapHash { get; }
|
|
|
|
|
2019-10-08 02:52:16 +00: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 12:52:44 +00:00
|
|
|
protected abstract string BeatmapFile { get; }
|
|
|
|
|
2019-10-08 03:08:47 +00:00
|
|
|
protected IBindable<bool> MenuVoice { get; private set; }
|
2019-09-23 12:52:44 +00:00
|
|
|
|
2019-10-08 03:08:47 +00:00
|
|
|
protected IBindable<bool> MenuMusic { get; private set; }
|
2019-09-23 12:52:44 +00:00
|
|
|
|
2020-06-08 05:48:42 +00:00
|
|
|
private WorkingBeatmap initialBeatmap;
|
2019-10-08 03:05:52 +00:00
|
|
|
|
2020-08-06 09:54:08 +00:00
|
|
|
protected ITrack Track { get; private set; }
|
2019-09-23 12:52:44 +00:00
|
|
|
|
2019-10-08 03:05:52 +00:00
|
|
|
private const int exit_delay = 3000;
|
|
|
|
|
2022-03-10 02:52:20 +00:00
|
|
|
private SkinnableSound skinnableSeeya;
|
|
|
|
private ISample seeya;
|
2020-06-13 15:48:15 +00:00
|
|
|
|
|
|
|
protected virtual string SeeyaSampleName => "Intro/seeya";
|
2019-07-09 08:59:40 +00:00
|
|
|
|
2022-06-15 08:37:30 +00:00
|
|
|
protected override bool PlayExitSound => false;
|
|
|
|
|
2019-08-18 17:32:56 +00:00
|
|
|
private LeasedBindable<WorkingBeatmap> beatmap;
|
|
|
|
|
2021-10-07 07:38:22 +00:00
|
|
|
private OsuScreen nextScreen;
|
2019-07-09 08:59:40 +00:00
|
|
|
|
2019-10-08 03:05:52 +00:00
|
|
|
[Resolved]
|
|
|
|
private AudioManager audio { get; set; }
|
2019-10-08 03:03:42 +00:00
|
|
|
|
2020-09-02 11:04:56 +00:00
|
|
|
[Resolved]
|
|
|
|
private MusicController musicController { get; set; }
|
|
|
|
|
2021-10-07 07:38:22 +00:00
|
|
|
[CanBeNull]
|
|
|
|
private readonly Func<OsuScreen> createNextScreen;
|
|
|
|
|
2022-02-21 07:21:36 +00:00
|
|
|
[Resolved]
|
|
|
|
private RulesetStore rulesets { get; set; }
|
|
|
|
|
2020-06-08 05:48:42 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Whether the <see cref="Track"/> is provided by osu! resources, rather than a user beatmap.
|
2020-08-21 06:50:14 +00:00
|
|
|
/// Only valid during or after <see cref="LogoArriving"/>.
|
2020-06-08 05:48:42 +00:00
|
|
|
/// </summary>
|
|
|
|
protected bool UsingThemedIntro { get; private set; }
|
|
|
|
|
2021-10-07 07:38:22 +00:00
|
|
|
protected IntroScreen([CanBeNull] Func<MainMenu> createNextScreen = null)
|
|
|
|
{
|
|
|
|
this.createNextScreen = createNextScreen;
|
|
|
|
}
|
|
|
|
|
2021-12-22 08:05:00 +00:00
|
|
|
[Resolved]
|
|
|
|
private BeatmapManager beatmaps { get; set; }
|
|
|
|
|
2019-07-09 08:59:40 +00:00
|
|
|
[BackgroundDependencyLoader]
|
2022-03-10 02:52:20 +00:00
|
|
|
private void load(OsuConfigManager config, Framework.Game game, RealmAccess realm, IAPIProvider api)
|
2019-07-09 08:59:40 +00:00
|
|
|
{
|
2021-12-17 09:45:22 +00:00
|
|
|
// prevent user from changing beatmap while the intro is still running.
|
2019-10-08 03:04:13 +00:00
|
|
|
beatmap = Beatmap.BeginLease(false);
|
2019-08-18 17:32:56 +00:00
|
|
|
|
2019-09-23 12:52:44 +00:00
|
|
|
MenuVoice = config.GetBindable<bool>(OsuSetting.MenuVoice);
|
|
|
|
MenuMusic = config.GetBindable<bool>(OsuSetting.MenuMusic);
|
2022-03-10 02:52:20 +00:00
|
|
|
|
|
|
|
if (api.LocalUser.Value.IsSupporter)
|
|
|
|
AddInternal(skinnableSeeya = new SkinnableSound(new SampleInfo(SeeyaSampleName)));
|
|
|
|
else
|
|
|
|
seeya = audio.Samples.Get(SeeyaSampleName);
|
2019-09-23 12:52:44 +00:00
|
|
|
|
2020-06-08 05:48:42 +00: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 12:52:44 +00:00
|
|
|
if (!MenuMusic.Value)
|
|
|
|
{
|
2022-01-24 10:59:58 +00:00
|
|
|
realm.Run(r =>
|
2020-06-08 05:48:42 +00:00
|
|
|
{
|
2022-01-24 10:59:58 +00:00
|
|
|
var usableBeatmapSets = r.All<BeatmapSetInfo>().Where(s => !s.DeletePending && !s.Protected).AsRealmCollection();
|
2022-01-21 08:55:27 +00:00
|
|
|
|
2022-01-23 08:51:32 +00:00
|
|
|
int setCount = usableBeatmapSets.Count;
|
2022-01-21 08:55:27 +00:00
|
|
|
|
2022-01-21 20:09:40 +00:00
|
|
|
if (setCount > 0)
|
2021-12-22 08:05:00 +00:00
|
|
|
{
|
2022-01-23 08:51:32 +00:00
|
|
|
var found = usableBeatmapSets[RNG.Next(0, setCount - 1)].Beatmaps.FirstOrDefault();
|
2021-12-22 08:05:00 +00:00
|
|
|
|
2022-01-21 08:55:27 +00:00
|
|
|
if (found != null)
|
|
|
|
initialBeatmap = beatmaps.GetWorkingBeatmap(found);
|
|
|
|
}
|
|
|
|
});
|
2022-01-23 08:51:32 +00:00
|
|
|
}
|
2019-09-23 12:52:44 +00:00
|
|
|
|
2022-01-23 08:51:32 +00: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.
|
|
|
|
if (initialBeatmap == null)
|
|
|
|
{
|
2022-02-21 07:21:36 +00:00
|
|
|
// Intro beatmaps are generally made using the osu! ruleset.
|
|
|
|
// It might not be present in test projects for other rulesets.
|
|
|
|
bool osuRulesetPresent = rulesets.GetRuleset(0) != null;
|
|
|
|
|
|
|
|
if (!loadThemedIntro() && osuRulesetPresent)
|
2019-09-23 12:52:44 +00:00
|
|
|
{
|
2022-01-23 08:51:32 +00: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.
|
|
|
|
var import = beatmaps.Import(new ZipArchiveReader(game.Resources.GetStream($"Tracks/{BeatmapFile}"), BeatmapFile)).GetResultSafely();
|
2021-09-30 10:33:12 +00:00
|
|
|
|
2022-01-23 08:51:32 +00:00
|
|
|
import?.PerformWrite(b => b.Protected = true);
|
2019-09-23 12:52:44 +00:00
|
|
|
|
2022-01-23 08:51:32 +00:00
|
|
|
loadThemedIntro();
|
2019-09-23 12:52:44 +00:00
|
|
|
}
|
2022-01-23 08:51:32 +00:00
|
|
|
}
|
2019-09-23 12:52:44 +00:00
|
|
|
|
2022-01-23 08:51:32 +00:00
|
|
|
bool loadThemedIntro()
|
|
|
|
{
|
2022-04-06 07:46:52 +00:00
|
|
|
var setInfo = beatmaps.QueryBeatmapSet(b => b.Protected && b.Hash == BeatmapHash);
|
2020-06-08 05:48:42 +00:00
|
|
|
|
2022-01-23 08:51:32 +00:00
|
|
|
if (setInfo == null)
|
|
|
|
return false;
|
2020-06-08 05:48:42 +00:00
|
|
|
|
2022-01-23 08:51:32 +00:00
|
|
|
setInfo.PerformRead(s =>
|
|
|
|
{
|
|
|
|
if (s.Beatmaps.Count == 0)
|
|
|
|
return;
|
2021-12-22 08:05:00 +00:00
|
|
|
|
2022-01-23 08:51:32 +00:00
|
|
|
initialBeatmap = beatmaps.GetWorkingBeatmap(s.Beatmaps.First());
|
|
|
|
});
|
2021-09-09 13:04:16 +00:00
|
|
|
|
2022-01-23 08:51:32 +00:00
|
|
|
return UsingThemedIntro = initialBeatmap != null;
|
2020-06-08 05:48:42 +00:00
|
|
|
}
|
2019-09-23 12:52:44 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 15:52:44 +00:00
|
|
|
public override void OnEntering(ScreenTransitionEvent e)
|
2022-01-30 09:37:00 +00:00
|
|
|
{
|
2022-04-21 15:52:44 +00:00
|
|
|
base.OnEntering(e);
|
2022-01-30 09:37:00 +00:00
|
|
|
ensureEventuallyArrivingAtMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Resolved]
|
2022-04-18 10:59:57 +00:00
|
|
|
private INotificationOverlay notifications { get; set; }
|
2022-01-30 09:37:00 +00:00
|
|
|
|
|
|
|
private void ensureEventuallyArrivingAtMenu()
|
|
|
|
{
|
|
|
|
// This intends to handle the case where an intro may get stuck.
|
|
|
|
// Historically, this could happen if the host system's audio device is in a state it can't
|
|
|
|
// play audio, causing a clock to never elapse time and the intro to never end.
|
|
|
|
//
|
|
|
|
// This safety measure gives the user a chance to fix the problem from the settings menu.
|
|
|
|
Scheduler.AddDelayed(() =>
|
|
|
|
{
|
|
|
|
if (DidLoadMenu)
|
|
|
|
return;
|
|
|
|
|
|
|
|
PrepareMenuLoad();
|
|
|
|
LoadMenu();
|
|
|
|
notifications.Post(new SimpleErrorNotification
|
|
|
|
{
|
|
|
|
Text = "osu! doesn't seem to be able to play audio correctly.\n\nPlease try changing your audio device to a working setting."
|
|
|
|
});
|
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
|
2022-04-21 15:52:44 +00:00
|
|
|
public override void OnResuming(ScreenTransitionEvent e)
|
2019-07-09 08:59:40 +00:00
|
|
|
{
|
|
|
|
this.FadeIn(300);
|
|
|
|
|
2019-10-08 02:54:39 +00:00
|
|
|
double fadeOutTime = exit_delay;
|
2020-09-03 04:13:48 +00:00
|
|
|
|
2020-09-03 04:15:16 +00: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 01:31:11 +00:00
|
|
|
// we also handle the exit transition.
|
2019-09-23 12:52:44 +00:00
|
|
|
if (MenuVoice.Value)
|
2020-09-03 04:13:48 +00:00
|
|
|
{
|
2022-03-10 14:25:13 +00:00
|
|
|
if (skinnableSeeya != null)
|
2022-03-10 02:52:20 +00:00
|
|
|
{
|
2022-03-10 14:25:13 +00:00
|
|
|
// resuming a screen (i.e. calling OnResume) happens before the screen itself becomes alive,
|
|
|
|
// therefore skinnable samples may not be updated yet with the recently selected skin.
|
|
|
|
// schedule after children to ensure skinnable samples have processed skin changes before playing.
|
|
|
|
ScheduleAfterChildren(() => skinnableSeeya.Play());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
seeya.Play();
|
2020-09-03 04:13:48 +00: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 04:15:16 +00:00
|
|
|
track
|
|
|
|
.VolumeTo(0.03f, initial_fade).Then()
|
|
|
|
.VolumeTo(0, fadeOutTime - initial_fade, Easing.In);
|
2020-09-03 04:13:48 +00:00
|
|
|
}
|
2019-07-09 08:59:40 +00:00
|
|
|
else
|
2020-09-03 04:13:48 +00:00
|
|
|
{
|
2019-07-09 08:59:40 +00:00
|
|
|
fadeOutTime = 500;
|
|
|
|
|
2020-09-03 04:13:48 +00:00
|
|
|
// if outro voice is turned off, just do a simple fade out.
|
2020-09-03 04:15:16 +00:00
|
|
|
track.VolumeTo(0, fadeOutTime, Easing.Out);
|
2020-09-03 04:13:48 +00:00
|
|
|
}
|
2019-07-09 08:59:40 +00:00
|
|
|
|
|
|
|
//don't want to fade out completely else we will stop running updates.
|
2020-09-03 04:13:48 +00:00
|
|
|
Game.FadeTo(0.01f, fadeOutTime).OnComplete(_ => this.Exit());
|
2019-07-09 08:59:40 +00:00
|
|
|
|
2022-04-21 15:52:44 +00:00
|
|
|
base.OnResuming(e);
|
2019-07-09 08:59:40 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 15:52:44 +00:00
|
|
|
public override void OnSuspending(ScreenTransitionEvent e)
|
2019-10-08 03:05:52 +00:00
|
|
|
{
|
2022-04-21 15:52:44 +00:00
|
|
|
base.OnSuspending(e);
|
2020-06-08 05:48:42 +00:00
|
|
|
initialBeatmap = null;
|
2019-10-08 03:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBlack();
|
|
|
|
|
2021-09-08 16:21:19 +00:00
|
|
|
protected virtual void StartTrack()
|
2019-10-08 03:05:52 +00: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-28 23:41:47 +00:00
|
|
|
if (UsingThemedIntro)
|
2021-02-18 05:55:15 +00:00
|
|
|
Track.Start();
|
2019-10-08 03:05:52 +00:00
|
|
|
}
|
|
|
|
|
2019-07-09 08:59:40 +00: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)
|
|
|
|
{
|
2022-01-11 12:32:01 +00:00
|
|
|
// generally this can never be null
|
2022-01-13 04:47:23 +00:00
|
|
|
// an exception is running ruleset tests, where the osu! ruleset may not be present (causing importing the intro to fail).
|
2022-01-11 12:32:01 +00:00
|
|
|
if (initialBeatmap != null)
|
|
|
|
beatmap.Value = initialBeatmap;
|
2022-01-11 10:25:50 +00:00
|
|
|
Track = beatmap.Value.Track;
|
2019-10-08 03:03:42 +00:00
|
|
|
|
2020-09-02 11:04:56 +00:00
|
|
|
// ensure the track starts at maximum volume
|
|
|
|
musicController.CurrentTrack.FinishTransforms();
|
|
|
|
|
2019-07-09 08:59:40 +00:00
|
|
|
logo.MoveTo(new Vector2(0.5f));
|
|
|
|
logo.ScaleTo(Vector2.One);
|
|
|
|
logo.Hide();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const int quick_appear = 350;
|
2021-10-27 04:04:41 +00:00
|
|
|
int initialMovementTime = logo.Alpha > 0.2f ? quick_appear : 0;
|
2019-07-09 08:59:40 +00: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 02:54:39 +00:00
|
|
|
.RotateTo(20, exit_delay * 1.5f)
|
|
|
|
.FadeOut(exit_delay);
|
2019-07-09 08:59:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-07 07:38:22 +00:00
|
|
|
protected void PrepareMenuLoad()
|
|
|
|
{
|
2022-01-30 09:37:00 +00:00
|
|
|
if (nextScreen != null)
|
|
|
|
return;
|
|
|
|
|
2021-10-07 07:38:22 +00:00
|
|
|
nextScreen = createNextScreen?.Invoke();
|
|
|
|
|
|
|
|
if (nextScreen != null)
|
|
|
|
LoadComponentAsync(nextScreen);
|
|
|
|
}
|
2019-07-09 08:59:40 +00:00
|
|
|
|
|
|
|
protected void LoadMenu()
|
|
|
|
{
|
2022-01-30 09:37:00 +00:00
|
|
|
if (DidLoadMenu)
|
|
|
|
return;
|
|
|
|
|
2019-08-20 09:18:41 +00:00
|
|
|
beatmap.Return();
|
2019-08-18 17:32:56 +00:00
|
|
|
|
2019-08-21 05:01:07 +00:00
|
|
|
DidLoadMenu = true;
|
2021-10-07 07:38:22 +00:00
|
|
|
if (nextScreen != null)
|
|
|
|
this.Push(nextScreen);
|
2019-07-09 08:59:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|