1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:17:26 +08:00

Add support for displaying "mapper" badges in comments

This commit is contained in:
Salman Ahmed 2024-02-14 03:48:45 +03:00
parent 72c6134dbf
commit 4d3b605e04
2 changed files with 48 additions and 3 deletions

View File

@ -4,7 +4,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
@ -23,12 +22,14 @@ namespace osu.Game.Overlays.Comments
public partial class CommentAuthorLine : FillFlowContainer public partial class CommentAuthorLine : FillFlowContainer
{ {
private readonly Comment comment; private readonly Comment comment;
private readonly IReadOnlyList<CommentableMeta> meta;
private OsuSpriteText deletedLabel = null!; private OsuSpriteText deletedLabel = null!;
public CommentAuthorLine(Comment comment) public CommentAuthorLine(Comment comment, IReadOnlyList<CommentableMeta> meta)
{ {
this.comment = comment; this.comment = comment;
this.meta = meta;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -49,6 +50,17 @@ namespace osu.Game.Overlays.Comments
username.AddText(comment.LegacyName!); username.AddText(comment.LegacyName!);
})); }));
var ownerMeta = meta.FirstOrDefault(m => m.Id == comment.CommentableId && m.Type == comment.CommentableType);
if (ownerMeta?.OwnerId != null && ownerMeta.OwnerId == comment.UserId)
{
Add(new OwnerTitleBadge(ownerMeta.OwnerTitle ?? string.Empty)
{
// add top space to align with username
Margin = new MarginPadding { Top = 2f },
});
}
if (comment.Pinned) if (comment.Pinned)
Add(new PinnedCommentNotice()); Add(new PinnedCommentNotice());
@ -67,6 +79,39 @@ namespace osu.Game.Overlays.Comments
deletedLabel.Show(); deletedLabel.Show();
} }
private partial class OwnerTitleBadge : CircularContainer
{
private readonly string title;
public OwnerTitleBadge(string title)
{
this.title = title;
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
AutoSizeAxes = Axes.Both;
Masking = true;
InternalChildren = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Light1,
},
new OsuSpriteText
{
Text = title,
Font = OsuFont.Default.With(size: 10, weight: FontWeight.Bold),
Margin = new MarginPadding { Vertical = 2, Horizontal = 5 },
Colour = colourProvider.Background6,
},
};
}
}
private partial class PinnedCommentNotice : FillFlowContainer private partial class PinnedCommentNotice : FillFlowContainer
{ {
public PinnedCommentNotice() public PinnedCommentNotice()

View File

@ -172,7 +172,7 @@ namespace osu.Game.Overlays.Comments
}, },
Children = new Drawable[] Children = new Drawable[]
{ {
author = new CommentAuthorLine(Comment), author = new CommentAuthorLine(Comment, Meta),
message = new CommentMarkdownContainer message = new CommentMarkdownContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,