2021-06-08 18:51:40 +08:00
|
|
|
// 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.
|
|
|
|
|
2021-06-08 20:58:39 +08:00
|
|
|
using System;
|
2021-06-08 18:51:40 +08:00
|
|
|
using System.Collections.Generic;
|
2021-06-08 20:58:39 +08:00
|
|
|
using System.Linq;
|
2021-06-08 18:51:40 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Animations;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Rulesets.Catch.UI;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.Skinning.Legacy
|
|
|
|
{
|
2021-06-14 19:26:33 +08:00
|
|
|
public partial class LegacyCatcherNew : CompositeDrawable
|
2021-06-08 18:51:40 +08:00
|
|
|
{
|
2021-06-10 14:47:03 +08:00
|
|
|
[Resolved]
|
2022-11-09 12:37:19 +08:00
|
|
|
private Bindable<CatcherAnimationState> currentState { get; set; } = null!;
|
2021-06-08 18:51:40 +08:00
|
|
|
|
|
|
|
private readonly Dictionary<CatcherAnimationState, Drawable> drawables = new Dictionary<CatcherAnimationState, Drawable>();
|
|
|
|
|
2022-11-09 12:37:19 +08:00
|
|
|
private Drawable currentDrawable = null!;
|
2021-06-08 18:51:40 +08:00
|
|
|
|
2021-06-08 20:58:39 +08:00
|
|
|
public LegacyCatcherNew()
|
2021-06-08 18:51:40 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-06-10 14:47:03 +08:00
|
|
|
private void load(ISkinSource skin)
|
2021-06-08 18:51:40 +08:00
|
|
|
{
|
2021-06-08 20:58:39 +08:00
|
|
|
foreach (var state in Enum.GetValues(typeof(CatcherAnimationState)).Cast<CatcherAnimationState>())
|
2021-06-08 18:51:40 +08:00
|
|
|
{
|
2021-06-10 14:45:49 +08:00
|
|
|
AddInternal(drawables[state] = getDrawableFor(state).With(d =>
|
|
|
|
{
|
|
|
|
d.Anchor = Anchor.TopCentre;
|
|
|
|
d.Origin = Anchor.TopCentre;
|
|
|
|
d.RelativeSizeAxes = Axes.Both;
|
|
|
|
d.Size = Vector2.One;
|
|
|
|
d.FillMode = FillMode.Fit;
|
|
|
|
d.Alpha = 0;
|
|
|
|
}));
|
2021-06-08 18:51:40 +08:00
|
|
|
}
|
|
|
|
|
2021-06-08 20:58:39 +08:00
|
|
|
currentDrawable = drawables[CatcherAnimationState.Idle];
|
|
|
|
|
|
|
|
Drawable getDrawableFor(CatcherAnimationState state) =>
|
|
|
|
skin.GetAnimation(@$"fruit-catcher-{state.ToString().ToLowerInvariant()}", true, true, true) ??
|
2022-11-09 12:37:19 +08:00
|
|
|
skin.GetAnimation(@"fruit-catcher-idle", true, true, true) ??
|
|
|
|
Empty();
|
2021-06-08 18:51:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2021-06-10 14:47:03 +08:00
|
|
|
currentState.BindValueChanged(state =>
|
2021-06-08 18:51:40 +08:00
|
|
|
{
|
|
|
|
currentDrawable.Alpha = 0;
|
|
|
|
currentDrawable = drawables[state.NewValue];
|
|
|
|
currentDrawable.Alpha = 1;
|
|
|
|
|
|
|
|
(currentDrawable as IFramedAnimation)?.GotoFrame(0);
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|