From 29fedd74a5443401f6488c25f7deeff37f7ad363 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Wed, 19 Jul 2017 19:53:38 +0200 Subject: [PATCH] Showcase the effects on the shop more slowly --- .../lonamiwebs/klooni/actors/EffectCard.java | 25 +++++++++++++++---- .../lonamiwebs/klooni/actors/ShopCard.java | 5 ++++ .../klooni/screens/CustomizeScreen.java | 24 ++++++++++++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/core/src/io/github/lonamiwebs/klooni/actors/EffectCard.java b/core/src/io/github/lonamiwebs/klooni/actors/EffectCard.java index 1dca3aa..beb65bd 100644 --- a/core/src/io/github/lonamiwebs/klooni/actors/EffectCard.java +++ b/core/src/io/github/lonamiwebs/klooni/actors/EffectCard.java @@ -21,6 +21,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.math.Matrix4; import io.github.lonamiwebs.klooni.Effect; import io.github.lonamiwebs.klooni.Klooni; @@ -71,16 +72,30 @@ public class EffectCard extends ShopCard { // so it's becomes cellSize * 2 cell.pos.set(x + cellSize * 2, y + cellSize * 2); - if (currentEffect != null && !currentEffect.isDone()) { - currentEffect.draw(batch); - } else { + // If we're not showcasing (currentEffect == null), show the cell alone + if (currentEffect == null) cell.draw(batch); - currentEffect = effect.create(cell, cell.pos); - } super.draw(batch, parentAlpha); } + @Override + public boolean showcase(Batch batch, float yDisplacement) { + cell.pos.y += yDisplacement; + + // If it's null, create it, then we want to render + if (currentEffect == null) { + currentEffect = effect.create(cell, cell.pos); + } else if (currentEffect.isDone()) { + // Set to null so it's created the next time + currentEffect = null; + return false; + } + + currentEffect.draw(batch); + return true; + } + @Override public void usedItemUpdated() { if (game.effect.name.equals(effect.name)) diff --git a/core/src/io/github/lonamiwebs/klooni/actors/ShopCard.java b/core/src/io/github/lonamiwebs/klooni/actors/ShopCard.java index c9082ad..e875a5b 100644 --- a/core/src/io/github/lonamiwebs/klooni/actors/ShopCard.java +++ b/core/src/io/github/lonamiwebs/klooni/actors/ShopCard.java @@ -70,6 +70,11 @@ public abstract class ShopCard extends Actor { priceLabel.draw(batch, parentAlpha); } + // Showcases the current effect (the shop will be showcasing them, one by one) + // This method should be called on the same card as long as it returns true. + // It should return false once it's done so that the next card can be showcased. + public boolean showcase(Batch batch, float yDisplacement) { return false; } + public abstract void usedItemUpdated(); public abstract void use(); public abstract boolean isBought(); diff --git a/core/src/io/github/lonamiwebs/klooni/screens/CustomizeScreen.java b/core/src/io/github/lonamiwebs/klooni/screens/CustomizeScreen.java index 580c3cd..a7da1a9 100644 --- a/core/src/io/github/lonamiwebs/klooni/screens/CustomizeScreen.java +++ b/core/src/io/github/lonamiwebs/klooni/screens/CustomizeScreen.java @@ -22,6 +22,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputListener; @@ -31,6 +32,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; +import com.badlogic.gdx.utils.SnapshotArray; import io.github.lonamiwebs.klooni.Effect; import io.github.lonamiwebs.klooni.Klooni; @@ -59,6 +61,7 @@ class CustomizeScreen implements Screen { final MoneyBuyBand buyBand; private boolean showingEffectsShop; + private int showcaseIndex; private float shopDragStartX, shopDragStartY; @@ -187,6 +190,8 @@ class CustomizeScreen implements Screen { } private void loadShop() { + showcaseIndex = 0; // Reset the index + final GameLayout layout = new GameLayout(); shopGroup.clear(); @@ -260,9 +265,28 @@ class CustomizeScreen implements Screen { public void render(float delta) { Klooni.theme.glClearBackground(); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + stage.act(Math.min(Gdx.graphics.getDeltaTime(), MIN_DELTA)); stage.draw(); + // After everything is drawn, showcase the current shop item + SnapshotArray children = shopGroup.getChildren(); + if (children.size > 0) { + final ShopCard card = (ShopCard)children.get(showcaseIndex); + + final Batch batch = stage.getBatch(); + batch.begin(); + // For some really strange reason, we need to displace the particle effect + // by "buyBand.height", or it will render exactly that height below where + // it should. + // TODO Fix this - maybe use the same project matrix as stage.draw()? + // batch.setProjectionMatrix(stage.getViewport().getCamera().combined) + if (!card.showcase(batch, buyBand.getHeight())) { + showcaseIndex = (showcaseIndex + 1) % children.size; + } + batch.end(); + } + if (Gdx.input.isKeyJustPressed(Input.Keys.BACK)) { goBack(); }