1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 20:07:29 +08:00
osu-lazer/osu.Game/Overlays/Comments/CommentsContainer.cs

124 lines
3.9 KiB
C#
Raw Normal View History

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.Game.Online.API.Requests.Responses;
2019-10-07 22:49:20 +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; }
[Resolved]
private OsuColour colours { get; set; }
private GetCommentsRequest request;
2019-10-07 22:49:20 +08:00
private readonly Box background;
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,
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
2019-10-07 23:45:22 +08:00
new CommentsHeader
{
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();
request = new GetCommentsRequest(type, id, Sort.Value);
request.Success += onSuccess;
api.Queue(request);
}
private void onSuccess(APICommentsController response)
{
foreach (var c in response.Comments)
{
if (!c.IsDeleted && c.IsTopLevel)
content.AddRange(new Drawable[]
{
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)
},
new Container
{
RelativeSizeAxes = Axes.X,
2019-10-08 20:39:03 +08:00
Height = separator_height,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colours.Gray1,
}
}
});
}
2019-10-07 22:49:20 +08:00
}
[BackgroundDependencyLoader]
private void load()
2019-10-07 22:49:20 +08:00
{
background.Colour = colours.Gray3;
}
}
}