1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 08:47:51 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/BreadcrumbControl.cs

91 lines
3.3 KiB
C#
Raw Normal View History

2017-05-26 18:49:45 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-09-04 08:10:04 +08:00
using System;
2017-05-26 18:49:45 +08:00
using OpenTK;
using osu.Framework;
2017-05-26 18:49:45 +08:00
using osu.Framework.Graphics;
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;
2017-05-26 18:49:45 +08:00
namespace osu.Game.Graphics.UserInterface
{
public class BreadcrumbControl<T> : OsuTabControl<T>
{
2017-05-27 03:46:09 +08:00
private const float padding = 10;
2017-05-26 18:49:45 +08:00
protected override TabItem<T> CreateTabItem(T value) => new BreadcrumbTabItem(value);
public BreadcrumbControl()
{
2017-05-27 03:21:37 +08:00
Height = 26;
2017-05-27 03:46:09 +08:00
TabContainer.Spacing = new Vector2(padding, 0f);
2017-05-26 18:49:45 +08:00
Current.ValueChanged += tab =>
{
2017-05-29 15:18:07 +08:00
foreach (var t in TabContainer.Children.OfType<BreadcrumbTabItem>())
2017-05-26 18:49:45 +08:00
{
var tIndex = TabContainer.IndexOf(t);
var tabIndex = TabContainer.IndexOf(TabMap[tab]);
2017-05-29 15:18:07 +08:00
t.State = tIndex < tabIndex ? Visibility.Hidden : Visibility.Visible;
2017-07-23 02:50:25 +08:00
t.Chevron.FadeTo(tIndex <= tabIndex ? 0f : 1f, 500, Easing.OutQuint);
2017-05-26 18:49:45 +08:00
}
};
}
private class BreadcrumbTabItem : OsuTabItem, IStateful<Visibility>
2017-05-26 18:49:45 +08:00
{
2017-09-04 08:10:04 +08:00
public event Action<Visibility> StateChanged;
public readonly SpriteIcon Chevron;
2017-05-26 18:49:45 +08:00
//don't allow clicking between transitions and don't make the chevron clickable
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => Alpha == 1f && Text.ReceiveMouseInputAt(screenSpacePos);
public override bool HandleInput => State == Visibility.Visible;
private Visibility state;
2017-09-04 08:10:04 +08:00
public Visibility State
{
get { return state; }
set
{
if (value == state) return;
state = value;
const float transition_duration = 500;
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);
}
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-09-04 08:10:04 +08:00
StateChanged?.Invoke(State);
}
}
2017-05-26 18:49:45 +08:00
public BreadcrumbTabItem(T value) : base(value)
{
2017-05-27 03:21:37 +08:00
Text.TextSize = 16;
2017-05-27 03:46:09 +08:00
Padding = new MarginPadding { Right = padding + 8 }; //padding + chevron width
Add(Chevron = new SpriteIcon
2017-05-26 18:49:45 +08:00
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreLeft,
Size = new Vector2(12),
2017-05-26 18:49:45 +08:00
Icon = FontAwesome.fa_chevron_right,
2017-05-27 03:46:09 +08:00
Margin = new MarginPadding { Left = padding },
2017-05-26 18:49:45 +08:00
Alpha = 0f,
});
}
}
}
}