2021-07-22 06:20:33 +00:00
|
|
|
// 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.
|
|
|
|
|
2021-07-22 06:41:01 +00:00
|
|
|
using osu.Framework.Graphics;
|
2021-07-23 01:10:55 +00:00
|
|
|
using osu.Framework.Input;
|
2021-07-22 06:41:01 +00:00
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Rulesets.Catch.Edit.Blueprints.Components;
|
2021-07-22 06:20:33 +00:00
|
|
|
using osu.Game.Rulesets.Catch.Objects;
|
2021-07-22 06:41:01 +00:00
|
|
|
using osu.Game.Rulesets.Edit;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Input;
|
2021-07-22 06:20:33 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.Edit.Blueprints
|
|
|
|
{
|
|
|
|
public partial class JuiceStreamPlacementBlueprint : CatchPlacementBlueprint<JuiceStream>
|
|
|
|
{
|
2021-07-22 06:41:01 +00:00
|
|
|
private readonly ScrollingPath scrollingPath;
|
|
|
|
|
|
|
|
private readonly NestedOutlineContainer nestedOutlineContainer;
|
|
|
|
|
|
|
|
private readonly PlacementEditablePath editablePath;
|
|
|
|
|
|
|
|
private int lastEditablePathId = -1;
|
|
|
|
|
2023-01-15 07:00:34 +00:00
|
|
|
private InputManager inputManager = null!;
|
2021-07-23 01:10:55 +00:00
|
|
|
|
2021-07-22 06:41:01 +00:00
|
|
|
public JuiceStreamPlacementBlueprint()
|
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
scrollingPath = new ScrollingPath(),
|
|
|
|
nestedOutlineContainer = new NestedOutlineContainer(),
|
2022-05-08 09:32:01 +00:00
|
|
|
editablePath = new PlacementEditablePath(positionToTime)
|
2021-07-22 06:41:01 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
if (PlacementActive == PlacementState.Active)
|
|
|
|
editablePath.UpdateFrom(HitObjectContainer, HitObject);
|
|
|
|
}
|
|
|
|
|
2021-07-23 01:10:55 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
inputManager = GetContainingInputManager();
|
2022-05-08 06:52:14 +00:00
|
|
|
|
|
|
|
BeginPlacement();
|
2021-07-23 01:10:55 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 06:41:01 +00:00
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
|
|
|
{
|
|
|
|
switch (PlacementActive)
|
|
|
|
{
|
|
|
|
case PlacementState.Waiting:
|
|
|
|
if (e.Button != MouseButton.Left) break;
|
|
|
|
|
|
|
|
editablePath.AddNewVertex();
|
|
|
|
BeginPlacement(true);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case PlacementState.Active:
|
|
|
|
switch (e.Button)
|
|
|
|
{
|
|
|
|
case MouseButton.Left:
|
|
|
|
editablePath.AddNewVertex();
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case MouseButton.Right:
|
|
|
|
EndPlacement(HitObject.Duration > 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.OnMouseDown(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void UpdateTimeAndPosition(SnapResult result)
|
|
|
|
{
|
|
|
|
switch (PlacementActive)
|
|
|
|
{
|
|
|
|
case PlacementState.Waiting:
|
|
|
|
if (!(result.Time is double snappedTime)) return;
|
|
|
|
|
|
|
|
HitObject.OriginalX = ToLocalSpace(result.ScreenSpacePosition).X;
|
|
|
|
HitObject.StartTime = snappedTime;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PlacementState.Active:
|
2021-07-23 01:10:55 +00:00
|
|
|
Vector2 unsnappedPosition = inputManager.CurrentState.Mouse.Position;
|
2021-07-22 06:41:01 +00:00
|
|
|
editablePath.MoveLastVertex(unsnappedPosition);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the up-to-date position is used for outlines.
|
|
|
|
Vector2 startPosition = CatchHitObjectUtils.GetStartPosition(HitObjectContainer, HitObject);
|
|
|
|
editablePath.Position = nestedOutlineContainer.Position = scrollingPath.Position = startPosition;
|
|
|
|
|
|
|
|
updateHitObjectFromPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateHitObjectFromPath()
|
|
|
|
{
|
|
|
|
if (lastEditablePathId == editablePath.PathId)
|
|
|
|
return;
|
|
|
|
|
|
|
|
editablePath.UpdateHitObjectFromPath(HitObject);
|
|
|
|
ApplyDefaultsToHitObject();
|
|
|
|
|
|
|
|
scrollingPath.UpdatePathFrom(HitObjectContainer, HitObject);
|
|
|
|
nestedOutlineContainer.UpdateNestedObjectsFrom(HitObjectContainer, HitObject);
|
|
|
|
|
|
|
|
lastEditablePathId = editablePath.PathId;
|
|
|
|
}
|
|
|
|
|
2022-05-08 09:32:01 +00:00
|
|
|
private double positionToTime(float relativeYPosition)
|
2021-07-22 06:41:01 +00:00
|
|
|
{
|
|
|
|
double time = HitObjectContainer.TimeAtPosition(relativeYPosition, HitObject.StartTime);
|
2022-05-08 09:32:01 +00:00
|
|
|
return time - HitObject.StartTime;
|
2021-07-22 06:41:01 +00:00
|
|
|
}
|
2021-07-22 06:20:33 +00:00
|
|
|
}
|
|
|
|
}
|