1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 22:12:53 +08:00

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

View File

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

View File

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

View File

@ -10,9 +10,9 @@ using osu.Game.Skinning;
namespace osu.Game.Rulesets.Catch.Objects.Drawables 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() public DrawableFruit()
: this(null) : this(null)

View File

@ -6,18 +6,22 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osuTK; using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Catch.Objects.Drawables 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 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> /// <summary>
/// The multiplicative factor applied to <see cref="Drawable.Scale"/> relative to <see cref="HitObject"/> scale. /// The multiplicative factor applied to <see cref="Drawable.Scale"/> relative to <see cref="HitObject"/> scale.
@ -26,7 +30,7 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
public float DisplayRadius => CatchHitObject.OBJECT_RADIUS * HitObject.Scale * ScaleFactor; public float DisplayRadius => CatchHitObject.OBJECT_RADIUS * HitObject.Scale * ScaleFactor;
protected DrawablePalpableCatchHitObject([CanBeNull] CatchHitObject h) protected DrawablePalpableHasCatchHitObject([CanBeNull] CatchHitObject h)
: base(h) : base(h)
{ {
Origin = Anchor.Centre; 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.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Catch.Objects.Drawables; using osu.Game.Rulesets.Catch.Objects.Drawables;
using osu.Game.Rulesets.Objects.Drawables;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Rulesets.Catch.Skinning.Default namespace osu.Game.Rulesets.Catch.Skinning.Default
@ -17,13 +16,8 @@ namespace osu.Game.Rulesets.Catch.Skinning.Default
public readonly Bindable<Color4> AccentColour = new Bindable<Color4>(); public readonly Bindable<Color4> AccentColour = new Bindable<Color4>();
public readonly Bindable<bool> HyperDash = new Bindable<bool>(); public readonly Bindable<bool> HyperDash = new Bindable<bool>();
[Resolved(canBeNull: true)] [Resolved]
[CanBeNull] protected IHasCatchObjectState ObjectState { get; private set; }
protected DrawableHitObject DrawableHitObject { get; private set; }
[Resolved(canBeNull: true)]
[CanBeNull]
protected CaughtObject CaughtObject { get; private set; }
/// <summary> /// <summary>
/// A part of this piece that will be faded out while falling in the playfield. /// A part of this piece that will be faded out while falling in the playfield.
@ -41,16 +35,8 @@ namespace osu.Game.Rulesets.Catch.Skinning.Default
{ {
base.LoadComplete(); base.LoadComplete();
var hitObject = (DrawablePalpableCatchHitObject)DrawableHitObject; AccentColour.BindTo(ObjectState.AccentColour);
HyperDash.BindTo(ObjectState.HyperDash);
if (hitObject != null)
{
AccentColour.BindTo(hitObject.AccentColour);
HyperDash.BindTo(hitObject.HyperDash);
}
if (CaughtObject != null)
AccentColour.BindTo(CaughtObject.AccentColour);
HyperDash.BindValueChanged(hyper => HyperDash.BindValueChanged(hyper =>
{ {
@ -61,13 +47,8 @@ namespace osu.Game.Rulesets.Catch.Skinning.Default
protected override void Update() protected override void Update()
{ {
if (BorderPiece != null) if (BorderPiece != null && ObjectState?.HitObject != null)
{ BorderPiece.Alpha = (float)Math.Clamp((ObjectState.HitObject.StartTime - Time.Current) / 500, 0, 1);
if (DrawableHitObject?.HitObject != null)
BorderPiece.Alpha = (float)Math.Clamp((DrawableHitObject.HitObject.StartTime - Time.Current) / 500, 0, 1);
else
BorderPiece.Alpha = 0;
}
} }
} }
} }

View File

@ -39,14 +39,8 @@ namespace osu.Game.Rulesets.Catch.Skinning.Default
{ {
base.LoadComplete(); base.LoadComplete();
var fruit = (DrawableFruit)DrawableHitObject; var fruitState = (IHasFruitState)ObjectState;
VisualRepresentation.BindTo(fruitState.VisualRepresentation);
if (fruit != null)
VisualRepresentation.BindTo(fruit.VisualRepresentation);
var caughtFruit = (CaughtFruit)CaughtObject;
if (caughtFruit != null)
VisualRepresentation.BindTo(caughtFruit.VisualRepresentation);
} }
} }
} }

View File

@ -14,14 +14,8 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy
{ {
base.LoadComplete(); base.LoadComplete();
var fruit = (DrawableFruit)DrawableHitObject; var fruitState = (IHasFruitState)ObjectState;
VisualRepresentation.BindTo(fruitState.VisualRepresentation);
if (fruit != null)
VisualRepresentation.BindTo(fruit.VisualRepresentation);
var caughtFruit = (CaughtFruit)CaughtObject;
if (caughtFruit != null)
VisualRepresentation.BindTo(caughtFruit.VisualRepresentation);
VisualRepresentation.BindValueChanged(visual => setTexture(visual.NewValue), true); 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. // 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 JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -10,7 +9,6 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Game.Rulesets.Catch.Objects.Drawables; using osu.Game.Rulesets.Catch.Objects.Drawables;
using osu.Game.Rulesets.Catch.UI; using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -29,13 +27,8 @@ namespace osu.Game.Rulesets.Catch.Skinning
[Resolved] [Resolved]
protected ISkinSource Skin { get; private set; } protected ISkinSource Skin { get; private set; }
[Resolved(canBeNull: true)] [Resolved]
[CanBeNull] protected IHasCatchObjectState ObjectState { get; private set; }
protected DrawableHitObject DrawableHitObject { get; private set; }
[Resolved(canBeNull: true)]
[CanBeNull]
protected CaughtObject CaughtObject { get; private set; }
protected LegacyCatchHitObjectPiece() protected LegacyCatchHitObjectPiece()
{ {
@ -69,16 +62,8 @@ namespace osu.Game.Rulesets.Catch.Skinning
{ {
base.LoadComplete(); base.LoadComplete();
var hitObject = (DrawablePalpableCatchHitObject)DrawableHitObject; AccentColour.BindTo(ObjectState.AccentColour);
HyperDash.BindTo(ObjectState.HyperDash);
if (hitObject != null)
{
AccentColour.BindTo(hitObject.AccentColour);
HyperDash.BindTo(hitObject.HyperDash);
}
if (CaughtObject != null)
AccentColour.BindTo(CaughtObject.AccentColour);
hyperSprite.Colour = Skin.GetConfig<CatchSkinColour, Color4>(CatchSkinColour.HyperDashFruit)?.Value ?? hyperSprite.Colour = Skin.GetConfig<CatchSkinColour, Color4>(CatchSkinColour.HyperDashFruit)?.Value ??
Skin.GetConfig<CatchSkinColour, Color4>(CatchSkinColour.HyperDash)?.Value ?? Skin.GetConfig<CatchSkinColour, Color4>(CatchSkinColour.HyperDash)?.Value ??

View File

@ -215,7 +215,7 @@ namespace osu.Game.Rulesets.Catch.UI
catchResult.CatcherAnimationState = CurrentState; catchResult.CatcherAnimationState = CurrentState;
catchResult.CatcherHyperDash = HyperDashing; catchResult.CatcherHyperDash = HyperDashing;
if (!(drawableObject is DrawablePalpableCatchHitObject palpableObject)) return; if (!(drawableObject is DrawablePalpableHasCatchHitObject palpableObject)) return;
var hitObject = palpableObject.HitObject; var hitObject = palpableObject.HitObject;
@ -450,7 +450,7 @@ namespace osu.Game.Rulesets.Catch.UI
updateCatcher(); updateCatcher();
} }
private void placeCaughtObject(DrawablePalpableCatchHitObject drawableObject, Vector2 position) private void placeCaughtObject(DrawablePalpableHasCatchHitObject drawableObject, Vector2 position)
{ {
var caughtObject = createCaughtObject(drawableObject.HitObject); var caughtObject = createCaughtObject(drawableObject.HitObject);
@ -458,6 +458,7 @@ namespace osu.Game.Rulesets.Catch.UI
caughtObject.CopyFrom(drawableObject); caughtObject.CopyFrom(drawableObject);
caughtObject.Position = position; caughtObject.Position = position;
caughtObject.Scale /= 2;
caughtFruitContainer.Add(caughtObject); caughtFruitContainer.Add(caughtObject);