mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
Start working on API to support transition animations
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -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/animation/AbilityEffect.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/GifDecoder.java -text
|
||||
forge-gui-mobile/src/forge/animation/GuiTimer.java -text
|
||||
|
||||
@@ -23,7 +23,7 @@ public abstract class ForgeAnimation {
|
||||
float dt = Gdx.graphics.getDeltaTime();
|
||||
for (int i = 0; i < activeAnimations.size(); i++) {
|
||||
if (!activeAnimations.get(i).advance(dt)) {
|
||||
activeAnimations.remove(i);
|
||||
activeAnimations.remove(i).onEnd(false);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
@@ -36,10 +36,14 @@ public abstract class ForgeAnimation {
|
||||
public static void endAll() {
|
||||
if (activeAnimations.isEmpty()) { return; }
|
||||
|
||||
for (ForgeAnimation animation : activeAnimations) {
|
||||
animation.onEnd(true);
|
||||
}
|
||||
activeAnimations.clear();
|
||||
Gdx.graphics.setContinuousRendering(false);
|
||||
}
|
||||
|
||||
//return true if animation should continue, false to stop the animation
|
||||
protected abstract boolean advance(float dt);
|
||||
protected abstract void onEnd(boolean endingAll);
|
||||
}
|
||||
|
||||
98
forge-gui-mobile/src/forge/animation/ForgeTransition.java
Normal file
98
forge-gui-mobile/src/forge/animation/ForgeTransition.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,4 +34,8 @@ public class GifAnimation extends ForgeAnimation {
|
||||
g.drawImage(currentFrame, x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEnd(boolean endingAll) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public abstract class FOverlay extends FContainer {
|
||||
if (overlays.get(overlays.size() - 1) == this) {
|
||||
//after removing the top overlay, delay hiding overlay for a brief period
|
||||
//to prevent back color flickering if another popup immediately follows
|
||||
if (tempOverlay != this) {
|
||||
if (tempOverlay != this && backColor != null) {
|
||||
tempOverlay = this;
|
||||
Timer.schedule(hideTempOverlayTask, 0.025f);
|
||||
return;
|
||||
@@ -104,6 +104,8 @@ public abstract class FOverlay extends FContainer {
|
||||
|
||||
@Override
|
||||
protected void drawBackground(Graphics g) {
|
||||
if (backColor == null) { return; }
|
||||
|
||||
g.fillRect(backColor, 0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
activeFlingAnimation = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEnd(boolean endingAll) {
|
||||
activeFlingAnimation = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user