osu/osu.Game/Screens/OsuScreen.cs

129 lines
3.9 KiB
C#
Raw Normal View History

// 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
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;
using osu.Game.Database;
2016-10-05 11:03:52 +00:00
using osu.Game.Graphics.Containers;
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-02-17 09:59:30 +00:00
internal 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
internal virtual bool ShowOverlays => true;
protected new OsuGameBase Game => base.Game as OsuGameBase;
2017-03-16 14:58:36 +00:00
internal virtual bool HasLocalCursorDisplayed => false;
internal virtual bool AllowRulesetChange => true;
2017-02-26 13:08:21 +00:00
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
2016-10-28 10:55:48 +00:00
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
2016-10-28 10:55:48 +00:00
public WorkingBeatmap Beatmap
{
get
{
return beatmap.Value;
}
set
{
beatmap.Value = value;
}
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuGameBase game, OsuGame osuGame)
{
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.
var localMap = beatmap.Value;
2017-02-27 03:24:50 +00:00
beatmap.BindTo(game.Beatmap);
2017-02-27 09:08:05 +00:00
if (localMap != null)
beatmap.Value = localMap;
}
beatmap.ValueChanged += OnBeatmapChanged;
if (osuGame != null)
ruleset.BindTo(osuGame.Ruleset);
2016-10-28 10:55:48 +00:00
}
/// <summary>
/// The global Beatmap was changed.
/// </summary>
2016-10-28 10:55:48 +00:00
protected virtual void OnBeatmapChanged(WorkingBeatmap beatmap)
{
}
protected override void Update()
{
if (!IsCurrentScreen) return;
2016-10-28 10:55:48 +00:00
ruleset.Disabled = !AllowRulesetChange;
2016-10-28 10:55:48 +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
OnBeatmapChanged(Beatmap);
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)
{
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
}
base.OnEntering(last);
}
2017-02-17 09:59:30 +00:00
protected override bool OnExiting(Screen next)
2016-10-05 07:35:10 +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))
{
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.
nextOsu.Background?.MakeCurrent();
else
Background.Exit();
}
2016-10-05 07:35:10 +00:00
return base.OnExiting(next);
2016-10-05 07:35:10 +00:00
}
}
}