Showcase the effects on the shop more slowly
This commit is contained in:
parent
b0abab11ab
commit
29fedd74a5
3 changed files with 49 additions and 5 deletions
|
@ -21,6 +21,7 @@ import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
|
import com.badlogic.gdx.math.Matrix4;
|
||||||
|
|
||||||
import io.github.lonamiwebs.klooni.Effect;
|
import io.github.lonamiwebs.klooni.Effect;
|
||||||
import io.github.lonamiwebs.klooni.Klooni;
|
import io.github.lonamiwebs.klooni.Klooni;
|
||||||
|
@ -71,16 +72,30 @@ public class EffectCard extends ShopCard {
|
||||||
// so it's becomes cellSize * 2
|
// so it's becomes cellSize * 2
|
||||||
cell.pos.set(x + cellSize * 2, y + cellSize * 2);
|
cell.pos.set(x + cellSize * 2, y + cellSize * 2);
|
||||||
|
|
||||||
if (currentEffect != null && !currentEffect.isDone()) {
|
// If we're not showcasing (currentEffect == null), show the cell alone
|
||||||
currentEffect.draw(batch);
|
if (currentEffect == null)
|
||||||
} else {
|
|
||||||
cell.draw(batch);
|
cell.draw(batch);
|
||||||
currentEffect = effect.create(cell, cell.pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.draw(batch, parentAlpha);
|
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
|
@Override
|
||||||
public void usedItemUpdated() {
|
public void usedItemUpdated() {
|
||||||
if (game.effect.name.equals(effect.name))
|
if (game.effect.name.equals(effect.name))
|
||||||
|
|
|
@ -70,6 +70,11 @@ public abstract class ShopCard extends Actor {
|
||||||
priceLabel.draw(batch, parentAlpha);
|
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 usedItemUpdated();
|
||||||
public abstract void use();
|
public abstract void use();
|
||||||
public abstract boolean isBought();
|
public abstract boolean isBought();
|
||||||
|
|
|
@ -22,6 +22,7 @@ import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Input;
|
import com.badlogic.gdx.Input;
|
||||||
import com.badlogic.gdx.Screen;
|
import com.badlogic.gdx.Screen;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
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.Actor;
|
||||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||||
import com.badlogic.gdx.scenes.scene2d.InputListener;
|
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.Table;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
|
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
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.Effect;
|
||||||
import io.github.lonamiwebs.klooni.Klooni;
|
import io.github.lonamiwebs.klooni.Klooni;
|
||||||
|
@ -59,6 +61,7 @@ class CustomizeScreen implements Screen {
|
||||||
final MoneyBuyBand buyBand;
|
final MoneyBuyBand buyBand;
|
||||||
|
|
||||||
private boolean showingEffectsShop;
|
private boolean showingEffectsShop;
|
||||||
|
private int showcaseIndex;
|
||||||
|
|
||||||
private float shopDragStartX, shopDragStartY;
|
private float shopDragStartX, shopDragStartY;
|
||||||
|
|
||||||
|
@ -187,6 +190,8 @@ class CustomizeScreen implements Screen {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadShop() {
|
private void loadShop() {
|
||||||
|
showcaseIndex = 0; // Reset the index
|
||||||
|
|
||||||
final GameLayout layout = new GameLayout();
|
final GameLayout layout = new GameLayout();
|
||||||
shopGroup.clear();
|
shopGroup.clear();
|
||||||
|
|
||||||
|
@ -260,9 +265,28 @@ class CustomizeScreen implements Screen {
|
||||||
public void render(float delta) {
|
public void render(float delta) {
|
||||||
Klooni.theme.glClearBackground();
|
Klooni.theme.glClearBackground();
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
stage.act(Math.min(Gdx.graphics.getDeltaTime(), MIN_DELTA));
|
stage.act(Math.min(Gdx.graphics.getDeltaTime(), MIN_DELTA));
|
||||||
stage.draw();
|
stage.draw();
|
||||||
|
|
||||||
|
// After everything is drawn, showcase the current shop item
|
||||||
|
SnapshotArray<Actor> 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)) {
|
if (Gdx.input.isKeyJustPressed(Input.Keys.BACK)) {
|
||||||
goBack();
|
goBack();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue