Move fruit visual logic from CHO to DrawableFruit

This commit is contained in:
ekrctb
2020-11-27 10:10:05 +09:00
parent c272fda416
commit 5e36fb322a
7 changed files with 77 additions and 42 deletions

View File

@ -30,7 +30,7 @@ namespace osu.Game.Rulesets.Catch.Tests
} }
private Drawable createDrawableFruit(FruitVisualRepresentation rep, bool hyperdash = false) => private Drawable createDrawableFruit(FruitVisualRepresentation rep, bool hyperdash = false) =>
setProperties(new DrawableFruit(new TestCatchFruit(rep)), hyperdash); setProperties(new TestDrawableFruit(new Fruit(), rep), hyperdash);
private Drawable createDrawableDroplet(bool hyperdash = false) => setProperties(new DrawableDroplet(new Droplet()), hyperdash); private Drawable createDrawableDroplet(bool hyperdash = false) => setProperties(new DrawableDroplet(new Droplet()), hyperdash);
@ -56,14 +56,17 @@ namespace osu.Game.Rulesets.Catch.Tests
return d; return d;
} }
public class TestCatchFruit : Fruit public class TestDrawableFruit : DrawableFruit
{ {
public TestCatchFruit(FruitVisualRepresentation rep) private readonly FruitVisualRepresentation visualRepresentation;
{
VisualRepresentation = rep;
}
public override FruitVisualRepresentation VisualRepresentation { get; } protected override FruitVisualRepresentation GetVisualRepresentation(int indexInBeatmap) => visualRepresentation;
public TestDrawableFruit(Fruit fruit, FruitVisualRepresentation rep)
: base(fruit)
{
visualRepresentation = rep;
}
} }
} }
} }

View File

@ -18,8 +18,6 @@ namespace osu.Game.Rulesets.Catch.Objects
/// </summary> /// </summary>
public int BananaIndex; public int BananaIndex;
public override FruitVisualRepresentation VisualRepresentation => FruitVisualRepresentation.Banana;
public override Judgement CreateJudgement() => new CatchBananaJudgement(); public override Judgement CreateJudgement() => new CatchBananaJudgement();
private static readonly List<HitSampleInfo> samples = new List<HitSampleInfo> { new BananaHitSampleInfo() }; private static readonly List<HitSampleInfo> samples = new List<HitSampleInfo> { new BananaHitSampleInfo() };

View File

@ -9,8 +9,6 @@ namespace osu.Game.Rulesets.Catch.Objects
{ {
public class BananaShower : CatchHitObject, IHasDuration public class BananaShower : CatchHitObject, IHasDuration
{ {
public override FruitVisualRepresentation VisualRepresentation => FruitVisualRepresentation.Banana;
public override bool LastInCombo => true; public override bool LastInCombo => true;
public override Judgement CreateJudgement() => new IgnoreJudgement(); public override Judgement CreateJudgement() => new IgnoreJudgement();

View File

@ -58,8 +58,6 @@ namespace osu.Game.Rulesets.Catch.Objects
set => IndexInBeatmapBindable.Value = value; set => IndexInBeatmapBindable.Value = value;
} }
public virtual FruitVisualRepresentation VisualRepresentation => (FruitVisualRepresentation)(IndexInBeatmap % 4);
public virtual bool NewCombo { get; set; } public virtual bool NewCombo { get; set; }
public int ComboOffset { get; set; } public int ComboOffset { get; set; }
@ -115,13 +113,4 @@ namespace osu.Game.Rulesets.Catch.Objects
XBindable.BindValueChanged(x => originalX = x.NewValue - xOffset); XBindable.BindValueChanged(x => originalX = x.NewValue - xOffset);
} }
} }
public enum FruitVisualRepresentation
{
Pear,
Grape,
Pineapple,
Raspberry,
Banana // banananananannaanana
}
} }

View File

@ -8,6 +8,8 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
{ {
public class DrawableBanana : DrawableFruit public class DrawableBanana : DrawableFruit
{ {
protected override FruitVisualRepresentation GetVisualRepresentation(int indexInBeatmap) => FruitVisualRepresentation.Banana;
public DrawableBanana(Banana h) public DrawableBanana(Banana h)
: base(h) : base(h)
{ {

View File

@ -3,6 +3,7 @@
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Rulesets.Catch.Objects.Drawables.Pieces; using osu.Game.Rulesets.Catch.Objects.Drawables.Pieces;
using osu.Game.Skinning; using osu.Game.Skinning;
@ -11,18 +12,61 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
{ {
public class DrawableFruit : DrawablePalpableCatchHitObject public class DrawableFruit : DrawablePalpableCatchHitObject
{ {
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;
public DrawableFruit(CatchHitObject h) public DrawableFruit(CatchHitObject h)
: base(h) : base(h)
{ {
IndexInBeatmap.Value = h.IndexInBeatmap;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
ScaleContainer.Child = new SkinnableDrawable(
new CatchSkinComponent(getComponent(HitObject.VisualRepresentation)), _ => new FruitPiece());
ScaleContainer.Rotation = (float)(RNG.NextDouble() - 0.5f) * 40; ScaleContainer.Rotation = (float)(RNG.NextDouble() - 0.5f) * 40;
IndexInBeatmap.BindValueChanged(change =>
{
VisualRepresentation.Value = GetVisualRepresentation(change.NewValue);
}, true);
VisualRepresentation.BindValueChanged(change =>
{
ScaleContainer.Child = new SkinnableDrawable(
new CatchSkinComponent(getComponent(change.NewValue)),
_ => fruitPiece = new FruitPiece
{
VisualRepresentation = { BindTarget = VisualRepresentation },
});
}, true);
}
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);
} }
private CatchSkinComponents getComponent(FruitVisualRepresentation hitObjectVisualRepresentation) private CatchSkinComponents getComponent(FruitVisualRepresentation hitObjectVisualRepresentation)
@ -49,4 +93,13 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
} }
} }
} }
public enum FruitVisualRepresentation
{
Pear,
Grape,
Pineapple,
Raspberry,
Banana // banananananannaanana
}
} }

View File

@ -1,11 +1,10 @@
// 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 osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; 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
{ {
@ -16,8 +15,10 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
/// </summary> /// </summary>
public const float RADIUS_ADJUST = 1.1f; public const float RADIUS_ADJUST = 1.1f;
private BorderPiece border; public readonly Bindable<FruitVisualRepresentation> VisualRepresentation = new Bindable<FruitVisualRepresentation>();
private PalpableCatchHitObject hitObject; public readonly Bindable<bool> HyperDash = new Bindable<bool>();
public BorderPiece Border;
public FruitPiece() public FruitPiece()
{ {
@ -25,29 +26,20 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables.Pieces
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(DrawableHitObject drawableObject) private void load()
{ {
var drawableCatchObject = (DrawablePalpableCatchHitObject)drawableObject;
hitObject = drawableCatchObject.HitObject;
AddRangeInternal(new[] AddRangeInternal(new[]
{ {
getFruitFor(hitObject.VisualRepresentation), getFruitFor(VisualRepresentation.Value),
border = new BorderPiece(), Border = new BorderPiece(),
}); });
if (hitObject.HyperDash) if (HyperDash.Value)
{ {
AddInternal(new HyperBorderPiece()); AddInternal(new HyperBorderPiece());
} }
} }
protected override void Update()
{
base.Update();
border.Alpha = (float)Math.Clamp((hitObject.StartTime - Time.Current) / 500, 0, 1);
}
private Drawable getFruitFor(FruitVisualRepresentation representation) private Drawable getFruitFor(FruitVisualRepresentation representation)
{ {
switch (representation) switch (representation)