mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 21:47:25 +08:00
36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
// 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
|
|
{
|
|
/// <summary>
|
|
/// A <see cref="BreadcrumbControl"/> which follows the active screen (and allows navigation) in a <see cref="Screen"/> stack.
|
|
/// </summary>
|
|
public class ScreenBreadcrumbControl : BreadcrumbControl<IScreen>
|
|
{
|
|
public ScreenBreadcrumbControl(ScreenStack stack)
|
|
{
|
|
stack.ScreenPushed += onPushed;
|
|
stack.ScreenExited += onExited;
|
|
|
|
Current.ValueChanged += newScreen => newScreen.MakeCurrent();
|
|
}
|
|
|
|
private void onPushed(IScreen lastScreen, IScreen newScreen)
|
|
{
|
|
Current.Value = newScreen;
|
|
AddItem(newScreen);
|
|
}
|
|
|
|
private void onExited(IScreen lastScreen, IScreen newScreen)
|
|
{
|
|
Current.Value = newScreen;
|
|
Items.ToList().SkipWhile(s => s != Current.Value).Skip(1).ForEach(RemoveItem);
|
|
}
|
|
}
|
|
}
|