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 @@ public List<Comment> Comments
comments.ForEach(parent =>
{
if (parent.Id == child.ParentId)
{
parent.ChildComments.Add(child);
child.ParentComment = parent;
}
});
}
});

View File

@ -28,6 +28,8 @@ public long? ParentId
public List<Comment> ChildComments = new List<Comment>();
public Comment ParentComment { get; set; }
[JsonProperty(@"user_id")]
public long UserId { get; set; }

View File

@ -12,6 +12,7 @@
using osu.Game.Utils;
using osu.Framework.Input.Events;
using System;
using osu.Framework.Graphics.Cursor;
namespace osu.Game.Overlays.Comments
{
@ -97,9 +98,19 @@ public DrawableComment(Comment comment)
Spacing = new Vector2(0, 2),
Children = new Drawable[]
{
username = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true))
new FillFlowContainer
{
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))
{
@ -196,5 +207,37 @@ protected override bool OnClick(ClickEvent 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
}
};
}
}
}
}