mirror of https://github.com/ppy/osu
Hoist `ModState` to column level
This commit is contained in:
parent
74599c9c62
commit
e86444c4bf
|
@ -19,6 +19,11 @@ public class IncompatibilityDisplayingModPanel : ModPanel, IHasCustomTooltip<Mod
|
|||
[Resolved]
|
||||
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; }
|
||||
|
||||
public IncompatibilityDisplayingModPanel(ModState modState)
|
||||
: base(modState)
|
||||
{
|
||||
}
|
||||
|
||||
public IncompatibilityDisplayingModPanel(Mod mod)
|
||||
: base(mod)
|
||||
{
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Lists;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
|
@ -83,20 +84,20 @@ public Func<Mod, bool>? Filter
|
|||
|
||||
protected override bool ReceivePositionalInputAtSubTree(Vector2 screenSpacePos) => base.ReceivePositionalInputAtSubTree(screenSpacePos) && Active.Value;
|
||||
|
||||
protected virtual ModPanel CreateModPanel(Mod mod) => new ModPanel(mod);
|
||||
protected virtual ModPanel CreateModPanel(ModState mod) => new ModPanel(mod);
|
||||
|
||||
private readonly Key[]? toggleKeys;
|
||||
|
||||
private readonly Bindable<Dictionary<ModType, IReadOnlyList<Mod>>> availableMods = new Bindable<Dictionary<ModType, IReadOnlyList<Mod>>>();
|
||||
|
||||
/// <summary>
|
||||
/// All mods that are available for the current ruleset in this particular column.
|
||||
/// Contains information about state of all mods that are available for the current ruleset in this particular column.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Note that the mod instances in this list are owned solely by this column
|
||||
/// (as in, they are locally-managed clones, to ensure proper isolation from any other external instances).
|
||||
/// </remarks>
|
||||
private IReadOnlyList<Mod> localAvailableMods = Array.Empty<Mod>();
|
||||
private IReadOnlyList<ModState> localAvailableMods = Array.Empty<ModState>();
|
||||
|
||||
private readonly TextFlowContainer headerText;
|
||||
private readonly Box headerBackground;
|
||||
|
@ -291,10 +292,10 @@ private void updateToggleAllText()
|
|||
private void updateLocalAvailableMods(bool asyncLoadContent)
|
||||
{
|
||||
var newMods = ModUtils.FlattenMods(availableMods.Value.GetValueOrDefault(ModType) ?? Array.Empty<Mod>())
|
||||
.Select(m => m.DeepClone())
|
||||
.Select(m => new ModState(m.DeepClone()))
|
||||
.ToList();
|
||||
|
||||
if (newMods.SequenceEqual(localAvailableMods))
|
||||
if (newMods.SequenceEqual(localAvailableMods, new FuncEqualityComparer<ModState>((x, y) => ReferenceEquals(x.Mod, y.Mod))))
|
||||
return;
|
||||
|
||||
localAvailableMods = newMods;
|
||||
|
@ -393,18 +394,18 @@ internal void SetSelection(IReadOnlyList<Mod> mods)
|
|||
|
||||
var newSelection = new List<Mod>();
|
||||
|
||||
foreach (var mod in localAvailableMods)
|
||||
foreach (var modState in localAvailableMods)
|
||||
{
|
||||
var matchingSelectedMod = mods.SingleOrDefault(selected => selected.GetType() == mod.GetType());
|
||||
var matchingSelectedMod = mods.SingleOrDefault(selected => selected.GetType() == modState.GetType());
|
||||
|
||||
if (matchingSelectedMod != null)
|
||||
{
|
||||
mod.CopyFrom(matchingSelectedMod);
|
||||
newSelection.Add(mod);
|
||||
modState.Mod.CopyFrom(matchingSelectedMod);
|
||||
newSelection.Add(modState.Mod);
|
||||
}
|
||||
else
|
||||
{
|
||||
mod.ResetSettingsToDefaults();
|
||||
modState.Mod.ResetSettingsToDefaults();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,9 +57,9 @@ public class ModPanel : OsuClickableContainer
|
|||
private Sample? sampleOff;
|
||||
private Sample? sampleOn;
|
||||
|
||||
public ModPanel(Mod mod)
|
||||
public ModPanel(ModState modState)
|
||||
{
|
||||
modState = new ModState(mod);
|
||||
this.modState = modState;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = 42;
|
||||
|
@ -81,7 +81,7 @@ public ModPanel(Mod mod)
|
|||
SwitchContainer = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Child = new ModSwitchSmall(mod)
|
||||
Child = new ModSwitchSmall(Mod)
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
|
@ -117,7 +117,7 @@ public ModPanel(Mod mod)
|
|||
{
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = mod.Name,
|
||||
Text = Mod.Name,
|
||||
Font = OsuFont.TorusAlternate.With(size: 18, weight: FontWeight.SemiBold),
|
||||
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
|
||||
Margin = new MarginPadding
|
||||
|
@ -127,7 +127,7 @@ public ModPanel(Mod mod)
|
|||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = mod.Description,
|
||||
Text = Mod.Description,
|
||||
Font = OsuFont.Default.With(size: 12),
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Truncate = true,
|
||||
|
@ -143,6 +143,11 @@ public ModPanel(Mod mod)
|
|||
Action = Active.Toggle;
|
||||
}
|
||||
|
||||
public ModPanel(Mod mod)
|
||||
: this(new ModState(mod))
|
||||
{
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(AudioManager audio, OsuColour colours, ISamplePlaybackDisabler? samplePlaybackDisabler)
|
||||
{
|
||||
|
|
|
@ -47,7 +47,7 @@ public UserModColumn(ModType modType, bool allowBulkSelection, [CanBeNull] Key[]
|
|||
{
|
||||
}
|
||||
|
||||
protected override ModPanel CreateModPanel(Mod mod) => new IncompatibilityDisplayingModPanel(mod);
|
||||
protected override ModPanel CreateModPanel(ModState modState) => new IncompatibilityDisplayingModPanel(modState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue