1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 15:32:57 +08:00
osu-lazer/osu.Game/Screens/Select/Carousel/SetPanelContent.cs

114 lines
4.7 KiB
C#
Raw Normal View History

2020-10-13 16:55: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-10-13 16:55:56 +08:00
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
2020-10-13 16:55:56 +08:00
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK;
namespace osu.Game.Screens.Select.Carousel
{
public class SetPanelContent : CompositeDrawable
{
// Disallow interacting with difficulty icons on a panel until the panel has been selected.
public override bool PropagatePositionalInputSubTree => carouselSet.State.Value == CarouselItemState.Selected;
2020-10-13 16:55:56 +08:00
private readonly CarouselBeatmapSet carouselSet;
public SetPanelContent(CarouselBeatmapSet carouselSet)
{
this.carouselSet = carouselSet;
// required to ensure we load as soon as any part of the panel comes on screen
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
var beatmapSet = carouselSet.BeatmapSet;
InternalChild = new FillFlowContainer
{
// required to ensure we load as soon as any part of the panel comes on screen
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Padding = new MarginPadding { Top = 5, Left = 18, Right = 10, Bottom = 10 },
Children = new Drawable[]
{
new OsuSpriteText
{
2022-01-04 13:35:18 +08:00
Text = new RomanisableString(beatmapSet.Metadata.TitleUnicode, beatmapSet.Metadata.Title),
2020-10-13 16:55:56 +08:00
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 22, italics: true),
Shadow = true,
},
new OsuSpriteText
{
2022-01-04 13:35:18 +08:00
Text = new RomanisableString(beatmapSet.Metadata.ArtistUnicode, beatmapSet.Metadata.Artist),
2020-10-13 16:55:56 +08:00
Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 17, italics: true),
Shadow = true,
},
new FillFlowContainer
{
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding { Top = 5 },
2022-07-18 17:06:11 +08:00
Spacing = new Vector2(5),
Children = new[]
2020-10-13 16:55:56 +08:00
{
2022-07-19 17:01:25 +08:00
beatmapSet.AllBeatmapsUpToDate
? Empty()
: new Container
{
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Children = new Drawable[]
{
new UpdateBeatmapSetButton(beatmapSet),
2022-07-19 17:01:25 +08:00
}
},
2020-10-13 16:55:56 +08:00
new BeatmapSetOnlineStatusPill
{
AutoSizeAxes = Axes.Both,
2020-10-13 16:55:56 +08:00
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
TextSize = 11,
TextPadding = new MarginPadding { Horizontal = 8, Vertical = 2 },
Status = beatmapSet.Status
},
new FillFlowContainer<DifficultyIcon>
{
AutoSizeAxes = Axes.Both,
2022-07-18 17:06:11 +08:00
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
2020-10-13 16:55:56 +08:00
Spacing = new Vector2(3),
ChildrenEnumerable = getDifficultyIcons(),
},
}
}
}
};
}
private const int maximum_difficulty_icons = 18;
private IEnumerable<DifficultyIcon> getDifficultyIcons()
{
var beatmaps = carouselSet.Beatmaps.ToList();
return beatmaps.Count > maximum_difficulty_icons
2022-06-24 13:48:43 +08:00
? beatmaps.GroupBy(b => b.BeatmapInfo.Ruleset)
2022-06-24 20:22:33 +08:00
.Select(group => new GroupedDifficultyIcon(group.ToList(), group.Last().BeatmapInfo.Ruleset))
2020-10-13 16:55:56 +08:00
: beatmaps.Select(b => new FilterableDifficultyIcon(b));
}
}
}