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-25 18:11:57 +08:00
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2018-10-25 18:11:57 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Timing;
|
2021-10-02 11:34:29 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2018-10-25 18:11:57 +08:00
|
|
|
using osu.Game.Rulesets.Edit;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2020-05-22 17:23:24 +08:00
|
|
|
using osu.Game.Screens.Edit;
|
2018-11-06 17:28:22 +08:00
|
|
|
using osu.Game.Screens.Edit.Compose;
|
2018-10-25 18:11:57 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public abstract partial class PlacementBlueprintTestScene : OsuManualInputManagerTestScene, IPlacementHandler
|
2018-10-25 18:11:57 +08:00
|
|
|
{
|
2020-04-13 14:31:54 +08:00
|
|
|
protected readonly Container HitObjectContainer;
|
2024-09-23 22:33:36 +08:00
|
|
|
protected HitObjectPlacementBlueprint CurrentBlueprint { get; private set; }
|
2018-10-25 18:11:57 +08:00
|
|
|
|
2019-05-15 03:37:25 +08:00
|
|
|
protected PlacementBlueprintTestScene()
|
2018-10-25 18:11:57 +08:00
|
|
|
{
|
2021-07-08 14:51:46 +08:00
|
|
|
base.Content.Add(HitObjectContainer = CreateHitObjectContainer().With(c => c.Clock = new FramedClock(new StopwatchClock())));
|
2018-10-25 18:11:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
|
|
|
{
|
|
|
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
2021-05-20 02:48:06 +08:00
|
|
|
|
2021-10-02 11:34:29 +08:00
|
|
|
var playable = GetPlayableBeatmap();
|
2022-08-17 14:40:01 +08:00
|
|
|
|
|
|
|
var editorClock = new EditorClock();
|
|
|
|
base.Content.Add(editorClock);
|
|
|
|
dependencies.CacheAs(editorClock);
|
|
|
|
|
|
|
|
var editorBeatmap = new EditorBeatmap(playable);
|
|
|
|
// Not adding to hierarchy as we don't satisfy its dependencies. Probably not good.
|
|
|
|
dependencies.CacheAs(editorBeatmap);
|
2021-05-20 02:48:06 +08:00
|
|
|
|
2018-10-25 18:11:57 +08:00
|
|
|
return dependencies;
|
|
|
|
}
|
|
|
|
|
2021-10-02 11:34:29 +08:00
|
|
|
protected virtual IBeatmap GetPlayableBeatmap()
|
|
|
|
{
|
|
|
|
var playable = Beatmap.Value.GetPlayableBeatmap(Beatmap.Value.BeatmapInfo.Ruleset);
|
|
|
|
playable.Difficulty.CircleSize = 2;
|
|
|
|
return playable;
|
|
|
|
}
|
|
|
|
|
2019-10-03 15:28:56 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2020-04-13 14:31:54 +08:00
|
|
|
ResetPlacement();
|
2019-10-03 15:28:56 +08:00
|
|
|
}
|
|
|
|
|
2018-10-25 18:11:57 +08:00
|
|
|
public void BeginPlacement(HitObject hitObject)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-07 17:02:48 +08:00
|
|
|
public void EndPlacement(HitObject hitObject, bool commit)
|
2018-10-25 18:11:57 +08:00
|
|
|
{
|
2020-02-07 17:02:48 +08:00
|
|
|
if (commit)
|
|
|
|
AddHitObject(CreateHitObject(hitObject));
|
2018-10-25 18:11:57 +08:00
|
|
|
|
2020-04-13 14:31:54 +08:00
|
|
|
ResetPlacement();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void ResetPlacement()
|
|
|
|
{
|
2021-07-08 15:36:41 +08:00
|
|
|
if (CurrentBlueprint != null)
|
2022-08-26 14:19:05 +08:00
|
|
|
Remove(CurrentBlueprint, true);
|
2021-07-08 15:36:41 +08:00
|
|
|
Add(CurrentBlueprint = CreateBlueprint());
|
2018-10-25 18:11:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Delete(HitObject hitObject)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-04-13 14:31:54 +08:00
|
|
|
protected override void Update()
|
2019-10-03 15:28:56 +08:00
|
|
|
{
|
2020-04-13 14:31:54 +08:00
|
|
|
base.Update();
|
|
|
|
|
2021-07-08 15:36:41 +08:00
|
|
|
CurrentBlueprint.UpdateTimeAndPosition(SnapForBlueprint(CurrentBlueprint));
|
2019-10-03 15:28:56 +08:00
|
|
|
}
|
|
|
|
|
2024-09-23 22:33:36 +08:00
|
|
|
protected virtual SnapResult SnapForBlueprint(HitObjectPlacementBlueprint blueprint) =>
|
2020-05-21 13:25:37 +08:00
|
|
|
new SnapResult(InputManager.CurrentState.Mouse.Position, null);
|
|
|
|
|
2019-10-03 15:28:56 +08:00
|
|
|
public override void Add(Drawable drawable)
|
|
|
|
{
|
|
|
|
base.Add(drawable);
|
|
|
|
|
2024-09-23 22:33:36 +08:00
|
|
|
if (drawable is HitObjectPlacementBlueprint blueprint)
|
2019-10-03 15:28:56 +08:00
|
|
|
{
|
|
|
|
blueprint.Show();
|
2020-11-26 18:16:18 +08:00
|
|
|
blueprint.UpdateTimeAndPosition(SnapForBlueprint(blueprint));
|
2019-10-03 15:28:56 +08:00
|
|
|
}
|
|
|
|
}
|
2018-11-12 18:41:06 +08:00
|
|
|
|
|
|
|
protected virtual void AddHitObject(DrawableHitObject hitObject) => HitObjectContainer.Add(hitObject);
|
|
|
|
|
2019-10-03 15:28:56 +08:00
|
|
|
protected virtual Container CreateHitObjectContainer() => new Container { RelativeSizeAxes = Axes.Both };
|
|
|
|
|
2018-10-25 18:11:57 +08:00
|
|
|
protected abstract DrawableHitObject CreateHitObject(HitObject hitObject);
|
2024-09-23 22:33:36 +08:00
|
|
|
protected abstract HitObjectPlacementBlueprint CreateBlueprint();
|
2018-10-25 18:11:57 +08:00
|
|
|
}
|
|
|
|
}
|