mirror of https://github.com/ppy/osu
Merge pull request #20518 from peppy/fix-leaderboard-wobble
Fix leaderboard wobble when in first place
This commit is contained in:
commit
715b1f64f3
|
@ -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]
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue