mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 21:47:25 +08:00
727fe76b60
Fixed this here because that blocks `Schedule` from running, and I don't want to add another override to the `IsPresent` flag.
92 lines
2.9 KiB
C#
92 lines
2.9 KiB
C#
// 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.
|
|
|
|
#nullable disable
|
|
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Bindables;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Game.Beatmaps;
|
|
using osu.Game.Database;
|
|
using osu.Game.Models;
|
|
using osu.Game.Online.API;
|
|
using osu.Game.Online.Leaderboards;
|
|
using osu.Game.Rulesets;
|
|
using osu.Game.Scoring;
|
|
using osuTK;
|
|
using Realms;
|
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
|
{
|
|
public class TopLocalRank : CompositeDrawable
|
|
{
|
|
private readonly BeatmapInfo beatmapInfo;
|
|
|
|
[Resolved]
|
|
private IBindable<RulesetInfo> ruleset { get; set; }
|
|
|
|
[Resolved]
|
|
private RealmAccess realm { get; set; }
|
|
|
|
[Resolved]
|
|
private IAPIProvider api { get; set; }
|
|
|
|
private IDisposable scoreSubscription;
|
|
private CancellationTokenSource scoreOrderCancellationSource;
|
|
|
|
private readonly UpdateableRank updateable;
|
|
|
|
public ScoreRank? DisplayedRank => updateable.Rank;
|
|
|
|
public TopLocalRank(BeatmapInfo beatmapInfo)
|
|
{
|
|
this.beatmapInfo = beatmapInfo;
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
InternalChild = updateable = new UpdateableRank
|
|
{
|
|
Anchor = Anchor.Centre,
|
|
Origin = Anchor.Centre,
|
|
Size = new Vector2(40, 20),
|
|
Alpha = 0,
|
|
};
|
|
}
|
|
|
|
protected override void LoadComplete()
|
|
{
|
|
base.LoadComplete();
|
|
|
|
ruleset.BindValueChanged(_ =>
|
|
{
|
|
scoreSubscription?.Dispose();
|
|
scoreSubscription = realm.RegisterForNotifications(r =>
|
|
r.All<ScoreInfo>()
|
|
.Filter($"{nameof(ScoreInfo.User)}.{nameof(RealmUser.OnlineID)} == $0"
|
|
+ $" && {nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.ID)} == $1"
|
|
+ $" && {nameof(ScoreInfo.Ruleset)}.{nameof(RulesetInfo.ShortName)} == $2"
|
|
+ $" && {nameof(ScoreInfo.DeletePending)} == false", api.LocalUser.Value.Id, beatmapInfo.ID, ruleset.Value.ShortName)
|
|
.OrderByDescending(s => s.TotalScore),
|
|
(items, _, _) =>
|
|
{
|
|
updateable.Rank = items.FirstOrDefault()?.Rank;
|
|
updateable.Alpha = updateable.Rank != null ? 1 : 0;
|
|
});
|
|
}, true);
|
|
}
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
{
|
|
base.Dispose(isDisposing);
|
|
|
|
scoreOrderCancellationSource?.Cancel();
|
|
scoreSubscription?.Dispose();
|
|
}
|
|
}
|
|
}
|