1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 14:17:27 +08:00
osu-lazer/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanelDownloadButton.cs

100 lines
3.4 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2020-04-12 21:00:05 +08:00
using System;
using osu.Framework.Allocation;
2020-04-13 02:57:35 +08:00
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
2020-04-11 19:08:16 +08:00
using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
2018-07-13 15:28:18 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Overlays.BeatmapListing.Panels
2018-04-13 17:19:50 +08:00
{
public class BeatmapPanelDownloadButton : BeatmapDownloadTrackingComposite
2018-04-13 17:19:50 +08:00
{
2019-06-27 12:38:21 +08:00
protected bool DownloadEnabled => button.Enabled.Value;
/// <summary>
/// Currently selected beatmap. Used to present the correct difficulty after completing a download.
/// </summary>
public readonly IBindable<BeatmapInfo> SelectedBeatmap = new Bindable<BeatmapInfo>();
2020-04-12 21:00:05 +08:00
private readonly ShakeContainer shakeContainer;
private readonly DownloadButton button;
private Bindable<bool> noVideoSetting;
public BeatmapPanelDownloadButton(BeatmapSetInfo beatmapSet)
: base(beatmapSet)
2018-04-13 17:19:50 +08:00
{
InternalChild = shakeContainer = new ShakeContainer
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.Both,
Child = button = new DownloadButton
{
RelativeSizeAxes = Axes.Both,
},
};
}
protected override void LoadComplete()
{
base.LoadComplete();
button.State.BindTo(State);
2018-07-13 20:19:10 +08:00
FinishTransforms(true);
}
[BackgroundDependencyLoader(true)]
2020-04-11 19:08:16 +08:00
private void load(OsuGame game, BeatmapManager beatmaps, OsuConfigManager osuConfig)
{
noVideoSetting = osuConfig.GetBindable<bool>(OsuSetting.PreferNoVideo);
2020-04-13 02:57:35 +08:00
button.Action = () =>
2018-07-17 20:36:33 +08:00
{
switch (State.Value)
2018-07-17 20:36:33 +08:00
{
case DownloadState.Downloading:
case DownloadState.Importing:
shakeContainer.Shake();
2018-07-17 20:36:33 +08:00
break;
2019-04-01 11:44:46 +08:00
case DownloadState.LocallyAvailable:
2020-04-12 21:00:05 +08:00
Predicate<BeatmapInfo> findPredicate = null;
if (SelectedBeatmap.Value != null)
findPredicate = b => b.OnlineBeatmapID == SelectedBeatmap.Value.OnlineBeatmapID;
2020-04-12 21:00:05 +08:00
game?.PresentBeatmap(BeatmapSet.Value, findPredicate);
2018-07-17 20:36:33 +08:00
break;
2019-04-01 11:44:46 +08:00
2018-07-17 20:36:33 +08:00
default:
2020-04-13 02:57:35 +08:00
beatmaps.Download(BeatmapSet.Value, noVideoSetting.Value);
2018-07-17 20:36:33 +08:00
break;
}
};
State.BindValueChanged(state =>
{
switch (state.NewValue)
{
case DownloadState.LocallyAvailable:
button.Enabled.Value = true;
button.TooltipText = "Go to beatmap";
break;
default:
if (BeatmapSet.Value?.OnlineInfo?.Availability?.DownloadDisabled ?? false)
{
button.Enabled.Value = false;
button.TooltipText = "this beatmap is currently not available for download.";
}
break;
}
}, true);
2018-04-13 17:19:50 +08:00
}
}
}