Merge pull request #1309 from kevlahnota/master

Add progressbar on adventure loading transition
This commit is contained in:
Anthony Calosa
2022-08-10 19:58:54 +08:00
committed by GitHub
3 changed files with 41 additions and 6 deletions

View File

@@ -56,10 +56,9 @@ public class NewGameScene extends UIScene {
Config.instance().getConfigData().difficulties[difficulty.getCurrentIndex()], Config.instance().getConfigData().difficulties[difficulty.getCurrentIndex()],
mode.getCurrentIndex()==2, mode.getCurrentIndex()==1, 0);//maybe replace with enum mode.getCurrentIndex()==2, mode.getCurrentIndex()==1, 0);//maybe replace with enum
GamePlayerUtil.getGuiPlayer().setName(selectedName.getText()); GamePlayerUtil.getGuiPlayer().setName(selectedName.getText());
Forge.clearTransitionScreen();
Forge.switchScene(SceneType.GameScene.instance); Forge.switchScene(SceneType.GameScene.instance);
}; };
Forge.setTransitionScreen(new TransitionScreen(runnable, null, false, true)); Forge.setTransitionScreen(new TransitionScreen(runnable, null, false, true, "Generating World..."));
return true; return true;
} }

View File

@@ -143,7 +143,7 @@ public class SaveLoadScene extends UIScene {
} else { } else {
Forge.clearTransitionScreen(); Forge.clearTransitionScreen();
} }
}, null, false, true)); }, null, false, true, "Generating World..."));
} catch (Exception e) { } catch (Exception e) {
Forge.clearTransitionScreen(); Forge.clearTransitionScreen();
} }

View File

@@ -8,19 +8,33 @@ import forge.animation.ForgeAnimation;
import forge.assets.FSkin; import forge.assets.FSkin;
import forge.assets.FSkinImage; import forge.assets.FSkinImage;
import forge.assets.FSkinTexture; import forge.assets.FSkinTexture;
import forge.gui.FThreads;
import forge.sound.SoundSystem; import forge.sound.SoundSystem;
import forge.toolbox.FContainer; import forge.toolbox.FContainer;
import forge.toolbox.FProgressBar;
public class TransitionScreen extends FContainer { public class TransitionScreen extends FContainer {
private BGAnimation bgAnimation; private BGAnimation bgAnimation;
private FProgressBar progressBar;
Runnable runnable; Runnable runnable;
TextureRegion textureRegion; TextureRegion textureRegion;
private String message = "";
boolean matchTransition, isloading, isIntro, isFadeMusic; boolean matchTransition, isloading, isIntro, isFadeMusic;
public TransitionScreen(Runnable proc, TextureRegion screen, boolean enterMatch, boolean loading) { public TransitionScreen(Runnable proc, TextureRegion screen, boolean enterMatch, boolean loading) {
this(proc, screen, enterMatch, loading, false, false); this(proc, screen, enterMatch, loading, false, false);
} }
public TransitionScreen(Runnable proc, TextureRegion screen, boolean enterMatch, boolean loading, String loadingMessage) {
this(proc, screen, enterMatch, loading, false, false, loadingMessage);
}
public TransitionScreen(Runnable proc, TextureRegion screen, boolean enterMatch, boolean loading, boolean intro, boolean fadeMusic) { public TransitionScreen(Runnable proc, TextureRegion screen, boolean enterMatch, boolean loading, boolean intro, boolean fadeMusic) {
this(proc, screen, enterMatch, loading, intro, fadeMusic, "");
}
public TransitionScreen(Runnable proc, TextureRegion screen, boolean enterMatch, boolean loading, boolean intro, boolean fadeMusic, String loadingMessage) {
progressBar = new FProgressBar();
progressBar.setMaximum(100);
progressBar.setPercentMode(true);
progressBar.setShowETA(false);
bgAnimation = new BGAnimation(); bgAnimation = new BGAnimation();
runnable = proc; runnable = proc;
textureRegion = screen; textureRegion = screen;
@@ -28,8 +42,12 @@ public class TransitionScreen extends FContainer {
isloading = loading; isloading = loading;
isIntro = intro; isIntro = intro;
isFadeMusic = fadeMusic; isFadeMusic = fadeMusic;
message = loadingMessage;
} }
public FProgressBar getProgressBar() {
return progressBar;
}
@Override @Override
protected void doLayout(float width, float height) { protected void doLayout(float width, float height) {
@@ -63,12 +81,29 @@ public class TransitionScreen extends FContainer {
g.setAlphaComposite(oldAlpha); g.setAlphaComposite(oldAlpha);
} }
float xmod = Forge.getScreenHeight() > 2000 ? 1.5f : 1f; float xmod = Forge.getScreenHeight() > 2000 ? 1.5f : 1f;
xmod *= percentage; xmod *= Forge.isMobileAdventureMode ? 1 : percentage;
float ymod;
if (FSkin.hdLogo != null) { if (FSkin.hdLogo != null) {
ymod = Forge.getScreenHeight()/2 + (FSkin.hdLogo.getHeight()*xmod)/2;
g.drawImage(FSkin.hdLogo, Forge.getScreenWidth()/2 - (FSkin.hdLogo.getWidth()*xmod)/2, Forge.getScreenHeight()/2 - (FSkin.hdLogo.getHeight()*xmod)/2, FSkin.hdLogo.getWidth()*xmod, FSkin.hdLogo.getHeight()*xmod); g.drawImage(FSkin.hdLogo, Forge.getScreenWidth()/2 - (FSkin.hdLogo.getWidth()*xmod)/2, Forge.getScreenHeight()/2 - (FSkin.hdLogo.getHeight()*xmod)/2, FSkin.hdLogo.getWidth()*xmod, FSkin.hdLogo.getHeight()*xmod);
} else { } else {
ymod = Forge.getScreenHeight()/2 + (FSkinImage.LOGO.getHeight()*xmod)/1.5f;
g.drawImage(FSkinImage.LOGO,Forge.getScreenWidth()/2 - (FSkinImage.LOGO.getWidth()*xmod)/2, Forge.getScreenHeight()/2 - (FSkinImage.LOGO.getHeight()*xmod)/1.5f, FSkinImage.LOGO.getWidth()*xmod, FSkinImage.LOGO.getHeight()*xmod); g.drawImage(FSkinImage.LOGO,Forge.getScreenWidth()/2 - (FSkinImage.LOGO.getWidth()*xmod)/2, Forge.getScreenHeight()/2 - (FSkinImage.LOGO.getHeight()*xmod)/1.5f, FSkinImage.LOGO.getWidth()*xmod, FSkinImage.LOGO.getHeight()*xmod);
} }
//loading progressbar - todo make this accurate when generating world
if (Forge.isMobileAdventureMode) {
float w = Forge.isLandscapeMode() ? Forge.getScreenWidth() / 2 : Forge.getScreenHeight() / 2;
float h = 57f / 450f * (w/2);
float x = (Forge.getScreenWidth() - w) / 2;
float y = ymod + 10;
int multi = ((int) (percentage*100)) < 97 ? (int) (percentage*100) : 100;
progressBar.setBounds(x, y, w, h);
progressBar.setValue(multi);
if (multi == 100 && !message.isEmpty()) {
progressBar.setDescription(message);
}
g.draw(progressBar);
}
} else if (matchTransition) { } else if (matchTransition) {
if (textureRegion != null) if (textureRegion != null)
g.drawWarpImage(textureRegion, 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight(), percentage); g.drawWarpImage(textureRegion, 0, 0, Forge.getScreenWidth(), Forge.getScreenHeight(), percentage);
@@ -93,8 +128,9 @@ public class TransitionScreen extends FContainer {
@Override @Override
protected void onEnd(boolean endingAll) { protected void onEnd(boolean endingAll) {
if (runnable != null) if (runnable != null) {
runnable.run(); FThreads.invokeInEdtNowOrLater(runnable);
}
} }
} }