1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 20:13:22 +08:00

Fix TopLocalRank hacking around presence to hide on null rank

Fixed this here because that blocks `Schedule` from running, and I don't
want to add another override to the `IsPresent` flag.
This commit is contained in:
Salman Ahmed 2022-07-23 08:09:00 +03:00
parent 1220250bb6
commit 727fe76b60
3 changed files with 32 additions and 19 deletions

View File

@ -58,7 +58,7 @@ namespace osu.Game.Tests.Visual.SongSelect
}); });
}); });
AddAssert("No rank displayed initially", () => topLocalRank.Rank == null); AddAssert("No rank displayed initially", () => topLocalRank.DisplayedRank == null);
} }
[Test] [Test]
@ -76,14 +76,14 @@ namespace osu.Game.Tests.Visual.SongSelect
scoreManager.Import(testScoreInfo); scoreManager.Import(testScoreInfo);
}); });
AddUntilStep("B rank displayed", () => topLocalRank.Rank == ScoreRank.B); AddUntilStep("B rank displayed", () => topLocalRank.DisplayedRank == ScoreRank.B);
AddStep("Delete score", () => AddStep("Delete score", () =>
{ {
scoreManager.Delete(testScoreInfo); scoreManager.Delete(testScoreInfo);
}); });
AddUntilStep("No rank displayed", () => topLocalRank.Rank == null); AddUntilStep("No rank displayed", () => topLocalRank.DisplayedRank == null);
} }
[Test] [Test]
@ -101,13 +101,13 @@ namespace osu.Game.Tests.Visual.SongSelect
scoreManager.Import(testScoreInfo); scoreManager.Import(testScoreInfo);
}); });
AddUntilStep("Wait for initial display", () => topLocalRank.Rank == ScoreRank.B); AddUntilStep("Wait for initial display", () => topLocalRank.DisplayedRank == ScoreRank.B);
AddStep("Change ruleset", () => Ruleset.Value = rulesets.GetRuleset("fruits")); AddStep("Change ruleset", () => Ruleset.Value = rulesets.GetRuleset("fruits"));
AddUntilStep("No rank displayed", () => topLocalRank.Rank == null); AddUntilStep("No rank displayed", () => topLocalRank.DisplayedRank == null);
AddStep("Change ruleset back", () => Ruleset.Value = rulesets.GetRuleset("osu")); AddStep("Change ruleset back", () => Ruleset.Value = rulesets.GetRuleset("osu"));
AddUntilStep("B rank displayed", () => topLocalRank.Rank == ScoreRank.B); AddUntilStep("B rank displayed", () => topLocalRank.DisplayedRank == ScoreRank.B);
} }
[Test] [Test]
@ -125,7 +125,7 @@ namespace osu.Game.Tests.Visual.SongSelect
scoreManager.Import(testScoreInfo); scoreManager.Import(testScoreInfo);
}); });
AddUntilStep("B rank displayed", () => topLocalRank.Rank == ScoreRank.B); AddUntilStep("B rank displayed", () => topLocalRank.DisplayedRank == ScoreRank.B);
AddStep("Add higher score for current user", () => AddStep("Add higher score for current user", () =>
{ {
@ -147,7 +147,7 @@ namespace osu.Game.Tests.Visual.SongSelect
scoreManager.Import(testScoreInfo2); scoreManager.Import(testScoreInfo2);
}); });
AddUntilStep("S rank displayed", () => topLocalRank.Rank == ScoreRank.S); AddUntilStep("S rank displayed", () => topLocalRank.DisplayedRank == ScoreRank.S);
} }
[Test] [Test]
@ -166,7 +166,7 @@ namespace osu.Game.Tests.Visual.SongSelect
scoreManager.Import(testScoreInfo); scoreManager.Import(testScoreInfo);
}); });
AddUntilStep("B rank displayed", () => topLocalRank.Rank == ScoreRank.B); AddUntilStep("B rank displayed", () => topLocalRank.DisplayedRank == ScoreRank.B);
AddStep("Add higher score for current user", () => AddStep("Add higher score for current user", () =>
{ {
@ -192,7 +192,7 @@ namespace osu.Game.Tests.Visual.SongSelect
scoreManager.Import(testScoreInfo2); scoreManager.Import(testScoreInfo2);
}); });
AddUntilStep("S rank displayed", () => topLocalRank.Rank == ScoreRank.S); AddUntilStep("S rank displayed", () => topLocalRank.DisplayedRank == ScoreRank.S);
} }
} }
} }

View File

@ -17,7 +17,7 @@ namespace osu.Game.Online.Leaderboards
set => Model = value; set => Model = value;
} }
public UpdateableRank(ScoreRank? rank) public UpdateableRank(ScoreRank? rank = null)
{ {
Rank = rank; Rank = rank;
} }

View File

@ -5,9 +5,12 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Models; using osu.Game.Models;
@ -20,7 +23,7 @@ using Realms;
namespace osu.Game.Screens.Select.Carousel namespace osu.Game.Screens.Select.Carousel
{ {
public class TopLocalRank : UpdateableRank public class TopLocalRank : CompositeDrawable
{ {
private readonly BeatmapInfo beatmapInfo; private readonly BeatmapInfo beatmapInfo;
@ -34,13 +37,25 @@ namespace osu.Game.Screens.Select.Carousel
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
private IDisposable scoreSubscription; private IDisposable scoreSubscription;
private CancellationTokenSource scoreOrderCancellationSource;
private readonly UpdateableRank updateable;
public ScoreRank? DisplayedRank => updateable.Rank;
public TopLocalRank(BeatmapInfo beatmapInfo) public TopLocalRank(BeatmapInfo beatmapInfo)
: base(null)
{ {
this.beatmapInfo = beatmapInfo; this.beatmapInfo = beatmapInfo;
Size = new Vector2(40, 20); AutoSizeAxes = Axes.Both;
InternalChild = updateable = new UpdateableRank
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(40, 20),
Alpha = 0,
};
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -59,19 +74,17 @@ namespace osu.Game.Screens.Select.Carousel
.OrderByDescending(s => s.TotalScore), .OrderByDescending(s => s.TotalScore),
(items, _, _) => (items, _, _) =>
{ {
Rank = items.FirstOrDefault()?.Rank; updateable.Rank = items.FirstOrDefault()?.Rank;
// Required since presence is changed via IsPresent override updateable.Alpha = updateable.Rank != null ? 1 : 0;
Invalidate(Invalidation.Presence);
}); });
}, true); }, true);
} }
public override bool IsPresent => base.IsPresent && Rank != null;
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
scoreOrderCancellationSource?.Cancel();
scoreSubscription?.Dispose(); scoreSubscription?.Dispose();
} }
} }