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-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-09-04 08:10:04 +08:00
|
|
|
|
using System;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2017-05-28 05:19:09 +08:00
|
|
|
|
using osu.Framework;
|
2017-05-26 18:49:45 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-05-28 05:19:09 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-05-26 18:49:45 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2017-05-29 15:18:07 +08:00
|
|
|
|
using System.Linq;
|
2024-02-02 18:48:13 +08:00
|
|
|
|
using JetBrains.Annotations;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-26 18:49:45 +08:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
public partial class BreadcrumbControl<T> : OsuTabControl<T>
|
|
|
|
|
{
|
2017-05-27 03:46:09 +08:00
|
|
|
|
private const float padding = 10;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-02 13:26:40 +08:00
|
|
|
|
protected override TabItem<T> CreateTabItem(T value) => new BreadcrumbTabItem(value)
|
2018-05-11 07:30:03 +08:00
|
|
|
|
{
|
|
|
|
|
AccentColour = AccentColour,
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-02 13:26:40 +08:00
|
|
|
|
protected override float StripWidth => base.StripWidth - TabContainer.FirstOrDefault()?.Padding.Right ?? 0;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-30 13:26:49 +08:00
|
|
|
|
public BreadcrumbControl()
|
2017-05-26 18:49:45 +08:00
|
|
|
|
{
|
2018-05-11 07:30:03 +08:00
|
|
|
|
Height = 32;
|
2017-05-27 03:46:09 +08:00
|
|
|
|
TabContainer.Spacing = new Vector2(padding, 0f);
|
2020-07-03 15:47:14 +08:00
|
|
|
|
SwitchTabOnRemove = false;
|
|
|
|
|
|
2019-02-22 16:51:39 +08:00
|
|
|
|
Current.ValueChanged += index =>
|
2017-05-26 18:49:45 +08:00
|
|
|
|
{
|
2024-01-23 04:32:11 +08:00
|
|
|
|
foreach (var t in TabContainer.OfType<BreadcrumbTabItem>())
|
2017-05-26 18:49:45 +08:00
|
|
|
|
{
|
2021-10-27 12:04:41 +08:00
|
|
|
|
int tIndex = TabContainer.IndexOf(t);
|
|
|
|
|
int tabIndex = TabContainer.IndexOf(TabMap[index.NewValue]);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-26 18:12:35 +08:00
|
|
|
|
t.State = tIndex > tabIndex ? Visibility.Hidden : Visibility.Visible;
|
|
|
|
|
t.Chevron.FadeTo(tIndex >= tabIndex ? 0f : 1f, 500, Easing.OutQuint);
|
2017-05-26 18:49:45 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-27 12:16:36 +08:00
|
|
|
|
public partial class BreadcrumbTabItem : OsuTabItem, IStateful<Visibility>
|
2017-05-26 18:49:45 +08:00
|
|
|
|
{
|
2020-01-02 13:26:40 +08:00
|
|
|
|
protected virtual float ChevronSize => 10;
|
|
|
|
|
|
2024-02-02 18:48:13 +08:00
|
|
|
|
[CanBeNull]
|
2017-09-04 08:10:04 +08:00
|
|
|
|
public event Action<Visibility> StateChanged;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-08-03 13:36:21 +08:00
|
|
|
|
public readonly SpriteIcon Chevron;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-12-17 13:44:10 +08:00
|
|
|
|
//don't allow clicking between transitions
|
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Alpha == 1f && base.ReceivePositionalInputAt(screenSpacePos);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-09-26 13:01:15 +08:00
|
|
|
|
public override bool HandleNonPositionalInput => State == Visibility.Visible;
|
|
|
|
|
public override bool HandlePositionalInput => State == Visibility.Visible;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-28 05:19:09 +08:00
|
|
|
|
private Visibility state;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-28 05:19:09 +08:00
|
|
|
|
public Visibility State
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => state;
|
2017-05-28 05:19:09 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == state) return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2017-05-28 05:19:09 +08:00
|
|
|
|
state = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-28 05:19:09 +08:00
|
|
|
|
const float transition_duration = 500;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-28 05:19:09 +08:00
|
|
|
|
if (State == Visibility.Visible)
|
|
|
|
|
{
|
2017-07-23 02:50:25 +08:00
|
|
|
|
this.FadeIn(transition_duration, Easing.OutQuint);
|
|
|
|
|
this.ScaleTo(new Vector2(1f), transition_duration, Easing.OutQuint);
|
2017-05-28 05:19:09 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-23 02:50:25 +08:00
|
|
|
|
this.FadeOut(transition_duration, Easing.OutQuint);
|
|
|
|
|
this.ScaleTo(new Vector2(0.8f, 1f), transition_duration, Easing.OutQuint);
|
2017-05-28 05:19:09 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-04 08:10:04 +08:00
|
|
|
|
StateChanged?.Invoke(State);
|
2017-05-28 05:19:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-11 13:28:52 +08:00
|
|
|
|
public override void Hide() => State = Visibility.Hidden;
|
|
|
|
|
|
|
|
|
|
public override void Show() => State = Visibility.Visible;
|
|
|
|
|
|
2020-01-02 13:26:40 +08:00
|
|
|
|
public BreadcrumbTabItem(T value)
|
2019-02-28 12:31:40 +08:00
|
|
|
|
: base(value)
|
2017-05-26 18:49:45 +08:00
|
|
|
|
{
|
2019-02-20 18:32:30 +08:00
|
|
|
|
Text.Font = Text.Font.With(size: 18);
|
2018-05-11 07:30:03 +08:00
|
|
|
|
Text.Margin = new MarginPadding { Vertical = 8 };
|
2022-12-17 13:44:10 +08:00
|
|
|
|
Margin = new MarginPadding { Right = padding + ChevronSize };
|
2017-08-03 13:36:21 +08:00
|
|
|
|
Add(Chevron = new SpriteIcon
|
2017-05-26 18:49:45 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
2020-01-02 13:26:40 +08:00
|
|
|
|
Size = new Vector2(ChevronSize),
|
2019-04-02 18:55:24 +08:00
|
|
|
|
Icon = FontAwesome.Solid.ChevronRight,
|
2017-05-27 03:46:09 +08:00
|
|
|
|
Margin = new MarginPadding { Left = padding },
|
2017-05-26 18:49:45 +08:00
|
|
|
|
Alpha = 0f,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|