2022-07-18 17:06: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.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2022-10-11 10:29:17 +08:00
|
|
|
using osu.Framework.Bindables;
|
2022-07-18 17:06:11 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-07-19 17:16:30 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2022-07-18 17:06:11 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Beatmaps;
|
2022-10-11 10:29:17 +08:00
|
|
|
using osu.Game.Configuration;
|
2022-07-18 17:06:11 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-09-12 15:15:14 +08:00
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Overlays;
|
2022-07-18 17:06:11 +08:00
|
|
|
using osuTK;
|
2022-07-19 17:16:30 +08:00
|
|
|
using osuTK.Graphics;
|
2022-07-18 17:06:11 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
|
|
|
{
|
2022-07-19 17:16:30 +08:00
|
|
|
public partial class UpdateBeatmapSetButton : OsuAnimatedButton
|
2022-07-18 17:06:11 +08:00
|
|
|
{
|
|
|
|
private readonly BeatmapSetInfo beatmapSetInfo;
|
2022-07-20 14:16:40 +08:00
|
|
|
private SpriteIcon icon = null!;
|
|
|
|
private Box progressFill = null!;
|
2022-07-19 17:16:30 +08:00
|
|
|
|
2022-09-12 15:15:14 +08:00
|
|
|
[Resolved]
|
|
|
|
private BeatmapModelDownloader beatmapDownloader { get; set; } = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; } = null!;
|
|
|
|
|
2022-10-13 07:39:37 +08:00
|
|
|
[Resolved]
|
2022-09-12 15:15:14 +08:00
|
|
|
private LoginOverlay? loginOverlay { get; set; }
|
|
|
|
|
2022-10-13 07:39:37 +08:00
|
|
|
[Resolved]
|
|
|
|
private IDialogOverlay? dialogOverlay { get; set; }
|
|
|
|
|
2022-07-19 17:16:30 +08:00
|
|
|
public UpdateBeatmapSetButton(BeatmapSetInfo beatmapSetInfo)
|
2022-07-18 17:06:11 +08:00
|
|
|
{
|
|
|
|
this.beatmapSetInfo = beatmapSetInfo;
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
Anchor = Anchor.CentreLeft;
|
|
|
|
Origin = Anchor.CentreLeft;
|
|
|
|
}
|
|
|
|
|
2022-10-11 10:29:17 +08:00
|
|
|
private Bindable<bool> preferNoVideo = null!;
|
|
|
|
|
2022-07-18 17:06:11 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2022-10-11 10:29:17 +08:00
|
|
|
private void load(OsuConfigManager config)
|
2022-07-18 17:06:11 +08:00
|
|
|
{
|
|
|
|
const float icon_size = 14;
|
|
|
|
|
2022-10-11 10:29:17 +08:00
|
|
|
preferNoVideo = config.GetBindable<bool>(OsuSetting.PreferNoVideo);
|
|
|
|
|
2022-07-18 17:06:11 +08:00
|
|
|
Content.Anchor = Anchor.CentreLeft;
|
|
|
|
Content.Origin = Anchor.CentreLeft;
|
|
|
|
|
|
|
|
Content.AddRange(new Drawable[]
|
|
|
|
{
|
2022-07-19 17:16:30 +08:00
|
|
|
progressFill = new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.White,
|
|
|
|
Alpha = 0.2f,
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Width = 0,
|
|
|
|
},
|
2022-07-18 17:06:11 +08:00
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Padding = new MarginPadding { Horizontal = 5, Vertical = 3 },
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(4),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Size = new Vector2(icon_size),
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
icon = new SpriteIcon
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Icon = FontAwesome.Solid.SyncAlt,
|
|
|
|
Size = new Vector2(icon_size),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Font = OsuFont.Default.With(weight: FontWeight.Bold),
|
|
|
|
Text = "Update",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-10-13 07:39:37 +08:00
|
|
|
Action = updateBeatmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool updateConfirmed;
|
|
|
|
|
|
|
|
private void updateBeatmap()
|
|
|
|
{
|
|
|
|
if (!api.IsLoggedIn)
|
|
|
|
{
|
|
|
|
loginOverlay?.Show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dialogOverlay != null && beatmapSetInfo.Status == BeatmapOnlineStatus.LocallyModified && !updateConfirmed)
|
2022-07-19 17:16:30 +08:00
|
|
|
{
|
2022-10-13 07:39:37 +08:00
|
|
|
dialogOverlay.Push(new UpdateLocalConfirmationDialog(() =>
|
2022-09-12 15:15:14 +08:00
|
|
|
{
|
2022-10-13 07:39:37 +08:00
|
|
|
updateConfirmed = true;
|
|
|
|
updateBeatmap();
|
|
|
|
}));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateConfirmed = false;
|
2022-09-12 15:15:14 +08:00
|
|
|
|
2022-10-13 07:39:37 +08:00
|
|
|
beatmapDownloader.DownloadAsUpdate(beatmapSetInfo, preferNoVideo.Value);
|
|
|
|
attachExistingDownload();
|
2022-07-18 17:06:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
icon.Spin(4000, RotationDirection.Clockwise);
|
|
|
|
}
|
|
|
|
|
2022-07-19 17:16:30 +08:00
|
|
|
private void attachExistingDownload()
|
|
|
|
{
|
|
|
|
var download = beatmapDownloader.GetExistingDownload(beatmapSetInfo);
|
|
|
|
|
|
|
|
if (download != null)
|
|
|
|
{
|
|
|
|
Enabled.Value = false;
|
|
|
|
TooltipText = string.Empty;
|
|
|
|
|
2022-07-19 18:01:23 +08:00
|
|
|
download.DownloadProgressed += progress => progressFill.ResizeWidthTo(progress, 100, Easing.OutQuint);
|
|
|
|
download.Failure += _ => attachExistingDownload();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Enabled.Value = true;
|
|
|
|
TooltipText = "Update beatmap with online changes";
|
|
|
|
|
|
|
|
progressFill.ResizeWidthTo(0, 100, Easing.OutQuint);
|
2022-07-19 17:16:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-18 17:06:11 +08:00
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
icon.Spin(400, RotationDirection.Clockwise);
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
icon.Spin(4000, RotationDirection.Clockwise);
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|