1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 09:58:21 +08:00

Simplify state management in ModColumn

Bad sign when you can't follow your own code.

All of the various state changing methods were flattened into one
because it was too hard to follow what was calling what and why.
This commit is contained in:
Bartłomiej Dach 2022-05-06 21:35:36 +02:00
parent 380cd1e036
commit c199b8fcb6
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497

View File

@ -49,7 +49,7 @@ namespace osu.Game.Overlays.Mods
set
{
filter = value;
updateFilter();
updateState();
}
}
@ -292,9 +292,7 @@ namespace osu.Game.Overlays.Mods
{
panelFlow.ChildrenEnumerable = loaded;
updateActiveState();
updateToggleAllState();
updateFilter();
updateState();
foreach (var panel in panelFlow)
{
@ -308,10 +306,19 @@ namespace osu.Game.Overlays.Mods
});
}
private void updateActiveState()
private void updateState()
{
foreach (var panel in panelFlow)
{
panel.Active.Value = SelectedMods.Contains(panel.Mod);
panel.ApplyFilter(Filter);
}
if (toggleAllCheckbox != null && !SelectionAnimationRunning)
{
toggleAllCheckbox.Alpha = panelFlow.Any(panel => !panel.Filtered.Value) ? 1 : 0;
toggleAllCheckbox.Current.Value = panelFlow.Where(panel => !panel.Filtered.Value).All(panel => panel.Active.Value);
}
}
/// <summary>
@ -323,13 +330,12 @@ namespace osu.Game.Overlays.Mods
private void panelStateChanged(ModPanel panel)
{
updateToggleAllState();
var newSelectedMods = panel.Active.Value
? SelectedMods.Append(panel.Mod)
: SelectedMods.Except(panel.Mod.Yield());
SelectedMods = newSelectedMods.ToArray();
updateState();
if (!externalSelectionUpdateInProgress)
SelectionChangedByUser?.Invoke();
}
@ -364,7 +370,7 @@ namespace osu.Game.Overlays.Mods
}
SelectedMods = newSelection;
updateActiveState();
updateState();
externalSelectionUpdateInProgress = false;
}
@ -403,15 +409,6 @@ namespace osu.Game.Overlays.Mods
}
}
private void updateToggleAllState()
{
if (toggleAllCheckbox != null && !SelectionAnimationRunning)
{
toggleAllCheckbox.Alpha = panelFlow.Any(panel => !panel.Filtered.Value) ? 1 : 0;
toggleAllCheckbox.Current.Value = panelFlow.Where(panel => !panel.Filtered.Value).All(panel => panel.Active.Value);
}
}
/// <summary>
/// Selects all mods.
/// </summary>
@ -507,18 +504,6 @@ namespace osu.Game.Overlays.Mods
#endregion
#region Filtering support
private void updateFilter()
{
foreach (var modPanel in panelFlow)
modPanel.ApplyFilter(Filter);
updateToggleAllState();
}
#endregion
#region Keyboard selection support
protected override bool OnKeyDown(KeyDownEvent e)