mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 11:42:56 +08:00
Move comment author line to separate component
This commit is contained in:
parent
f7a223f328
commit
5267e0abf7
135
osu.Game/Overlays/Comments/CommentAuthorLine.cs
Normal file
135
osu.Game/Overlays/Comments/CommentAuthorLine.cs
Normal file
@ -0,0 +1,135 @@
|
||||
// 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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<CommentEditor> 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
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user