scorll container and save mod after popover hidden

Requires manual handling of many visual effects
This commit is contained in:
cdwcgt 2023-03-11 12:31:33 +09:00
parent 1cd565193e
commit 15f11bb1e8
4 changed files with 95 additions and 18 deletions

View File

@ -353,7 +353,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddWaitStep("wait some", 3); AddWaitStep("wait some", 3);
AddUntilStep("popover not closed", () => this.ChildrenOfType<OsuPopover>().Any()); AddUntilStep("popover not closed", () => this.ChildrenOfType<OsuPopover>().Any());
AddAssert("present mod not changed", () => AddAssert("present mod not changed", () =>
!new HashSet<Mod>(this.ChildrenOfType<ModPresetPanel>().First().Preset.Value.Mods).SetEquals(mods)); !new HashSet<Mod>(this.ChildrenOfType<ModPresetPanel>().First().Mods.Value).SetEquals(mods));
AddStep("select mods", () => SelectedMods.Value = mods); AddStep("select mods", () => SelectedMods.Value = mods);
AddStep("right click first panel", () => AddStep("right click first panel", () =>
@ -378,8 +378,16 @@ namespace osu.Game.Tests.Visual.UserInterface
InputManager.Click(MouseButton.Left); InputManager.Click(MouseButton.Left);
}); });
AddWaitStep("wait some", 3); AddWaitStep("wait some", 3);
AddUntilStep("popover closed", () => !this.ChildrenOfType<OsuPopover>().Any()); AddUntilStep("popover not closed", () => this.ChildrenOfType<OsuPopover>().Any());
AddAssert("present mod is changed", () => AddAssert("present mod is changed", () =>
new HashSet<Mod>(this.ChildrenOfType<ModPresetPanel>().First().Mods.Value).SetEquals(mods));
AddStep("click edit", () =>
{
InputManager.MoveMouseTo(popover.ChildrenOfType<ShearedButton>().ElementAt(1));
InputManager.Click(MouseButton.Left);
});
AddAssert("present mod in realm is changed", () =>
new HashSet<Mod>(this.ChildrenOfType<ModPresetPanel>().First().Preset.Value.Mods).SetEquals(mods)); new HashSet<Mod>(this.ChildrenOfType<ModPresetPanel>().First().Preset.Value.Mods).SetEquals(mods));
} }

View File

@ -1,12 +1,16 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // 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.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Extensions; using osu.Game.Extensions;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Localisation; using osu.Game.Localisation;
@ -23,8 +27,19 @@ namespace osu.Game.Overlays.Mods
private readonly LabelledTextBox descriptionTextBox; private readonly LabelledTextBox descriptionTextBox;
private readonly ShearedButton useCurrentModButton; private readonly ShearedButton useCurrentModButton;
private readonly ShearedButton createButton; private readonly ShearedButton createButton;
private readonly FillFlowContainer scrollContent;
private readonly ModPreset preset; private readonly ModPreset preset;
private List<Mod> saveModAfterClosed = new List<Mod>();
[Resolved]
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;
[Resolved]
private OsuColour colours { get; set; } = null!;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
public EditPresetPopover(ModPresetPanel modPresetPanel) public EditPresetPopover(ModPresetPanel modPresetPanel)
{ {
@ -53,6 +68,19 @@ namespace osu.Game.Overlays.Mods
Label = CommonStrings.Description, Label = CommonStrings.Description,
TabbableContentContainer = this TabbableContentContainer = this
}, },
new OsuScrollContainer
{
RelativeSizeAxes = Axes.X,
Height = 100,
Padding = new MarginPadding(7),
Child = scrollContent = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding(7),
Spacing = new Vector2(7),
}
},
new FillFlowContainer new FillFlowContainer
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
@ -83,7 +111,7 @@ namespace osu.Game.Overlays.Mods
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider, OsuColour colours) private void load()
{ {
Body.BorderThickness = 3; Body.BorderThickness = 3;
Body.BorderColour = colours.Orange1; Body.BorderColour = colours.Orange1;
@ -95,17 +123,40 @@ namespace osu.Game.Overlays.Mods
createButton.LighterColour = colours.Orange0; createButton.LighterColour = colours.Orange0;
createButton.TextColour = colourProvider.Background6; createButton.TextColour = colourProvider.Background6;
useCurrentModButton.DarkerColour = colours.Blue1; selectedMods.BindValueChanged(_ => updateActiveState(), true);
useCurrentModButton.LighterColour = colours.Blue0;
useCurrentModButton.TextColour = colourProvider.Background6; scrollContent.ChildrenEnumerable = preset.Mods.Select(mod => new ModPresetRow(mod));
} }
private void trySaveCurrentMod() private void trySaveCurrentMod()
{ {
if (button.SaveCurrentMod()) if (!button.CheckCurrentModCanBeSave())
{
Body.Shake();
return; return;
}
Body.Shake(); 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())
{
useCurrentModButton.DarkerColour = colours.Blue1;
useCurrentModButton.LighterColour = colours.Blue0;
useCurrentModButton.TextColour = colourProvider.Background6;
}
else
{
useCurrentModButton.DarkerColour = colours.Blue3;
useCurrentModButton.LighterColour = colours.Blue4;
useCurrentModButton.TextColour = colourProvider.Background2;
}
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -131,5 +182,18 @@ namespace osu.Game.Overlays.Mods
this.HidePopover(); 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;
});
}
}
} }
} }

View File

@ -18,10 +18,12 @@ using osu.Game.Rulesets.Mods;
namespace osu.Game.Overlays.Mods namespace osu.Game.Overlays.Mods
{ {
public partial class ModPresetPanel : ModSelectPanel, IHasCustomTooltip<ModPreset>, IHasContextMenu, IHasPopover public partial class ModPresetPanel : ModSelectPanel, IHasCustomTooltip<List<Mod>>, IHasContextMenu, IHasPopover
{ {
public readonly Live<ModPreset> Preset; public readonly Live<ModPreset> Preset;
public readonly Bindable<List<Mod>> Mods = new Bindable<List<Mod>>();
public override BindableBool Active { get; } = new BindableBool(); public override BindableBool Active { get; } = new BindableBool();
[Resolved] [Resolved]
@ -35,6 +37,7 @@ namespace osu.Game.Overlays.Mods
public ModPresetPanel(Live<ModPreset> preset) public ModPresetPanel(Live<ModPreset> preset)
{ {
Preset = preset; Preset = preset;
Mods.Value = preset.Value.Mods.ToList();
Title = preset.Value.Name; Title = preset.Value.Name;
Description = preset.Value.Description; Description = preset.Value.Description;
@ -51,6 +54,7 @@ namespace osu.Game.Overlays.Mods
base.LoadComplete(); base.LoadComplete();
selectedMods.BindValueChanged(_ => selectedModsChanged(), true); selectedMods.BindValueChanged(_ => selectedModsChanged(), true);
Mods.BindValueChanged(_ => updateActiveState(), true);
} }
protected override void Select() protected override void Select()
@ -78,13 +82,13 @@ namespace osu.Game.Overlays.Mods
private void updateActiveState() private void updateActiveState()
{ {
Active.Value = new HashSet<Mod>(Preset.Value.Mods).SetEquals(selectedMods.Value); Active.Value = new HashSet<Mod>(Mods.Value).SetEquals(selectedMods.Value);
} }
#region IHasCustomTooltip #region IHasCustomTooltip
public ModPreset TooltipContent => Preset.Value; public List<Mod> TooltipContent => Mods.Value;
public ITooltip<ModPreset> GetCustomTooltip() => new ModPresetTooltip(ColourProvider); public ITooltip<List<Mod>> GetCustomTooltip() => new ModPresetTooltip(ColourProvider);
#endregion #endregion

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -11,7 +12,7 @@ using osuTK;
namespace osu.Game.Overlays.Mods namespace osu.Game.Overlays.Mods
{ {
public partial class ModPresetTooltip : VisibilityContainer, ITooltip<ModPreset> public partial class ModPresetTooltip : VisibilityContainer, ITooltip<List<Mod>>
{ {
protected override Container<Drawable> Content { get; } protected override Container<Drawable> Content { get; }
@ -42,15 +43,15 @@ namespace osu.Game.Overlays.Mods
}; };
} }
private ModPreset? lastPreset; private List<Mod>? lastPreset;
public void SetContent(ModPreset preset) public void SetContent(List<Mod> mods)
{ {
if (ReferenceEquals(preset, lastPreset)) if (ReferenceEquals(mods, lastPreset))
return; return;
lastPreset = preset; lastPreset = mods;
Content.ChildrenEnumerable = preset.Mods.Select(mod => new ModPresetRow(mod)); Content.ChildrenEnumerable = mods.Select(mod => new ModPresetRow(mod));
} }
protected override void PopIn() => this.FadeIn(transition_duration, Easing.OutQuint); protected override void PopIn() => this.FadeIn(transition_duration, Easing.OutQuint);