2017-02-07 04:59:30 +00:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-10-05 07:35:10 +00:00
|
|
|
|
|
2017-07-19 04:32:16 +00:00
|
|
|
|
using System;
|
2016-11-10 22:40:42 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2016-10-28 10:55:48 +00:00
|
|
|
|
using osu.Framework.Configuration;
|
2017-02-17 09:59:30 +00:00
|
|
|
|
using osu.Framework.Screens;
|
2016-10-28 10:55:48 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
2016-10-05 11:03:52 +00:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-05-12 10:03:21 +00:00
|
|
|
|
using OpenTK;
|
2017-06-28 17:19:04 +00:00
|
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
|
using osu.Framework.Audio;
|
2017-11-01 11:54:58 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-07-26 04:22:46 +00:00
|
|
|
|
using osu.Game.Rulesets;
|
2017-11-01 11:54:58 +00:00
|
|
|
|
using osu.Game.Screens.Menu;
|
2016-10-05 07:35:10 +00:00
|
|
|
|
|
2016-11-14 08:23:33 +00:00
|
|
|
|
namespace osu.Game.Screens
|
2016-10-05 07:35:10 +00:00
|
|
|
|
{
|
2017-02-17 09:59:30 +00:00
|
|
|
|
public abstract class OsuScreen : Screen
|
2016-10-05 07:35:10 +00:00
|
|
|
|
{
|
2017-11-01 07:57:59 +00:00
|
|
|
|
public BackgroundScreen Background { get; private set; }
|
2016-10-05 07:35:10 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-04-18 07:05:58 +00:00
|
|
|
|
/// Override to create a BackgroundMode for the current screen.
|
2016-10-05 07:35:10 +00:00
|
|
|
|
/// Note that the instance created may not be the used instance if it matches the BackgroundMode equality clause.
|
|
|
|
|
/// </summary>
|
2017-02-17 09:59:30 +00:00
|
|
|
|
protected virtual BackgroundScreen CreateBackground() => null;
|
2016-10-05 07:35:10 +00:00
|
|
|
|
|
2017-11-01 07:57:59 +00:00
|
|
|
|
public virtual bool ShowOverlays => true;
|
2016-11-09 06:22:54 +00:00
|
|
|
|
|
2016-11-12 10:44:16 +00:00
|
|
|
|
protected new OsuGameBase Game => base.Game as OsuGameBase;
|
2016-11-09 06:22:54 +00:00
|
|
|
|
|
2017-11-01 07:57:59 +00:00
|
|
|
|
public virtual bool HasLocalCursorDisplayed => false;
|
2017-03-16 14:58:36 +00:00
|
|
|
|
|
2017-11-01 11:54:58 +00:00
|
|
|
|
private OsuLogo logo;
|
|
|
|
|
|
2017-07-11 09:39:10 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the beatmap or ruleset should be allowed to be changed by the user or game.
|
|
|
|
|
/// Used to mark exclusive areas where this is strongly prohibited, like gameplay.
|
|
|
|
|
/// </summary>
|
2017-11-01 07:57:59 +00:00
|
|
|
|
public virtual bool AllowBeatmapRulesetChange => true;
|
2017-04-21 07:03:59 +00:00
|
|
|
|
|
2017-07-19 04:32:16 +00:00
|
|
|
|
protected readonly Bindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
|
2016-10-28 10:55:48 +00:00
|
|
|
|
|
2017-07-19 04:32:16 +00:00
|
|
|
|
public WorkingBeatmap InitialBeatmap
|
2016-10-28 10:55:48 +00:00
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-07-19 04:32:16 +00:00
|
|
|
|
if (IsLoaded) throw new InvalidOperationException($"Cannot set {nameof(InitialBeatmap)} post-load.");
|
|
|
|
|
Beatmap.Value = value;
|
2016-10-28 10:55:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-24 13:47:31 +00:00
|
|
|
|
protected readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
|
2017-07-19 04:32:16 +00:00
|
|
|
|
|
|
|
|
|
private SampleChannel sampleExit;
|
|
|
|
|
|
2016-11-12 10:44:16 +00:00
|
|
|
|
[BackgroundDependencyLoader(permitNulls: true)]
|
2017-07-19 04:32:16 +00:00
|
|
|
|
private void load(OsuGameBase game, OsuGame osuGame, AudioManager audio)
|
2016-10-28 13:03:59 +00:00
|
|
|
|
{
|
2017-02-27 03:24:50 +00:00
|
|
|
|
if (game != null)
|
2017-02-27 09:08:05 +00:00
|
|
|
|
{
|
|
|
|
|
//if we were given a beatmap at ctor time, we want to pass this on to the game-wide beatmap.
|
2017-07-19 04:32:16 +00:00
|
|
|
|
var localMap = Beatmap.Value;
|
|
|
|
|
Beatmap.BindTo(game.Beatmap);
|
2017-02-27 09:08:05 +00:00
|
|
|
|
if (localMap != null)
|
2017-07-19 04:32:16 +00:00
|
|
|
|
Beatmap.Value = localMap;
|
2017-02-27 09:08:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-21 07:03:59 +00:00
|
|
|
|
if (osuGame != null)
|
2017-07-24 13:47:31 +00:00
|
|
|
|
Ruleset.BindTo(osuGame.Ruleset);
|
2017-06-28 17:19:04 +00:00
|
|
|
|
|
|
|
|
|
sampleExit = audio.Sample.Get(@"UI/melodic-1");
|
2016-10-28 10:55:48 +00:00
|
|
|
|
}
|
2017-05-21 23:53:36 +00:00
|
|
|
|
|
2017-06-28 17:19:04 +00:00
|
|
|
|
protected override void OnResuming(Screen last)
|
|
|
|
|
{
|
|
|
|
|
base.OnResuming(last);
|
2017-11-09 08:38:20 +00:00
|
|
|
|
logo.DelayUntilTransformsFinished().Schedule(() => LogoArriving(logo, true));
|
2017-06-28 17:19:04 +00:00
|
|
|
|
sampleExit?.Play();
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-01 11:54:58 +00:00
|
|
|
|
protected override void OnSuspending(Screen next)
|
|
|
|
|
{
|
|
|
|
|
base.OnSuspending(next);
|
2017-11-08 07:34:03 +00:00
|
|
|
|
onSuspendingLogo();
|
2017-11-01 11:54:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 09:59:30 +00:00
|
|
|
|
protected override void OnEntering(Screen last)
|
2016-10-05 07:35:10 +00:00
|
|
|
|
{
|
2017-02-17 09:59:30 +00:00
|
|
|
|
OsuScreen lastOsu = last as OsuScreen;
|
2016-10-05 07:35:10 +00:00
|
|
|
|
|
2017-02-17 09:59:30 +00:00
|
|
|
|
BackgroundScreen bg = CreateBackground();
|
2016-10-05 07:35:10 +00:00
|
|
|
|
|
|
|
|
|
if (lastOsu?.Background != null)
|
|
|
|
|
{
|
|
|
|
|
if (bg == null || lastOsu.Background.Equals(bg))
|
|
|
|
|
//we can keep the previous mode's background.
|
|
|
|
|
Background = lastOsu.Background;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
lastOsu.Background.Push(Background = bg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (bg != null)
|
|
|
|
|
{
|
2017-05-12 10:03:21 +00:00
|
|
|
|
// this makes up for the fact our padding changes when the global toolbar is visible.
|
|
|
|
|
bg.Scale = new Vector2(1.06f);
|
|
|
|
|
|
2016-10-09 09:56:41 +00:00
|
|
|
|
AddInternal(new ParallaxContainer
|
2016-10-05 11:03:52 +00:00
|
|
|
|
{
|
2016-11-29 19:50:12 +00:00
|
|
|
|
Depth = float.MaxValue,
|
2016-10-05 11:03:52 +00:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
Background = bg
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-10-05 07:35:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-01 11:54:58 +00:00
|
|
|
|
if ((logo = lastOsu?.logo) == null)
|
2017-11-12 06:59:11 +00:00
|
|
|
|
LoadComponentAsync(logo = new OsuLogo(), AddInternal);
|
2017-11-01 11:54:58 +00:00
|
|
|
|
|
2016-10-05 07:35:10 +00:00
|
|
|
|
base.OnEntering(last);
|
2017-11-01 11:54:58 +00:00
|
|
|
|
|
2017-11-09 08:38:20 +00:00
|
|
|
|
logo.DelayUntilTransformsFinished().Schedule(() => LogoArriving(logo, false));
|
2016-10-05 07:35:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 09:59:30 +00:00
|
|
|
|
protected override bool OnExiting(Screen next)
|
2016-10-05 07:35:10 +00:00
|
|
|
|
{
|
2017-11-01 11:54:58 +00:00
|
|
|
|
if (ValidForResume && logo != null)
|
2017-11-08 07:34:03 +00:00
|
|
|
|
onExitingLogo();
|
2017-11-01 11:54:58 +00:00
|
|
|
|
|
2017-02-17 09:59:30 +00:00
|
|
|
|
OsuScreen nextOsu = next as OsuScreen;
|
2016-10-05 07:35:10 +00:00
|
|
|
|
|
|
|
|
|
if (Background != null && !Background.Equals(nextOsu?.Background))
|
2016-10-07 11:35:44 +00:00
|
|
|
|
{
|
|
|
|
|
if (nextOsu != null)
|
2017-04-18 07:05:58 +00:00
|
|
|
|
//We need to use MakeCurrent in case we are jumping up multiple game screens.
|
2017-01-20 08:20:56 +00:00
|
|
|
|
nextOsu.Background?.MakeCurrent();
|
2016-10-07 11:35:44 +00:00
|
|
|
|
else
|
|
|
|
|
Background.Exit();
|
|
|
|
|
}
|
2016-10-05 07:35:10 +00:00
|
|
|
|
|
2017-05-23 13:30:15 +00:00
|
|
|
|
if (base.OnExiting(next))
|
|
|
|
|
return true;
|
|
|
|
|
|
2017-07-19 04:32:16 +00:00
|
|
|
|
Beatmap.UnbindAll();
|
2017-05-23 13:30:15 +00:00
|
|
|
|
return false;
|
2016-10-05 07:35:10 +00:00
|
|
|
|
}
|
2017-11-01 11:54:58 +00:00
|
|
|
|
|
2017-11-08 07:34:03 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fired when this screen was entered or resumed and the logo state is required to be adjusted.
|
|
|
|
|
/// </summary>
|
2017-11-09 08:38:20 +00:00
|
|
|
|
protected virtual void LogoArriving(OsuLogo logo, bool resuming)
|
2017-11-01 11:54:58 +00:00
|
|
|
|
{
|
|
|
|
|
logo.Action = null;
|
|
|
|
|
logo.FadeOut(300, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-08 07:34:03 +00:00
|
|
|
|
private void onExitingLogo()
|
2017-11-01 11:54:58 +00:00
|
|
|
|
{
|
|
|
|
|
logo.ClearTransforms();
|
2017-11-09 08:38:20 +00:00
|
|
|
|
LogoExiting(logo);
|
2017-11-01 11:54:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-08 07:34:03 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fired when this screen was exited to add any outwards transition to the logo.
|
|
|
|
|
/// </summary>
|
2017-11-09 08:38:20 +00:00
|
|
|
|
protected virtual void LogoExiting(OsuLogo logo)
|
2017-11-01 11:54:58 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-08 07:34:03 +00:00
|
|
|
|
private void onSuspendingLogo()
|
2017-11-01 11:54:58 +00:00
|
|
|
|
{
|
|
|
|
|
logo.ClearTransforms();
|
2017-11-09 08:38:20 +00:00
|
|
|
|
LogoSuspending(logo);
|
2017-11-01 11:54:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-08 07:34:03 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fired when this screen was suspended to add any outwards transition to the logo.
|
|
|
|
|
/// </summary>
|
2017-11-09 08:38:20 +00:00
|
|
|
|
protected virtual void LogoSuspending(OsuLogo logo)
|
2017-11-01 11:54:58 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2016-10-05 07:35:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|