1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 16:12:54 +08:00

Allow PulpFormation to update formation dynamically

Pulps are lazily allocated but never deallocated for a DrawableFruit
This commit is contained in:
ekrctb 2020-12-07 13:56:22 +09:00
parent 0d73bf8488
commit b8f1c499a4
9 changed files with 95 additions and 254 deletions

View File

@ -1,30 +0,0 @@
// 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.
using osu.Framework.Graphics;
using osuTK;
namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
{
public class BananaPiece : PulpFormation
{
public BananaPiece()
{
InternalChildren = new Drawable[]
{
new Pulp
{
AccentColour = { BindTarget = AccentColour },
Size = new Vector2(SMALL_PULP),
Y = -0.3f
},
new Pulp
{
AccentColour = { BindTarget = AccentColour },
Size = new Vector2(LARGE_PULP_4 * 0.8f, LARGE_PULP_4 * 2.5f),
Y = 0.05f,
},
};
}
}
}

View File

@ -18,6 +18,17 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
public FruitPiece()
{
RelativeSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
new FruitPulpFormation
{
AccentColour = { BindTarget = AccentColour },
VisualRepresentation = { BindTarget = VisualRepresentation }
},
BorderPiece = new BorderPiece(),
HyperBorderPiece = new HyperBorderPiece()
};
}
protected override void LoadComplete()
@ -29,41 +40,6 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
var fruit = (DrawableFruit)DrawableHitObject;
VisualRepresentation.BindTo(fruit.VisualRepresentation);
}
VisualRepresentation.BindValueChanged(_ => recreateChildren(), true);
}
private void recreateChildren()
{
ClearInternal();
AddInternal(getFruitFor(VisualRepresentation.Value));
if (DrawableHitObject != null)
AddInternal(BorderPiece = new BorderPiece());
if (HyperDash.Value)
AddInternal(HyperBorderPiece = new HyperBorderPiece());
}
private Drawable getFruitFor(FruitVisualRepresentation representation)
{
switch (representation)
{
case FruitVisualRepresentation.Pear:
return new PearPiece();
case FruitVisualRepresentation.Grape:
return new GrapePiece();
case FruitVisualRepresentation.Pineapple:
return new PineapplePiece();
case FruitVisualRepresentation.Raspberry:
return new RaspberryPiece();
}
return Empty();
}
}
}

View File

@ -0,0 +1,63 @@
// 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.
using osu.Framework.Bindables;
using osuTK;
namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
{
public class FruitPulpFormation : PulpFormation
{
public readonly Bindable<FruitVisualRepresentation> VisualRepresentation = new Bindable<FruitVisualRepresentation>();
protected override void LoadComplete()
{
base.LoadComplete();
VisualRepresentation.BindValueChanged(setFormation, true);
}
private void setFormation(ValueChangedEvent<FruitVisualRepresentation> visualRepresentation)
{
Clear();
switch (visualRepresentation.NewValue)
{
case FruitVisualRepresentation.Pear:
Add(new Vector2(0, -0.33f), new Vector2(SMALL_PULP));
Add(PositionAt(60, DISTANCE_FROM_CENTRE_3), new Vector2(LARGE_PULP_3));
Add(PositionAt(180, DISTANCE_FROM_CENTRE_3), new Vector2(LARGE_PULP_3));
Add(PositionAt(300, DISTANCE_FROM_CENTRE_3), new Vector2(LARGE_PULP_3));
break;
case FruitVisualRepresentation.Grape:
Add(new Vector2(0, -0.25f), new Vector2(SMALL_PULP));
Add(PositionAt(0, DISTANCE_FROM_CENTRE_3), new Vector2(LARGE_PULP_3));
Add(PositionAt(120, DISTANCE_FROM_CENTRE_3), new Vector2(LARGE_PULP_3));
Add(PositionAt(240, DISTANCE_FROM_CENTRE_3), new Vector2(LARGE_PULP_3));
break;
case FruitVisualRepresentation.Pineapple:
Add(new Vector2(0, -0.3f), new Vector2(SMALL_PULP));
Add(PositionAt(45, DISTANCE_FROM_CENTRE_4), new Vector2(LARGE_PULP_4));
Add(PositionAt(135, DISTANCE_FROM_CENTRE_4), new Vector2(LARGE_PULP_4));
Add(PositionAt(225, DISTANCE_FROM_CENTRE_4), new Vector2(LARGE_PULP_4));
Add(PositionAt(315, DISTANCE_FROM_CENTRE_4), new Vector2(LARGE_PULP_4));
break;
case FruitVisualRepresentation.Raspberry:
Add(new Vector2(0, -0.34f), new Vector2(SMALL_PULP));
Add(PositionAt(0, DISTANCE_FROM_CENTRE_4), new Vector2(LARGE_PULP_4));
Add(PositionAt(90, DISTANCE_FROM_CENTRE_4), new Vector2(LARGE_PULP_4));
Add(PositionAt(180, DISTANCE_FROM_CENTRE_4), new Vector2(LARGE_PULP_4));
Add(PositionAt(270, DISTANCE_FROM_CENTRE_4), new Vector2(LARGE_PULP_4));
break;
case FruitVisualRepresentation.Banana:
Add(new Vector2(0, -0.3f), new Vector2(SMALL_PULP));
Add(new Vector2(0, 0.05f), new Vector2(LARGE_PULP_4 * 0.8f, LARGE_PULP_4 * 2.5f));
break;
}
}
}
}

View File

@ -1,42 +0,0 @@
// 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.
using osu.Framework.Graphics;
using osuTK;
namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
{
public class GrapePiece : PulpFormation
{
public GrapePiece()
{
InternalChildren = new Drawable[]
{
new Pulp
{
AccentColour = { BindTarget = AccentColour },
Size = new Vector2(SMALL_PULP),
Y = -0.25f,
},
new Pulp
{
AccentColour = { BindTarget = AccentColour },
Size = new Vector2(LARGE_PULP_3),
Position = PositionAt(0, DISTANCE_FROM_CENTRE_3),
},
new Pulp
{
AccentColour = { BindTarget = AccentColour },
Size = new Vector2(LARGE_PULP_3),
Position = PositionAt(120, DISTANCE_FROM_CENTRE_3),
},
new Pulp
{
Size = new Vector2(LARGE_PULP_3),
AccentColour = { BindTarget = AccentColour },
Position = PositionAt(240, DISTANCE_FROM_CENTRE_3),
},
};
}
}
}

View File

@ -1,42 +0,0 @@
// 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.
using osu.Framework.Graphics;
using osuTK;
namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
{
public class PearPiece : PulpFormation
{
public PearPiece()
{
InternalChildren = new Drawable[]
{
new Pulp
{
AccentColour = { BindTarget = AccentColour },
Size = new Vector2(SMALL_PULP),
Y = -0.33f,
},
new Pulp
{
AccentColour = { BindTarget = AccentColour },
Size = new Vector2(LARGE_PULP_3),
Position = PositionAt(60, DISTANCE_FROM_CENTRE_3),
},
new Pulp
{
AccentColour = { BindTarget = AccentColour },
Size = new Vector2(LARGE_PULP_3),
Position = PositionAt(180, DISTANCE_FROM_CENTRE_3),
},
new Pulp
{
Size = new Vector2(LARGE_PULP_3),
AccentColour = { BindTarget = AccentColour },
Position = PositionAt(300, DISTANCE_FROM_CENTRE_3),
},
};
}
}
}

View File

@ -1,48 +0,0 @@
// 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.
using osu.Framework.Graphics;
using osuTK;
namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
{
public class PineapplePiece : PulpFormation
{
public PineapplePiece()
{
InternalChildren = new Drawable[]
{
new Pulp
{
AccentColour = { BindTarget = AccentColour },
Size = new Vector2(SMALL_PULP),
Y = -0.3f,
},
new Pulp
{
AccentColour = { BindTarget = AccentColour },
Size = new Vector2(LARGE_PULP_4),
Position = PositionAt(45, DISTANCE_FROM_CENTRE_4),
},
new Pulp
{
AccentColour = { BindTarget = AccentColour },
Size = new Vector2(LARGE_PULP_4),
Position = PositionAt(135, DISTANCE_FROM_CENTRE_4),
},
new Pulp
{
AccentColour = { BindTarget = AccentColour },
Size = new Vector2(LARGE_PULP_4),
Position = PositionAt(225, DISTANCE_FROM_CENTRE_4),
},
new Pulp
{
Size = new Vector2(LARGE_PULP_4),
AccentColour = { BindTarget = AccentColour },
Position = PositionAt(315, DISTANCE_FROM_CENTRE_4),
},
};
}
}
}

View File

@ -12,6 +12,8 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
{
public class Pulp : Circle
{
public readonly Bindable<Color4> AccentColour = new Bindable<Color4>();
public Pulp()
{
RelativePositionAxes = Axes.Both;
@ -22,8 +24,6 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
Colour = Color4.White.Opacity(0.9f);
}
public readonly Bindable<Color4> AccentColour = new Bindable<Color4>();
protected override void LoadComplete()
{
base.LoadComplete();

View File

@ -2,11 +2,9 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects.Drawables;
using osuTK;
using osuTK.Graphics;
@ -14,7 +12,7 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
{
public abstract class PulpFormation : CompositeDrawable
{
protected readonly IBindable<Color4> AccentColour = new Bindable<Color4>();
public readonly Bindable<Color4> AccentColour = new Bindable<Color4>();
protected const float LARGE_PULP_3 = 16f * FruitPiece.RADIUS_ADJUST;
protected const float DISTANCE_FROM_CENTRE_3 = 0.15f;
@ -24,6 +22,8 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
protected const float SMALL_PULP = LARGE_PULP_3 / 2;
private int numPulps;
protected PulpFormation()
{
RelativeSizeAxes = Axes.Both;
@ -33,11 +33,23 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
distance * MathF.Sin(angle * MathF.PI / 180),
distance * MathF.Cos(angle * MathF.PI / 180));
[BackgroundDependencyLoader]
private void load(DrawableHitObject drawableObject)
protected void Clear()
{
DrawableCatchHitObject drawableCatchObject = (DrawableCatchHitObject)drawableObject;
AccentColour.BindTo(drawableCatchObject.AccentColour);
for (; numPulps > 0; numPulps--)
InternalChildren[numPulps - 1].Alpha = 0;
}
protected void Add(Vector2 position, Vector2 size)
{
if (numPulps == InternalChildren.Count)
AddInternal(new Pulp { AccentColour = { BindTarget = AccentColour } });
var pulp = InternalChildren[numPulps];
pulp.Position = position;
pulp.Size = size;
pulp.Alpha = 1;
numPulps++;
}
}
}

View File

@ -1,48 +0,0 @@
// 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.
using osu.Framework.Graphics;
using osuTK;
namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
{
public class RaspberryPiece : PulpFormation
{
public RaspberryPiece()
{
InternalChildren = new Drawable[]
{
new Pulp
{
AccentColour = { BindTarget = AccentColour },
Size = new Vector2(SMALL_PULP),
Y = -0.34f,
},
new Pulp
{
AccentColour = { BindTarget = AccentColour },
Size = new Vector2(LARGE_PULP_4),
Position = PositionAt(0, DISTANCE_FROM_CENTRE_4),
},
new Pulp
{
AccentColour = { BindTarget = AccentColour },
Size = new Vector2(LARGE_PULP_4),
Position = PositionAt(90, DISTANCE_FROM_CENTRE_4),
},
new Pulp
{
AccentColour = { BindTarget = AccentColour },
Size = new Vector2(LARGE_PULP_4),
Position = PositionAt(180, DISTANCE_FROM_CENTRE_4),
},
new Pulp
{
Size = new Vector2(LARGE_PULP_4),
AccentColour = { BindTarget = AccentColour },
Position = PositionAt(270, DISTANCE_FROM_CENTRE_4),
},
};
}
}
}