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
|
|
|
|
2018-11-13 12:00:00 +08:00
|
|
|
using System;
|
|
|
|
using osu.Framework;
|
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;
|
2018-10-03 15:44:37 +08:00
|
|
|
using osu.Framework.Timing;
|
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;
|
2018-11-06 17:28:22 +08:00
|
|
|
using osu.Game.Screens.Edit.Compose;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
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>
|
2018-11-29 12:21:11 +08:00
|
|
|
public abstract class PlacementBlueprint : CompositeDrawable, IStateful<PlacementState>
|
2018-10-03 15:27:26 +08:00
|
|
|
{
|
2018-11-13 12:00:00 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Invoked when <see cref="State"/> has changed.
|
|
|
|
/// </summary>
|
|
|
|
public event Action<PlacementState> StateChanged;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether the <see cref="HitObject"/> is currently being placed, but has not necessarily finished being placed.
|
|
|
|
/// </summary>
|
|
|
|
public bool PlacementBegun { get; private set; }
|
|
|
|
|
2018-10-03 15:27:26 +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; }
|
2018-10-03 15:44:37 +08:00
|
|
|
|
2018-10-17 17:36:47 +08:00
|
|
|
private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
|
|
|
|
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
|
|
|
|
|
|
|
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-11-13 11:52:04 +08:00
|
|
|
Alpha = 0;
|
2018-10-03 15:27:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2019-02-01 14:42:15 +08:00
|
|
|
private void load(IBindable<WorkingBeatmap> beatmap, IAdjustableClock clock)
|
2018-10-03 15:27:26 +08:00
|
|
|
{
|
2018-10-17 17:36:47 +08:00
|
|
|
this.beatmap.BindTo(beatmap);
|
|
|
|
|
2018-10-10 14:32:55 +08:00
|
|
|
EditorClock = clock;
|
2018-10-03 15:44:37 +08:00
|
|
|
|
2018-10-17 17:36:47 +08:00
|
|
|
ApplyDefaultsToHitObject();
|
2018-10-03 15:27:26 +08:00
|
|
|
}
|
|
|
|
|
2018-11-13 12:00:00 +08:00
|
|
|
private PlacementState state;
|
|
|
|
|
|
|
|
public PlacementState State
|
|
|
|
{
|
|
|
|
get => state;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (state == value)
|
|
|
|
return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
2018-11-13 12:00:00 +08:00
|
|
|
state = value;
|
|
|
|
|
|
|
|
if (state == PlacementState.Shown)
|
|
|
|
Show();
|
|
|
|
else
|
|
|
|
Hide();
|
|
|
|
|
|
|
|
StateChanged?.Invoke(value);
|
|
|
|
}
|
|
|
|
}
|
2018-10-17 13:37:39 +08:00
|
|
|
|
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>
|
2018-10-17 13:37:39 +08:00
|
|
|
protected void BeginPlacement()
|
|
|
|
{
|
2018-10-17 14:46:30 +08:00
|
|
|
placementHandler.BeginPlacement(HitObject);
|
2018-11-13 11:52:04 +08:00
|
|
|
PlacementBegun = true;
|
2018-10-17 13:37:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Signals that the placement of <see cref="HitObject"/> has finished.
|
2018-11-06 17:04:03 +08:00
|
|
|
/// This will destroy this <see cref="PlacementBlueprint"/>, and add the <see cref="HitObject"/> to the <see cref="Beatmap"/>.
|
2018-10-17 13:37:39 +08:00
|
|
|
/// </summary>
|
|
|
|
protected void EndPlacement()
|
|
|
|
{
|
2018-11-13 11:52:04 +08:00
|
|
|
if (!PlacementBegun)
|
2018-10-17 13:37:39 +08:00
|
|
|
BeginPlacement();
|
2018-10-17 14:46:30 +08:00
|
|
|
placementHandler.EndPlacement(HitObject);
|
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>
|
|
|
|
/// 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);
|
|
|
|
|
2018-10-17 17:36:47 +08:00
|
|
|
/// <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"/>.
|
2018-10-17 17:36:47 +08:00
|
|
|
/// </summary>
|
|
|
|
protected void ApplyDefaultsToHitObject() => HitObject.ApplyDefaults(beatmap.Value.Beatmap.ControlPointInfo, beatmap.Value.Beatmap.BeatmapInfo.BaseDifficulty);
|
|
|
|
|
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)
|
|
|
|
{
|
2018-10-31 16:23:27 +08:00
|
|
|
case ScrollEvent _:
|
|
|
|
return false;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
2019-10-03 15:14:42 +08:00
|
|
|
case MouseButtonEvent _:
|
2018-10-03 15:27:26 +08:00
|
|
|
return true;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
2018-10-03 15:27:26 +08:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-13 12:00:00 +08:00
|
|
|
|
|
|
|
public enum PlacementState
|
|
|
|
{
|
|
|
|
Hidden,
|
|
|
|
Shown,
|
|
|
|
}
|
2018-10-03 15:27:26 +08:00
|
|
|
}
|