2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Allocation;
|
2020-11-27 09:10:05 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2020-01-09 12:43:44 +08:00
|
|
|
|
using osu.Framework.Utils;
|
2020-11-26 13:26:38 +08:00
|
|
|
|
using osu.Game.Rulesets.Catch.Objects.Drawables.Pieces;
|
2020-02-17 17:47:22 +08:00
|
|
|
|
using osu.Game.Skinning;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-19 17:01:59 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Catch.Objects.Drawables
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-11-24 18:13:46 +08:00
|
|
|
|
public class DrawableFruit : DrawablePalpableCatchHitObject
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-11-27 09:10:05 +08:00
|
|
|
|
public readonly Bindable<int> IndexInBeatmap = new Bindable<int>();
|
|
|
|
|
|
|
|
|
|
public readonly Bindable<FruitVisualRepresentation> VisualRepresentation = new Bindable<FruitVisualRepresentation>();
|
|
|
|
|
|
|
|
|
|
protected virtual FruitVisualRepresentation GetVisualRepresentation(int indexInBeatmap) => (FruitVisualRepresentation)(indexInBeatmap % 4);
|
|
|
|
|
|
|
|
|
|
private FruitPiece fruitPiece;
|
|
|
|
|
|
2020-11-24 16:03:26 +08:00
|
|
|
|
public DrawableFruit(CatchHitObject h)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
: base(h)
|
|
|
|
|
{
|
2020-11-27 09:10:05 +08:00
|
|
|
|
IndexInBeatmap.Value = h.IndexInBeatmap;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2020-03-10 18:30:31 +08:00
|
|
|
|
ScaleContainer.Rotation = (float)(RNG.NextDouble() - 0.5f) * 40;
|
2020-11-27 09:10:05 +08:00
|
|
|
|
|
|
|
|
|
IndexInBeatmap.BindValueChanged(change =>
|
|
|
|
|
{
|
|
|
|
|
VisualRepresentation.Value = GetVisualRepresentation(change.NewValue);
|
|
|
|
|
}, true);
|
|
|
|
|
|
2020-11-27 09:55:33 +08:00
|
|
|
|
VisualRepresentation.BindValueChanged(_ => updatePiece());
|
|
|
|
|
HyperDash.BindValueChanged(_ => updatePiece(), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updatePiece()
|
|
|
|
|
{
|
|
|
|
|
ScaleContainer.Child = new SkinnableDrawable(
|
|
|
|
|
new CatchSkinComponent(getComponent(VisualRepresentation.Value)),
|
|
|
|
|
_ => fruitPiece = new FruitPiece
|
|
|
|
|
{
|
|
|
|
|
VisualRepresentation = { BindTarget = VisualRepresentation },
|
|
|
|
|
HyperDash = { BindTarget = HyperDash },
|
|
|
|
|
});
|
2020-11-27 09:10:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnApply()
|
|
|
|
|
{
|
|
|
|
|
base.OnApply();
|
|
|
|
|
|
|
|
|
|
IndexInBeatmap.BindTo(HitObject.IndexInBeatmapBindable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnFree()
|
|
|
|
|
{
|
|
|
|
|
IndexInBeatmap.UnbindFrom(HitObject.IndexInBeatmapBindable);
|
|
|
|
|
|
|
|
|
|
base.OnFree();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
if (fruitPiece != null)
|
|
|
|
|
fruitPiece.Border.Alpha = (float)Math.Clamp((StartTimeBindable.Value - Time.Current) / 500, 0, 1);
|
2020-02-19 14:16:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-17 17:47:22 +08:00
|
|
|
|
private CatchSkinComponents getComponent(FruitVisualRepresentation hitObjectVisualRepresentation)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-02-17 17:47:22 +08:00
|
|
|
|
switch (hitObjectVisualRepresentation)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-02-17 17:47:22 +08:00
|
|
|
|
case FruitVisualRepresentation.Pear:
|
|
|
|
|
return CatchSkinComponents.FruitPear;
|
|
|
|
|
|
|
|
|
|
case FruitVisualRepresentation.Grape:
|
|
|
|
|
return CatchSkinComponents.FruitGrapes;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case FruitVisualRepresentation.Pineapple:
|
2020-02-17 17:47:22 +08:00
|
|
|
|
return CatchSkinComponents.FruitApple;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2020-02-19 13:31:43 +08:00
|
|
|
|
case FruitVisualRepresentation.Raspberry:
|
|
|
|
|
return CatchSkinComponents.FruitOrange;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case FruitVisualRepresentation.Banana:
|
2020-02-17 17:47:22 +08:00
|
|
|
|
return CatchSkinComponents.FruitBananas;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-17 17:47:22 +08:00
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(hitObjectVisualRepresentation), hitObjectVisualRepresentation, null);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-27 09:10:05 +08:00
|
|
|
|
|
|
|
|
|
public enum FruitVisualRepresentation
|
|
|
|
|
{
|
|
|
|
|
Pear,
|
|
|
|
|
Grape,
|
|
|
|
|
Pineapple,
|
|
|
|
|
Raspberry,
|
|
|
|
|
Banana // banananananannaanana
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|