From 38dcd42d0891fd3c2961277a32661ab7f4d2a974 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Thu, 17 Oct 2019 12:35:12 +0300 Subject: [PATCH] Parse voted comments --- .../Online/API/Requests/Responses/Comment.cs | 2 ++ .../API/Requests/Responses/CommentBundle.cs | 20 ++++++++++++++++ osu.Game/Overlays/Comments/DrawableComment.cs | 24 ++++++++++++++----- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/osu.Game/Online/API/Requests/Responses/Comment.cs b/osu.Game/Online/API/Requests/Responses/Comment.cs index 29abaa74e5..5510e9afff 100644 --- a/osu.Game/Online/API/Requests/Responses/Comment.cs +++ b/osu.Game/Online/API/Requests/Responses/Comment.cs @@ -72,6 +72,8 @@ namespace osu.Game.Online.API.Requests.Responses public bool HasMessage => !string.IsNullOrEmpty(MessageHtml); + public bool IsVoted { get; set; } + public string GetMessage => HasMessage ? WebUtility.HtmlDecode(Regex.Replace(MessageHtml, @"<(.|\n)*?>", string.Empty)) : string.Empty; public int DeletedChildrenCount => ChildComments.Count(c => c.IsDeleted); diff --git a/osu.Game/Online/API/Requests/Responses/CommentBundle.cs b/osu.Game/Online/API/Requests/Responses/CommentBundle.cs index 7063581605..f910c738ac 100644 --- a/osu.Game/Online/API/Requests/Responses/CommentBundle.cs +++ b/osu.Game/Online/API/Requests/Responses/CommentBundle.cs @@ -47,6 +47,26 @@ namespace osu.Game.Online.API.Requests.Responses [JsonProperty(@"included_comments")] public List IncludedComments { get; set; } + private List userVotes; + + [JsonProperty(@"user_votes")] + public List UserVotes + { + get => userVotes; + set + { + userVotes = value; + value.ForEach(v => + { + Comments.ForEach(c => + { + if (v == c.Id) + c.IsVoted = true; + }); + }); + } + } + private List users; [JsonProperty(@"users")] diff --git a/osu.Game/Overlays/Comments/DrawableComment.cs b/osu.Game/Overlays/Comments/DrawableComment.cs index 89abda92cf..3e9c6a5eca 100644 --- a/osu.Game/Overlays/Comments/DrawableComment.cs +++ b/osu.Game/Overlays/Comments/DrawableComment.cs @@ -15,6 +15,8 @@ using osu.Framework.Bindables; using osu.Framework.Graphics.Shapes; using System.Linq; using osu.Game.Online.Chat; +using osu.Framework.Allocation; +using osu.Game.Graphics.Sprites; namespace osu.Game.Overlays.Comments { @@ -81,7 +83,7 @@ namespace osu.Game.Overlays.Comments Spacing = new Vector2(5, 0), Children = new Drawable[] { - votePill = new VotePill(comment.VotesCount) + votePill = new VotePill(comment) { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -336,28 +338,38 @@ namespace osu.Game.Overlays.Comments private class VotePill : CircularContainer { - public VotePill(int count) + private readonly Box background; + private readonly Comment comment; + + public VotePill(Comment comment) { + this.comment = comment; + AutoSizeAxes = Axes.X; Height = 20; Masking = true; Children = new Drawable[] { - new Box + background = new Box { RelativeSizeAxes = Axes.Both, - Colour = OsuColour.Gray(0.05f) }, - new SpriteText + new OsuSpriteText { Anchor = Anchor.Centre, Origin = Anchor.Centre, Margin = new MarginPadding { Horizontal = margin }, Font = OsuFont.GetFont(size: 14), - Text = $"+{count}" + Text = $"+{comment.VotesCount}" } }; } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + background.Colour = comment.IsVoted ? colours.GreenLight : OsuColour.Gray(0.05f); + } } } }