2022-07-22 04:01:03 +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.
|
|
|
|
|
2022-07-24 05:15:28 +08:00
|
|
|
using System.Collections.Generic;
|
2022-07-24 05:35:56 +08:00
|
|
|
using System.Linq;
|
2022-07-22 04:01:03 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2023-03-07 01:00:40 +08:00
|
|
|
using osu.Framework.Extensions;
|
2022-07-22 04:34:54 +08:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2022-07-24 04:03:31 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2023-05-02 19:15:33 +08:00
|
|
|
using osu.Framework.Localisation;
|
2022-07-24 05:15:28 +08:00
|
|
|
using osu.Game.Configuration;
|
2022-07-24 00:01:11 +08:00
|
|
|
using osu.Game.Database;
|
2022-07-22 04:01:03 +08:00
|
|
|
using osu.Game.Graphics;
|
2022-07-24 04:03:31 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2022-07-22 04:01:03 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Mods
|
|
|
|
{
|
2023-03-16 18:15:50 +08:00
|
|
|
public partial class ModPresetPanel : ModSelectPanel, IHasCustomTooltip<ModPreset>, IHasContextMenu, IHasPopover
|
2022-07-22 04:01:03 +08:00
|
|
|
{
|
2022-07-24 00:01:11 +08:00
|
|
|
public readonly Live<ModPreset> Preset;
|
2022-07-22 04:34:54 +08:00
|
|
|
|
2022-07-22 04:01:03 +08:00
|
|
|
public override BindableBool Active { get; } = new BindableBool();
|
|
|
|
|
2022-07-24 04:03:31 +08:00
|
|
|
[Resolved]
|
|
|
|
private IDialogOverlay? dialogOverlay { get; set; }
|
|
|
|
|
2022-07-24 05:15:28 +08:00
|
|
|
[Resolved]
|
2022-07-24 05:35:56 +08:00
|
|
|
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;
|
2022-07-24 05:15:28 +08:00
|
|
|
|
|
|
|
private ModSettingChangeTracker? settingChangeTracker;
|
|
|
|
|
2022-07-24 00:01:11 +08:00
|
|
|
public ModPresetPanel(Live<ModPreset> preset)
|
2022-07-22 04:01:03 +08:00
|
|
|
{
|
2022-07-22 04:34:54 +08:00
|
|
|
Preset = preset;
|
|
|
|
|
2022-07-24 00:01:11 +08:00
|
|
|
Title = preset.Value.Name;
|
|
|
|
Description = preset.Value.Description;
|
2022-07-22 04:01:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
AccentColour = colours.Orange1;
|
|
|
|
}
|
2022-07-22 04:34:54 +08:00
|
|
|
|
2022-07-24 05:15:28 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
selectedMods.BindValueChanged(_ => selectedModsChanged(), true);
|
|
|
|
}
|
|
|
|
|
2022-08-17 04:41:32 +08:00
|
|
|
protected override void Select()
|
|
|
|
{
|
2023-11-06 15:05:42 +08:00
|
|
|
var selectedSystemMods = selectedMods.Value.Where(mod => mod.Type == ModType.System);
|
|
|
|
// will also have the side effect of activating the preset (see `updateActiveState()`).
|
|
|
|
selectedMods.Value = Preset.Value.Mods.Concat(selectedSystemMods).ToArray();
|
2022-08-17 04:41:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Deselect()
|
2022-07-24 05:35:56 +08:00
|
|
|
{
|
2023-11-06 15:05:42 +08:00
|
|
|
selectedMods.Value = selectedMods.Value.Except(Preset.Value.Mods).ToArray();
|
2022-07-24 05:35:56 +08:00
|
|
|
}
|
|
|
|
|
2022-07-24 05:15:28 +08:00
|
|
|
private void selectedModsChanged()
|
|
|
|
{
|
|
|
|
settingChangeTracker?.Dispose();
|
|
|
|
settingChangeTracker = new ModSettingChangeTracker(selectedMods.Value);
|
|
|
|
settingChangeTracker.SettingChanged = _ => updateActiveState();
|
|
|
|
updateActiveState();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateActiveState()
|
|
|
|
{
|
2023-11-06 15:05:42 +08:00
|
|
|
Active.Value = new HashSet<Mod>(Preset.Value.Mods).SetEquals(selectedMods.Value.Where(mod => mod.Type != ModType.System));
|
2022-07-24 05:15:28 +08:00
|
|
|
}
|
|
|
|
|
2023-05-02 19:15:33 +08:00
|
|
|
#region Filtering support
|
|
|
|
|
2023-05-05 14:52:09 +08:00
|
|
|
public override IEnumerable<LocalisableString> FilterTerms => getFilterTerms();
|
|
|
|
|
|
|
|
private IEnumerable<LocalisableString> getFilterTerms()
|
2023-05-02 19:15:33 +08:00
|
|
|
{
|
2023-06-19 00:06:45 +08:00
|
|
|
var preset = Preset.Value;
|
2023-05-05 14:52:09 +08:00
|
|
|
|
2023-06-19 00:06:45 +08:00
|
|
|
yield return preset.Name;
|
|
|
|
yield return preset.Description;
|
|
|
|
|
|
|
|
foreach (Mod mod in preset.Mods)
|
2023-05-05 14:52:09 +08:00
|
|
|
{
|
|
|
|
yield return mod.Name;
|
|
|
|
yield return mod.Acronym;
|
|
|
|
yield return mod.Description;
|
|
|
|
}
|
|
|
|
}
|
2023-05-02 19:15:33 +08:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2022-07-24 04:03:31 +08:00
|
|
|
#region IHasCustomTooltip
|
|
|
|
|
2022-07-24 00:01:11 +08:00
|
|
|
public ModPreset TooltipContent => Preset.Value;
|
2022-07-22 04:34:54 +08:00
|
|
|
public ITooltip<ModPreset> GetCustomTooltip() => new ModPresetTooltip(ColourProvider);
|
2022-07-24 04:03:31 +08:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region IHasContextMenu
|
|
|
|
|
|
|
|
public MenuItem[] ContextMenuItems => new MenuItem[]
|
|
|
|
{
|
2023-05-03 22:01:31 +08:00
|
|
|
new OsuMenuItem(CommonStrings.ButtonsEdit, MenuItemType.Highlighted, this.ShowPopover),
|
|
|
|
new OsuMenuItem(CommonStrings.ButtonsDelete, MenuItemType.Destructive, () => dialogOverlay?.Push(new DeleteModPresetDialog(Preset))),
|
2022-07-24 04:03:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endregion
|
2022-07-24 05:15:28 +08:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
settingChangeTracker?.Dispose();
|
|
|
|
}
|
2023-03-07 01:00:40 +08:00
|
|
|
|
2023-05-04 10:19:09 +08:00
|
|
|
public Popover GetPopover() => new EditPresetPopover(Preset);
|
2022-07-22 04:01:03 +08:00
|
|
|
}
|
|
|
|
}
|