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