From ad3c093a084cf035b2982a4497937fcbdfaa2551 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 2 Jun 2022 18:33:09 +0900 Subject: [PATCH] Improve group tracking logic to avoid switching which point type unnecessarily --- osu.Game/Screens/Edit/Timing/TimingScreen.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Edit/Timing/TimingScreen.cs b/osu.Game/Screens/Edit/Timing/TimingScreen.cs index 40e6e8082a5b..aba6b2f23e55 100644 --- a/osu.Game/Screens/Edit/Timing/TimingScreen.cs +++ b/osu.Game/Screens/Edit/Timing/TimingScreen.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -139,6 +140,8 @@ protected override void Update() trackActivePoint(); } + private Type trackedType; + /// /// Given the user has selected a control point group, we want to track any group which is /// active at the current point in time which matches the type the user has selected. @@ -149,16 +152,27 @@ protected override void Update() private void trackActivePoint() { // For simplicity only match on the first type of the active control point. - var selectedPointType = selectedGroup.Value?.ControlPoints.FirstOrDefault()?.GetType(); + if (selectedGroup.Value == null) + trackedType = null; + else + { + // If the selected group only has one control point, update the tracking type. + if (selectedGroup.Value.ControlPoints.Count == 1) + trackedType = selectedGroup.Value?.ControlPoints.Single().GetType(); + // If the selected group has more than one control point, choose the first as the tracking type + // if we don't already have a singular tracked type. + else if (trackedType == null) + trackedType = selectedGroup.Value?.ControlPoints.FirstOrDefault()?.GetType(); + } - if (selectedPointType != null) + if (trackedType != null) { // We don't have an efficient way of looking up groups currently, only individual point types. // To improve the efficiency of this in the future, we should reconsider the overall structure of ControlPointInfo. // Find the next group which has the same type as the selected one. var found = Beatmap.ControlPointInfo.Groups - .Where(g => g.ControlPoints.Any(cp => cp.GetType() == selectedPointType)) + .Where(g => g.ControlPoints.Any(cp => cp.GetType() == trackedType)) .LastOrDefault(g => g.Time <= clock.CurrentTimeAccurate); if (found != null)