1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:57:36 +08:00

Apply NRT to remaining classes in slider blueprint namespace

This commit is contained in:
Dean Herbert 2024-08-27 13:18:55 +09:00
parent 4fc96ebfde
commit 50a8348bf9
No known key found for this signature in database
2 changed files with 40 additions and 49 deletions

View File

@ -1,13 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input; using osu.Framework.Input;
@ -29,30 +25,29 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
{ {
public new Slider HitObject => (Slider)base.HitObject; public new Slider HitObject => (Slider)base.HitObject;
private SliderBodyPiece bodyPiece; private SliderBodyPiece bodyPiece = null!;
private HitCirclePiece headCirclePiece; private HitCirclePiece headCirclePiece = null!;
private HitCirclePiece tailCirclePiece; private HitCirclePiece tailCirclePiece = null!;
private PathControlPointVisualiser<Slider> controlPointVisualiser; private PathControlPointVisualiser<Slider> controlPointVisualiser = null!;
private InputManager inputManager; private InputManager inputManager = null!;
private PathControlPoint? cursor;
private SliderPlacementState state; private SliderPlacementState state;
private PathControlPoint segmentStart; private PathControlPoint segmentStart;
private PathControlPoint cursor;
private int currentSegmentLength; private int currentSegmentLength;
private bool usingCustomSegmentType; private bool usingCustomSegmentType;
[Resolved(CanBeNull = true)] [Resolved]
[CanBeNull] private IPositionSnapProvider? positionSnapProvider { get; set; }
private IPositionSnapProvider positionSnapProvider { get; set; }
[Resolved(CanBeNull = true)] [Resolved]
[CanBeNull] private IDistanceSnapProvider? distanceSnapProvider { get; set; }
private IDistanceSnapProvider distanceSnapProvider { get; set; }
[Resolved(CanBeNull = true)] [Resolved]
[CanBeNull] private FreehandSliderToolboxGroup? freehandToolboxGroup { get; set; }
private FreehandSliderToolboxGroup freehandToolboxGroup { get; set; }
private readonly IncrementalBSplineBuilder bSplineBuilder = new IncrementalBSplineBuilder { Degree = 4 }; private readonly IncrementalBSplineBuilder bSplineBuilder = new IncrementalBSplineBuilder { Degree = 4 };
@ -84,7 +79,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
inputManager = GetContainingInputManager();
inputManager = GetContainingInputManager()!;
if (freehandToolboxGroup != null) if (freehandToolboxGroup != null)
{ {
@ -108,7 +104,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
} }
[Resolved] [Resolved]
private EditorBeatmap editorBeatmap { get; set; } private EditorBeatmap editorBeatmap { get; set; } = null!;
public override void UpdateTimeAndPosition(SnapResult result) public override void UpdateTimeAndPosition(SnapResult result)
{ {
@ -151,7 +147,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
case SliderPlacementState.ControlPoints: case SliderPlacementState.ControlPoints:
if (canPlaceNewControlPoint(out var lastPoint)) if (canPlaceNewControlPoint(out var lastPoint))
placeNewControlPoint(); placeNewControlPoint();
else else if (lastPoint != null)
beginNewSegment(lastPoint); beginNewSegment(lastPoint);
break; break;
@ -162,9 +158,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
private void beginNewSegment(PathControlPoint lastPoint) private void beginNewSegment(PathControlPoint lastPoint)
{ {
// Transform the last point into a new segment.
Debug.Assert(lastPoint != null);
segmentStart = lastPoint; segmentStart = lastPoint;
segmentStart.Type = PathType.LINEAR; segmentStart.Type = PathType.LINEAR;
@ -384,7 +377,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
/// </summary> /// </summary>
/// <param name="lastPoint">The last-placed control point. May be null, but is not null if <c>false</c> is returned.</param> /// <param name="lastPoint">The last-placed control point. May be null, but is not null if <c>false</c> is returned.</param>
/// <returns>Whether a new control point can be placed at the current position.</returns> /// <returns>Whether a new control point can be placed at the current position.</returns>
private bool canPlaceNewControlPoint([CanBeNull] out PathControlPoint lastPoint) private bool canPlaceNewControlPoint(out PathControlPoint? lastPoint)
{ {
// We cannot rely on the ordering of drawable pieces, so find the respective drawable piece by searching for the last non-cursor control point. // We cannot rely on the ordering of drawable pieces, so find the respective drawable piece by searching for the last non-cursor control point.
var last = HitObject.Path.ControlPoints.LastOrDefault(p => p != cursor); var last = HitObject.Path.ControlPoints.LastOrDefault(p => p != cursor);
@ -436,7 +429,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
// Replace this segment with a circular arc if it is a reasonable substitute. // Replace this segment with a circular arc if it is a reasonable substitute.
var circleArcSegment = tryCircleArc(segment); var circleArcSegment = tryCircleArc(segment);
if (circleArcSegment is not null) if (circleArcSegment != null)
{ {
HitObject.Path.ControlPoints.Add(new PathControlPoint(circleArcSegment[0], PathType.PERFECT_CURVE)); HitObject.Path.ControlPoints.Add(new PathControlPoint(circleArcSegment[0], PathType.PERFECT_CURVE));
HitObject.Path.ControlPoints.Add(new PathControlPoint(circleArcSegment[1])); HitObject.Path.ControlPoints.Add(new PathControlPoint(circleArcSegment[1]));
@ -453,7 +446,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
} }
} }
private Vector2[] tryCircleArc(List<Vector2> segment) private Vector2[]? tryCircleArc(List<Vector2> segment)
{ {
if (segment.Count < 3 || freehandToolboxGroup?.CircleThreshold.Value == 0) return null; if (segment.Count < 3 || freehandToolboxGroup?.CircleThreshold.Value == 0) return null;

View File

@ -1,13 +1,10 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Caching; using osu.Framework.Caching;
@ -36,30 +33,28 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
{ {
protected new DrawableSlider DrawableObject => (DrawableSlider)base.DrawableObject; protected new DrawableSlider DrawableObject => (DrawableSlider)base.DrawableObject;
protected SliderBodyPiece BodyPiece { get; private set; } protected SliderBodyPiece BodyPiece { get; private set; } = null!;
protected SliderCircleOverlay HeadOverlay { get; private set; } protected SliderCircleOverlay HeadOverlay { get; private set; } = null!;
protected SliderCircleOverlay TailOverlay { get; private set; } protected SliderCircleOverlay TailOverlay { get; private set; } = null!;
[CanBeNull] protected PathControlPointVisualiser<Slider>? ControlPointVisualiser { get; private set; }
protected PathControlPointVisualiser<Slider> ControlPointVisualiser { get; private set; }
[Resolved(CanBeNull = true)] [Resolved]
private IDistanceSnapProvider distanceSnapProvider { get; set; } private IDistanceSnapProvider? distanceSnapProvider { get; set; }
[Resolved(CanBeNull = true)] [Resolved]
private IPlacementHandler placementHandler { get; set; } private IPlacementHandler? placementHandler { get; set; }
[Resolved(CanBeNull = true)] [Resolved]
private EditorBeatmap editorBeatmap { get; set; } private EditorBeatmap? editorBeatmap { get; set; }
[Resolved(CanBeNull = true)] [Resolved]
private IEditorChangeHandler changeHandler { get; set; } private IEditorChangeHandler? changeHandler { get; set; }
[Resolved(CanBeNull = true)] [Resolved]
private BindableBeatDivisor beatDivisor { get; set; } private BindableBeatDivisor? beatDivisor { get; set; }
[CanBeNull] private PathControlPoint? placementControlPoint;
private PathControlPoint placementControlPoint;
public override Quad SelectionQuad public override Quad SelectionQuad
{ {
@ -145,7 +140,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
return false; return false;
hoveredControlPoint.IsSelected.Value = true; hoveredControlPoint.IsSelected.Value = true;
ControlPointVisualiser.DeleteSelected(); ControlPointVisualiser?.DeleteSelected();
return true; return true;
} }
@ -487,6 +482,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
private void splitControlPoints(List<PathControlPoint> controlPointsToSplitAt) private void splitControlPoints(List<PathControlPoint> controlPointsToSplitAt)
{ {
if (editorBeatmap == null)
return;
// Arbitrary gap in milliseconds to put between split slider pieces // Arbitrary gap in milliseconds to put between split slider pieces
const double split_gap = 100; const double split_gap = 100;