2019-06-18 13:20:35 +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.
|
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2020-03-26 14:43:48 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-06-18 13:20:35 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2020-01-21 02:24:49 +00:00
|
|
|
|
public abstract partial class OverlayTabControl<T> : OsuTabControl<T>
|
2019-06-18 13:20:35 +00:00
|
|
|
|
{
|
2020-01-22 06:36:16 +00:00
|
|
|
|
private readonly Box bar;
|
2019-06-18 13:20:35 +00:00
|
|
|
|
|
2019-12-27 23:50:52 +00:00
|
|
|
|
protected float BarHeight
|
|
|
|
|
{
|
|
|
|
|
set => bar.Height = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-26 14:21:22 +00:00
|
|
|
|
public override Color4 AccentColour
|
|
|
|
|
{
|
|
|
|
|
get => base.AccentColour;
|
2020-01-26 14:42:07 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.AccentColour = value;
|
|
|
|
|
bar.Colour = value;
|
|
|
|
|
}
|
2020-01-26 14:21:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-18 13:20:35 +00:00
|
|
|
|
protected OverlayTabControl()
|
|
|
|
|
{
|
|
|
|
|
TabContainer.Masking = false;
|
2020-03-26 14:43:48 +00:00
|
|
|
|
TabContainer.Spacing = new Vector2(20, 0);
|
2019-06-18 13:20:35 +00:00
|
|
|
|
|
2020-01-22 06:36:16 +00:00
|
|
|
|
AddInternal(bar = new Box
|
2019-06-18 13:20:35 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2020-03-26 14:43:48 +00:00
|
|
|
|
Origin = Anchor.BottomLeft
|
2019-06-18 13:20:35 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-26 14:43:48 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
|
{
|
|
|
|
|
AccentColour = colourProvider.Highlight1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-18 13:20:35 +00:00
|
|
|
|
protected override Dropdown<T> CreateDropdown() => null;
|
|
|
|
|
|
2019-12-10 13:04:26 +00:00
|
|
|
|
protected override TabItem<T> CreateTabItem(T value) => new OverlayTabItem(value);
|
2019-06-18 13:20:35 +00:00
|
|
|
|
|
2020-01-21 02:24:49 +00:00
|
|
|
|
protected partial class OverlayTabItem : TabItem<T>, IHasAccentColour
|
2019-06-18 13:20:35 +00:00
|
|
|
|
{
|
2019-12-27 23:50:52 +00:00
|
|
|
|
protected readonly ExpandingBar Bar;
|
2019-06-18 13:20:35 +00:00
|
|
|
|
protected readonly OsuSpriteText Text;
|
|
|
|
|
|
|
|
|
|
private Color4 accentColour;
|
|
|
|
|
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
|
|
|
|
get => accentColour;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (accentColour == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
accentColour = value;
|
2019-12-27 23:50:52 +00:00
|
|
|
|
Bar.Colour = value;
|
2019-06-18 13:20:35 +00:00
|
|
|
|
|
|
|
|
|
updateState();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-10 13:04:26 +00:00
|
|
|
|
public OverlayTabItem(T value)
|
2019-06-18 13:20:35 +00:00
|
|
|
|
: 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(),
|
|
|
|
|
},
|
2019-12-27 23:50:52 +00:00
|
|
|
|
Bar = new ExpandingBar
|
2019-06-18 13:20:35 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
2020-03-26 14:43:48 +00:00
|
|
|
|
ExpandedSize = 5f,
|
2019-06-18 13:20:35 +00:00
|
|
|
|
CollapsedSize = 0
|
|
|
|
|
},
|
2021-06-18 08:26:28 +00:00
|
|
|
|
new HoverClickSounds(HoverSampleSet.TabSelect)
|
2019-06-18 13:20:35 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
|
{
|
|
|
|
|
base.OnHover(e);
|
|
|
|
|
|
|
|
|
|
if (!Active.Value)
|
2019-06-21 10:24:12 +00:00
|
|
|
|
HoverAction();
|
2019-06-18 13:20:35 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
|
{
|
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
|
|
|
|
|
|
if (!Active.Value)
|
2019-06-21 10:24:12 +00:00
|
|
|
|
UnhoverAction();
|
2019-06-18 13:20:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnActivated()
|
|
|
|
|
{
|
2019-06-21 10:24:12 +00:00
|
|
|
|
HoverAction();
|
2019-06-18 13:20:35 +00:00
|
|
|
|
Text.Font = Text.Font.With(weight: FontWeight.Bold);
|
2020-03-26 14:43:48 +00:00
|
|
|
|
Text.FadeColour(Color4.White, 120, Easing.InQuad);
|
2019-06-18 13:20:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDeactivated()
|
|
|
|
|
{
|
2019-06-21 10:24:12 +00:00
|
|
|
|
UnhoverAction();
|
2019-06-18 13:20:35 +00:00
|
|
|
|
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()
|
|
|
|
|
{
|
2019-12-27 23:50:52 +00:00
|
|
|
|
Bar.Collapse();
|
2019-06-21 10:24:12 +00:00
|
|
|
|
Text.FadeColour(AccentColour, 120, Easing.InQuad);
|
|
|
|
|
}
|
2019-06-18 13:20:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|