2021-12-17 20:27:11 +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-11-27 23:20:51 +08:00
|
|
|
using System;
|
2021-12-17 20:27:11 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Online;
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables.Cards
|
|
|
|
{
|
2022-11-05 00:01:52 +08:00
|
|
|
public abstract class BeatmapCard : OsuClickableContainer
|
2021-12-17 20:27:11 +08:00
|
|
|
{
|
|
|
|
public const float TRANSITION_DURATION = 400;
|
|
|
|
public const float CORNER_RADIUS = 10;
|
|
|
|
|
2021-12-24 16:17:07 +08:00
|
|
|
protected const float WIDTH = 430;
|
|
|
|
|
2021-12-17 20:27:11 +08:00
|
|
|
public IBindable<bool> Expanded { get; }
|
|
|
|
|
2021-12-22 20:16:36 +08:00
|
|
|
public readonly APIBeatmapSet BeatmapSet;
|
|
|
|
|
2021-12-17 20:27:11 +08:00
|
|
|
protected readonly Bindable<BeatmapSetFavouriteState> FavouriteState;
|
|
|
|
|
|
|
|
protected abstract Drawable IdleContent { get; }
|
|
|
|
protected abstract Drawable DownloadInProgressContent { get; }
|
|
|
|
|
|
|
|
protected readonly BeatmapDownloadTracker DownloadTracker;
|
|
|
|
|
2021-12-21 15:26:19 +08:00
|
|
|
protected BeatmapCard(APIBeatmapSet beatmapSet, bool allowExpansion = true)
|
2022-06-01 20:00:14 +08:00
|
|
|
: base(HoverSampleSet.Button)
|
2021-12-17 20:27:11 +08:00
|
|
|
{
|
|
|
|
Expanded = new BindableBool { Disabled = !allowExpansion };
|
|
|
|
|
|
|
|
BeatmapSet = beatmapSet;
|
|
|
|
FavouriteState = new Bindable<BeatmapSetFavouriteState>(new BeatmapSetFavouriteState(beatmapSet.HasFavourited, beatmapSet.FavouriteCount));
|
|
|
|
DownloadTracker = new BeatmapDownloadTracker(beatmapSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
private void load(BeatmapSetOverlay? beatmapSetOverlay)
|
|
|
|
{
|
|
|
|
Action = () => beatmapSetOverlay?.FetchAndShowBeatmapSet(BeatmapSet.OnlineID);
|
|
|
|
|
|
|
|
AddInternal(DownloadTracker);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
DownloadTracker.State.BindValueChanged(_ => UpdateState());
|
|
|
|
Expanded.BindValueChanged(_ => UpdateState(), true);
|
|
|
|
FinishTransforms(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
UpdateState();
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
UpdateState();
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void UpdateState()
|
|
|
|
{
|
|
|
|
bool showProgress = DownloadTracker.State.Value == DownloadState.Downloading || DownloadTracker.State.Value == DownloadState.Importing;
|
|
|
|
|
|
|
|
IdleContent.FadeTo(showProgress ? 0 : 1, TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
DownloadInProgressContent.FadeTo(showProgress ? 1 : 0, TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
}
|
2021-11-27 23:20:51 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a beatmap card of the given <paramref name="size"/> for the supplied <paramref name="beatmapSet"/>.
|
|
|
|
/// </summary>
|
|
|
|
public static BeatmapCard Create(APIBeatmapSet beatmapSet, BeatmapCardSize size, bool allowExpansion = true)
|
|
|
|
{
|
|
|
|
switch (size)
|
|
|
|
{
|
|
|
|
case BeatmapCardSize.Normal:
|
|
|
|
return new BeatmapCardNormal(beatmapSet, allowExpansion);
|
|
|
|
|
|
|
|
case BeatmapCardSize.Extra:
|
|
|
|
return new BeatmapCardExtra(beatmapSet, allowExpansion);
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(size), size, @"Unsupported card size");
|
|
|
|
}
|
|
|
|
}
|
2021-12-17 20:27:11 +08:00
|
|
|
}
|
|
|
|
}
|