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;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osuTK;
|
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-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();
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
content.Clear();
|
|
|
|
|
|
|
|
|
|
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-08 19:51:12 +08:00
|
|
|
|
new DrawableComment(c),
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class CommentsHeader : CompositeDrawable
|
|
|
|
|
{
|
|
|
|
|
private const int height = 40;
|
|
|
|
|
private const int spacing = 10;
|
|
|
|
|
private const int padding = 50;
|
|
|
|
|
|
|
|
|
|
public readonly Bindable<SortCommentsBy> Sort = new Bindable<SortCommentsBy>();
|
|
|
|
|
|
|
|
|
|
private readonly Box background;
|
|
|
|
|
|
|
|
|
|
public CommentsHeader()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Height = height;
|
|
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
background = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding { Horizontal = padding },
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(spacing, 0),
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Font = OsuFont.GetFont(size: 14),
|
|
|
|
|
Text = @"Sort by"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
background.Colour = colours.Gray4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|