2019-01-24 08:43:03 +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.
|
2018-10-03 07:27:26 +00:00
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
using osu.Framework.Bindables;
|
2018-10-25 09:16:25 +00:00
|
|
|
using osu.Framework.Graphics;
|
2018-10-03 07:27:26 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Input.Events;
|
2018-10-03 07:44:37 +00:00
|
|
|
using osu.Framework.Timing;
|
2018-10-03 07:27:26 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2019-04-25 08:36:17 +00:00
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2018-10-03 07:27:26 +00:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2018-11-06 09:28:22 +00:00
|
|
|
using osu.Game.Screens.Edit.Compose;
|
2018-11-20 07:51:59 +00:00
|
|
|
using osuTK;
|
2018-10-03 07:27:26 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Edit
|
|
|
|
{
|
2018-10-31 03:01:10 +00:00
|
|
|
/// <summary>
|
2018-11-06 09:06:34 +00:00
|
|
|
/// A blueprint which governs the creation of a new <see cref="HitObject"/> to actualisation.
|
2018-10-31 03:01:10 +00:00
|
|
|
/// </summary>
|
2020-02-13 01:00:09 +00:00
|
|
|
public abstract class PlacementBlueprint : CompositeDrawable
|
2018-10-03 07:27:26 +00:00
|
|
|
{
|
2018-11-13 04:00:00 +00:00
|
|
|
/// <summary>
|
2020-02-13 00:03:48 +00:00
|
|
|
/// Whether the <see cref="HitObject"/> is currently mid-placement, but has not necessarily finished being placed.
|
2018-11-13 04:00:00 +00:00
|
|
|
/// </summary>
|
2020-02-13 00:03:48 +00:00
|
|
|
public bool PlacementActive { get; private set; }
|
2018-11-13 04:00:00 +00:00
|
|
|
|
2018-10-03 07:27:26 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The <see cref="HitObject"/> that is being placed.
|
|
|
|
/// </summary>
|
|
|
|
protected readonly HitObject HitObject;
|
|
|
|
|
2018-10-10 06:32:55 +00:00
|
|
|
protected IClock EditorClock { get; private set; }
|
2018-10-03 07:44:37 +00:00
|
|
|
|
2018-10-17 09:36:47 +00:00
|
|
|
private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
|
|
|
|
2018-10-17 06:46:30 +00:00
|
|
|
[Resolved]
|
|
|
|
private IPlacementHandler placementHandler { get; set; }
|
|
|
|
|
2018-11-06 09:04:03 +00:00
|
|
|
protected PlacementBlueprint(HitObject hitObject)
|
2018-10-03 07:27:26 +00:00
|
|
|
{
|
|
|
|
HitObject = hitObject;
|
2018-10-25 09:16:25 +00:00
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2018-11-13 03:52:04 +00:00
|
|
|
|
2018-11-29 05:55:20 +00: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 07:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2019-02-01 06:42:15 +00:00
|
|
|
private void load(IBindable<WorkingBeatmap> beatmap, IAdjustableClock clock)
|
2018-10-03 07:27:26 +00:00
|
|
|
{
|
2018-10-17 09:36:47 +00:00
|
|
|
this.beatmap.BindTo(beatmap);
|
|
|
|
|
2018-10-10 06:32:55 +00:00
|
|
|
EditorClock = clock;
|
2018-10-03 07:44:37 +00:00
|
|
|
|
2018-10-17 09:36:47 +00:00
|
|
|
ApplyDefaultsToHitObject();
|
2018-10-03 07:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2018-10-17 05:37:39 +00:00
|
|
|
/// Signals that the placement of <see cref="HitObject"/> has started.
|
2018-10-03 07:27:26 +00:00
|
|
|
/// </summary>
|
2020-02-13 00:03:48 +00:00
|
|
|
/// <param name="commitStart">Whether this call is committing a value for HitObject.StartTime and continuing with further adjustments.</param>
|
2020-05-20 09:46:15 +00:00
|
|
|
protected void BeginPlacement(bool commitStart = false)
|
2018-10-17 05:37:39 +00:00
|
|
|
{
|
2020-05-20 08:48:43 +00:00
|
|
|
// applies snapping to above time
|
2018-10-17 06:46:30 +00:00
|
|
|
placementHandler.BeginPlacement(HitObject);
|
2020-05-20 08:48:43 +00:00
|
|
|
|
2020-02-13 00:03:48 +00:00
|
|
|
PlacementActive |= commitStart;
|
2018-10-17 05:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Signals that the placement of <see cref="HitObject"/> has finished.
|
2020-02-13 00:03:48 +00:00
|
|
|
/// This will destroy this <see cref="PlacementBlueprint"/>, and add the HitObject.StartTime to the <see cref="Beatmap"/>.
|
2018-10-17 05:37:39 +00:00
|
|
|
/// </summary>
|
2020-02-07 09:02:48 +00:00
|
|
|
/// <param name="commit">Whether the object should be committed.</param>
|
|
|
|
public void EndPlacement(bool commit)
|
2018-10-17 05:37:39 +00:00
|
|
|
{
|
2020-02-13 00:03:48 +00:00
|
|
|
if (!PlacementActive)
|
2018-10-17 05:37:39 +00:00
|
|
|
BeginPlacement();
|
2020-02-07 09:02:48 +00:00
|
|
|
placementHandler.EndPlacement(HitObject, commit);
|
2020-02-13 00:03:48 +00:00
|
|
|
PlacementActive = false;
|
2018-10-17 05:37:39 +00:00
|
|
|
}
|
2018-10-03 07:27:26 +00:00
|
|
|
|
2020-05-21 05:38:40 +00:00
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
private IFrameBasedClock editorClock { get; set; }
|
|
|
|
|
2019-10-03 07:14:42 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Updates the position of this <see cref="PlacementBlueprint"/> to a new screen-space position.
|
|
|
|
/// </summary>
|
2020-05-20 10:05:03 +00:00
|
|
|
/// <param name="snapResult">The snap result information.</param>
|
2020-05-21 05:38:40 +00:00
|
|
|
public virtual void UpdatePosition(SnapResult snapResult)
|
|
|
|
{
|
|
|
|
if (!PlacementActive)
|
|
|
|
HitObject.StartTime = snapResult.Time ?? editorClock?.CurrentTime ?? Time.Current;
|
|
|
|
}
|
2019-10-03 07:14:42 +00:00
|
|
|
|
2018-10-17 09:36:47 +00:00
|
|
|
/// <summary>
|
2019-04-25 08:36:17 +00:00
|
|
|
/// Invokes <see cref="Objects.HitObject.ApplyDefaults(ControlPointInfo,BeatmapDifficulty)"/>,
|
|
|
|
/// refreshing <see cref="Objects.HitObject.NestedHitObjects"/> and parameters for the <see cref="HitObject"/>.
|
2018-10-17 09:36:47 +00:00
|
|
|
/// </summary>
|
|
|
|
protected void ApplyDefaultsToHitObject() => HitObject.ApplyDefaults(beatmap.Value.Beatmap.ControlPointInfo, beatmap.Value.Beatmap.BeatmapInfo.BaseDifficulty);
|
|
|
|
|
2018-10-03 07:27:26 +00:00
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Parent?.ReceivePositionalInputAt(screenSpacePos) ?? false;
|
|
|
|
|
|
|
|
protected override bool Handle(UIEvent e)
|
|
|
|
{
|
|
|
|
base.Handle(e);
|
|
|
|
|
|
|
|
switch (e)
|
|
|
|
{
|
2018-10-31 08:23:27 +00:00
|
|
|
case ScrollEvent _:
|
|
|
|
return false;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
2020-04-13 04:57:15 +00:00
|
|
|
case DoubleClickEvent _:
|
|
|
|
return false;
|
|
|
|
|
2019-10-03 07:14:42 +00:00
|
|
|
case MouseButtonEvent _:
|
2018-10-03 07:27:26 +00:00
|
|
|
return true;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
2018-10-03 07:27:26 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|