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-25 10:11:57 +00:00
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Timing;
|
|
|
|
using osu.Game.Rulesets.Edit;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2020-05-22 09:23:24 +00:00
|
|
|
using osu.Game.Screens.Edit;
|
2018-11-06 09:28:22 +00:00
|
|
|
using osu.Game.Screens.Edit.Compose;
|
2018-10-25 10:11:57 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
|
|
|
[Cached(Type = typeof(IPlacementHandler))]
|
2020-04-13 06:31:54 +00:00
|
|
|
public abstract class PlacementBlueprintTestScene : OsuManualInputManagerTestScene, IPlacementHandler
|
2018-10-25 10:11:57 +00:00
|
|
|
{
|
2020-04-13 06:31:54 +00:00
|
|
|
protected readonly Container HitObjectContainer;
|
2018-11-06 09:04:03 +00:00
|
|
|
private PlacementBlueprint currentBlueprint;
|
2018-10-25 10:11:57 +00:00
|
|
|
|
2019-05-14 19:37:25 +00:00
|
|
|
protected PlacementBlueprintTestScene()
|
2018-10-25 10:11:57 +00:00
|
|
|
{
|
2019-10-03 07:28:56 +00:00
|
|
|
Add(HitObjectContainer = CreateHitObjectContainer().With(c => c.Clock = new FramedClock(new StopwatchClock())));
|
2018-10-25 10:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2019-06-04 03:08:23 +00:00
|
|
|
Beatmap.Value.BeatmapInfo.BaseDifficulty.CircleSize = 2;
|
2018-10-25 10:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
|
|
|
{
|
|
|
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
2020-05-22 09:23:24 +00:00
|
|
|
dependencies.CacheAs(new EditorClock());
|
2018-10-25 10:11:57 +00:00
|
|
|
|
|
|
|
return dependencies;
|
|
|
|
}
|
|
|
|
|
2019-10-03 07:28:56 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2020-04-13 06:31:54 +00:00
|
|
|
ResetPlacement();
|
2019-10-03 07:28:56 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 10:11:57 +00:00
|
|
|
public void BeginPlacement(HitObject hitObject)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-07 09:02:48 +00:00
|
|
|
public void EndPlacement(HitObject hitObject, bool commit)
|
2018-10-25 10:11:57 +00:00
|
|
|
{
|
2020-02-07 09:02:48 +00:00
|
|
|
if (commit)
|
|
|
|
AddHitObject(CreateHitObject(hitObject));
|
2018-10-25 10:11:57 +00:00
|
|
|
|
2020-04-13 06:31:54 +00:00
|
|
|
ResetPlacement();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void ResetPlacement()
|
|
|
|
{
|
|
|
|
if (currentBlueprint != null)
|
|
|
|
Remove(currentBlueprint);
|
2018-11-07 06:04:48 +00:00
|
|
|
Add(currentBlueprint = CreateBlueprint());
|
2018-10-25 10:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Delete(HitObject hitObject)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-04-13 06:31:54 +00:00
|
|
|
protected override void Update()
|
2019-10-03 07:28:56 +00:00
|
|
|
{
|
2020-04-13 06:31:54 +00:00
|
|
|
base.Update();
|
|
|
|
|
2020-11-26 10:16:18 +00:00
|
|
|
currentBlueprint.UpdateTimeAndPosition(SnapForBlueprint(currentBlueprint));
|
2019-10-03 07:28:56 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 05:25:37 +00:00
|
|
|
protected virtual SnapResult SnapForBlueprint(PlacementBlueprint blueprint) =>
|
|
|
|
new SnapResult(InputManager.CurrentState.Mouse.Position, null);
|
|
|
|
|
2019-10-03 07:28:56 +00:00
|
|
|
public override void Add(Drawable drawable)
|
|
|
|
{
|
|
|
|
base.Add(drawable);
|
|
|
|
|
|
|
|
if (drawable is PlacementBlueprint blueprint)
|
|
|
|
{
|
|
|
|
blueprint.Show();
|
2020-11-26 10:16:18 +00:00
|
|
|
blueprint.UpdateTimeAndPosition(SnapForBlueprint(blueprint));
|
2019-10-03 07:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-12 10:41:06 +00:00
|
|
|
|
|
|
|
protected virtual void AddHitObject(DrawableHitObject hitObject) => HitObjectContainer.Add(hitObject);
|
|
|
|
|
2019-10-03 07:28:56 +00:00
|
|
|
protected virtual Container CreateHitObjectContainer() => new Container { RelativeSizeAxes = Axes.Both };
|
|
|
|
|
2018-10-25 10:11:57 +00:00
|
|
|
protected abstract DrawableHitObject CreateHitObject(HitObject hitObject);
|
2018-11-07 06:04:48 +00:00
|
|
|
protected abstract PlacementBlueprint CreateBlueprint();
|
2018-10-25 10:11:57 +00:00
|
|
|
}
|
|
|
|
}
|