2020-02-11 06:44:56 +08: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.
|
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2020-02-11 06:44:56 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
2021-12-03 17:16:29 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-10-25 01:21:46 +08:00
|
|
|
|
using osu.Game.Beatmaps.Drawables.Cards;
|
2020-02-11 06:44:56 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-12-03 17:16:29 +08:00
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
|
using osu.Game.Overlays.Rankings.Tables;
|
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
using osuTK;
|
2020-02-11 06:44:56 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Rankings
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class SpotlightsLayout : CompositeDrawable
|
2020-02-11 06:44:56 +08:00
|
|
|
|
{
|
|
|
|
|
public readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
|
|
|
|
|
|
|
|
|
|
private readonly Bindable<APISpotlight> selectedSpotlight = new Bindable<APISpotlight>();
|
2020-07-14 23:09:09 +08:00
|
|
|
|
private readonly Bindable<RankingsSortCriteria> sort = new Bindable<RankingsSortCriteria>();
|
2020-02-11 06:44:56 +08:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private IAPIProvider api { get; set; }
|
|
|
|
|
|
|
|
|
|
private CancellationTokenSource cancellationToken;
|
|
|
|
|
private GetSpotlightRankingsRequest getRankingsRequest;
|
|
|
|
|
private GetSpotlightsRequest spotlightsRequest;
|
|
|
|
|
|
2020-02-11 07:35:23 +08:00
|
|
|
|
private SpotlightSelector selector;
|
|
|
|
|
private Container content;
|
2020-02-21 14:31:40 +08:00
|
|
|
|
private LoadingLayer loading;
|
2020-02-11 06:44:56 +08:00
|
|
|
|
|
2020-02-11 07:35:23 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2020-02-11 06:44:56 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2021-01-04 21:42:39 +08:00
|
|
|
|
|
2020-02-11 06:44:56 +08:00
|
|
|
|
InternalChild = new ReverseChildIDFillFlowContainer<Drawable>
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
selector = new SpotlightSelector
|
|
|
|
|
{
|
|
|
|
|
Current = selectedSpotlight,
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
content = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2020-02-11 07:35:23 +08:00
|
|
|
|
Margin = new MarginPadding { Vertical = 10 }
|
2020-02-11 06:44:56 +08:00
|
|
|
|
},
|
2021-01-04 21:42:39 +08:00
|
|
|
|
loading = new LoadingLayer(true)
|
2020-02-11 06:44:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-07-14 23:09:09 +08:00
|
|
|
|
|
|
|
|
|
sort.BindTo(selector.Sort);
|
2020-02-11 06:44:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2020-07-14 23:09:09 +08:00
|
|
|
|
selectedSpotlight.BindValueChanged(_ => onSpotlightChanged());
|
|
|
|
|
sort.BindValueChanged(_ => onSpotlightChanged());
|
2020-02-11 06:44:56 +08:00
|
|
|
|
Ruleset.BindValueChanged(onRulesetChanged);
|
|
|
|
|
|
|
|
|
|
getSpotlights();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void getSpotlights()
|
|
|
|
|
{
|
|
|
|
|
spotlightsRequest = new GetSpotlightsRequest();
|
2020-02-17 15:07:32 +08:00
|
|
|
|
spotlightsRequest.Success += response => Schedule(() => selector.Spotlights = response.Spotlights);
|
2020-02-11 06:44:56 +08:00
|
|
|
|
api.Queue(spotlightsRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onRulesetChanged(ValueChangedEvent<RulesetInfo> ruleset)
|
|
|
|
|
{
|
|
|
|
|
if (!selector.Spotlights.Any())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
selectedSpotlight.TriggerChange();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-14 23:09:09 +08:00
|
|
|
|
private void onSpotlightChanged()
|
2020-02-11 06:44:56 +08:00
|
|
|
|
{
|
|
|
|
|
loading.Show();
|
|
|
|
|
|
|
|
|
|
cancellationToken?.Cancel();
|
|
|
|
|
getRankingsRequest?.Cancel();
|
|
|
|
|
|
2020-07-14 23:09:09 +08:00
|
|
|
|
getRankingsRequest = new GetSpotlightRankingsRequest(Ruleset.Value, selectedSpotlight.Value.Id, sort.Value);
|
2020-02-11 06:44:56 +08:00
|
|
|
|
getRankingsRequest.Success += onSuccess;
|
|
|
|
|
api.Queue(getRankingsRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onSuccess(GetSpotlightRankingsResponse response)
|
|
|
|
|
{
|
|
|
|
|
LoadComponentAsync(createContent(response), loaded =>
|
|
|
|
|
{
|
|
|
|
|
selector.ShowInfo(response);
|
|
|
|
|
|
|
|
|
|
content.Clear();
|
|
|
|
|
content.Add(loaded);
|
|
|
|
|
|
|
|
|
|
loading.Hide();
|
|
|
|
|
}, (cancellationToken = new CancellationTokenSource()).Token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Drawable createContent(GetSpotlightRankingsResponse response) => new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Spacing = new Vector2(0, 20),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new ScoresTable(1, response.Users),
|
2021-12-07 04:00:26 +08:00
|
|
|
|
// reverse ID flow is required for correct Z-ordering of the cards' expandable content (last card should be front-most).
|
2021-12-21 15:25:52 +08:00
|
|
|
|
new ReverseChildIDFillFlowContainer<BeatmapCardNormal>
|
2020-02-11 06:44:56 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2022-01-04 01:43:20 +08:00
|
|
|
|
Margin = new MarginPadding { Bottom = ExpandedContentScrollContainer.HEIGHT },
|
2020-02-11 06:44:56 +08:00
|
|
|
|
Spacing = new Vector2(10),
|
2021-12-21 15:25:52 +08:00
|
|
|
|
Children = response.BeatmapSets.Select(b => new BeatmapCardNormal(b)
|
2020-02-11 06:44:56 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
}).ToList()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
spotlightsRequest?.Cancel();
|
|
|
|
|
getRankingsRequest?.Cancel();
|
|
|
|
|
cancellationToken?.Cancel();
|
2020-02-17 15:07:32 +08:00
|
|
|
|
|
|
|
|
|
base.Dispose(isDisposing);
|
2020-02-11 06:44:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|