Move catcher trail generation logic to CatcherArea

This commit is contained in:
ekrctb
2021-07-27 18:59:55 +09:00
parent de68fd12b3
commit da69867fd4
7 changed files with 48 additions and 57 deletions

View File

@ -41,7 +41,7 @@ namespace osu.Game.Rulesets.Catch.Tests
var skin = new TestSkin { FlipCatcherPlate = flip }; var skin = new TestSkin { FlipCatcherPlate = flip };
container.Child = new SkinProvidingContainer(skin) container.Child = new SkinProvidingContainer(skin)
{ {
Child = catcher = new Catcher(new CatcherTrailDisplay(), new DroppedObjectContainer()) Child = catcher = new Catcher(new DroppedObjectContainer())
{ {
Anchor = Anchor.Centre Anchor = Anchor.Centre
} }

View File

@ -31,8 +31,6 @@ namespace osu.Game.Rulesets.Catch.Tests
[Resolved] [Resolved]
private OsuConfigManager config { get; set; } private OsuConfigManager config { get; set; }
private CatcherTrailDisplay trailDisplay;
private DroppedObjectContainer droppedObjectContainer; private DroppedObjectContainer droppedObjectContainer;
private TestCatcher catcher; private TestCatcher catcher;
@ -45,7 +43,6 @@ namespace osu.Game.Rulesets.Catch.Tests
CircleSize = 0, CircleSize = 0,
}; };
trailDisplay = new CatcherTrailDisplay();
droppedObjectContainer = new DroppedObjectContainer(); droppedObjectContainer = new DroppedObjectContainer();
Child = new Container Child = new Container
@ -54,8 +51,7 @@ namespace osu.Game.Rulesets.Catch.Tests
Children = new Drawable[] Children = new Drawable[]
{ {
droppedObjectContainer, droppedObjectContainer,
catcher = new TestCatcher(trailDisplay, droppedObjectContainer, difficulty), catcher = new TestCatcher(droppedObjectContainer, difficulty),
trailDisplay,
} }
}; };
}); });
@ -294,8 +290,8 @@ namespace osu.Game.Rulesets.Catch.Tests
{ {
public IEnumerable<CaughtObject> CaughtObjects => this.ChildrenOfType<CaughtObject>(); public IEnumerable<CaughtObject> CaughtObjects => this.ChildrenOfType<CaughtObject>();
public TestCatcher(CatcherTrailDisplay trails, DroppedObjectContainer droppedObjectTarget, BeatmapDifficulty difficulty) public TestCatcher(DroppedObjectContainer droppedObjectTarget, BeatmapDifficulty difficulty)
: base(trails, droppedObjectTarget, difficulty) : base(droppedObjectTarget, difficulty)
{ {
} }
} }

View File

@ -121,13 +121,10 @@ namespace osu.Game.Rulesets.Catch.Tests
{ {
public TestCatcherArea(BeatmapDifficulty beatmapDifficulty) public TestCatcherArea(BeatmapDifficulty beatmapDifficulty)
{ {
var trailDisplay = new CatcherTrailDisplay { Depth = -1 };
Add(trailDisplay);
var droppedObjectContainer = new DroppedObjectContainer(); var droppedObjectContainer = new DroppedObjectContainer();
Add(droppedObjectContainer); Add(droppedObjectContainer);
Catcher = new Catcher(trailDisplay, droppedObjectContainer, beatmapDifficulty) Catcher = new Catcher(droppedObjectContainer, beatmapDifficulty)
{ {
X = CatchPlayfield.CENTER_X X = CatchPlayfield.CENTER_X
}; };

View File

@ -118,19 +118,19 @@ namespace osu.Game.Rulesets.Catch.Tests
AddStep("create hyper-dashing catcher", () => AddStep("create hyper-dashing catcher", () =>
{ {
trails = new CatcherTrailDisplay(); CatcherArea catcherArea;
Child = setupSkinHierarchy(new Container Child = setupSkinHierarchy(new Container
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Children = new Drawable[] Child = catcherArea = new CatcherArea
{ {
catcher = new Catcher(trails, new DroppedObjectContainer()) Catcher = catcher = new Catcher(new DroppedObjectContainer())
{ {
Scale = new Vector2(4) Scale = new Vector2(4)
}, }
trails
} }
}, skin); }, skin);
trails = catcherArea.CatcherTrails;
}); });
AddStep("start hyper-dash", () => AddStep("start hyper-dash", () =>

View File

@ -44,14 +44,9 @@ namespace osu.Game.Rulesets.Catch.UI
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
var trailDisplay = new CatcherTrailDisplay
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.TopLeft
};
var droppedObjectContainer = new DroppedObjectContainer(); var droppedObjectContainer = new DroppedObjectContainer();
Catcher = new Catcher(trailDisplay, droppedObjectContainer, difficulty) Catcher = new Catcher(droppedObjectContainer, difficulty)
{ {
X = CENTER_X X = CENTER_X
}; };
@ -69,7 +64,6 @@ namespace osu.Game.Rulesets.Catch.UI
Origin = Anchor.TopLeft, Origin = Anchor.TopLeft,
Catcher = Catcher, Catcher = Catcher,
}, },
trailDisplay,
HitObjectContainer, HitObjectContainer,
}); });

View File

@ -71,11 +71,6 @@ namespace osu.Game.Rulesets.Catch.UI
/// </summary> /// </summary>
private const float caught_fruit_scale_adjust = 0.5f; private const float caught_fruit_scale_adjust = 0.5f;
/// <summary>
/// Contains trails and afterimages (also called "end glow" in code) of the catcher.
/// </summary>
private readonly CatcherTrailDisplay trails;
/// <summary> /// <summary>
/// Contains caught objects on the plate. /// Contains caught objects on the plate.
/// </summary> /// </summary>
@ -102,6 +97,8 @@ namespace osu.Game.Rulesets.Catch.UI
/// </summary> /// </summary>
public Direction VisualDirection { get; set; } = Direction.Right; public Direction VisualDirection { get; set; } = Direction.Right;
public Vector2 BodyScale => Scale * body.Scale;
/// <summary> /// <summary>
/// Whether the contents of the catcher plate should be visually flipped when the catcher direction is changed. /// Whether the contents of the catcher plate should be visually flipped when the catcher direction is changed.
/// </summary> /// </summary>
@ -127,9 +124,8 @@ namespace osu.Game.Rulesets.Catch.UI
private readonly DrawablePool<CaughtBanana> caughtBananaPool; private readonly DrawablePool<CaughtBanana> caughtBananaPool;
private readonly DrawablePool<CaughtDroplet> caughtDropletPool; private readonly DrawablePool<CaughtDroplet> caughtDropletPool;
public Catcher([NotNull] CatcherTrailDisplay trails, [NotNull] DroppedObjectContainer droppedObjectTarget, BeatmapDifficulty difficulty = null) public Catcher([NotNull] DroppedObjectContainer droppedObjectTarget, BeatmapDifficulty difficulty = null)
{ {
this.trails = trails;
this.droppedObjectTarget = droppedObjectTarget; this.droppedObjectTarget = droppedObjectTarget;
Origin = Anchor.TopCentre; Origin = Anchor.TopCentre;
@ -292,12 +288,9 @@ namespace osu.Game.Rulesets.Catch.UI
hyperDashTargetPosition = targetPosition; hyperDashTargetPosition = targetPosition;
if (!wasHyperDashing) if (!wasHyperDashing)
{
trails.DisplayEndGlow(CurrentState, X, Scale * body.Scale);
runHyperDashStateTransition(true); runHyperDashStateTransition(true);
} }
} }
}
/// <summary> /// <summary>
/// Drop any fruit off the plate. /// Drop any fruit off the plate.
@ -342,15 +335,6 @@ namespace osu.Game.Rulesets.Catch.UI
X = hyperDashTargetPosition; X = hyperDashTargetPosition;
SetHyperDashState(); SetHyperDashState();
} }
if (Dashing || HyperDashing)
{
double lastTrailTime = trails.LastDashTrail?.LifetimeStart ?? double.NegativeInfinity;
double generationInterval = HyperDashing ? 25 : 50;
if (Time.Current - lastTrailTime >= generationInterval)
trails.DisplayDashTrail(CurrentState, X, Scale * body.Scale, HyperDashing);
}
} }
private void placeCaughtObject(DrawablePalpableCatchHitObject drawableObject, Vector2 position) private void placeCaughtObject(DrawablePalpableCatchHitObject drawableObject, Vector2 position)

View File

@ -25,14 +25,12 @@ namespace osu.Game.Rulesets.Catch.UI
public Catcher Catcher public Catcher Catcher
{ {
get => catcher; get => catcher;
set set => catcherContainer.Child = catcher = value;
{ }
if (catcher != null)
Remove(catcher);
Add(catcher = value); internal CatcherTrailDisplay CatcherTrails { get; }
}
} private readonly Container<Catcher> catcherContainer;
private readonly CatchComboDisplay comboDisplay; private readonly CatchComboDisplay comboDisplay;
@ -45,13 +43,20 @@ namespace osu.Game.Rulesets.Catch.UI
/// </summary> /// </summary>
private int currentDirection; private int currentDirection;
// TODO: support replay rewind
private bool lastHyperDashState;
/// <remarks> /// <remarks>
/// <see cref="Catcher"/> must be set before loading. /// <see cref="Catcher"/> must be set before loading.
/// </remarks> /// </remarks>
public CatcherArea() public CatcherArea()
{ {
Size = new Vector2(CatchPlayfield.WIDTH, Catcher.BASE_SIZE); Size = new Vector2(CatchPlayfield.WIDTH, Catcher.BASE_SIZE);
Child = comboDisplay = new CatchComboDisplay Children = new Drawable[]
{
catcherContainer = new Container<Catcher> { RelativeSizeAxes = Axes.Both },
CatcherTrails = new CatcherTrailDisplay(),
comboDisplay = new CatchComboDisplay
{ {
RelativeSizeAxes = Axes.None, RelativeSizeAxes = Axes.None,
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
@ -59,6 +64,7 @@ namespace osu.Game.Rulesets.Catch.UI
Origin = Anchor.Centre, Origin = Anchor.Centre,
Margin = new MarginPadding { Bottom = 350f }, Margin = new MarginPadding { Bottom = 350f },
X = CatchPlayfield.CENTER_X X = CatchPlayfield.CENTER_X
}
}; };
} }
@ -102,6 +108,20 @@ namespace osu.Game.Rulesets.Catch.UI
base.UpdateAfterChildren(); base.UpdateAfterChildren();
comboDisplay.X = Catcher.X; comboDisplay.X = Catcher.X;
if (!lastHyperDashState && Catcher.HyperDashing && Time.Elapsed > 0)
CatcherTrails.DisplayEndGlow(Catcher.CurrentState, Catcher.X, Catcher.BodyScale);
if (Catcher.Dashing || Catcher.HyperDashing)
{
double lastTrailTime = CatcherTrails.LastDashTrail?.LifetimeStart ?? double.NegativeInfinity;
double generationInterval = Catcher.HyperDashing ? 25 : 50;
if (Time.Current - lastTrailTime >= generationInterval)
CatcherTrails.DisplayDashTrail(Catcher.CurrentState, Catcher.X, Catcher.BodyScale, Catcher.HyperDashing);
}
lastHyperDashState = Catcher.HyperDashing;
} }
public void SetCatcherPosition(float X) public void SetCatcherPosition(float X)