Reset osu! triangle pieces on hitobject application

This commit is contained in:
smoogipoo
2020-11-17 13:06:52 +09:00
parent 3bcf9c255a
commit c101f32db8
3 changed files with 58 additions and 3 deletions

View File

@ -13,6 +13,11 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
{ {
public class CirclePiece : CompositeDrawable public class CirclePiece : CompositeDrawable
{ {
[Resolved]
private DrawableHitObject drawableObject { get; set; }
private TrianglesPiece triangles;
public CirclePiece() public CirclePiece()
{ {
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2); Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
@ -26,7 +31,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(TextureStore textures, DrawableHitObject drawableHitObject) private void load(TextureStore textures)
{ {
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
@ -36,13 +41,32 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
Origin = Anchor.Centre, Origin = Anchor.Centre,
Texture = textures.Get(@"Gameplay/osu/disc"), Texture = textures.Get(@"Gameplay/osu/disc"),
}, },
new TrianglesPiece(drawableHitObject.GetHashCode()) triangles = new TrianglesPiece
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Blending = BlendingParameters.Additive, Blending = BlendingParameters.Additive,
Alpha = 0.5f, Alpha = 0.5f,
} }
}; };
drawableObject.HitObjectApplied += onHitObjectApplied;
onHitObjectApplied(drawableObject);
}
private void onHitObjectApplied(DrawableHitObject obj)
{
if (obj.HitObject == null)
return;
triangles.Reset((int)obj.HitObject.StartTime);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (drawableObject != null)
drawableObject.HitObjectApplied -= onHitObjectApplied;
} }
} }
} }

View File

@ -1,14 +1,21 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects.Drawables;
using osuTK; using osuTK;
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
{ {
public class ExplodePiece : Container public class ExplodePiece : Container
{ {
[Resolved]
private DrawableHitObject drawableObject { get; set; }
private TrianglesPiece triangles;
public ExplodePiece() public ExplodePiece()
{ {
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2); Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
@ -18,13 +25,36 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
Blending = BlendingParameters.Additive; Blending = BlendingParameters.Additive;
Alpha = 0; Alpha = 0;
}
Child = new TrianglesPiece [BackgroundDependencyLoader]
private void load()
{
Child = triangles = new TrianglesPiece
{ {
Blending = BlendingParameters.Additive, Blending = BlendingParameters.Additive,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Alpha = 0.2f, Alpha = 0.2f,
}; };
drawableObject.HitObjectApplied += onHitObjectApplied;
onHitObjectApplied(drawableObject);
}
private void onHitObjectApplied(DrawableHitObject obj)
{
if (obj.HitObject == null)
return;
triangles.Reset((int)obj.HitObject.StartTime);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (drawableObject != null)
drawableObject.HitObjectApplied -= onHitObjectApplied;
} }
} }
} }

View File

@ -7,6 +7,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
{ {
public class TrianglesPiece : Triangles public class TrianglesPiece : Triangles
{ {
protected override bool CreateNewTriangles => false;
protected override float SpawnRatio => 0.5f; protected override float SpawnRatio => 0.5f;
public TrianglesPiece(int? seed = null) public TrianglesPiece(int? seed = null)