mirror of
https://github.com/ppy/osu
synced 2025-01-05 21:59:46 +00:00
Merge pull request #19613 from bdach/mod-overlay/delete-preset
Add flow for deleting mod presets
This commit is contained in:
commit
c81b3ee9e9
@ -11,9 +11,11 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
|
using osu.Game.Graphics.Cursor;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Graphics.UserInterfaceV2;
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Overlays.Dialog;
|
||||||
using osu.Game.Overlays.Mods;
|
using osu.Game.Overlays.Mods;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Mania.Mods;
|
using osu.Game.Rulesets.Mania.Mods;
|
||||||
@ -35,16 +37,27 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[Cached]
|
[Cached]
|
||||||
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
|
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
|
||||||
|
|
||||||
|
[Cached(typeof(IDialogOverlay))]
|
||||||
|
private readonly DialogOverlay dialogOverlay = new DialogOverlay();
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
Dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
|
Dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
|
||||||
Dependencies.Cache(Realm);
|
Dependencies.Cache(Realm);
|
||||||
|
|
||||||
base.Content.Add(content = new PopoverContainer
|
base.Content.AddRange(new Drawable[]
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
new OsuContextMenuContainer
|
||||||
Padding = new MarginPadding(30),
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Child = content = new PopoverContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Padding = new MarginPadding(30),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dialogOverlay
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,6 +218,46 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
AddUntilStep("popover closed", () => !this.ChildrenOfType<OsuPopover>().Any());
|
AddUntilStep("popover closed", () => !this.ChildrenOfType<OsuPopover>().Any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestDeleteFlow()
|
||||||
|
{
|
||||||
|
ModPresetColumn modPresetColumn = null!;
|
||||||
|
|
||||||
|
AddStep("create content", () => Child = modPresetColumn = new ModPresetColumn
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("items loaded", () => modPresetColumn.IsLoaded && modPresetColumn.ItemsLoaded);
|
||||||
|
AddStep("right click first panel", () =>
|
||||||
|
{
|
||||||
|
var panel = this.ChildrenOfType<ModPresetPanel>().First();
|
||||||
|
InputManager.MoveMouseTo(panel);
|
||||||
|
InputManager.Click(MouseButton.Right);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("wait for context menu", () => this.ChildrenOfType<OsuContextMenu>().Any());
|
||||||
|
AddStep("click delete", () =>
|
||||||
|
{
|
||||||
|
var deleteItem = this.ChildrenOfType<DrawableOsuMenuItem>().Single();
|
||||||
|
InputManager.MoveMouseTo(deleteItem);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("wait for dialog", () => dialogOverlay.CurrentDialog is DeleteModPresetDialog);
|
||||||
|
AddStep("hold confirm", () =>
|
||||||
|
{
|
||||||
|
var confirmButton = this.ChildrenOfType<PopupDialogDangerousButton>().Single();
|
||||||
|
InputManager.MoveMouseTo(confirmButton);
|
||||||
|
InputManager.PressButton(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddUntilStep("wait for dialog to close", () => dialogOverlay.CurrentDialog == null);
|
||||||
|
AddStep("release mouse", () => InputManager.ReleaseButton(MouseButton.Left));
|
||||||
|
AddUntilStep("preset deletion occurred", () => this.ChildrenOfType<ModPresetPanel>().Count() == 2);
|
||||||
|
AddAssert("preset soft-deleted", () => Realm.Run(r => r.All<ModPreset>().Count(preset => preset.DeletePending) == 1));
|
||||||
|
}
|
||||||
|
|
||||||
private ICollection<ModPreset> createTestPresets() => new[]
|
private ICollection<ModPreset> createTestPresets() => new[]
|
||||||
{
|
{
|
||||||
new ModPreset
|
new ModPreset
|
||||||
|
@ -25,6 +25,7 @@ using osu.Game.Configuration;
|
|||||||
using osu.Game.Input.Bindings;
|
using osu.Game.Input.Bindings;
|
||||||
using osu.Game.Models;
|
using osu.Game.Models;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
using Realms;
|
using Realms;
|
||||||
@ -292,6 +293,11 @@ namespace osu.Game.Database
|
|||||||
foreach (var s in pendingDeleteSkins)
|
foreach (var s in pendingDeleteSkins)
|
||||||
realm.Remove(s);
|
realm.Remove(s);
|
||||||
|
|
||||||
|
var pendingDeletePresets = realm.All<ModPreset>().Where(s => s.DeletePending);
|
||||||
|
|
||||||
|
foreach (var s in pendingDeletePresets)
|
||||||
|
realm.Remove(s);
|
||||||
|
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
osu.Game/Overlays/Mods/DeleteModPresetDialog.cs
Normal file
18
osu.Game/Overlays/Mods/DeleteModPresetDialog.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,18 +4,24 @@
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Resources.Localisation.Web;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.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 readonly Live<ModPreset> Preset;
|
||||||
|
|
||||||
public override BindableBool Active { get; } = new BindableBool();
|
public override BindableBool Active { get; } = new BindableBool();
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private IDialogOverlay? dialogOverlay { get; set; }
|
||||||
|
|
||||||
public ModPresetPanel(Live<ModPreset> preset)
|
public ModPresetPanel(Live<ModPreset> preset)
|
||||||
{
|
{
|
||||||
Preset = preset;
|
Preset = preset;
|
||||||
@ -30,7 +36,20 @@ namespace osu.Game.Overlays.Mods
|
|||||||
AccentColour = colours.Orange1;
|
AccentColour = colours.Orange1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region IHasCustomTooltip
|
||||||
|
|
||||||
public ModPreset TooltipContent => Preset.Value;
|
public ModPreset TooltipContent => Preset.Value;
|
||||||
public ITooltip<ModPreset> GetCustomTooltip() => new ModPresetTooltip(ColourProvider);
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user