Use `With` to simplify drawable construction

This commit is contained in:
Dean Herbert 2021-06-10 15:45:49 +09:00
parent e5deecf459
commit 6995945360
1 changed files with 11 additions and 10 deletions

View File

@ -35,18 +35,17 @@ public LegacyCatcherNew()
[BackgroundDependencyLoader]
private void load(ISkinSource skin, Bindable<CatcherAnimationState> currentState)
{
CurrentState.BindTo(currentState);
foreach (var state in Enum.GetValues(typeof(CatcherAnimationState)).Cast<CatcherAnimationState>())
{
var d = getDrawableFor(state);
d.Anchor = Anchor.TopCentre;
d.Origin = Anchor.TopCentre;
d.RelativeSizeAxes = Axes.Both;
d.Size = Vector2.One;
d.FillMode = FillMode.Fit;
d.Alpha = 0;
AddInternal(drawables[state] = d);
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;
}));
}
currentDrawable = drawables[CatcherAnimationState.Idle];
@ -54,6 +53,8 @@ private void load(ISkinSource skin, Bindable<CatcherAnimationState> currentState
Drawable getDrawableFor(CatcherAnimationState state) =>
skin.GetAnimation(@$"fruit-catcher-{state.ToString().ToLowerInvariant()}", true, true, true) ??
skin.GetAnimation(@"fruit-catcher-idle", true, true, true);
CurrentState.BindTo(currentState);
}
protected override void LoadComplete()