Implement DeletedChildsPlaceholder component

This commit is contained in:
Andrei Zavatski 2019-10-09 13:37:07 +03:00
parent b2bd78308d
commit 7e3c97f496
3 changed files with 86 additions and 4 deletions

View File

@ -40,6 +40,12 @@ public TestSceneCommentsContainer()
scrollFlow.Clear();
scrollFlow.Add(new CommentsContainer(CommentableType.Beatmapset, 41823));
});
AddStep("Airman comments", () =>
{
scrollFlow.Clear();
scrollFlow.Add(new CommentsContainer(CommentableType.Beatmapset, 24313));
});
}
}
}

View File

@ -5,6 +5,7 @@
using osu.Game.Users;
using System;
using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Online.API.Requests.Responses
{
@ -91,5 +92,22 @@ public string GetMessage()
{
return IsDeleted ? @"deleted" : MessageHTML.Replace("<div class='osu-md-default'>", "").Replace("<p class=\"osu-md-default__paragraph\">", "").Replace("<br />", "").Replace("</p>", "").Replace("</div>", "").Replace("&quot;", "\"");
}
public int GetDeletedChildsCount()
{
int count = 0;
if (ChildComments.Any())
ChildComments.ForEach(child =>
{
if (child.IsDeleted)
count++;
});
if (IsDeleted)
count++;
return count;
}
}
}

View File

@ -27,6 +27,7 @@ public class DrawableComment : CompositeDrawable
private const int message_padding = 40;
private const int duration = 200;
private const float separator_height = 1.5f;
private const int deleted_placeholder_margin = 80;
public readonly BindableBool ShowDeleted = new BindableBool();
@ -161,12 +162,26 @@ public DrawableComment(Comment comment)
AutoSizeDuration = duration,
AutoSizeEasing = Easing.OutQuint,
Masking = true,
Child = childCommentsContainer = new FillFlowContainer
Child = new FillFlowContainer
{
Margin = new MarginPadding { Left = child_margin },
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
childCommentsContainer = new FillFlowContainer
{
Margin = new MarginPadding { Left = child_margin },
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical
},
new DeletedChildsPlaceholder(comment.GetDeletedChildsCount())
{
Margin = new MarginPadding { Bottom = margin, Left = deleted_placeholder_margin },
ShowDeleted = { BindTarget = ShowDeleted }
}
}
}
}
}
@ -221,7 +236,8 @@ public DrawableComment(Comment comment)
}
}
comment.ChildComments.ForEach(c => childCommentsContainer.Add(new DrawableComment(c)));
comment.ChildComments.ForEach(c => childCommentsContainer.Add(new DrawableComment(c)
{ ShowDeleted = { BindTarget = ShowDeleted } }));
}
protected override void LoadComplete()
@ -258,6 +274,48 @@ private void onShowDeletedChanged(ValueChangedEvent<bool> show)
}
}
private class DeletedChildsPlaceholder : FillFlowContainer
{
public readonly BindableBool ShowDeleted = new BindableBool();
private readonly bool canBeVisible;
public DeletedChildsPlaceholder(int count)
{
canBeVisible = count != 0;
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Horizontal;
Spacing = new Vector2(3, 0);
Alpha = 0;
Children = new Drawable[]
{
new SpriteIcon
{
Icon = FontAwesome.Solid.Trash,
Size = new Vector2(14),
},
new SpriteText
{
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true),
Text = $@"{count} deleted comments"
}
};
}
protected override void LoadComplete()
{
ShowDeleted.BindValueChanged(onShowDeletedChanged, true);
base.LoadComplete();
}
private void onShowDeletedChanged(ValueChangedEvent<bool> showDeleted)
{
if (canBeVisible)
this.FadeTo(showDeleted.NewValue ? 0 : 1);
}
}
private class ChevronButton : ShowChildsButton
{
private readonly SpriteIcon icon;