From a859fe78ee52841fd458f4949e2b1e72d3c59a1c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 25 Sep 2020 15:27:45 +0900 Subject: [PATCH] Expose update ternary state method and use better state determination function --- .../Compose/Components/SelectionHandler.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs index 1c564c6605..8a152a9c57 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs @@ -366,32 +366,32 @@ namespace osu.Game.Screens.Edit.Compose.Components }; // bring in updates from selection changes - EditorBeatmap.HitObjectUpdated += _ => updateTernaryStates(); - EditorBeatmap.SelectedHitObjects.CollectionChanged += (sender, args) => updateTernaryStates(); + EditorBeatmap.HitObjectUpdated += _ => UpdateTernaryStates(); + EditorBeatmap.SelectedHitObjects.CollectionChanged += (sender, args) => UpdateTernaryStates(); } - private void updateTernaryStates() + /// + /// Called when context menu ternary states may need to be recalculated (selection changed or hitobject updated). + /// + protected virtual void UpdateTernaryStates() { - selectionNewComboState.Value = getStateFromBlueprints(selectedBlueprints.Select(b => (IHasComboInformation)b.HitObject).Count(h => h.NewCombo)); + selectionNewComboState.Value = GetStateFromSelection(SelectedHitObjects.OfType(), h => h.NewCombo); foreach (var (sampleName, bindable) in selectionSampleStates) { - bindable.Value = getStateFromBlueprints(SelectedHitObjects.Count(h => h.Samples.Any(s => s.Name == sampleName))); + bindable.Value = GetStateFromSelection(SelectedHitObjects, h => h.Samples.Any(s => s.Name == sampleName)); } } /// - /// Given a count of "true" blueprints, retrieve the correct ternary display state. + /// Given a selection target and a function of truth, retrieve the correct ternary state for display. /// - private TernaryState getStateFromBlueprints(int count) + protected TernaryState GetStateFromSelection(IEnumerable selection, Func func) { - if (count == 0) - return TernaryState.False; + if (selection.Any(func)) + return selection.All(func) ? TernaryState.True : TernaryState.Indeterminate; - if (count < SelectedHitObjects.Count()) - return TernaryState.Indeterminate; - - return TernaryState.True; + return TernaryState.False; } #endregion