diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerPositionDisplay.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerPositionDisplay.cs index 42f34539de..228ae4eb1a 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerPositionDisplay.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayerPositionDisplay.cs @@ -86,5 +86,39 @@ namespace osu.Game.Tests.Visual.Multiplayer AddStep("change local user", () => ((DummyAPIAccess)API).LocalUser.Value = new GuestUser()); AddUntilStep("display hidden", () => display.Alpha, () => Is.EqualTo(0)); } + + [Test] + public void TestTwoPlayers() + { + AddStep("create content", () => + { + Children = new Drawable[] + { + new DependencyProvidingContainer + { + RelativeSizeAxes = Axes.Both, + CachedDependencies = + [ + (typeof(IGameplayLeaderboardProvider), leaderboardProvider = new TestSceneGameplayLeaderboard.TestGameplayLeaderboardProvider()), + (typeof(GameplayState), gameplayState = TestGameplayState.Create(new OsuRuleset())) + ], + Child = display = new MultiplayerPositionDisplay + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + } + } + }; + + score = leaderboardProvider.CreateLeaderboardScore(new BindableLong(), API.LocalUser.Value, true); + score.Position.BindTo(position); + + var r = leaderboardProvider.CreateRandomScore(new APIUser()); + r.Position.Value = 1; + }); + + AddStep("first place", () => position.Value = 1); + AddStep("second place", () => position.Value = 2); + } } } diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerPositionDisplay.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerPositionDisplay.cs index 4be6e3b8c4..a2b9db5a06 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerPositionDisplay.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerPositionDisplay.cs @@ -158,13 +158,15 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer return; } - float relativePosition = (float)(position.Value.Value - 1) / scores.Count; + float relativePosition = Math.Clamp((float)(position.Value.Value - 1) / Math.Max(scores.Count - 1, 1), 0, 1); positionText.Current.Value = position.Value.Value; positionText.FadeTo(min_alpha + (max_alpha - min_alpha) * (1 - relativePosition), 1000, Easing.OutPow10); localPlayerMarker.FadeIn(); - localPlayerMarker.MoveToX(marker_size / 2 + Math.Min(relativePosition * (width - marker_size / 2), width - marker_size / 2), 1000, Easing.OutPow10); + float markerWidth = Math.Max(marker_size, width / scores.Count); + localPlayerMarker.ResizeWidthTo(markerWidth, 1000, Easing.OutPow10); + localPlayerMarker.MoveToX(markerWidth / 2 + (width - markerWidth) * relativePosition, 1000, Easing.OutPow10); } private partial class PositionCounter : RollingCounter