mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
animated startup
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package forge.screens;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
|
||||
import forge.Forge;
|
||||
import forge.Graphics;
|
||||
import forge.animation.ForgeAnimation;
|
||||
import forge.assets.FSkin;
|
||||
import forge.assets.FSkinColor;
|
||||
import forge.assets.FSkinFont;
|
||||
@@ -20,12 +22,14 @@ public class SplashScreen extends FContainer {
|
||||
private TextureRegion background;
|
||||
private final FProgressBar progressBar;
|
||||
private FSkinFont disclaimerFont;
|
||||
private boolean preparedForDialogs, showModeSelector, init;
|
||||
private boolean preparedForDialogs, showModeSelector, init, nobg;
|
||||
private FButton btnAdventure, btnHome;
|
||||
private BGAnimation bgAnimation;
|
||||
|
||||
public SplashScreen() {
|
||||
progressBar = new FProgressBar();
|
||||
progressBar.setDescription("Welcome to Forge");
|
||||
bgAnimation = new BGAnimation();
|
||||
}
|
||||
|
||||
public FProgressBar getProgressBar() {
|
||||
@@ -72,13 +76,59 @@ public class SplashScreen extends FContainer {
|
||||
showModeSelector = value;
|
||||
}
|
||||
|
||||
private class BGAnimation extends ForgeAnimation {
|
||||
private static final float DURATION = 0.8f;
|
||||
private float progress = 0;
|
||||
private boolean finished, openAdventure;
|
||||
|
||||
public void drawBackground(Graphics g) {
|
||||
float percentage = progress / DURATION;
|
||||
if (percentage < 0) {
|
||||
percentage = 0;
|
||||
} else if (percentage > 1) {
|
||||
percentage = 1;
|
||||
}
|
||||
if (nobg) {
|
||||
float scale = 1.3f+(percentage*0.7f);
|
||||
float hscale = 1.5f+(percentage*0.9f);
|
||||
float logoHeight = FSkin.hdLogo.getHeight()*scale;
|
||||
float logoWidth = FSkin.hdLogo.getWidth()*scale;
|
||||
float logoY = getHeight()/2 - logoHeight/hscale;
|
||||
float logoX = getWidth()/2 - logoWidth/2;
|
||||
float mod = getHeight()/2 - logoHeight/2;
|
||||
float oldalpha = g.getfloatAlphaComposite();
|
||||
g.setAlphaComposite(oldalpha-percentage);
|
||||
g.drawImage(FSkin.hdLogo, logoX, logoY+(mod*percentage), logoWidth, logoHeight);
|
||||
g.setAlphaComposite(oldalpha);
|
||||
} else if (showModeSelector)
|
||||
showSelector(g);
|
||||
else
|
||||
showSplash(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean advance(float dt) {
|
||||
progress += dt;
|
||||
return progress < DURATION;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEnd(boolean endingAll) {
|
||||
if (nobg) {
|
||||
if (openAdventure)
|
||||
Forge.openAdventure();
|
||||
else
|
||||
Forge.openHomeDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground(Graphics g) {
|
||||
if (showModeSelector)
|
||||
showSelector(g);
|
||||
else
|
||||
showSplash(g);
|
||||
bgAnimation.start();
|
||||
bgAnimation.drawBackground(g);
|
||||
}
|
||||
|
||||
private void showSelector(Graphics g) {
|
||||
g.drawImage(FSkinTexture.BG_TEXTURE, 0, 0, getWidth(), getHeight());
|
||||
|
||||
@@ -97,14 +147,11 @@ public class SplashScreen extends FContainer {
|
||||
w = getHeight() / backgroundRatio;
|
||||
x = (getWidth() - w) / 2;
|
||||
}
|
||||
float oldalpha = g.getfloatAlphaComposite();
|
||||
g.setAlphaComposite(0.5f);
|
||||
if (FSkin.hdLogo != null) {
|
||||
g.drawImage(FSkin.hdLogo, getWidth()/2 - (FSkin.hdLogo.getWidth()*1.3f)/2, getHeight()/2 - (FSkin.hdLogo.getHeight()*1.3f)/1.5f, FSkin.hdLogo.getWidth()*1.3f, FSkin.hdLogo.getHeight()*1.3f);
|
||||
} else {
|
||||
g.drawImage(background, x, y, w, h);
|
||||
}
|
||||
g.setAlphaComposite(oldalpha);
|
||||
y += h * 295f / 450f;
|
||||
float padding = 20f / 450f * w;
|
||||
float height = 57f / 450f * h;
|
||||
@@ -115,13 +162,29 @@ public class SplashScreen extends FContainer {
|
||||
btnAdventure.setCommand(new FEvent.FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
Forge.openAdventure();
|
||||
if (FSkin.hdLogo == null)
|
||||
Forge.openAdventure();
|
||||
else {
|
||||
btnAdventure.setVisible(false);
|
||||
btnHome.setVisible(false);
|
||||
nobg = true;
|
||||
bgAnimation.progress = 0;
|
||||
bgAnimation.openAdventure = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
btnHome.setCommand(new FEvent.FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
Forge.openHomeDefault();
|
||||
if (FSkin.hdLogo == null)
|
||||
Forge.openHomeDefault();
|
||||
else {
|
||||
btnAdventure.setVisible(false);
|
||||
btnHome.setVisible(false);
|
||||
nobg = true;
|
||||
bgAnimation.progress = 0;
|
||||
bgAnimation.openAdventure = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
float btn_w = (w - 2 * padding);
|
||||
|
||||
Reference in New Issue
Block a user