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
|
|
|
|
|
{
|
|
|
|
|
private readonly CommentableType type;
|
|
|
|
|
private readonly long id;
|
|
|
|
|
|
|
|
|
|
public readonly Bindable<SortCommentsBy> Sort = new Bindable<SortCommentsBy>();
|
2019-10-09 17:18:49 +08:00
|
|
|
|
public readonly BindableBool ShowDeleted = new BindableBool();
|
2019-10-07 22:49:20 +08:00
|
|
|
|
|
|
|
|
|
[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
|
|
|
|
{
|
2019-10-09 17:18:49 +08:00
|
|
|
|
Sort = { BindTarget = Sort },
|
|
|
|
|
ShowDeleted = { BindTarget = ShowDeleted }
|
2019-10-07 23:26:07 +08:00
|
|
|
|
},
|
|
|
|
|
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-09 17:18:49 +08:00
|
|
|
|
if (c.IsTopLevel)
|
|
|
|
|
content.Add(new DrawableComment(c)
|
|
|
|
|
{ ShowDeleted = { BindTarget = ShowDeleted } });
|
2019-10-08 19:51:12 +08:00
|
|
|
|
}
|
2019-10-09 19:10:05 +08:00
|
|
|
|
|
|
|
|
|
int deletedComments = 0;
|
|
|
|
|
|
|
|
|
|
response.Comments.ForEach(comment =>
|
|
|
|
|
{
|
|
|
|
|
if (comment.IsDeleted && comment.IsTopLevel)
|
|
|
|
|
deletedComments++;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
content.Add(new DeletedChildsPlaceholder(deletedComments)
|
|
|
|
|
{
|
|
|
|
|
ShowDeleted = { BindTarget = ShowDeleted }
|
|
|
|
|
});
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|