// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; using osu.Game.Beatmaps; using osu.Game.Online.API; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Multiplayer; using osu.Game.Scoring; using osu.Game.Screens.Multi.Match.Components; using osu.Game.Screens.Multi.Ranking; using osu.Game.Screens.Multi.Ranking.Pages; using osu.Game.Screens.Multi.Ranking.Types; using osu.Game.Screens.Ranking; using osu.Game.Users; namespace osu.Game.Tests.Visual { public class TestCaseMultiResults : OsuTestCase { public override IReadOnlyList RequiredTypes => new[] { typeof(MatchResults), typeof(RoomLeaderboardPageInfo), typeof(RoomRankingResultsPage) }; [Resolved] private BeatmapManager beatmaps { get; set; } [BackgroundDependencyLoader] private void load() { var beatmapInfo = beatmaps.QueryBeatmap(b => b.RulesetID == 0); if (beatmapInfo != null) Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmapInfo); Child = new TestMatchResults(new ScoreInfo { User = new User { Id = 10 }, }); } private class TestMatchResults : MatchResults { private readonly Room room; public TestMatchResults(ScoreInfo score) : this(score, new Room()) { } public TestMatchResults(ScoreInfo score, Room room) : base(score, room) { this.room = room; } protected override IEnumerable CreateResultPages() => new[] { new TestRoomLeaderboardPageInfo(Score, Beatmap, room) }; } private class TestRoomLeaderboardPageInfo : RoomLeaderboardPageInfo { private readonly ScoreInfo score; private readonly WorkingBeatmap beatmap; private readonly Room room; public TestRoomLeaderboardPageInfo(ScoreInfo score, WorkingBeatmap beatmap, Room room) : base(score, beatmap, room) { this.score = score; this.beatmap = beatmap; this.room = room; } public override ResultsPage CreatePage() => new TestRoomRankingResultsPage(score, beatmap, room); } private class TestRoomRankingResultsPage : RoomRankingResultsPage { public TestRoomRankingResultsPage(ScoreInfo score, WorkingBeatmap beatmap, Room room) : base(score, beatmap, room) { } protected override MatchLeaderboard CreateLeaderboard(Room room) => new TestMatchLeaderboard(room); } private class TestMatchLeaderboard : MatchLeaderboard { public TestMatchLeaderboard(Room room) : base(room) { } protected override APIRequest FetchScores(Action> scoresCallback) { var scores = Enumerable.Range(0, 50).Select(createRoomScore).ToArray(); scoresCallback?.Invoke(scores); ScoresLoaded?.Invoke(scores); return null; } private APIRoomScoreInfo createRoomScore(int id) => new APIRoomScoreInfo { User = new User { Id = id, Username = $"User {id}" }, Accuracy = 0.98, TotalScore = 987654, TotalAttempts = 13, CompletedBeatmaps = 5 }; } } }