Parse parent comments

This commit is contained in:
Andrei Zavatski 2019-10-08 19:09:02 +03:00
parent 3f8fecbc50
commit 000e4a563c
3 changed files with 49 additions and 1 deletions

View File

@ -25,7 +25,10 @@ namespace osu.Game.Online.API.Requests.Responses
comments.ForEach(parent => comments.ForEach(parent =>
{ {
if (parent.Id == child.ParentId) if (parent.Id == child.ParentId)
{
parent.ChildComments.Add(child); parent.ChildComments.Add(child);
child.ParentComment = parent;
}
}); });
} }
}); });

View File

@ -28,6 +28,8 @@ namespace osu.Game.Online.API.Requests.Responses
public List<Comment> ChildComments = new List<Comment>(); public List<Comment> ChildComments = new List<Comment>();
public Comment ParentComment { get; set; }
[JsonProperty(@"user_id")] [JsonProperty(@"user_id")]
public long UserId { get; set; } public long UserId { get; set; }

View File

@ -12,6 +12,7 @@ using osu.Game.Graphics.Containers;
using osu.Game.Utils; using osu.Game.Utils;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using System; using System;
using osu.Framework.Graphics.Cursor;
namespace osu.Game.Overlays.Comments namespace osu.Game.Overlays.Comments
{ {
@ -97,9 +98,19 @@ namespace osu.Game.Overlays.Comments
Spacing = new Vector2(0, 2), Spacing = new Vector2(0, 2),
Children = new Drawable[] Children = new Drawable[]
{ {
username = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true)) new FillFlowContainer
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(7, 0),
Children = new Drawable[]
{
username = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true))
{
AutoSizeAxes = Axes.Both,
},
new ParentUsername(comment)
}
}, },
new TextFlowContainer(s => s.Font = OsuFont.GetFont(size: 14)) new TextFlowContainer(s => s.Font = OsuFont.GetFont(size: 14))
{ {
@ -196,5 +207,37 @@ namespace osu.Game.Overlays.Comments
return base.OnClick(e); return base.OnClick(e);
} }
} }
private class ParentUsername : FillFlowContainer, IHasTooltip
{
private const int spacing = 3;
public string TooltipText => comment.ParentComment?.GetMessage() ?? "";
private readonly Comment comment;
public ParentUsername(Comment comment)
{
this.comment = comment;
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Horizontal;
Spacing = new Vector2(spacing, 0);
Alpha = comment.ParentId == null ? 0 : 1;
Children = new Drawable[]
{
new SpriteIcon
{
Icon = FontAwesome.Solid.Reply,
Size = new Vector2(14),
},
new SpriteText
{
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true),
Text = comment.ParentComment?.User?.Username
}
};
}
}
} }
} }