mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
update transform animation
This commit is contained in:
@@ -447,6 +447,10 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
|
|||||||
return setState(state, updateView, false);
|
return setState(state, updateView, false);
|
||||||
}
|
}
|
||||||
public boolean setState(final CardStateName state, boolean updateView, boolean forceUpdate) {
|
public boolean setState(final CardStateName state, boolean updateView, boolean forceUpdate) {
|
||||||
|
boolean rollback = state == CardStateName.Original
|
||||||
|
&& (currentStateName == CardStateName.Flipped || currentStateName == CardStateName.Transformed);
|
||||||
|
boolean transform = state == CardStateName.Flipped || state == CardStateName.Transformed || state == CardStateName.Meld;
|
||||||
|
boolean updateNeedsTransform = transform || rollback;
|
||||||
// faceDown has higher priority over clone states
|
// faceDown has higher priority over clone states
|
||||||
// while text change states doesn't apply while the card is faceDown
|
// while text change states doesn't apply while the card is faceDown
|
||||||
if (state != CardStateName.FaceDown) {
|
if (state != CardStateName.FaceDown) {
|
||||||
@@ -487,6 +491,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
|
|||||||
|
|
||||||
if (updateView) {
|
if (updateView) {
|
||||||
view.updateState(this);
|
view.updateState(this);
|
||||||
|
view.updateNeedsTransformAnimation(transform);
|
||||||
|
|
||||||
final Game game = getGame();
|
final Game game = getGame();
|
||||||
if (game != null) {
|
if (game != null) {
|
||||||
|
|||||||
@@ -830,6 +830,14 @@ public class CardView extends GameEntityView {
|
|||||||
set(TrackableProperty.HasBackSide, hasBackSide);
|
set(TrackableProperty.HasBackSide, hasBackSide);
|
||||||
set(TrackableProperty.BackSideName, stateName);
|
set(TrackableProperty.BackSideName, stateName);
|
||||||
}
|
}
|
||||||
|
public boolean needsTransformAnimation() {
|
||||||
|
if (get(TrackableProperty.NeedsTransformAnimation) == null)
|
||||||
|
return false;
|
||||||
|
return get(TrackableProperty.NeedsTransformAnimation);
|
||||||
|
}
|
||||||
|
public void updateNeedsTransformAnimation(boolean value) {
|
||||||
|
set(TrackableProperty.NeedsTransformAnimation, value);
|
||||||
|
}
|
||||||
void updateState(Card c) {
|
void updateState(Card c) {
|
||||||
updateName(c);
|
updateName(c);
|
||||||
updateZoneText(c);
|
updateZoneText(c);
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ public enum TrackableProperty {
|
|||||||
ExiledWith(TrackableTypes.CardViewType),
|
ExiledWith(TrackableTypes.CardViewType),
|
||||||
WasDestroyed(TrackableTypes.BooleanType),
|
WasDestroyed(TrackableTypes.BooleanType),
|
||||||
CrackOverlay(TrackableTypes.IntegerType),
|
CrackOverlay(TrackableTypes.IntegerType),
|
||||||
|
NeedsTransformAnimation(TrackableTypes.BooleanType),
|
||||||
|
|
||||||
ImprintedCards(TrackableTypes.CardViewCollectionType),
|
ImprintedCards(TrackableTypes.CardViewCollectionType),
|
||||||
HauntedBy(TrackableTypes.CardViewCollectionType),
|
HauntedBy(TrackableTypes.CardViewCollectionType),
|
||||||
|
|||||||
@@ -572,6 +572,7 @@ public class MatchScreen extends FScreen {
|
|||||||
}
|
}
|
||||||
else { //ensure card not on battlefield is reset such that it no longer thinks it's on the battlefield
|
else { //ensure card not on battlefield is reset such that it no longer thinks it's on the battlefield
|
||||||
pnl.setTapped(false);
|
pnl.setTapped(false);
|
||||||
|
pnl.setNeedsTransform(false);
|
||||||
pnl.getAttachedPanels().clear();
|
pnl.getAttachedPanels().clear();
|
||||||
pnl.setAttachedToPanel(null);
|
pnl.setAttachedToPanel(null);
|
||||||
pnl.setPrevPanelInStack(null);
|
pnl.setPrevPanelInStack(null);
|
||||||
|
|||||||
@@ -283,6 +283,7 @@ public abstract class VCardDisplayArea extends VDisplayArea implements ActivateH
|
|||||||
|
|
||||||
public void updateCard(final CardView card) {
|
public void updateCard(final CardView card) {
|
||||||
setTapped(card.isTapped());
|
setTapped(card.isTapped());
|
||||||
|
setNeedsTransform(card.needsTransformAnimation());
|
||||||
|
|
||||||
attachedPanels.clear();
|
attachedPanels.clear();
|
||||||
|
|
||||||
|
|||||||
@@ -23,12 +23,11 @@ public class FCardPanel extends FDisplayObject {
|
|||||||
private boolean tapped;
|
private boolean tapped;
|
||||||
private boolean highlighted;
|
private boolean highlighted;
|
||||||
private boolean wasTapped;
|
private boolean wasTapped;
|
||||||
private boolean wasTransformed;
|
private boolean needsTransform;
|
||||||
CardTapAnimation tapAnimation;
|
CardTapAnimation tapAnimation;
|
||||||
CardUnTapAnimation untapAnimation;
|
CardUnTapAnimation untapAnimation;
|
||||||
CardDestroyedAnimation destroyedAnimation;
|
CardDestroyedAnimation destroyedAnimation;
|
||||||
CardTransformAnimation transformAnimation;
|
CardTransformAnimation transformAnimation;
|
||||||
CardRollbackAnimation rollbackAnimation;
|
|
||||||
|
|
||||||
public FCardPanel() {
|
public FCardPanel() {
|
||||||
this(null);
|
this(null);
|
||||||
@@ -39,7 +38,6 @@ public class FCardPanel extends FDisplayObject {
|
|||||||
untapAnimation = new CardUnTapAnimation();
|
untapAnimation = new CardUnTapAnimation();
|
||||||
destroyedAnimation = new CardDestroyedAnimation();
|
destroyedAnimation = new CardDestroyedAnimation();
|
||||||
transformAnimation = new CardTransformAnimation();
|
transformAnimation = new CardTransformAnimation();
|
||||||
rollbackAnimation = new CardRollbackAnimation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CardView getCard() {
|
public CardView getCard() {
|
||||||
@@ -62,6 +60,9 @@ public class FCardPanel extends FDisplayObject {
|
|||||||
public void setTapped(final boolean tapped0) {
|
public void setTapped(final boolean tapped0) {
|
||||||
tapped = tapped0;
|
tapped = tapped0;
|
||||||
}
|
}
|
||||||
|
public void setNeedsTransform(final boolean needsTransform0) {
|
||||||
|
needsTransform = needsTransform0;
|
||||||
|
}
|
||||||
|
|
||||||
protected float getTappedAngle() {
|
protected float getTappedAngle() {
|
||||||
return -90;
|
return -90;
|
||||||
@@ -95,8 +96,8 @@ public class FCardPanel extends FDisplayObject {
|
|||||||
return CardStackPosition.Top;
|
return CardStackPosition.Top;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CardRollbackAnimation extends ForgeAnimation {
|
private class CardTransformAnimation extends ForgeAnimation {
|
||||||
private static final float DURATION = 0.12f;
|
private static final float DURATION = 0.14f;
|
||||||
private float progress = 0;
|
private float progress = 0;
|
||||||
private boolean finished;
|
private boolean finished;
|
||||||
|
|
||||||
@@ -106,60 +107,27 @@ public class FCardPanel extends FDisplayObject {
|
|||||||
percentage = 0;
|
percentage = 0;
|
||||||
} else if (percentage > 1) {
|
} else if (percentage > 1) {
|
||||||
percentage = 1;
|
percentage = 1;
|
||||||
wasTransformed = false;
|
needsTransform = false;
|
||||||
|
card.updateNeedsTransformAnimation(false);
|
||||||
|
progress = 0;
|
||||||
}
|
}
|
||||||
float mod = percentage;
|
float mod = percentage;
|
||||||
float x2 = x + (w - (w*mod))/2;
|
|
||||||
float w2 = w*mod;
|
|
||||||
if (tapped) {
|
|
||||||
g.startRotateTransform(x + edgeOffset, y + h - edgeOffset, getTappedAngle());
|
|
||||||
}
|
|
||||||
CardRenderer.drawCardWithOverlays(g, card, x2, y, w2, h, getStackPosition());
|
|
||||||
if (tapped) {
|
|
||||||
g.endTransform();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean advance(float dt) {
|
|
||||||
progress += dt;
|
|
||||||
return progress < DURATION;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onEnd(boolean endingAll) {
|
|
||||||
finished = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private class CardTransformAnimation extends ForgeAnimation {
|
|
||||||
private static final float DURATION = 0.12f;
|
|
||||||
private float progress = 0;
|
|
||||||
private boolean finished;
|
|
||||||
|
|
||||||
private void drawCard(Graphics g, CardView card, float x, float y, float w, float h, float edgeOffset) {
|
|
||||||
float percentage = progress / DURATION;
|
|
||||||
if (percentage < 0) {
|
|
||||||
percentage = 0;
|
|
||||||
} else if (percentage > 1) {
|
|
||||||
percentage = 1;
|
|
||||||
wasTransformed = true;
|
|
||||||
}
|
|
||||||
float mod = card.hasAlternateState() ? percentage : 1f;
|
|
||||||
float y2 = y + (h - (h*mod))/2;
|
float y2 = y + (h - (h*mod))/2;
|
||||||
float x2 = x + (w - (w*mod))/2;
|
float x2 = x + (w - (w*mod))/2;
|
||||||
float w2 = w*mod;
|
float w2 = w*mod;
|
||||||
float h2 = h*mod;
|
float h2 = h*mod;
|
||||||
if (tapped) {
|
if (card.getCurrentState().getState() == CardStateName.Original && needsTransform) {
|
||||||
g.startRotateTransform(x + edgeOffset, y + h - edgeOffset, getTappedAngle());
|
//rollback
|
||||||
}
|
CardRenderer.drawCardWithOverlays(g, card, x2, y, w2, h, getStackPosition());
|
||||||
|
} else if (card.hasAlternateState() && (card.getCurrentState().getState() == CardStateName.Flipped
|
||||||
|
|| card.getCurrentState().getState() == CardStateName.Transformed || card.getCurrentState().getState() == CardStateName.Meld) && needsTransform) {
|
||||||
|
//transform
|
||||||
if (card.getCurrentState().getState() == CardStateName.Transformed || card.getCurrentState().getState() == CardStateName.Flipped)
|
if (card.getCurrentState().getState() == CardStateName.Transformed || card.getCurrentState().getState() == CardStateName.Flipped)
|
||||||
CardRenderer.drawCardWithOverlays(g, card, x2, y, w2, h, getStackPosition());
|
CardRenderer.drawCardWithOverlays(g, card, x2, y, w2, h, getStackPosition());
|
||||||
else if (card.getCurrentState().getState() == CardStateName.Meld)
|
else if (card.getCurrentState().getState() == CardStateName.Meld)
|
||||||
CardRenderer.drawCardWithOverlays(g, card, x2, y2, w2, h2, getStackPosition());
|
CardRenderer.drawCardWithOverlays(g, card, x2, y2, w2, h2, getStackPosition());
|
||||||
else //default
|
} else {
|
||||||
CardRenderer.drawCardWithOverlays(g, card, x, y, w, h, getStackPosition());
|
CardRenderer.drawCardWithOverlays(g, card, x, y2, w, h2, getStackPosition());
|
||||||
if (tapped) {
|
|
||||||
g.endTransform();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,15 +193,12 @@ public class FCardPanel extends FDisplayObject {
|
|||||||
percentage = 0;
|
percentage = 0;
|
||||||
} else if (percentage > 1) {
|
} else if (percentage > 1) {
|
||||||
percentage = 1;
|
percentage = 1;
|
||||||
|
wasTapped = false;
|
||||||
}
|
}
|
||||||
float angle = -90 + (percentage*90);
|
float angle = -90 + (percentage*90);
|
||||||
if (wasTapped) {
|
|
||||||
g.startRotateTransform(x + edgeOffset, y + h - edgeOffset, angle);
|
g.startRotateTransform(x + edgeOffset, y + h - edgeOffset, angle);
|
||||||
CardRenderer.drawCardWithOverlays(g, card, x, y, w, h, getStackPosition());
|
CardRenderer.drawCardWithOverlays(g, card, x, y, w, h, getStackPosition());
|
||||||
g.endTransform();
|
g.endTransform();
|
||||||
} else {
|
|
||||||
CardRenderer.drawCardWithOverlays(g, card, x, y, w, h, getStackPosition());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -249,7 +214,7 @@ public class FCardPanel extends FDisplayObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class CardTapAnimation extends ForgeAnimation {
|
private class CardTapAnimation extends ForgeAnimation {
|
||||||
private static final float DURATION = 0.18f;
|
private static final float DURATION = 0.14f;
|
||||||
private float progress = 0;
|
private float progress = 0;
|
||||||
private boolean finished;
|
private boolean finished;
|
||||||
|
|
||||||
@@ -297,13 +262,7 @@ public class FCardPanel extends FDisplayObject {
|
|||||||
|
|
||||||
if (!animate || isGameFast || MatchController.instance.getGameView().isMatchOver()) {
|
if (!animate || isGameFast || MatchController.instance.getGameView().isMatchOver()) {
|
||||||
//don't animate if game is fast or match is over
|
//don't animate if game is fast or match is over
|
||||||
if (tapped) {
|
rotateTransform(g, x, y, w, h, edgeOffset, false);
|
||||||
g.startRotateTransform(x + edgeOffset, y + h - edgeOffset, getTappedAngle());
|
|
||||||
}
|
|
||||||
CardRenderer.drawCardWithOverlays(g, card, x, y, w, h, getStackPosition());
|
|
||||||
if (tapped) {
|
|
||||||
g.endTransform();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
//card destroy animation
|
//card destroy animation
|
||||||
if (card.wasDestroyed()) {
|
if (card.wasDestroyed()) {
|
||||||
@@ -312,61 +271,13 @@ public class FCardPanel extends FDisplayObject {
|
|||||||
destroyedAnimation.start();
|
destroyedAnimation.start();
|
||||||
destroyedAnimation.drawCard(g, card, x, y, w, h, edgeOffset);
|
destroyedAnimation.drawCard(g, card, x, y, w, h, edgeOffset);
|
||||||
} else {
|
} else {
|
||||||
if (tapped) {
|
rotateTransform(g, x, y, w, h, edgeOffset, animate);
|
||||||
g.startRotateTransform(x + edgeOffset, y + h - edgeOffset, getTappedAngle());
|
|
||||||
}
|
|
||||||
CardRenderer.drawCardWithOverlays(g, card, x, y, w, h, getStackPosition());
|
|
||||||
if (tapped) {
|
|
||||||
g.endTransform();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//card transform animation
|
|
||||||
if (card.getCurrentState().getState() == CardStateName.Original && wasTransformed) {
|
|
||||||
//reset transform
|
|
||||||
if (transformAnimation != null)
|
|
||||||
transformAnimation.progress = 0;
|
|
||||||
if (rollbackAnimation != null) {
|
|
||||||
if (rollbackAnimation.progress < 1) {
|
|
||||||
rollbackAnimation.start();
|
|
||||||
rollbackAnimation.drawCard(g, card, x, y, w, h, edgeOffset);
|
|
||||||
} else {
|
|
||||||
if (tapped) {
|
|
||||||
g.startRotateTransform(x + edgeOffset, y + h - edgeOffset, getTappedAngle());
|
|
||||||
}
|
|
||||||
CardRenderer.drawCardWithOverlays(g, card, x, y, w, h, getStackPosition());
|
|
||||||
if (tapped) {
|
|
||||||
g.endTransform();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (card.hasAlternateState() && (card.getCurrentState().getState() == CardStateName.Flipped
|
|
||||||
|| card.getCurrentState().getState() == CardStateName.Transformed || card.getCurrentState().getState() == CardStateName.Meld) && !wasTransformed) {
|
|
||||||
//reset rollback
|
|
||||||
if (rollbackAnimation != null)
|
|
||||||
rollbackAnimation.progress = 0;
|
|
||||||
if (transformAnimation != null) {
|
|
||||||
if (transformAnimation.progress < 1) {
|
|
||||||
transformAnimation.start();
|
|
||||||
transformAnimation.drawCard(g, card, x, y, w, h, edgeOffset);
|
|
||||||
} else {
|
|
||||||
if (tapped) {
|
|
||||||
g.startRotateTransform(x + edgeOffset, y + h - edgeOffset, getTappedAngle());
|
|
||||||
}
|
|
||||||
CardRenderer.drawCardWithOverlays(g, card, x, y, w, h, getStackPosition());
|
|
||||||
if (tapped) {
|
|
||||||
g.endTransform();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//tap-untap animation
|
//tap-untap animation
|
||||||
if (tapped) {
|
if (tapped && !wasTapped) {
|
||||||
//reset untapAnimation
|
//reset untapAnimation
|
||||||
if (untapAnimation != null) {
|
if (untapAnimation != null) {
|
||||||
untapAnimation.progress = 0;
|
untapAnimation.progress = 0;
|
||||||
@@ -378,11 +289,16 @@ public class FCardPanel extends FDisplayObject {
|
|||||||
tapAnimation.drawCard(g, card, x, y, w, h, w / 2f, getTappedAngle());
|
tapAnimation.drawCard(g, card, x, y, w, h, w / 2f, getTappedAngle());
|
||||||
} else {
|
} else {
|
||||||
g.startRotateTransform(x + edgeOffset, y + h - edgeOffset, getTappedAngle());
|
g.startRotateTransform(x + edgeOffset, y + h - edgeOffset, getTappedAngle());
|
||||||
|
if (needsTransform) {
|
||||||
|
transformAnimation.start();
|
||||||
|
transformAnimation.drawCard(g, card, x, y, w, h, edgeOffset);
|
||||||
|
} else {
|
||||||
CardRenderer.drawCardWithOverlays(g, card, x, y, w, h, getStackPosition());
|
CardRenderer.drawCardWithOverlays(g, card, x, y, w, h, getStackPosition());
|
||||||
|
}
|
||||||
g.endTransform();
|
g.endTransform();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!tapped && wasTapped) {
|
||||||
//reset tapAnimation
|
//reset tapAnimation
|
||||||
if (tapAnimation != null) {
|
if (tapAnimation != null) {
|
||||||
tapAnimation.progress = 0;
|
tapAnimation.progress = 0;
|
||||||
@@ -393,14 +309,33 @@ public class FCardPanel extends FDisplayObject {
|
|||||||
untapAnimation.start();
|
untapAnimation.start();
|
||||||
untapAnimation.drawCard(g, card, x, y, w, h, edgeOffset);
|
untapAnimation.drawCard(g, card, x, y, w, h, edgeOffset);
|
||||||
} else {
|
} else {
|
||||||
wasTapped = false;
|
if (needsTransform) {
|
||||||
|
transformAnimation.start();
|
||||||
|
transformAnimation.drawCard(g, card, x, y, w, h, edgeOffset);
|
||||||
|
} else {
|
||||||
CardRenderer.drawCardWithOverlays(g, card, x, y, w, h, getStackPosition());
|
CardRenderer.drawCardWithOverlays(g, card, x, y, w, h, getStackPosition());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
rotateTransform(g, x, y, w, h, edgeOffset, animate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void rotateTransform(Graphics g, float x, float y, float w, float h, float edgeOffset, boolean animate) {
|
||||||
|
if (tapped) {
|
||||||
|
g.startRotateTransform(x + edgeOffset, y + h - edgeOffset, getTappedAngle());
|
||||||
|
}
|
||||||
|
if (needsTransform && animate) {
|
||||||
|
transformAnimation.start();
|
||||||
|
transformAnimation.drawCard(g, card, x, y, w, h, edgeOffset);
|
||||||
|
} else {
|
||||||
|
CardRenderer.drawCardWithOverlays(g, card, x, y, w, h, getStackPosition());
|
||||||
|
}
|
||||||
|
if (tapped) {
|
||||||
|
g.endTransform();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return card == null ? "" : card.toString();
|
return card == null ? "" : card.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user