Skip to content

Commit ef63f62

Browse files
authored
Merge pull request #32718 from minetoblend/feature/tag-vote-count-transition
Add transition when vote-count changes in user tag control
2 parents 4bd405a + 0bb085b commit ef63f62

File tree

1 file changed

+54
-5
lines changed

1 file changed

+54
-5
lines changed

osu.Game/Screens/Ranking/UserTagControl.cs

+54-5
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ private partial class DrawableUserTag : OsuAnimatedButton
302302

303303
protected OsuSpriteText TagCategoryText { get; private set; } = null!;
304304
protected OsuSpriteText TagNameText { get; private set; } = null!;
305-
protected OsuSpriteText VoteCountText { get; private set; } = null!;
305+
protected VoteCountText VoteCountText { get; private set; } = null!;
306306

307307
private readonly bool showVoteCount;
308308

@@ -382,7 +382,8 @@ private void load()
382382
showVoteCount
383383
? new Container
384384
{
385-
AutoSizeAxes = Axes.Both,
385+
RelativeSizeAxes = Axes.Y,
386+
AutoSizeAxes = Axes.X,
386387
Anchor = Anchor.CentreLeft,
387388
Origin = Anchor.CentreLeft,
388389
Children = new Drawable[]
@@ -391,9 +392,9 @@ private void load()
391392
{
392393
RelativeSizeAxes = Axes.Both,
393394
},
394-
VoteCountText = new OsuSpriteText
395+
VoteCountText = new VoteCountText(voteCount)
395396
{
396-
Margin = new MarginPadding { Horizontal = 6, Vertical = 3, },
397+
Margin = new MarginPadding { Horizontal = 6 },
397398
},
398399
}
399400
}
@@ -418,7 +419,6 @@ protected override void LoadComplete()
418419
{
419420
voteCount.BindValueChanged(_ =>
420421
{
421-
VoteCountText.Text = voteCount.Value.ToLocalisableString();
422422
confirmed.Value = voteCount.Value >= 10;
423423
}, true);
424424
voted.BindValueChanged(v =>
@@ -731,5 +731,54 @@ protected override void LoadComplete()
731731
}
732732
}
733733
}
734+
735+
private partial class VoteCountText : CompositeDrawable
736+
{
737+
private OsuSpriteText? text;
738+
739+
private readonly Bindable<int> voteCount;
740+
741+
public VoteCountText(Bindable<int> voteCount)
742+
{
743+
RelativeSizeAxes = Axes.Y;
744+
AutoSizeAxes = Axes.X;
745+
746+
this.voteCount = voteCount.GetBoundCopy();
747+
}
748+
749+
protected override void LoadComplete()
750+
{
751+
base.LoadComplete();
752+
753+
voteCount.BindValueChanged(count =>
754+
{
755+
OsuSpriteText? previousText = text;
756+
757+
AddInternal(text = new OsuSpriteText
758+
{
759+
Anchor = Anchor.CentreLeft,
760+
Origin = Anchor.CentreLeft,
761+
Font = OsuFont.GetFont(weight: FontWeight.SemiBold),
762+
Text = voteCount.Value.ToLocalisableString(),
763+
});
764+
765+
if (previousText != null)
766+
{
767+
const double transition_duration = 500;
768+
769+
bool isIncrease = count.NewValue > count.OldValue;
770+
771+
text.MoveToY(isIncrease ? 20 : -20)
772+
.MoveToY(0, transition_duration, Easing.OutExpo);
773+
774+
previousText.BypassAutoSizeAxes = Axes.Both;
775+
previousText.MoveToY(isIncrease ? -20 : 20, transition_duration, Easing.OutExpo).Expire();
776+
777+
AutoSizeDuration = 300;
778+
AutoSizeEasing = Easing.OutQuint;
779+
}
780+
}, true);
781+
}
782+
}
734783
}
735784
}

0 commit comments

Comments
 (0)