Introduce IHasCatchObjectState implemented by DHO and CaughtObject

This commit is contained in:
ekrctb 2020-12-08 21:29:03 +09:00
parent c301223d8c
commit a32dac00dd
11 changed files with 70 additions and 86 deletions

View File

@ -12,12 +12,12 @@
namespace osu.Game.Rulesets.Catch.Objects.Drawables
{
[Cached(typeof(CaughtObject))]
public abstract class CaughtObject : SkinnableDrawable
[Cached(typeof(IHasCatchObjectState))]
public abstract class CaughtObject : SkinnableDrawable, IHasCatchObjectState
{
public readonly Bindable<Color4> AccentColour = new Bindable<Color4>();
public CatchHitObject HitObject { get; private set; }
public Bindable<Color4> AccentColour { get; } = new Bindable<Color4>();
public Bindable<bool> HyperDash { get; } = new Bindable<bool>();
/// <summary>
/// Whether this hit object should stay on the catcher plate when the object is caught by the catcher.
@ -36,30 +36,31 @@ protected CaughtObject(CatchSkinComponents skinComponent, Func<ISkinComponent, D
Size = new Vector2(CatchHitObject.OBJECT_RADIUS * 2);
}
public virtual void CopyFrom(DrawablePalpableCatchHitObject drawableObject)
public virtual void CopyFrom(IHasCatchObjectState objectState)
{
HitObject = drawableObject.HitObject;
Scale = drawableObject.Scale / 2;
Rotation = drawableObject.Rotation;
AccentColour.Value = drawableObject.AccentColour.Value;
HitObject = objectState.HitObject;
Scale = objectState.Scale;
Rotation = objectState.Rotation;
AccentColour.Value = objectState.AccentColour.Value;
HyperDash.Value = objectState.HyperDash.Value;
}
}
public class CaughtFruit : CaughtObject
public class CaughtFruit : CaughtObject, IHasFruitState
{
public readonly Bindable<FruitVisualRepresentation> VisualRepresentation = new Bindable<FruitVisualRepresentation>();
public Bindable<FruitVisualRepresentation> VisualRepresentation { get; } = new Bindable<FruitVisualRepresentation>();
public CaughtFruit()
: base(CatchSkinComponents.Fruit, _ => new FruitPiece())
{
}
public override void CopyFrom(DrawablePalpableCatchHitObject drawableObject)
public override void CopyFrom(IHasCatchObjectState objectState)
{
base.CopyFrom(drawableObject);
base.CopyFrom(objectState);
var drawableFruit = (DrawableFruit)drawableObject;
VisualRepresentation.Value = drawableFruit.VisualRepresentation.Value;
var fruitState = (IHasFruitState)objectState;
VisualRepresentation.Value = fruitState.VisualRepresentation.Value;
}
}

View File

@ -9,7 +9,7 @@
namespace osu.Game.Rulesets.Catch.Objects.Drawables
{
public class DrawableBanana : DrawablePalpableCatchHitObject
public class DrawableBanana : DrawablePalpableHasCatchHitObject
{
public DrawableBanana()
: this(null)

View File

@ -9,7 +9,7 @@
namespace osu.Game.Rulesets.Catch.Objects.Drawables
{
public class DrawableDroplet : DrawablePalpableCatchHitObject
public class DrawableDroplet : DrawablePalpableHasCatchHitObject
{
public DrawableDroplet()
: this(null)

View File

@ -10,9 +10,9 @@
namespace osu.Game.Rulesets.Catch.Objects.Drawables
{
public class DrawableFruit : DrawablePalpableCatchHitObject
public class DrawableFruit : DrawablePalpableHasCatchHitObject, IHasFruitState
{
public readonly Bindable<FruitVisualRepresentation> VisualRepresentation = new Bindable<FruitVisualRepresentation>();
public Bindable<FruitVisualRepresentation> VisualRepresentation { get; } = new Bindable<FruitVisualRepresentation>();
public DrawableFruit()
: this(null)

View File

@ -6,18 +6,22 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Catch.Objects.Drawables
{
public abstract class DrawablePalpableCatchHitObject : DrawableCatchHitObject
[Cached(typeof(IHasCatchObjectState))]
public abstract class DrawablePalpableHasCatchHitObject : DrawableCatchHitObject, IHasCatchObjectState
{
public new PalpableCatchHitObject HitObject => (PalpableCatchHitObject)base.HitObject;
public readonly Bindable<bool> HyperDash = new Bindable<bool>();
Bindable<Color4> IHasCatchObjectState.AccentColour => AccentColour;
public readonly Bindable<float> ScaleBindable = new Bindable<float>(1);
public Bindable<bool> HyperDash { get; } = new Bindable<bool>();
public readonly Bindable<int> IndexInBeatmap = new Bindable<int>();
public Bindable<float> ScaleBindable { get; } = new Bindable<float>(1);
public Bindable<int> IndexInBeatmap { get; } = new Bindable<int>();
/// <summary>
/// The multiplicative factor applied to <see cref="Drawable.Scale"/> relative to <see cref="HitObject"/> scale.
@ -26,7 +30,7 @@ public abstract class DrawablePalpableCatchHitObject : DrawableCatchHitObject
public float DisplayRadius => CatchHitObject.OBJECT_RADIUS * HitObject.Scale * ScaleFactor;
protected DrawablePalpableCatchHitObject([CanBeNull] CatchHitObject h)
protected DrawablePalpableHasCatchHitObject([CanBeNull] CatchHitObject h)
: base(h)
{
Origin = Anchor.Centre;

View File

@ -0,0 +1,24 @@
// 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.Bindables;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Catch.Objects.Drawables
{
public interface IHasCatchObjectState
{
CatchHitObject HitObject { get; }
Bindable<Color4> AccentColour { get; }
Bindable<bool> HyperDash { get; }
float Rotation { get; }
Vector2 Scale { get; }
}
public interface IHasFruitState : IHasCatchObjectState
{
Bindable<FruitVisualRepresentation> VisualRepresentation { get; }
}
}

View File

@ -7,7 +7,6 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Catch.Objects.Drawables;
using osu.Game.Rulesets.Objects.Drawables;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Catch.Skinning.Default
@ -17,13 +16,8 @@ public abstract class CatchHitObjectPiece : CompositeDrawable
public readonly Bindable<Color4> AccentColour = new Bindable<Color4>();
public readonly Bindable<bool> HyperDash = new Bindable<bool>();
[Resolved(canBeNull: true)]
[CanBeNull]
protected DrawableHitObject DrawableHitObject { get; private set; }
[Resolved(canBeNull: true)]
[CanBeNull]
protected CaughtObject CaughtObject { get; private set; }
[Resolved]
protected IHasCatchObjectState ObjectState { get; private set; }
/// <summary>
/// A part of this piece that will be faded out while falling in the playfield.
@ -41,16 +35,8 @@ protected override void LoadComplete()
{
base.LoadComplete();
var hitObject = (DrawablePalpableCatchHitObject)DrawableHitObject;
if (hitObject != null)
{
AccentColour.BindTo(hitObject.AccentColour);
HyperDash.BindTo(hitObject.HyperDash);
}
if (CaughtObject != null)
AccentColour.BindTo(CaughtObject.AccentColour);
AccentColour.BindTo(ObjectState.AccentColour);
HyperDash.BindTo(ObjectState.HyperDash);
HyperDash.BindValueChanged(hyper =>
{
@ -61,13 +47,8 @@ protected override void LoadComplete()
protected override void Update()
{
if (BorderPiece != null)
{
if (DrawableHitObject?.HitObject != null)
BorderPiece.Alpha = (float)Math.Clamp((DrawableHitObject.HitObject.StartTime - Time.Current) / 500, 0, 1);
else
BorderPiece.Alpha = 0;
}
if (BorderPiece != null && ObjectState?.HitObject != null)
BorderPiece.Alpha = (float)Math.Clamp((ObjectState.HitObject.StartTime - Time.Current) / 500, 0, 1);
}
}
}

View File

@ -39,14 +39,8 @@ protected override void LoadComplete()
{
base.LoadComplete();
var fruit = (DrawableFruit)DrawableHitObject;
if (fruit != null)
VisualRepresentation.BindTo(fruit.VisualRepresentation);
var caughtFruit = (CaughtFruit)CaughtObject;
if (caughtFruit != null)
VisualRepresentation.BindTo(caughtFruit.VisualRepresentation);
var fruitState = (IHasFruitState)ObjectState;
VisualRepresentation.BindTo(fruitState.VisualRepresentation);
}
}
}

View File

@ -14,14 +14,8 @@ protected override void LoadComplete()
{
base.LoadComplete();
var fruit = (DrawableFruit)DrawableHitObject;
if (fruit != null)
VisualRepresentation.BindTo(fruit.VisualRepresentation);
var caughtFruit = (CaughtFruit)CaughtObject;
if (caughtFruit != null)
VisualRepresentation.BindTo(caughtFruit.VisualRepresentation);
var fruitState = (IHasFruitState)ObjectState;
VisualRepresentation.BindTo(fruitState.VisualRepresentation);
VisualRepresentation.BindValueChanged(visual => setTexture(visual.NewValue), true);
}

View File

@ -1,7 +1,6 @@
// 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 JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -10,7 +9,6 @@
using osu.Framework.Graphics.Textures;
using osu.Game.Rulesets.Catch.Objects.Drawables;
using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Skinning;
using osuTK;
using osuTK.Graphics;
@ -29,13 +27,8 @@ public abstract class LegacyCatchHitObjectPiece : PoolableDrawable
[Resolved]
protected ISkinSource Skin { get; private set; }
[Resolved(canBeNull: true)]
[CanBeNull]
protected DrawableHitObject DrawableHitObject { get; private set; }
[Resolved(canBeNull: true)]
[CanBeNull]
protected CaughtObject CaughtObject { get; private set; }
[Resolved]
protected IHasCatchObjectState ObjectState { get; private set; }
protected LegacyCatchHitObjectPiece()
{
@ -69,16 +62,8 @@ protected override void LoadComplete()
{
base.LoadComplete();
var hitObject = (DrawablePalpableCatchHitObject)DrawableHitObject;
if (hitObject != null)
{
AccentColour.BindTo(hitObject.AccentColour);
HyperDash.BindTo(hitObject.HyperDash);
}
if (CaughtObject != null)
AccentColour.BindTo(CaughtObject.AccentColour);
AccentColour.BindTo(ObjectState.AccentColour);
HyperDash.BindTo(ObjectState.HyperDash);
hyperSprite.Colour = Skin.GetConfig<CatchSkinColour, Color4>(CatchSkinColour.HyperDashFruit)?.Value ??
Skin.GetConfig<CatchSkinColour, Color4>(CatchSkinColour.HyperDash)?.Value ??

View File

@ -215,7 +215,7 @@ public void OnNewResult(DrawableCatchHitObject drawableObject, JudgementResult r
catchResult.CatcherAnimationState = CurrentState;
catchResult.CatcherHyperDash = HyperDashing;
if (!(drawableObject is DrawablePalpableCatchHitObject palpableObject)) return;
if (!(drawableObject is DrawablePalpableHasCatchHitObject palpableObject)) return;
var hitObject = palpableObject.HitObject;
@ -450,7 +450,7 @@ private void updateState(CatcherAnimationState state)
updateCatcher();
}
private void placeCaughtObject(DrawablePalpableCatchHitObject drawableObject, Vector2 position)
private void placeCaughtObject(DrawablePalpableHasCatchHitObject drawableObject, Vector2 position)
{
var caughtObject = createCaughtObject(drawableObject.HitObject);
@ -458,6 +458,7 @@ private void placeCaughtObject(DrawablePalpableCatchHitObject drawableObject, Ve
caughtObject.CopyFrom(drawableObject);
caughtObject.Position = position;
caughtObject.Scale /= 2;
caughtFruitContainer.Add(caughtObject);