From 1f28c00594daa535678f651a5d16501347653648 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Thu, 17 Oct 2019 13:10:28 +0300 Subject: [PATCH] UI implementation --- osu.Game/Overlays/Comments/DrawableComment.cs | 68 +++++++++++++++++-- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/Comments/DrawableComment.cs b/osu.Game/Overlays/Comments/DrawableComment.cs index 3e9c6a5eca..d1cae6592a 100644 --- a/osu.Game/Overlays/Comments/DrawableComment.cs +++ b/osu.Game/Overlays/Comments/DrawableComment.cs @@ -17,6 +17,10 @@ using System.Linq; using osu.Game.Online.Chat; using osu.Framework.Allocation; 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 { @@ -57,7 +61,7 @@ namespace osu.Game.Overlays.Comments { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, - Padding = new MarginPadding(margin), + Padding = new MarginPadding(margin) { Left = margin + 5 }, Child = content = new GridContainer { 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 hoverLayer; private readonly Comment comment; + private readonly CircularContainer borderContainer; + private readonly SpriteText sideNumber; public VotePill(Comment comment) { @@ -347,12 +356,24 @@ namespace osu.Game.Overlays.Comments AutoSizeAxes = Axes.X; Height = 20; - Masking = true; Children = new Drawable[] { - background = new Box + borderContainer = new CircularContainer { RelativeSizeAxes = Axes.Both, + Masking = true, + Children = new Drawable[] + { + background = new Box + { + RelativeSizeAxes = Axes.Both + }, + hoverLayer = new Box + { + RelativeSizeAxes = Axes.Both, + Alpha = 0 + } + } }, new OsuSpriteText { @@ -361,14 +382,49 @@ namespace osu.Game.Overlays.Comments Margin = new MarginPadding { Horizontal = margin }, Font = OsuFont.GetFont(size: 14), 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] 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; } } }