mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 22:19:30 +08:00
Merge pull request #7639 from santerinogelainen/master
Add top rank to the beatmap carousel
This commit is contained in:
commit
4bfc738f5b
@ -7,23 +7,31 @@ using osu.Game.Scoring;
|
|||||||
|
|
||||||
namespace osu.Game.Online.Leaderboards
|
namespace osu.Game.Online.Leaderboards
|
||||||
{
|
{
|
||||||
public class UpdateableRank : ModelBackedDrawable<ScoreRank>
|
public class UpdateableRank : ModelBackedDrawable<ScoreRank?>
|
||||||
{
|
{
|
||||||
public ScoreRank Rank
|
public ScoreRank? Rank
|
||||||
{
|
{
|
||||||
get => Model;
|
get => Model;
|
||||||
set => Model = value;
|
set => Model = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UpdateableRank(ScoreRank rank)
|
public UpdateableRank(ScoreRank? rank)
|
||||||
{
|
{
|
||||||
Rank = rank;
|
Rank = rank;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Drawable CreateDrawable(ScoreRank rank) => new DrawableRank(rank)
|
protected override Drawable CreateDrawable(ScoreRank? rank)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
if (rank.HasValue)
|
||||||
Origin = Anchor.Centre,
|
{
|
||||||
};
|
return new DrawableRank(rank.Value)
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,10 +122,24 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
starCounter = new StarCounter
|
new FillFlowContainer
|
||||||
{
|
{
|
||||||
Current = (float)beatmap.StarDifficulty,
|
Direction = FillDirection.Horizontal,
|
||||||
Scale = new Vector2(0.8f),
|
Spacing = new Vector2(4, 0),
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new TopLocalRank(beatmap)
|
||||||
|
{
|
||||||
|
Scale = new Vector2(0.8f),
|
||||||
|
Size = new Vector2(40, 20)
|
||||||
|
},
|
||||||
|
starCounter = new StarCounter
|
||||||
|
{
|
||||||
|
Current = (float)beatmap.StarDifficulty,
|
||||||
|
Scale = new Vector2(0.8f),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
90
osu.Game/Screens/Select/Carousel/TopLocalRank.cs
Normal file
90
osu.Game/Screens/Select/Carousel/TopLocalRank.cs
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
// 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.Linq;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Threading;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.Leaderboards;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Scoring;
|
||||||
|
|
||||||
|
namespace osu.Game.Screens.Select.Carousel
|
||||||
|
{
|
||||||
|
public class TopLocalRank : UpdateableRank
|
||||||
|
{
|
||||||
|
private readonly BeatmapInfo beatmap;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private ScoreManager scores { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private IBindable<RulesetInfo> ruleset { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private IAPIProvider api { get; set; }
|
||||||
|
|
||||||
|
public TopLocalRank(BeatmapInfo beatmap)
|
||||||
|
: base(null)
|
||||||
|
{
|
||||||
|
this.beatmap = beatmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
scores.ItemAdded += scoreChanged;
|
||||||
|
scores.ItemRemoved += scoreChanged;
|
||||||
|
ruleset.ValueChanged += _ => fetchAndLoadTopScore();
|
||||||
|
|
||||||
|
fetchAndLoadTopScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scoreChanged(ScoreInfo score)
|
||||||
|
{
|
||||||
|
if (score.BeatmapInfoID == beatmap.ID)
|
||||||
|
fetchAndLoadTopScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScheduledDelegate scheduledRankUpdate;
|
||||||
|
|
||||||
|
private void fetchAndLoadTopScore()
|
||||||
|
{
|
||||||
|
var rank = fetchTopScore()?.Rank;
|
||||||
|
scheduledRankUpdate = Schedule(() =>
|
||||||
|
{
|
||||||
|
Rank = rank;
|
||||||
|
|
||||||
|
// Required since presence is changed via IsPresent override
|
||||||
|
Invalidate(Invalidation.Presence);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// We're present if a rank is set, or if there is a pending rank update (IsPresent = true is required for the scheduler to run).
|
||||||
|
public override bool IsPresent => base.IsPresent && (Rank != null || scheduledRankUpdate?.Completed == false);
|
||||||
|
|
||||||
|
private ScoreInfo fetchTopScore()
|
||||||
|
{
|
||||||
|
if (scores == null || beatmap == null || ruleset?.Value == null || api?.LocalUser.Value == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return scores.QueryScores(s => s.UserID == api.LocalUser.Value.Id && s.BeatmapInfoID == beatmap.ID && s.RulesetID == ruleset.Value.ID && !s.DeletePending)
|
||||||
|
.OrderByDescending(s => s.TotalScore)
|
||||||
|
.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
|
if (scores != null)
|
||||||
|
{
|
||||||
|
scores.ItemAdded -= scoreChanged;
|
||||||
|
scores.ItemRemoved -= scoreChanged;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user