Commit 148fffa5 authored by Matyáš Latner's avatar Matyáš Latner

#7 Loading dialog assets separate loader

parent 9006b4bf
......@@ -110,7 +110,7 @@ task prepareSoundAssets(dependsOn: prepareAssets) {
new File("${assetsDir}/${assetsSourceDirName}/").eachDir() { langDir ->
langDir.eachDir() { sectionDir ->
sectionDir.eachDir() { atlasDir ->
task("${name}_" + atlasDir.name + "_" + langDir.name, type: Copy) {
task("${name}_" + sectionDir.name + "_" + atlasDir.name + "_" + langDir.name, type: Copy) {
from atlasDir
into "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/"
include '**/*.mp3'
......@@ -135,7 +135,7 @@ task prepareJsonAssets(dependsOn: prepareAssets) {
new File("${assetsDir}/${assetsSourceDirName}/").eachDir() { langDir ->
langDir.eachDir() { sectionDir ->
sectionDir.eachDir() { atlasDir ->
task("${name}_" + atlasDir.name + "_" + langDir.name, type: Copy) {
task("${name}_" + sectionDir.name + "_" + atlasDir.name + "_" + langDir.name, type: Copy) {
from atlasDir
into "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/"
include '**/*.json'
......
......@@ -22,6 +22,7 @@ import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.bus.ApplicationBus.ApplicationEvent;
import cz.nic.tablexia.bus.event.DimmerControlEvent;
import cz.nic.tablexia.debug.DebugInfo;
import cz.nic.tablexia.loader.TablexiaAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.menu.MenuController;
......@@ -49,10 +50,15 @@ public abstract class TablexiaApplication implements ApplicationListener {
private static final float LOADER_DIALOG_SIZE_RATIO = 2f / 3;
private TablexiaAtlasManager preloaderAtlasManager;
private ScreenTransaction currentScreenTransaction;
private boolean newScreenPreloaderAsync = true;
private boolean preloaderStart = false;
private static AbstractTablexiaScreen<?> screen;
private AbstractTablexiaScreen<?> lastScreen;
private InputMultiplexer inputMultiplexer;
private LoaderDialog loadingDialog;
private PreloaderDialog loadingDialog;
private DebugInfo debugInfo;
private Actor screenDimmer;
private Group menuLayer;
......@@ -77,6 +83,7 @@ public abstract class TablexiaApplication implements ApplicationListener {
@Override
public void dispose() {
disposePreloader();
ApplicationBus.getInstance().unsubscribe(screenDimmer);
inputMultiplexer.removeProcessor(stage);
if (debugInfo != null) {
......@@ -131,6 +138,15 @@ public abstract class TablexiaApplication implements ApplicationListener {
stage.act(deltaTime);
stage.draw();
if (preloaderStart && preloaderAtlasManager != null) {
if (newScreenPreloaderAsync) {
if (!preloaderAtlasManager.update()) return;
preloaderComplete();
} else {
preloaderAtlasManager.finishLoading();
}
}
}
@Override
......@@ -212,26 +228,13 @@ public abstract class TablexiaApplication implements ApplicationListener {
}
//////////////////////////// SCREEN HANDLING
public static class ScreenChangedEvent implements ApplicationEvent {
private Class<? extends AbstractTablexiaScreen<?>> screenClass;
public ScreenChangedEvent(Class<? extends AbstractTablexiaScreen<?>> screenClass) {
this.screenClass = screenClass;
}
public Class<? extends AbstractTablexiaScreen<?>> getScreenClass() {
return screenClass;
}
}
//////////////////////////// SCREEN PRELOADER
private static abstract class LoaderDialog extends TablexiaDialog {
private static abstract class PreloaderDialog extends TablexiaDialog {
private TablexiaButton textButton;
public LoaderDialog(float x, float y, float width, float height, BackGroundType backGroundType) {
public PreloaderDialog(float x, float y, float width, float height, BackGroundType backGroundType) {
super(x, y, width, height, backGroundType);
}
......@@ -261,6 +264,67 @@ public abstract class TablexiaApplication implements ApplicationListener {
}
public void startPreloader(AbstractTablexiaScreen newScreen, ScreenTransaction screenTransaction) {
currentScreenTransaction = screenTransaction;
newScreenPreloaderAsync = newScreen.isLoadAsync();
preloaderAtlasManager = new TablexiaAtlasManager(newScreen.getStorageType());
preloaderAtlasManager.loadAtlas(newScreen.preparePreloaderAtlasPath());
preloaderStart = true;
}
public void stopPreloader() {
preloaderStart = false;
preloaderAtlasManager = null;
currentScreenTransaction = null;
newScreenPreloaderAsync = true;
}
public void disposePreloader() {
if (preloaderAtlasManager != null) {
preloaderAtlasManager.dispose();
stopPreloader();
}
}
private void preloaderComplete() {
preloaderStart = false;
float width = getStage().getHeight() * LOADER_DIALOG_SIZE_RATIO;
float height = width;
loadingDialog = new PreloaderDialog(TablexiaSettings.getViewportWidth(getStage()) / 2 - width / 2,
TablexiaSettings.getViewportHeight(getStage()) / 2 - height / 2,
width, height, TablexiaDialog.BackGroundType.DIALOG_SQUARE) {
@Override
protected void buttonAction() {
currentScreenTransaction.continueWithTransaction();
}
@Override
protected void prepareContent() {
getContentTable().add(new Image(preloaderAtlasManager.getTextureRegionFromAtlas(screen.preparePreloaderAtlasPath(), "preloader_info", null)));
getContentTable().row();
super.prepareContent();
}
};
loadingDialog.show(getStage());
}
//////////////////////////// SCREEN HANDLING
public static class ScreenChangedEvent implements ApplicationEvent {
private Class<? extends AbstractTablexiaScreen<?>> screenClass;
public ScreenChangedEvent(Class<? extends AbstractTablexiaScreen<?>> screenClass) {
this.screenClass = screenClass;
}
public Class<? extends AbstractTablexiaScreen<?>> getScreenClass() {
return screenClass;
}
}
/**
* Change current screen if is different from actual screen.
*
......@@ -350,35 +414,13 @@ public abstract class TablexiaApplication implements ApplicationListener {
new Runnable() {
@Override
public void run() {
if (newScreen.hasPreloader()) {
float width = getStage().getHeight() * LOADER_DIALOG_SIZE_RATIO;
float height = width;
loadingDialog = new LoaderDialog(TablexiaSettings.getViewportWidth(getStage()) / 2 - width / 2,
TablexiaSettings.getViewportHeight(getStage()) / 2 - height / 2,
width, height, TablexiaDialog.BackGroundType.DIALOG_SQUARE) {
@Override
protected void buttonAction() {
screenTransaction.continueWithTransaction();
}
};
loadingDialog.show(getStage());
} else {
loadingDialog = null;
}
public void run() {processStartLoading(newScreen, screenTransaction);
}
},
new Runnable() {
@Override
public void run() {
if (loadingDialog == null) {
screenTransaction.continueWithTransaction();
} else {
loadingDialog.setDisabled(false);
}
public void run() { processLoadingComplete(screenTransaction);
}
});
}
......@@ -417,7 +459,25 @@ public abstract class TablexiaApplication implements ApplicationListener {
}
}
private void processStartLoading(AbstractTablexiaScreen<?> newScreen, ScreenTransaction screenTransaction) {
if (newScreen.hasPreloader()) {
startPreloader(newScreen, screenTransaction);
} else {
stopPreloader();
loadingDialog = null;
}
}
private void processLoadingComplete(ScreenTransaction screenTransaction) {
if (loadingDialog == null) {
screenTransaction.continueWithTransaction();
} else {
loadingDialog.setDisabled(false);
}
}
private void processScreenVisible(AbstractTablexiaScreen<?> lastScreen) {
disposePreloader();
try {
lastScreen.performScreenVisible();
} catch (Throwable t) {
......
......@@ -42,10 +42,6 @@ public enum GameDefinition implements ApplicationEvent, IMenuItem {
private boolean hasTutorial;
private GameResultResolver gameResultResolver;
public static GameDefinition[] getActiveGames() {
return new GameDefinition[]{ROBBERY, PURSUIT, KIDNAPPING, NIGHT_WATCH, SHOOTING_RANGE, IN_THE_DARKNESS};
}
GameDefinition(int gameNumber, String nameResource, String descriptionResource, Class<? extends AbstractTablexiaGame<?>> screenClass, boolean hasTutorial, GameResultResolver gameResultResolver) {
this.gameNumber = gameNumber;
this.menuTextKey = nameResource;
......
......@@ -274,8 +274,15 @@ public abstract class AbstractTablexiaScreen<T> extends ScreenAdapter {
dataManager.setInitialState(initialState);
}
public TablexiaAbstractFileManager.AssetsStorageType getStorageType() {
return storageType;
}
public boolean isLoadAsync() {
return loadAsync;
}
//////////////////////////// SCREEN PAUSE
//////////////////////////// SCREEN PAUSE
public boolean canBePaused() {
return true;
......@@ -524,6 +531,11 @@ public abstract class AbstractTablexiaScreen<T> extends ScreenAdapter {
}
}
public String preparePreloaderAtlasPath() {
// prepare standard preloader atlas path
return "_preloader/" + screenName + "/" + prepareScreenName() + ".atlas";
}
protected String prepareScreenAtlasPath(String screenAssetsPath, String screenName) {
// prepare standard screen atlas name
return screenAssetsPath + screenName + ".atlas";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment