2019-01-24 16:43:03 +08: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.
|
2018-10-29 17:35:46 +08:00
|
|
|
|
2020-02-07 18:09:47 +08:00
|
|
|
using System;
|
2022-12-02 16:56:34 +08:00
|
|
|
using osu.Framework.Allocation;
|
2018-10-29 17:35:46 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Rulesets.Edit;
|
2018-11-07 15:08:56 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Edit.Blueprints.Spinners.Components;
|
2018-10-29 17:35:46 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
2018-11-01 18:24:58 +08:00
|
|
|
using osu.Game.Rulesets.Osu.UI;
|
2020-02-07 18:09:47 +08:00
|
|
|
using osuTK.Input;
|
2018-10-29 17:35:46 +08:00
|
|
|
|
2018-11-07 15:08:56 +08:00
|
|
|
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Spinners
|
2018-10-29 17:35:46 +08:00
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class SpinnerPlacementBlueprint : PlacementBlueprint
|
2018-10-29 17:35:46 +08:00
|
|
|
{
|
|
|
|
public new Spinner HitObject => (Spinner)base.HitObject;
|
|
|
|
|
|
|
|
private readonly SpinnerPiece piece;
|
|
|
|
|
|
|
|
private bool isPlacingEnd;
|
|
|
|
|
2023-05-17 19:54:17 +08:00
|
|
|
[Resolved]
|
|
|
|
private IBeatSnapProvider? beatSnapProvider { get; set; }
|
2022-12-02 16:56:34 +08:00
|
|
|
|
2018-11-06 17:04:03 +08:00
|
|
|
public SpinnerPlacementBlueprint()
|
2018-11-01 18:24:58 +08:00
|
|
|
: base(new Spinner { Position = OsuPlayfield.BASE_SIZE / 2 })
|
2018-10-29 17:35:46 +08:00
|
|
|
{
|
2019-09-27 17:45:22 +08:00
|
|
|
InternalChild = piece = new SpinnerPiece { Alpha = 0.5f };
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2020-02-07 18:09:47 +08:00
|
|
|
if (isPlacingEnd)
|
2022-12-02 16:56:34 +08:00
|
|
|
updateEndTimeFromCurrent();
|
2020-02-07 18:09:47 +08:00
|
|
|
|
2019-09-27 17:45:22 +08:00
|
|
|
piece.UpdateFrom(HitObject);
|
2018-10-29 17:35:46 +08:00
|
|
|
}
|
|
|
|
|
2020-02-07 18:09:47 +08:00
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
2018-10-29 17:35:46 +08:00
|
|
|
{
|
|
|
|
if (isPlacingEnd)
|
|
|
|
{
|
2020-02-07 18:09:47 +08:00
|
|
|
if (e.Button != MouseButton.Right)
|
|
|
|
return false;
|
|
|
|
|
2022-12-02 16:56:34 +08:00
|
|
|
updateEndTimeFromCurrent();
|
2020-02-07 17:02:48 +08:00
|
|
|
EndPlacement(true);
|
2018-10-29 17:35:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-07 18:09:47 +08:00
|
|
|
if (e.Button != MouseButton.Left)
|
|
|
|
return false;
|
2018-11-13 11:52:44 +08:00
|
|
|
|
2020-02-13 08:03:48 +08:00
|
|
|
BeginPlacement(commitStart: true);
|
2020-02-07 23:28:52 +08:00
|
|
|
piece.FadeTo(1f, 150, Easing.OutQuint);
|
|
|
|
|
2020-02-07 18:09:47 +08:00
|
|
|
isPlacingEnd = true;
|
2018-10-29 17:35:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2022-12-02 16:56:34 +08:00
|
|
|
|
2022-12-02 17:32:40 +08:00
|
|
|
private void updateEndTimeFromCurrent()
|
|
|
|
{
|
|
|
|
HitObject.EndTime = beatSnapProvider == null
|
|
|
|
? Math.Max(HitObject.StartTime, EditorClock.CurrentTime)
|
|
|
|
: Math.Max(HitObject.StartTime + beatSnapProvider.GetBeatLengthAtTime(HitObject.StartTime), beatSnapProvider.SnapTime(EditorClock.CurrentTime));
|
|
|
|
}
|
2018-10-29 17:35:46 +08:00
|
|
|
}
|
|
|
|
}
|