1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 22:22:55 +08:00
osu-lazer/osu.Game/Overlays/OverlayTabControl.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

157 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.
2022-06-17 15:37:17 +08:00
#nullable disable
2020-03-26 22:43:48 +08: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 14:36:16 +08:00
private readonly Box bar;
protected float BarHeight
{
set => bar.Height = value;
}
public override Color4 AccentColour
{
get => base.AccentColour;
2020-01-26 22:42:07 +08:00
set
{
base.AccentColour = value;
bar.Colour = value;
}
}
protected OverlayTabControl()
{
TabContainer.Masking = false;
2020-03-26 22:43:48 +08:00
TabContainer.Spacing = new Vector2(20, 0);
2020-01-22 14:36:16 +08:00
AddInternal(bar = new Box
{
RelativeSizeAxes = Axes.X,
Anchor = Anchor.BottomLeft,
2020-03-26 22:43:48 +08:00
Origin = Anchor.BottomLeft
});
}
2020-03-26 22:43:48 +08: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 22:43:48 +08:00
ExpandedSize = 5f,
CollapsedSize = 0
},
2021-06-18 16:26:28 +08:00
new HoverClickSounds(HoverSampleSet.TabSelect)
};
}
protected override bool OnHover(HoverEvent e)
{
base.OnHover(e);
if (!Active.Value)
2019-06-21 18:24:12 +08:00
HoverAction();
return true;
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
if (!Active.Value)
2019-06-21 18:24:12 +08:00
UnhoverAction();
}
protected override void OnActivated()
{
2019-06-21 18:24:12 +08:00
HoverAction();
Text.Font = Text.Font.With(weight: FontWeight.Bold);
2020-03-26 22:43:48 +08:00
Text.FadeColour(Color4.White, 120, Easing.InQuad);
}
protected override void OnDeactivated()
{
2019-06-21 18:24:12 +08:00
UnhoverAction();
Text.Font = Text.Font.With(weight: FontWeight.Medium);
}
private void updateState()
{
if (Active.Value)
OnActivated();
else
OnDeactivated();
}
2019-06-21 18:24:12 +08:00
2020-03-26 22:43:48 +08:00
protected virtual void HoverAction() => Bar.Expand();
2019-06-21 18:24:12 +08:00
protected virtual void UnhoverAction()
{
Bar.Collapse();
2019-06-21 18:24:12 +08:00
Text.FadeColour(AccentColour, 120, Easing.InQuad);
}
}
}
}