diff --git a/build.gradle b/build.gradle index 0f9178de35371204f5cdd511ef009063ebdc18bf..99384bacf0feb5bdda6928e4356be161b112e222 100644 --- a/build.gradle +++ b/build.gradle @@ -118,6 +118,7 @@ task prepareSoundAssets(dependsOn: prepareAssets) { eachFile { FileCopyDetails fcd -> fcd.setPath(fcd.getRelativePath().toString().replace(File.separator, '.')) } + outputs.upToDateWhen { false } }.execute() } } diff --git a/core/assets/common/_preloader/inthedarkness/preloader_anim_0.png b/core/assets/common/_preloader/inthedarkness/preloader_anim_0.png new file mode 100644 index 0000000000000000000000000000000000000000..5ce91de1b598eaacc01b2398969bb96d97a56d98 Binary files /dev/null and b/core/assets/common/_preloader/inthedarkness/preloader_anim_0.png differ diff --git a/core/assets/common/_preloader/inthedarkness/preloader_anim_1.png b/core/assets/common/_preloader/inthedarkness/preloader_anim_1.png index 5ce91de1b598eaacc01b2398969bb96d97a56d98..be6978fcb3891ebdf952732819bffb0130b33750 100644 Binary files a/core/assets/common/_preloader/inthedarkness/preloader_anim_1.png and b/core/assets/common/_preloader/inthedarkness/preloader_anim_1.png differ diff --git a/core/assets/common/_preloader/inthedarkness/preloader_anim_10.png b/core/assets/common/_preloader/inthedarkness/preloader_anim_10.png index 78dfe19bdbc204439ea360797df67aabf4b5a584..e708f3e422fbfa28d992737bdf4acc557d81526b 100644 Binary files a/core/assets/common/_preloader/inthedarkness/preloader_anim_10.png and b/core/assets/common/_preloader/inthedarkness/preloader_anim_10.png differ diff --git a/core/assets/common/_preloader/inthedarkness/preloader_anim_11.png b/core/assets/common/_preloader/inthedarkness/preloader_anim_11.png index e708f3e422fbfa28d992737bdf4acc557d81526b..06ddcaf8e8d79e496ff636f76e447b48c6bfa7b3 100644 Binary files a/core/assets/common/_preloader/inthedarkness/preloader_anim_11.png and b/core/assets/common/_preloader/inthedarkness/preloader_anim_11.png differ diff --git a/core/assets/common/_preloader/inthedarkness/preloader_anim_12.png b/core/assets/common/_preloader/inthedarkness/preloader_anim_12.png index 06ddcaf8e8d79e496ff636f76e447b48c6bfa7b3..22a6aac49099cd4f0da1348494b19649316afbd5 100644 Binary files a/core/assets/common/_preloader/inthedarkness/preloader_anim_12.png and b/core/assets/common/_preloader/inthedarkness/preloader_anim_12.png differ diff --git a/core/assets/common/_preloader/inthedarkness/preloader_anim_13.png b/core/assets/common/_preloader/inthedarkness/preloader_anim_13.png index 22a6aac49099cd4f0da1348494b19649316afbd5..a4a3a45c618354dcb60a36a81f4449cc9525dd05 100644 Binary files a/core/assets/common/_preloader/inthedarkness/preloader_anim_13.png and b/core/assets/common/_preloader/inthedarkness/preloader_anim_13.png differ diff --git a/core/assets/common/_preloader/inthedarkness/preloader_anim_14.png b/core/assets/common/_preloader/inthedarkness/preloader_anim_14.png index a4a3a45c618354dcb60a36a81f4449cc9525dd05..f81cb79715b9bda7b4f21c3f558349050f01811c 100644 Binary files a/core/assets/common/_preloader/inthedarkness/preloader_anim_14.png and b/core/assets/common/_preloader/inthedarkness/preloader_anim_14.png differ diff --git a/core/assets/common/_preloader/inthedarkness/preloader_anim_15.png b/core/assets/common/_preloader/inthedarkness/preloader_anim_15.png deleted file mode 100644 index f81cb79715b9bda7b4f21c3f558349050f01811c..0000000000000000000000000000000000000000 Binary files a/core/assets/common/_preloader/inthedarkness/preloader_anim_15.png and /dev/null differ diff --git a/core/assets/common/_preloader/inthedarkness/preloader_anim_2.png b/core/assets/common/_preloader/inthedarkness/preloader_anim_2.png index be6978fcb3891ebdf952732819bffb0130b33750..57e80075a95f8d9dbac9c682f825e446162f7ee5 100644 Binary files a/core/assets/common/_preloader/inthedarkness/preloader_anim_2.png and b/core/assets/common/_preloader/inthedarkness/preloader_anim_2.png differ diff --git a/core/assets/common/_preloader/inthedarkness/preloader_anim_3.png b/core/assets/common/_preloader/inthedarkness/preloader_anim_3.png index 57e80075a95f8d9dbac9c682f825e446162f7ee5..69f6b685427089e235709a3f0f2a65bd1956f6b3 100644 Binary files a/core/assets/common/_preloader/inthedarkness/preloader_anim_3.png and b/core/assets/common/_preloader/inthedarkness/preloader_anim_3.png differ diff --git a/core/assets/common/_preloader/inthedarkness/preloader_anim_4.png b/core/assets/common/_preloader/inthedarkness/preloader_anim_4.png index 69f6b685427089e235709a3f0f2a65bd1956f6b3..afab7f6745328cae131b847b50eb560e26f448f6 100644 Binary files a/core/assets/common/_preloader/inthedarkness/preloader_anim_4.png and b/core/assets/common/_preloader/inthedarkness/preloader_anim_4.png differ diff --git a/core/assets/common/_preloader/inthedarkness/preloader_anim_5.png b/core/assets/common/_preloader/inthedarkness/preloader_anim_5.png index afab7f6745328cae131b847b50eb560e26f448f6..2cfe1bc6b72160011bf8ceb5b7c08f92c9a6db47 100644 Binary files a/core/assets/common/_preloader/inthedarkness/preloader_anim_5.png and b/core/assets/common/_preloader/inthedarkness/preloader_anim_5.png differ diff --git a/core/assets/common/_preloader/inthedarkness/preloader_anim_6.png b/core/assets/common/_preloader/inthedarkness/preloader_anim_6.png index 2cfe1bc6b72160011bf8ceb5b7c08f92c9a6db47..f9ff12501cdce60843da8cf1fa62f15722180063 100644 Binary files a/core/assets/common/_preloader/inthedarkness/preloader_anim_6.png and b/core/assets/common/_preloader/inthedarkness/preloader_anim_6.png differ diff --git a/core/assets/common/_preloader/inthedarkness/preloader_anim_7.png b/core/assets/common/_preloader/inthedarkness/preloader_anim_7.png index f9ff12501cdce60843da8cf1fa62f15722180063..6980486267cb4c3732bdbd427cfc9e260c85197d 100644 Binary files a/core/assets/common/_preloader/inthedarkness/preloader_anim_7.png and b/core/assets/common/_preloader/inthedarkness/preloader_anim_7.png differ diff --git a/core/assets/common/_preloader/inthedarkness/preloader_anim_8.png b/core/assets/common/_preloader/inthedarkness/preloader_anim_8.png index 6980486267cb4c3732bdbd427cfc9e260c85197d..eb56327cfe8e443e76f2ec43043ec19b95ee176a 100644 Binary files a/core/assets/common/_preloader/inthedarkness/preloader_anim_8.png and b/core/assets/common/_preloader/inthedarkness/preloader_anim_8.png differ diff --git a/core/assets/common/_preloader/inthedarkness/preloader_anim_9.png b/core/assets/common/_preloader/inthedarkness/preloader_anim_9.png index eb56327cfe8e443e76f2ec43043ec19b95ee176a..78dfe19bdbc204439ea360797df67aabf4b5a584 100644 Binary files a/core/assets/common/_preloader/inthedarkness/preloader_anim_9.png and b/core/assets/common/_preloader/inthedarkness/preloader_anim_9.png differ diff --git a/core/src/cz/nic/tablexia/TablexiaApplication.java b/core/src/cz/nic/tablexia/TablexiaApplication.java index 7372686e50a7ba75e7ef9e8115ae80c276e9fc21..a376af6f8aa18b9269b1157321e8fc4a03498714 100644 --- a/core/src/cz/nic/tablexia/TablexiaApplication.java +++ b/core/src/cz/nic/tablexia/TablexiaApplication.java @@ -14,6 +14,7 @@ import com.badlogic.gdx.scenes.scene2d.Touchable; import com.badlogic.gdx.scenes.scene2d.actions.Actions; import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.utils.viewport.ScreenViewport; @@ -49,8 +50,7 @@ public abstract class TablexiaApplication implements ApplicationListener { private static final Color BACKGROUND_COLOR = new Color(0f, 0f, 0f, 1f); private static final int DIMMER_TRANSACTION_SPEED = 1; - - private static final float LOADER_DIALOG_SIZE_RATIO = 2f / 3; + private static final float PRELOADER_SIZE_RATIO = 2f / 3; private TablexiaAtlasManager preloaderAtlasManager; private ScreenTransaction currentScreenTransaction; @@ -234,6 +234,11 @@ public abstract class TablexiaApplication implements ApplicationListener { private abstract class PreloaderDialog extends TablexiaDialog { + private static final float PRELOADER_TITLE_PADDING = 1f / 40; + private static final float PRELOADER_CONTENT_PADDING = 1f / 40; + private final ApplicationFontManager.FontType PRELOADER_TITLE_FONT = ApplicationFontManager.FontType.ROBOTO_BOLD_26; + private final Color PRELOADER_TITLE_COLOR = Color.BLACK; + private TablexiaButton textButton; public PreloaderDialog(float x, float y, float width, float height, BackGroundType backGroundType) { @@ -243,11 +248,14 @@ public abstract class TablexiaApplication implements ApplicationListener { @Override protected void prepareContent() { super.prepareContent(); - Label.LabelStyle titleLableStyle = new Label.LabelStyle(ApplicationFontManager.getInstance().getFont(ApplicationFontManager.FontType.ROBOTO_BOLD_20), Color.BLACK); + Label.LabelStyle titleLableStyle = new Label.LabelStyle(ApplicationFontManager.getInstance().getFont(PRELOADER_TITLE_FONT), PRELOADER_TITLE_COLOR); Label titleLabel = new Label(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.PRELOADER_TITLE), titleLableStyle); - getContentTable().add(titleLabel); + getContentTable().add(titleLabel).pad(getHeight() * PRELOADER_TITLE_PADDING); getContentTable().row(); - screen.preparePreloaderContent(getContentTable(), preloaderAtlasManager, ApplicationTextManager.getInstance(), ApplicationFontManager.getInstance()); + Table preloaderContent = new Table(); + preloaderContent.setSize(getWidth(), getHeight()); + screen.preparePreloaderContent(preloaderContent, preloaderAtlasManager, ApplicationTextManager.getInstance(), ApplicationFontManager.getInstance()); + getContentTable().add(preloaderContent).expandY().fillY().pad(getWidth() * PRELOADER_CONTENT_PADDING); getContentTable().row(); textButton = new TablexiaButton(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.CONFIRM_BUTTON), TablexiaButton.ButtonType.GREEN); textButton.addListener(new ClickListener() { @@ -296,11 +304,11 @@ public abstract class TablexiaApplication implements ApplicationListener { private void preloaderComplete() { preloaderStart = false; - float width = getStage().getHeight() * LOADER_DIALOG_SIZE_RATIO; + float width = getStage().getHeight() * PRELOADER_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) { + width, height, TablexiaDialog.BackGroundType.DIALOG_SQUARE_BORDERLINES) { @Override protected void buttonAction() { diff --git a/core/src/cz/nic/tablexia/game/games/in_the_darkness/InTheDarknessGame.java b/core/src/cz/nic/tablexia/game/games/in_the_darkness/InTheDarknessGame.java index 36c214c1b5a196b8f0ac7aafcb20ee6db3ad8424..bdfbea82c81ac0ae6bc8d96948beb8ce39df3537 100644 --- a/core/src/cz/nic/tablexia/game/games/in_the_darkness/InTheDarknessGame.java +++ b/core/src/cz/nic/tablexia/game/games/in_the_darkness/InTheDarknessGame.java @@ -39,6 +39,7 @@ import cz.nic.tablexia.loader.application.ApplicationTextManager; import cz.nic.tablexia.model.game.Game; import cz.nic.tablexia.util.Log; import cz.nic.tablexia.util.ScaleUtil; +import cz.nic.tablexia.util.ui.AnimatedImage; import cz.nic.tablexia.util.ui.TablexiaButton; import static com.badlogic.gdx.scenes.scene2d.actions.Actions.alpha; @@ -132,12 +133,16 @@ public class InTheDarknessGame extends AbstractTablexiaGame<List<MapWidget>> imp } } - private static final ApplicationFontManager.FontType PRELOADER_TEXT_FONT = ApplicationFontManager.FontType.ROBOTO_REGULAR_20; - private static final Color PRELOADER_TEXT_COLOR = Color.BLACK; - private static final String PRELOADER_INFO_IMAGE = "preloader_info"; - private static final String PRELOADER_ANIM_IMAGE = "preloader_anim"; - private static final String PRELOADER_TEXT1_KEY = ApplicationTextManager.ApplicationTextsAssets.GAME_IN_THE_DARKNESS_PRELOADER_TEXT1; - private static final String PRELOADER_TEXT2_KEY = ApplicationTextManager.ApplicationTextsAssets.GAME_IN_THE_DARKNESS_PRELOADER_TEXT2; + private static final ApplicationFontManager.FontType PRELOADER_TEXT_FONT = ApplicationFontManager.FontType.ROBOTO_REGULAR_20; + private static final Color PRELOADER_TEXT_COLOR = Color.BLACK; + private static final String PRELOADER_INFO_IMAGE = "preloader_info"; + private static final String PRELOADER_ANIM_IMAGE = "preloader_anim"; + private static final int PRELOADER_ANIM_FRAMES = 15; + private static final float PRELOADER_ANIM_FRAME_DURATION = 0.5f; + private static final String PRELOADER_TEXT1_KEY = ApplicationTextManager.ApplicationTextsAssets.GAME_IN_THE_DARKNESS_PRELOADER_TEXT1; + private static final String PRELOADER_TEXT2_KEY = ApplicationTextManager.ApplicationTextsAssets.GAME_IN_THE_DARKNESS_PRELOADER_TEXT2; + private static final float PRELOADER_TEXT_PADDING_RATIO = 1f / 40; + private static final float PRELOADER_IMAGE_WIDTH_RATIO = 1f / 3; private static final String SCORE_KEY_PLANNING_DURATION = "planning_duration"; public static final String SCORE_KEY_ERRORS_COUNT = "errors_count"; @@ -377,18 +382,34 @@ public class InTheDarknessGame extends AbstractTablexiaGame<List<MapWidget>> imp @Override public void preparePreloaderContent(Table contentTable, TablexiaAtlasManager preloaderAtlasManager, ApplicationTextManager applicationTextManager, ApplicationFontManager applicationFontManager) { - contentTable.setDebug(TablexiaSettings.getInstance().isShowBoundingBoxes(), true); + float textPadding = contentTable.getWidth() * PRELOADER_TEXT_PADDING_RATIO; + float imageWidth = contentTable.getWidth() * PRELOADER_IMAGE_WIDTH_RATIO; + float textWidth = contentTable.getWidth() - imageWidth; + + // HELP IMAGE + Table preloaderContent1 = new Table(); Image preloaderInfoImage = new Image(getPreloaderTextureRegion(preloaderAtlasManager, PRELOADER_INFO_IMAGE)); - contentTable.add(preloaderInfoImage); + ScaleUtil.setImageDrawableMinSizeForWidth(preloaderInfoImage, imageWidth); + preloaderContent1.add(preloaderInfoImage); + // HELP TEXT 1 Label.LabelStyle textLabelStyle = new Label.LabelStyle(applicationFontManager.getFont(PRELOADER_TEXT_FONT), PRELOADER_TEXT_COLOR); Label preloaderText1 = new Label(applicationTextManager.getText(PRELOADER_TEXT1_KEY), textLabelStyle); preloaderText1.setWrap(true); - contentTable.add(preloaderText1); + preloaderContent1.add(preloaderText1).width(textWidth).pad(textPadding); + contentTable.add(preloaderContent1).expandX().fillX(); contentTable.row(); + + // HELP TEXT 2 + Table preloaderContent2 = new Table(); Label preloaderText2 = new Label(applicationTextManager.getText(PRELOADER_TEXT2_KEY), textLabelStyle); preloaderText2.setWrap(true); - contentTable.add(preloaderText2); - contentTable.add(new Image(getPreloaderTextureRegion(preloaderAtlasManager, PRELOADER_ANIM_IMAGE))); + preloaderContent2.add(preloaderText2).width(textWidth).pad(textPadding); + // HELP ANIMATION + AnimatedImage preloaderAnimImage = new AnimatedImage(getPreloaderAnimation(preloaderAtlasManager, PRELOADER_ANIM_IMAGE, PRELOADER_ANIM_FRAMES, PRELOADER_ANIM_FRAME_DURATION, false), false); + preloaderAnimImage.startAnimationLoop(); + ScaleUtil.setImageDrawableMinSizeForWidth(preloaderAnimImage, imageWidth); + preloaderContent2.add(preloaderAnimImage); + contentTable.add(preloaderContent2).expandX().fillX(); } diff --git a/core/src/cz/nic/tablexia/game/games/in_the_darkness/creature/Player.java b/core/src/cz/nic/tablexia/game/games/in_the_darkness/creature/Player.java index fe2574fd59e9b77b02de4ae68e9f3259d5df1183..f51e333195e43d3f16396ce90969088f3611d9a4 100644 --- a/core/src/cz/nic/tablexia/game/games/in_the_darkness/creature/Player.java +++ b/core/src/cz/nic/tablexia/game/games/in_the_darkness/creature/Player.java @@ -23,19 +23,22 @@ import com.badlogic.gdx.graphics.g2d.Animation; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.scenes.scene2d.Group; -import com.badlogic.gdx.scenes.scene2d.ui.Image; -import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Array; -import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*; - -import cz.nic.tablexia.TablexiaSettings; import cz.nic.tablexia.game.games.in_the_darkness.InTheDarknessGame; import cz.nic.tablexia.game.games.in_the_darkness.assets.InTheDarknessAssets; import cz.nic.tablexia.game.games.in_the_darkness.map.TileMap; import cz.nic.tablexia.game.games.in_the_darkness.map.TileMap.TileMapPosition; import cz.nic.tablexia.game.games.in_the_darkness.map.tile.TileType; +import cz.nic.tablexia.util.ui.AnimatedImage; + +import static com.badlogic.gdx.scenes.scene2d.actions.Actions.moveTo; +import static com.badlogic.gdx.scenes.scene2d.actions.Actions.parallel; +import static com.badlogic.gdx.scenes.scene2d.actions.Actions.rotateTo; +import static com.badlogic.gdx.scenes.scene2d.actions.Actions.run; +import static com.badlogic.gdx.scenes.scene2d.actions.Actions.scaleTo; +import static com.badlogic.gdx.scenes.scene2d.actions.Actions.sequence; /** * Player sprite @@ -77,66 +80,13 @@ public class Player extends Group { } } - public class AnimatedImage extends Image { - - protected Animation animation; - private float stateTime = 0; - - private boolean started; - private boolean loop; - private Runnable finishHandler; - - public AnimatedImage(Animation animation, boolean started) { - super(animation.getKeyFrame(0)); - this.animation = animation; - this.started = started; - this.loop = false; - } - - public void startAnimation(Runnable finishHandler) { - this.finishHandler = finishHandler; - stateTime = 0; - started = true; - loop = false; - } - - public void startAnimationLoop() { - stateTime = 0; - started = true; - loop = true; - } - - public void stopAnimation() { - started = false; - loop = false; - } - - @Override - public void act(float delta) { - if (started) { - stateTime = stateTime + delta; - if (loop) { - ((TextureRegionDrawable)getDrawable()).setRegion(animation.getKeyFrame(stateTime += delta, true)); - } else { - ((TextureRegionDrawable)getDrawable()).setRegion(animation.getKeyFrame(stateTime, false)); - if (finishHandler != null && animation.isAnimationFinished(stateTime)) { - finishHandler.run(); - } - } - } else { - ((TextureRegionDrawable)getDrawable()).setRegion(animation.getKeyFrame(0)); - } - super.act(delta); - } - } - - private static final int PLAYER_WIDTH = 55; - private static final int PLAYER_HEIGHT = 55; + private static final int PLAYER_WIDTH = 55; + private static final int PLAYER_HEIGHT = 55; - private static final int QUARTAL_ROTATION = 90; + private static final int QUARTAL_ROTATION = 90; private AnimatedImage actualPlayerAnimatedImage; - private AnimatedImage playerWalkAnimatedImage; + private AnimatedImage playerWalkAnimatedImage; private AnimatedImage playerJumpAnimatedImage; private AnimatedImage playerCrashAnimatedImage; diff --git a/core/src/cz/nic/tablexia/loader/TablexiaAtlasManager.java b/core/src/cz/nic/tablexia/loader/TablexiaAtlasManager.java index 65eb3e964a724fce2d2416ae5f87dbb89bd6439a..1dc095be518168a6c52858abcd57c127de33932e 100644 --- a/core/src/cz/nic/tablexia/loader/TablexiaAtlasManager.java +++ b/core/src/cz/nic/tablexia/loader/TablexiaAtlasManager.java @@ -3,6 +3,7 @@ package cz.nic.tablexia.loader; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.Animation; import com.badlogic.gdx.graphics.g2d.NinePatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureRegion; @@ -84,6 +85,14 @@ public class TablexiaAtlasManager extends TablexiaAbstractFileManager { } } + public Animation getAnimationFromAtlas(String atlasName, String regionName, int framesCount, float frameDuration, boolean useBleedingFix) { + TextureRegion[] textureRegions = new TextureRegion[framesCount]; + for (int i = 0; i < framesCount; i++) { + textureRegions[i] = getTextureRegionFromAtlas(atlasName, regionName, i, useBleedingFix); + } + return new Animation(frameDuration, textureRegions); + } + public NinePatch getPatchFromAtlas(String atlasName, String patchName) { TextureAtlas atlas = getAsset(atlasName, TextureAtlas.class); if (atlas == null) { diff --git a/core/src/cz/nic/tablexia/screen/AbstractTablexiaScreen.java b/core/src/cz/nic/tablexia/screen/AbstractTablexiaScreen.java index 45beb5237e354409a9d724c58fd6dbbc7f6e3553..18ec62302d5c857d72ad2b6493ac599355c812dc 100644 --- a/core/src/cz/nic/tablexia/screen/AbstractTablexiaScreen.java +++ b/core/src/cz/nic/tablexia/screen/AbstractTablexiaScreen.java @@ -7,6 +7,7 @@ import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.g2d.Animation; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.NinePatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; @@ -635,6 +636,10 @@ public abstract class AbstractTablexiaScreen<T> extends ScreenAdapter { return preloaderAtlasManager.getTextureRegionFromAtlas(preparePreloaderAtlasPath(), regionName, null); } + public Animation getPreloaderAnimation(TablexiaAtlasManager preloaderAtlasManager, String regionName, int framesCount, float frameDuration, boolean useBleedingFix) { + return preloaderAtlasManager.getAnimationFromAtlas(preparePreloaderAtlasPath(), regionName, framesCount, frameDuration, useBleedingFix); + } + public TextureRegion getTextureRegionForAtlas(String atlasName, String regionName) { return atlasManager.getTextureRegionFromAtlas(atlasName, regionName, null); } diff --git a/core/src/cz/nic/tablexia/util/ScaleUtil.java b/core/src/cz/nic/tablexia/util/ScaleUtil.java index 4d2d3aef3afd8118288c424642e8aa06796564ba..e7915cb87418ad5ac7bf104d6c5aeeb1a860688f 100644 --- a/core/src/cz/nic/tablexia/util/ScaleUtil.java +++ b/core/src/cz/nic/tablexia/util/ScaleUtil.java @@ -1,6 +1,5 @@ package cz.nic.tablexia.util; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.scenes.scene2d.Actor; @@ -154,6 +153,16 @@ public class ScaleUtil { image.setSize(getWidth(image.getWidth(), image.getHeight(), height), height); } + public static void setImageDrawableMinSizeForHeight(Image image, float height) { + image.getDrawable().setMinHeight(height); + image.getDrawable().setMinWidth(getWidth(image.getWidth(), image.getHeight(), height)); + } + + public static void setImageDrawableMinSizeForWidth(Image image, float width) { + image.getDrawable().setMinWidth(width); + image.getDrawable().setMinHeight(getHeight(image.getWidth(), image.getHeight(), width)); + } + public static Actor setBackgroundBounds(Actor actor) { actor.setPosition(0, -TablexiaSettings.getMinWorldHeight() / 2); actor.setSize(TablexiaSettings.getWorldSize(), TablexiaSettings.getMinWorldHeight() * 2); diff --git a/core/src/cz/nic/tablexia/util/ui/AnimatedImage.java b/core/src/cz/nic/tablexia/util/ui/AnimatedImage.java new file mode 100644 index 0000000000000000000000000000000000000000..ef9724356414434abccb2f4a1e04a2fb65d2e594 --- /dev/null +++ b/core/src/cz/nic/tablexia/util/ui/AnimatedImage.java @@ -0,0 +1,61 @@ +package cz.nic.tablexia.util.ui; + +import com.badlogic.gdx.graphics.g2d.Animation; +import com.badlogic.gdx.scenes.scene2d.ui.Image; +import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; + +/** + * Created by Matyáš Latner. + */ +public class AnimatedImage extends Image { + + protected Animation animation; + private float stateTime = 0; + + private boolean started; + private boolean loop; + private Runnable finishHandler; + + public AnimatedImage(Animation animation, boolean started) { + super(animation.getKeyFrame(0)); + this.animation = animation; + this.started = started; + this.loop = false; + } + + public void startAnimation(Runnable finishHandler) { + this.finishHandler = finishHandler; + stateTime = 0; + started = true; + loop = false; + } + + public void startAnimationLoop() { + stateTime = 0; + started = true; + loop = true; + } + + public void stopAnimation() { + started = false; + loop = false; + } + + @Override + public void act(float delta) { + if (started) { + stateTime = stateTime + delta; + if (loop) { + ((TextureRegionDrawable)getDrawable()).setRegion(animation.getKeyFrame(stateTime += delta, true)); + } else { + ((TextureRegionDrawable)getDrawable()).setRegion(animation.getKeyFrame(stateTime, false)); + if (finishHandler != null && animation.isAnimationFinished(stateTime)) { + finishHandler.run(); + } + } + } else { + ((TextureRegionDrawable)getDrawable()).setRegion(animation.getKeyFrame(0)); + } + super.act(delta); + } +}