From 5b25a3f6d5662d57b8bb13800a3ef45e1ad1b6f6 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Wed, 19 Jul 2017 13:32:49 +0200 Subject: [PATCH] Show EffectCard's in the customize screen shop --- .../klooni/actors/MoneyBuyBand.java | 25 ++++++- .../lonamiwebs/klooni/actors/ThemeCard.java | 1 - .../lonamiwebs/klooni/game/GameLayout.java | 16 +++++ .../klooni/screens/CustomizeScreen.java | 70 ++++++++++++++++--- 4 files changed, 98 insertions(+), 14 deletions(-) diff --git a/core/src/io/github/lonamiwebs/klooni/actors/MoneyBuyBand.java b/core/src/io/github/lonamiwebs/klooni/actors/MoneyBuyBand.java index 0475e9c..89dbd2a 100644 --- a/core/src/io/github/lonamiwebs/klooni/actors/MoneyBuyBand.java +++ b/core/src/io/github/lonamiwebs/klooni/actors/MoneyBuyBand.java @@ -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(); diff --git a/core/src/io/github/lonamiwebs/klooni/actors/ThemeCard.java b/core/src/io/github/lonamiwebs/klooni/actors/ThemeCard.java index 46fe019..9bcbd9a 100644 --- a/core/src/io/github/lonamiwebs/klooni/actors/ThemeCard.java +++ b/core/src/io/github/lonamiwebs/klooni/actors/ThemeCard.java @@ -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; diff --git a/core/src/io/github/lonamiwebs/klooni/game/GameLayout.java b/core/src/io/github/lonamiwebs/klooni/game/GameLayout.java index 90d0404..709a444 100644 --- a/core/src/io/github/lonamiwebs/klooni/game/GameLayout.java +++ b/core/src/io/github/lonamiwebs/klooni/game/GameLayout.java @@ -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 } diff --git a/core/src/io/github/lonamiwebs/klooni/screens/CustomizeScreen.java b/core/src/io/github/lonamiwebs/klooni/screens/CustomizeScreen.java index 22e1db0..1066ff5 100644 --- a/core/src/io/github/lonamiwebs/klooni/screens/CustomizeScreen.java +++ b/core/src/io/github/lonamiwebs/klooni/screens/CustomizeScreen.java @@ -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))