mirror of
https://github.com/ppy/osu.git
synced 2025-02-05 02:03:04 +08: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(
|
ScaleContainer.Child = new SkinnableDrawable(
|
||||||
new CatchSkinComponent(CatchSkinComponents.Droplet),
|
new CatchSkinComponent(CatchSkinComponents.Droplet),
|
||||||
_ => new DropletPiece
|
_ => new DropletPiece());
|
||||||
{
|
|
||||||
HyperDash = { BindTarget = HyperDash },
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateInitialTransforms()
|
protected override void UpdateInitialTransforms()
|
||||||
|
@ -36,11 +36,7 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
|
|||||||
|
|
||||||
ScaleContainer.Child = new SkinnableDrawable(
|
ScaleContainer.Child = new SkinnableDrawable(
|
||||||
new CatchSkinComponent(this is DrawableBanana ? CatchSkinComponents.Banana : CatchSkinComponents.Fruit),
|
new CatchSkinComponent(this is DrawableBanana ? CatchSkinComponents.Banana : CatchSkinComponents.Fruit),
|
||||||
_ => new FruitPiece
|
_ => new FruitPiece());
|
||||||
{
|
|
||||||
VisualRepresentation = { BindTarget = VisualRepresentation },
|
|
||||||
HyperDash = { BindTarget = HyperDash },
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateInitialTransforms()
|
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.
|
// 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.Bindables;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Game.Rulesets.Objects.Drawables;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
|
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()
|
public DropletPiece()
|
||||||
{
|
{
|
||||||
Size = new Vector2(CatchHitObject.OBJECT_RADIUS / 2);
|
Size = new Vector2(CatchHitObject.OBJECT_RADIUS / 2);
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
InternalChildren = new Drawable[]
|
||||||
private void load(DrawableHitObject drawableObject)
|
|
||||||
{
|
|
||||||
InternalChild = new Pulp
|
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
new Pulp
|
||||||
AccentColour = { BindTarget = drawableObject.AccentColour }
|
{
|
||||||
|
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.
|
// 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 System;
|
|
||||||
using JetBrains.Annotations;
|
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Game.Rulesets.Objects.Drawables;
|
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
|
namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
|
||||||
{
|
{
|
||||||
internal class FruitPiece : CompositeDrawable
|
internal class FruitPiece : CatchHitObjectPiece
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Because we're adding a border around the fruit, we need to scale down some.
|
/// 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 const float RADIUS_ADJUST = 1.1f;
|
||||||
|
|
||||||
public readonly Bindable<FruitVisualRepresentation> VisualRepresentation = new Bindable<FruitVisualRepresentation>();
|
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()
|
public FruitPiece()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader(permitNulls: true)]
|
protected override void LoadComplete()
|
||||||
private void load([CanBeNull] DrawableHitObject drawable)
|
|
||||||
{
|
{
|
||||||
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));
|
AddInternal(getFruitFor(VisualRepresentation.Value));
|
||||||
|
|
||||||
// if it is not part of a DHO, the border is always invisible.
|
if (DrawableHitObject != null)
|
||||||
if (drawableHitObject != null)
|
AddInternal(BorderPiece = new BorderPiece());
|
||||||
AddInternal(borderPiece = new BorderPiece());
|
|
||||||
|
|
||||||
if (HyperDash.Value)
|
if (HyperDash.Value)
|
||||||
AddInternal(new HyperBorderPiece());
|
AddInternal(HyperBorderPiece = 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Drawable getFruitFor(FruitVisualRepresentation representation)
|
private Drawable getFruitFor(FruitVisualRepresentation representation)
|
||||||
@ -66,9 +59,6 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
|
|||||||
case FruitVisualRepresentation.Pineapple:
|
case FruitVisualRepresentation.Pineapple:
|
||||||
return new PineapplePiece();
|
return new PineapplePiece();
|
||||||
|
|
||||||
case FruitVisualRepresentation.Banana:
|
|
||||||
return new BananaPiece();
|
|
||||||
|
|
||||||
case FruitVisualRepresentation.Raspberry:
|
case FruitVisualRepresentation.Raspberry:
|
||||||
return new RaspberryPiece();
|
return new RaspberryPiece();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user