mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 04:13:00 +08:00
Added ability to edit mod presets
This commit is contained in:
parent
778cde8932
commit
4858d3fd42
@ -243,7 +243,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
AddUntilStep("wait for context menu", () => this.ChildrenOfType<OsuContextMenu>().Any());
|
AddUntilStep("wait for context menu", () => this.ChildrenOfType<OsuContextMenu>().Any());
|
||||||
AddStep("click delete", () =>
|
AddStep("click delete", () =>
|
||||||
{
|
{
|
||||||
var deleteItem = this.ChildrenOfType<DrawableOsuMenuItem>().Single();
|
var deleteItem = this.ChildrenOfType<DrawableOsuMenuItem>().ElementAt(1);
|
||||||
InputManager.MoveMouseTo(deleteItem);
|
InputManager.MoveMouseTo(deleteItem);
|
||||||
InputManager.Click(MouseButton.Left);
|
InputManager.Click(MouseButton.Left);
|
||||||
});
|
});
|
||||||
@ -261,6 +261,175 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
AddAssert("preset soft-deleted", () => Realm.Run(r => r.All<ModPreset>().Count(preset => preset.DeletePending) == 1));
|
AddAssert("preset soft-deleted", () => Realm.Run(r => r.All<ModPreset>().Count(preset => preset.DeletePending) == 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestEditPresentName()
|
||||||
|
{
|
||||||
|
ModPresetColumn modPresetColumn = null!;
|
||||||
|
string presetName = null!;
|
||||||
|
|
||||||
|
AddStep("clear mods", () => SelectedMods.Value = Array.Empty<Mod>());
|
||||||
|
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();
|
||||||
|
presetName = panel.Preset.Value.Name;
|
||||||
|
InputManager.MoveMouseTo(panel);
|
||||||
|
InputManager.Click(MouseButton.Right);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("wait for context menu", () => this.ChildrenOfType<OsuContextMenu>().Any());
|
||||||
|
AddStep("click edit", () =>
|
||||||
|
{
|
||||||
|
var editItem = this.ChildrenOfType<DrawableOsuMenuItem>().ElementAt(0);
|
||||||
|
InputManager.MoveMouseTo(editItem);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
OsuPopover? popover = null;
|
||||||
|
AddUntilStep("wait for popover", () => (popover = this.ChildrenOfType<OsuPopover>().FirstOrDefault()) != null);
|
||||||
|
AddStep("clear preset name", () => popover.ChildrenOfType<LabelledTextBox>().First().Current.Value = "");
|
||||||
|
AddStep("attempt preset edit", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(popover.ChildrenOfType<ShearedButton>().Single());
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddWaitStep("wait some", 3);
|
||||||
|
AddAssert("present is not changed", () => this.ChildrenOfType<ModPresetPanel>().First().Preset.Value.Name == presetName);
|
||||||
|
AddUntilStep("popover is unchanged", () => this.ChildrenOfType<OsuPopover>().FirstOrDefault() == popover);
|
||||||
|
AddStep("edit preset name", () => popover.ChildrenOfType<LabelledTextBox>().First().Current.Value = "something new");
|
||||||
|
AddStep("attempt preset edit", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(popover.ChildrenOfType<ShearedButton>().Single());
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddUntilStep("popover closed", () => !this.ChildrenOfType<OsuPopover>().Any());
|
||||||
|
AddAssert("present is changed", () => this.ChildrenOfType<ModPresetPanel>().First().Preset.Value.Name != presetName);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestEditPresetMod()
|
||||||
|
{
|
||||||
|
ModPresetColumn modPresetColumn = null!;
|
||||||
|
var mods = new Mod[] { new OsuModHidden(), new OsuModHardRock() };
|
||||||
|
|
||||||
|
AddStep("clear mods", () => SelectedMods.Value = Array.Empty<Mod>());
|
||||||
|
AddStep("create content", () => Child = modPresetColumn = new ModPresetColumn
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("items loaded", () => modPresetColumn.IsLoaded && modPresetColumn.ItemsLoaded);
|
||||||
|
AddStep("select mods", () => SelectedMods.Value = mods);
|
||||||
|
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 edit", () =>
|
||||||
|
{
|
||||||
|
var editItem = this.ChildrenOfType<DrawableOsuMenuItem>().ElementAt(0);
|
||||||
|
InputManager.MoveMouseTo(editItem);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
OsuPopover? popover = null;
|
||||||
|
AddUntilStep("wait for popover", () => (popover = this.ChildrenOfType<OsuPopover>().FirstOrDefault()) != null);
|
||||||
|
AddStep("enable switch", () => popover.ChildrenOfType<LabelledSwitchButton>().Single().Current.Value = true);
|
||||||
|
AddStep("attempt preset edit", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(popover.ChildrenOfType<ShearedButton>().Single());
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddUntilStep("popover closed", () => !this.ChildrenOfType<OsuPopover>().Any());
|
||||||
|
AddAssert("present mod is changed", () => this.ChildrenOfType<ModPresetPanel>().First().Preset.Value.Mods.Count == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestEditModSwitchDisableWithNoModSelest()
|
||||||
|
{
|
||||||
|
ModPresetColumn modPresetColumn = null!;
|
||||||
|
|
||||||
|
AddStep("clear mods", () => SelectedMods.Value = Array.Empty<Mod>());
|
||||||
|
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 edit", () =>
|
||||||
|
{
|
||||||
|
var editItem = this.ChildrenOfType<DrawableOsuMenuItem>().ElementAt(0);
|
||||||
|
InputManager.MoveMouseTo(editItem);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
OsuPopover? popover = null;
|
||||||
|
AddUntilStep("wait for popover", () => (popover = this.ChildrenOfType<OsuPopover>().FirstOrDefault()) != null);
|
||||||
|
AddAssert("use current mod is disblaed", () => popover.ChildrenOfType<LabelledSwitchButton>().Single().Current.Value == false);
|
||||||
|
AddAssert("use current mod switch cannot be switch", () => popover.ChildrenOfType<LabelledSwitchButton>().Single().Current.Disabled == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestEditModSwitchDisableWithPresetSelest()
|
||||||
|
{
|
||||||
|
ModPresetColumn modPresetColumn = null!;
|
||||||
|
|
||||||
|
AddStep("clear mods", () => SelectedMods.Value = Array.Empty<Mod>());
|
||||||
|
AddStep("create content", () => Child = modPresetColumn = new ModPresetColumn
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("items loaded", () => modPresetColumn.IsLoaded && modPresetColumn.ItemsLoaded);
|
||||||
|
AddStep("select first preset mod", () =>
|
||||||
|
SelectedMods.Value = this.ChildrenOfType<ModPresetPanel>().First().Preset.Value.Mods.ToList());
|
||||||
|
|
||||||
|
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 edit", () =>
|
||||||
|
{
|
||||||
|
var editItem = this.ChildrenOfType<DrawableOsuMenuItem>().ElementAt(0);
|
||||||
|
InputManager.MoveMouseTo(editItem);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
OsuPopover? popover = null;
|
||||||
|
AddUntilStep("wait for popover", () => (popover = this.ChildrenOfType<OsuPopover>().FirstOrDefault()) != null);
|
||||||
|
AddAssert("use current mod is enabled", () => popover.ChildrenOfType<LabelledSwitchButton>().Single().Current.Value == true);
|
||||||
|
AddAssert("use current mod switch cannot be switch", () => popover.ChildrenOfType<LabelledSwitchButton>().Single().Current.Disabled == true);
|
||||||
|
|
||||||
|
AddStep("clear mods", () => SelectedMods.Value = Array.Empty<Mod>());
|
||||||
|
AddAssert("use current mod is disblaed", () => popover.ChildrenOfType<LabelledSwitchButton>().Single().Current.Value == false);
|
||||||
|
AddAssert("use current mod switch cannot be switch", () => popover.ChildrenOfType<LabelledSwitchButton>().Single().Current.Disabled == true);
|
||||||
|
}
|
||||||
|
|
||||||
private ICollection<ModPreset> createTestPresets() => new[]
|
private ICollection<ModPreset> createTestPresets() => new[]
|
||||||
{
|
{
|
||||||
new ModPreset
|
new ModPreset
|
||||||
|
140
osu.Game/Overlays/Mods/EditPresetPopover.cs
Normal file
140
osu.Game/Overlays/Mods/EditPresetPopover.cs
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
// 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.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Extensions;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
|
using osu.Game.Localisation;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Mods
|
||||||
|
{
|
||||||
|
internal partial class EditPresetPopover : OsuPopover
|
||||||
|
{
|
||||||
|
private readonly ModPresetPanel button;
|
||||||
|
|
||||||
|
private readonly LabelledTextBox nameTextBox;
|
||||||
|
private readonly LabelledTextBox descriptionTextBox;
|
||||||
|
private readonly LabelledSwitchButton useCurrentSwitch;
|
||||||
|
private readonly ShearedButton createButton;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;
|
||||||
|
|
||||||
|
private readonly ModPreset preset;
|
||||||
|
|
||||||
|
public EditPresetPopover(ModPresetPanel modPresetPanel)
|
||||||
|
{
|
||||||
|
button = modPresetPanel;
|
||||||
|
preset = button.Preset.Value;
|
||||||
|
|
||||||
|
Child = new FillFlowContainer
|
||||||
|
{
|
||||||
|
Width = 300,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Spacing = new Vector2(7),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
nameTextBox = new LabelledTextBox
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Label = CommonStrings.Name,
|
||||||
|
TabbableContentContainer = this
|
||||||
|
},
|
||||||
|
descriptionTextBox = new LabelledTextBox
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Label = CommonStrings.Description,
|
||||||
|
TabbableContentContainer = this
|
||||||
|
},
|
||||||
|
useCurrentSwitch = new LabelledSwitchButton
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Label = "Use Current Mod select",
|
||||||
|
},
|
||||||
|
createButton = new ShearedButton
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Text = CommonStrings.MenuBarEdit,
|
||||||
|
Action = tryEditPreset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OverlayColourProvider colourProvider, OsuColour colours)
|
||||||
|
{
|
||||||
|
Body.BorderThickness = 3;
|
||||||
|
Body.BorderColour = colours.Orange1;
|
||||||
|
|
||||||
|
nameTextBox.Current.Value = preset.Name;
|
||||||
|
descriptionTextBox.Current.Value = preset.Description;
|
||||||
|
|
||||||
|
selectedMods.BindValueChanged(_ => updateMods(), true);
|
||||||
|
|
||||||
|
createButton.DarkerColour = colours.Orange1;
|
||||||
|
createButton.LighterColour = colours.Orange0;
|
||||||
|
createButton.TextColour = colourProvider.Background6;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateMods()
|
||||||
|
{
|
||||||
|
useCurrentSwitch.Current.Disabled = false;
|
||||||
|
|
||||||
|
// disable the switch when mod is equal.
|
||||||
|
if (button.Active.Value)
|
||||||
|
{
|
||||||
|
useCurrentSwitch.Current.Value = true;
|
||||||
|
useCurrentSwitch.Current.Disabled = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
useCurrentSwitch.Current.Value = false;
|
||||||
|
useCurrentSwitch.Current.Disabled = !selectedMods.Value.Any();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
ScheduleAfterChildren(() => GetContainingInputManager().ChangeFocus(nameTextBox));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tryEditPreset()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(nameTextBox.Current.Value))
|
||||||
|
{
|
||||||
|
Body.Shake();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.Preset.PerformWrite(s =>
|
||||||
|
{
|
||||||
|
s.Name = nameTextBox.Current.Value;
|
||||||
|
s.Description = descriptionTextBox.Current.Value;
|
||||||
|
|
||||||
|
if (useCurrentSwitch.Current.Value)
|
||||||
|
{
|
||||||
|
s.Mods = selectedMods.Value.ToArray();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.HidePopover();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
@ -17,7 +18,7 @@ using osu.Game.Rulesets.Mods;
|
|||||||
|
|
||||||
namespace osu.Game.Overlays.Mods
|
namespace osu.Game.Overlays.Mods
|
||||||
{
|
{
|
||||||
public partial class ModPresetPanel : ModSelectPanel, IHasCustomTooltip<ModPreset>, IHasContextMenu
|
public partial class ModPresetPanel : ModSelectPanel, IHasCustomTooltip<ModPreset>, IHasContextMenu, IHasPopover
|
||||||
{
|
{
|
||||||
public readonly Live<ModPreset> Preset;
|
public readonly Live<ModPreset> Preset;
|
||||||
|
|
||||||
@ -91,7 +92,8 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
public MenuItem[] ContextMenuItems => new MenuItem[]
|
public MenuItem[] ContextMenuItems => new MenuItem[]
|
||||||
{
|
{
|
||||||
new OsuMenuItem(CommonStrings.ButtonsDelete, MenuItemType.Destructive, () => dialogOverlay?.Push(new DeleteModPresetDialog(Preset)))
|
new OsuMenuItem(CommonStrings.ButtonsEdit, MenuItemType.Highlighted, this.ShowPopover),
|
||||||
|
new OsuMenuItem(CommonStrings.ButtonsDelete, MenuItemType.Destructive, () => dialogOverlay?.Push(new DeleteModPresetDialog(Preset))),
|
||||||
};
|
};
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -102,5 +104,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
settingChangeTracker?.Dispose();
|
settingChangeTracker?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Popover GetPopover() => new EditPresetPopover(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user