2019-10-08 19:51:12 +08:00
|
|
|
|
// 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.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.Game.Utils;
|
2019-10-09 00:09:02 +08:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2019-10-09 00:18:46 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-10-09 00:56:43 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-10-09 16:07:56 +08:00
|
|
|
|
using System.Linq;
|
2019-10-14 21:56:07 +08:00
|
|
|
|
using osu.Game.Online.Chat;
|
2019-10-08 19:51:12 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Comments
|
|
|
|
|
{
|
|
|
|
|
public class DrawableComment : CompositeDrawable
|
|
|
|
|
{
|
|
|
|
|
private const int avatar_size = 40;
|
|
|
|
|
private const int margin = 10;
|
2019-10-09 17:18:49 +08:00
|
|
|
|
|
|
|
|
|
public readonly BindableBool ShowDeleted = new BindableBool();
|
2019-10-08 21:00:34 +08:00
|
|
|
|
|
2019-10-09 00:18:46 +08:00
|
|
|
|
private readonly BindableBool childExpanded = new BindableBool(true);
|
2019-10-08 21:00:34 +08:00
|
|
|
|
|
2019-10-10 16:43:45 +08:00
|
|
|
|
private readonly FillFlowContainer childCommentsVisibilityContainer;
|
2019-10-13 17:38:50 +08:00
|
|
|
|
private readonly DeletedChildsPlaceholder deletedChildsPlaceholder;
|
2019-10-14 21:43:43 +08:00
|
|
|
|
private readonly Comment comment;
|
2019-10-08 19:51:12 +08:00
|
|
|
|
|
|
|
|
|
public DrawableComment(Comment comment)
|
|
|
|
|
{
|
|
|
|
|
LinkFlowContainer username;
|
2019-10-08 20:39:03 +08:00
|
|
|
|
FillFlowContainer childCommentsContainer;
|
2019-10-09 16:32:17 +08:00
|
|
|
|
FillFlowContainer info;
|
2019-10-14 21:56:07 +08:00
|
|
|
|
LinkFlowContainer message;
|
2019-10-09 17:18:49 +08:00
|
|
|
|
GridContainer content;
|
|
|
|
|
VotePill votePill;
|
|
|
|
|
|
|
|
|
|
this.comment = comment;
|
2019-10-08 19:51:12 +08:00
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2019-10-08 20:39:03 +08:00
|
|
|
|
InternalChild = new FillFlowContainer
|
2019-10-08 19:51:12 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2019-10-08 20:39:03 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
2019-10-08 19:51:12 +08:00
|
|
|
|
{
|
2019-10-09 17:18:49 +08:00
|
|
|
|
content = new GridContainer
|
2019-10-08 19:51:12 +08:00
|
|
|
|
{
|
2019-10-08 20:39:03 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Margin = new MarginPadding(margin),
|
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
|
new Dimension(),
|
|
|
|
|
},
|
|
|
|
|
RowDimensions = new[]
|
2019-10-08 19:51:12 +08:00
|
|
|
|
{
|
2019-10-08 20:39:03 +08:00
|
|
|
|
new Dimension(GridSizeMode.AutoSize)
|
2019-10-08 19:51:12 +08:00
|
|
|
|
},
|
2019-10-08 20:39:03 +08:00
|
|
|
|
Content = new[]
|
2019-10-08 19:51:12 +08:00
|
|
|
|
{
|
2019-10-08 20:39:03 +08:00
|
|
|
|
new Drawable[]
|
2019-10-08 19:51:12 +08:00
|
|
|
|
{
|
2019-10-09 00:56:43 +08:00
|
|
|
|
new FillFlowContainer
|
2019-10-08 19:51:12 +08:00
|
|
|
|
{
|
2019-10-09 00:56:43 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2019-10-08 20:39:03 +08:00
|
|
|
|
Margin = new MarginPadding { Horizontal = margin },
|
2019-10-09 00:56:43 +08:00
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(5, 0),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2019-10-09 17:18:49 +08:00
|
|
|
|
votePill = new VotePill(comment.VotesCount)
|
2019-10-09 00:56:43 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2019-10-09 17:18:49 +08:00
|
|
|
|
AlwaysPresent = true,
|
2019-10-09 00:56:43 +08:00
|
|
|
|
},
|
|
|
|
|
new UpdateableAvatar(comment.User)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(avatar_size),
|
|
|
|
|
Masking = true,
|
|
|
|
|
CornerRadius = avatar_size / 2,
|
|
|
|
|
},
|
|
|
|
|
}
|
2019-10-08 19:51:12 +08:00
|
|
|
|
},
|
2019-10-08 20:39:03 +08:00
|
|
|
|
new FillFlowContainer
|
2019-10-08 19:51:12 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2019-10-09 17:18:49 +08:00
|
|
|
|
Spacing = new Vector2(0, 3),
|
2019-10-08 20:39:03 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2019-10-09 17:18:49 +08:00
|
|
|
|
new FillFlowContainer
|
2019-10-08 20:39:03 +08:00
|
|
|
|
{
|
2019-10-09 17:18:49 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(7, 0),
|
2019-10-09 00:09:02 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2019-10-09 17:18:49 +08:00
|
|
|
|
username = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true))
|
2019-10-09 00:09:02 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
},
|
2019-10-09 17:18:49 +08:00
|
|
|
|
new ParentUsername(comment),
|
|
|
|
|
new SpriteText
|
2019-10-09 16:07:56 +08:00
|
|
|
|
{
|
2019-10-09 17:18:49 +08:00
|
|
|
|
Alpha = comment.IsDeleted? 1 : 0,
|
|
|
|
|
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true),
|
|
|
|
|
Text = @"deleted",
|
2019-10-09 16:07:56 +08:00
|
|
|
|
}
|
2019-10-09 00:09:02 +08:00
|
|
|
|
}
|
2019-10-08 20:39:03 +08:00
|
|
|
|
},
|
2019-10-14 21:56:07 +08:00
|
|
|
|
message = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 14))
|
2019-10-08 20:39:03 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2019-10-14 21:43:43 +08:00
|
|
|
|
Padding = new MarginPadding { Right = 40 }
|
2019-10-08 21:00:34 +08:00
|
|
|
|
},
|
2019-10-09 17:18:49 +08:00
|
|
|
|
info = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(10, 0),
|
2019-10-13 16:50:27 +08:00
|
|
|
|
Colour = OsuColour.Gray(0.7f),
|
2019-10-09 17:18:49 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Font = OsuFont.GetFont(size: 12),
|
|
|
|
|
Text = HumanizerUtils.Humanize(comment.CreatedAt)
|
|
|
|
|
},
|
|
|
|
|
new RepliesButton(comment.RepliesCount)
|
2019-10-10 16:43:45 +08:00
|
|
|
|
{
|
|
|
|
|
Expanded = { BindTarget = childExpanded }
|
|
|
|
|
},
|
2019-10-09 17:18:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-08 21:00:34 +08:00
|
|
|
|
}
|
2019-10-08 19:51:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2019-10-10 16:43:45 +08:00
|
|
|
|
childCommentsVisibilityContainer = new FillFlowContainer
|
2019-10-08 19:51:12 +08:00
|
|
|
|
{
|
2019-10-08 20:39:03 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2019-10-10 16:43:45 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
2019-10-08 21:00:34 +08:00
|
|
|
|
{
|
2019-10-10 16:43:45 +08:00
|
|
|
|
childCommentsContainer = new FillFlowContainer
|
2019-10-09 18:37:07 +08:00
|
|
|
|
{
|
2019-10-14 21:43:43 +08:00
|
|
|
|
Margin = new MarginPadding { Left = 20 },
|
2019-10-10 16:43:45 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical
|
|
|
|
|
},
|
2019-10-13 17:38:50 +08:00
|
|
|
|
deletedChildsPlaceholder = new DeletedChildsPlaceholder
|
2019-10-10 16:43:45 +08:00
|
|
|
|
{
|
|
|
|
|
ShowDeleted = { BindTarget = ShowDeleted }
|
2019-10-09 18:37:07 +08:00
|
|
|
|
}
|
2019-10-08 21:00:34 +08:00
|
|
|
|
}
|
2019-10-08 19:51:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-13 17:38:50 +08:00
|
|
|
|
deletedChildsPlaceholder.DeletedCount.Value = comment.GetDeletedChildsCount();
|
|
|
|
|
|
2019-10-14 21:43:43 +08:00
|
|
|
|
if (comment.UserId.HasValue)
|
2019-10-09 03:46:42 +08:00
|
|
|
|
username.AddUserLink(comment.User);
|
2019-10-14 21:43:43 +08:00
|
|
|
|
else
|
|
|
|
|
username.AddText(comment.LegacyName);
|
2019-10-08 20:39:03 +08:00
|
|
|
|
|
2019-10-09 16:32:17 +08:00
|
|
|
|
if (comment.EditedAt.HasValue)
|
|
|
|
|
{
|
|
|
|
|
info.Add(new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Font = OsuFont.GetFont(size: 12),
|
|
|
|
|
Text = $@"edited {HumanizerUtils.Humanize(comment.EditedAt.Value)} by {comment.EditedUser.Username}"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 17:18:49 +08:00
|
|
|
|
if (!comment.IsDeleted)
|
2019-10-14 21:56:07 +08:00
|
|
|
|
{
|
|
|
|
|
var formattedSource = MessageFormatter.FormatText(comment.GetMessage());
|
|
|
|
|
message.AddLinks(formattedSource.Text, formattedSource.Links);
|
|
|
|
|
}
|
2019-10-09 17:18:49 +08:00
|
|
|
|
else
|
2019-10-08 20:39:03 +08:00
|
|
|
|
{
|
2019-10-09 17:18:49 +08:00
|
|
|
|
content.FadeColour(OsuColour.Gray(0.5f));
|
|
|
|
|
votePill.Hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (comment.IsTopLevel)
|
|
|
|
|
{
|
|
|
|
|
AddInternal(new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2019-10-14 21:43:43 +08:00
|
|
|
|
Height = 1.5f,
|
2019-10-09 19:10:05 +08:00
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
2019-10-09 17:18:49 +08:00
|
|
|
|
Child = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = OsuColour.Gray(0.1f)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (comment.ChildComments.Any())
|
|
|
|
|
{
|
|
|
|
|
AddInternal(new ChevronButton(comment)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
2019-10-14 21:43:43 +08:00
|
|
|
|
Margin = new MarginPadding { Right = 30, Top = margin },
|
2019-10-09 17:18:49 +08:00
|
|
|
|
Expanded = { BindTarget = childExpanded }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 18:37:07 +08:00
|
|
|
|
comment.ChildComments.ForEach(c => childCommentsContainer.Add(new DrawableComment(c)
|
2019-10-10 16:43:45 +08:00
|
|
|
|
{
|
|
|
|
|
ShowDeleted = { BindTarget = ShowDeleted }
|
|
|
|
|
}));
|
2019-10-09 00:18:46 +08:00
|
|
|
|
}
|
2019-10-08 21:00:34 +08:00
|
|
|
|
|
2019-10-09 00:18:46 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
2019-10-09 17:18:49 +08:00
|
|
|
|
ShowDeleted.BindValueChanged(onShowDeletedChanged, true);
|
2019-10-14 21:43:43 +08:00
|
|
|
|
childExpanded.BindValueChanged(expanded => childCommentsVisibilityContainer.FadeTo(expanded.NewValue ? 1 : 0), true);
|
2019-10-09 00:18:46 +08:00
|
|
|
|
base.LoadComplete();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 17:18:49 +08:00
|
|
|
|
private void onShowDeletedChanged(ValueChangedEvent<bool> show)
|
|
|
|
|
{
|
|
|
|
|
if (comment.IsDeleted)
|
2019-10-10 16:43:45 +08:00
|
|
|
|
this.FadeTo(show.NewValue ? 1 : 0);
|
2019-10-09 17:18:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 16:07:56 +08:00
|
|
|
|
private class ChevronButton : ShowChildsButton
|
|
|
|
|
{
|
|
|
|
|
private readonly SpriteIcon icon;
|
|
|
|
|
|
|
|
|
|
public ChevronButton(Comment comment)
|
|
|
|
|
{
|
|
|
|
|
Alpha = comment.IsTopLevel && comment.ChildComments.Any() ? 1 : 0;
|
|
|
|
|
Child = icon = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(12),
|
2019-10-13 16:50:27 +08:00
|
|
|
|
Colour = OsuColour.Gray(0.7f)
|
2019-10-09 16:07:56 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnExpandedChanged(ValueChangedEvent<bool> expanded)
|
|
|
|
|
{
|
|
|
|
|
icon.Icon = expanded.NewValue ? FontAwesome.Solid.ChevronUp : FontAwesome.Solid.ChevronDown;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class RepliesButton : ShowChildsButton
|
2019-10-08 21:00:34 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly SpriteText text;
|
|
|
|
|
private readonly int count;
|
|
|
|
|
|
|
|
|
|
public RepliesButton(int count)
|
|
|
|
|
{
|
|
|
|
|
this.count = count;
|
|
|
|
|
|
|
|
|
|
Alpha = count == 0 ? 0 : 1;
|
|
|
|
|
Child = text = new SpriteText
|
|
|
|
|
{
|
2019-10-09 01:44:01 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
|
2019-10-08 21:00:34 +08:00
|
|
|
|
};
|
2019-10-09 00:18:46 +08:00
|
|
|
|
}
|
2019-10-08 21:00:34 +08:00
|
|
|
|
|
2019-10-09 16:07:56 +08:00
|
|
|
|
protected override void OnExpandedChanged(ValueChangedEvent<bool> expanded)
|
2019-10-09 00:18:46 +08:00
|
|
|
|
{
|
|
|
|
|
text.Text = $@"{(expanded.NewValue ? "[+]" : "[-]")} replies ({count})";
|
2019-10-08 21:00:34 +08:00
|
|
|
|
}
|
2019-10-08 19:51:12 +08:00
|
|
|
|
}
|
2019-10-09 00:09:02 +08:00
|
|
|
|
|
|
|
|
|
private class ParentUsername : FillFlowContainer, IHasTooltip
|
|
|
|
|
{
|
|
|
|
|
private const int spacing = 3;
|
|
|
|
|
|
|
|
|
|
public string TooltipText => comment.ParentComment?.GetMessage() ?? "";
|
|
|
|
|
|
|
|
|
|
private readonly Comment comment;
|
|
|
|
|
|
|
|
|
|
public ParentUsername(Comment comment)
|
|
|
|
|
{
|
|
|
|
|
this.comment = comment;
|
|
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
Direction = FillDirection.Horizontal;
|
|
|
|
|
Spacing = new Vector2(spacing, 0);
|
|
|
|
|
Alpha = comment.ParentId == null ? 0 : 1;
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.Solid.Reply,
|
|
|
|
|
Size = new Vector2(14),
|
|
|
|
|
},
|
|
|
|
|
new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true),
|
2019-10-09 16:18:26 +08:00
|
|
|
|
Text = comment.ParentComment?.User?.Username ?? comment.ParentComment?.LegacyName
|
2019-10-09 00:09:02 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-09 00:56:43 +08:00
|
|
|
|
|
|
|
|
|
private class VotePill : CircularContainer
|
|
|
|
|
{
|
|
|
|
|
private const int height = 20;
|
|
|
|
|
private const int margin = 10;
|
|
|
|
|
|
|
|
|
|
public VotePill(int count)
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
|
Height = height;
|
|
|
|
|
Masking = true;
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-10-13 16:50:27 +08:00
|
|
|
|
Colour = OsuColour.Gray(0.05f)
|
2019-10-09 00:56:43 +08:00
|
|
|
|
},
|
|
|
|
|
new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Margin = new MarginPadding { Horizontal = margin },
|
|
|
|
|
Font = OsuFont.GetFont(size: 14),
|
|
|
|
|
Text = $"+{count}"
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-08 19:51:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|