Skip to content

Commit

Permalink
Merge branch 'master' into footer-v2-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Jul 10, 2024
2 parents ed1f3a1 + 4fe3f39 commit 9a88281
Show file tree
Hide file tree
Showing 18 changed files with 631 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Utils;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Rooms;
using osu.Game.Overlays;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens.OnlinePlay.DailyChallenge;
using osuTK;

namespace osu.Game.Tests.Visual.DailyChallenge
{
public partial class TestSceneDailyChallengeLeaderboard : OsuTestScene
{
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;

[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);

[Test]
public void TestBasicBehaviour()
{
DailyChallengeLeaderboard leaderboard = null!;

AddStep("set up response without user best", () =>
{
dummyAPI.HandleRequest = req =>
{
if (req is IndexPlaylistScoresRequest indexRequest)
{
indexRequest.TriggerSuccess(createResponse(50, false));
return true;
}
return false;
};
});
AddStep("create leaderboard", () => Child = leaderboard = new DailyChallengeLeaderboard(new Room { RoomID = { Value = 1 } }, new PlaylistItem(Beatmap.Value.BeatmapInfo))
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(0.8f),
});

AddStep("set up response with user best", () =>
{
dummyAPI.HandleRequest = req =>
{
if (req is IndexPlaylistScoresRequest indexRequest)
{
indexRequest.TriggerSuccess(createResponse(50, true));
return true;
}
return false;
};
});
AddStep("force refetch", () => leaderboard.RefetchScores());
}

[Test]
public void TestLoadingBehaviour()
{
IndexPlaylistScoresRequest pendingRequest = null!;
DailyChallengeLeaderboard leaderboard = null!;

AddStep("set up requests handler", () =>
{
dummyAPI.HandleRequest = req =>
{
if (req is IndexPlaylistScoresRequest indexRequest)
{
pendingRequest = indexRequest;
return true;
}
return false;
};
});
AddStep("create leaderboard", () => Child = leaderboard = new DailyChallengeLeaderboard(new Room { RoomID = { Value = 1 } }, new PlaylistItem(Beatmap.Value.BeatmapInfo))
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(0.8f),
});
AddStep("complete load", () => pendingRequest.TriggerSuccess(createResponse(3, true)));
AddStep("force refetch", () => leaderboard.RefetchScores());
AddStep("complete load", () => pendingRequest.TriggerSuccess(createResponse(4, true)));
}

private IndexedMultiplayerScores createResponse(int scoreCount, bool returnUserBest)
{
var result = new IndexedMultiplayerScores();

for (int i = 0; i < scoreCount; ++i)
{
result.Scores.Add(new MultiplayerScore
{
ID = i,
Accuracy = 1 - (float)i / (2 * scoreCount),
Position = i + 1,
EndedAt = DateTimeOffset.Now,
Passed = true,
Rank = (ScoreRank)RNG.Next((int)ScoreRank.D, (int)ScoreRank.XH),
MaxCombo = 1000 - i,
TotalScore = (long)(1_000_000 * (1 - (float)i / (2 * scoreCount))),
User = new APIUser { Username = $"user {i}" },
Statistics = new Dictionary<HitResult, int>()
});
}

if (returnUserBest)
{
result.UserScore = new MultiplayerScore
{
ID = 99999,
Accuracy = 0.91,
Position = 4,
EndedAt = DateTimeOffset.Now,
Passed = true,
Rank = ScoreRank.A,
MaxCombo = 100,
TotalScore = 800000,
User = dummyAPI.LocalUser.Value,
Statistics = new Dictionary<HitResult, int>()
};
}

return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ private void addCursor(MultiplayerScores scores)
};
}

private partial class TestResultsScreen : PlaylistsResultsScreen
private partial class TestResultsScreen : PlaylistItemUserResultsScreen
{
public new LoadingSpinner LeftSpinner => base.LeftSpinner;
public new LoadingSpinner CentreSpinner => base.CentreSpinner;
Expand Down
82 changes: 60 additions & 22 deletions osu.Game.Tests/Visual/SongSelect/TestSceneLeaderboardScoreV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,73 @@ private void load()
});
}

[SetUp]
public void Setup() => Schedule(() =>
[Test]
public void TestSheared()
{
Children = new Drawable[]
AddStep("create content", () =>
{
fillFlow = new FillFlowContainer
Children = new Drawable[]
{
Width = relativeWidth,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(0f, 2f),
Shear = new Vector2(OsuGame.SHEAR, 0)
},
drawWidthText = new OsuSpriteText(),
};
fillFlow = new FillFlowContainer
{
Width = relativeWidth,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(0f, 2f),
Shear = new Vector2(OsuGame.SHEAR, 0)
},
drawWidthText = new OsuSpriteText(),
};
foreach (var scoreInfo in getTestScores())
{
fillFlow.Add(new LeaderboardScoreV2(scoreInfo)
{
Rank = scoreInfo.Position,
IsPersonalBest = scoreInfo.User.Id == 2,
Shear = Vector2.Zero,
});
}
foreach (var score in fillFlow.Children)
score.Show();
});
}

foreach (var scoreInfo in getTestScores())
[Test]
public void TestNonSheared()
{
AddStep("create content", () =>
{
fillFlow.Add(new LeaderboardScoreV2(scoreInfo, scoreInfo.Position, scoreInfo.User.Id == 2)
Children = new Drawable[]
{
Shear = Vector2.Zero,
});
}
fillFlow = new FillFlowContainer
{
Width = relativeWidth,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(0f, 2f),
},
drawWidthText = new OsuSpriteText(),
};
foreach (var score in fillFlow.Children)
score.Show();
});
foreach (var scoreInfo in getTestScores())
{
fillFlow.Add(new LeaderboardScoreV2(scoreInfo)
{
Rank = scoreInfo.Position,
IsPersonalBest = scoreInfo.User.Id == 2,
});
}
foreach (var score in fillFlow.Children)
score.Show();
});
}

[SetUpSteps]
public void SetUpSteps()
Expand Down
23 changes: 23 additions & 0 deletions osu.Game/Online/Rooms/ShowPlaylistScoreRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Game.Online.API;

namespace osu.Game.Online.Rooms
{
public class ShowPlaylistScoreRequest : APIRequest<MultiplayerScore>
{
private readonly long roomId;
private readonly long playlistItemId;
private readonly long scoreId;

public ShowPlaylistScoreRequest(long roomId, long playlistItemId, long scoreId)
{
this.roomId = roomId;
this.playlistItemId = playlistItemId;
this.scoreId = scoreId;
}

protected override string Target => $@"rooms/{roomId}/playlist/{playlistItemId}/scores/{scoreId}";
}
}
14 changes: 12 additions & 2 deletions osu.Game/Overlays/Mods/ShearedOverlayContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public abstract partial class ShearedOverlayContainer : OsuFocusedOverlayContain
/// </summary>
protected ShearedOverlayHeader Header { get; private set; } = null!;

/// <summary>
/// The overlay's footer.
/// </summary>
protected Container Footer { get; private set; } = null!;

[Resolved]
private ScreenFooter? footer { get; set; }

Expand All @@ -43,6 +48,11 @@ public abstract partial class ShearedOverlayContainer : OsuFocusedOverlayContain
/// </summary>
protected Container MainAreaContent { get; private set; } = null!;

/// <summary>
/// A container for content that is to be displayed inside the footer.
/// </summary>
protected Container FooterContent { get; private set; } = null!;

protected override bool StartHidden => true;

protected override bool BlockNonPositionalInput => true;
Expand Down Expand Up @@ -125,7 +135,7 @@ protected override void PopIn()

if (footer != null)
{
footer.SetOverlayContent(this);
footer.SetActiveOverlayContainer(this);

if (footer.State.Value == Visibility.Hidden)
{
Expand All @@ -146,7 +156,7 @@ protected override void PopOut()

if (footer != null)
{
footer.ClearOverlayContent();
footer.ClearActiveOverlayContainer();

if (hideFooterOnPopOut)
{
Expand Down
6 changes: 3 additions & 3 deletions osu.Game/Screens/Footer/ScreenFooter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void SetButtons(IReadOnlyList<ScreenFooterButton> buttons)
temporarilyHiddenButtons.Clear();
overlays.Clear();

ClearOverlayContent();
ClearActiveOverlayContainer();

var oldButtons = buttonsFlow.ToArray();

Expand Down Expand Up @@ -189,7 +189,7 @@ public void SetButtons(IReadOnlyList<ScreenFooterButton> buttons)
private Container? contentContainer;
private readonly List<ScreenFooterButton> temporarilyHiddenButtons = new List<ScreenFooterButton>();

public void SetOverlayContent(ShearedOverlayContainer overlay)
public void SetActiveOverlayContainer(ShearedOverlayContainer overlay)
{
if (contentContainer != null)
{
Expand Down Expand Up @@ -234,7 +234,7 @@ public void SetOverlayContent(ShearedOverlayContainer overlay)
content.Show();
}

public void ClearOverlayContent()
public void ClearActiveOverlayContainer()
{
if (contentContainer == null)
return;
Expand Down
Loading

0 comments on commit 9a88281

Please sign in to comment.