Merge pull request #7893 from EVAST9919/rankings-refactor

Various RankingsOverlay fixes
This commit is contained in:
Dan Balasescu 2020-02-19 11:20:04 +09:00 committed by GitHub
commit 02f3e78b14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 25 deletions

View File

@ -11,23 +11,21 @@ namespace osu.Game.Overlays.Rankings
{ {
public class RankingsOverlayHeader : TabControlOverlayHeader<RankingsScope> public class RankingsOverlayHeader : TabControlOverlayHeader<RankingsScope>
{ {
public readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>(); public Bindable<RulesetInfo> Ruleset => rulesetSelector.Current;
public readonly Bindable<Country> Country = new Bindable<Country>();
public Bindable<Country> Country => countryFilter.Current;
private OverlayRulesetSelector rulesetSelector;
private CountryFilter countryFilter;
protected override ScreenTitle CreateTitle() => new RankingsTitle protected override ScreenTitle CreateTitle() => new RankingsTitle
{ {
Scope = { BindTarget = Current } Scope = { BindTarget = Current }
}; };
protected override Drawable CreateTitleContent() => new OverlayRulesetSelector protected override Drawable CreateTitleContent() => rulesetSelector = new OverlayRulesetSelector();
{
Current = Ruleset
};
protected override Drawable CreateContent() => new CountryFilter protected override Drawable CreateContent() => countryFilter = new CountryFilter();
{
Current = Country
};
private class RankingsTitle : ScreenTitle private class RankingsTitle : ScreenTitle
{ {

View File

@ -19,14 +19,17 @@ namespace osu.Game.Overlays
{ {
public class RankingsOverlay : FullscreenOverlay public class RankingsOverlay : FullscreenOverlay
{ {
protected readonly Bindable<Country> Country = new Bindable<Country>(); protected Bindable<Country> Country => header.Country;
protected readonly Bindable<RankingsScope> Scope = new Bindable<RankingsScope>();
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>(); protected Bindable<RankingsScope> Scope => header.Current;
private Bindable<RulesetInfo> ruleset => header.Ruleset;
private readonly BasicScrollContainer scrollFlow; private readonly BasicScrollContainer scrollFlow;
private readonly Container contentContainer; private readonly Container contentContainer;
private readonly DimmedLoadingLayer loading; private readonly DimmedLoadingLayer loading;
private readonly Box background; private readonly Box background;
private readonly RankingsOverlayHeader header;
private APIRequest lastRequest; private APIRequest lastRequest;
private CancellationTokenSource cancellationToken; private CancellationTokenSource cancellationToken;
@ -54,14 +57,11 @@ namespace osu.Game.Overlays
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
Children = new Drawable[] Children = new Drawable[]
{ {
new RankingsOverlayHeader header = new RankingsOverlayHeader
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
Depth = -float.MaxValue, Depth = -float.MaxValue
Country = { BindTarget = Country },
Current = { BindTarget = Scope },
Ruleset = { BindTarget = ruleset }
}, },
new Container new Container
{ {
@ -94,6 +94,8 @@ namespace osu.Game.Overlays
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete();
Country.BindValueChanged(_ => Country.BindValueChanged(_ =>
{ {
// if a country is requested, force performance scope. // if a country is requested, force performance scope.
@ -101,7 +103,7 @@ namespace osu.Game.Overlays
Scope.Value = RankingsScope.Performance; Scope.Value = RankingsScope.Performance;
Scheduler.AddOnce(loadNewContent); Scheduler.AddOnce(loadNewContent);
}, true); });
Scope.BindValueChanged(_ => Scope.BindValueChanged(_ =>
{ {
@ -110,7 +112,7 @@ namespace osu.Game.Overlays
Country.Value = null; Country.Value = null;
Scheduler.AddOnce(loadNewContent); Scheduler.AddOnce(loadNewContent);
}, true); });
ruleset.BindValueChanged(_ => ruleset.BindValueChanged(_ =>
{ {
@ -118,9 +120,7 @@ namespace osu.Game.Overlays
return; return;
Scheduler.AddOnce(loadNewContent); Scheduler.AddOnce(loadNewContent);
}, true); });
base.LoadComplete();
} }
public void ShowCountry(Country requested) public void ShowCountry(Country requested)
@ -158,8 +158,8 @@ namespace osu.Game.Overlays
return; return;
} }
request.Success += () => loadContent(createTableFromResponse(request)); request.Success += () => Schedule(() => loadContent(createTableFromResponse(request)));
request.Failure += _ => loadContent(null); request.Failure += _ => Schedule(() => loadContent(null));
api.Queue(request); api.Queue(request);
} }
@ -221,5 +221,13 @@ namespace osu.Game.Overlays
contentContainer.Child = loaded; contentContainer.Child = loaded;
}, (cancellationToken = new CancellationTokenSource()).Token); }, (cancellationToken = new CancellationTokenSource()).Token);
} }
protected override void Dispose(bool isDisposing)
{
lastRequest?.Cancel();
cancellationToken?.Cancel();
base.Dispose(isDisposing);
}
} }
} }