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-03 15:27:26 +08:00
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2022-06-18 12:49:57 +08:00
|
|
|
using System.Linq;
|
2020-05-15 17:07:41 +08:00
|
|
|
using System.Threading;
|
2018-10-03 15:27:26 +08:00
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-10-25 17:16:25 +08:00
|
|
|
using osu.Framework.Graphics;
|
2018-10-03 15:27:26 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Input.Events;
|
2021-02-11 16:16:17 +08:00
|
|
|
using osu.Game.Audio;
|
2018-10-03 15:27:26 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2019-04-25 16:36:17 +08:00
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2018-10-03 15:27:26 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2020-05-22 15:37:28 +08:00
|
|
|
using osu.Game.Screens.Edit;
|
2018-11-06 17:28:22 +08:00
|
|
|
using osu.Game.Screens.Edit.Compose;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
2021-04-22 14:27:08 +08:00
|
|
|
using osuTK.Input;
|
2018-10-03 15:27:26 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Edit
|
|
|
|
{
|
2018-10-31 11:01:10 +08:00
|
|
|
/// <summary>
|
2018-11-06 17:06:34 +08:00
|
|
|
/// A blueprint which governs the creation of a new <see cref="HitObject"/> to actualisation.
|
2018-10-31 11:01:10 +08:00
|
|
|
/// </summary>
|
2020-02-13 09:00:09 +08:00
|
|
|
public abstract class PlacementBlueprint : CompositeDrawable
|
2018-10-03 15:27:26 +08:00
|
|
|
{
|
2018-11-13 12:00:00 +08:00
|
|
|
/// <summary>
|
2020-02-13 08:03:48 +08:00
|
|
|
/// Whether the <see cref="HitObject"/> is currently mid-placement, but has not necessarily finished being placed.
|
2018-11-13 12:00:00 +08:00
|
|
|
/// </summary>
|
2021-04-16 13:10:21 +08:00
|
|
|
public PlacementState PlacementActive { get; private set; }
|
2018-11-13 12:00:00 +08:00
|
|
|
|
2018-10-03 15:27:26 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The <see cref="HitObject"/> that is being placed.
|
|
|
|
/// </summary>
|
2020-09-25 13:10:30 +08:00
|
|
|
public readonly HitObject HitObject;
|
2018-10-03 15:27:26 +08:00
|
|
|
|
2020-05-25 14:40:25 +08:00
|
|
|
[Resolved(canBeNull: true)]
|
2020-05-22 15:37:28 +08:00
|
|
|
protected EditorClock EditorClock { get; private set; }
|
2018-10-03 15:44:37 +08:00
|
|
|
|
2021-05-19 17:34:02 +08:00
|
|
|
[Resolved]
|
|
|
|
private EditorBeatmap beatmap { get; set; }
|
2018-10-17 17:36:47 +08:00
|
|
|
|
2020-05-22 21:41:06 +08:00
|
|
|
private Bindable<double> startTimeBindable;
|
|
|
|
|
2018-10-17 14:46:30 +08:00
|
|
|
[Resolved]
|
|
|
|
private IPlacementHandler placementHandler { get; set; }
|
|
|
|
|
2018-11-06 17:04:03 +08:00
|
|
|
protected PlacementBlueprint(HitObject hitObject)
|
2018-10-03 15:27:26 +08:00
|
|
|
{
|
|
|
|
HitObject = hitObject;
|
2018-10-25 17:16:25 +08:00
|
|
|
|
2021-02-11 16:16:17 +08:00
|
|
|
// adding the default hit sample should be the case regardless of the ruleset.
|
|
|
|
HitObject.Samples.Add(new HitSampleInfo(HitSampleInfo.HIT_NORMAL));
|
|
|
|
|
2018-10-25 17:16:25 +08:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
2018-11-13 11:52:04 +08:00
|
|
|
|
2018-11-29 13:55:20 +08:00
|
|
|
// This is required to allow the blueprint's position to be updated via OnMouseMove/Handle
|
|
|
|
// on the same frame it is made visible via a PlacementState change.
|
|
|
|
AlwaysPresent = true;
|
2018-10-03 15:27:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-05-19 17:34:02 +08:00
|
|
|
private void load()
|
2018-10-03 15:27:26 +08:00
|
|
|
{
|
2020-05-22 21:41:06 +08:00
|
|
|
startTimeBindable = HitObject.StartTimeBindable.GetBoundCopy();
|
|
|
|
startTimeBindable.BindValueChanged(_ => ApplyDefaultsToHitObject(), true);
|
2018-10-03 15:27:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2018-10-17 13:37:39 +08:00
|
|
|
/// Signals that the placement of <see cref="HitObject"/> has started.
|
2018-10-03 15:27:26 +08:00
|
|
|
/// </summary>
|
2020-02-13 08:03:48 +08:00
|
|
|
/// <param name="commitStart">Whether this call is committing a value for HitObject.StartTime and continuing with further adjustments.</param>
|
2020-05-20 17:46:15 +08:00
|
|
|
protected void BeginPlacement(bool commitStart = false)
|
2018-10-17 13:37:39 +08:00
|
|
|
{
|
2022-06-18 12:49:57 +08:00
|
|
|
var nearestSampleControlPoint = beatmap.HitObjects.LastOrDefault(h => h.GetEndTime() < HitObject.StartTime)?.SampleControlPoint?.DeepClone() as SampleControlPoint;
|
|
|
|
|
|
|
|
HitObject.SampleControlPoint = nearestSampleControlPoint ?? new SampleControlPoint();
|
|
|
|
|
2018-10-17 14:46:30 +08:00
|
|
|
placementHandler.BeginPlacement(HitObject);
|
2021-04-16 13:10:21 +08:00
|
|
|
if (commitStart)
|
|
|
|
PlacementActive = PlacementState.Active;
|
2018-10-17 13:37:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Signals that the placement of <see cref="HitObject"/> has finished.
|
2020-02-13 08:03:48 +08:00
|
|
|
/// This will destroy this <see cref="PlacementBlueprint"/>, and add the HitObject.StartTime to the <see cref="Beatmap"/>.
|
2018-10-17 13:37:39 +08:00
|
|
|
/// </summary>
|
2020-02-07 17:02:48 +08:00
|
|
|
/// <param name="commit">Whether the object should be committed.</param>
|
|
|
|
public void EndPlacement(bool commit)
|
2018-10-17 13:37:39 +08:00
|
|
|
{
|
2021-04-16 13:10:21 +08:00
|
|
|
switch (PlacementActive)
|
|
|
|
{
|
|
|
|
case PlacementState.Finished:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case PlacementState.Waiting:
|
|
|
|
// ensure placement was started before ending to make state handling simpler.
|
|
|
|
BeginPlacement();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-02-07 17:02:48 +08:00
|
|
|
placementHandler.EndPlacement(HitObject, commit);
|
2021-04-16 13:10:21 +08:00
|
|
|
PlacementActive = PlacementState.Finished;
|
2018-10-17 13:37:39 +08:00
|
|
|
}
|
2018-10-03 15:27:26 +08:00
|
|
|
|
2019-10-03 15:14:42 +08:00
|
|
|
/// <summary>
|
2020-11-30 17:35:30 +08:00
|
|
|
/// Updates the time and position of this <see cref="PlacementBlueprint"/> based on the provided snap information.
|
2019-10-03 15:14:42 +08:00
|
|
|
/// </summary>
|
2020-05-28 19:33:12 +08:00
|
|
|
/// <param name="result">The snap result information.</param>
|
2020-11-26 18:16:18 +08:00
|
|
|
public virtual void UpdateTimeAndPosition(SnapResult result)
|
2020-05-21 13:38:40 +08:00
|
|
|
{
|
2021-04-16 13:10:21 +08:00
|
|
|
if (PlacementActive == PlacementState.Waiting)
|
2020-05-28 19:33:12 +08:00
|
|
|
HitObject.StartTime = result.Time ?? EditorClock?.CurrentTime ?? Time.Current;
|
2020-05-21 13:38:40 +08:00
|
|
|
}
|
2019-10-03 15:14:42 +08:00
|
|
|
|
2018-10-17 17:36:47 +08:00
|
|
|
/// <summary>
|
2021-10-01 13:56:42 +08:00
|
|
|
/// Invokes <see cref="Objects.HitObject.ApplyDefaults(ControlPointInfo,IBeatmapDifficultyInfo,CancellationToken)"/>,
|
2019-04-25 16:36:17 +08:00
|
|
|
/// refreshing <see cref="Objects.HitObject.NestedHitObjects"/> and parameters for the <see cref="HitObject"/>.
|
2018-10-17 17:36:47 +08:00
|
|
|
/// </summary>
|
2021-10-02 11:34:29 +08:00
|
|
|
protected void ApplyDefaultsToHitObject() => HitObject.ApplyDefaults(beatmap.ControlPointInfo, beatmap.Difficulty);
|
2018-10-17 17:36:47 +08:00
|
|
|
|
2018-10-03 15:27:26 +08:00
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Parent?.ReceivePositionalInputAt(screenSpacePos) ?? false;
|
|
|
|
|
|
|
|
protected override bool Handle(UIEvent e)
|
|
|
|
{
|
|
|
|
base.Handle(e);
|
|
|
|
|
|
|
|
switch (e)
|
|
|
|
{
|
2022-06-24 20:25:23 +08:00
|
|
|
case ScrollEvent:
|
2018-10-31 16:23:27 +08:00
|
|
|
return false;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
2022-06-24 20:25:23 +08:00
|
|
|
case DoubleClickEvent:
|
2020-04-13 12:57:15 +08:00
|
|
|
return false;
|
|
|
|
|
2021-04-22 14:27:08 +08:00
|
|
|
case MouseButtonEvent mouse:
|
|
|
|
// placement blueprints should generally block mouse from reaching underlying components (ie. performing clicks on interface buttons).
|
|
|
|
// for now, the one exception we want to allow is when using a non-main mouse button when shift is pressed, which is used to trigger object deletion
|
|
|
|
// while in placement mode.
|
|
|
|
return mouse.Button == MouseButton.Left || !mouse.ShiftPressed;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
2018-10-03 15:27:26 +08:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2021-04-16 13:10:21 +08:00
|
|
|
|
|
|
|
public enum PlacementState
|
|
|
|
{
|
|
|
|
Waiting,
|
|
|
|
Active,
|
|
|
|
Finished
|
|
|
|
}
|
2018-10-03 15:27:26 +08:00
|
|
|
}
|
|
|
|
}
|