1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-12 02:27:28 +08:00
osu-lazer/osu.Game/Screens/SelectV2/PanelBeatmapSet.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

175 lines
6.7 KiB
C#
Raw Normal View History

// 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.
using System.Diagnostics;
2025-02-05 07:15:53 -05:00
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
2025-02-05 07:15:53 -05:00
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
2025-02-05 07:15:53 -05:00
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2025-02-05 07:15:53 -05:00
using osu.Game.Overlays;
using osuTK;
namespace osu.Game.Screens.SelectV2
{
public partial class PanelBeatmapSet : PanelBase
{
2025-02-05 07:15:53 -05:00
public const float HEIGHT = CarouselItem.DEFAULT_HEIGHT * 1.6f;
// todo: this should be replaced with information from CarouselItem about how deep is PanelBeatmap in the carousel
2025-02-05 22:14:38 -05:00
// (i.e. whether it's under a beatmap set that's under a group, or just under a top-level beatmap set).
private const float set_x_offset = 20f; // constant X offset for beatmap set/standalone panels specifically.
2025-02-05 07:15:53 -05:00
private const float duration = 500;
private BeatmapSetPanelBackground background = null!;
private OsuSpriteText titleText = null!;
private OsuSpriteText artistText = null!;
private Drawable chevronIcon = null!;
2025-02-12 19:22:57 +09:00
private UpdateBeatmapSetButton updateButton = null!;
private BeatmapSetOnlineStatusPill statusPill = null!;
private DifficultySpectrumDisplay difficultiesDisplay = null!;
2025-02-05 07:15:53 -05:00
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
2025-02-05 07:15:53 -05:00
[Resolved]
private BeatmapManager beatmaps { get; set; } = null!;
2025-02-05 04:45:32 -05:00
public PanelBeatmapSet()
: base(set_x_offset)
{
}
[BackgroundDependencyLoader]
private void load()
{
2025-02-05 07:15:53 -05:00
Anchor = Anchor.TopRight;
Origin = Anchor.TopRight;
RelativeSizeAxes = Axes.X;
Height = HEIGHT;
Icon = chevronIcon = new Container
{
Size = new Vector2(22),
Child = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.ChevronRight,
Size = new Vector2(12),
X = 1f,
Colour = colourProvider.Background5,
},
};
Background = background = new BeatmapSetPanelBackground
{
RelativeSizeAxes = Axes.Both,
};
Content.Children = new[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Padding = new MarginPadding { Top = 7.5f, Left = 15, Bottom = 5 },
Children = new Drawable[]
2025-02-05 07:15:53 -05:00
{
titleText = new OsuSpriteText
2025-02-05 07:15:53 -05:00
{
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 22, italics: true),
},
artistText = new OsuSpriteText
{
Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 17, italics: true),
},
new FillFlowContainer
{
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding { Top = 5f },
Children = new Drawable[]
2025-02-05 07:15:53 -05:00
{
2025-02-12 19:22:57 +09:00
updateButton = new UpdateBeatmapSetButton
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Right = 5f, Top = -2f },
},
statusPill = new BeatmapSetOnlineStatusPill
{
AutoSizeAxes = Axes.Both,
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
TextSize = 11,
TextPadding = new MarginPadding { Horizontal = 8, Vertical = 2 },
Margin = new MarginPadding { Right = 5f },
},
difficultiesDisplay = new DifficultySpectrumDisplay
2025-02-05 07:15:53 -05:00
{
DotSize = new Vector2(5, 10),
DotSpacing = 2,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
2025-02-05 07:15:53 -05:00
},
},
2025-02-05 07:15:53 -05:00
}
}
}
};
2025-02-05 07:15:53 -05:00
}
protected override void LoadComplete()
2025-02-05 07:15:53 -05:00
{
base.LoadComplete();
2025-02-05 07:15:53 -05:00
Expanded.BindValueChanged(_ => onExpanded(), true);
KeyboardSelected.BindValueChanged(k => KeyboardSelected.Value = k.NewValue, true);
2025-02-05 07:15:53 -05:00
}
private void onExpanded()
2025-02-05 07:15:53 -05:00
{
chevronIcon.ResizeWidthTo(Expanded.Value ? 22 : 0f, duration, Easing.OutQuint);
chevronIcon.FadeTo(Expanded.Value ? 1f : 0f, duration, Easing.OutQuint);
}
protected override void PrepareForUse()
{
base.PrepareForUse();
Debug.Assert(Item != null);
2025-02-05 07:15:53 -05:00
var beatmapSet = (BeatmapSetInfo)Item.Model;
// Choice of background image matches BSS implementation (always uses the lowest `beatmap_id` from the set).
background.Beatmap = beatmaps.GetWorkingBeatmap(beatmapSet.Beatmaps.MinBy(b => b.OnlineID));
titleText.Text = new RomanisableString(beatmapSet.Metadata.TitleUnicode, beatmapSet.Metadata.Title);
artistText.Text = new RomanisableString(beatmapSet.Metadata.ArtistUnicode, beatmapSet.Metadata.Artist);
updateButton.BeatmapSet = beatmapSet;
statusPill.Status = beatmapSet.Status;
difficultiesDisplay.BeatmapSet = beatmapSet;
2025-02-05 07:15:53 -05:00
FinishTransforms(true);
this.FadeInFromZero(duration, Easing.OutQuint);
}
protected override void FreeAfterUse()
{
base.FreeAfterUse();
background.Beatmap = null;
updateButton.BeatmapSet = null;
difficultiesDisplay.BeatmapSet = null;
}
}
}