Start working on API to support transition animations

This commit is contained in:
drdev
2014-12-02 23:07:57 +00:00
parent bce1831b95
commit a7534d15e4
6 changed files with 116 additions and 3 deletions

1
.gitattributes vendored
View File

@@ -1177,6 +1177,7 @@ forge-gui-mobile/src/forge/Graphics.java -text
forge-gui-mobile/src/forge/GuiMobile.java -text forge-gui-mobile/src/forge/GuiMobile.java -text
forge-gui-mobile/src/forge/animation/AbilityEffect.java -text forge-gui-mobile/src/forge/animation/AbilityEffect.java -text
forge-gui-mobile/src/forge/animation/ForgeAnimation.java -text forge-gui-mobile/src/forge/animation/ForgeAnimation.java -text
forge-gui-mobile/src/forge/animation/ForgeTransition.java -text
forge-gui-mobile/src/forge/animation/GifAnimation.java -text forge-gui-mobile/src/forge/animation/GifAnimation.java -text
forge-gui-mobile/src/forge/animation/GifDecoder.java -text forge-gui-mobile/src/forge/animation/GifDecoder.java -text
forge-gui-mobile/src/forge/animation/GuiTimer.java -text forge-gui-mobile/src/forge/animation/GuiTimer.java -text

View File

@@ -23,7 +23,7 @@ public abstract class ForgeAnimation {
float dt = Gdx.graphics.getDeltaTime(); float dt = Gdx.graphics.getDeltaTime();
for (int i = 0; i < activeAnimations.size(); i++) { for (int i = 0; i < activeAnimations.size(); i++) {
if (!activeAnimations.get(i).advance(dt)) { if (!activeAnimations.get(i).advance(dt)) {
activeAnimations.remove(i); activeAnimations.remove(i).onEnd(false);
i--; i--;
} }
} }
@@ -36,10 +36,14 @@ public abstract class ForgeAnimation {
public static void endAll() { public static void endAll() {
if (activeAnimations.isEmpty()) { return; } if (activeAnimations.isEmpty()) { return; }
for (ForgeAnimation animation : activeAnimations) {
animation.onEnd(true);
}
activeAnimations.clear(); activeAnimations.clear();
Gdx.graphics.setContinuousRendering(false); Gdx.graphics.setContinuousRendering(false);
} }
//return true if animation should continue, false to stop the animation //return true if animation should continue, false to stop the animation
protected abstract boolean advance(float dt); protected abstract boolean advance(float dt);
protected abstract void onEnd(boolean endingAll);
} }

View File

@@ -0,0 +1,98 @@
package forge.animation;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import com.badlogic.gdx.math.Rectangle;
import forge.Graphics;
import forge.toolbox.FDisplayObject;
import forge.toolbox.FOverlay;
public class ForgeTransition extends ForgeAnimation {
private static final FOverlay overlay = new FOverlay(null) {
@Override
protected void doLayout(float width, float height) {
}
};
private static final Map<FDisplayObject, TransitionObject> transitionLookup = new LinkedHashMap<FDisplayObject, TransitionObject>();
public static void queue(FDisplayObject obj, Rectangle destBounds, float duration) {
queue(obj, destBounds, duration, 0, false);
}
public static void queue(FDisplayObject obj, Rectangle destBounds, float duration, float arcAmount, boolean arcOriginBelow) {
TransitionObject transitionObj = transitionLookup.get(obj);
if (transitionObj == null) {
transitionObj = new TransitionObject(obj);
transitionLookup.put(obj, transitionObj);
overlay.add(transitionObj);
obj.setVisible(false); //hide original object while transition in progress
}
ForgeTransition transition = new ForgeTransition(transitionObj, destBounds, duration, arcAmount, arcOriginBelow);
transitionObj.transitions.add(transition);
if (transitionObj.transitions.size() == 1) {
transition.start(); //start transition right away if first transition added
overlay.setVisible(true);
}
}
private final TransitionObject obj;
private final Rectangle destBounds;
private final float duration;
private final float arcAmount;
private final boolean arcOriginBelow;
private ForgeTransition(TransitionObject obj0, Rectangle destBounds0, float duration0, float arcAmount0, boolean arcOriginBelow0) {
obj = obj0;
destBounds = destBounds0;
duration = duration0;
arcAmount = arcAmount0;
arcOriginBelow = arcOriginBelow0;
}
@Override
protected boolean advance(float dt) {
return false;
}
@Override
protected void onEnd(boolean endingAll) {
if (endingAll) {
transitionLookup.clear();
return;
}
int index = obj.transitions.indexOf(this);
obj.transitions.remove(index);
if (index == 0) {
if (obj.transitions.isEmpty()) {
transitionLookup.remove(obj.originalObj);
overlay.remove(obj);
obj.originalObj.setVisible(true);
if (transitionLookup.isEmpty()) {
overlay.setVisible(false);
}
}
else {
obj.transitions.getFirst().start(); //start next transition if needed
}
}
}
private static class TransitionObject extends FDisplayObject {
private final FDisplayObject originalObj;
private final LinkedList<ForgeTransition> transitions = new LinkedList<ForgeTransition>();
private TransitionObject(FDisplayObject originalObj0) {
originalObj = originalObj0;
setBounds(originalObj.screenPos.x, originalObj.screenPos.y, originalObj.getWidth(), originalObj.getHeight());
}
@Override
public void draw(Graphics g) {
originalObj.draw(g);
}
}
}

View File

@@ -34,4 +34,8 @@ public class GifAnimation extends ForgeAnimation {
g.drawImage(currentFrame, x, y, w, h); g.drawImage(currentFrame, x, y, w, h);
} }
} }
@Override
protected void onEnd(boolean endingAll) {
}
} }

View File

@@ -84,7 +84,7 @@ public abstract class FOverlay extends FContainer {
if (overlays.get(overlays.size() - 1) == this) { if (overlays.get(overlays.size() - 1) == this) {
//after removing the top overlay, delay hiding overlay for a brief period //after removing the top overlay, delay hiding overlay for a brief period
//to prevent back color flickering if another popup immediately follows //to prevent back color flickering if another popup immediately follows
if (tempOverlay != this) { if (tempOverlay != this && backColor != null) {
tempOverlay = this; tempOverlay = this;
Timer.schedule(hideTempOverlayTask, 0.025f); Timer.schedule(hideTempOverlayTask, 0.025f);
return; return;
@@ -104,6 +104,8 @@ public abstract class FOverlay extends FContainer {
@Override @Override
protected void drawBackground(Graphics g) { protected void drawBackground(Graphics g) {
if (backColor == null) { return; }
g.fillRect(backColor, 0, 0, this.getWidth(), this.getHeight()); g.fillRect(backColor, 0, 0, this.getWidth(), this.getHeight());
} }

View File

@@ -238,9 +238,13 @@ public abstract class FScrollPane extends FContainer {
} }
//end fling animation if can't scroll anymore or physics object is no longer moving //end fling animation if can't scroll anymore or physics object is no longer moving
activeFlingAnimation = null;
return false; return false;
} }
@Override
protected void onEnd(boolean endingAll) {
activeFlingAnimation = null;
}
} }
@Override @Override