Show EffectCard's in the customize screen shop

This commit is contained in:
Lonami Exo 2017-07-19 13:32:49 +02:00
parent 779f37045b
commit 5b25a3f6d5
4 changed files with 98 additions and 14 deletions

View file

@ -43,7 +43,7 @@ public class MoneyBuyBand extends Table {
// The theme card that is going to be bought next. We can't
// only save the Theme because we need to tell the ThemeCard
// that it was bought so it can reflect the new theme status.
private ThemeCard toBuy;
private Object toBuy; // Either ThemeCard or EffectCard
// Used to interpolate between strings
private StringBuilder shownText;
@ -77,8 +77,12 @@ public class MoneyBuyBand extends Table {
confirmButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (toBuy != null)
toBuy.performBuy();
if (toBuy != null) {
if (toBuy instanceof ThemeCard)
((ThemeCard)toBuy).performBuy();
else if (toBuy instanceof EffectCard)
((EffectCard)toBuy).performBuy();
}
showCurrentMoney();
hideBuyButtons();
}
@ -187,6 +191,21 @@ public class MoneyBuyBand extends Table {
}
}
// TODO Make a generic card class so they all inherit
public void askBuy(final EffectCard toBuy) {
if (toBuy.effect.price > Klooni.getMoney()) {
setTempText("cannot buy!");
confirmButton.setVisible(false);
cancelButton.setVisible(false);
}
else {
this.toBuy = toBuy;
setText("confirm?");
confirmButton.setVisible(true);
cancelButton.setVisible(true);
}
}
@Override
public void draw(Batch batch, float parentAlpha) {
long now = TimeUtils.millis();

View file

@ -17,7 +17,6 @@
*/
package io.github.lonamiwebs.klooni.actors;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;

View file

@ -23,6 +23,7 @@ import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import io.github.lonamiwebs.klooni.actors.Band;
import io.github.lonamiwebs.klooni.actors.EffectCard;
import io.github.lonamiwebs.klooni.actors.ThemeCard;
// Helper class to calculate the size of each element
@ -145,5 +146,20 @@ public class GameLayout {
availableWidth - themeCardHeight, themeCardHeight);
}
// TODO Probably a more generic class "card" that can hold any type (theme/effect)
public void update(EffectCard card) {
card.setSize(availableWidth - marginWidth, themeCardHeight);
card.cellSize = themeCardHeight * 0.2f;
// X offset from the cells (5 cells = themeCardHeight)
card.nameBounds.set(
themeCardHeight, card.cellSize,
availableWidth - themeCardHeight, themeCardHeight);
card.priceBounds.set(
themeCardHeight, -card.cellSize,
availableWidth - themeCardHeight, themeCardHeight);
}
//endregion
}

View file

@ -32,8 +32,10 @@ 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 io.github.lonamiwebs.klooni.Effect;
import io.github.lonamiwebs.klooni.Klooni;
import io.github.lonamiwebs.klooni.Theme;
import io.github.lonamiwebs.klooni.actors.EffectCard;
import io.github.lonamiwebs.klooni.actors.MoneyBuyBand;
import io.github.lonamiwebs.klooni.actors.SoftButton;
import io.github.lonamiwebs.klooni.actors.ThemeCard;
@ -57,7 +59,7 @@ class CustomizeScreen implements Screen {
private boolean showingEffectsShop;
private float themeDragStartX, themeDragStartY;
private float shopDragStartX, shopDragStartY;
//endregion
@ -188,16 +190,13 @@ class CustomizeScreen implements Screen {
shopGroup.clear();
if (showingEffectsShop) {
// TODO Show the effects shop
} else {
// Showing themes shop otherwise
for (Theme theme : Theme.getThemes()) {
final ThemeCard card = new ThemeCard(game, layout, theme);
for (Effect effect : Effect.getEffects()) {
final EffectCard card = new EffectCard(game, layout, effect);
card.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
themeDragStartX = x;
themeDragStartY = y;
shopDragStartX = x;
shopDragStartY = y;
return true;
}
@ -208,8 +207,59 @@ class CustomizeScreen implements Screen {
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
x -= themeDragStartX;
y -= themeDragStartY;
x -= shopDragStartX;
y -= shopDragStartY;
float distSq = x * x + y * y;
if (distSq < DRAG_LIMIT_SQ) {
if (Klooni.isEffectBought(card.effect))
card.use();
else
buyBand.askBuy(card);
for (Actor a : shopGroup.getChildren()) {
EffectCard c = (EffectCard)a;
c.usedEffectUpdated();
}
}
}
});
shopGroup.addActor(card);
// Scroll to the currently selected theme
table.layout();
for (Actor a : shopGroup.getChildren()) {
EffectCard c = (EffectCard)a;
if (c.isUsed()) {
shopScroll.scrollTo(
c.getX(), c.getY() + c.getHeight(),
c.getWidth(), c.getHeight());
break;
}
c.usedEffectUpdated();
}
}
} else {
// Showing themes shop otherwise
for (Theme theme : Theme.getThemes()) {
final ThemeCard card = new ThemeCard(game, layout, theme);
card.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
shopDragStartX = x;
shopDragStartY = y;
return true;
}
// We could actually rely on touchDragged not being called,
// but perhaps it would be hard for some people not to move
// their fingers even the slightest bit, so we use a custom
// drag limit
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
x -= shopDragStartX;
y -= shopDragStartY;
float distSq = x * x + y * y;
if (distSq < DRAG_LIMIT_SQ) {
if (Klooni.isThemeBought(card.theme))