Various RankingsOverlay fixes

This commit is contained in:
Andrei Zavatski 2020-02-18 21:26:25 +03:00
parent 6a5c69e544
commit 5347119a85
2 changed files with 30 additions and 25 deletions

View File

@ -11,23 +11,20 @@ namespace osu.Game.Overlays.Rankings
{
public class RankingsOverlayHeader : TabControlOverlayHeader<RankingsScope>
{
public readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
public readonly Bindable<Country> Country = new Bindable<Country>();
public Bindable<RulesetInfo> Ruleset => rulesetSelector.Current;
public Bindable<Country> 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
{

View File

@ -19,14 +19,17 @@ namespace osu.Game.Overlays
{
public class RankingsOverlay : FullscreenOverlay
{
protected readonly Bindable<Country> Country = new Bindable<Country>();
protected readonly Bindable<RankingsScope> Scope = new Bindable<RankingsScope>();
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
protected Bindable<Country> Country => header.Country;
protected Bindable<RankingsScope> Scope => header.Current;
private Bindable<RulesetInfo> 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);
}
}
}