Merge pull request #20518 from peppy/fix-leaderboard-wobble

Fix leaderboard wobble when in first place
This commit is contained in:
Dan Balasescu 2022-09-28 17:03:31 +09:00 committed by GitHub
commit 715b1f64f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 14 deletions

View File

@ -58,6 +58,16 @@ public void TestLayoutWithManyScores()
AddUntilStep("wait for some scores not masked away",
() => leaderboard.ChildrenOfType<GameplayLeaderboardScore>().Any(s => leaderboard.ScreenSpaceDrawQuad.Contains(s.ScreenSpaceDrawQuad.Centre)));
AddUntilStep("wait for tracked score fully visible", () => leaderboard.ScreenSpaceDrawQuad.Intersects(leaderboard.TrackedScore!.ScreenSpaceDrawQuad));
AddStep("change score to middle", () => playerScore.Value = 1000000);
AddWaitStep("wait for movement", 5);
AddUntilStep("wait for tracked score fully visible", () => leaderboard.ScreenSpaceDrawQuad.Intersects(leaderboard.TrackedScore!.ScreenSpaceDrawQuad));
AddStep("change score to first", () => playerScore.Value = 5000000);
AddWaitStep("wait for movement", 5);
AddUntilStep("wait for tracked score fully visible", () => leaderboard.ScreenSpaceDrawQuad.Intersects(leaderboard.TrackedScore!.ScreenSpaceDrawQuad));
}
[Test]

View File

@ -27,7 +27,7 @@ public abstract class GameplayLeaderboard : CompositeDrawable
private bool requiresScroll;
private readonly OsuScrollContainer scroll;
private GameplayLeaderboardScore? trackedScore;
public GameplayLeaderboardScore? TrackedScore { get; private set; }
private const int max_panels = 8;
@ -42,6 +42,7 @@ protected GameplayLeaderboard()
{
scroll = new InputDisabledScrollContainer
{
ClampExtension = 0,
RelativeSizeAxes = Axes.Both,
Child = Flow = new FillFlowContainer<GameplayLeaderboardScore>
{
@ -78,10 +79,10 @@ public ILeaderboardScore Add(IUser? user, bool isTracked)
if (isTracked)
{
if (trackedScore != null)
if (TrackedScore != null)
throw new InvalidOperationException("Cannot track more than one score.");
trackedScore = drawable;
TrackedScore = drawable;
}
drawable.Expanded.BindTo(Expanded);
@ -92,14 +93,6 @@ public ILeaderboardScore Add(IUser? user, bool isTracked)
int displayCount = Math.Min(Flow.Count, max_panels);
Height = displayCount * (GameplayLeaderboardScore.PANEL_HEIGHT + Flow.Spacing.Y);
// Add extra margin space to flow equal to height of leaderboard.
// This ensures the content is always on screen, but also accounts for the fact that scroll operations
// without animation were actually forcing the local score to a location it can't usually reside at.
//
// Basically, the local score was in the scroll extension region (due to always trying to scroll the
// local player to the middle of the display, but there being no other content below the local player
// to scroll up by).
Flow.Margin = new MarginPadding { Bottom = Height };
requiresScroll = displayCount != Flow.Count;
return drawable;
@ -108,7 +101,7 @@ public ILeaderboardScore Add(IUser? user, bool isTracked)
public void Clear()
{
Flow.Clear();
trackedScore = null;
TrackedScore = null;
scroll.ScrollToStart(false);
}
@ -119,9 +112,10 @@ protected override void Update()
{
base.Update();
if (requiresScroll && trackedScore != null)
if (requiresScroll && TrackedScore != null)
{
float scrollTarget = scroll.GetChildPosInContent(trackedScore) + trackedScore.DrawHeight / 2 - scroll.DrawHeight / 2;
float scrollTarget = scroll.GetChildPosInContent(TrackedScore) + TrackedScore.DrawHeight / 2 - scroll.DrawHeight / 2;
scroll.ScrollTo(scrollTarget);
}