2023-03-07 01:00:40 +08:00
|
|
|
|
// 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.
|
|
|
|
|
|
2023-03-11 11:31:33 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2023-03-07 01:00:40 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2023-03-11 11:31:33 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2023-03-07 01:00:40 +08:00
|
|
|
|
using osu.Framework.Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics;
|
2023-03-11 11:31:33 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2023-03-07 01:00:40 +08:00
|
|
|
|
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
|
|
|
|
|
{
|
2023-05-04 10:14:51 +08:00
|
|
|
|
private readonly ModPresetPanel presetPanel;
|
2023-03-07 01:00:40 +08:00
|
|
|
|
|
2023-05-04 10:14:51 +08:00
|
|
|
|
private LabelledTextBox nameTextBox = null!;
|
|
|
|
|
private LabelledTextBox descriptionTextBox = null!;
|
|
|
|
|
private ShearedButton useCurrentModsButton = null!;
|
|
|
|
|
private ShearedButton saveButton = null!;
|
|
|
|
|
private FillFlowContainer scrollContent = null!;
|
2023-03-07 01:00:40 +08:00
|
|
|
|
|
|
|
|
|
private readonly ModPreset preset;
|
2023-05-04 10:07:09 +08:00
|
|
|
|
|
|
|
|
|
private HashSet<Mod>? newMods;
|
2023-03-11 11:31:33 +08:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuColour colours { get; set; } = null!;
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
2023-03-07 01:00:40 +08:00
|
|
|
|
|
2023-05-04 10:14:51 +08:00
|
|
|
|
public EditPresetPopover(ModPresetPanel presetPanel)
|
2023-03-07 01:00:40 +08:00
|
|
|
|
{
|
2023-05-04 10:14:51 +08:00
|
|
|
|
this.presetPanel = presetPanel;
|
|
|
|
|
preset = presetPanel.Preset.Value;
|
|
|
|
|
}
|
2023-03-07 01:00:40 +08:00
|
|
|
|
|
2023-05-04 10:14:51 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2023-03-07 01:00:40 +08:00
|
|
|
|
Child = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Width = 300,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Spacing = new Vector2(7),
|
2023-03-07 20:13:35 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
2023-03-07 01:00:40 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
nameTextBox = new LabelledTextBox
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Label = CommonStrings.Name,
|
2023-05-04 10:14:51 +08:00
|
|
|
|
TabbableContentContainer = this,
|
|
|
|
|
Current = { Value = preset.Name },
|
2023-03-07 01:00:40 +08:00
|
|
|
|
},
|
|
|
|
|
descriptionTextBox = new LabelledTextBox
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Label = CommonStrings.Description,
|
2023-05-04 10:14:51 +08:00
|
|
|
|
TabbableContentContainer = this,
|
|
|
|
|
Current = { Value = preset.Description },
|
2023-03-07 01:00:40 +08:00
|
|
|
|
},
|
2023-03-11 11:31:33 +08:00
|
|
|
|
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),
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-03-07 20:13:35 +08:00
|
|
|
|
new FillFlowContainer
|
2023-03-07 01:00:40 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2023-03-07 20:13:35 +08:00
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Spacing = new Vector2(7),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2023-05-04 10:10:05 +08:00
|
|
|
|
useCurrentModsButton = new ShearedButton
|
2023-03-07 20:13:35 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2023-05-04 10:11:19 +08:00
|
|
|
|
Text = ModSelectOverlayStrings.UseCurrentMods,
|
2023-05-04 10:14:51 +08:00
|
|
|
|
DarkerColour = colours.Blue1,
|
|
|
|
|
LighterColour = colours.Blue0,
|
|
|
|
|
TextColour = colourProvider.Background6,
|
|
|
|
|
Action = useCurrentMods,
|
2023-03-07 20:13:35 +08:00
|
|
|
|
},
|
2023-05-04 10:10:05 +08:00
|
|
|
|
saveButton = new ShearedButton
|
2023-03-07 20:13:35 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Text = Resources.Localisation.Web.CommonStrings.ButtonsSave,
|
2023-05-04 10:14:51 +08:00
|
|
|
|
DarkerColour = colours.Orange1,
|
|
|
|
|
LighterColour = colours.Orange0,
|
|
|
|
|
TextColour = colourProvider.Background6,
|
|
|
|
|
Action = save,
|
2023-03-07 20:13:35 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
2023-03-07 01:00:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Body.BorderThickness = 3;
|
|
|
|
|
Body.BorderColour = colours.Orange1;
|
|
|
|
|
|
2023-03-11 11:31:33 +08:00
|
|
|
|
selectedMods.BindValueChanged(_ => updateActiveState(), true);
|
2023-05-03 22:22:46 +08:00
|
|
|
|
nameTextBox.Current.BindValueChanged(s =>
|
|
|
|
|
{
|
2023-05-04 10:10:05 +08:00
|
|
|
|
saveButton.Enabled.Value = !string.IsNullOrWhiteSpace(s.NewValue);
|
2023-05-03 22:22:46 +08:00
|
|
|
|
}, true);
|
2023-03-07 01:00:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 10:10:05 +08:00
|
|
|
|
private void useCurrentMods()
|
2023-03-07 01:00:40 +08:00
|
|
|
|
{
|
2023-05-04 10:07:09 +08:00
|
|
|
|
newMods = selectedMods.Value.ToHashSet();
|
2023-03-11 11:31:33 +08:00
|
|
|
|
scrollContent.Clear();
|
|
|
|
|
updateActiveState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateActiveState()
|
|
|
|
|
{
|
2023-05-03 22:24:14 +08:00
|
|
|
|
scrollContent.ChildrenEnumerable = preset.Mods.Select(mod => new ModPresetRow(mod));
|
2023-05-04 10:10:05 +08:00
|
|
|
|
useCurrentModsButton.Enabled.Value = checkSelectedModsDiffersFromSaved();
|
2023-03-07 01:00:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 10:07:09 +08:00
|
|
|
|
private bool checkSelectedModsDiffersFromSaved()
|
2023-03-16 18:38:52 +08:00
|
|
|
|
{
|
|
|
|
|
if (!selectedMods.Value.Any())
|
|
|
|
|
return false;
|
|
|
|
|
|
2023-05-04 10:07:09 +08:00
|
|
|
|
if (newMods?.SetEquals(selectedMods.Value) == false)
|
|
|
|
|
return true;
|
2023-03-16 18:38:52 +08:00
|
|
|
|
|
2023-05-04 10:14:51 +08:00
|
|
|
|
return presetPanel.CheckCurrentModCanBeSave();
|
2023-03-16 18:38:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-07 01:00:40 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
ScheduleAfterChildren(() => GetContainingInputManager().ChangeFocus(nameTextBox));
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 10:10:05 +08:00
|
|
|
|
private void save()
|
2023-03-07 01:00:40 +08:00
|
|
|
|
{
|
2023-05-04 10:14:51 +08:00
|
|
|
|
presetPanel.Preset.PerformWrite(s =>
|
2023-03-07 01:00:40 +08:00
|
|
|
|
{
|
|
|
|
|
s.Name = nameTextBox.Current.Value;
|
|
|
|
|
s.Description = descriptionTextBox.Current.Value;
|
|
|
|
|
|
2023-05-04 10:07:09 +08:00
|
|
|
|
if (newMods != null)
|
|
|
|
|
s.Mods = newMods;
|
2023-03-16 18:38:52 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.HidePopover();
|
2023-03-11 11:31:33 +08:00
|
|
|
|
}
|
2023-03-07 01:00:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|