1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 13:37:25 +08:00

Add grid container with sections, add background colours and hover logic

This commit is contained in:
mk56-spn 2023-01-16 17:15:37 +01:00
parent c907751a5c
commit b7584b4a02
2 changed files with 85 additions and 3 deletions

View File

@ -5,6 +5,7 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Online.Leaderboards;
using osuTK;
namespace osu.Game.Tests.Visual.SongSelect
{
@ -13,13 +14,18 @@ namespace osu.Game.Tests.Visual.SongSelect
[BackgroundDependencyLoader]
private void load()
{
Child = new Container
Child = new FillFlowContainer
{
Width = 900,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Spacing = new Vector2(0, 10),
AutoSizeAxes = Axes.Y,
Child = new LeaderBoardScoreV2()
Children = new Drawable[]
{
new LeaderBoardScoreV2(),
new LeaderBoardScoreV2(true)
}
};
}
}

View File

@ -5,23 +5,43 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays;
using osuTK;
namespace osu.Game.Online.Leaderboards
{
public partial class LeaderBoardScoreV2 : OsuClickableContainer
{
private readonly bool isPersonalBest;
private const int HEIGHT = 60;
private const int corner_radius = 10;
private const int transition_duration = 200;
private Colour4 foregroundColour;
private Colour4 backgroundColour;
private static readonly Vector2 shear = new Vector2(0.15f, 0);
[Cached]
private OverlayColourProvider colourProvider { get; set; } = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
private Container content = null!;
private Box background = null!;
private Box foreground = null!;
public LeaderBoardScoreV2(bool isPersonalBest = false)
{
this.isPersonalBest = isPersonalBest;
}
[BackgroundDependencyLoader]
private void load()
{
foregroundColour = isPersonalBest ? colourProvider.Background1 : colourProvider.Background5;
backgroundColour = isPersonalBest ? colourProvider.Background2 : colourProvider.Background4;
Shear = shear;
RelativeSizeAxes = Axes.X;
Height = HEIGHT;
@ -32,12 +52,68 @@ namespace osu.Game.Online.Leaderboards
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
background = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = backgroundColour
},
new GridContainer
{
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, 65),
new Dimension(),
new Dimension(GridSizeMode.Absolute, 176)
},
Content = new[]
{
new[]
{
Empty(),
createCentreContent(),
Empty(),
}
}
}
}
};
}
private Container createCentreContent() =>
new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Masking = true,
CornerRadius = corner_radius,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
foreground = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = foregroundColour
}
}
};
protected override bool OnHover(HoverEvent e)
{
updateState();
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
updateState();
base.OnHoverLost(e);
}
private void updateState()
{
foreground.FadeColour(IsHovered ? foregroundColour.Lighten(0.2f) : foregroundColour, transition_duration, Easing.OutQuint);
background.FadeColour(IsHovered ? backgroundColour.Lighten(0.2f) : backgroundColour, transition_duration, Easing.OutQuint);
}
}
}