1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 15:33:05 +08:00

DeletedChildsPlaceholder refactor

This commit is contained in:
Andrei Zavatski 2019-10-13 12:38:50 +03:00
parent 795ce81468
commit 60954f969d
3 changed files with 55 additions and 13 deletions

View File

@ -33,6 +33,8 @@ namespace osu.Game.Overlays.Comments
private readonly Box background;
private readonly FillFlowContainer content;
private readonly FillFlowContainer footer;
private readonly DeletedChildsPlaceholder deletedChildsPlaceholder;
public CommentsContainer(CommentableType type, long id)
{
@ -64,6 +66,32 @@ namespace osu.Game.Overlays.Comments
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.2f)
},
footer = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
deletedChildsPlaceholder = new DeletedChildsPlaceholder
{
ShowDeleted = { BindTarget = ShowDeleted }
}
}
}
}
}
}
}
@ -121,10 +149,7 @@ namespace osu.Game.Overlays.Comments
deletedComments++;
});
content.Add(new DeletedChildsPlaceholder(deletedComments)
{
ShowDeleted = { BindTarget = ShowDeleted }
});
deletedChildsPlaceholder.DeletedCount.Value = deletedComments;
}, loadCancellation.Token);
}

View File

@ -17,18 +17,18 @@ namespace osu.Game.Overlays.Comments
private const int margin = 10;
public readonly BindableBool ShowDeleted = new BindableBool();
public readonly BindableInt DeletedCount = new BindableInt();
private readonly bool canBeVisible;
private bool canBeShown;
public DeletedChildsPlaceholder(int count)
private readonly SpriteText countText;
public DeletedChildsPlaceholder()
{
canBeVisible = count != 0;
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Horizontal;
Spacing = new Vector2(3, 0);
Margin = new MarginPadding { Vertical = margin, Left = deleted_placeholder_margin };
Alpha = 0;
Children = new Drawable[]
{
new SpriteIcon
@ -36,24 +36,38 @@ namespace osu.Game.Overlays.Comments
Icon = FontAwesome.Solid.Trash,
Size = new Vector2(14),
},
new SpriteText
countText = new SpriteText
{
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true),
Text = $@"{count} deleted comment{(count.ToString().ToCharArray().Last() == '1' ? "" : "s")}"
}
};
}
protected override void LoadComplete()
{
DeletedCount.BindValueChanged(onCountChanged, true);
ShowDeleted.BindValueChanged(onShowDeletedChanged, true);
base.LoadComplete();
}
private void onShowDeletedChanged(ValueChangedEvent<bool> showDeleted)
{
if (canBeVisible)
if (canBeShown)
this.FadeTo(showDeleted.NewValue ? 0 : 1);
}
private void onCountChanged(ValueChangedEvent<int> count)
{
canBeShown = count.NewValue != 0;
if (!canBeShown)
{
Hide();
return;
}
countText.Text = $@"{count.NewValue} deleted comment{(count.NewValue.ToString().ToCharArray().Last() == '1' ? "" : "s")}";
Show();
}
}
}

View File

@ -32,6 +32,7 @@ namespace osu.Game.Overlays.Comments
private readonly FillFlowContainer childCommentsVisibilityContainer;
private readonly Comment comment;
private readonly DeletedChildsPlaceholder deletedChildsPlaceholder;
public DrawableComment(Comment comment)
{
@ -168,7 +169,7 @@ namespace osu.Game.Overlays.Comments
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical
},
new DeletedChildsPlaceholder(comment.GetDeletedChildsCount())
deletedChildsPlaceholder = new DeletedChildsPlaceholder
{
ShowDeleted = { BindTarget = ShowDeleted }
}
@ -177,6 +178,8 @@ namespace osu.Game.Overlays.Comments
}
};
deletedChildsPlaceholder.DeletedCount.Value = comment.GetDeletedChildsCount();
if (comment.UserId == null)
username.AddText(comment.LegacyName);
else