mirror of
https://github.com/ppy/osu
synced 2025-01-19 20:40:52 +00:00
Refactor catch default piece to allow reuse
But Fruit in-place update is still incomplete, as child drawables are recreated when reused.
This commit is contained in:
parent
d51d2c5331
commit
0d73bf8488
@ -28,10 +28,7 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
|
||||
{
|
||||
ScaleContainer.Child = new SkinnableDrawable(
|
||||
new CatchSkinComponent(CatchSkinComponents.Droplet),
|
||||
_ => new DropletPiece
|
||||
{
|
||||
HyperDash = { BindTarget = HyperDash },
|
||||
});
|
||||
_ => new DropletPiece());
|
||||
}
|
||||
|
||||
protected override void UpdateInitialTransforms()
|
||||
|
@ -36,11 +36,7 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
|
||||
|
||||
ScaleContainer.Child = new SkinnableDrawable(
|
||||
new CatchSkinComponent(this is DrawableBanana ? CatchSkinComponents.Banana : CatchSkinComponents.Fruit),
|
||||
_ => new FruitPiece
|
||||
{
|
||||
VisualRepresentation = { BindTarget = VisualRepresentation },
|
||||
HyperDash = { BindTarget = HyperDash },
|
||||
});
|
||||
_ => new FruitPiece());
|
||||
}
|
||||
|
||||
protected override void UpdateInitialTransforms()
|
||||
|
@ -0,0 +1,54 @@
|
||||
// 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 System;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
|
||||
{
|
||||
public class CatchHitObjectPiece : CompositeDrawable
|
||||
{
|
||||
public readonly Bindable<Color4> AccentColour = new Bindable<Color4>();
|
||||
public readonly Bindable<bool> HyperDash = new Bindable<bool>();
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private DrawableHitObject drawableHitObject { get; set; }
|
||||
|
||||
[CanBeNull]
|
||||
protected DrawablePalpableCatchHitObject DrawableHitObject => (DrawablePalpableCatchHitObject)drawableHitObject;
|
||||
|
||||
[CanBeNull]
|
||||
protected BorderPiece BorderPiece;
|
||||
|
||||
[CanBeNull]
|
||||
protected HyperBorderPiece HyperBorderPiece;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
if (DrawableHitObject != null)
|
||||
{
|
||||
AccentColour.BindTo(DrawableHitObject.AccentColour);
|
||||
HyperDash.BindTo(DrawableHitObject.HyperDash);
|
||||
}
|
||||
|
||||
HyperDash.BindValueChanged(hyper =>
|
||||
{
|
||||
if (HyperBorderPiece != null)
|
||||
HyperBorderPiece.Alpha = hyper.NewValue ? 1 : 0;
|
||||
}, true);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
if (BorderPiece != null && DrawableHitObject?.HitObject != null)
|
||||
BorderPiece.Alpha = (float)Math.Clamp((DrawableHitObject.HitObject.StartTime - Time.Current) / 500, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +1,26 @@
|
||||
// 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.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
|
||||
{
|
||||
public class DropletPiece : CompositeDrawable
|
||||
public class DropletPiece : CatchHitObjectPiece
|
||||
{
|
||||
public readonly Bindable<bool> HyperDash = new Bindable<bool>();
|
||||
|
||||
public DropletPiece()
|
||||
{
|
||||
Size = new Vector2(CatchHitObject.OBJECT_RADIUS / 2);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(DrawableHitObject drawableObject)
|
||||
{
|
||||
InternalChild = new Pulp
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
AccentColour = { BindTarget = drawableObject.AccentColour }
|
||||
new Pulp
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
AccentColour = { BindTarget = AccentColour }
|
||||
},
|
||||
HyperBorderPiece = new HyperDropletBorderPiece()
|
||||
};
|
||||
|
||||
if (HyperDash.Value)
|
||||
{
|
||||
AddInternal(new HyperDropletBorderPiece());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,12 @@
|
||||
// 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 System;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
|
||||
namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
|
||||
{
|
||||
internal class FruitPiece : CompositeDrawable
|
||||
internal class FruitPiece : CatchHitObjectPiece
|
||||
{
|
||||
/// <summary>
|
||||
/// Because we're adding a border around the fruit, we need to scale down some.
|
||||
@ -19,38 +14,36 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
|
||||
public const float RADIUS_ADJUST = 1.1f;
|
||||
|
||||
public readonly Bindable<FruitVisualRepresentation> VisualRepresentation = new Bindable<FruitVisualRepresentation>();
|
||||
public readonly Bindable<bool> HyperDash = new Bindable<bool>();
|
||||
|
||||
[CanBeNull]
|
||||
private DrawableCatchHitObject drawableHitObject;
|
||||
|
||||
[CanBeNull]
|
||||
private BorderPiece borderPiece;
|
||||
|
||||
public FruitPiece()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(permitNulls: true)]
|
||||
private void load([CanBeNull] DrawableHitObject drawable)
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
drawableHitObject = (DrawableCatchHitObject)drawable;
|
||||
base.LoadComplete();
|
||||
|
||||
if (DrawableHitObject != null)
|
||||
{
|
||||
var fruit = (DrawableFruit)DrawableHitObject;
|
||||
VisualRepresentation.BindTo(fruit.VisualRepresentation);
|
||||
}
|
||||
|
||||
VisualRepresentation.BindValueChanged(_ => recreateChildren(), true);
|
||||
}
|
||||
|
||||
private void recreateChildren()
|
||||
{
|
||||
ClearInternal();
|
||||
|
||||
AddInternal(getFruitFor(VisualRepresentation.Value));
|
||||
|
||||
// if it is not part of a DHO, the border is always invisible.
|
||||
if (drawableHitObject != null)
|
||||
AddInternal(borderPiece = new BorderPiece());
|
||||
if (DrawableHitObject != null)
|
||||
AddInternal(BorderPiece = new BorderPiece());
|
||||
|
||||
if (HyperDash.Value)
|
||||
AddInternal(new HyperBorderPiece());
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
if (borderPiece != null && drawableHitObject?.HitObject != null)
|
||||
borderPiece.Alpha = (float)Math.Clamp((drawableHitObject.HitObject.StartTime - Time.Current) / 500, 0, 1);
|
||||
AddInternal(HyperBorderPiece = new HyperBorderPiece());
|
||||
}
|
||||
|
||||
private Drawable getFruitFor(FruitVisualRepresentation representation)
|
||||
@ -66,9 +59,6 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
|
||||
case FruitVisualRepresentation.Pineapple:
|
||||
return new PineapplePiece();
|
||||
|
||||
case FruitVisualRepresentation.Banana:
|
||||
return new BananaPiece();
|
||||
|
||||
case FruitVisualRepresentation.Raspberry:
|
||||
return new RaspberryPiece();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user