1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 15:03:13 +08:00

Close #5820 (Ability to delete a single skin)

This commit is contained in:
theangryepicbanana 2022-06-07 18:01:40 -04:00
parent 5b4954aac1
commit 6c05329144
3 changed files with 87 additions and 0 deletions

View File

@ -54,6 +54,11 @@ namespace osu.Game.Localisation
/// </summary>
public static LocalisableString ExportSkinButton => new TranslatableString(getKey(@"export_skin_button"), @"Export selected skin");
/// <summary>
/// "Delete selected skin"
/// </summary>
public static LocalisableString DeleteSkinButton => new TranslatableString(getKey(@"delete_skin_button"), @"Delete selected skin");
private static string getKey(string key) => $"{prefix}:{key}";
}
}

View File

@ -16,6 +16,7 @@ using osu.Game.Configuration;
using osu.Game.Database;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osu.Game.Screens.Select;
using osu.Game.Skinning;
using osu.Game.Skinning.Editor;
using Realms;
@ -67,6 +68,7 @@ namespace osu.Game.Overlays.Settings.Sections
Action = () => skinEditor?.ToggleVisibility(),
},
new ExportSkinButton(),
new DeleteSkinButton(),
};
config.BindWith(OsuSetting.Skin, configBindable);
@ -202,5 +204,37 @@ namespace osu.Game.Overlays.Settings.Sections
}
}
}
public class DeleteSkinButton : DangerousSettingsButton
{
[Resolved]
private SkinManager skins { get; set; }
[Resolved(CanBeNull = true)]
private IDialogOverlay dialogOverlay { get; set; }
private Bindable<Skin> currentSkin;
[BackgroundDependencyLoader]
private void load()
{
Text = SkinSettingsStrings.DeleteSkinButton;
Action = delete;
}
protected override void LoadComplete()
{
base.LoadComplete();
currentSkin = skins.CurrentSkin.GetBoundCopy();
currentSkin.BindValueChanged(skin => Enabled.Value = skin.NewValue.SkinInfo.PerformRead(s => !s.Protected), true);
}
private void delete()
{
if (dialogOverlay != null)
dialogOverlay.Push(new SkinDeleteDialog(currentSkin.Value));
}
}
}
}

View File

@ -0,0 +1,48 @@
// 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;
using osu.Framework.Graphics.Sprites;
using osu.Game.Skinning;
using osu.Game.Overlays.Dialog;
using osu.Game.Database;
namespace osu.Game.Screens.Select
{
public class SkinDeleteDialog : PopupDialog
{
private SkinManager manager;
[BackgroundDependencyLoader]
private void load(SkinManager skinManager)
{
manager = skinManager;
}
public SkinDeleteDialog(Skin skin)
{
skin.SkinInfo.PerformRead(s =>
{
BodyText = s.Name;
Icon = FontAwesome.Regular.TrashAlt;
HeaderText = @"Confirm deletion of";
Buttons = new PopupDialogButton[]
{
new PopupDialogDangerousButton
{
Text = @"Yes. Totally. Delete it.",
Action = () => {
manager.Delete(s);
manager.CurrentSkinInfo.Value = DefaultSkin.CreateInfo().ToLiveUnmanaged();
},
},
new PopupDialogCancelButton
{
Text = @"Firetruck, I didn't mean to!",
},
};
});
}
}
}