2020-01-18 06:36:14 +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.
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2020-01-20 03:57:39 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
|
using osuTK.Graphics;
|
2020-01-18 06:36:14 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Profile.Sections
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class ProfileItemContainer : Container
|
2020-01-18 06:36:14 +08:00
|
|
|
|
{
|
2020-01-20 03:57:39 +08:00
|
|
|
|
private const int hover_duration = 200;
|
|
|
|
|
|
2020-01-18 06:36:14 +08:00
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
|
|
|
|
|
private readonly Box background;
|
|
|
|
|
private readonly Container content;
|
|
|
|
|
|
2020-02-29 04:09:49 +08:00
|
|
|
|
private Color4 idleColour;
|
|
|
|
|
|
2020-03-05 04:19:26 +08:00
|
|
|
|
protected Color4 IdleColour
|
2020-02-29 04:09:49 +08:00
|
|
|
|
{
|
|
|
|
|
get => idleColour;
|
2020-03-05 04:19:26 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
idleColour = value;
|
2020-03-06 06:10:14 +08:00
|
|
|
|
fadeBackgroundColour();
|
2020-03-05 04:19:26 +08:00
|
|
|
|
}
|
2020-02-29 04:09:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-05 04:19:26 +08:00
|
|
|
|
private Color4 hoverColour;
|
|
|
|
|
|
|
|
|
|
protected Color4 HoverColour
|
|
|
|
|
{
|
|
|
|
|
get => hoverColour;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
hoverColour = value;
|
2020-03-06 06:10:14 +08:00
|
|
|
|
fadeBackgroundColour();
|
2020-03-05 04:19:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-29 04:09:49 +08:00
|
|
|
|
|
2020-01-20 03:48:11 +08:00
|
|
|
|
public ProfileItemContainer()
|
2020-01-18 06:36:14 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
Masking = true;
|
|
|
|
|
CornerRadius = 6;
|
|
|
|
|
|
2020-01-20 03:57:39 +08:00
|
|
|
|
AddRangeInternal(new Drawable[]
|
2020-01-18 06:36:14 +08:00
|
|
|
|
{
|
|
|
|
|
background = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
content = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-01-27 17:55:19 +08:00
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2020-01-18 06:36:14 +08:00
|
|
|
|
{
|
2023-01-01 03:51:29 +08:00
|
|
|
|
IdleColour = colourProvider.Background2;
|
|
|
|
|
HoverColour = colourProvider.Background1;
|
2020-01-20 03:57:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
|
{
|
2020-03-06 06:10:14 +08:00
|
|
|
|
fadeBackgroundColour(hover_duration);
|
2020-03-06 06:15:53 +08:00
|
|
|
|
return true;
|
2020-01-20 03:57:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
|
{
|
|
|
|
|
base.OnHoverLost(e);
|
2020-03-06 06:10:14 +08:00
|
|
|
|
fadeBackgroundColour(hover_duration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fadeBackgroundColour(double fadeDuration = 0)
|
|
|
|
|
{
|
|
|
|
|
background.FadeColour(IsHovered ? HoverColour : IdleColour, fadeDuration, Easing.OutQuint);
|
2020-01-18 06:36:14 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|