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 osu.Game.Rulesets.Mods;
|
2022-04-21 05:34:43 +08:00
|
|
|
using osu.Game.Utils;
|
2022-03-28 05:07:52 +08:00
|
|
|
|
|
|
|
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-06-21 18:49:01 +08:00
|
|
|
protected override ModColumn CreateModColumn(ModType modType) => new UserModColumn(modType, false);
|
2022-03-28 05:07:52 +08:00
|
|
|
|
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
|
|
|
|
{
|
2022-06-21 20:48:41 +08:00
|
|
|
public UserModColumn(ModType modType, bool allowIncompatibleSelection)
|
|
|
|
: base(modType, allowIncompatibleSelection)
|
2022-03-28 05:07:52 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-05-12 00:37:31 +08:00
|
|
|
protected override ModPanel CreateModPanel(ModState modState) => new IncompatibilityDisplayingModPanel(modState);
|
2022-03-28 05:07:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|