1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-19 19:13:21 +08:00

Implement CommentsPage class

This commit is contained in:
Andrei Zavatski 2020-01-29 06:22:08 +03:00
parent c5e0c77bca
commit e7964023ae
2 changed files with 79 additions and 51 deletions

View File

@ -12,7 +12,6 @@ using osu.Game.Online.API.Requests.Responses;
using System.Threading; using System.Threading;
using System.Linq; using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Overlays.Comments namespace osu.Game.Overlays.Comments
{ {
@ -163,34 +162,12 @@ namespace osu.Game.Overlays.Comments
private void onSuccess(CommentBundle response) private void onSuccess(CommentBundle response)
{ {
if (!response.Comments.Any())
{
content.Add(new NoCommentsPlaceholder());
moreButton.Hide();
return;
}
loadCancellation = new CancellationTokenSource(); loadCancellation = new CancellationTokenSource();
var page = new FillFlowContainer LoadComponentAsync(new CommentsPage(response)
{ {
RelativeSizeAxes = Axes.X, ShowDeleted = { BindTarget = ShowDeleted }
AutoSizeAxes = Axes.Y, }, loaded =>
Direction = FillDirection.Vertical,
};
foreach (var c in response.Comments)
{
if (c.IsTopLevel)
{
page.Add(new DrawableComment(c)
{
ShowDeleted = { BindTarget = ShowDeleted }
});
}
}
LoadComponentAsync(page, loaded =>
{ {
content.Add(loaded); content.Add(loaded);
@ -217,30 +194,5 @@ namespace osu.Game.Overlays.Comments
loadCancellation?.Cancel(); loadCancellation?.Cancel();
base.Dispose(isDisposing); base.Dispose(isDisposing);
} }
private class NoCommentsPlaceholder : CompositeDrawable
{
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
Height = 80;
RelativeSizeAxes = Axes.X;
AddRangeInternal(new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background4
},
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Left = 50 },
Text = @"No comments yet."
}
});
}
}
} }
} }

View File

@ -0,0 +1,76 @@
// 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.Framework.Graphics;
using osu.Framework.Bindables;
using osu.Game.Online.API.Requests.Responses;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Sprites;
using System.Linq;
namespace osu.Game.Overlays.Comments
{
public class CommentsPage : FillFlowContainer
{
public readonly BindableBool ShowDeleted = new BindableBool();
private readonly CommentBundle commentBundle;
public CommentsPage(CommentBundle commentBundle)
{
this.commentBundle = commentBundle;
}
[BackgroundDependencyLoader]
private void load()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Direction = FillDirection.Vertical;
if (!commentBundle.Comments.Any())
{
Add(new NoCommentsPlaceholder());
return;
}
foreach (var c in commentBundle.Comments)
{
if (c.IsTopLevel)
{
Add(new DrawableComment(c)
{
ShowDeleted = { BindTarget = ShowDeleted }
});
}
}
}
private class NoCommentsPlaceholder : CompositeDrawable
{
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
Height = 80;
RelativeSizeAxes = Axes.X;
AddRangeInternal(new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background4
},
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Left = 50 },
Text = @"No comments yet."
}
});
}
}
}
}