mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Prevent back color flickering when multiple popups appear back to back
This commit is contained in:
@@ -258,11 +258,7 @@ public class Forge implements ApplicationListener {
|
|||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
if (currentScreen != null) {
|
if (currentScreen != null) {
|
||||||
FOverlay overlay = FOverlay.getTopOverlay();
|
FOverlay.hideAll();
|
||||||
while (overlay != null) {
|
|
||||||
overlay.hide();
|
|
||||||
overlay = FOverlay.getTopOverlay();
|
|
||||||
}
|
|
||||||
currentScreen.onClose(null);
|
currentScreen.onClose(null);
|
||||||
currentScreen = null;
|
currentScreen = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package forge.toolbox;
|
|||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import com.badlogic.gdx.Input.Keys;
|
import com.badlogic.gdx.Input.Keys;
|
||||||
|
import com.badlogic.gdx.utils.Timer;
|
||||||
|
import com.badlogic.gdx.utils.Timer.Task;
|
||||||
|
|
||||||
import forge.Forge;
|
import forge.Forge;
|
||||||
import forge.Graphics;
|
import forge.Graphics;
|
||||||
@@ -12,6 +14,8 @@ import forge.assets.FSkinColor.Colors;
|
|||||||
public abstract class FOverlay extends FContainer {
|
public abstract class FOverlay extends FContainer {
|
||||||
public static final float ALPHA_COMPOSITE = 0.5f;
|
public static final float ALPHA_COMPOSITE = 0.5f;
|
||||||
private static final Stack<FOverlay> overlays = new Stack<FOverlay>();
|
private static final Stack<FOverlay> overlays = new Stack<FOverlay>();
|
||||||
|
private static boolean hidingAll = false;
|
||||||
|
private static FOverlay tempOverlay;
|
||||||
|
|
||||||
private FSkinColor backColor;
|
private FSkinColor backColor;
|
||||||
|
|
||||||
@@ -34,6 +38,22 @@ public abstract class FOverlay extends FContainer {
|
|||||||
return overlays;
|
return overlays;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void hideAll() {
|
||||||
|
hidingAll = true;
|
||||||
|
for (int i = overlays.size() - 1; i >= 0; i--) {
|
||||||
|
overlays.get(i).hide();
|
||||||
|
}
|
||||||
|
overlays.clear();
|
||||||
|
hidingAll = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Task hideTempOverlayTask = new Task() {
|
||||||
|
@Override
|
||||||
|
public void run () {
|
||||||
|
tempOverlay.hide();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public void show() {
|
public void show() {
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
@@ -46,12 +66,38 @@ public abstract class FOverlay extends FContainer {
|
|||||||
public void setVisible(boolean visible0) {
|
public void setVisible(boolean visible0) {
|
||||||
if (this.isVisible() == visible0) { return; }
|
if (this.isVisible() == visible0) { return; }
|
||||||
|
|
||||||
|
//ensure task to hide temporary overlay cancelled and run if another overlay becomes shown or hidden
|
||||||
|
if (tempOverlay != this && hideTempOverlayTask.isScheduled()) {
|
||||||
|
hideTempOverlayTask.cancel();
|
||||||
|
hideTempOverlayTask.run();
|
||||||
|
}
|
||||||
|
|
||||||
if (visible0) {
|
if (visible0) {
|
||||||
overlays.push(this);
|
overlays.push(this);
|
||||||
}
|
}
|
||||||
|
else if (!hidingAll) { //hiding all handles cleaning up overlay collection
|
||||||
|
if (overlays.get(overlays.size() - 1) == this) {
|
||||||
|
overlays.pop();
|
||||||
|
|
||||||
|
//after removing the top overlay, put up an empty overlay for a brief period
|
||||||
|
//to prevent back color flickering if another popup immediately follows
|
||||||
|
if (tempOverlay != this) {
|
||||||
|
if (tempOverlay == null) {
|
||||||
|
tempOverlay = new FOverlay() {
|
||||||
|
@Override
|
||||||
|
protected void doLayout(float width, float height) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
tempOverlay.backColor = backColor;
|
||||||
|
tempOverlay.show();
|
||||||
|
Timer.schedule(hideTempOverlayTask, 0.025f);
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
overlays.remove(this);
|
overlays.remove(this);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
super.setVisible(visible0);
|
super.setVisible(visible0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user