1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 01:27:29 +08:00

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