1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 18:02:55 +08:00
osu-lazer/osu.Game/Overlays/OverlayHeaderTabControl.cs

155 lines
4.3 KiB
C#
Raw Normal View History

2019-01-28 06:45:00 +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-12-23 04:50:25 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
2019-03-06 15:09:21 +08:00
using osu.Game.Graphics;
2018-12-23 04:50:25 +08:00
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays
2018-12-23 04:50:25 +08:00
{
public class OverlayHeaderTabControl : TabControl<string>
2018-12-23 04:50:25 +08:00
{
private readonly Box bar;
private Color4 accentColour = Color4.White;
2018-12-23 04:50:25 +08:00
public Color4 AccentColour
{
get => accentColour;
set
{
if (accentColour == value)
return;
2018-12-23 04:50:25 +08:00
accentColour = value;
bar.Colour = value;
foreach (TabItem<string> tabItem in TabContainer)
{
((HeaderTabItem)tabItem).AccentColour = value;
2018-12-23 04:50:25 +08:00
}
}
}
2019-03-06 15:09:21 +08:00
public new MarginPadding Padding
2018-12-23 04:50:25 +08:00
{
get => TabContainer.Padding;
2018-12-25 08:09:49 +08:00
set => TabContainer.Padding = value;
2018-12-23 04:50:25 +08:00
}
public OverlayHeaderTabControl()
2018-12-23 04:50:25 +08:00
{
TabContainer.Masking = false;
2019-04-25 19:09:42 +08:00
TabContainer.Spacing = new Vector2(15, 0);
2018-12-23 04:50:25 +08:00
AddInternal(bar = new Box
{
RelativeSizeAxes = Axes.X,
Height = 2,
Anchor = Anchor.BottomLeft,
Origin = Anchor.CentreLeft
});
}
protected override Dropdown<string> CreateDropdown() => null;
protected override TabItem<string> CreateTabItem(string value) => new HeaderTabItem(value)
2018-12-23 04:50:25 +08:00
{
AccentColour = AccentColour
};
private class HeaderTabItem : TabItem<string>
2018-12-23 04:50:25 +08:00
{
private readonly OsuSpriteText text;
2019-05-22 15:44:47 +08:00
private readonly ExpandingBar bar;
2018-12-23 04:50:25 +08:00
private Color4 accentColour;
public Color4 AccentColour
{
get => accentColour;
set
{
if (accentColour == value)
return;
2018-12-23 04:50:25 +08:00
accentColour = value;
2018-12-23 04:50:25 +08:00
bar.Colour = value;
updateState();
2018-12-23 04:50:25 +08:00
}
}
public HeaderTabItem(string value)
2018-12-23 04:50:25 +08:00
: base(value)
{
AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y;
2019-05-22 15:44:47 +08:00
Children = new Drawable[]
2018-12-23 04:50:25 +08:00
{
text = new OsuSpriteText
{
2019-03-10 06:58:14 +08:00
Margin = new MarginPadding { Bottom = 10 },
2018-12-23 04:50:25 +08:00
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Text = value,
2019-03-10 06:58:14 +08:00
Font = OsuFont.GetFont()
2018-12-23 04:50:25 +08:00
},
2019-05-22 15:44:47 +08:00
bar = new ExpandingBar
2018-12-23 04:50:25 +08:00
{
2019-05-22 15:44:47 +08:00
Anchor = Anchor.BottomCentre,
ExpandedSize = 7.5f,
CollapsedSize = 0
2018-12-23 04:50:25 +08:00
},
new HoverClickSounds()
};
}
protected override bool OnHover(HoverEvent e)
{
base.OnHover(e);
updateState();
return true;
2018-12-23 04:50:25 +08:00
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
updateState();
2018-12-23 04:50:25 +08:00
}
protected override void OnActivated() => updateState();
2018-12-23 04:50:25 +08:00
protected override void OnDeactivated() => updateState();
2018-12-23 04:50:25 +08:00
private void updateState()
2018-12-23 04:50:25 +08:00
{
if (Active.Value || IsHovered)
{
text.FadeColour(Color4.White, 120, Easing.InQuad);
2019-05-22 15:44:47 +08:00
bar.Expand();
if (Active.Value)
text.Font = text.Font.With(weight: FontWeight.Bold);
}
else
{
text.FadeColour(AccentColour, 120, Easing.InQuad);
2019-05-22 15:44:47 +08:00
bar.Collapse();
text.Font = text.Font.With(weight: FontWeight.Medium);
}
2018-12-23 04:50:25 +08:00
}
}
}
}