2020-03-28 15:22:01 +00:00
|
|
|
|
// 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.
|
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2021-12-17 10:09:35 +00:00
|
|
|
|
using System;
|
2020-03-28 15:22:01 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
2020-04-07 06:30:06 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2020-03-28 15:22:01 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
2021-12-13 10:01:20 +00:00
|
|
|
|
using osu.Game.Database;
|
2022-01-17 09:48:11 +00:00
|
|
|
|
using osu.Game.Models;
|
2020-03-28 15:22:01 +00:00
|
|
|
|
using osu.Game.Online.API;
|
2020-04-07 06:31:22 +00:00
|
|
|
|
using osu.Game.Online.Leaderboards;
|
2020-03-28 15:22:01 +00:00
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
using osu.Game.Scoring;
|
2022-01-19 04:20:52 +00:00
|
|
|
|
using osuTK;
|
2022-01-07 05:47:03 +00:00
|
|
|
|
using Realms;
|
2020-03-28 15:22:01 +00:00
|
|
|
|
|
2020-04-07 06:31:22 +00:00
|
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
2020-03-28 15:22:01 +00:00
|
|
|
|
{
|
2020-04-04 19:28:36 +00:00
|
|
|
|
public class TopLocalRank : UpdateableRank
|
2020-03-28 15:22:01 +00:00
|
|
|
|
{
|
2021-10-02 15:55:29 +00:00
|
|
|
|
private readonly BeatmapInfo beatmapInfo;
|
2020-03-28 15:22:01 +00:00
|
|
|
|
|
2020-04-07 05:49:24 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private IBindable<RulesetInfo> ruleset { get; set; }
|
|
|
|
|
|
2021-12-13 10:01:20 +00:00
|
|
|
|
[Resolved]
|
2022-01-24 10:59:58 +00:00
|
|
|
|
private RealmAccess realm { get; set; }
|
2021-12-13 10:01:20 +00:00
|
|
|
|
|
2020-04-07 05:49:24 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private IAPIProvider api { get; set; }
|
2020-03-28 15:22:01 +00:00
|
|
|
|
|
2022-01-17 09:48:11 +00:00
|
|
|
|
private IDisposable scoreSubscription;
|
|
|
|
|
|
2021-10-02 15:55:29 +00:00
|
|
|
|
public TopLocalRank(BeatmapInfo beatmapInfo)
|
2020-04-04 19:42:13 +00:00
|
|
|
|
: base(null)
|
2020-03-28 15:22:01 +00:00
|
|
|
|
{
|
2021-10-02 15:55:29 +00:00
|
|
|
|
this.beatmapInfo = beatmapInfo;
|
2022-01-19 04:20:52 +00:00
|
|
|
|
|
|
|
|
|
Size = new Vector2(40, 20);
|
2020-03-28 15:22:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-17 10:09:35 +00:00
|
|
|
|
protected override void LoadComplete()
|
2020-04-04 19:28:36 +00:00
|
|
|
|
{
|
2021-12-17 10:09:35 +00:00
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2022-01-17 09:48:11 +00:00
|
|
|
|
ruleset.BindValueChanged(_ =>
|
2020-04-07 06:30:06 +00:00
|
|
|
|
{
|
2022-01-17 09:48:11 +00:00
|
|
|
|
scoreSubscription?.Dispose();
|
2022-01-25 04:09:47 +00:00
|
|
|
|
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),
|
2022-01-23 10:50:29 +00:00
|
|
|
|
(items, changes, ___) =>
|
|
|
|
|
{
|
|
|
|
|
Rank = items.FirstOrDefault()?.Rank;
|
|
|
|
|
// Required since presence is changed via IsPresent override
|
|
|
|
|
Invalidate(Invalidation.Presence);
|
|
|
|
|
});
|
2022-01-17 09:48:11 +00:00
|
|
|
|
}, true);
|
2020-03-28 15:22:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-19 04:20:52 +00:00
|
|
|
|
public override bool IsPresent => base.IsPresent && Rank != null;
|
2021-11-05 09:05:31 +00:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
2021-12-17 10:09:35 +00:00
|
|
|
|
scoreSubscription?.Dispose();
|
2021-11-05 09:05:31 +00:00
|
|
|
|
}
|
2020-03-28 15:22:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|