1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 16:52:55 +08:00

Make report button a separate component

This commit is contained in:
ansel 2022-10-20 18:47:42 +03:00
parent da4f04ace7
commit 0ef903230c

View File

@ -34,7 +34,8 @@ using osu.Game.Resources.Localisation.Web;
namespace osu.Game.Overlays.Comments namespace osu.Game.Overlays.Comments
{ {
public class DrawableComment : CompositeDrawable, IHasPopover [Cached]
public class DrawableComment : CompositeDrawable
{ {
private const int avatar_size = 40; private const int avatar_size = 40;
@ -64,6 +65,7 @@ namespace osu.Game.Overlays.Comments
private ShowRepliesButton showRepliesButton = null!; private ShowRepliesButton showRepliesButton = null!;
private ChevronButton chevronButton = null!; private ChevronButton chevronButton = null!;
private LinkFlowContainer actionsContainer = null!; private LinkFlowContainer actionsContainer = null!;
private ReportButton? reportButton;
private LoadingSpinner actionsLoading = null!; private LoadingSpinner actionsLoading = null!;
private DeletedCommentsCounter deletedCommentsCounter = null!; private DeletedCommentsCounter deletedCommentsCounter = null!;
private OsuSpriteText deletedLabel = null!; private OsuSpriteText deletedLabel = null!;
@ -334,12 +336,12 @@ namespace osu.Game.Overlays.Comments
makeDeleted(); makeDeleted();
actionsContainer.AddLink("Copy link", copyUrl); actionsContainer.AddLink("Copy link", copyUrl);
actionsContainer.AddArbitraryDrawable(new Container { Width = 10 }); actionsContainer.AddArbitraryDrawable(Empty().With(d => d.Width = 10));
if (Comment.UserId.HasValue && Comment.UserId.Value == api.LocalUser.Value.Id) if (Comment.UserId.HasValue && Comment.UserId.Value == api.LocalUser.Value.Id)
actionsContainer.AddLink("Delete", deleteComment); actionsContainer.AddLink("Delete", deleteComment);
else else
actionsContainer.AddLink(UsersStrings.ReportButtonText, this.ShowPopover); actionsContainer.AddArbitraryDrawable(reportButton = new ReportButton());
if (Comment.IsTopLevel) if (Comment.IsTopLevel)
{ {
@ -424,6 +426,8 @@ namespace osu.Game.Overlays.Comments
request.Success += () => Schedule(() => request.Success += () => Schedule(() =>
{ {
actionsLoading.Hide(); actionsLoading.Hide();
reportButton?.Expire();
actionsContainer.Show();
onScreenDisplay?.Display(new ReportToast()); onScreenDisplay?.Display(new ReportToast());
}); });
request.Failure += _ => Schedule(() => request.Failure += _ => Schedule(() =>
@ -582,8 +586,6 @@ namespace osu.Game.Overlays.Comments
} }
} }
public Popover GetPopover() => new ReportCommentPopover(this);
private class ReportToast : Toast private class ReportToast : Toast
{ {
public ReportToast() public ReportToast()
@ -591,5 +593,25 @@ namespace osu.Game.Overlays.Comments
{ {
} }
} }
private class ReportButton : LinkFlowContainer, IHasPopover
{
public ReportButton()
: base(s => s.Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold))
{
}
[Resolved]
private DrawableComment comment { get; set; } = null!;
[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Both;
AddLink(UsersStrings.ReportButtonText, this.ShowPopover);
}
public Popover GetPopover() => new ReportCommentPopover(comment);
}
} }
} }