2022-03-28 05:07:52 +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-04-21 05:34:43 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2022-03-28 05:07:52 +08:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2022-04-21 05:34:43 +08:00
|
|
|
using osu.Game.Utils;
|
2022-03-28 05:07:52 +08:00
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Mods
|
|
|
|
{
|
2022-05-11 04:29:57 +08:00
|
|
|
public class UserModSelectOverlay : ModSelectOverlay
|
2022-03-28 05:07:52 +08:00
|
|
|
{
|
2022-05-11 04:29:57 +08:00
|
|
|
public UserModSelectOverlay(OverlayColourScheme colourScheme = OverlayColourScheme.Green)
|
2022-05-05 04:17:40 +08:00
|
|
|
: base(colourScheme)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-28 05:07:52 +08:00
|
|
|
protected override ModColumn CreateModColumn(ModType modType, Key[] toggleKeys = null) => new UserModColumn(modType, false, toggleKeys);
|
|
|
|
|
2022-05-04 03:44:44 +08:00
|
|
|
protected override IReadOnlyList<Mod> ComputeNewModsFromSelection(IReadOnlyList<Mod> oldSelection, IReadOnlyList<Mod> newSelection)
|
2022-04-21 05:34:43 +08:00
|
|
|
{
|
2022-05-04 03:44:44 +08:00
|
|
|
var addedMods = newSelection.Except(oldSelection);
|
|
|
|
var removedMods = oldSelection.Except(newSelection);
|
|
|
|
|
|
|
|
IEnumerable<Mod> modsAfterRemoval = newSelection.Except(removedMods).ToList();
|
2022-04-21 05:34:43 +08:00
|
|
|
|
|
|
|
// the preference is that all new mods should override potential incompatible old mods.
|
|
|
|
// in general that's a bit difficult to compute if more than one mod is added at a time,
|
|
|
|
// so be conservative and just remove all mods that aren't compatible with any one added mod.
|
|
|
|
foreach (var addedMod in addedMods)
|
|
|
|
{
|
|
|
|
if (!ModUtils.CheckCompatibleSet(modsAfterRemoval.Append(addedMod), out var invalidMods))
|
|
|
|
modsAfterRemoval = modsAfterRemoval.Except(invalidMods);
|
|
|
|
|
|
|
|
modsAfterRemoval = modsAfterRemoval.Append(addedMod).ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
return modsAfterRemoval.ToList();
|
|
|
|
}
|
|
|
|
|
2022-03-28 05:07:52 +08:00
|
|
|
private class UserModColumn : ModColumn
|
|
|
|
{
|
|
|
|
public UserModColumn(ModType modType, bool allowBulkSelection, [CanBeNull] Key[] toggleKeys = null)
|
|
|
|
: base(modType, allowBulkSelection, toggleKeys)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override ModPanel CreateModPanel(Mod mod) => new IncompatibilityDisplayingModPanel(mod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|