2019-06-24 13:40:08 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-06-22 23:53:00 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
2020-03-10 10:42:08 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2019-06-22 23:53:00 +08:00
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.UI
|
|
|
|
|
{
|
2020-03-10 10:42:08 +08:00
|
|
|
|
public class CatcherSprite : SkinnableDrawable
|
2019-06-22 23:53:00 +08:00
|
|
|
|
{
|
2020-03-10 10:42:08 +08:00
|
|
|
|
protected override bool ApplySizeRestrictionsToDefault => true;
|
|
|
|
|
|
2020-03-10 14:26:39 +08:00
|
|
|
|
public CatcherSprite(CatcherAnimationState state)
|
|
|
|
|
: base(new CatchSkinComponent(componentFromState(state)), _ =>
|
|
|
|
|
new DefaultCatcherSprite(state), confineMode: ConfineMode.ScaleDownToFit)
|
2019-06-22 23:53:00 +08:00
|
|
|
|
{
|
2020-03-10 10:42:08 +08:00
|
|
|
|
RelativeSizeAxes = Axes.None;
|
2019-06-22 23:53:00 +08:00
|
|
|
|
Size = new Vector2(CatcherArea.CATCHER_SIZE);
|
|
|
|
|
|
|
|
|
|
// Sets the origin roughly to the centre of the catcher's plate to allow for correct scaling.
|
2020-03-10 10:42:08 +08:00
|
|
|
|
OriginPosition = new Vector2(0.5f, 0.06f) * CatcherArea.CATCHER_SIZE;
|
2019-06-22 23:53:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-10 14:26:39 +08:00
|
|
|
|
private static CatchSkinComponents componentFromState(CatcherAnimationState state)
|
|
|
|
|
{
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case CatcherAnimationState.Fail:
|
|
|
|
|
return CatchSkinComponents.CatcherFail;
|
|
|
|
|
|
|
|
|
|
case CatcherAnimationState.Kiai:
|
|
|
|
|
return CatchSkinComponents.CatcherKiai;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return CatchSkinComponents.CatcherIdle;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-10 10:42:08 +08:00
|
|
|
|
private class DefaultCatcherSprite : Sprite
|
2019-06-22 23:53:00 +08:00
|
|
|
|
{
|
2020-03-10 14:26:39 +08:00
|
|
|
|
private readonly CatcherAnimationState state;
|
|
|
|
|
|
|
|
|
|
public DefaultCatcherSprite(CatcherAnimationState state)
|
|
|
|
|
{
|
|
|
|
|
this.state = state;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-10 10:42:08 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(TextureStore textures)
|
2019-06-22 23:53:00 +08:00
|
|
|
|
{
|
2020-03-10 14:26:39 +08:00
|
|
|
|
Texture = textures.Get($"Gameplay/catch/fruit-catcher-{state.ToString().ToLower()}");
|
2020-03-10 10:42:08 +08:00
|
|
|
|
}
|
2019-06-22 23:53:00 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|