From 5efc7cb4965e25e28b0bdf0163dc5c44db032fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Drahom=C3=ADr=20Karch=C5=88=C3=A1k?= <drahomir.karchnak@nic.cz> Date: Mon, 14 Dec 2015 09:07:18 +0100 Subject: [PATCH] #68 - Tweaks before building... --- .../tablexia/loader/zip/ZipAssetLoader.java | 8 -- .../tablexia/screen/loader/LoaderScreen.java | 119 +----------------- 2 files changed, 1 insertion(+), 126 deletions(-) diff --git a/core/src/cz/nic/tablexia/loader/zip/ZipAssetLoader.java b/core/src/cz/nic/tablexia/loader/zip/ZipAssetLoader.java index f0fe6c3b0..fda722174 100644 --- a/core/src/cz/nic/tablexia/loader/zip/ZipAssetLoader.java +++ b/core/src/cz/nic/tablexia/loader/zip/ZipAssetLoader.java @@ -26,7 +26,6 @@ import cz.nic.tablexia.loader.TablexiaAbstractFileManager; import cz.nic.tablexia.loader.TablexiaDataManager; import cz.nic.tablexia.loader.application.ApplicationTextManager; import cz.nic.tablexia.screen.AbstractTablexiaScreen; -import cz.nic.tablexia.screen.loader.event.FileDownloadEvent; import cz.nic.tablexia.util.Log; /** @@ -267,8 +266,6 @@ public class ZipAssetLoader extends TablexiaDataManager<Void> implements IApplic long lastTime = System.currentTimeMillis(); float speed = 0; - ApplicationBus.getInstance().post(new FileDownloadEvent(FileDownloadEvent.FileDownloadEventType.Started, fileName, 0, 0)).asynchronously(); - try { while ((count = is.read(bytes, 0, bytes.length)) != -1) { os.write(bytes, 0, count); @@ -280,14 +277,11 @@ public class ZipAssetLoader extends TablexiaDataManager<Void> implements IApplic final int progress = ((int) (((double) read / (double) length) * 100)); ApplicationBus.getInstance().post(new AbstractTablexiaScreen.ScreenInfoEvent("Downloading: ", fileName + " [ " + progress + "% ]")).asynchronously(); - ApplicationBus.getInstance().post(new FileDownloadEvent(FileDownloadEvent.FileDownloadEventType.Update, fileName, progress, speed)).asynchronously(); } - ApplicationBus.getInstance().post(new FileDownloadEvent(FileDownloadEvent.FileDownloadEventType.Finished, fileName, 1, speed)).asynchronously(); downloadResult = true; } catch (IOException e) { Log.err(ZipAssetLoader.class, "Cannot download file: " + fileName + " !", e); - ApplicationBus.getInstance().post(new FileDownloadEvent(FileDownloadEvent.FileDownloadEventType.Failed, fileName, 0, 0)).asynchronously(); downloadResult = false; } notifyDownload(); @@ -296,7 +290,6 @@ public class ZipAssetLoader extends TablexiaDataManager<Void> implements IApplic @Override public void failed(Throwable t) { Log.err(ZipAssetLoader.class, "Downloading of file: " + fileName + " Failed!", t); - ApplicationBus.getInstance().post(new FileDownloadEvent(FileDownloadEvent.FileDownloadEventType.Failed, fileName, 0, 0)).asynchronously(); downloadResult = false; notifyDownload(); } @@ -304,7 +297,6 @@ public class ZipAssetLoader extends TablexiaDataManager<Void> implements IApplic @Override public void cancelled() { Log.info(ZipAssetLoader.class, "Downloading of file: " + fileName + " Canceled!"); - ApplicationBus.getInstance().post(new FileDownloadEvent(FileDownloadEvent.FileDownloadEventType.Failed, fileName, 0, 0)).asynchronously(); downloadResult = false; notifyDownload(); } diff --git a/core/src/cz/nic/tablexia/screen/loader/LoaderScreen.java b/core/src/cz/nic/tablexia/screen/loader/LoaderScreen.java index 69578085a..2e583c826 100644 --- a/core/src/cz/nic/tablexia/screen/loader/LoaderScreen.java +++ b/core/src/cz/nic/tablexia/screen/loader/LoaderScreen.java @@ -44,18 +44,12 @@ public class LoaderScreen extends AbstractTablexiaScreen<Void> { private TablexiaTextureManager textureManager; - private LoadingBar loadingBar; - private LoadingStatusText loadingStatusText; private Image launchLogo; private String currentLanguage; - private boolean finishedDownload = false; public LoaderScreen() { this.textureManager = new TablexiaTextureManager(TablexiaAbstractFileManager.AssetsStorageType.INTERNAL); - - //TODO - Unsubcribe - ApplicationBus.getInstance().subscribe(this); } @Override @@ -88,77 +82,9 @@ public class LoaderScreen extends AbstractTablexiaScreen<Void> { prepareBackground(); prepareClockHands(); prepareLaunchLogo(); - prepareLoadingBar(); - prepareLoadingStatusText(); - loadingStatusText.changeText(LoadingStatusText.StatusText.ASSETS_CHECK, 1); - -// simulateDownload(); - } - - private void simulateDownload() { - final int repeat = 20 * 10; - - Timer.schedule(new Timer.Task() { - float progress = 0; - boolean started = false; - @Override - public void run() { - if(!started) { - ApplicationBus.getInstance().post(new FileDownloadEvent(FileDownloadEvent.FileDownloadEventType.Started, "test", progress, 0)).asynchronously(); - started = true; - } - ApplicationBus.getInstance().post(new FileDownloadEvent(FileDownloadEvent.FileDownloadEventType.Update, "test", progress, 1234f)).asynchronously(); - progress += (1 / (float)(repeat)); - - if(progress >= 1) - ApplicationBus.getInstance().post(new FileDownloadEvent(FileDownloadEvent.FileDownloadEventType.Finished, "test", progress, 0)).asynchronously(); - } - }, 2, 0.05f, repeat); } - - ////////////////// HANDLERS - - @Handler - public void onLoadingCompleteEvent(Tablexia.ApplicationLoadingCompleteEvent applicationLoadingCompleteEvent) { - loadingBar.addAction(new SequenceAction(Actions.fadeOut(1), Actions.visible(false))); - loadingStatusText.addAction(Actions.fadeOut(1)); - } - - @Handler - public void onFileDownloadEvent(FileDownloadEvent event) { - switch (event.getType()) { - case Started: - if(!loadingBar.isVisible()) { - loadingBar.addAction(Actions.alpha(0)); - loadingBar.addAction(Actions.visible(true)); - loadingBar.addAction(Actions.fadeIn(1)); - } - loadingStatusText.changeText(LoadingStatusText.StatusText.DOWNLOADING_ASSETS, 1); - finishedDownload = false; - break; - - case Update: - loadingBar.setCurrentPercentage(event.getProgress()); - break; - - case Finished: - if(!finishedDownload) { - System.out.println("Finished downloading file: " + event.getFileName() + "."); - finishedDownload = true; - - loadingBar.addAction(new SequenceAction(Actions.fadeOut(.5f), Actions.visible(false))); - loadingStatusText.changeText(LoadingStatusText.StatusText.EXTRACTING_ASSETS, 1); - } - break; - - case Failed: - System.out.println("Failed downloading file: " + event.getFileName() + "."); - break; - } - } - ////////////////// PREPARING private void prepareTextures () { @@ -216,51 +142,8 @@ public class LoaderScreen extends AbstractTablexiaScreen<Void> { int height = (int) (width * (launchLogoTexture.getHeight() / (float)(launchLogoTexture.getWidth()))); launchLogo.setSize(width, height); - launchLogo.setPosition(getSceneWidth() / 2 - width / 2, getSceneInnerTopY()); - launchLogo.addAction(Actions.alpha(0)); + launchLogo.setPosition(getSceneWidth() / 2 - width / 2, getSceneInnerTopY() - height - (getSceneInnerHeight() * LAUNCH_LOGO_FINAL_Y_OFFSET)); getStage().addActor(launchLogo); - - //Animate the launch logo - MoveToAction moveActions = Actions.moveTo(getSceneWidth() / 2 - (width / 2), - getSceneInnerTopY() - height - (getSceneInnerHeight() * LAUNCH_LOGO_FINAL_Y_OFFSET), - LAUNCH_LOGO_ANIM_DURATION, - Interpolation.pow2); - - launchLogo.addAction(new ParallelAction(Actions.alpha(1, LAUNCH_LOGO_ANIM_DURATION), moveActions)); - } - - public void prepareLoadingBar() { - //Skin for LoadingBar - LoadingBar.LoadingBarSkin skin = new LoadingBar.LoadingBarSkin( - textureManager.getTexture(LoaderAssets.LOADER_BAR_BACKGROUND), - textureManager.getTexture(LoaderAssets.LOADER_BAR_FOREGROUND) - ); - - //Creates loading bar - this.loadingBar = new LoadingBar(0, 100, skin); - - //Set Size - loadingBar.setWidth(LOADING_BAR_WIDTH * getSceneWidth()); - loadingBar.setHeight(loadingBar.getWidth() * (skin.getBackgroundImage().getHeight() / (float) (skin.getForegroundImage().getWidth()))); - - //Set position - loadingBar.setPosition(getSceneWidth() / 2 - loadingBar.getWidth() / 2, 100); - loadingBar.addAction(Actions.visible(false)); - - getStage().addActor(loadingBar); - } - - public void prepareLoadingStatusText() { - Texture tex = textureManager.getTexture(LoaderAssets.LOADER_TEXTS + "_" + currentLanguage + ".png"); - tex.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); - - loadingStatusText = new LoadingStatusText(tex); - float width = LOADING_STATUS_TEXT_WIDTH * getSceneWidth(); - float height = width * (loadingStatusText.getSourceLineHeight() / tex.getWidth()); - loadingStatusText.setSize(width, height); - loadingStatusText.setPosition(getSceneWidth() / 2 - loadingStatusText.getWidth() / 2, loadingBar.getY() + loadingBar.getHeight() + 10); - - getStage().addActor(loadingStatusText); } } \ No newline at end of file -- GitLab