1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-21 07:09:53 +08:00
Files
osu-lazer/osu.Game/Screens/SelectV2/PanelGroupStarDifficulty.cs
T
Dean Herbert 0aff50fbf5 Rename song select v2 classes and namespaces
This aims to bring some conformity to naming to make it easier to
understand component structure for new components.

Renames are pulled out of the song select v2 changes and are more
relevant there due to many new classes being added.

- `V2` suffix is dropped, with v2 components being moved to a relevant V2 namespace.
- Related classes have a prefix of the area they are used.
- Experimenting with using partial/nested classes in the song select v2 implementation.
  Not committing to this yet but want to see how it plays out.
- Moved base carousel components to a generic namespace to avoid confusion with actual beatmap carousel implementation.
2025-04-16 18:34:53 +09:00

187 lines
6.2 KiB
C#

// 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;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.SelectV2
{
public partial class PanelGroupStarDifficulty : Panel
{
[Resolved]
private OsuColour colours { get; set; } = null!;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
private Drawable iconContainer = null!;
private Box contentBackground = null!;
private OsuSpriteText starRatingText = null!;
private TrianglesV2 triangles = null!;
private Box glow = null!;
[BackgroundDependencyLoader]
private void load()
{
Height = PanelGroup.HEIGHT;
Icon = iconContainer = new Container
{
AlwaysPresent = true,
RelativeSizeAxes = Axes.Y,
Child = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.ChevronDown,
Size = new Vector2(12),
},
};
Background = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
contentBackground = new Box
{
RelativeSizeAxes = Axes.Both,
},
triangles = new TrianglesV2
{
RelativeSizeAxes = Axes.Both,
Thickness = 0.02f,
SpawnRatio = 0.6f,
},
glow = new Box
{
RelativeSizeAxes = Axes.Both,
Width = 0.5f,
},
},
};
AccentColour = colourProvider.Highlight1;
Content.Children = new Drawable[]
{
new FillFlowContainer
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(10f, 0f),
Margin = new MarginPadding { Left = 10f },
Children = new Drawable[]
{
starRatingText = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
UseFullGlyphHeight = false,
Font = OsuFont.Style.Heading2,
}
}
},
new CircularContainer
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Size = new Vector2(50f, 14f),
Margin = new MarginPadding { Right = 20f },
Masking = true,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black.Opacity(0.7f),
},
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.Style.Caption1.With(weight: FontWeight.Bold),
// TODO: requires Carousel/CarouselItem-side implementation
Text = "43",
UseFullGlyphHeight = false,
}
},
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
Expanded.BindValueChanged(_ => onExpanded(), true);
}
private Color4 ratingColour;
protected override void PrepareForUse()
{
base.PrepareForUse();
Debug.Assert(Item != null);
int starNumber = (int)((GroupDefinition)Item.Model).Data;
ratingColour = starNumber >= 9 ? OsuColour.Gray(0.2f) : colours.ForStarDifficulty(starNumber);
AccentColour = ratingColour;
contentBackground.Colour = ratingColour.Darken(1f);
glow.Colour = ColourInfo.GradientHorizontal(ratingColour, ratingColour.Opacity(0f));
switch (starNumber)
{
case 0:
starRatingText.Text = @"Below 1 Star";
break;
case 1:
starRatingText.Text = @"1 Star";
break;
default:
starRatingText.Text = $"{starNumber} Stars";
break;
}
iconContainer.Colour = starNumber >= 7 ? colourProvider.Content1 : colourProvider.Background5;
starRatingText.Colour = colourProvider.Content1;
ColourInfo colour;
if (starNumber >= 8)
colour = ColourInfo.GradientHorizontal(ratingColour, ratingColour.Darken(0.2f));
else
colour = ColourInfo.GradientHorizontal(ratingColour.Darken(0.6f), ratingColour.Darken(0.8f));
triangles.Colour = colour;
onExpanded();
}
private void onExpanded()
{
const float duration = 500;
iconContainer.ResizeWidthTo(Expanded.Value ? 20f : 5f, duration, Easing.OutQuint);
iconContainer.FadeTo(Expanded.Value ? 1f : 0f, duration, Easing.OutQuint);
glow.FadeTo(Expanded.Value ? 0.4f : 0, duration, Easing.OutQuint);
}
}
}