2016-10-05 07:35:10 +00:00
|
|
|
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
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;
|
2016-10-05 07:35:10 +00:00
|
|
|
|
using osu.Framework.GameModes;
|
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;
|
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
|
|
|
|
{
|
2016-10-28 10:55:48 +00:00
|
|
|
|
public abstract class OsuGameMode : GameMode
|
2016-10-05 07:35:10 +00:00
|
|
|
|
{
|
|
|
|
|
internal BackgroundMode Background { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <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>
|
|
|
|
|
protected virtual BackgroundMode CreateBackground() => null;
|
|
|
|
|
|
2016-11-15 11:43:43 +00:00
|
|
|
|
internal 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
|
|
|
|
|
2016-11-15 11:43:43 +00:00
|
|
|
|
protected float ToolbarPadding => ShowOverlays ? (Game as OsuGame)?.Toolbar.DrawHeight ?? 0 : 0;
|
2016-11-09 06:22:54 +00:00
|
|
|
|
|
2016-10-28 10:55:48 +00:00
|
|
|
|
private bool boundToBeatmap;
|
|
|
|
|
private Bindable<WorkingBeatmap> beatmap;
|
|
|
|
|
|
|
|
|
|
public WorkingBeatmap Beatmap
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
bindBeatmap();
|
|
|
|
|
return beatmap.Value;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
bindBeatmap();
|
|
|
|
|
beatmap.Value = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void bindBeatmap()
|
|
|
|
|
{
|
|
|
|
|
if (beatmap == null)
|
|
|
|
|
beatmap = new Bindable<WorkingBeatmap>();
|
|
|
|
|
|
|
|
|
|
if (!boundToBeatmap)
|
|
|
|
|
{
|
|
|
|
|
beatmap.ValueChanged += beatmap_ValueChanged;
|
|
|
|
|
boundToBeatmap = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
if (boundToBeatmap)
|
|
|
|
|
beatmap.ValueChanged -= beatmap_ValueChanged;
|
|
|
|
|
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void beatmap_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
OnBeatmapChanged(beatmap.Value);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 10:44:16 +00:00
|
|
|
|
[BackgroundDependencyLoader(permitNulls: true)]
|
|
|
|
|
private void load(OsuGameBase game)
|
2016-10-28 13:03:59 +00:00
|
|
|
|
{
|
2016-11-12 09:24:56 +00:00
|
|
|
|
if (beatmap == null)
|
2016-11-12 10:44:16 +00:00
|
|
|
|
beatmap = game?.Beatmap;
|
2016-10-28 13:03:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 10:55:48 +00:00
|
|
|
|
public override bool Push(GameMode mode)
|
|
|
|
|
{
|
|
|
|
|
OsuGameMode nextOsu = mode as OsuGameMode;
|
|
|
|
|
if (nextOsu != null)
|
|
|
|
|
{
|
|
|
|
|
nextOsu.beatmap = beatmap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.Push(mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void OnBeatmapChanged(WorkingBeatmap beatmap)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 07:35:10 +00:00
|
|
|
|
protected override void OnEntering(GameMode last)
|
|
|
|
|
{
|
|
|
|
|
OsuGameMode lastOsu = last as OsuGameMode;
|
|
|
|
|
|
|
|
|
|
BackgroundMode bg = CreateBackground();
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.OnEntering(last);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-07 09:58:20 +00:00
|
|
|
|
protected override bool OnExiting(GameMode next)
|
2016-10-05 07:35:10 +00:00
|
|
|
|
{
|
|
|
|
|
OsuGameMode nextOsu = next as OsuGameMode;
|
|
|
|
|
|
|
|
|
|
if (Background != null && !Background.Equals(nextOsu?.Background))
|
2016-10-07 11:35:44 +00:00
|
|
|
|
{
|
|
|
|
|
if (nextOsu != null)
|
|
|
|
|
//We need to use MakeCurrent in case we are jumping up multiple game modes.
|
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
|
|
|
|
|
2016-10-07 09:58:20 +00:00
|
|
|
|
return base.OnExiting(next);
|
2016-10-05 07:35:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|