mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:57:39 +08:00
Provide scores directly to Player
instance rather than relying on DI
This commit is contained in:
parent
0227eddda1
commit
4c4fdfd153
@ -10,7 +10,6 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Leaderboards;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Scoring;
|
||||
@ -18,7 +17,7 @@ using osu.Game.Screens.Play.HUD;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
public class TestSceneSoloGameplayLeaderboard : OsuTestScene, ILeaderboardScoreSource
|
||||
public class TestSceneSoloGameplayLeaderboard : OsuTestScene
|
||||
{
|
||||
[Cached]
|
||||
private readonly ScoreProcessor scoreProcessor = new ScoreProcessor(new OsuRuleset());
|
||||
@ -40,6 +39,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
Child = new SoloGameplayLeaderboard(trackingUser)
|
||||
{
|
||||
Scores = { BindTarget = scores },
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Expanded = { Value = true },
|
||||
@ -57,8 +57,6 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
AddSliderStep("combo", 0, 1000, 0, v => scoreProcessor.Combo.Value = v);
|
||||
}
|
||||
|
||||
IBindableList<ScoreInfo> ILeaderboardScoreSource.Scores => scores;
|
||||
|
||||
private static List<ScoreInfo> createSampleScores()
|
||||
{
|
||||
return new[]
|
||||
|
@ -1,15 +0,0 @@
|
||||
// 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.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Scoring;
|
||||
|
||||
namespace osu.Game.Online.Leaderboards
|
||||
{
|
||||
[Cached]
|
||||
public interface ILeaderboardScoreSource
|
||||
{
|
||||
IBindableList<ScoreInfo> Scores { get; }
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Online.Leaderboards;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Users;
|
||||
@ -16,7 +15,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
private readonly IUser trackingUser;
|
||||
|
||||
private readonly IBindableList<ScoreInfo> scores = new BindableList<ScoreInfo>();
|
||||
public readonly IBindableList<ScoreInfo> Scores = new BindableList<ScoreInfo>();
|
||||
|
||||
// hold references to ensure bindables are updated.
|
||||
private readonly List<Bindable<long>> scoreBindables = new List<Bindable<long>>();
|
||||
@ -32,13 +31,10 @@ namespace osu.Game.Screens.Play.HUD
|
||||
this.trackingUser = trackingUser;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(ILeaderboardScoreSource? scoreSource)
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
if (scoreSource != null)
|
||||
scores.BindTo(scoreSource.Scores);
|
||||
|
||||
scores.BindCollectionChanged((_, _) => Scheduler.AddOnce(showScores), true);
|
||||
base.LoadComplete();
|
||||
Scores.BindCollectionChanged((_, _) => Scheduler.AddOnce(showScores), true);
|
||||
}
|
||||
|
||||
private void showScores()
|
||||
@ -46,7 +42,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
Clear();
|
||||
scoreBindables.Clear();
|
||||
|
||||
if (!scores.Any())
|
||||
if (!Scores.Any())
|
||||
return;
|
||||
|
||||
ILeaderboardScore local = Add(trackingUser, true);
|
||||
@ -58,7 +54,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
// Local score should always show lower than any existing scores in cases of ties.
|
||||
local.DisplayOrder.Value = long.MaxValue;
|
||||
|
||||
foreach (var s in scores)
|
||||
foreach (var s in Scores)
|
||||
{
|
||||
var score = Add(s.User, false);
|
||||
|
||||
|
@ -843,7 +843,12 @@ namespace osu.Game.Screens.Play
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual GameplayLeaderboard CreateGameplayLeaderboard() => new SoloGameplayLeaderboard(Score.ScoreInfo.User);
|
||||
public readonly BindableList<ScoreInfo> LeaderboardScores = new BindableList<ScoreInfo>();
|
||||
|
||||
protected virtual GameplayLeaderboard CreateGameplayLeaderboard() => new SoloGameplayLeaderboard(Score.ScoreInfo.User)
|
||||
{
|
||||
Scores = { BindTarget = LeaderboardScores }
|
||||
};
|
||||
|
||||
protected virtual void AddLeaderboardToHUD(GameplayLeaderboard leaderboard) => HUDOverlay.LeaderboardFlow.Add(leaderboard);
|
||||
|
||||
|
@ -23,7 +23,7 @@ using Realms;
|
||||
|
||||
namespace osu.Game.Screens.Select.Leaderboards
|
||||
{
|
||||
public class BeatmapLeaderboard : Leaderboard<BeatmapLeaderboardScope, ScoreInfo>, ILeaderboardScoreSource
|
||||
public class BeatmapLeaderboard : Leaderboard<BeatmapLeaderboardScope, ScoreInfo>
|
||||
{
|
||||
public Action<ScoreInfo> ScoreSelected;
|
||||
|
||||
|
@ -9,7 +9,6 @@ using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Online.Leaderboards;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
@ -22,7 +21,7 @@ using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Screens.Select
|
||||
{
|
||||
public class PlaySongSelect : SongSelect, ILeaderboardScoreSource
|
||||
public class PlaySongSelect : SongSelect
|
||||
{
|
||||
private OsuScreen? playerLoader;
|
||||
|
||||
@ -111,14 +110,18 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
Player createPlayer()
|
||||
{
|
||||
Player player;
|
||||
|
||||
var replayGeneratingMod = Mods.Value.OfType<ICreateReplayData>().FirstOrDefault();
|
||||
|
||||
if (replayGeneratingMod != null)
|
||||
{
|
||||
return new ReplayPlayer((beatmap, mods) => replayGeneratingMod.CreateScoreFromReplayData(beatmap, mods));
|
||||
}
|
||||
player = new ReplayPlayer((beatmap, mods) => replayGeneratingMod.CreateScoreFromReplayData(beatmap, mods));
|
||||
else
|
||||
player = new SoloPlayer();
|
||||
|
||||
return new SoloPlayer();
|
||||
((IBindableList<ScoreInfo>)player.LeaderboardScores).BindTo(playBeatmapDetailArea.Leaderboard.Scores);
|
||||
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,7 +135,5 @@ namespace osu.Game.Screens.Select
|
||||
playerLoader = null;
|
||||
}
|
||||
}
|
||||
|
||||
IBindableList<ScoreInfo> ILeaderboardScoreSource.Scores => playBeatmapDetailArea.Leaderboard.Scores;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user