1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 02:02:53 +08:00

delay mod save after click save or not popover hidden

This commit is contained in:
cdwcgt 2023-03-16 19:38:52 +09:00
parent 42bcc8bafc
commit d025c441ca
2 changed files with 31 additions and 25 deletions

View File

@ -319,6 +319,7 @@ namespace osu.Game.Tests.Visual.UserInterface
{
ModPresetColumn modPresetColumn = null!;
var mods = new Mod[] { new OsuModHidden(), new OsuModHardRock() };
List<Mod> previousMod = null!;
AddStep("clear mods", () => SelectedMods.Value = Array.Empty<Mod>());
AddStep("create content", () => Child = modPresetColumn = new ModPresetColumn
@ -332,6 +333,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("right click first panel", () =>
{
var panel = this.ChildrenOfType<ModPresetPanel>().First();
previousMod = panel.Preset.Value.Mods.ToList();
InputManager.MoveMouseTo(panel);
InputManager.Click(MouseButton.Right);
});
@ -350,10 +352,14 @@ namespace osu.Game.Tests.Visual.UserInterface
InputManager.MoveMouseTo(popover.ChildrenOfType<ShearedButton>().ElementAt(0));
InputManager.Click(MouseButton.Left);
});
AddStep("attempt preset edit", () =>
{
InputManager.MoveMouseTo(popover.ChildrenOfType<ShearedButton>().ElementAt(1));
InputManager.Click(MouseButton.Left);
});
AddWaitStep("wait some", 3);
AddUntilStep("popover not closed", () => this.ChildrenOfType<OsuPopover>().Any());
AddAssert("present mod not changed", () =>
!new HashSet<Mod>(this.ChildrenOfType<ModPresetPanel>().First().Mods.Value).SetEquals(mods));
new HashSet<Mod>(this.ChildrenOfType<ModPresetPanel>().First().Preset.Value.Mods).SetEquals(previousMod));
AddStep("select mods", () => SelectedMods.Value = mods);
AddStep("right click first panel", () =>
@ -377,17 +383,13 @@ namespace osu.Game.Tests.Visual.UserInterface
InputManager.MoveMouseTo(popover.ChildrenOfType<ShearedButton>().ElementAt(0));
InputManager.Click(MouseButton.Left);
});
AddWaitStep("wait some", 3);
AddUntilStep("popover not closed", () => this.ChildrenOfType<OsuPopover>().Any());
AddAssert("present mod is changed", () =>
new HashSet<Mod>(this.ChildrenOfType<ModPresetPanel>().First().Mods.Value).SetEquals(mods));
AddStep("click edit", () =>
AddStep("attempt preset edit", () =>
{
InputManager.MoveMouseTo(popover.ChildrenOfType<ShearedButton>().ElementAt(1));
InputManager.Click(MouseButton.Left);
});
AddAssert("present mod in realm is changed", () =>
AddWaitStep("wait some", 3);
AddAssert("present mod is changed", () =>
new HashSet<Mod>(this.ChildrenOfType<ModPresetPanel>().First().Preset.Value.Mods).SetEquals(mods));
}

View File

@ -130,7 +130,7 @@ namespace osu.Game.Overlays.Mods
private void trySaveCurrentMod()
{
if (!button.CheckCurrentModCanBeSave())
if (!checkCanBeSave())
{
Body.Shake();
return;
@ -139,13 +139,12 @@ namespace osu.Game.Overlays.Mods
saveModAfterClosed = selectedMods.Value.ToList();
scrollContent.Clear();
scrollContent.ChildrenEnumerable = saveModAfterClosed.Select(mod => new ModPresetRow(mod));
button.Mods.Value = saveModAfterClosed;
updateActiveState();
}
private void updateActiveState()
{
if (button.CheckCurrentModCanBeSave())
if (checkCanBeSave())
{
useCurrentModButton.DarkerColour = colours.Blue1;
useCurrentModButton.LighterColour = colours.Blue0;
@ -159,6 +158,19 @@ namespace osu.Game.Overlays.Mods
}
}
private bool checkCanBeSave()
{
if (!selectedMods.Value.Any())
return false;
if (saveModAfterClosed.Any())
{
return !new HashSet<Mod>(saveModAfterClosed).SetEquals(selectedMods.Value);
}
return button.CheckCurrentModCanBeSave();
}
protected override void LoadComplete()
{
base.LoadComplete();
@ -178,22 +190,14 @@ namespace osu.Game.Overlays.Mods
{
s.Name = nameTextBox.Current.Value;
s.Description = descriptionTextBox.Current.Value;
if (saveModAfterClosed.Any())
{
s.Mods = saveModAfterClosed;
}
});
this.HidePopover();
}
protected override void UpdateState(ValueChangedEvent<Visibility> state)
{
base.UpdateState(state);
if (state.NewValue == Visibility.Hidden && saveModAfterClosed.Any())
{
button.Preset.PerformWrite(s =>
{
s.Mods = saveModAfterClosed;
});
}
}
}
}