mirror of
https://github.com/ppy/osu
synced 2025-02-15 09:37:07 +00:00
Parse child comments
This commit is contained in:
parent
2564214a72
commit
451a7342ce
@ -9,8 +9,28 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
{
|
||||
public class APIComments
|
||||
{
|
||||
private List<Comment> comments;
|
||||
|
||||
[JsonProperty(@"comments")]
|
||||
public List<Comment> Comments { get; set; }
|
||||
public List<Comment> Comments
|
||||
{
|
||||
get => comments;
|
||||
set
|
||||
{
|
||||
comments = value;
|
||||
comments.ForEach(child =>
|
||||
{
|
||||
if (child.ParentId != null)
|
||||
{
|
||||
comments.ForEach(parent =>
|
||||
{
|
||||
if (parent.Id == child.ParentId)
|
||||
parent.ChildComments.Add(child);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty(@"has_more")]
|
||||
public bool HasMore { get; set; }
|
||||
|
@ -4,6 +4,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using osu.Game.Users;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace osu.Game.Online.API.Requests.Responses
|
||||
{
|
||||
@ -25,6 +26,8 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
}
|
||||
}
|
||||
|
||||
public List<Comment> ChildComments = new List<Comment>();
|
||||
|
||||
[JsonProperty(@"user_id")]
|
||||
public long UserId { get; set; }
|
||||
|
||||
|
@ -17,6 +17,8 @@ namespace osu.Game.Overlays.Comments
|
||||
{
|
||||
public class CommentsContainer : CompositeDrawable
|
||||
{
|
||||
private const float separator_height = 1.5f;
|
||||
|
||||
private readonly CommentableType type;
|
||||
private readonly long id;
|
||||
|
||||
@ -97,7 +99,7 @@ namespace osu.Game.Overlays.Comments
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 1,
|
||||
Height = separator_height,
|
||||
Child = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
|
@ -17,78 +17,102 @@ namespace osu.Game.Overlays.Comments
|
||||
{
|
||||
private const int avatar_size = 40;
|
||||
private const int margin = 10;
|
||||
private const int child_margin = 20;
|
||||
|
||||
public DrawableComment(Comment comment)
|
||||
{
|
||||
LinkFlowContainer username;
|
||||
FillFlowContainer childCommentsContainer;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
InternalChild = new GridContainer
|
||||
InternalChild = new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Margin = new MarginPadding(margin),
|
||||
ColumnDimensions = new[]
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
new Dimension(),
|
||||
},
|
||||
RowDimensions = new[]
|
||||
{
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
new Dimension(GridSizeMode.AutoSize)
|
||||
},
|
||||
Content = new[]
|
||||
{
|
||||
new Drawable[]
|
||||
new GridContainer
|
||||
{
|
||||
new UpdateableAvatar(comment.User)
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Margin = new MarginPadding(margin),
|
||||
ColumnDimensions = new[]
|
||||
{
|
||||
Size = new Vector2(avatar_size),
|
||||
Margin = new MarginPadding { Horizontal = margin },
|
||||
Masking = true,
|
||||
CornerRadius = avatar_size / 2,
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
new Dimension(),
|
||||
},
|
||||
new FillFlowContainer
|
||||
RowDimensions = new[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Margin = new MarginPadding { Top = margin / 2 },
|
||||
Spacing = new Vector2(0, 2),
|
||||
Children = new Drawable[]
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
new Dimension(GridSizeMode.AutoSize)
|
||||
},
|
||||
Content = new[]
|
||||
{
|
||||
new Drawable[]
|
||||
{
|
||||
username = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true))
|
||||
new UpdateableAvatar(comment.User)
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Size = new Vector2(avatar_size),
|
||||
Margin = new MarginPadding { Horizontal = margin },
|
||||
Masking = true,
|
||||
CornerRadius = avatar_size / 2,
|
||||
},
|
||||
new TextFlowContainer(s => s.Font = OsuFont.GetFont(size: 14))
|
||||
new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Text = comment.GetMessage()
|
||||
Margin = new MarginPadding { Top = margin / 2 },
|
||||
Spacing = new Vector2(0, 2),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
username = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true))
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
},
|
||||
new TextFlowContainer(s => s.Font = OsuFont.GetFont(size: 14))
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Text = comment.GetMessage()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new Drawable[]
|
||||
{
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
new SpriteText
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Font = OsuFont.GetFont(size: 12),
|
||||
Text = HumanizerUtils.Humanize(comment.CreatedAt)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new Drawable[]
|
||||
childCommentsContainer = new FillFlowContainer
|
||||
{
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
new SpriteText
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Font = OsuFont.GetFont(size: 12),
|
||||
Text = HumanizerUtils.Humanize(comment.CreatedAt)
|
||||
}
|
||||
Margin = new MarginPadding { Left = child_margin },
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
username.AddUserLink(comment.User);
|
||||
|
||||
comment.ChildComments.ForEach(c =>
|
||||
{
|
||||
if (!c.IsDeleted)
|
||||
childCommentsContainer.Add(new DrawableComment(c));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user