1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 10:57:27 +08:00
osu-lazer/osu.Game/Beatmaps/Drawables/Cards/Buttons/DownloadButton.cs

69 lines
2.3 KiB
C#
Raw Normal View History

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.
#nullable enable
2021-10-23 21:01:53 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2021-10-23 21:01:53 +08:00
using osu.Framework.Graphics;
2021-10-18 03:34:31 +08:00
using osu.Framework.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Configuration;
2021-10-23 21:01:53 +08:00
using osu.Game.Online;
using osu.Game.Resources.Localisation.Web;
2021-10-18 03:34:31 +08:00
namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
{
public class DownloadButton : BeatmapCardIconButton
2021-10-18 03:34:31 +08:00
{
private readonly APIBeatmapSet beatmapSet;
2021-11-19 05:50:41 +08:00
private readonly Bindable<DownloadState> downloadState = new Bindable<DownloadState>();
private Bindable<bool> preferNoVideo = null!;
2021-10-23 21:01:53 +08:00
[Resolved]
private BeatmapManager beatmaps { get; set; } = null!;
2021-10-23 21:01:53 +08:00
2021-10-18 03:34:31 +08:00
public DownloadButton(APIBeatmapSet beatmapSet)
{
Icon.Icon = FontAwesome.Solid.Download;
2021-10-23 21:01:53 +08:00
this.beatmapSet = beatmapSet;
2021-10-23 21:01:53 +08:00
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, BeatmapDownloadTracker downloadTracker)
{
preferNoVideo = config.GetBindable<bool>(OsuSetting.PreferNoVideo);
((IBindable<DownloadState>)downloadState).BindTo(downloadTracker.State);
}
protected override void LoadComplete()
2021-10-23 21:01:53 +08:00
{
base.LoadComplete();
preferNoVideo.BindValueChanged(_ => updateState());
downloadState.BindValueChanged(_ => updateState(), true);
FinishTransforms(true);
2021-10-23 21:01:53 +08:00
}
private void updateState()
2021-10-23 21:01:53 +08:00
{
this.FadeTo(downloadState.Value != DownloadState.LocallyAvailable ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
if (beatmapSet.Availability.DownloadDisabled)
2021-10-23 21:01:53 +08:00
{
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-18 03:34:31 +08:00
}
}