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;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
public class PageTabControl<T> : OsuTabControl<T>
|
|
|
|
|
{
|
|
|
|
|
protected override TabItem<T> CreateTabItem(T value) => new PageTabItem(value);
|
|
|
|
|
|
|
|
|
|
public PageTabControl()
|
|
|
|
|
{
|
|
|
|
|
Height = 30;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-12 11:33:30 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
AccentColour = colours.Yellow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class PageTabItem : TabItem<T>, IHasAccentColour
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
private const float transition_duration = 100;
|
|
|
|
|
|
|
|
|
|
private readonly Box box;
|
|
|
|
|
|
|
|
|
|
protected readonly SpriteText Text;
|
|
|
|
|
|
2019-08-12 11:33:30 +00:00
|
|
|
|
private Color4 accentColour;
|
|
|
|
|
|
|
|
|
|
public Color4 AccentColour
|
2019-08-12 10:08:15 +00:00
|
|
|
|
{
|
2019-08-12 11:33:30 +00:00
|
|
|
|
get => accentColour;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
accentColour = value;
|
|
|
|
|
box.Colour = accentColour;
|
|
|
|
|
}
|
2019-08-12 10:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-28 04:31:40 +00:00
|
|
|
|
public PageTabItem(T value)
|
|
|
|
|
: base(value)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
Text = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Margin = new MarginPadding { Top = 8, Bottom = 8 },
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2019-09-12 02:03:59 +00:00
|
|
|
|
Text = CreateText(),
|
2019-02-12 04:04:46 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 14)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
},
|
|
|
|
|
box = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 5,
|
|
|
|
|
Scale = new Vector2(1f, 0f),
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
},
|
|
|
|
|
new HoverClickSounds()
|
|
|
|
|
};
|
2018-12-29 14:43:19 +00:00
|
|
|
|
|
2020-03-13 04:32:16 +00:00
|
|
|
|
Active.BindValueChanged(active => Text.Font = Text.Font.With(Typeface.Torus, weight: active.NewValue ? FontWeight.Bold : FontWeight.Medium), true);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 02:03:59 +00:00
|
|
|
|
protected virtual string CreateText() => (Value as Enum)?.GetDescription() ?? Value.ToString();
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-02-21 09:56:34 +00:00
|
|
|
|
if (!Active.Value)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
slideActive();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-02-21 09:56:34 +00:00
|
|
|
|
if (!Active.Value)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
slideInactive();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void slideActive()
|
|
|
|
|
{
|
|
|
|
|
box.ScaleTo(new Vector2(1f), transition_duration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void slideInactive()
|
|
|
|
|
{
|
|
|
|
|
box.ScaleTo(new Vector2(1f, 0f), transition_duration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnActivated() => slideActive();
|
|
|
|
|
|
|
|
|
|
protected override void OnDeactivated() => slideInactive();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|