2019-10-07 22:49:20 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Game.Graphics;
|
2019-10-07 23:26:07 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2019-10-07 22:49:20 +08:00
|
|
|
|
|
2019-10-08 19:51:12 +08:00
|
|
|
|
namespace osu.Game.Overlays.Comments
|
2019-10-07 22:49:20 +08:00
|
|
|
|
{
|
|
|
|
|
public class CommentsContainer : CompositeDrawable
|
|
|
|
|
{
|
2019-10-08 20:39:03 +08:00
|
|
|
|
private const float separator_height = 1.5f;
|
2019-10-09 15:34:17 +08:00
|
|
|
|
private const int padding = 40;
|
2019-10-08 20:39:03 +08:00
|
|
|
|
|
2019-10-07 22:49:20 +08:00
|
|
|
|
private readonly CommentableType type;
|
|
|
|
|
private readonly long id;
|
|
|
|
|
|
|
|
|
|
public readonly Bindable<SortCommentsBy> Sort = new Bindable<SortCommentsBy>();
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private IAPIProvider api { get; set; }
|
|
|
|
|
|
2019-10-07 23:26:07 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
|
|
|
|
|
private GetCommentsRequest request;
|
|
|
|
|
|
2019-10-07 22:49:20 +08:00
|
|
|
|
private readonly Box background;
|
2019-10-07 23:26:07 +08:00
|
|
|
|
private readonly FillFlowContainer content;
|
2019-10-07 22:49:20 +08:00
|
|
|
|
|
|
|
|
|
public CommentsContainer(CommentableType type, long id)
|
|
|
|
|
{
|
|
|
|
|
this.type = type;
|
|
|
|
|
this.id = id;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
background = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
2019-10-07 23:26:07 +08:00
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2019-10-07 23:45:22 +08:00
|
|
|
|
new CommentsHeader
|
2019-10-07 23:26:07 +08:00
|
|
|
|
{
|
|
|
|
|
Sort = { BindTarget = Sort }
|
|
|
|
|
},
|
|
|
|
|
content = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
Sort.BindValueChanged(onSortChanged, true);
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onSortChanged(ValueChangedEvent<SortCommentsBy> sort) => getComments();
|
|
|
|
|
|
|
|
|
|
private void getComments()
|
|
|
|
|
{
|
|
|
|
|
request?.Cancel();
|
2019-10-09 03:46:42 +08:00
|
|
|
|
content.Clear();
|
2019-10-07 23:26:07 +08:00
|
|
|
|
request = new GetCommentsRequest(type, id, Sort.Value);
|
|
|
|
|
request.Success += onSuccess;
|
|
|
|
|
api.Queue(request);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 00:22:23 +08:00
|
|
|
|
private void onSuccess(APICommentsController response)
|
2019-10-07 23:26:07 +08:00
|
|
|
|
{
|
|
|
|
|
foreach (var c in response.Comments)
|
|
|
|
|
{
|
2019-10-08 19:51:12 +08:00
|
|
|
|
if (!c.IsDeleted && c.IsTopLevel)
|
|
|
|
|
content.AddRange(new Drawable[]
|
2019-10-07 23:26:07 +08:00
|
|
|
|
{
|
2019-10-09 15:34:17 +08:00
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Padding = new MarginPadding { Right = padding },
|
|
|
|
|
Child = new DrawableComment(c)
|
|
|
|
|
},
|
2019-10-08 19:51:12 +08:00
|
|
|
|
new Container
|
2019-10-08 18:45:13 +08:00
|
|
|
|
{
|
2019-10-08 19:51:12 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2019-10-08 20:39:03 +08:00
|
|
|
|
Height = separator_height,
|
2019-10-08 19:51:12 +08:00
|
|
|
|
Child = new Box
|
2019-10-08 18:45:13 +08:00
|
|
|
|
{
|
2019-10-08 19:51:12 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = colours.Gray1,
|
|
|
|
|
}
|
2019-10-08 18:45:13 +08:00
|
|
|
|
}
|
2019-10-08 19:51:12 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2019-10-07 22:49:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2019-10-07 23:26:07 +08:00
|
|
|
|
private void load()
|
2019-10-07 22:49:20 +08:00
|
|
|
|
{
|
|
|
|
|
background.Colour = colours.Gray3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|