Factor out SkinnableDrawable component of the catcher to SkinnableCatcher

This commit is contained in:
ekrctb
2021-06-14 19:41:51 +09:00
parent ebe850fe9f
commit ca061c4b93
2 changed files with 37 additions and 26 deletions

View File

@ -17,7 +17,6 @@ using osu.Game.Rulesets.Catch.Judgements;
using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.Objects.Drawables; using osu.Game.Rulesets.Catch.Objects.Drawables;
using osu.Game.Rulesets.Catch.Skinning; using osu.Game.Rulesets.Catch.Skinning;
using osu.Game.Rulesets.Catch.Skinning.Default;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK; using osuTK;
@ -83,17 +82,18 @@ namespace osu.Game.Rulesets.Catch.UI
/// </summary> /// </summary>
private readonly Container<CaughtObject> droppedObjectTarget; private readonly Container<CaughtObject> droppedObjectTarget;
[Cached] public CatcherAnimationState CurrentState
protected readonly Bindable<CatcherAnimationState> CurrentStateBindable = new Bindable<CatcherAnimationState>(); {
get => body.AnimationState.Value;
public CatcherAnimationState CurrentState => CurrentStateBindable.Value; private set => body.AnimationState.Value = value;
}
/// <summary> /// <summary>
/// The width of the catcher which can receive fruit. Equivalent to "catchMargin" in osu-stable. /// The width of the catcher which can receive fruit. Equivalent to "catchMargin" in osu-stable.
/// </summary> /// </summary>
public const float ALLOWED_CATCH_RANGE = 0.8f; public const float ALLOWED_CATCH_RANGE = 0.8f;
internal Texture CurrentTexture => ((ICatcherSprite)currentCatcher.Drawable).CurrentTexture; internal Texture CurrentTexture => ((ICatcherSprite)body.Drawable).CurrentTexture;
private bool dashing; private bool dashing;
@ -121,7 +121,7 @@ namespace osu.Game.Rulesets.Catch.UI
/// </summary> /// </summary>
private readonly float catchWidth; private readonly float catchWidth;
private readonly SkinnableDrawable currentCatcher; private readonly SkinnableCatcher body;
private Color4 hyperDashColour = DEFAULT_HYPER_DASH_COLOUR; private Color4 hyperDashColour = DEFAULT_HYPER_DASH_COLOUR;
private Color4 hyperDashEndGlowColour = DEFAULT_HYPER_DASH_COLOUR; private Color4 hyperDashEndGlowColour = DEFAULT_HYPER_DASH_COLOUR;
@ -161,13 +161,7 @@ namespace osu.Game.Rulesets.Catch.UI
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.BottomCentre, Origin = Anchor.BottomCentre,
}, },
currentCatcher = new SkinnableDrawable( body = new SkinnableCatcher(),
new CatchSkinComponent(CatchSkinComponents.Catcher),
_ => new DefaultCatcher())
{
Anchor = Anchor.TopCentre,
OriginPosition = new Vector2(0.5f, 0.06f) * CatcherArea.CATCHER_SIZE
},
hitExplosionContainer = new HitExplosionContainer hitExplosionContainer = new HitExplosionContainer
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
@ -268,17 +262,16 @@ namespace osu.Game.Rulesets.Catch.UI
SetHyperDashState(); SetHyperDashState();
if (result.IsHit) if (result.IsHit)
updateState(hitObject.Kiai ? CatcherAnimationState.Kiai : CatcherAnimationState.Idle); CurrentState = hitObject.Kiai ? CatcherAnimationState.Kiai : CatcherAnimationState.Idle;
else if (!(hitObject is Banana)) else if (!(hitObject is Banana))
updateState(CatcherAnimationState.Fail); CurrentState = CatcherAnimationState.Fail;
} }
public void OnRevertResult(DrawableCatchHitObject drawableObject, JudgementResult result) public void OnRevertResult(DrawableCatchHitObject drawableObject, JudgementResult result)
{ {
var catchResult = (CatchJudgementResult)result; var catchResult = (CatchJudgementResult)result;
if (CurrentState != catchResult.CatcherAnimationState) CurrentState = catchResult.CatcherAnimationState;
updateState(catchResult.CatcherAnimationState);
if (HyperDashing != catchResult.CatcherHyperDash) if (HyperDashing != catchResult.CatcherHyperDash)
{ {
@ -373,14 +366,6 @@ namespace osu.Game.Rulesets.Catch.UI
} }
} }
private void updateState(CatcherAnimationState state)
{
if (CurrentState == state)
return;
CurrentStateBindable.Value = state;
}
private void placeCaughtObject(DrawablePalpableCatchHitObject drawableObject, Vector2 position) private void placeCaughtObject(DrawablePalpableCatchHitObject drawableObject, Vector2 position)
{ {
var caughtObject = getCaughtObject(drawableObject.HitObject); var caughtObject = getCaughtObject(drawableObject.HitObject);

View File

@ -0,0 +1,26 @@
// 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.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Catch.Skinning.Default;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Rulesets.Catch.UI
{
public class SkinnableCatcher : SkinnableDrawable
{
[Cached]
public readonly Bindable<CatcherAnimationState> AnimationState = new Bindable<CatcherAnimationState>();
public SkinnableCatcher()
: base(new CatchSkinComponent(CatchSkinComponents.Catcher), _ => new DefaultCatcher())
{
Anchor = Anchor.TopCentre;
// Sets the origin roughly to the centre of the catcher's plate to allow for correct scaling.
OriginPosition = new Vector2(0.5f, 0.06f) * CatcherArea.CATCHER_SIZE;
}
}
}