Update all beatmap overlay views to use APIBeatmap/APIBeatmapSet

This commit is contained in:
Dean Herbert
2021-10-29 17:58:46 +09:00
parent b8ee7e05f4
commit a16c8f1ebc
45 changed files with 471 additions and 613 deletions

View File

@ -17,6 +17,7 @@ using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets;
using osuTK;
@ -34,10 +35,10 @@ namespace osu.Game.Overlays.BeatmapSet
public readonly DifficultiesContainer Difficulties;
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
private BeatmapSetInfo beatmapSet;
public readonly Bindable<APIBeatmap> Beatmap = new Bindable<APIBeatmap>();
private APIBeatmapSet beatmapSet;
public BeatmapSetInfo BeatmapSet
public APIBeatmapSet BeatmapSet
{
get => beatmapSet;
set
@ -164,35 +165,38 @@ namespace osu.Game.Overlays.BeatmapSet
if (BeatmapSet != null)
{
Difficulties.ChildrenEnumerable = BeatmapSet.Beatmaps.Where(b => b.Ruleset.Equals(ruleset.Value)).OrderBy(b => b.StarDifficulty).Select(b => new DifficultySelectorButton(b)
{
State = DifficultySelectorState.NotSelected,
OnHovered = beatmap =>
{
showBeatmap(beatmap);
starRating.Text = beatmap.StarDifficulty.ToLocalisableString(@"0.##");
starRatingContainer.FadeIn(100);
},
OnClicked = beatmap => { Beatmap.Value = beatmap; },
});
Difficulties.ChildrenEnumerable = BeatmapSet.Beatmaps
.Where(b => b.Ruleset?.OnlineID == ruleset.Value?.OnlineID)
.OrderBy(b => b.StarRating)
.Select(b => new DifficultySelectorButton(b)
{
State = DifficultySelectorState.NotSelected,
OnHovered = beatmap =>
{
showBeatmap(beatmap);
starRating.Text = beatmap.StarRating.ToLocalisableString(@"0.##");
starRatingContainer.FadeIn(100);
},
OnClicked = beatmap => { Beatmap.Value = beatmap; },
});
}
starRatingContainer.FadeOut(100);
Beatmap.Value = Difficulties.FirstOrDefault()?.BeatmapInfo;
plays.Value = BeatmapSet?.OnlineInfo.PlayCount ?? 0;
favourites.Value = BeatmapSet?.OnlineInfo.FavouriteCount ?? 0;
Beatmap.Value = Difficulties.FirstOrDefault()?.Beatmap;
plays.Value = BeatmapSet?.PlayCount ?? 0;
favourites.Value = BeatmapSet?.FavouriteCount ?? 0;
updateDifficultyButtons();
}
private void showBeatmap(BeatmapInfo beatmapInfo)
private void showBeatmap(IBeatmapInfo beatmapInfo)
{
version.Text = beatmapInfo?.Version;
version.Text = beatmapInfo?.DifficultyName;
}
private void updateDifficultyButtons()
{
Difficulties.Children.ToList().ForEach(diff => diff.State = diff.BeatmapInfo == Beatmap.Value ? DifficultySelectorState.Selected : DifficultySelectorState.NotSelected);
Difficulties.Children.ToList().ForEach(diff => diff.State = diff.Beatmap == Beatmap.Value ? DifficultySelectorState.Selected : DifficultySelectorState.NotSelected);
}
public class DifficultiesContainer : FillFlowContainer<DifficultySelectorButton>
@ -216,10 +220,10 @@ namespace osu.Game.Overlays.BeatmapSet
private readonly Box backgroundBox;
private readonly DifficultyIcon icon;
public readonly BeatmapInfo BeatmapInfo;
public readonly APIBeatmap Beatmap;
public Action<BeatmapInfo> OnHovered;
public Action<BeatmapInfo> OnClicked;
public Action<APIBeatmap> OnHovered;
public Action<APIBeatmap> OnClicked;
public event Action<DifficultySelectorState> StateChanged;
private DifficultySelectorState state;
@ -241,9 +245,9 @@ namespace osu.Game.Overlays.BeatmapSet
}
}
public DifficultySelectorButton(BeatmapInfo beatmapInfo)
public DifficultySelectorButton(APIBeatmap beatmapInfo)
{
BeatmapInfo = beatmapInfo;
Beatmap = beatmapInfo;
Size = new Vector2(size);
Margin = new MarginPadding { Horizontal = tile_spacing / 2 };
@ -273,7 +277,7 @@ namespace osu.Game.Overlays.BeatmapSet
protected override bool OnHover(HoverEvent e)
{
fadeIn();
OnHovered?.Invoke(BeatmapInfo);
OnHovered?.Invoke(Beatmap);
return base.OnHover(e);
}
@ -286,7 +290,7 @@ namespace osu.Game.Overlays.BeatmapSet
protected override bool OnClick(ClickEvent e)
{
OnClicked?.Invoke(BeatmapInfo);
OnClicked?.Invoke(Beatmap);
return base.OnClick(e);
}