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

144 lines
4.8 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.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Pooling;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.SelectV2
{
public partial class PanelGroup : PoolableDrawable, ICarouselPanel
{
public const float HEIGHT = CarouselItem.DEFAULT_HEIGHT;
private const float duration = 500;
[Resolved]
private BeatmapCarousel? carousel { get; set; }
private CarouselPanelPiece panel = null!;
private Drawable chevronIcon = null!;
private OsuSpriteText titleText = null!;
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
Anchor = Anchor.TopRight;
Origin = Anchor.TopRight;
RelativeSizeAxes = Axes.X;
Height = HEIGHT;
InternalChild = panel = new CarouselPanelPiece(0)
{
Action = () => carousel?.Activate(Item!),
Icon = chevronIcon = new SpriteIcon
{
AlwaysPresent = true,
Icon = FontAwesome.Solid.ChevronDown,
Size = new Vector2(12),
Margin = new MarginPadding { Horizontal = 5f },
X = 2f,
Colour = colourProvider.Background3,
},
Background = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Dark1,
},
AccentColour = colourProvider.Highlight1,
Children = new Drawable[]
{
titleText = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
X = 10f,
},
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.Torus.With(size: 14.4f, weight: FontWeight.Bold),
// TODO: requires Carousel/CarouselItem-side implementation
Text = "43",
UseFullGlyphHeight = false,
}
},
}
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
Expanded.BindValueChanged(_ => onExpanded(), true);
KeyboardSelected.BindValueChanged(k => panel.KeyboardActive.Value = k.NewValue, true);
}
private void onExpanded()
{
panel.Active.Value = Expanded.Value;
panel.Flash();
chevronIcon.ResizeWidthTo(Expanded.Value ? 12f : 0f, duration, Easing.OutQuint);
chevronIcon.FadeTo(Expanded.Value ? 1f : 0f, duration, Easing.OutQuint);
}
protected override void PrepareForUse()
{
base.PrepareForUse();
Debug.Assert(Item != null);
GroupDefinition group = (GroupDefinition)Item.Model;
titleText.Text = group.Title;
FinishTransforms(true);
this.FadeInFromZero(500, Easing.OutQuint);
}
#region ICarouselPanel
public CarouselItem? Item { get; set; }
public BindableBool Selected { get; } = new BindableBool();
public BindableBool Expanded { get; } = new BindableBool();
public BindableBool KeyboardSelected { get; } = new BindableBool();
public double DrawYPosition { get; set; }
public void Activated()
{
}
#endregion
}
}