1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 09:27:34 +08:00
osu-lazer/osu.Game/Rulesets/Edit/PlacementBlueprint.cs

124 lines
4.5 KiB
C#
Raw Normal View History

// 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.
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
2019-04-25 16:36:17 +08:00
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Objects;
2018-11-06 17:28:22 +08:00
using osu.Game.Screens.Edit.Compose;
2018-11-20 15:51:59 +08:00
using osuTK;
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>
public abstract class PlacementBlueprint : CompositeDrawable
{
2018-11-13 12:00:00 +08:00
/// <summary>
/// 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>
public bool PlacementActive { get; private set; }
2018-11-13 12:00:00 +08:00
/// <summary>
/// The <see cref="HitObject"/> that is being placed.
/// </summary>
protected readonly HitObject HitObject;
2018-10-10 14:32:55 +08:00
protected IClock EditorClock { get; private set; }
private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
[Resolved]
private IPlacementHandler placementHandler { get; set; }
2018-11-06 17:04:03 +08:00
protected PlacementBlueprint(HitObject hitObject)
{
HitObject = hitObject;
RelativeSizeAxes = Axes.Both;
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;
}
[BackgroundDependencyLoader]
2019-02-01 14:42:15 +08:00
private void load(IBindable<WorkingBeatmap> beatmap, IAdjustableClock clock)
{
this.beatmap.BindTo(beatmap);
2018-10-10 14:32:55 +08:00
EditorClock = clock;
ApplyDefaultsToHitObject();
}
/// <summary>
/// Signals that the placement of <see cref="HitObject"/> has started.
/// </summary>
/// <param name="startTime">The start time of <see cref="HitObject"/> at the placement point. If null, the current clock time is used.</param>
/// <param name="commitStart">Whether this call is committing a value for HitObject.StartTime and continuing with further adjustments.</param>
protected void BeginPlacement(double? startTime = null, bool commitStart = false)
{
HitObject.StartTime = startTime ?? EditorClock.CurrentTime;
// applies snapping to above time
placementHandler.BeginPlacement(HitObject);
PlacementActive |= commitStart;
}
/// <summary>
/// Signals that the placement of <see cref="HitObject"/> has finished.
/// This will destroy this <see cref="PlacementBlueprint"/>, and add the HitObject.StartTime to the <see cref="Beatmap"/>.
/// </summary>
/// <param name="commit">Whether the object should be committed.</param>
public void EndPlacement(bool commit)
{
if (!PlacementActive)
BeginPlacement();
placementHandler.EndPlacement(HitObject, commit);
PlacementActive = false;
}
/// <summary>
/// Updates the position of this <see cref="PlacementBlueprint"/> to a new screen-space position.
/// </summary>
/// <param name="screenSpacePosition">The screen-space position.</param>
public abstract void UpdatePosition(Vector2 screenSpacePosition);
/// <summary>
2019-04-25 16:36:17 +08:00
/// Invokes <see cref="Objects.HitObject.ApplyDefaults(ControlPointInfo,BeatmapDifficulty)"/>,
/// refreshing <see cref="Objects.HitObject.NestedHitObjects"/> and parameters for the <see cref="HitObject"/>.
/// </summary>
protected void ApplyDefaultsToHitObject() => HitObject.ApplyDefaults(beatmap.Value.Beatmap.ControlPointInfo, beatmap.Value.Beatmap.BeatmapInfo.BaseDifficulty);
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Parent?.ReceivePositionalInputAt(screenSpacePos) ?? false;
protected override bool Handle(UIEvent e)
{
base.Handle(e);
switch (e)
{
case ScrollEvent _:
return false;
2019-04-01 11:44:46 +08:00
case DoubleClickEvent _:
return false;
case MouseButtonEvent _:
return true;
2019-04-01 11:44:46 +08:00
default:
return false;
}
}
}
}