Skip to content

Add transition when vote-count changes in user tag control #32718

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

Merged
merged 2 commits into from
Apr 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 54 additions & 5 deletions osu.Game/Screens/Ranking/UserTagControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ private partial class DrawableUserTag : OsuAnimatedButton

protected OsuSpriteText TagCategoryText { get; private set; } = null!;
protected OsuSpriteText TagNameText { get; private set; } = null!;
protected OsuSpriteText VoteCountText { get; private set; } = null!;
protected VoteCountText VoteCountText { get; private set; } = null!;

private readonly bool showVoteCount;

Expand Down Expand Up @@ -382,7 +382,8 @@ private void load()
showVoteCount
? new Container
{
AutoSizeAxes = Axes.Both,
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Children = new Drawable[]
Expand All @@ -391,9 +392,9 @@ private void load()
{
RelativeSizeAxes = Axes.Both,
},
VoteCountText = new OsuSpriteText
VoteCountText = new VoteCountText(voteCount)
{
Margin = new MarginPadding { Horizontal = 6, Vertical = 3, },
Margin = new MarginPadding { Horizontal = 6 },
},
}
}
Expand All @@ -418,7 +419,6 @@ protected override void LoadComplete()
{
voteCount.BindValueChanged(_ =>
{
VoteCountText.Text = voteCount.Value.ToLocalisableString();
confirmed.Value = voteCount.Value >= 10;
}, true);
voted.BindValueChanged(v =>
Expand Down Expand Up @@ -731,5 +731,54 @@ protected override void LoadComplete()
}
}
}

private partial class VoteCountText : CompositeDrawable
{
private OsuSpriteText? text;

private readonly Bindable<int> voteCount;

public VoteCountText(Bindable<int> voteCount)
{
RelativeSizeAxes = Axes.Y;
AutoSizeAxes = Axes.X;

this.voteCount = voteCount.GetBoundCopy();
}

protected override void LoadComplete()
{
base.LoadComplete();

voteCount.BindValueChanged(count =>
{
OsuSpriteText? previousText = text;

AddInternal(text = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(weight: FontWeight.SemiBold),
Text = voteCount.Value.ToLocalisableString(),
});

if (previousText != null)
{
const double transition_duration = 500;

bool isIncrease = count.NewValue > count.OldValue;

text.MoveToY(isIncrease ? 20 : -20)
.MoveToY(0, transition_duration, Easing.OutExpo);

previousText.BypassAutoSizeAxes = Axes.Both;
previousText.MoveToY(isIncrease ? -20 : 20, transition_duration, Easing.OutExpo).Expire();

AutoSizeDuration = 300;
AutoSizeEasing = Easing.OutQuint;
}
}, true);
}
}
}
}