From 5347119a857fa86545dc2231039bd2dc3be6fab7 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 18 Feb 2020 21:26:25 +0300 Subject: [PATCH] Various RankingsOverlay fixes --- .../Rankings/RankingsOverlayHeader.cs | 17 ++++----- osu.Game/Overlays/RankingsOverlay.cs | 38 +++++++++++-------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/osu.Game/Overlays/Rankings/RankingsOverlayHeader.cs b/osu.Game/Overlays/Rankings/RankingsOverlayHeader.cs index 2674b3a81e..164585de38 100644 --- a/osu.Game/Overlays/Rankings/RankingsOverlayHeader.cs +++ b/osu.Game/Overlays/Rankings/RankingsOverlayHeader.cs @@ -11,23 +11,20 @@ namespace osu.Game.Overlays.Rankings { public class RankingsOverlayHeader : TabControlOverlayHeader { - public readonly Bindable Ruleset = new Bindable(); - public readonly Bindable Country = new Bindable(); + public Bindable Ruleset => rulesetSelector.Current; + public Bindable Country => countryFilter.Current; + + private OverlayRulesetSelector rulesetSelector; + private CountryFilter countryFilter; protected override ScreenTitle CreateTitle() => new RankingsTitle { Scope = { BindTarget = Current } }; - protected override Drawable CreateTitleContent() => new OverlayRulesetSelector - { - Current = Ruleset - }; + protected override Drawable CreateTitleContent() => rulesetSelector = new OverlayRulesetSelector(); - protected override Drawable CreateContent() => new CountryFilter - { - Current = Country - }; + protected override Drawable CreateContent() => countryFilter = new CountryFilter(); private class RankingsTitle : ScreenTitle { diff --git a/osu.Game/Overlays/RankingsOverlay.cs b/osu.Game/Overlays/RankingsOverlay.cs index f3215d07fa..2c5ea61315 100644 --- a/osu.Game/Overlays/RankingsOverlay.cs +++ b/osu.Game/Overlays/RankingsOverlay.cs @@ -19,14 +19,17 @@ namespace osu.Game.Overlays { public class RankingsOverlay : FullscreenOverlay { - protected readonly Bindable Country = new Bindable(); - protected readonly Bindable Scope = new Bindable(); - private readonly Bindable ruleset = new Bindable(); + protected Bindable Country => header.Country; + + protected Bindable Scope => header.Current; + + private Bindable ruleset => header.Ruleset; private readonly BasicScrollContainer scrollFlow; private readonly Container contentContainer; private readonly DimmedLoadingLayer loading; private readonly Box background; + private readonly RankingsOverlayHeader header; private APIRequest lastRequest; private CancellationTokenSource cancellationToken; @@ -54,14 +57,11 @@ namespace osu.Game.Overlays Direction = FillDirection.Vertical, Children = new Drawable[] { - new RankingsOverlayHeader + header = new RankingsOverlayHeader { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, - Depth = -float.MaxValue, - Country = { BindTarget = Country }, - Current = { BindTarget = Scope }, - Ruleset = { BindTarget = ruleset } + Depth = -float.MaxValue }, new Container { @@ -94,6 +94,8 @@ namespace osu.Game.Overlays protected override void LoadComplete() { + base.LoadComplete(); + Country.BindValueChanged(_ => { // if a country is requested, force performance scope. @@ -101,7 +103,7 @@ namespace osu.Game.Overlays Scope.Value = RankingsScope.Performance; Scheduler.AddOnce(loadNewContent); - }, true); + }); Scope.BindValueChanged(_ => { @@ -110,7 +112,7 @@ namespace osu.Game.Overlays Country.Value = null; Scheduler.AddOnce(loadNewContent); - }, true); + }); ruleset.BindValueChanged(_ => { @@ -118,9 +120,7 @@ namespace osu.Game.Overlays return; Scheduler.AddOnce(loadNewContent); - }, true); - - base.LoadComplete(); + }); } public void ShowCountry(Country requested) @@ -158,8 +158,8 @@ namespace osu.Game.Overlays return; } - request.Success += () => loadContent(createTableFromResponse(request)); - request.Failure += _ => loadContent(null); + request.Success += () => Schedule(() => loadContent(createTableFromResponse(request))); + request.Failure += _ => Schedule(() => loadContent(null)); api.Queue(request); } @@ -221,5 +221,13 @@ namespace osu.Game.Overlays contentContainer.Child = loaded; }, (cancellationToken = new CancellationTokenSource()).Token); } + + protected override void Dispose(bool isDisposing) + { + lastRequest?.Cancel(); + cancellationToken?.Cancel(); + + base.Dispose(isDisposing); + } } }