Implement mod preset deletion flow

This commit is contained in:
Bartłomiej Dach 2022-07-23 22:03:31 +02:00
parent 26b9adbe0c
commit 9b3183b2b4
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
3 changed files with 53 additions and 4 deletions

View File

@ -11,6 +11,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Framework.Graphics.Cursor;
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays;
@ -35,16 +36,27 @@ namespace osu.Game.Tests.Visual.UserInterface
[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
[Cached(typeof(IDialogOverlay))]
private readonly DialogOverlay dialogOverlay = new DialogOverlay();
[BackgroundDependencyLoader]
private void load()
{
Dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
Dependencies.Cache(Realm);
base.Content.Add(content = new PopoverContainer
base.Content.AddRange(new Drawable[]
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(30),
new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.Both,
Child = content = new PopoverContainer
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(30),
}
},
dialogOverlay
});
}

View File

@ -0,0 +1,18 @@
// 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.Game.Database;
using osu.Game.Overlays.Dialog;
using osu.Game.Rulesets.Mods;
namespace osu.Game.Overlays.Mods
{
public class DeleteModPresetDialog : DeleteConfirmationDialog
{
public DeleteModPresetDialog(Live<ModPreset> modPreset)
{
BodyText = modPreset.PerformRead(preset => preset.Name);
DeleteAction = () => modPreset.PerformWrite(preset => preset.DeletePending = true);
}
}
}

View File

@ -4,18 +4,24 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets.Mods;
namespace osu.Game.Overlays.Mods
{
public class ModPresetPanel : ModSelectPanel, IHasCustomTooltip<ModPreset>
public class ModPresetPanel : ModSelectPanel, IHasCustomTooltip<ModPreset>, IHasContextMenu
{
public readonly Live<ModPreset> Preset;
public override BindableBool Active { get; } = new BindableBool();
[Resolved]
private IDialogOverlay? dialogOverlay { get; set; }
public ModPresetPanel(Live<ModPreset> preset)
{
Preset = preset;
@ -30,7 +36,20 @@ namespace osu.Game.Overlays.Mods
AccentColour = colours.Orange1;
}
#region IHasCustomTooltip
public ModPreset TooltipContent => Preset.Value;
public ITooltip<ModPreset> GetCustomTooltip() => new ModPresetTooltip(ColourProvider);
#endregion
#region IHasContextMenu
public MenuItem[] ContextMenuItems => new MenuItem[]
{
new OsuMenuItem(CommonStrings.ButtonsDelete, MenuItemType.Destructive, () => dialogOverlay?.Push(new DeleteModPresetDialog(Preset)))
};
#endregion
}
}