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>
|
2019-01-23 19:52:00 +08:00
|
|
|
|
public class ScreenBreadcrumbControl : BreadcrumbControl<IScreen>
|
2018-05-11 08:35:26 +08:00
|
|
|
|
{
|
2019-01-23 19:52:00 +08:00
|
|
|
|
public ScreenBreadcrumbControl(ScreenStack stack)
|
2018-05-11 08:35:26 +08:00
|
|
|
|
{
|
2019-01-23 19:52:00 +08:00
|
|
|
|
stack.ScreenPushed += onPushed;
|
|
|
|
|
stack.ScreenExited += onExited;
|
2018-05-11 08:35:26 +08:00
|
|
|
|
|
2019-01-25 16:44:33 +08:00
|
|
|
|
onPushed(null, stack.CurrentScreen);
|
|
|
|
|
|
2019-01-23 19:52:00 +08:00
|
|
|
|
Current.ValueChanged += newScreen => newScreen.MakeCurrent();
|
2018-05-11 08:35:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 19:52:00 +08:00
|
|
|
|
private void onPushed(IScreen lastScreen, IScreen newScreen)
|
2018-05-11 08:35:26 +08:00
|
|
|
|
{
|
2019-01-23 19:52:00 +08:00
|
|
|
|
AddItem(newScreen);
|
2019-01-25 16:44:33 +08:00
|
|
|
|
Current.Value = newScreen;
|
2018-05-11 08:35:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 19:52:00 +08:00
|
|
|
|
private void onExited(IScreen lastScreen, IScreen newScreen)
|
2018-05-11 08:35:26 +08:00
|
|
|
|
{
|
2019-01-23 19:52:00 +08:00
|
|
|
|
Current.Value = newScreen;
|
|
|
|
|
Items.ToList().SkipWhile(s => s != Current.Value).Skip(1).ForEach(RemoveItem);
|
2018-05-11 08:35:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|