Add room leaderboard to results

This commit is contained in:
smoogipoo 2018-12-21 18:22:13 +09:00
parent 8a2cc64bfa
commit 4149734f89
8 changed files with 226 additions and 8 deletions

View File

@ -0,0 +1,47 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Game.Beatmaps;
using osu.Game.Online.Multiplayer;
using osu.Game.Scoring;
using osu.Game.Screens.Multi.Ranking;
using osu.Game.Screens.Multi.Ranking.Pages;
using osu.Game.Screens.Multi.Ranking.Types;
using osu.Game.Users;
namespace osu.Game.Tests.Visual
{
public class TestCaseMultiResults : OsuTestCase
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(MultiResults),
typeof(RoomRankingResultType),
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);
MultiResults res;
Child = res = new MultiResults(new ScoreInfo
{
User = new User
{
Id = 9623649
},
}, new Room { RoomID = { Value = 46 } });
}
}
}

View File

@ -18,6 +18,8 @@ namespace osu.Game.Screens.Multi.Match.Components
{
public class MatchLeaderboard : Leaderboard<MatchLeaderboardScope, RoomScore>
{
public Action<IEnumerable<RoomScore>> ScoresLoaded;
private readonly Room room;
public MatchLeaderboard(Room room)
@ -42,7 +44,11 @@ namespace osu.Game.Screens.Multi.Match.Components
var req = new GetRoomScoresRequest(room.RoomID.Value ?? 0);
req.Success += r => scoresCallback?.Invoke(r);
req.Success += r =>
{
scoresCallback?.Invoke(r);
ScoresLoaded?.Invoke(r);
};
return req;
}

View File

@ -174,7 +174,7 @@ namespace osu.Game.Screens.Multi.Match
{
default:
case GameTypeTimeshift _:
var player = new TimeshiftPlayer(room.RoomID.Value ?? 0, room.Playlist.First().ID);
var player = new TimeshiftPlayer(room, room.Playlist.First().ID);
player.Exited += _ => leaderboard.RefreshScores();
pushGameplayScreen?.Invoke(new PlayerLoader(player));

View File

@ -9,22 +9,25 @@ using osu.Framework.Allocation;
using osu.Framework.IO.Network;
using osu.Framework.Logging;
using osu.Game.Online.API;
using osu.Game.Online.Multiplayer;
using osu.Game.Scoring;
using osu.Game.Screens.Multi.Ranking;
using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking;
namespace osu.Game.Screens.Multi.Play
{
public class TimeshiftPlayer : Player
{
private readonly int roomId;
private readonly Room room;
private readonly int playlistItemId;
[Resolved]
private APIAccess api { get; set; }
public TimeshiftPlayer(int roomId, int playlistItemId)
public TimeshiftPlayer(Room room, int playlistItemId)
{
this.roomId = roomId;
this.room = room;
this.playlistItemId = playlistItemId;
}
@ -37,7 +40,7 @@ namespace osu.Game.Screens.Multi.Play
bool failed = false;
var req = new CreateScoreRequest(roomId, playlistItemId);
var req = new CreateScoreRequest(room.RoomID.Value ?? 0, playlistItemId);
req.Success += r => token = r.ID;
req.Failure += e =>
{
@ -64,12 +67,14 @@ namespace osu.Game.Screens.Multi.Play
Debug.Assert(token != null);
var request = new SubmitScoreRequest(token.Value, roomId, playlistItemId, score);
var request = new SubmitScoreRequest(token.Value, room.RoomID.Value ?? 0, playlistItemId, score);
request.Failure += e => Logger.Error(e, "Failed to submit score");
api.Queue(request);
return score;
}
protected override Results CreateResults(ScoreInfo score) => new MultiResults(score, room);
}
public class SubmitScoreRequest : APIRequest

View File

@ -0,0 +1,30 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Game.Online.Multiplayer;
using osu.Game.Scoring;
using osu.Game.Screens.Multi.Ranking.Types;
using osu.Game.Screens.Ranking;
using osu.Game.Screens.Ranking.Types;
namespace osu.Game.Screens.Multi.Ranking
{
public class MultiResults : Results
{
private readonly Room room;
public MultiResults(ScoreInfo score, Room room)
: base(score)
{
this.room = room;
}
protected override IEnumerable<IResultType> CreateResultTypes() => new IResultType[]
{
new ScoreResultType(Score, Beatmap),
new RankingResultType(Score, Beatmap),
new RoomRankingResultType(Score, Beatmap, room),
};
}
}

View File

@ -0,0 +1,96 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Internal;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Lists;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Online.Leaderboards;
using osu.Game.Online.Multiplayer;
using osu.Game.Scoring;
using osu.Game.Screens.Multi.Match.Components;
using osu.Game.Screens.Ranking.Pages;
namespace osu.Game.Screens.Multi.Ranking.Pages
{
public class RoomRankingResultsPage : ResultsPage
{
private readonly Room room;
private OsuColour colours;
private TextFlowContainer rankText;
public RoomRankingResultsPage(ScoreInfo score, WorkingBeatmap beatmap, Room room)
: base(score, beatmap)
{
this.room = room;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
this.colours = colours;
Children = new Drawable[]
{
new Box
{
Colour = colours.GrayE,
RelativeSizeAxes = Axes.Both,
},
new BufferedContainer
{
RelativeSizeAxes = Axes.Both,
BackgroundColour = colours.GrayE,
Children = new Drawable[]
{
new MatchLeaderboard(room)
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Height = 0.8f,
Y = 95,
ScoresLoaded = scoresLoaded
}
}
},
rankText = new TextFlowContainer
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
Width = 0.5f,
AutoSizeAxes = Axes.Y,
Y = 75,
TextAnchor = Anchor.TopCentre
},
};
}
private void scoresLoaded(IEnumerable<RoomScore> scores)
{
Action<SpriteText> gray = s => s.Colour = colours.Gray8;
rankText.AddText("You are placed ", gray);
int index = scores.IndexOf(new RoomScore { User = Score.User }, new FuncEqualityComparer<RoomScore>((s1, s2) => s1.User.Id.Equals(s2.User.Id)));
rankText.AddText($"#{index + 1} ", s =>
{
s.Font = "Exo2.0-Bold";
s.Colour = colours.YellowDark;
});
rankText.AddText("in the room!", gray);
}
}
}

View File

@ -0,0 +1,31 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Online.Multiplayer;
using osu.Game.Scoring;
using osu.Game.Screens.Multi.Ranking.Pages;
using osu.Game.Screens.Ranking.Pages;
using osu.Game.Screens.Ranking.Types;
namespace osu.Game.Screens.Multi.Ranking.Types
{
public class RoomRankingResultType : IResultType
{
private readonly ScoreInfo score;
private readonly WorkingBeatmap beatmap;
private readonly Room room;
public RoomRankingResultType(ScoreInfo score, WorkingBeatmap beatmap, Room room)
{
this.score = score;
this.beatmap = beatmap;
this.room = room;
}
public FontAwesome Icon => FontAwesome.fa_list;
public ResultsPage CreatePage() => new RoomRankingResultsPage(score, beatmap, room);
}
}

View File

@ -28,6 +28,7 @@ using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking;
using osu.Game.Skinning;
using osu.Game.Storyboards.Drawables;
@ -287,7 +288,7 @@ namespace osu.Game.Screens.Play
if (RulesetContainer.Replay == null)
scoreManager.Import(score, true);
Push(new SoloResults(score));
Push(CreateResults(score));
onCompletionEvent = null;
});
@ -431,5 +432,7 @@ namespace osu.Game.Screens.Play
if (storyboardVisible && beatmap.Storyboard.ReplacesBackground)
Background?.FadeTo(0, BACKGROUND_FADE_DURATION, Easing.OutQuint);
}
protected virtual Results CreateResults(ScoreInfo score) => new SoloResults(score);
}
}