1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 15:17:44 +08:00
osu-lazer/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardThumbnail.cs

107 lines
3.5 KiB
C#
Raw Normal View History

2023-06-23 00:37:25 +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.
2021-10-24 01:27:07 +08:00
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.Shapes;
using osu.Game.Beatmaps.Drawables.Cards.Buttons;
using osu.Game.Online.API.Requests.Responses;
2021-10-24 01:27:07 +08:00
using osu.Game.Overlays;
using osu.Framework.Graphics.UserInterface;
2021-10-24 01:27:07 +08:00
using osuTK;
namespace osu.Game.Beatmaps.Drawables.Cards
{
2022-11-24 13:32:20 +08:00
public partial class BeatmapCardThumbnail : Container
{
public BindableBool Dimmed { get; } = new BindableBool();
2021-10-24 01:27:07 +08:00
public new MarginPadding Padding
{
get => foreground.Padding;
set => foreground.Padding = value;
}
private readonly Box background;
2021-10-24 01:27:07 +08:00
private readonly Container foreground;
2021-10-24 00:26:28 +08:00
private readonly PlayButton playButton;
private readonly CircularProgress progress;
private readonly Container content;
protected override Container<Drawable> Content => content;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
public BeatmapCardThumbnail(APIBeatmapSet beatmapSetInfo)
{
InternalChildren = new Drawable[]
{
new UpdateableOnlineBeatmapSetCover(BeatmapSetCoverType.List)
{
RelativeSizeAxes = Axes.Both,
OnlineInfo = beatmapSetInfo
},
background = new Box
{
RelativeSizeAxes = Axes.Both
},
2021-10-24 01:27:07 +08:00
foreground = new Container
{
2021-10-24 01:27:07 +08:00
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
playButton = new PlayButton(beatmapSetInfo)
{
RelativeSizeAxes = Axes.Both
},
progress = new CircularProgress
2021-10-24 01:27:07 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(50),
InnerRadius = 0.2f
},
content = new Container
{
RelativeSizeAxes = Axes.Both
}
}
}
};
}
2021-10-24 01:27:07 +08:00
[BackgroundDependencyLoader]
private void load()
2021-10-24 01:27:07 +08:00
{
progress.Colour = colourProvider.Highlight1;
}
protected override void LoadComplete()
{
base.LoadComplete();
Dimmed.BindValueChanged(_ => updateState());
2021-10-24 01:27:07 +08:00
playButton.Playing.BindValueChanged(_ => updateState(), true);
FinishTransforms(true);
}
protected override void Update()
{
base.Update();
progress.Progress = playButton.Progress.Value;
}
private void updateState()
{
bool shouldDim = Dimmed.Value || playButton.Playing.Value;
2021-12-21 15:26:19 +08:00
playButton.FadeTo(shouldDim ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
background.FadeColour(colourProvider.Background6.Opacity(shouldDim ? 0.8f : 0f), BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
}
}
}