2022-03-27 21:07:52 +00: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-20 21:34:43 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2022-03-27 21:07:52 +00:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2022-04-20 21:34:43 +00:00
|
|
|
using osu.Game.Utils;
|
2022-03-27 21:07:52 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Mods
|
|
|
|
{
|
2022-05-10 20:29:57 +00:00
|
|
|
public class UserModSelectOverlay : ModSelectOverlay
|
2022-03-27 21:07:52 +00:00
|
|
|
{
|
2022-05-10 20:29:57 +00:00
|
|
|
public UserModSelectOverlay(OverlayColourScheme colourScheme = OverlayColourScheme.Green)
|
2022-05-04 20:17:40 +00:00
|
|
|
: base(colourScheme)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-06-21 10:49:01 +00:00
|
|
|
protected override ModColumn CreateModColumn(ModType modType) => new UserModColumn(modType, false);
|
2022-03-27 21:07:52 +00:00
|
|
|
|
2022-05-03 19:44:44 +00:00
|
|
|
protected override IReadOnlyList<Mod> ComputeNewModsFromSelection(IReadOnlyList<Mod> oldSelection, IReadOnlyList<Mod> newSelection)
|
2022-04-20 21:34:43 +00:00
|
|
|
{
|
2022-05-03 19:44:44 +00:00
|
|
|
var addedMods = newSelection.Except(oldSelection);
|
|
|
|
var removedMods = oldSelection.Except(newSelection);
|
|
|
|
|
|
|
|
IEnumerable<Mod> modsAfterRemoval = newSelection.Except(removedMods).ToList();
|
2022-04-20 21:34:43 +00: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-27 21:07:52 +00:00
|
|
|
private class UserModColumn : ModColumn
|
|
|
|
{
|
2022-06-21 12:48:41 +00:00
|
|
|
public UserModColumn(ModType modType, bool allowIncompatibleSelection)
|
|
|
|
: base(modType, allowIncompatibleSelection)
|
2022-03-27 21:07:52 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-05-11 16:37:31 +00:00
|
|
|
protected override ModPanel CreateModPanel(ModState modState) => new IncompatibilityDisplayingModPanel(modState);
|
2022-03-27 21:07:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|