2017-02-07 12:59:30 +08: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 15:35:10 +08:00
|
|
|
|
|
2016-11-11 06:40:42 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2016-10-28 18:55:48 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2017-02-17 17:59:30 +08:00
|
|
|
|
using osu.Framework.Screens;
|
2016-10-28 18:55:48 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2017-04-21 15:03:59 +08:00
|
|
|
|
using osu.Game.Database;
|
2016-10-05 19:03:52 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-05-12 18:03:21 +08:00
|
|
|
|
using OpenTK;
|
2016-10-05 15:35:10 +08:00
|
|
|
|
|
2016-11-14 16:23:33 +08:00
|
|
|
|
namespace osu.Game.Screens
|
2016-10-05 15:35:10 +08:00
|
|
|
|
{
|
2017-02-17 17:59:30 +08:00
|
|
|
|
public abstract class OsuScreen : Screen
|
2016-10-05 15:35:10 +08:00
|
|
|
|
{
|
2017-02-17 17:59:30 +08:00
|
|
|
|
internal BackgroundScreen Background { get; private set; }
|
2016-10-05 15:35:10 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-04-18 15:05:58 +08:00
|
|
|
|
/// Override to create a BackgroundMode for the current screen.
|
2016-10-05 15:35:10 +08:00
|
|
|
|
/// Note that the instance created may not be the used instance if it matches the BackgroundMode equality clause.
|
|
|
|
|
/// </summary>
|
2017-02-17 17:59:30 +08:00
|
|
|
|
protected virtual BackgroundScreen CreateBackground() => null;
|
2016-10-05 15:35:10 +08:00
|
|
|
|
|
2016-11-15 19:43:43 +08:00
|
|
|
|
internal virtual bool ShowOverlays => true;
|
2016-11-09 14:22:54 +08:00
|
|
|
|
|
2016-11-12 18:44:16 +08:00
|
|
|
|
protected new OsuGameBase Game => base.Game as OsuGameBase;
|
2016-11-09 14:22:54 +08:00
|
|
|
|
|
2017-03-16 22:58:36 +08:00
|
|
|
|
internal virtual bool HasLocalCursorDisplayed => false;
|
|
|
|
|
|
2017-04-21 15:03:59 +08:00
|
|
|
|
internal virtual bool AllowRulesetChange => true;
|
|
|
|
|
|
2017-02-26 21:08:21 +08:00
|
|
|
|
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
2016-10-28 18:55:48 +08:00
|
|
|
|
|
2017-04-21 15:03:59 +08:00
|
|
|
|
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
|
|
|
|
|
2016-10-28 18:55:48 +08:00
|
|
|
|
public WorkingBeatmap Beatmap
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return beatmap.Value;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
beatmap.Value = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 18:44:16 +08:00
|
|
|
|
[BackgroundDependencyLoader(permitNulls: true)]
|
2017-04-21 15:03:59 +08:00
|
|
|
|
private void load(OsuGameBase game, OsuGame osuGame)
|
2016-10-28 21:03:59 +08:00
|
|
|
|
{
|
2017-02-27 11:24:50 +08:00
|
|
|
|
if (game != null)
|
2017-02-27 17:08:05 +08:00
|
|
|
|
{
|
|
|
|
|
//if we were given a beatmap at ctor time, we want to pass this on to the game-wide beatmap.
|
|
|
|
|
var localMap = beatmap.Value;
|
2017-02-27 11:24:50 +08:00
|
|
|
|
beatmap.BindTo(game.Beatmap);
|
2017-02-27 17:08:05 +08:00
|
|
|
|
if (localMap != null)
|
|
|
|
|
beatmap.Value = localMap;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-21 15:03:59 +08:00
|
|
|
|
if (osuGame != null)
|
|
|
|
|
ruleset.BindTo(osuGame.Ruleset);
|
2016-10-28 18:55:48 +08:00
|
|
|
|
}
|
2017-05-22 07:53:36 +08:00
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
beatmap.ValueChanged += OnBeatmapChanged;
|
|
|
|
|
}
|
2016-10-28 18:55:48 +08:00
|
|
|
|
|
2017-04-21 15:03:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The global Beatmap was changed.
|
|
|
|
|
/// </summary>
|
2016-10-28 18:55:48 +08:00
|
|
|
|
protected virtual void OnBeatmapChanged(WorkingBeatmap beatmap)
|
|
|
|
|
{
|
2017-04-21 15:03:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
if (!IsCurrentScreen) return;
|
2016-10-28 18:55:48 +08:00
|
|
|
|
|
2017-04-21 15:03:59 +08:00
|
|
|
|
ruleset.Disabled = !AllowRulesetChange;
|
2016-10-28 18:55:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 17:59:30 +08:00
|
|
|
|
protected override void OnEntering(Screen last)
|
2016-10-05 15:35:10 +08:00
|
|
|
|
{
|
2017-02-17 17:59:30 +08:00
|
|
|
|
OsuScreen lastOsu = last as OsuScreen;
|
2016-10-05 15:35:10 +08:00
|
|
|
|
|
2017-02-17 17:59:30 +08:00
|
|
|
|
BackgroundScreen bg = CreateBackground();
|
2016-10-05 15:35:10 +08:00
|
|
|
|
|
2017-03-15 18:09:30 +08:00
|
|
|
|
OnBeatmapChanged(Beatmap);
|
|
|
|
|
|
2016-10-05 15:35:10 +08: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 18:03:21 +08: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 17:56:41 +08:00
|
|
|
|
AddInternal(new ParallaxContainer
|
2016-10-05 19:03:52 +08:00
|
|
|
|
{
|
2016-11-30 03:50:12 +08:00
|
|
|
|
Depth = float.MaxValue,
|
2016-10-05 19:03:52 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
Background = bg
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-10-05 15:35:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.OnEntering(last);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 17:59:30 +08:00
|
|
|
|
protected override bool OnExiting(Screen next)
|
2016-10-05 15:35:10 +08:00
|
|
|
|
{
|
2017-02-17 17:59:30 +08:00
|
|
|
|
OsuScreen nextOsu = next as OsuScreen;
|
2016-10-05 15:35:10 +08:00
|
|
|
|
|
|
|
|
|
if (Background != null && !Background.Equals(nextOsu?.Background))
|
2016-10-07 19:35:44 +08:00
|
|
|
|
{
|
|
|
|
|
if (nextOsu != null)
|
2017-04-18 15:05:58 +08:00
|
|
|
|
//We need to use MakeCurrent in case we are jumping up multiple game screens.
|
2017-01-20 16:20:56 +08:00
|
|
|
|
nextOsu.Background?.MakeCurrent();
|
2016-10-07 19:35:44 +08:00
|
|
|
|
else
|
|
|
|
|
Background.Exit();
|
|
|
|
|
}
|
2016-10-05 15:35:10 +08:00
|
|
|
|
|
2016-10-07 17:58:20 +08:00
|
|
|
|
return base.OnExiting(next);
|
2016-10-05 15:35:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|