mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 23:05:37 +08:00
Parse voted comments
This commit is contained in:
parent
a1bb061405
commit
38dcd42d08
@ -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);
|
||||
|
@ -47,6 +47,26 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
[JsonProperty(@"included_comments")]
|
||||
public List<Comment> IncludedComments { get; set; }
|
||||
|
||||
private List<long> userVotes;
|
||||
|
||||
[JsonProperty(@"user_votes")]
|
||||
public List<long> UserVotes
|
||||
{
|
||||
get => userVotes;
|
||||
set
|
||||
{
|
||||
userVotes = value;
|
||||
value.ForEach(v =>
|
||||
{
|
||||
Comments.ForEach(c =>
|
||||
{
|
||||
if (v == c.Id)
|
||||
c.IsVoted = true;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private List<User> users;
|
||||
|
||||
[JsonProperty(@"users")]
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user