osu/osu.Game/Overlays/OverlayTabControl.cs

155 lines
4.3 KiB
C#
Raw Normal View History

// 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.
2020-03-26 14:43:48 +00:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays
{
public abstract class OverlayTabControl<T> : OsuTabControl<T>
{
2020-01-22 06:36:16 +00:00
private readonly Box bar;
protected float BarHeight
{
set => bar.Height = value;
}
public override Color4 AccentColour
{
get => base.AccentColour;
2020-01-26 14:42:07 +00:00
set
{
base.AccentColour = value;
bar.Colour = value;
}
}
protected OverlayTabControl()
{
TabContainer.Masking = false;
2020-03-26 14:43:48 +00:00
TabContainer.Spacing = new Vector2(20, 0);
2020-01-22 06:36:16 +00:00
AddInternal(bar = new Box
{
RelativeSizeAxes = Axes.X,
Anchor = Anchor.BottomLeft,
2020-03-26 14:43:48 +00:00
Origin = Anchor.BottomLeft
});
}
2020-03-26 14:43:48 +00:00
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
AccentColour = colourProvider.Highlight1;
}
protected override Dropdown<T> CreateDropdown() => null;
protected override TabItem<T> CreateTabItem(T value) => new OverlayTabItem(value);
protected class OverlayTabItem : TabItem<T>, IHasAccentColour
{
protected readonly ExpandingBar Bar;
protected readonly OsuSpriteText Text;
private Color4 accentColour;
public Color4 AccentColour
{
get => accentColour;
set
{
if (accentColour == value)
return;
accentColour = value;
Bar.Colour = value;
updateState();
}
}
public OverlayTabItem(T value)
: base(value)
{
AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y;
Children = new Drawable[]
{
Text = new OsuSpriteText
{
Margin = new MarginPadding { Bottom = 10 },
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Font = OsuFont.GetFont(),
},
Bar = new ExpandingBar
{
Anchor = Anchor.BottomCentre,
2020-03-26 14:43:48 +00:00
ExpandedSize = 5f,
CollapsedSize = 0
},
2021-06-18 08:26:28 +00:00
new HoverClickSounds(HoverSampleSet.TabSelect)
};
}
protected override bool OnHover(HoverEvent e)
{
base.OnHover(e);
if (!Active.Value)
2019-06-21 10:24:12 +00:00
HoverAction();
return true;
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
if (!Active.Value)
2019-06-21 10:24:12 +00:00
UnhoverAction();
}
protected override void OnActivated()
{
2019-06-21 10:24:12 +00:00
HoverAction();
Text.Font = Text.Font.With(weight: FontWeight.Bold);
2020-03-26 14:43:48 +00:00
Text.FadeColour(Color4.White, 120, Easing.InQuad);
}
protected override void OnDeactivated()
{
2019-06-21 10:24:12 +00:00
UnhoverAction();
Text.Font = Text.Font.With(weight: FontWeight.Medium);
}
private void updateState()
{
if (Active.Value)
OnActivated();
else
OnDeactivated();
}
2019-06-21 10:24:12 +00:00
2020-03-26 14:43:48 +00:00
protected virtual void HoverAction() => Bar.Expand();
2019-06-21 10:24:12 +00:00
protected virtual void UnhoverAction()
{
Bar.Collapse();
2019-06-21 10:24:12 +00:00
Text.FadeColour(AccentColour, 120, Easing.InQuad);
}
}
}
}