2020-03-28 17:22:01 +02: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.
|
|
|
|
|
|
2021-12-17 19:09:35 +09:00
|
|
|
|
using System;
|
2023-07-16 10:21:32 +08:00
|
|
|
|
using System.Linq;
|
2020-03-28 17:22:01 +02:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
2020-04-07 15:30:06 +09:00
|
|
|
|
using osu.Framework.Graphics;
|
2022-07-23 08:09:00 +03:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-03-28 17:22:01 +02:00
|
|
|
|
using osu.Game.Beatmaps;
|
2021-12-13 19:01:20 +09:00
|
|
|
|
using osu.Game.Database;
|
2022-01-17 18:48:11 +09:00
|
|
|
|
using osu.Game.Models;
|
2020-03-28 17:22:01 +02:00
|
|
|
|
using osu.Game.Online.API;
|
2020-04-07 15:31:22 +09:00
|
|
|
|
using osu.Game.Online.Leaderboards;
|
2020-03-28 17:22:01 +02:00
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
using osu.Game.Scoring;
|
2022-01-19 13:20:52 +09:00
|
|
|
|
using osuTK;
|
2022-01-07 14:47:03 +09:00
|
|
|
|
using Realms;
|
2020-03-28 17:22:01 +02:00
|
|
|
|
|
2020-04-07 15:31:22 +09:00
|
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
2020-03-28 17:22:01 +02:00
|
|
|
|
{
|
2022-11-24 14:32:20 +09:00
|
|
|
|
public partial class TopLocalRank : CompositeDrawable
|
2020-03-28 17:22:01 +02:00
|
|
|
|
{
|
2021-10-03 00:55:29 +09:00
|
|
|
|
private readonly BeatmapInfo beatmapInfo;
|
2020-03-28 17:22:01 +02:00
|
|
|
|
|
2020-04-07 14:49:24 +09:00
|
|
|
|
[Resolved]
|
2022-07-23 09:25:06 +03:00
|
|
|
|
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
|
2020-04-07 14:49:24 +09:00
|
|
|
|
|
2021-12-13 19:01:20 +09:00
|
|
|
|
[Resolved]
|
2022-07-23 09:25:06 +03:00
|
|
|
|
private RealmAccess realm { get; set; } = null!;
|
2021-12-13 19:01:20 +09:00
|
|
|
|
|
2020-04-07 14:49:24 +09:00
|
|
|
|
[Resolved]
|
2022-07-23 09:25:06 +03:00
|
|
|
|
private IAPIProvider api { get; set; } = null!;
|
2020-03-28 17:22:01 +02:00
|
|
|
|
|
2022-07-23 09:25:06 +03:00
|
|
|
|
private IDisposable? scoreSubscription;
|
2022-07-23 08:09:00 +03:00
|
|
|
|
|
|
|
|
|
private readonly UpdateableRank updateable;
|
|
|
|
|
|
|
|
|
|
public ScoreRank? DisplayedRank => updateable.Rank;
|
2022-01-17 18:48:11 +09:00
|
|
|
|
|
2021-10-03 00:55:29 +09:00
|
|
|
|
public TopLocalRank(BeatmapInfo beatmapInfo)
|
2020-03-28 17:22:01 +02:00
|
|
|
|
{
|
2021-10-03 00:55:29 +09:00
|
|
|
|
this.beatmapInfo = beatmapInfo;
|
2022-01-19 13:20:52 +09:00
|
|
|
|
|
2022-07-23 08:09:00 +03:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
InternalChild = updateable = new UpdateableRank
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(40, 20),
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
};
|
2020-03-28 17:22:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-17 19:09:35 +09:00
|
|
|
|
protected override void LoadComplete()
|
2020-04-04 22:28:36 +03:00
|
|
|
|
{
|
2021-12-17 19:09:35 +09:00
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2022-01-17 18:48:11 +09:00
|
|
|
|
ruleset.BindValueChanged(_ =>
|
2020-04-07 15:30:06 +09:00
|
|
|
|
{
|
2022-01-17 18:48:11 +09:00
|
|
|
|
scoreSubscription?.Dispose();
|
2022-01-25 13:09:47 +09:00
|
|
|
|
scoreSubscription = realm.RegisterForNotifications(r =>
|
|
|
|
|
r.All<ScoreInfo>()
|
|
|
|
|
.Filter($"{nameof(ScoreInfo.User)}.{nameof(RealmUser.OnlineID)} == $0"
|
|
|
|
|
+ $" && {nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.ID)} == $1"
|
2023-02-07 11:52:47 +03:00
|
|
|
|
+ $" && {nameof(ScoreInfo.BeatmapInfo)}.{nameof(BeatmapInfo.Hash)} == {nameof(ScoreInfo.BeatmapHash)}"
|
2022-01-25 13:09:47 +09:00
|
|
|
|
+ $" && {nameof(ScoreInfo.Ruleset)}.{nameof(RulesetInfo.ShortName)} == $2"
|
2022-07-23 08:13:05 +03:00
|
|
|
|
+ $" && {nameof(ScoreInfo.DeletePending)} == false", api.LocalUser.Value.Id, beatmapInfo.ID, ruleset.Value.ShortName),
|
|
|
|
|
localScoresChanged);
|
2022-01-17 18:48:11 +09:00
|
|
|
|
}, true);
|
2022-07-23 08:13:05 +03:00
|
|
|
|
|
2023-07-06 13:37:42 +09:00
|
|
|
|
void localScoresChanged(IRealmCollection<ScoreInfo> sender, ChangeSet? changes)
|
2022-07-23 08:13:05 +03:00
|
|
|
|
{
|
|
|
|
|
// This subscription may fire from changes to linked beatmaps, which we don't care about.
|
|
|
|
|
// It's currently not possible for a score to be modified after insertion, so we can safely ignore callbacks with only modifications.
|
|
|
|
|
if (changes?.HasCollectionChanges() == false)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-07-16 10:21:32 +08:00
|
|
|
|
ScoreInfo? topScore = sender.MaxBy(info => (info.TotalScore, -info.Date.UtcDateTime.Ticks));
|
2022-09-09 19:01:50 +03:00
|
|
|
|
updateable.Rank = topScore?.Rank;
|
|
|
|
|
updateable.Alpha = topScore != null ? 1 : 0;
|
2022-07-23 08:13:05 +03:00
|
|
|
|
}
|
2020-03-28 17:22:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-05 18:05:31 +09:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
2021-12-17 19:09:35 +09:00
|
|
|
|
scoreSubscription?.Dispose();
|
2021-11-05 18:05:31 +09:00
|
|
|
|
}
|
2020-03-28 17:22:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|