Add confirmation dialog for updating locally modified beatmaps

This commit is contained in:
Salman Ahmed 2022-10-13 02:39:37 +03:00
parent 3da54814f8
commit 964ed01abb
3 changed files with 76 additions and 11 deletions

View File

@ -0,0 +1,24 @@
// 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.Localisation;
namespace osu.Game.Localisation
{
public static class PopupDialogStrings
{
private const string prefix = @"osu.Game.Resources.Localisation.PopupDialog";
/// <summary>
/// "Are you sure you want to update this beatmap?"
/// </summary>
public static LocalisableString UpdateLocallyModifiedText => new TranslatableString(getKey(@"update_locally_modified_text"), @"Are you sure you want to update this beatmap?");
/// <summary>
/// "This will discard all local changes you have on that beatmap."
/// </summary>
public static LocalisableString UpdateLocallyModifiedDescription => new TranslatableString(getKey(@"update_locally_modified_description"), @"This will discard all local changes you have on that beatmap.");
private static string getKey(string key) => $@"{prefix}:{key}";
}
}

View File

@ -32,9 +32,12 @@ public class UpdateBeatmapSetButton : OsuAnimatedButton
[Resolved]
private IAPIProvider api { get; set; } = null!;
[Resolved(canBeNull: true)]
[Resolved]
private LoginOverlay? loginOverlay { get; set; }
[Resolved]
private IDialogOverlay? dialogOverlay { get; set; }
public UpdateBeatmapSetButton(BeatmapSetInfo beatmapSetInfo)
{
this.beatmapSetInfo = beatmapSetInfo;
@ -102,17 +105,34 @@ private void load(OsuConfigManager config)
},
});
Action = () =>
{
if (!api.IsLoggedIn)
{
loginOverlay?.Show();
return;
}
Action = updateBeatmap;
}
beatmapDownloader.DownloadAsUpdate(beatmapSetInfo, preferNoVideo.Value);
attachExistingDownload();
};
private bool updateConfirmed;
private void updateBeatmap()
{
if (!api.IsLoggedIn)
{
loginOverlay?.Show();
return;
}
if (dialogOverlay != null && beatmapSetInfo.Status == BeatmapOnlineStatus.LocallyModified && !updateConfirmed)
{
dialogOverlay.Push(new UpdateLocalConfirmationDialog(() =>
{
updateConfirmed = true;
updateBeatmap();
}));
return;
}
updateConfirmed = false;
beatmapDownloader.DownloadAsUpdate(beatmapSetInfo, preferNoVideo.Value);
attachExistingDownload();
}
protected override void LoadComplete()

View File

@ -0,0 +1,21 @@
// 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 System;
using osu.Framework.Graphics.Sprites;
using osu.Game.Overlays.Dialog;
using osu.Game.Localisation;
namespace osu.Game.Screens.Select.Carousel
{
public class UpdateLocalConfirmationDialog : DeleteConfirmationDialog
{
public UpdateLocalConfirmationDialog(Action onConfirm)
{
HeaderText = PopupDialogStrings.UpdateLocallyModifiedText;
BodyText = PopupDialogStrings.UpdateLocallyModifiedDescription;
Icon = FontAwesome.Solid.ExclamationTriangle;
DeleteAction = onConfirm;
}
}
}