1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 01:27:29 +08:00
osu-lazer/osu.Game/Screens/OsuGameScreen.cs

106 lines
3.1 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 15:35:10 +08:00
using System;
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;
2016-10-05 19:03:52 +08:00
using osu.Game.Graphics.Containers;
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>
/// Override to create a BackgroundMode for the current GameMode.
/// 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
internal virtual bool ShowOverlays => true;
protected new OsuGameBase Game => base.Game as OsuGameBase;
2017-02-26 21:08:21 +08:00
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
2016-10-28 18:55:48 +08:00
public WorkingBeatmap Beatmap
{
get
{
return beatmap.Value;
}
set
{
beatmap.Value = value;
}
}
private void beatmap_ValueChanged(object sender, EventArgs e)
{
OnBeatmapChanged(beatmap.Value);
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuGameBase game)
{
2017-02-26 21:08:21 +08:00
beatmap.Weld(game?.Beatmap);
beatmap.ValueChanged += beatmap_ValueChanged;
2016-10-28 18:55:48 +08:00
}
protected virtual void OnBeatmapChanged(WorkingBeatmap beatmap)
{
}
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
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 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))
{
if (nextOsu != null)
//We need to use MakeCurrent in case we are jumping up multiple game modes.
nextOsu.Background?.MakeCurrent();
else
Background.Exit();
}
2016-10-05 15:35:10 +08:00
return base.OnExiting(next);
2016-10-05 15:35:10 +08:00
}
}
}