2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-05-11 00:35:26 +00:00
|
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2018-05-15 12:08:55 +00:00
|
|
|
|
/// <summary>
|
2019-04-25 08:36:17 +00:00
|
|
|
|
/// A <see cref="BreadcrumbControl{IScreen}"/> which follows the active screen (and allows navigation) in a <see cref="Screen"/> stack.
|
2018-05-15 12:08:55 +00:00
|
|
|
|
/// </summary>
|
2019-01-23 11:52:00 +00:00
|
|
|
|
public class ScreenBreadcrumbControl : BreadcrumbControl<IScreen>
|
2018-05-11 00:35:26 +00:00
|
|
|
|
{
|
2019-01-23 11:52:00 +00:00
|
|
|
|
public ScreenBreadcrumbControl(ScreenStack stack)
|
2018-05-11 00:35:26 +00:00
|
|
|
|
{
|
2019-01-23 11:52:00 +00:00
|
|
|
|
stack.ScreenPushed += onPushed;
|
|
|
|
|
stack.ScreenExited += onExited;
|
2018-05-11 00:35:26 +00:00
|
|
|
|
|
2020-01-31 10:10:44 +00:00
|
|
|
|
if (stack.CurrentScreen != null)
|
|
|
|
|
onPushed(null, stack.CurrentScreen);
|
2019-01-25 08:44:33 +00:00
|
|
|
|
|
2019-02-22 08:51:39 +00:00
|
|
|
|
Current.ValueChanged += current => current.NewValue.MakeCurrent();
|
2018-05-11 00:35:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 11:52:00 +00:00
|
|
|
|
private void onPushed(IScreen lastScreen, IScreen newScreen)
|
2018-05-11 00:35:26 +00:00
|
|
|
|
{
|
2019-01-23 11:52:00 +00:00
|
|
|
|
AddItem(newScreen);
|
2019-01-25 08:44:33 +00:00
|
|
|
|
Current.Value = newScreen;
|
2018-05-11 00:35:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 11:52:00 +00:00
|
|
|
|
private void onExited(IScreen lastScreen, IScreen newScreen)
|
2018-05-11 00:35:26 +00:00
|
|
|
|
{
|
2019-01-25 10:31:52 +00:00
|
|
|
|
if (newScreen != null)
|
|
|
|
|
Current.Value = newScreen;
|
|
|
|
|
|
2019-01-23 11:52:00 +00:00
|
|
|
|
Items.ToList().SkipWhile(s => s != Current.Value).Skip(1).ForEach(RemoveItem);
|
2018-05-11 00:35:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|