1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 06:42:54 +08:00

Hoist ModState to column level

This commit is contained in:
Bartłomiej Dach 2022-05-11 18:37:31 +02:00
parent 74599c9c62
commit e86444c4bf
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
4 changed files with 27 additions and 16 deletions

View File

@ -19,6 +19,11 @@ namespace osu.Game.Overlays.Mods
[Resolved] [Resolved]
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; }
public IncompatibilityDisplayingModPanel(ModState modState)
: base(modState)
{
}
public IncompatibilityDisplayingModPanel(Mod mod) public IncompatibilityDisplayingModPanel(Mod mod)
: base(mod) : base(mod)
{ {

View File

@ -20,6 +20,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Lists;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -83,20 +84,20 @@ namespace osu.Game.Overlays.Mods
protected override bool ReceivePositionalInputAtSubTree(Vector2 screenSpacePos) => base.ReceivePositionalInputAtSubTree(screenSpacePos) && Active.Value; 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 Key[]? toggleKeys;
private readonly Bindable<Dictionary<ModType, IReadOnlyList<Mod>>> availableMods = new Bindable<Dictionary<ModType, IReadOnlyList<Mod>>>(); private readonly Bindable<Dictionary<ModType, IReadOnlyList<Mod>>> availableMods = new Bindable<Dictionary<ModType, IReadOnlyList<Mod>>>();
/// <summary> /// <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> /// </summary>
/// <remarks> /// <remarks>
/// Note that the mod instances in this list are owned solely by this column /// 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). /// (as in, they are locally-managed clones, to ensure proper isolation from any other external instances).
/// </remarks> /// </remarks>
private IReadOnlyList<Mod> localAvailableMods = Array.Empty<Mod>(); private IReadOnlyList<ModState> localAvailableMods = Array.Empty<ModState>();
private readonly TextFlowContainer headerText; private readonly TextFlowContainer headerText;
private readonly Box headerBackground; private readonly Box headerBackground;
@ -291,10 +292,10 @@ namespace osu.Game.Overlays.Mods
private void updateLocalAvailableMods(bool asyncLoadContent) private void updateLocalAvailableMods(bool asyncLoadContent)
{ {
var newMods = ModUtils.FlattenMods(availableMods.Value.GetValueOrDefault(ModType) ?? Array.Empty<Mod>()) var newMods = ModUtils.FlattenMods(availableMods.Value.GetValueOrDefault(ModType) ?? Array.Empty<Mod>())
.Select(m => m.DeepClone()) .Select(m => new ModState(m.DeepClone()))
.ToList(); .ToList();
if (newMods.SequenceEqual(localAvailableMods)) if (newMods.SequenceEqual(localAvailableMods, new FuncEqualityComparer<ModState>((x, y) => ReferenceEquals(x.Mod, y.Mod))))
return; return;
localAvailableMods = newMods; localAvailableMods = newMods;
@ -393,18 +394,18 @@ namespace osu.Game.Overlays.Mods
var newSelection = new List<Mod>(); 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) if (matchingSelectedMod != null)
{ {
mod.CopyFrom(matchingSelectedMod); modState.Mod.CopyFrom(matchingSelectedMod);
newSelection.Add(mod); newSelection.Add(modState.Mod);
} }
else else
{ {
mod.ResetSettingsToDefaults(); modState.Mod.ResetSettingsToDefaults();
} }
} }

View File

@ -57,9 +57,9 @@ namespace osu.Game.Overlays.Mods
private Sample? sampleOff; private Sample? sampleOff;
private Sample? sampleOn; private Sample? sampleOn;
public ModPanel(Mod mod) public ModPanel(ModState modState)
{ {
modState = new ModState(mod); this.modState = modState;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
Height = 42; Height = 42;
@ -81,7 +81,7 @@ namespace osu.Game.Overlays.Mods
SwitchContainer = new Container SwitchContainer = new Container
{ {
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
Child = new ModSwitchSmall(mod) Child = new ModSwitchSmall(Mod)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -117,7 +117,7 @@ namespace osu.Game.Overlays.Mods
{ {
new OsuSpriteText new OsuSpriteText
{ {
Text = mod.Name, Text = Mod.Name,
Font = OsuFont.TorusAlternate.With(size: 18, weight: FontWeight.SemiBold), Font = OsuFont.TorusAlternate.With(size: 18, weight: FontWeight.SemiBold),
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0), Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
Margin = new MarginPadding Margin = new MarginPadding
@ -127,7 +127,7 @@ namespace osu.Game.Overlays.Mods
}, },
new OsuSpriteText new OsuSpriteText
{ {
Text = mod.Description, Text = Mod.Description,
Font = OsuFont.Default.With(size: 12), Font = OsuFont.Default.With(size: 12),
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Truncate = true, Truncate = true,
@ -143,6 +143,11 @@ namespace osu.Game.Overlays.Mods
Action = Active.Toggle; Action = Active.Toggle;
} }
public ModPanel(Mod mod)
: this(new ModState(mod))
{
}
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(AudioManager audio, OsuColour colours, ISamplePlaybackDisabler? samplePlaybackDisabler) private void load(AudioManager audio, OsuColour colours, ISamplePlaybackDisabler? samplePlaybackDisabler)
{ {

View File

@ -47,7 +47,7 @@ namespace osu.Game.Overlays.Mods
{ {
} }
protected override ModPanel CreateModPanel(Mod mod) => new IncompatibilityDisplayingModPanel(mod); protected override ModPanel CreateModPanel(ModState modState) => new IncompatibilityDisplayingModPanel(modState);
} }
} }
} }