osu/osu.Game/Graphics/UserInterface/OsuTabItem.cs

122 lines
3.4 KiB
C#
Raw Normal View History

2017-03-05 04:07:47 +00:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
2017-03-08 09:19:00 +00:00
using OpenTK.Graphics;
2017-03-05 04:07:47 +00:00
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
2017-03-16 12:26:03 +00:00
using osu.Framework.Graphics.Transforms;
using osu.Framework.Graphics.UserInterface;
2017-03-05 04:07:47 +00:00
using osu.Framework.Input;
using osu.Game.Graphics.Sprites;
2017-03-16 00:11:50 +00:00
namespace osu.Game.Graphics.UserInterface
2017-03-05 04:07:47 +00:00
{
2017-03-16 00:11:50 +00:00
public class OsuTabItem<T> : TabItem<T>
2017-03-05 04:07:47 +00:00
{
private SpriteText text;
private Box box;
2017-03-16 00:52:31 +00:00
private Color4? accentColour;
public Color4 AccentColour
{
get { return accentColour.GetValueOrDefault(); }
set
{
accentColour = value;
if (!Active)
text.Colour = value;
}
}
2017-03-05 04:07:47 +00:00
public new T Value
{
get { return base.Value; }
set
{
base.Value = value;
text.Text = (value as Enum)?.GetDescription();
}
}
public override bool Active
{
get { return base.Active; }
set
{
2017-03-16 12:33:08 +00:00
if (Active == value) return;
2017-03-05 04:07:47 +00:00
if (value)
fadeActive();
else
fadeInactive();
base.Active = value;
}
}
2017-03-16 12:26:03 +00:00
private const float transition_length = 500;
2017-03-05 04:07:47 +00:00
private void fadeActive()
{
2017-03-16 12:26:03 +00:00
box.FadeIn(transition_length, EasingTypes.OutQuint);
text.FadeColour(Color4.White, transition_length, EasingTypes.OutQuint);
2017-03-05 04:07:47 +00:00
}
private void fadeInactive()
{
2017-03-16 12:26:03 +00:00
box.FadeOut(transition_length, EasingTypes.OutQuint);
text.FadeColour(AccentColour, transition_length, EasingTypes.OutQuint);
2017-03-05 04:07:47 +00:00
}
2017-03-16 00:52:31 +00:00
protected override bool OnHover(InputState state)
{
2017-03-05 04:07:47 +00:00
if (!Active)
fadeActive();
return true;
}
2017-03-16 00:52:31 +00:00
protected override void OnHoverLost(InputState state)
{
2017-03-05 04:07:47 +00:00
if (!Active)
fadeInactive();
}
2017-03-16 00:11:50 +00:00
public OsuTabItem()
2017-03-05 04:07:47 +00:00
{
AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y;
2017-03-05 04:07:47 +00:00
Children = new Drawable[]
{
text = new OsuSpriteText
{
Margin = new MarginPadding(5),
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
2017-03-05 04:07:47 +00:00
TextSize = 14,
Font = @"Exo2.0-Bold", // Font should only turn bold when active?
},
box = new Box
{
RelativeSizeAxes = Axes.X,
Height = 1,
Alpha = 0,
Colour = Color4.White,
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
}
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
2017-03-16 00:52:31 +00:00
if (accentColour == null)
AccentColour = colours.Blue;
2017-03-05 04:07:47 +00:00
}
}
}