mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 06:52:56 +08:00
Refactor mod reference management to meet test expectations
This commit is contained in:
parent
fe59f4ae58
commit
7c04bf5c53
@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -10,6 +12,7 @@ using Humanizer;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Colour;
|
using osu.Framework.Graphics.Colour;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -25,8 +28,6 @@ using osuTK;
|
|||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
|
|
||||||
#nullable enable
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Mods
|
namespace osu.Game.Overlays.Mods
|
||||||
{
|
{
|
||||||
public class ModColumn : CompositeDrawable
|
public class ModColumn : CompositeDrawable
|
||||||
@ -256,7 +257,9 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
private void updateMods()
|
private void updateMods()
|
||||||
{
|
{
|
||||||
var newMods = ModUtils.FlattenMods(availableMods.Value.GetValueOrDefault(ModType) ?? Array.Empty<Mod>()).ToList();
|
var newMods = ModUtils.FlattenMods(availableMods.Value.GetValueOrDefault(ModType) ?? Array.Empty<Mod>())
|
||||||
|
.Select(m => m.DeepClone())
|
||||||
|
.ToList();
|
||||||
|
|
||||||
if (newMods.SequenceEqual(panelFlow.Children.Select(p => p.Mod)))
|
if (newMods.SequenceEqual(panelFlow.Children.Select(p => p.Mod)))
|
||||||
return;
|
return;
|
||||||
@ -280,9 +283,16 @@ namespace osu.Game.Overlays.Mods
|
|||||||
panel.Active.BindValueChanged(_ =>
|
panel.Active.BindValueChanged(_ =>
|
||||||
{
|
{
|
||||||
updateToggleAllState();
|
updateToggleAllState();
|
||||||
SelectedMods.Value = panel.Active.Value
|
|
||||||
? SelectedMods.Value.Append(panel.Mod).ToArray()
|
var newSelectedMods = SelectedMods.Value;
|
||||||
: SelectedMods.Value.Except(new[] { panel.Mod }).ToArray();
|
|
||||||
|
var matchingModInstance = SelectedMods.Value.SingleOrDefault(selected => selected.GetType() == panel.Mod.GetType());
|
||||||
|
if (matchingModInstance != null && (matchingModInstance != panel.Mod || !panel.Active.Value))
|
||||||
|
newSelectedMods = newSelectedMods.Except(matchingModInstance.Yield()).ToArray();
|
||||||
|
if (panel.Active.Value)
|
||||||
|
newSelectedMods = newSelectedMods.Append(panel.Mod).ToArray();
|
||||||
|
|
||||||
|
SelectedMods.Value = newSelectedMods.ToArray();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, (cancellationTokenSource = new CancellationTokenSource()).Token);
|
}, (cancellationTokenSource = new CancellationTokenSource()).Token);
|
||||||
@ -296,7 +306,12 @@ namespace osu.Game.Overlays.Mods
|
|||||||
private void updateActiveState()
|
private void updateActiveState()
|
||||||
{
|
{
|
||||||
foreach (var panel in panelFlow)
|
foreach (var panel in panelFlow)
|
||||||
panel.Active.Value = SelectedMods.Value.Any(selected => selected.GetType() == panel.Mod.GetType());
|
{
|
||||||
|
var matchingSelectedMod = SelectedMods.Value.SingleOrDefault(selected => selected.GetType() == panel.Mod.GetType());
|
||||||
|
panel.Active.Value = matchingSelectedMod != null;
|
||||||
|
if (matchingSelectedMod != null)
|
||||||
|
panel.Mod.CopyFrom(matchingSelectedMod);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Bulk select / deselect
|
#region Bulk select / deselect
|
||||||
|
Loading…
Reference in New Issue
Block a user