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 JetBrains.Annotations;
|
|
|
|
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
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Mods
|
|
|
|
{
|
|
|
|
public class UserModSelectScreen : ModSelectScreen
|
|
|
|
{
|
2022-05-04 20:17:40 +00:00
|
|
|
public UserModSelectScreen(OverlayColourScheme colourScheme = OverlayColourScheme.Green)
|
|
|
|
: base(colourScheme)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-27 21:07:52 +00:00
|
|
|
protected override ModColumn CreateModColumn(ModType modType, Key[] toggleKeys = null) => new UserModColumn(modType, false, toggleKeys);
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
public UserModColumn(ModType modType, bool allowBulkSelection, [CanBeNull] Key[] toggleKeys = null)
|
|
|
|
: base(modType, allowBulkSelection, toggleKeys)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override ModPanel CreateModPanel(Mod mod) => new IncompatibilityDisplayingModPanel(mod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|