2021-10-18 03:34:31 +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-23 21:51:36 +08:00
|
|
|
#nullable enable
|
|
|
|
|
2021-10-23 21:01:53 +08:00
|
|
|
using osu.Framework.Allocation;
|
2021-10-23 21:51:36 +08:00
|
|
|
using osu.Framework.Bindables;
|
2021-10-23 21:01:53 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-10-18 03:34:31 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-10-23 21:51:36 +08:00
|
|
|
using osu.Game.Configuration;
|
2021-10-23 21:27:04 +08:00
|
|
|
using osu.Game.Graphics;
|
2021-10-23 21:01:53 +08:00
|
|
|
using osu.Game.Online;
|
|
|
|
using osu.Game.Overlays;
|
2021-10-23 21:51:36 +08:00
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2021-10-18 03:34:31 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
|
|
|
|
{
|
2021-10-23 21:01:53 +08:00
|
|
|
public class DownloadButton : CompositeDrawable
|
2021-10-18 03:34:31 +08:00
|
|
|
{
|
2021-10-23 21:01:53 +08:00
|
|
|
protected readonly DownloadIcon Download;
|
|
|
|
protected readonly PlayIcon Play;
|
2021-11-13 22:38:04 +08:00
|
|
|
protected readonly Bindable<DownloadState> State = new Bindable<DownloadState>();
|
2021-10-23 21:01:53 +08:00
|
|
|
|
2021-10-23 21:27:04 +08:00
|
|
|
[Resolved]
|
2021-10-23 21:51:36 +08:00
|
|
|
private OsuColour colours { get; set; } = null!;
|
2021-10-23 21:27:04 +08:00
|
|
|
|
|
|
|
[Resolved]
|
2021-10-23 21:51:36 +08:00
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
2021-10-23 21:01:53 +08:00
|
|
|
|
2021-10-18 03:34:31 +08:00
|
|
|
public DownloadButton(APIBeatmapSet beatmapSet)
|
|
|
|
{
|
2021-10-23 21:01:53 +08:00
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
Origin = Anchor.Centre;
|
2021-10-23 21:27:04 +08:00
|
|
|
AutoSizeAxes = Axes.Both;
|
2021-10-23 21:01:53 +08:00
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2021-10-23 21:51:36 +08:00
|
|
|
Download = new DownloadIcon(beatmapSet),
|
|
|
|
Play = new PlayIcon(beatmapSet)
|
2021-10-23 21:01:53 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-11-13 22:38:04 +08:00
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
private void load(BeatmapDownloadTracker? tracker)
|
|
|
|
{
|
|
|
|
if (tracker != null)
|
|
|
|
((IBindable<DownloadState>)State).BindTo(tracker.State);
|
|
|
|
}
|
|
|
|
|
2021-10-23 21:27:04 +08:00
|
|
|
protected override void LoadComplete()
|
2021-10-23 21:01:53 +08:00
|
|
|
{
|
2021-10-23 21:27:04 +08:00
|
|
|
base.LoadComplete();
|
|
|
|
|
2021-11-13 22:38:04 +08:00
|
|
|
State.BindValueChanged(_ => updateState(), true);
|
2021-10-23 21:27:04 +08:00
|
|
|
FinishTransforms(true);
|
2021-10-23 21:01:53 +08:00
|
|
|
}
|
|
|
|
|
2021-10-23 21:27:04 +08:00
|
|
|
private void updateState()
|
2021-10-23 21:01:53 +08:00
|
|
|
{
|
2021-11-13 22:38:04 +08:00
|
|
|
Download.FadeTo(State.Value != DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
Download.Enabled.Value = State.Value == DownloadState.NotDownloaded;
|
2021-10-23 21:27:04 +08:00
|
|
|
|
2021-11-13 22:38:04 +08:00
|
|
|
Play.FadeTo(State.Value == DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
2021-10-23 21:01:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected class DownloadIcon : BeatmapCardIconButton
|
|
|
|
{
|
2021-10-23 21:51:36 +08:00
|
|
|
private readonly APIBeatmapSet beatmapSet;
|
|
|
|
private Bindable<bool> preferNoVideo = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private BeatmapManager beatmaps { get; set; } = null!;
|
|
|
|
|
|
|
|
public DownloadIcon(APIBeatmapSet beatmapSet)
|
2021-10-23 21:01:53 +08:00
|
|
|
{
|
|
|
|
Icon.Icon = FontAwesome.Solid.Download;
|
2021-10-23 21:51:36 +08:00
|
|
|
|
|
|
|
this.beatmapSet = beatmapSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
{
|
|
|
|
preferNoVideo = config.GetBindable<bool>(OsuSetting.PreferNoVideo);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
preferNoVideo.BindValueChanged(_ => updateState(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
{
|
|
|
|
if (beatmapSet.Availability.DownloadDisabled)
|
|
|
|
{
|
|
|
|
Enabled.Value = false;
|
|
|
|
TooltipText = BeatmapsetsStrings.AvailabilityDisabled;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!beatmapSet.HasVideo)
|
|
|
|
TooltipText = BeatmapsetsStrings.PanelDownloadAll;
|
|
|
|
else
|
|
|
|
TooltipText = preferNoVideo.Value ? BeatmapsetsStrings.PanelDownloadNoVideo : BeatmapsetsStrings.PanelDownloadVideo;
|
|
|
|
|
|
|
|
Action = () => beatmaps.Download(beatmapSet, preferNoVideo.Value);
|
2021-10-23 21:01:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected class PlayIcon : BeatmapCardIconButton
|
|
|
|
{
|
2021-10-23 21:51:36 +08:00
|
|
|
private readonly APIBeatmapSet beatmapSet;
|
|
|
|
|
|
|
|
public PlayIcon(APIBeatmapSet beatmapSet)
|
2021-10-23 21:01:53 +08:00
|
|
|
{
|
2021-10-23 21:51:36 +08:00
|
|
|
this.beatmapSet = beatmapSet;
|
|
|
|
|
2021-11-09 15:07:56 +08:00
|
|
|
Icon.Icon = FontAwesome.Solid.AngleDoubleRight;
|
2021-10-23 21:51:36 +08:00
|
|
|
TooltipText = "Go to beatmap";
|
2021-10-23 21:01:53 +08:00
|
|
|
}
|
2021-10-18 03:34:31 +08:00
|
|
|
|
2021-10-23 21:51:36 +08:00
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
private void load(OsuGame? game)
|
|
|
|
{
|
|
|
|
if (game != null)
|
|
|
|
Action = () => game.PresentBeatmap(beatmapSet);
|
|
|
|
}
|
|
|
|
}
|
2021-10-18 03:34:31 +08:00
|
|
|
}
|
|
|
|
}
|