2020-02-17 17:47:22 +08:00
|
|
|
// 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.
|
|
|
|
|
2020-11-27 09:10:05 +08:00
|
|
|
using osu.Framework.Bindables;
|
2020-02-17 17:47:22 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
2020-11-26 13:26:38 +08:00
|
|
|
namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
|
2020-02-17 17:47:22 +08:00
|
|
|
{
|
2020-12-07 12:14:00 +08:00
|
|
|
internal class FruitPiece : CatchHitObjectPiece
|
2020-02-17 17:47:22 +08:00
|
|
|
{
|
2020-02-19 08:39:56 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Because we're adding a border around the fruit, we need to scale down some.
|
|
|
|
/// </summary>
|
2020-02-19 22:32:56 +08:00
|
|
|
public const float RADIUS_ADJUST = 1.1f;
|
2020-02-19 08:39:56 +08:00
|
|
|
|
2020-11-27 09:10:05 +08:00
|
|
|
public readonly Bindable<FruitVisualRepresentation> VisualRepresentation = new Bindable<FruitVisualRepresentation>();
|
2020-02-17 17:47:22 +08:00
|
|
|
|
|
|
|
public FruitPiece()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
2020-12-07 12:14:00 +08:00
|
|
|
protected override void LoadComplete()
|
2020-02-17 17:47:22 +08:00
|
|
|
{
|
2020-12-07 12:14:00 +08:00
|
|
|
base.LoadComplete();
|
2020-11-30 12:46:02 +08:00
|
|
|
|
2020-12-07 12:14:00 +08:00
|
|
|
if (DrawableHitObject != null)
|
|
|
|
{
|
|
|
|
var fruit = (DrawableFruit)DrawableHitObject;
|
|
|
|
VisualRepresentation.BindTo(fruit.VisualRepresentation);
|
|
|
|
}
|
2020-02-17 17:47:22 +08:00
|
|
|
|
2020-12-07 12:14:00 +08:00
|
|
|
VisualRepresentation.BindValueChanged(_ => recreateChildren(), true);
|
2020-11-30 12:46:02 +08:00
|
|
|
}
|
|
|
|
|
2020-12-07 12:14:00 +08:00
|
|
|
private void recreateChildren()
|
2020-11-30 12:46:02 +08:00
|
|
|
{
|
2020-12-07 12:14:00 +08:00
|
|
|
ClearInternal();
|
|
|
|
|
|
|
|
AddInternal(getFruitFor(VisualRepresentation.Value));
|
|
|
|
|
|
|
|
if (DrawableHitObject != null)
|
|
|
|
AddInternal(BorderPiece = new BorderPiece());
|
|
|
|
|
|
|
|
if (HyperDash.Value)
|
|
|
|
AddInternal(HyperBorderPiece = new HyperBorderPiece());
|
2020-02-17 17:47:22 +08:00
|
|
|
}
|
|
|
|
|
2020-02-19 22:32:56 +08:00
|
|
|
private Drawable getFruitFor(FruitVisualRepresentation representation)
|
2020-02-17 17:47:22 +08:00
|
|
|
{
|
|
|
|
switch (representation)
|
|
|
|
{
|
|
|
|
case FruitVisualRepresentation.Pear:
|
2020-02-19 22:32:56 +08:00
|
|
|
return new PearPiece();
|
2020-02-17 17:47:22 +08:00
|
|
|
|
|
|
|
case FruitVisualRepresentation.Grape:
|
2020-02-19 22:32:56 +08:00
|
|
|
return new GrapePiece();
|
|
|
|
|
|
|
|
case FruitVisualRepresentation.Pineapple:
|
|
|
|
return new PineapplePiece();
|
2020-02-17 17:47:22 +08:00
|
|
|
|
2020-02-19 22:32:56 +08:00
|
|
|
case FruitVisualRepresentation.Raspberry:
|
|
|
|
return new RaspberryPiece();
|
2020-02-17 17:47:22 +08:00
|
|
|
}
|
2020-02-19 22:32:56 +08:00
|
|
|
|
|
|
|
return Empty();
|
2020-02-17 17:47:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|