2019-01-24 16:43:03 +08: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 08:35:26 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-05-11 08:35:26 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2021-06-22 11:24:22 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-05-11 08:35:26 +08:00
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2018-05-15 20:08:55 +08:00
|
|
|
|
/// <summary>
|
2019-04-25 16:36:17 +08:00
|
|
|
|
/// A <see cref="BreadcrumbControl{IScreen}"/> which follows the active screen (and allows navigation) in a <see cref="Screen"/> stack.
|
2018-05-15 20:08:55 +08:00
|
|
|
|
/// </summary>
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial 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
|
|
|
|
|
2020-01-31 18:10:44 +08:00
|
|
|
|
if (stack.CurrentScreen != null)
|
|
|
|
|
onPushed(null, stack.CurrentScreen);
|
2021-06-22 11:24:22 +08:00
|
|
|
|
}
|
2019-01-25 16:44:33 +08:00
|
|
|
|
|
2021-06-22 11:24:22 +08:00
|
|
|
|
protected override void SelectTab(TabItem<IScreen> tab)
|
|
|
|
|
{
|
|
|
|
|
// override base method to prevent current item from being changed on click.
|
|
|
|
|
// depend on screen push/exit to change current item instead.
|
|
|
|
|
tab.Value.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-25 18:31:52 +08:00
|
|
|
|
if (newScreen != null)
|
|
|
|
|
Current.Value = newScreen;
|
|
|
|
|
|
2019-01-23 19:52:00 +08:00
|
|
|
|
Items.ToList().SkipWhile(s => s != Current.Value).Skip(1).ForEach(RemoveItem);
|
2018-05-11 08:35:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|