mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 18:42:56 +08:00
Handle deleted comments
This commit is contained in:
parent
ad99a3236f
commit
b2bd78308d
@ -89,7 +89,7 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
|
|
||||||
public string GetMessage()
|
public string GetMessage()
|
||||||
{
|
{
|
||||||
return MessageHTML.Replace("<div class='osu-md-default'>", "").Replace("<p class=\"osu-md-default__paragraph\">", "").Replace("<br />", "").Replace("</p>", "").Replace("</div>", "").Replace(""", "\"");
|
return IsDeleted ? @"deleted" : MessageHTML.Replace("<div class='osu-md-default'>", "").Replace("<p class=\"osu-md-default__paragraph\">", "").Replace("<br />", "").Replace("</p>", "").Replace("</div>", "").Replace(""", "\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,11 @@ namespace osu.Game.Overlays.Comments
|
|||||||
{
|
{
|
||||||
public class CommentsContainer : CompositeDrawable
|
public class CommentsContainer : CompositeDrawable
|
||||||
{
|
{
|
||||||
private const float separator_height = 1.5f;
|
|
||||||
|
|
||||||
private readonly CommentableType type;
|
private readonly CommentableType type;
|
||||||
private readonly long id;
|
private readonly long id;
|
||||||
|
|
||||||
public readonly Bindable<SortCommentsBy> Sort = new Bindable<SortCommentsBy>();
|
public readonly Bindable<SortCommentsBy> Sort = new Bindable<SortCommentsBy>();
|
||||||
|
public readonly BindableBool ShowDeleted = new BindableBool();
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IAPIProvider api { get; set; }
|
private IAPIProvider api { get; set; }
|
||||||
@ -55,7 +54,8 @@ namespace osu.Game.Overlays.Comments
|
|||||||
{
|
{
|
||||||
new CommentsHeader
|
new CommentsHeader
|
||||||
{
|
{
|
||||||
Sort = { BindTarget = Sort }
|
Sort = { BindTarget = Sort },
|
||||||
|
ShowDeleted = { BindTarget = ShowDeleted }
|
||||||
},
|
},
|
||||||
content = new FillFlowContainer
|
content = new FillFlowContainer
|
||||||
{
|
{
|
||||||
@ -89,21 +89,9 @@ namespace osu.Game.Overlays.Comments
|
|||||||
{
|
{
|
||||||
foreach (var c in response.Comments)
|
foreach (var c in response.Comments)
|
||||||
{
|
{
|
||||||
if (!c.IsDeleted && c.IsTopLevel)
|
if (c.IsTopLevel)
|
||||||
content.AddRange(new Drawable[]
|
content.Add(new DrawableComment(c)
|
||||||
{
|
{ ShowDeleted = { BindTarget = ShowDeleted } });
|
||||||
new DrawableComment(c),
|
|
||||||
new Container
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
Height = separator_height,
|
|
||||||
Child = new Box
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Colour = colours.Gray1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,19 +26,29 @@ namespace osu.Game.Overlays.Comments
|
|||||||
private const int chevron_margin = 30;
|
private const int chevron_margin = 30;
|
||||||
private const int message_padding = 40;
|
private const int message_padding = 40;
|
||||||
private const int duration = 200;
|
private const int duration = 200;
|
||||||
|
private const float separator_height = 1.5f;
|
||||||
|
|
||||||
|
public readonly BindableBool ShowDeleted = new BindableBool();
|
||||||
|
|
||||||
private readonly BindableBool childExpanded = new BindableBool(true);
|
private readonly BindableBool childExpanded = new BindableBool(true);
|
||||||
|
|
||||||
private readonly Container childCommentsVisibilityContainer;
|
private readonly Container childCommentsVisibilityContainer;
|
||||||
|
private readonly Comment comment;
|
||||||
|
|
||||||
public DrawableComment(Comment comment)
|
public DrawableComment(Comment comment)
|
||||||
{
|
{
|
||||||
LinkFlowContainer username;
|
LinkFlowContainer username;
|
||||||
FillFlowContainer childCommentsContainer;
|
FillFlowContainer childCommentsContainer;
|
||||||
FillFlowContainer info;
|
FillFlowContainer info;
|
||||||
|
TextFlowContainer message;
|
||||||
|
GridContainer content;
|
||||||
|
VotePill votePill;
|
||||||
|
|
||||||
|
this.comment = comment;
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
AutoSizeAxes = Axes.Y;
|
AutoSizeAxes = Axes.Y;
|
||||||
|
Masking = true;
|
||||||
InternalChild = new FillFlowContainer
|
InternalChild = new FillFlowContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
@ -46,7 +56,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
Direction = FillDirection.Vertical,
|
Direction = FillDirection.Vertical,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new GridContainer
|
content = new GridContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
@ -58,7 +68,6 @@ namespace osu.Game.Overlays.Comments
|
|||||||
},
|
},
|
||||||
RowDimensions = new[]
|
RowDimensions = new[]
|
||||||
{
|
{
|
||||||
new Dimension(GridSizeMode.AutoSize),
|
|
||||||
new Dimension(GridSizeMode.AutoSize)
|
new Dimension(GridSizeMode.AutoSize)
|
||||||
},
|
},
|
||||||
Content = new[]
|
Content = new[]
|
||||||
@ -73,10 +82,11 @@ namespace osu.Game.Overlays.Comments
|
|||||||
Spacing = new Vector2(5, 0),
|
Spacing = new Vector2(5, 0),
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new VotePill(comment.VotesCount)
|
votePill = new VotePill(comment.VotesCount)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
|
AlwaysPresent = true,
|
||||||
},
|
},
|
||||||
new UpdateableAvatar(comment.User)
|
new UpdateableAvatar(comment.User)
|
||||||
{
|
{
|
||||||
@ -92,71 +102,53 @@ namespace osu.Game.Overlays.Comments
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
Margin = new MarginPadding { Top = margin / 2 },
|
Spacing = new Vector2(0, 3),
|
||||||
Spacing = new Vector2(0, 2),
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new Container
|
new FillFlowContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
AutoSizeAxes = Axes.Both,
|
||||||
AutoSizeAxes = Axes.Y,
|
Direction = FillDirection.Horizontal,
|
||||||
|
Spacing = new Vector2(7, 0),
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new FillFlowContainer
|
username = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true))
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.Both,
|
||||||
Direction = FillDirection.Horizontal,
|
|
||||||
Spacing = new Vector2(7, 0),
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
username = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true))
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
},
|
|
||||||
new ParentUsername(comment)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
new ChevronButton(comment)
|
new ParentUsername(comment),
|
||||||
|
new SpriteText
|
||||||
{
|
{
|
||||||
Anchor = Anchor.TopRight,
|
Alpha = comment.IsDeleted? 1 : 0,
|
||||||
Origin = Anchor.TopRight,
|
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true),
|
||||||
Margin = new MarginPadding { Right = chevron_margin },
|
Text = @"deleted",
|
||||||
Expanded = { BindTarget = childExpanded }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new TextFlowContainer(s => s.Font = OsuFont.GetFont(size: 14))
|
message = new TextFlowContainer(s => s.Font = OsuFont.GetFont(size: 14))
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
Text = comment.GetMessage(),
|
|
||||||
Padding = new MarginPadding { Right = message_padding }
|
Padding = new MarginPadding { Right = message_padding }
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new Drawable[]
|
|
||||||
{
|
|
||||||
new Container
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
},
|
|
||||||
info = new FillFlowContainer
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
Direction = FillDirection.Horizontal,
|
|
||||||
Spacing = new Vector2(10, 0),
|
|
||||||
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)
|
info = new FillFlowContainer
|
||||||
{ Expanded = { BindTarget = childExpanded } },
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Direction = FillDirection.Horizontal,
|
||||||
|
Spacing = new Vector2(10, 0),
|
||||||
|
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)
|
||||||
|
{ Expanded = { BindTarget = childExpanded } },
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,13 +173,9 @@ namespace osu.Game.Overlays.Comments
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (comment.UserId == null)
|
if (comment.UserId == null)
|
||||||
{
|
|
||||||
username.AddText(comment.LegacyName);
|
username.AddText(comment.LegacyName);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
username.AddUserLink(comment.User);
|
username.AddUserLink(comment.User);
|
||||||
}
|
|
||||||
|
|
||||||
if (comment.EditedAt.HasValue)
|
if (comment.EditedAt.HasValue)
|
||||||
{
|
{
|
||||||
@ -200,15 +188,45 @@ namespace osu.Game.Overlays.Comments
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
comment.ChildComments.ForEach(c =>
|
if (!comment.IsDeleted)
|
||||||
|
message.Text = comment.GetMessage();
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (!c.IsDeleted)
|
content.FadeColour(OsuColour.Gray(0.5f));
|
||||||
childCommentsContainer.Add(new DrawableComment(c));
|
votePill.Hide();
|
||||||
});
|
}
|
||||||
|
|
||||||
|
if (comment.IsTopLevel)
|
||||||
|
{
|
||||||
|
AddInternal(new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
Height = separator_height,
|
||||||
|
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,
|
||||||
|
Margin = new MarginPadding { Right = chevron_margin, Top = margin },
|
||||||
|
Expanded = { BindTarget = childExpanded }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
comment.ChildComments.ForEach(c => childCommentsContainer.Add(new DrawableComment(c)));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
|
ShowDeleted.BindValueChanged(onShowDeletedChanged, true);
|
||||||
childExpanded.BindValueChanged(onChildExpandedChanged, true);
|
childExpanded.BindValueChanged(onChildExpandedChanged, true);
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
}
|
}
|
||||||
@ -226,6 +244,20 @@ namespace osu.Game.Overlays.Comments
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onShowDeletedChanged(ValueChangedEvent<bool> show)
|
||||||
|
{
|
||||||
|
if (comment.IsDeleted)
|
||||||
|
{
|
||||||
|
if (show.NewValue)
|
||||||
|
AutoSizeAxes = Axes.Y;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.None;
|
||||||
|
this.ResizeHeightTo(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class ChevronButton : ShowChildsButton
|
private class ChevronButton : ShowChildsButton
|
||||||
{
|
{
|
||||||
private readonly SpriteIcon icon;
|
private readonly SpriteIcon icon;
|
||||||
|
Loading…
Reference in New Issue
Block a user