1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-07 18:47:26 +08:00

Merge pull request #22747 from mk56-spn/make_skin_reset_dangerous

Make reverting a skin in the skin editor a dangerous action
This commit is contained in:
Bartłomiej Dach 2023-03-07 21:42:01 +01:00 committed by GitHub
commit 942feb5550
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 50 additions and 26 deletions

View File

@ -8,12 +8,12 @@ using osu.Game.Overlays.Dialog;
namespace osu.Game.Collections
{
public partial class DeleteCollectionDialog : DeleteConfirmationDialog
public partial class DeleteCollectionDialog : DangerousActionDialog
{
public DeleteCollectionDialog(Live<BeatmapCollection> collection, Action deleteAction)
{
BodyText = collection.PerformRead(c => $"{c.Name} ({"beatmap".ToQuantity(c.BeatmapMD5Hashes.Count)})");
DeleteAction = deleteAction;
DangerousAction = deleteAction;
}
}
}

View File

@ -42,7 +42,12 @@ namespace osu.Game.Localisation
/// <summary>
/// "Currently editing"
/// </summary>
public static LocalisableString CurrentlyEditing => new TranslatableString(getKey(@"currently_editing"), "Currently editing");
public static LocalisableString CurrentlyEditing => new TranslatableString(getKey(@"currently_editing"), @"Currently editing");
/// <summary>
/// "All layout elements for layers in the current screen will be reset to defaults."
/// </summary>
public static LocalisableString RevertToDefaultDescription => new TranslatableString(getKey(@"revert_to_default_description"), @"All layout elements for layers in the current screen will be reset to defaults.");
private static string getKey(string key) => $@"{prefix}:{key}";
}

View File

@ -8,18 +8,22 @@ using osu.Game.Localisation;
namespace osu.Game.Overlays.Dialog
{
/// <summary>
/// Base class for various confirmation dialogs that concern deletion actions.
/// A dialog which provides confirmation for actions which result in permanent consequences.
/// Differs from <see cref="ConfirmDialog"/> in that the confirmation button is a "dangerous" one
/// (requires the confirm button to be held).
/// </summary>
public abstract partial class DeleteConfirmationDialog : PopupDialog
/// <remarks>
/// The default implementation comes with text for a generic deletion operation.
/// This can be further customised by specifying custom <see cref="PopupDialog.HeaderText"/>.
/// </remarks>
public abstract partial class DangerousActionDialog : PopupDialog
{
/// <summary>
/// The action which performs the deletion.
/// </summary>
protected Action? DeleteAction { get; set; }
protected Action? DangerousAction { get; set; }
protected DeleteConfirmationDialog()
protected DangerousActionDialog()
{
HeaderText = DeleteConfirmationDialogStrings.HeaderText;
@ -30,7 +34,7 @@ namespace osu.Game.Overlays.Dialog
new PopupDialogDangerousButton
{
Text = DeleteConfirmationDialogStrings.Confirm,
Action = () => DeleteAction?.Invoke()
Action = () => DangerousAction?.Invoke()
},
new PopupDialogCancelButton
{

View File

@ -7,12 +7,12 @@ using osu.Game.Rulesets.Mods;
namespace osu.Game.Overlays.Mods
{
public partial class DeleteModPresetDialog : DeleteConfirmationDialog
public partial class DeleteModPresetDialog : DangerousActionDialog
{
public DeleteModPresetDialog(Live<ModPreset> modPreset)
{
BodyText = modPreset.PerformRead(preset => preset.Name);
DeleteAction = () => modPreset.PerformWrite(preset => preset.DeletePending = true);
DangerousAction = () => modPreset.PerformWrite(preset => preset.DeletePending = true);
}
}
}

View File

@ -6,12 +6,12 @@ using osu.Game.Overlays.Dialog;
namespace osu.Game.Overlays.Settings.Sections.Maintenance
{
public partial class MassDeleteConfirmationDialog : DeleteConfirmationDialog
public partial class MassDeleteConfirmationDialog : DangerousActionDialog
{
public MassDeleteConfirmationDialog(Action deleteAction)
{
BodyText = "Everything?";
DeleteAction = deleteAction;
DangerousAction = deleteAction;
}
}
}

View File

@ -17,6 +17,7 @@ using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using Web = osu.Game.Resources.Localisation.Web;
using osu.Framework.Testing;
using osu.Game.Database;
using osu.Game.Graphics;
@ -24,6 +25,7 @@ using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osu.Game.Overlays.Dialog;
using osu.Game.Overlays.OSD;
using osu.Game.Overlays.Settings;
using osu.Game.Screens.Edit;
@ -97,6 +99,9 @@ namespace osu.Game.Overlays.SkinEditor
[Resolved]
private OnScreenDisplay? onScreenDisplay { get; set; }
[Resolved]
private IDialogOverlay? dialogOverlay { get; set; }
public SkinEditor()
{
}
@ -147,8 +152,8 @@ namespace osu.Game.Overlays.SkinEditor
{
Items = new[]
{
new EditorMenuItem(Resources.Localisation.Web.CommonStrings.ButtonsSave, MenuItemType.Standard, () => Save()),
new EditorMenuItem(CommonStrings.RevertToDefault, MenuItemType.Destructive, revert),
new EditorMenuItem(Web.CommonStrings.ButtonsSave, MenuItemType.Standard, () => Save()),
new EditorMenuItem(CommonStrings.RevertToDefault, MenuItemType.Destructive, () => dialogOverlay?.Push(new RevertConfirmDialog(revert))),
new EditorMenuItemSpacer(),
new EditorMenuItem(CommonStrings.Exit, MenuItemType.Standard, () => skinEditorOverlay?.Hide()),
},
@ -670,6 +675,16 @@ namespace osu.Game.Overlays.SkinEditor
}
}
public partial class RevertConfirmDialog : DangerousActionDialog
{
public RevertConfirmDialog(Action revert)
{
HeaderText = CommonStrings.RevertToDefault;
BodyText = SkinEditorStrings.RevertToDefaultDescription;
DangerousAction = revert;
}
}
#region Delegation of IEditorChangeHandler
public event Action? OnStateChange

View File

@ -7,12 +7,12 @@ using osu.Game.Overlays.Dialog;
namespace osu.Game.Screens.Edit
{
public partial class DeleteDifficultyConfirmationDialog : DeleteConfirmationDialog
public partial class DeleteDifficultyConfirmationDialog : DangerousActionDialog
{
public DeleteDifficultyConfirmationDialog(BeatmapInfo beatmapInfo, Action deleteAction)
{
BodyText = $"\"{beatmapInfo.DifficultyName}\" difficulty";
DeleteAction = deleteAction;
DangerousAction = deleteAction;
}
}
}

View File

@ -10,7 +10,7 @@ using osu.Game.Scoring;
namespace osu.Game.Screens.Select
{
public partial class BeatmapClearScoresDialog : DeleteConfirmationDialog
public partial class BeatmapClearScoresDialog : DangerousActionDialog
{
[Resolved]
private ScoreManager scoreManager { get; set; } = null!;
@ -18,7 +18,7 @@ namespace osu.Game.Screens.Select
public BeatmapClearScoresDialog(BeatmapInfo beatmapInfo, Action onCompletion)
{
BodyText = $"All local scores on {beatmapInfo.GetDisplayTitle()}";
DeleteAction = () =>
DangerousAction = () =>
{
Task.Run(() => scoreManager.Delete(beatmapInfo))
.ContinueWith(_ => onCompletion);

View File

@ -7,7 +7,7 @@ using osu.Game.Overlays.Dialog;
namespace osu.Game.Screens.Select
{
public partial class BeatmapDeleteDialog : DeleteConfirmationDialog
public partial class BeatmapDeleteDialog : DangerousActionDialog
{
private readonly BeatmapSetInfo beatmapSet;
@ -20,7 +20,7 @@ namespace osu.Game.Screens.Select
[BackgroundDependencyLoader]
private void load(BeatmapManager beatmapManager)
{
DeleteAction = () => beatmapManager.Delete(beatmapSet);
DangerousAction = () => beatmapManager.Delete(beatmapSet);
}
}
}

View File

@ -8,14 +8,14 @@ using osu.Game.Localisation;
namespace osu.Game.Screens.Select.Carousel
{
public partial class UpdateLocalConfirmationDialog : DeleteConfirmationDialog
public partial class UpdateLocalConfirmationDialog : DangerousActionDialog
{
public UpdateLocalConfirmationDialog(Action onConfirm)
{
HeaderText = PopupDialogStrings.UpdateLocallyModifiedText;
BodyText = PopupDialogStrings.UpdateLocallyModifiedDescription;
Icon = FontAwesome.Solid.ExclamationTriangle;
DeleteAction = onConfirm;
DangerousAction = onConfirm;
}
}
}

View File

@ -10,7 +10,7 @@ using osu.Game.Beatmaps;
namespace osu.Game.Screens.Select
{
public partial class LocalScoreDeleteDialog : DeleteConfirmationDialog
public partial class LocalScoreDeleteDialog : DangerousActionDialog
{
private readonly ScoreInfo score;
@ -28,7 +28,7 @@ namespace osu.Game.Screens.Select
BodyText = $"{score.User} ({score.DisplayAccuracy}, {score.Rank})";
Icon = FontAwesome.Regular.TrashAlt;
DeleteAction = () => scoreManager.Delete(score);
DangerousAction = () => scoreManager.Delete(score);
}
}
}

View File

@ -7,7 +7,7 @@ using osu.Game.Overlays.Dialog;
namespace osu.Game.Screens.Select
{
public partial class SkinDeleteDialog : DeleteConfirmationDialog
public partial class SkinDeleteDialog : DangerousActionDialog
{
private readonly Skin skin;
@ -20,7 +20,7 @@ namespace osu.Game.Screens.Select
[BackgroundDependencyLoader]
private void load(SkinManager manager)
{
DeleteAction = () =>
DangerousAction = () =>
{
manager.Delete(skin.SkinInfo.Value);
manager.CurrentSkinInfo.SetDefault();