From 5267e0abf788da62e6eaaa1fed1ac35be0fcb428 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 14 Feb 2024 03:38:49 +0300 Subject: [PATCH 1/8] Move comment author line to separate component --- .../Overlays/Comments/CommentAuthorLine.cs | 135 ++++++++++++++++++ osu.Game/Overlays/Comments/DrawableComment.cs | 102 +------------ 2 files changed, 139 insertions(+), 98 deletions(-) create mode 100644 osu.Game/Overlays/Comments/CommentAuthorLine.cs diff --git a/osu.Game/Overlays/Comments/CommentAuthorLine.cs b/osu.Game/Overlays/Comments/CommentAuthorLine.cs new file mode 100644 index 0000000000..b6b5dc00e1 --- /dev/null +++ b/osu.Game/Overlays/Comments/CommentAuthorLine.cs @@ -0,0 +1,135 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Extensions.ObjectExtensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Localisation; +using osu.Game.Graphics; +using osu.Game.Graphics.Containers; +using osu.Game.Graphics.Sprites; +using osu.Game.Online.API.Requests.Responses; +using osu.Game.Resources.Localisation.Web; +using osuTK; + +namespace osu.Game.Overlays.Comments +{ + public partial class CommentAuthorLine : FillFlowContainer + { + private readonly Comment comment; + + private OsuSpriteText deletedLabel = null!; + + public CommentAuthorLine(Comment comment) + { + this.comment = comment; + } + + [BackgroundDependencyLoader] + private void load() + { + AutoSizeAxes = Axes.Both; + Direction = FillDirection.Horizontal; + Spacing = new Vector2(4, 0); + + Add(new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold)) + { + AutoSizeAxes = Axes.Both + }.With(username => + { + if (comment.UserId.HasValue) + username.AddUserLink(comment.User); + else + username.AddText(comment.LegacyName!); + })); + + if (comment.Pinned) + Add(new PinnedCommentNotice()); + + Add(new ParentUsername(comment)); + + Add(deletedLabel = new OsuSpriteText + { + Alpha = 0f, + Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold), + Text = CommentsStrings.Deleted + }); + } + + public void MarkDeleted() + { + deletedLabel.Show(); + } + + private partial class PinnedCommentNotice : FillFlowContainer + { + public PinnedCommentNotice() + { + AutoSizeAxes = Axes.Both; + Direction = FillDirection.Horizontal; + Spacing = new Vector2(2, 0); + Children = new Drawable[] + { + new SpriteIcon + { + Icon = FontAwesome.Solid.Thumbtack, + Size = new Vector2(14), + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + }, + new OsuSpriteText + { + Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold), + Text = CommentsStrings.Pinned, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + } + }; + } + } + + private partial class ParentUsername : FillFlowContainer, IHasTooltip + { + public LocalisableString TooltipText => getParentMessage(); + + private readonly Comment? parentComment; + + public ParentUsername(Comment comment) + { + parentComment = comment.ParentComment; + + AutoSizeAxes = Axes.Both; + Direction = FillDirection.Horizontal; + Spacing = new Vector2(3, 0); + Alpha = comment.ParentId == null ? 0 : 1; + Children = new Drawable[] + { + new SpriteIcon + { + Icon = FontAwesome.Solid.Reply, + Size = new Vector2(14), + }, + new OsuSpriteText + { + Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true), + Text = parentComment?.User?.Username ?? parentComment?.LegacyName! + } + }; + } + + private LocalisableString getParentMessage() + { + if (parentComment == null) + return string.Empty; + + return parentComment.HasMessage ? parentComment.Message : parentComment.IsDeleted ? CommentsStrings.Deleted : string.Empty; + } + } + } +} diff --git a/osu.Game/Overlays/Comments/DrawableComment.cs b/osu.Game/Overlays/Comments/DrawableComment.cs index ceae17aa5d..70b1809c3e 100644 --- a/osu.Game/Overlays/Comments/DrawableComment.cs +++ b/osu.Game/Overlays/Comments/DrawableComment.cs @@ -4,12 +4,10 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics; using osu.Game.Graphics; -using osu.Framework.Graphics.Sprites; using osuTK; using osu.Game.Online.API.Requests.Responses; using osu.Game.Users.Drawables; using osu.Game.Graphics.Containers; -using osu.Framework.Graphics.Cursor; using osu.Framework.Bindables; using System.Linq; using osu.Game.Graphics.Sprites; @@ -21,7 +19,6 @@ using osu.Framework.Extensions.IEnumerableExtensions; using System.Collections.Specialized; using System.Diagnostics; using osu.Framework.Extensions.LocalisationExtensions; -using osu.Framework.Localisation; using osu.Framework.Logging; using osu.Framework.Platform; using osu.Game.Graphics.UserInterface; @@ -72,7 +69,7 @@ namespace osu.Game.Overlays.Comments private LinkFlowContainer actionsContainer = null!; private LoadingSpinner actionsLoading = null!; private DeletedCommentsCounter deletedCommentsCounter = null!; - private OsuSpriteText deletedLabel = null!; + private CommentAuthorLine author = null!; private GridContainer content = null!; private VotePill votePill = null!; private Container replyEditorContainer = null!; @@ -98,7 +95,6 @@ namespace osu.Game.Overlays.Comments [BackgroundDependencyLoader] private void load(OverlayColourProvider colourProvider, DrawableComment? parentComment) { - LinkFlowContainer username; FillFlowContainer info; CommentMarkdownContainer message; @@ -174,27 +170,7 @@ namespace osu.Game.Overlays.Comments }, Children = new Drawable[] { - new FillFlowContainer - { - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Horizontal, - Spacing = new Vector2(10, 0), - Children = new[] - { - username = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold)) - { - AutoSizeAxes = Axes.Both - }, - Comment.Pinned ? new PinnedCommentNotice() : Empty(), - new ParentUsername(Comment), - deletedLabel = new OsuSpriteText - { - Alpha = 0f, - Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold), - Text = CommentsStrings.Deleted - } - } - }, + author = new CommentAuthorLine(Comment), message = new CommentMarkdownContainer { RelativeSizeAxes = Axes.X, @@ -218,7 +194,7 @@ namespace osu.Game.Overlays.Comments { new DrawableDate(Comment.CreatedAt, 12, false) { - Colour = colourProvider.Foreground1 + Colour = colourProvider.Foreground1, } } }, @@ -311,11 +287,6 @@ namespace osu.Game.Overlays.Comments } }; - if (Comment.UserId.HasValue) - username.AddUserLink(Comment.User); - else - username.AddText(Comment.LegacyName!); - if (Comment.EditedAt.HasValue && Comment.EditedUser != null) { var font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular); @@ -400,7 +371,7 @@ namespace osu.Game.Overlays.Comments /// private void makeDeleted() { - deletedLabel.Show(); + author.MarkDeleted(); content.FadeColour(OsuColour.Gray(0.5f)); votePill.Hide(); actionsContainer.Expire(); @@ -547,70 +518,5 @@ namespace osu.Game.Overlays.Comments Top = 10 }; } - - private partial class PinnedCommentNotice : FillFlowContainer - { - public PinnedCommentNotice() - { - AutoSizeAxes = Axes.Both; - Direction = FillDirection.Horizontal; - Spacing = new Vector2(2, 0); - Children = new Drawable[] - { - new SpriteIcon - { - Icon = FontAwesome.Solid.Thumbtack, - Size = new Vector2(14), - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - }, - new OsuSpriteText - { - Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold), - Text = CommentsStrings.Pinned, - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - } - }; - } - } - - private partial class ParentUsername : FillFlowContainer, IHasTooltip - { - public LocalisableString TooltipText => getParentMessage(); - - private readonly Comment? parentComment; - - public ParentUsername(Comment comment) - { - parentComment = comment.ParentComment; - - AutoSizeAxes = Axes.Both; - Direction = FillDirection.Horizontal; - Spacing = new Vector2(3, 0); - Alpha = comment.ParentId == null ? 0 : 1; - Children = new Drawable[] - { - new SpriteIcon - { - Icon = FontAwesome.Solid.Reply, - Size = new Vector2(14), - }, - new OsuSpriteText - { - Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true), - Text = parentComment?.User?.Username ?? parentComment?.LegacyName! - } - }; - } - - private LocalisableString getParentMessage() - { - if (parentComment == null) - return string.Empty; - - return parentComment.HasMessage ? parentComment.Message : parentComment.IsDeleted ? CommentsStrings.Deleted : string.Empty; - } - } } } From c4e358044a5f0478119c39309dd7525483847413 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 14 Feb 2024 03:44:32 +0300 Subject: [PATCH 2/8] Add API models for comment page metadata --- .../API/Requests/Responses/CommentBundle.cs | 3 ++ .../API/Requests/Responses/CommentableMeta.cs | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 osu.Game/Online/API/Requests/Responses/CommentableMeta.cs diff --git a/osu.Game/Online/API/Requests/Responses/CommentBundle.cs b/osu.Game/Online/API/Requests/Responses/CommentBundle.cs index ae8b850723..cbff8bf76c 100644 --- a/osu.Game/Online/API/Requests/Responses/CommentBundle.cs +++ b/osu.Game/Online/API/Requests/Responses/CommentBundle.cs @@ -11,6 +11,9 @@ namespace osu.Game.Online.API.Requests.Responses { public class CommentBundle { + [JsonProperty(@"commentable_meta")] + public List CommentableMeta { get; set; } = new List(); + [JsonProperty(@"comments")] public List Comments { get; set; } diff --git a/osu.Game/Online/API/Requests/Responses/CommentableMeta.cs b/osu.Game/Online/API/Requests/Responses/CommentableMeta.cs new file mode 100644 index 0000000000..1084f1c900 --- /dev/null +++ b/osu.Game/Online/API/Requests/Responses/CommentableMeta.cs @@ -0,0 +1,28 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using Newtonsoft.Json; + +namespace osu.Game.Online.API.Requests.Responses +{ + public class CommentableMeta + { + [JsonProperty("id")] + public long Id { get; set; } + + [JsonProperty("owner_id")] + public long? OwnerId { get; set; } + + [JsonProperty("owner_title")] + public string? OwnerTitle { get; set; } + + [JsonProperty("title")] + public string Title { get; set; } = string.Empty; + + [JsonProperty("type")] + public string Type { get; set; } = string.Empty; + + [JsonProperty("url")] + public string Url { get; set; } = string.Empty; + } +} From 72c6134dbff17ba8a7a2ee82a741a61412bdfa1d Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 14 Feb 2024 03:46:19 +0300 Subject: [PATCH 3/8] Include commentable object metadata in comments --- osu.Game/Overlays/Comments/CommentsContainer.cs | 8 ++++---- osu.Game/Overlays/Comments/DrawableComment.cs | 4 +++- osu.Game/Overlays/Comments/ReplyCommentEditor.cs | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/Comments/CommentsContainer.cs b/osu.Game/Overlays/Comments/CommentsContainer.cs index b4e9a80ff1..2e5f13aa99 100644 --- a/osu.Game/Overlays/Comments/CommentsContainer.cs +++ b/osu.Game/Overlays/Comments/CommentsContainer.cs @@ -301,7 +301,7 @@ namespace osu.Game.Overlays.Comments void addNewComment(Comment comment) { - var drawableComment = GetDrawableComment(comment); + var drawableComment = GetDrawableComment(comment, bundle.CommentableMeta); if (comment.ParentId == null) { @@ -333,7 +333,7 @@ namespace osu.Game.Overlays.Comments if (CommentDictionary.ContainsKey(comment.Id)) continue; - topLevelComments.Add(GetDrawableComment(comment)); + topLevelComments.Add(GetDrawableComment(comment, bundle.CommentableMeta)); } if (topLevelComments.Any()) @@ -351,12 +351,12 @@ namespace osu.Game.Overlays.Comments } } - public DrawableComment GetDrawableComment(Comment comment) + public DrawableComment GetDrawableComment(Comment comment, IReadOnlyList meta) { if (CommentDictionary.TryGetValue(comment.Id, out var existing)) return existing; - return CommentDictionary[comment.Id] = new DrawableComment(comment) + return CommentDictionary[comment.Id] = new DrawableComment(comment, meta) { ShowDeleted = { BindTarget = ShowDeleted }, Sort = { BindTarget = Sort }, diff --git a/osu.Game/Overlays/Comments/DrawableComment.cs b/osu.Game/Overlays/Comments/DrawableComment.cs index 70b1809c3e..afb8bdcc8b 100644 --- a/osu.Game/Overlays/Comments/DrawableComment.cs +++ b/osu.Game/Overlays/Comments/DrawableComment.cs @@ -39,6 +39,7 @@ namespace osu.Game.Overlays.Comments public Action RepliesRequested = null!; public readonly Comment Comment; + public readonly IReadOnlyList Meta; public readonly BindableBool ShowDeleted = new BindableBool(); public readonly Bindable Sort = new Bindable(); @@ -87,9 +88,10 @@ namespace osu.Game.Overlays.Comments [Resolved] private OnScreenDisplay? onScreenDisplay { get; set; } - public DrawableComment(Comment comment) + public DrawableComment(Comment comment, IReadOnlyList meta) { Comment = comment; + Meta = meta; } [BackgroundDependencyLoader] diff --git a/osu.Game/Overlays/Comments/ReplyCommentEditor.cs b/osu.Game/Overlays/Comments/ReplyCommentEditor.cs index dd4c35ef20..8e9e82507d 100644 --- a/osu.Game/Overlays/Comments/ReplyCommentEditor.cs +++ b/osu.Game/Overlays/Comments/ReplyCommentEditor.cs @@ -60,7 +60,7 @@ namespace osu.Game.Overlays.Comments foreach (var comment in cb.Comments) comment.ParentComment = parentComment; - var drawables = cb.Comments.Select(commentsContainer.GetDrawableComment).ToArray(); + var drawables = cb.Comments.Select(c => commentsContainer.GetDrawableComment(c, cb.CommentableMeta)).ToArray(); OnPost?.Invoke(drawables); OnCancel!.Invoke(); From 4d3b605e04d73ff69031d2d4c97ddcd937cb043f Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 14 Feb 2024 03:48:45 +0300 Subject: [PATCH 4/8] Add support for displaying "mapper" badges in comments --- .../Overlays/Comments/CommentAuthorLine.cs | 49 ++++++++++++++++++- osu.Game/Overlays/Comments/DrawableComment.cs | 2 +- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/Comments/CommentAuthorLine.cs b/osu.Game/Overlays/Comments/CommentAuthorLine.cs index b6b5dc00e1..c269ab4c01 100644 --- a/osu.Game/Overlays/Comments/CommentAuthorLine.cs +++ b/osu.Game/Overlays/Comments/CommentAuthorLine.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; -using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; @@ -23,12 +22,14 @@ namespace osu.Game.Overlays.Comments public partial class CommentAuthorLine : FillFlowContainer { private readonly Comment comment; + private readonly IReadOnlyList meta; private OsuSpriteText deletedLabel = null!; - public CommentAuthorLine(Comment comment) + public CommentAuthorLine(Comment comment, IReadOnlyList meta) { this.comment = comment; + this.meta = meta; } [BackgroundDependencyLoader] @@ -49,6 +50,17 @@ namespace osu.Game.Overlays.Comments 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) Add(new PinnedCommentNotice()); @@ -67,6 +79,39 @@ namespace osu.Game.Overlays.Comments 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 { public PinnedCommentNotice() diff --git a/osu.Game/Overlays/Comments/DrawableComment.cs b/osu.Game/Overlays/Comments/DrawableComment.cs index afb8bdcc8b..afd4b96c68 100644 --- a/osu.Game/Overlays/Comments/DrawableComment.cs +++ b/osu.Game/Overlays/Comments/DrawableComment.cs @@ -172,7 +172,7 @@ namespace osu.Game.Overlays.Comments }, Children = new Drawable[] { - author = new CommentAuthorLine(Comment), + author = new CommentAuthorLine(Comment, Meta), message = new CommentMarkdownContainer { RelativeSizeAxes = Axes.X, From c24af5bfeb65ea125ebdd1c37e8c3e0a296ef78e Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Wed, 14 Feb 2024 03:49:29 +0300 Subject: [PATCH 5/8] Add test coverage --- .../Online/TestSceneCommentsContainer.cs | 41 ++++++++- .../Visual/Online/TestSceneDrawableComment.cs | 88 ++++++++++--------- .../UserInterface/ThemeComparisonTestScene.cs | 30 ++++--- 3 files changed, 103 insertions(+), 56 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs index 3d8781d902..fd3552f675 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs @@ -170,6 +170,24 @@ namespace osu.Game.Tests.Visual.Online }); } + [Test] + public void TestPostAsOwner() + { + setUpCommentsResponse(getExampleComments()); + AddStep("show comments", () => commentsContainer.ShowComments(CommentableType.Beatmapset, 123)); + + setUpPostResponse(true); + AddStep("enter text", () => editorTextBox.Current.Value = "comm"); + AddStep("submit", () => commentsContainer.ChildrenOfType().Single().ChildrenOfType().First().TriggerClick()); + + AddUntilStep("comment sent", () => + { + string writtenText = editorTextBox.Current.Value; + var comment = commentsContainer.ChildrenOfType().LastOrDefault(); + return comment != null && comment.ChildrenOfType().Any(y => y.Text == writtenText) && comment.ChildrenOfType().Any(y => y.Text == "MAPPER"); + }); + } + private void setUpCommentsResponse(CommentBundle commentBundle) => AddStep("set up response", () => { @@ -183,7 +201,7 @@ namespace osu.Game.Tests.Visual.Online }; }); - private void setUpPostResponse() + private void setUpPostResponse(bool asOwner = false) => AddStep("set up response", () => { dummyAPI.HandleRequest = request => @@ -191,7 +209,7 @@ namespace osu.Game.Tests.Visual.Online if (!(request is CommentPostRequest req)) return false; - req.TriggerSuccess(new CommentBundle + var bundle = new CommentBundle { Comments = new List { @@ -202,9 +220,26 @@ namespace osu.Game.Tests.Visual.Online LegacyName = "FirstUser", CreatedAt = DateTimeOffset.Now, VotesCount = 98, + CommentableId = 2001, + CommentableType = "test", } } - }); + }; + + if (asOwner) + { + bundle.Comments[0].UserId = 1001; + bundle.Comments[0].User = new APIUser { Id = 1001, Username = "FirstUser" }; + bundle.CommentableMeta.Add(new CommentableMeta + { + Id = 2001, + OwnerId = 1001, + OwnerTitle = "MAPPER", + Type = "test", + }); + } + + req.TriggerSuccess(bundle); return true; }; }); diff --git a/osu.Game.Tests/Visual/Online/TestSceneDrawableComment.cs b/osu.Game.Tests/Visual/Online/TestSceneDrawableComment.cs index 5e83dd4fb3..6f09e4c1f6 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneDrawableComment.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneDrawableComment.cs @@ -4,62 +4,66 @@ #nullable disable using System; -using NUnit.Framework; -using osu.Framework.Allocation; +using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics.Containers; using osu.Game.Online.API.Requests.Responses; -using osu.Game.Overlays; using osu.Game.Overlays.Comments; +using osu.Game.Tests.Visual.UserInterface; namespace osu.Game.Tests.Visual.Online { - public partial class TestSceneDrawableComment : OsuTestScene + public partial class TestSceneDrawableComment : ThemeComparisonTestScene { - [Cached] - private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple); - - private Container container; - - [SetUp] - public void SetUp() => Schedule(() => + public TestSceneDrawableComment() + : base(false) { - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = colourProvider.Background4, - }, - container = new Container - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - }, - }; - }); - - [TestCaseSource(nameof(comments))] - public void TestComment(string description, string text) - { - AddStep(description, () => - { - comment.Pinned = description == "Pinned"; - comment.Message = text; - container.Add(new DrawableComment(comment)); - }); } - private static readonly Comment comment = new Comment + protected override Drawable CreateContent() => new OsuScrollContainer(Direction.Vertical) { - Id = 1, - LegacyName = "Test User", - CreatedAt = DateTimeOffset.Now, - VotesCount = 0, + RelativeSizeAxes = Axes.Both, + Child = new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + ChildrenEnumerable = comments.Select(info => + { + var comment = new Comment + { + Id = 1, + UserId = 1000, + User = new APIUser { Id = 1000, Username = "Someone" }, + CreatedAt = DateTimeOffset.Now, + VotesCount = 0, + Pinned = info[0] == "Pinned", + Message = info[1], + CommentableId = 2001, + CommentableType = "test" + }; + + return new[] + { + new DrawableComment(comment, Array.Empty()), + new DrawableComment(comment, new[] + { + new CommentableMeta + { + Id = 2001, + OwnerId = comment.UserId, + OwnerTitle = "MAPPER", + Type = "test", + }, + new CommentableMeta { Title = "Other Meta" }, + }), + }; + }).SelectMany(c => c) + } }; - private static object[] comments = + private static readonly string[][] comments = { new[] { "Plain", "This is plain comment" }, new[] { "Pinned", "This is pinned comment" }, diff --git a/osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs b/osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs index 2c894eacab..f0c4b5543f 100644 --- a/osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs +++ b/osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs @@ -14,31 +14,39 @@ namespace osu.Game.Tests.Visual.UserInterface { public abstract partial class ThemeComparisonTestScene : OsuGridTestScene { - protected ThemeComparisonTestScene() - : base(1, 2) + private readonly bool showNoColourProvider; + + protected ThemeComparisonTestScene(bool showNoColourProvider = true) + : base(1, showNoColourProvider ? 2 : 1) { + this.showNoColourProvider = showNoColourProvider; } [BackgroundDependencyLoader] private void load(OsuColour colours) { - Cell(0, 0).AddRange(new[] + if (showNoColourProvider) { - new Box + Cell(0, 0).AddRange(new[] { - RelativeSizeAxes = Axes.Both, - Colour = colours.GreySeaFoam - }, - CreateContent() - }); + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = colours.GreySeaFoam + }, + CreateContent() + }); + } } protected void CreateThemedContent(OverlayColourScheme colourScheme) { var colourProvider = new OverlayColourProvider(colourScheme); - Cell(0, 1).Clear(); - Cell(0, 1).Add(new DependencyProvidingContainer + int col = showNoColourProvider ? 1 : 0; + + Cell(0, col).Clear(); + Cell(0, col).Add(new DependencyProvidingContainer { RelativeSizeAxes = Axes.Both, CachedDependencies = new (Type, object)[] From d189fa0f6907afbe9f8a83a10c6a712e793a9efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 14 Feb 2024 11:53:41 +0100 Subject: [PATCH 6/8] Rename flag --- .../Visual/UserInterface/ThemeComparisonTestScene.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs b/osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs index f0c4b5543f..3177695f44 100644 --- a/osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs +++ b/osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs @@ -14,18 +14,18 @@ namespace osu.Game.Tests.Visual.UserInterface { public abstract partial class ThemeComparisonTestScene : OsuGridTestScene { - private readonly bool showNoColourProvider; + private readonly bool showWithoutColourProvider; - protected ThemeComparisonTestScene(bool showNoColourProvider = true) - : base(1, showNoColourProvider ? 2 : 1) + protected ThemeComparisonTestScene(bool showWithoutColourProvider = true) + : base(1, showWithoutColourProvider ? 2 : 1) { - this.showNoColourProvider = showNoColourProvider; + this.showWithoutColourProvider = showWithoutColourProvider; } [BackgroundDependencyLoader] private void load(OsuColour colours) { - if (showNoColourProvider) + if (showWithoutColourProvider) { Cell(0, 0).AddRange(new[] { @@ -43,7 +43,7 @@ namespace osu.Game.Tests.Visual.UserInterface { var colourProvider = new OverlayColourProvider(colourScheme); - int col = showNoColourProvider ? 1 : 0; + int col = showWithoutColourProvider ? 1 : 0; Cell(0, col).Clear(); Cell(0, col).Add(new DependencyProvidingContainer From 8312f92b4ea24a981b6916f5207aaaf747471546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 14 Feb 2024 12:24:28 +0100 Subject: [PATCH 7/8] Use better value for alignment --- osu.Game/Overlays/Comments/CommentAuthorLine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Comments/CommentAuthorLine.cs b/osu.Game/Overlays/Comments/CommentAuthorLine.cs index c269ab4c01..1f6fef4df3 100644 --- a/osu.Game/Overlays/Comments/CommentAuthorLine.cs +++ b/osu.Game/Overlays/Comments/CommentAuthorLine.cs @@ -57,7 +57,7 @@ namespace osu.Game.Overlays.Comments Add(new OwnerTitleBadge(ownerMeta.OwnerTitle ?? string.Empty) { // add top space to align with username - Margin = new MarginPadding { Top = 2f }, + Margin = new MarginPadding { Top = 1f }, }); } From 68247fa022c0ba3cbab5fe3c92457e11fb48c4a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 14 Feb 2024 13:21:37 +0100 Subject: [PATCH 8/8] Fix typo in json property name Would cause the mapper badge to never actually be shown in the real world. --- osu.Game/Online/API/Requests/Responses/Comment.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Online/API/Requests/Responses/Comment.cs b/osu.Game/Online/API/Requests/Responses/Comment.cs index 907632186c..e6a5559d1f 100644 --- a/osu.Game/Online/API/Requests/Responses/Comment.cs +++ b/osu.Game/Online/API/Requests/Responses/Comment.cs @@ -33,7 +33,7 @@ namespace osu.Game.Online.API.Requests.Responses [JsonProperty(@"votes_count")] public int VotesCount { get; set; } - [JsonProperty(@"commenatble_type")] + [JsonProperty(@"commentable_type")] public string CommentableType { get; set; } = null!; [JsonProperty(@"commentable_id")]