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;
|
|
|
|
|
|
2018-12-23 05:50:19 +08:00
|
|
|
|
namespace osu.Game.Overlays.Profile.Header
|
2018-12-23 04:50:25 +08:00
|
|
|
|
{
|
|
|
|
|
public class ProfileHeaderTabControl : TabControl<string>
|
|
|
|
|
{
|
|
|
|
|
private readonly Box bar;
|
|
|
|
|
|
|
|
|
|
private Color4 accentColour;
|
|
|
|
|
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
|
|
|
|
get => accentColour;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (accentColour == value) return;
|
|
|
|
|
|
|
|
|
|
accentColour = value;
|
|
|
|
|
|
|
|
|
|
bar.Colour = value;
|
|
|
|
|
|
|
|
|
|
foreach (TabItem<string> tabItem in TabContainer)
|
|
|
|
|
{
|
|
|
|
|
((ProfileHeaderTabItem)tabItem).AccentColour = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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 ProfileHeaderTabControl()
|
|
|
|
|
{
|
|
|
|
|
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 ProfileHeaderTabItem(value)
|
|
|
|
|
{
|
|
|
|
|
AccentColour = AccentColour
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private class ProfileHeaderTabItem : TabItem<string>
|
|
|
|
|
{
|
|
|
|
|
private readonly OsuSpriteText text;
|
|
|
|
|
private readonly Drawable bar;
|
|
|
|
|
|
|
|
|
|
private Color4 accentColour;
|
|
|
|
|
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
|
|
|
|
get => accentColour;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
accentColour = value;
|
|
|
|
|
|
|
|
|
|
bar.Colour = value;
|
2019-03-06 15:09:21 +08:00
|
|
|
|
if (!Active.Value) text.Colour = value;
|
2018-12-23 04:50:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ProfileHeaderTabItem(string value)
|
|
|
|
|
: base(value)
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
},
|
|
|
|
|
bar = new Circle
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 0,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
},
|
|
|
|
|
new HoverClickSounds()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
|
{
|
2019-03-06 15:09:21 +08:00
|
|
|
|
if (!Active.Value)
|
2018-12-23 04:50:25 +08:00
|
|
|
|
onActivated(true);
|
|
|
|
|
return base.OnHover(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
|
{
|
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
|
|
2019-03-06 15:09:21 +08:00
|
|
|
|
if (!Active.Value)
|
2018-12-23 04:50:25 +08:00
|
|
|
|
OnDeactivated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnActivated()
|
|
|
|
|
{
|
|
|
|
|
onActivated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDeactivated()
|
|
|
|
|
{
|
|
|
|
|
text.FadeColour(AccentColour, 120, Easing.InQuad);
|
|
|
|
|
bar.ResizeHeightTo(0, 120, Easing.InQuad);
|
2019-03-10 06:58:14 +08:00
|
|
|
|
text.Font = text.Font.With(weight: FontWeight.Medium);
|
2018-12-23 04:50:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onActivated(bool fake = false)
|
|
|
|
|
{
|
|
|
|
|
text.FadeColour(Color4.White, 120, Easing.InQuad);
|
|
|
|
|
bar.ResizeHeightTo(7.5f, 120, Easing.InQuad);
|
|
|
|
|
if (!fake)
|
2019-03-10 06:58:14 +08:00
|
|
|
|
text.Font = text.Font.With(weight: FontWeight.Bold);
|
2018-12-23 04:50:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|