Merge pull request #20965 from peppy/reduce-slider-blueprint-overhead

Only draw path visualiser when hovered or single slider is selected
This commit is contained in:
Dan Balasescu 2022-10-28 16:01:30 +09:00 committed by GitHub
commit 74f3b9b18d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 46 additions and 10 deletions

View File

@ -59,6 +59,7 @@ public class SliderSelectionBlueprint : OsuSelectionBlueprint<Slider>
private readonly BindableList<PathControlPoint> controlPoints = new BindableList<PathControlPoint>();
private readonly IBindable<int> pathVersion = new Bindable<int>();
private readonly BindableList<HitObject> selectedObjects = new BindableList<HitObject>();
public SliderSelectionBlueprint(Slider slider)
: base(slider)
@ -86,6 +87,10 @@ protected override void LoadComplete()
pathVersion.BindValueChanged(_ => editorBeatmap?.Update(HitObject));
BodyPiece.UpdateFrom(HitObject);
if (editorBeatmap != null)
selectedObjects.BindTo(editorBeatmap.SelectedHitObjects);
selectedObjects.BindCollectionChanged((_, _) => updateVisualDefinition(), true);
}
public override bool HandleQuickDeletion()
@ -100,6 +105,8 @@ public override bool HandleQuickDeletion()
return true;
}
private bool hasSingleObjectSelected => selectedObjects.Count == 1;
protected override void Update()
{
base.Update();
@ -108,14 +115,25 @@ protected override void Update()
BodyPiece.UpdateFrom(HitObject);
}
protected override bool OnHover(HoverEvent e)
{
updateVisualDefinition();
// In the case more than a single object is selected, block hover from arriving at sliders behind this one.
// Without doing this, the path visualisers of potentially hundreds of sliders will render, which is not only
// visually noisy but also functionally useless.
return !hasSingleObjectSelected;
}
protected override void OnHoverLost(HoverLostEvent e)
{
updateVisualDefinition();
base.OnHoverLost(e);
}
protected override void OnSelected()
{
AddInternal(ControlPointVisualiser = new PathControlPointVisualiser(HitObject, true)
{
RemoveControlPointsRequested = removeControlPoints,
SplitControlPointsRequested = splitControlPoints
});
updateVisualDefinition();
base.OnSelected();
}
@ -123,13 +141,31 @@ protected override void OnDeselected()
{
base.OnDeselected();
// throw away frame buffers on deselection.
ControlPointVisualiser?.Expire();
ControlPointVisualiser = null;
updateVisualDefinition();
BodyPiece.RecyclePath();
}
private void updateVisualDefinition()
{
// To reduce overhead of drawing these blueprints, only add extra detail when hovered or when only this slider is selected.
if (IsSelected && (hasSingleObjectSelected || IsHovered))
{
if (ControlPointVisualiser == null)
{
AddInternal(ControlPointVisualiser = new PathControlPointVisualiser(HitObject, true)
{
RemoveControlPointsRequested = removeControlPoints,
SplitControlPointsRequested = splitControlPoints
});
}
}
else
{
ControlPointVisualiser?.Expire();
ControlPointVisualiser = null;
}
}
private Vector2 rightClickPosition;
protected override bool OnMouseDown(MouseDownEvent e)