mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Refactor mod panel selection logic to avoid overwriting
This commit is contained in:
@ -37,8 +37,6 @@ namespace osu.Game.Overlays.Mods
|
|||||||
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
|
Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0),
|
||||||
Scale = new Vector2(HEIGHT / ModSwitchSmall.DEFAULT_SIZE)
|
Scale = new Vector2(HEIGHT / ModSwitchSmall.DEFAULT_SIZE)
|
||||||
};
|
};
|
||||||
|
|
||||||
Action = select;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ModPanel(Mod mod)
|
public ModPanel(Mod mod)
|
||||||
@ -59,18 +57,16 @@ namespace osu.Game.Overlays.Mods
|
|||||||
Filtered.BindValueChanged(_ => updateFilterState(), true);
|
Filtered.BindValueChanged(_ => updateFilterState(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void select()
|
protected override void Select()
|
||||||
{
|
{
|
||||||
if (!Active.Value)
|
modState.RequiresConfiguration = Mod.RequiresConfiguration;
|
||||||
{
|
Active.Value = true;
|
||||||
modState.RequiresConfiguration = Mod.RequiresConfiguration;
|
}
|
||||||
Active.Value = true;
|
|
||||||
}
|
protected override void Deselect()
|
||||||
else
|
{
|
||||||
{
|
modState.RequiresConfiguration = false;
|
||||||
modState.RequiresConfiguration = false;
|
Active.Value = false;
|
||||||
Active.Value = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Filtering support
|
#region Filtering support
|
||||||
|
@ -37,8 +37,6 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
Title = preset.Value.Name;
|
Title = preset.Value.Name;
|
||||||
Description = preset.Value.Description;
|
Description = preset.Value.Description;
|
||||||
|
|
||||||
Action = toggleRequestedByUser;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -54,15 +52,19 @@ namespace osu.Game.Overlays.Mods
|
|||||||
selectedMods.BindValueChanged(_ => selectedModsChanged(), true);
|
selectedMods.BindValueChanged(_ => selectedModsChanged(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleRequestedByUser()
|
protected override void Select()
|
||||||
|
{
|
||||||
|
// if the preset is not active at the point of the user click, then set the mods using the preset directly, discarding any previous selections,
|
||||||
|
// which will also have the side effect of activating the preset (see `updateActiveState()`).
|
||||||
|
selectedMods.Value = Preset.Value.Mods.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Deselect()
|
||||||
{
|
{
|
||||||
// if the preset is not active at the point of the user click, then set the mods using the preset directly, discarding any previous selections.
|
|
||||||
// if the preset is active when the user has clicked it, then it means that the set of active mods is exactly equal to the set of mods in the preset
|
// if the preset is active when the user has clicked it, then it means that the set of active mods is exactly equal to the set of mods in the preset
|
||||||
// (there are no other active mods than what the preset specifies, and the mod settings match exactly).
|
// (there are no other active mods than what the preset specifies, and the mod settings match exactly).
|
||||||
// therefore it's safe to just clear selected mods, since it will have the effect of toggling the preset off.
|
// therefore it's safe to just clear selected mods, since it will have the effect of toggling the preset off.
|
||||||
selectedMods.Value = !Active.Value
|
selectedMods.Value = Array.Empty<Mod>();
|
||||||
? Preset.Value.Mods.ToArray()
|
|
||||||
: Array.Empty<Mod>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectedModsChanged()
|
private void selectedModsChanged()
|
||||||
|
@ -143,9 +143,25 @@ namespace osu.Game.Overlays.Mods
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Action = () => Active.Toggle();
|
Action = () =>
|
||||||
|
{
|
||||||
|
if (!Active.Value)
|
||||||
|
Select();
|
||||||
|
else
|
||||||
|
Deselect();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Performs all actions necessary to select this <see cref="ModSelectPanel"/>.
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void Select();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Performs all actions necessary to deselect this <see cref="ModSelectPanel"/>.
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void Deselect();
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(AudioManager audio, ISamplePlaybackDisabler? samplePlaybackDisabler)
|
private void load(AudioManager audio, ISamplePlaybackDisabler? samplePlaybackDisabler)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user