2016-10-05 15:35:10 +08: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;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using osu.Framework.GameModes;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.Background;
|
2016-10-05 19:03:52 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2016-10-05 15:35:10 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.GameModes
|
|
|
|
|
{
|
|
|
|
|
public class OsuGameMode : GameMode
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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-05 19:03:52 +08:00
|
|
|
|
AddTopLevel(new ParallaxContainer
|
|
|
|
|
{
|
|
|
|
|
Depth = float.MinValue,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
Background = bg
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-10-05 15:35:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
base.OnEntering(last);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnExiting(GameMode next)
|
|
|
|
|
{
|
|
|
|
|
OsuGameMode nextOsu = next as OsuGameMode;
|
|
|
|
|
|
|
|
|
|
if (Background != null && !Background.Equals(nextOsu?.Background))
|
|
|
|
|
Background.Exit();
|
|
|
|
|
|
|
|
|
|
base.OnExiting(next);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|