add a DRAWABLE_BADGE_SIZE const and center badges

This commit is contained in:
jorolf 2018-04-16 18:51:35 +02:00
parent af0c49cca8
commit 2a18b4c3f8
2 changed files with 12 additions and 6 deletions

View File

@ -52,7 +52,7 @@ namespace osu.Game.Tests.Visual
{ {
AwardedAt = DateTimeOffset.Now, AwardedAt = DateTimeOffset.Now,
Description = i.ToString(), Description = i.ToString(),
ImageUrl = "Flags/__" ImageUrl = "https://assets.ppy.sh/profile-badges/contributor.jpg"
}).ToArray()), false)); }).ToArray()), false));
checkSupporterTag(false); checkSupporterTag(false);

View File

@ -49,7 +49,7 @@ namespace osu.Game.Overlays.Profile.Header
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
Padding = outer_padding, Padding = outer_padding,
Width = badge_size.X + outer_padding.TotalHorizontal * 2, Width = DrawableBadge.DRAWABLE_BADGE_SIZE.X + outer_padding.TotalHorizontal,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Children = new Drawable[] Children = new Drawable[]
{ {
@ -68,6 +68,8 @@ namespace osu.Game.Overlays.Profile.Header
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Child = badgeFlowContainer = new FillFlowContainer Child = badgeFlowContainer = new FillFlowContainer
{ {
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
} }
@ -86,7 +88,7 @@ namespace osu.Game.Overlays.Profile.Header
visibleBadge = (visibleBadge + 1) % badgeCount; visibleBadge = (visibleBadge + 1) % badgeCount;
badgeFlowContainer.MoveToX(-badge_size.X * visibleBadge, 500, Easing.InOutQuad); badgeFlowContainer.MoveToX(-DrawableBadge.DRAWABLE_BADGE_SIZE.X * visibleBadge, 500, Easing.InOutQuad);
} }
private int visibleBadge; private int visibleBadge;
@ -116,7 +118,8 @@ namespace osu.Game.Overlays.Profile.Header
{ {
LoadComponentAsync(new DrawableBadge(badge) LoadComponentAsync(new DrawableBadge(badge)
{ {
Size = badge_size + outer_padding.Total, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
}, badgeFlowContainer.Add); }, badgeFlowContainer.Add);
} }
} }
@ -136,7 +139,7 @@ namespace osu.Game.Overlays.Profile.Header
badgeFlowContainer.MoveToX(-badge_size.X * visibleBadge, 500, Easing.InOutQuad); badgeFlowContainer.MoveToX(-badge_size.X * visibleBadge, 500, Easing.InOutQuad);
badgeFlowContainer.Direction = FillDirection.Horizontal; badgeFlowContainer.Direction = FillDirection.Horizontal;
outerBadgeContainer.AutoSizeAxes = Axes.Y; outerBadgeContainer.AutoSizeAxes = Axes.Y;
outerBadgeContainer.Width = badge_size.X + outer_padding.TotalHorizontal * 2; outerBadgeContainer.Width = DrawableBadge.DRAWABLE_BADGE_SIZE.X + outer_padding.TotalHorizontal;
} }
private class OuterBadgeContainer : FillFlowContainer private class OuterBadgeContainer : FillFlowContainer
@ -161,12 +164,15 @@ namespace osu.Game.Overlays.Profile.Header
private class DrawableBadge : Container, IHasTooltip private class DrawableBadge : Container, IHasTooltip
{ {
public static readonly Vector2 DRAWABLE_BADGE_SIZE = badge_size + outer_padding.Total;
private readonly Badge badge; private readonly Badge badge;
public DrawableBadge(Badge badge) public DrawableBadge(Badge badge)
{ {
this.badge = badge; this.badge = badge;
Padding = new MarginPadding(3); Padding = outer_padding;
Size = DRAWABLE_BADGE_SIZE;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]