2018-05-11 08:35:26 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2018-05-15 20:08:55 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A <see cref="BreadcrumbControl"/> which follows the active screen (and allows navigation) in a <see cref="Screen"/> stack.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ScreenBreadcrumbControl : BreadcrumbControl<Screen>
|
2018-05-11 08:35:26 +08:00
|
|
|
|
{
|
2018-05-15 20:08:55 +08:00
|
|
|
|
private Screen last;
|
|
|
|
|
|
|
|
|
|
public ScreenBreadcrumbControl(Screen initialScreen)
|
2018-05-11 08:35:26 +08:00
|
|
|
|
{
|
2018-05-15 20:08:55 +08:00
|
|
|
|
Current.ValueChanged += newScreen =>
|
2018-05-11 08:35:26 +08:00
|
|
|
|
{
|
2018-05-15 20:08:55 +08:00
|
|
|
|
if (last != newScreen && !newScreen.IsCurrentScreen)
|
|
|
|
|
newScreen.MakeCurrent();
|
|
|
|
|
};
|
2018-05-11 08:35:26 +08:00
|
|
|
|
|
2018-05-15 20:08:55 +08:00
|
|
|
|
onPushed(initialScreen);
|
2018-05-11 08:35:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-15 20:08:55 +08:00
|
|
|
|
private void screenChanged(Screen newScreen)
|
2018-05-11 08:35:26 +08:00
|
|
|
|
{
|
2018-05-16 06:42:50 +08:00
|
|
|
|
if (newScreen == null) return;
|
|
|
|
|
|
2018-05-15 20:08:55 +08:00
|
|
|
|
if (last != null)
|
2018-05-11 08:35:26 +08:00
|
|
|
|
{
|
2018-05-15 20:08:55 +08:00
|
|
|
|
last.Exited -= screenChanged;
|
|
|
|
|
last.ModePushed -= onPushed;
|
|
|
|
|
}
|
2018-05-11 08:35:26 +08:00
|
|
|
|
|
2018-05-15 20:08:55 +08:00
|
|
|
|
last = newScreen;
|
|
|
|
|
|
|
|
|
|
newScreen.Exited += screenChanged;
|
|
|
|
|
newScreen.ModePushed += onPushed;
|
|
|
|
|
|
|
|
|
|
Current.Value = newScreen;
|
2018-05-11 08:35:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onPushed(Screen screen)
|
|
|
|
|
{
|
|
|
|
|
Items.ToList().SkipWhile(i => i != Current.Value).Skip(1).ForEach(RemoveItem);
|
2018-05-15 20:08:55 +08:00
|
|
|
|
AddItem(screen);
|
2018-05-11 08:35:26 +08:00
|
|
|
|
|
2018-05-15 20:08:55 +08:00
|
|
|
|
screenChanged(screen);
|
2018-05-11 08:35:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|