-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add badges to ProfileHeader #2407
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6ca714d
add badges to ProfileHeader
jorolf af755b4
Merge branch 'master' into profile-badges
jorolf af0c49c
badge_size is the actual badge size now
jorolf 2a18b4c
add a DRAWABLE_BADGE_SIZE const and center badges
jorolf 046412f
make hover lost transition instant (similar to hover transition)
jorolf de9f15f
add new test case and fix rotation not working
jorolf ddd5938
Merge branch 'profile-badges' of github.com:Jorolf/osu into profile-b…
jorolf a827fb5
Simplify child definition
peppy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. | ||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE | ||
|
||
using System; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Cursor; | ||
using osu.Framework.Graphics.Shapes; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Framework.Graphics.Textures; | ||
using osu.Framework.Input; | ||
using osu.Game.Graphics; | ||
using osu.Game.Graphics.Sprites; | ||
using osu.Game.Users; | ||
using OpenTK; | ||
|
||
namespace osu.Game.Overlays.Profile.Header | ||
{ | ||
public class BadgeContainer : Container | ||
{ | ||
private const float outer_container_width = 98; | ||
private const float outer_container_padding = 3; | ||
private static readonly Vector2 badge_size = new Vector2(outer_container_width - outer_container_padding * 2, 46); | ||
This comment was marked as off-topic.
Sorry, something went wrong. |
||
|
||
private OsuSpriteText badgeCountText; | ||
private FillFlowContainer badgeFlowContainer; | ||
private FillFlowContainer outerBadgeContainer; | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(OsuColour colours) | ||
{ | ||
Child = new Container | ||
{ | ||
Anchor = Anchor.BottomLeft, | ||
Origin = Anchor.BottomLeft, | ||
Masking = true, | ||
CornerRadius = 4, | ||
AutoSizeAxes = Axes.Both, | ||
Children = new Drawable[] | ||
{ | ||
new Box | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Colour = colours.Gray3 | ||
}, | ||
outerBadgeContainer = new OuterBadgeContainer(onOuterHover, onOuterHoverLost) | ||
{ | ||
Anchor = Anchor.BottomLeft, | ||
Origin = Anchor.BottomLeft, | ||
Direction = FillDirection.Vertical, | ||
Padding = new MarginPadding(outer_container_padding), | ||
Width = outer_container_width, | ||
AutoSizeAxes = Axes.Y, | ||
Children = new Drawable[] | ||
{ | ||
badgeCountText = new OsuSpriteText | ||
{ | ||
Alpha = 0, | ||
TextSize = 12, | ||
Anchor = Anchor.BottomCentre, | ||
Origin = Anchor.BottomCentre, | ||
Font = "Exo2.0-Regular" | ||
}, | ||
new Container | ||
{ | ||
Anchor = Anchor.BottomLeft, | ||
Origin = Anchor.BottomLeft, | ||
AutoSizeAxes = Axes.Both, | ||
Child = badgeFlowContainer = new FillFlowContainer | ||
{ | ||
Direction = FillDirection.Horizontal, | ||
AutoSizeAxes = Axes.Both, | ||
} | ||
} | ||
} | ||
}, | ||
} | ||
}; | ||
|
||
Scheduler.AddDelayed(rotateBadges, 3000, true); | ||
} | ||
|
||
private void rotateBadges() | ||
{ | ||
if (outerBadgeContainer.IsHovered) return; | ||
|
||
visibleBadge = (visibleBadge + 1) % badgeCount; | ||
|
||
badgeFlowContainer.MoveToX(-badge_size.X * visibleBadge, 500, Easing.InOutQuad); | ||
} | ||
|
||
private int visibleBadge; | ||
private int badgeCount; | ||
|
||
public void ShowBadges(Badge[] badges) | ||
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
Sorry, something went wrong. |
||
{ | ||
switch (badges.Length) | ||
{ | ||
case 0: | ||
Hide(); | ||
return; | ||
case 1: | ||
badgeCountText.Hide(); | ||
break; | ||
default: | ||
badgeCountText.Show(); | ||
badgeCountText.Text = $"{badges.Length} badges"; | ||
break; | ||
} | ||
|
||
Show(); | ||
badgeCount = badges.Length; | ||
visibleBadge = 0; | ||
|
||
foreach (var badge in badges) | ||
{ | ||
LoadComponentAsync(new DrawableBadge(badge) | ||
{ | ||
Size = badge_size, | ||
}, badgeFlowContainer.Add); | ||
} | ||
} | ||
|
||
private void onOuterHover() | ||
{ | ||
badgeFlowContainer.ClearTransforms(); | ||
badgeFlowContainer.X = 0; | ||
badgeFlowContainer.Direction = FillDirection.Full; | ||
outerBadgeContainer.AutoSizeAxes = Axes.Both; | ||
|
||
badgeFlowContainer.MaximumSize = new Vector2(ChildSize.X, float.MaxValue); | ||
} | ||
|
||
private void onOuterHoverLost() | ||
{ | ||
rotateBadges(); | ||
This comment was marked as off-topic.
Sorry, something went wrong. |
||
badgeFlowContainer.Direction = FillDirection.Horizontal; | ||
outerBadgeContainer.AutoSizeAxes = Axes.Y; | ||
outerBadgeContainer.Width = outer_container_width; | ||
} | ||
|
||
private class OuterBadgeContainer : FillFlowContainer | ||
{ | ||
private readonly Action hoverAction; | ||
private readonly Action hoverLostAction; | ||
|
||
public OuterBadgeContainer(Action hoverAction, Action hoverLostAction) | ||
{ | ||
this.hoverAction = hoverAction; | ||
this.hoverLostAction = hoverLostAction; | ||
} | ||
|
||
protected override bool OnHover(InputState state) | ||
{ | ||
hoverAction(); | ||
return true; | ||
} | ||
|
||
protected override void OnHoverLost(InputState state) => hoverLostAction(); | ||
} | ||
|
||
private class DrawableBadge : Container, IHasTooltip | ||
{ | ||
private readonly Badge badge; | ||
|
||
public DrawableBadge(Badge badge) | ||
{ | ||
this.badge = badge; | ||
Padding = new MarginPadding(3); | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(TextureStore textures) | ||
{ | ||
Child = new Sprite | ||
{ | ||
FillMode = FillMode.Fit, | ||
RelativeSizeAxes = Axes.Both, | ||
Texture = textures.Get(badge.ImageUrl), | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
OnLoadComplete = d => d.FadeInFromZero(200) | ||
This comment was marked as off-topic.
Sorry, something went wrong. |
||
}; | ||
} | ||
|
||
public string TooltipText => badge.Description; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
osu.Game/Overlays/Profile/SupporterIcon.cs → .../Overlays/Profile/Header/SupporterIcon.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as off-topic.
Sorry, something went wrong.