mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 21:02:55 +08:00
Move all logic to TopLocalRank and remove CarouselBeatmapRank
This commit is contained in:
parent
6bde102207
commit
1e8badb14a
@ -1,12 +1,9 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
@ -14,43 +11,44 @@ using osu.Game.Scoring;
|
|||||||
|
|
||||||
namespace osu.Game.Online.Leaderboards
|
namespace osu.Game.Online.Leaderboards
|
||||||
{
|
{
|
||||||
public class TopLocalRank : Container
|
public class TopLocalRank : UpdateableRank
|
||||||
{
|
{
|
||||||
private readonly BeatmapInfo beatmap;
|
private readonly BeatmapInfo beatmap;
|
||||||
private readonly UpdateableRank rank;
|
|
||||||
|
|
||||||
private ScoreManager scores;
|
private ScoreManager scores;
|
||||||
private IBindable<RulesetInfo> ruleset;
|
private IBindable<RulesetInfo> ruleset;
|
||||||
private IAPIProvider api;
|
private IAPIProvider api;
|
||||||
|
|
||||||
/// <summary>
|
protected override double LoadDelay => 250;
|
||||||
/// Raised when the top score is loaded
|
|
||||||
/// </summary>
|
|
||||||
public Action<ScoreInfo> ScoreLoaded;
|
|
||||||
|
|
||||||
public TopLocalRank(BeatmapInfo beatmap)
|
public TopLocalRank(BeatmapInfo beatmap) : base(null)
|
||||||
{
|
{
|
||||||
this.beatmap = beatmap;
|
this.beatmap = beatmap;
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.Both;
|
|
||||||
|
|
||||||
InternalChild = rank = new UpdateableRank(null)
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(ScoreManager scores, IBindable<RulesetInfo> ruleset, IAPIProvider api)
|
private void load(ScoreManager scores, IBindable<RulesetInfo> ruleset, IAPIProvider api)
|
||||||
{
|
{
|
||||||
|
scores.ItemAdded += scoreChanged;
|
||||||
|
scores.ItemRemoved += scoreChanged;
|
||||||
|
ruleset.ValueChanged += _ => fetchAndLoadTopScore();
|
||||||
|
|
||||||
|
this.ruleset = ruleset.GetBoundCopy();
|
||||||
this.scores = scores;
|
this.scores = scores;
|
||||||
this.ruleset = ruleset;
|
|
||||||
this.api = api;
|
this.api = api;
|
||||||
|
|
||||||
FetchAndLoadTopScore();
|
fetchAndLoadTopScore();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FetchAndLoadTopScore()
|
private void scoreChanged(ScoreInfo score)
|
||||||
|
{
|
||||||
|
if (score.BeatmapInfoID == beatmap.ID)
|
||||||
|
{
|
||||||
|
fetchAndLoadTopScore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fetchAndLoadTopScore()
|
||||||
{
|
{
|
||||||
var score = fetchTopScore();
|
var score = fetchTopScore();
|
||||||
|
|
||||||
@ -59,9 +57,16 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
|
|
||||||
private void loadTopScore(ScoreInfo score)
|
private void loadTopScore(ScoreInfo score)
|
||||||
{
|
{
|
||||||
Schedule(() => rank.Rank = score?.Rank);
|
var rank = score?.Rank;
|
||||||
|
|
||||||
ScoreLoaded?.Invoke(score);
|
// toggle the display of this drawable
|
||||||
|
// we do not want empty space if there is no rank to be displayed
|
||||||
|
if (rank.HasValue)
|
||||||
|
Show();
|
||||||
|
else
|
||||||
|
Hide();
|
||||||
|
|
||||||
|
Schedule(() => Rank = rank);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScoreInfo fetchTopScore()
|
private ScoreInfo fetchTopScore()
|
||||||
@ -69,8 +74,7 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
if (scores == null || beatmap == null || ruleset?.Value == null || api?.LocalUser.Value == null)
|
if (scores == null || beatmap == null || ruleset?.Value == null || api?.LocalUser.Value == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return scores.GetAllUsableScores()
|
return scores.QueryScores(s => s.UserID == api.LocalUser.Value.Id && s.BeatmapInfoID == beatmap.ID && s.RulesetID == ruleset.Value.ID && !s.DeletePending)
|
||||||
.Where(s => s.UserID == api.LocalUser.Value.Id && s.BeatmapInfoID == beatmap.ID && s.RulesetID == ruleset.Value.ID)
|
|
||||||
.OrderByDescending(s => s.TotalScore)
|
.OrderByDescending(s => s.TotalScore)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
@ -1,68 +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.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Online.Leaderboards;
|
|
||||||
using osu.Game.Rulesets;
|
|
||||||
using osu.Game.Scoring;
|
|
||||||
|
|
||||||
namespace osu.Game.Screens.Select.Carousel
|
|
||||||
{
|
|
||||||
public class CarouselBeatmapRank : Container
|
|
||||||
{
|
|
||||||
private const int rank_size = 20;
|
|
||||||
private readonly BeatmapInfo beatmap;
|
|
||||||
|
|
||||||
private TopLocalRank rank;
|
|
||||||
|
|
||||||
public CarouselBeatmapRank(BeatmapInfo beatmap)
|
|
||||||
{
|
|
||||||
this.beatmap = beatmap;
|
|
||||||
|
|
||||||
Height = rank_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(ScoreManager scores, IBindable<RulesetInfo> ruleset)
|
|
||||||
{
|
|
||||||
scores.ItemAdded += scoreChanged;
|
|
||||||
scores.ItemRemoved += scoreChanged;
|
|
||||||
ruleset.ValueChanged += _ => rulesetChanged();
|
|
||||||
|
|
||||||
rank = new TopLocalRank(beatmap)
|
|
||||||
{
|
|
||||||
ScoreLoaded = scaleDisplay
|
|
||||||
};
|
|
||||||
|
|
||||||
InternalChild = new DelayedLoadWrapper(rank)
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private void rulesetChanged()
|
|
||||||
{
|
|
||||||
rank.FetchAndLoadTopScore();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void scoreChanged(ScoreInfo score)
|
|
||||||
{
|
|
||||||
if (score.BeatmapInfoID == beatmap.ID)
|
|
||||||
{
|
|
||||||
rank.FetchAndLoadTopScore();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void scaleDisplay(ScoreInfo score)
|
|
||||||
{
|
|
||||||
if (score != null)
|
|
||||||
Width = rank_size * 2;
|
|
||||||
else
|
|
||||||
Width = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -19,6 +19,7 @@ using osu.Game.Graphics;
|
|||||||
using osu.Game.Graphics.Backgrounds;
|
using osu.Game.Graphics.Backgrounds;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Online.Leaderboards;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
@ -129,9 +130,10 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
AutoSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.Both,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new CarouselBeatmapRank(beatmap)
|
new TopLocalRank(beatmap)
|
||||||
{
|
{
|
||||||
Scale = new Vector2(0.8f)
|
Scale = new Vector2(0.8f),
|
||||||
|
Size = new Vector2(40, 20)
|
||||||
},
|
},
|
||||||
starCounter = new StarCounter
|
starCounter = new StarCounter
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user