From beb77176b6054840677769072c18bbcdf0c9da68 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 19 May 2025 16:58:01 +0900 Subject: [PATCH 1/2] Fix multiplayer position display looking wrong when player count is low Spotted when watching video in #33173's opening post. --- .../TestSceneMultiplayerPositionDisplay.cs | 34 +++++++++++++++++++ .../Multiplayer/MultiplayerPositionDisplay.cs | 6 ++-- 2 files changed, 38 insertions(+), 2 deletions(-) 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..8c9d0a9ef8 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) / (scores.Count - 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 From 962ec3dca0fd0163309762a0ebb81b4e371c859c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 19 May 2025 18:25:41 +0900 Subject: [PATCH 2/2] Fix case where there's only one player causing NaN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartłomiej Dach --- .../OnlinePlay/Multiplayer/MultiplayerPositionDisplay.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerPositionDisplay.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerPositionDisplay.cs index 8c9d0a9ef8..a2b9db5a06 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerPositionDisplay.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerPositionDisplay.cs @@ -158,7 +158,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer return; } - float relativePosition = Math.Clamp((float)(position.Value.Value - 1) / (scores.Count - 1), 0, 1); + 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);