2018-10-03 07:27:26 +00:00
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
2018-11-13 04:00:00 +00:00
|
|
|
using System;
|
|
|
|
using osu.Framework;
|
2018-10-03 07:27:26 +00:00
|
|
|
using osu.Framework.Allocation;
|
2018-10-17 09:36:47 +00:00
|
|
|
using osu.Framework.Configuration;
|
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;
|
|
|
|
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;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2018-11-06 09:28:22 +00:00
|
|
|
using osu.Game.Screens.Edit.Compose;
|
2018-10-03 07:27:26 +00:00
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
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>
|
2018-11-13 04:00:00 +00:00
|
|
|
public abstract class PlacementBlueprint : CompositeDrawable, IStateful<PlacementState>, IRequireHighFrequencyMousePosition
|
2018-10-03 07:27:26 +00:00
|
|
|
{
|
2018-11-13 04:00:00 +00: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 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
|
|
|
|
|
|
|
Alpha = 0;
|
2018-10-03 07:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2018-10-17 09:36:47 +00:00
|
|
|
private void load(IBindableBeatmap 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
|
|
|
}
|
|
|
|
|
2018-11-13 04:00:00 +00:00
|
|
|
private PlacementState state;
|
|
|
|
|
|
|
|
public PlacementState State
|
|
|
|
{
|
|
|
|
get => state;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (state == value)
|
|
|
|
return;
|
|
|
|
state = value;
|
|
|
|
|
|
|
|
if (state == PlacementState.Shown)
|
|
|
|
Show();
|
|
|
|
else
|
|
|
|
Hide();
|
|
|
|
|
|
|
|
StateChanged?.Invoke(value);
|
|
|
|
}
|
|
|
|
}
|
2018-10-17 05:37:39 +00:00
|
|
|
|
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>
|
2018-10-17 05:37:39 +00:00
|
|
|
protected void BeginPlacement()
|
|
|
|
{
|
2018-10-17 06:46:30 +00:00
|
|
|
placementHandler.BeginPlacement(HitObject);
|
2018-11-13 03:52:04 +00:00
|
|
|
PlacementBegun = true;
|
2018-10-17 05:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Signals that the placement of <see cref="HitObject"/> has finished.
|
2018-11-06 09:04:03 +00:00
|
|
|
/// This will destroy this <see cref="PlacementBlueprint"/>, and add the <see cref="HitObject"/> to the <see cref="Beatmap"/>.
|
2018-10-17 05:37:39 +00:00
|
|
|
/// </summary>
|
|
|
|
protected void EndPlacement()
|
|
|
|
{
|
2018-11-13 03:52:04 +00:00
|
|
|
if (!PlacementBegun)
|
2018-10-17 05:37:39 +00:00
|
|
|
BeginPlacement();
|
2018-10-17 06:46:30 +00:00
|
|
|
placementHandler.EndPlacement(HitObject);
|
2018-10-17 05:37:39 +00:00
|
|
|
}
|
2018-10-03 07:27:26 +00:00
|
|
|
|
2018-10-17 09:36:47 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Invokes <see cref="HitObject.ApplyDefaults"/>, refreshing <see cref="HitObject.NestedHitObjects"/> and parameters for the <see cref="HitObject"/>.
|
|
|
|
/// </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;
|
2018-10-03 07:27:26 +00:00
|
|
|
case MouseEvent _:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-13 04:00:00 +00:00
|
|
|
|
|
|
|
public enum PlacementState
|
|
|
|
{
|
|
|
|
Hidden,
|
|
|
|
Shown,
|
|
|
|
}
|
2018-10-03 07:27:26 +00:00
|
|
|
}
|