1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:47:29 +08:00

UI implementation

This commit is contained in:
Andrei Zavatski 2019-10-17 13:10:28 +03:00
parent 38dcd42d08
commit 1f28c00594

View File

@ -17,6 +17,10 @@ using System.Linq;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osuTK.Graphics;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Input.Events;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.Comments namespace osu.Game.Overlays.Comments
{ {
@ -57,7 +61,7 @@ namespace osu.Game.Overlays.Comments
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Padding = new MarginPadding(margin), Padding = new MarginPadding(margin) { Left = margin + 5 },
Child = content = new GridContainer Child = content = new GridContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
@ -336,10 +340,15 @@ namespace osu.Game.Overlays.Comments
} }
} }
private class VotePill : CircularContainer private class VotePill : Container, IHasAccentColour
{ {
public Color4 AccentColour { get; set; }
private readonly Box background; private readonly Box background;
private readonly Box hoverLayer;
private readonly Comment comment; private readonly Comment comment;
private readonly CircularContainer borderContainer;
private readonly SpriteText sideNumber;
public VotePill(Comment comment) public VotePill(Comment comment)
{ {
@ -347,12 +356,24 @@ namespace osu.Game.Overlays.Comments
AutoSizeAxes = Axes.X; AutoSizeAxes = Axes.X;
Height = 20; Height = 20;
Masking = true;
Children = new Drawable[] Children = new Drawable[]
{ {
background = new Box borderContainer = new CircularContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Masking = true,
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both
},
hoverLayer = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0
}
}
}, },
new OsuSpriteText new OsuSpriteText
{ {
@ -361,14 +382,49 @@ namespace osu.Game.Overlays.Comments
Margin = new MarginPadding { Horizontal = margin }, Margin = new MarginPadding { Horizontal = margin },
Font = OsuFont.GetFont(size: 14), Font = OsuFont.GetFont(size: 14),
Text = $"+{comment.VotesCount}" Text = $"+{comment.VotesCount}"
} },
sideNumber = new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreRight,
Text = "+1",
Font = OsuFont.GetFont(size: 14),
Margin = new MarginPadding { Right = 3 },
Alpha = 0,
},
new HoverClickSounds(),
}; };
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
background.Colour = comment.IsVoted ? colours.GreenLight : OsuColour.Gray(0.05f); AccentColour = borderContainer.BorderColour = sideNumber.Colour = colours.GreenLight;
background.Colour = comment.IsVoted ? AccentColour : OsuColour.Gray(0.05f);
hoverLayer.Colour = Color4.Black.Opacity(0.5f);
}
protected override bool OnHover(HoverEvent e)
{
if (comment.IsVoted)
hoverLayer.Show();
else
sideNumber.Show();
borderContainer.BorderThickness = 3;
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
if (comment.IsVoted)
hoverLayer.Hide();
else
sideNumber.Hide();
borderContainer.BorderThickness = 0;
} }
} }
} }