diff --git a/core/src/io/github/lonamiwebs/klooni/Theme.java b/core/src/io/github/lonamiwebs/klooni/Theme.java index 7a0c89d..4644be9 100644 --- a/core/src/io/github/lonamiwebs/klooni/Theme.java +++ b/core/src/io/github/lonamiwebs/klooni/Theme.java @@ -3,6 +3,8 @@ package io.github.lonamiwebs.klooni; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.NinePatch; import com.badlogic.gdx.scenes.scene2d.ui.ImageButton; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.utils.JsonReader; @@ -19,6 +21,8 @@ public class Theme { public static Skin skin; + public NinePatch cellPatch; + private ImageButton.ImageButtonStyle[] buttonStyles; private Theme() { @@ -82,6 +86,9 @@ public class Theme { } String cellTextureFile = json.getString("cell_texture"); + cellPatch = new NinePatch(new Texture( + Gdx.files.internal("ui/cells/"+cellTextureFile)), 4, 4, 4, 4); + return this; } diff --git a/core/src/io/github/lonamiwebs/klooni/actors/ThemeCard.java b/core/src/io/github/lonamiwebs/klooni/actors/ThemeCard.java index 86a4d92..ecc5fb4 100644 --- a/core/src/io/github/lonamiwebs/klooni/actors/ThemeCard.java +++ b/core/src/io/github/lonamiwebs/klooni/actors/ThemeCard.java @@ -2,9 +2,7 @@ package io.github.lonamiwebs.klooni.actors; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; -import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.g2d.NinePatch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.scenes.scene2d.Actor; @@ -19,15 +17,9 @@ public class ThemeCard extends Actor { public final Theme theme; - // TODO Use the cell patch given the theme, not basic - private final NinePatch cellPatch; - public ThemeCard(final GameLayout layout, final Theme theme) { shapeRenderer = new ShapeRenderer(20); this.theme = theme; - cellPatch = new NinePatch( - new Texture(Gdx.files.internal("ui/cells/basic.png")), 4, 4, 4, 4); - layout.update(this); } @@ -55,16 +47,16 @@ public class ThemeCard extends Actor { // 8 7 3 // 8 8 3 float cellSize = getHeight() * 0.2f; - Cell.draw(theme.getCellColor(0), batch, cellPatch, x + cellSize, y + cellSize, cellSize); - Cell.draw(theme.getCellColor(7), batch, cellPatch, x + cellSize * 2, y + cellSize, cellSize); - Cell.draw(theme.getCellColor(7), batch, cellPatch, x + cellSize * 3, y + cellSize, cellSize); + Cell.draw(theme.getCellColor(0), batch, x + cellSize, y + cellSize, cellSize); + Cell.draw(theme.getCellColor(7), batch, x + cellSize * 2, y + cellSize, cellSize); + Cell.draw(theme.getCellColor(7), batch, x + cellSize * 3, y + cellSize, cellSize); - Cell.draw(theme.getCellColor(8), batch, cellPatch, x + cellSize, y + cellSize * 2, cellSize); - Cell.draw(theme.getCellColor(7), batch, cellPatch, x + cellSize * 2, y + cellSize * 2, cellSize); - Cell.draw(theme.getCellColor(8), batch, cellPatch, x + cellSize * 3, y + cellSize * 2, cellSize); + Cell.draw(theme.getCellColor(8), batch, x + cellSize, y + cellSize * 2, cellSize); + Cell.draw(theme.getCellColor(7), batch, x + cellSize * 2, y + cellSize * 2, cellSize); + Cell.draw(theme.getCellColor(8), batch, x + cellSize * 3, y + cellSize * 2, cellSize); - Cell.draw(theme.getCellColor(8), batch, cellPatch, x + cellSize, y + cellSize * 3, cellSize); - Cell.draw(theme.getCellColor(8), batch, cellPatch, x + cellSize * 2, y + cellSize * 3, cellSize); - Cell.draw(theme.getCellColor(3), batch, cellPatch, x + cellSize * 3, y + cellSize * 3, cellSize); + Cell.draw(theme.getCellColor(8), batch, x + cellSize, y + cellSize * 3, cellSize); + Cell.draw(theme.getCellColor(8), batch, x + cellSize * 2, y + cellSize * 3, cellSize); + Cell.draw(theme.getCellColor(3), batch, x + cellSize * 3, y + cellSize * 3, cellSize); } } diff --git a/core/src/io/github/lonamiwebs/klooni/game/Board.java b/core/src/io/github/lonamiwebs/klooni/game/Board.java index 96a1b2a..1bc12e2 100644 --- a/core/src/io/github/lonamiwebs/klooni/game/Board.java +++ b/core/src/io/github/lonamiwebs/klooni/game/Board.java @@ -2,8 +2,6 @@ package io.github.lonamiwebs.klooni.game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.audio.Sound; -import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.NinePatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; @@ -20,15 +18,11 @@ public class Board { final Vector2 pos; - public NinePatch cellPatch; private final Sound stripClearSound; public Board(final GameLayout layout, int cellCount) { this.cellCount = cellCount; - cellPatch = new NinePatch( - new Texture(Gdx.files.internal("ui/cells/basic.png")), 4, 4, 4, 4); - stripClearSound = Gdx.audio.newSound(Gdx.files.internal("sound/strip_clear.mp3")); lastPutPiecePos = new Vector2(); @@ -175,7 +169,7 @@ public class Board { public void draw(SpriteBatch batch) { for (int i = 0; i < cellCount; i++) { for (int j = 0; j < cellCount; j++) { - cells[i][j].draw(batch, cellPatch); + cells[i][j].draw(batch); } } } diff --git a/core/src/io/github/lonamiwebs/klooni/game/Cell.java b/core/src/io/github/lonamiwebs/klooni/game/Cell.java index 51ff383..6f92c94 100644 --- a/core/src/io/github/lonamiwebs/klooni/game/Cell.java +++ b/core/src/io/github/lonamiwebs/klooni/game/Cell.java @@ -3,11 +3,12 @@ package io.github.lonamiwebs.klooni.game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.g2d.NinePatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.math.Vector2; +import io.github.lonamiwebs.klooni.Klooni; + public class Cell { private boolean empty; @@ -35,8 +36,8 @@ public class Cell { color = c; } - void draw(SpriteBatch batch, NinePatch patch) { - draw(color, batch, patch, pos.x, pos.y, size); + void draw(SpriteBatch batch) { + draw(color, batch, pos.x, pos.y, size); // Draw the previous vanishing cell if (vanishElapsed <= vanishLifetime) { @@ -49,15 +50,15 @@ public class Cell { vanishSize = Interpolation.elasticIn.apply(size, 0, progress); float centerOffset = size * 0.5f - vanishSize * 0.5f; - draw(vanishColor, batch, patch, pos.x + centerOffset, pos.y + centerOffset, vanishSize); + draw(vanishColor, batch, pos.x + centerOffset, pos.y + centerOffset, vanishSize); } } // TODO Use skin atlas - public static void draw(Color color, Batch batch, NinePatch patch, + public static void draw(Color color, Batch batch, float x, float y, float size) { batch.setColor(color); - patch.draw(batch, x, y, size, size); + Klooni.theme.cellPatch.draw(batch, x, y, size, size); } boolean isEmpty() { diff --git a/core/src/io/github/lonamiwebs/klooni/game/Piece.java b/core/src/io/github/lonamiwebs/klooni/game/Piece.java index 5c146c1..6929f1b 100644 --- a/core/src/io/github/lonamiwebs/klooni/game/Piece.java +++ b/core/src/io/github/lonamiwebs/klooni/game/Piece.java @@ -1,7 +1,6 @@ package io.github.lonamiwebs.klooni.game; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.g2d.NinePatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Rectangle; @@ -126,11 +125,11 @@ public class Piece { return result.scl(1f / filledCount); } - void draw(SpriteBatch batch, NinePatch patch) { + void draw(SpriteBatch batch) { for (int i = 0; i < cellRows; i++) { for (int j = 0; j < cellCols; j++) { if (shape[i][j]) { - Cell.draw(color, batch, patch, + Cell.draw(color, batch, pos.x + j * cellSize, pos.y + i * cellSize, cellSize); } } diff --git a/core/src/io/github/lonamiwebs/klooni/game/PieceHolder.java b/core/src/io/github/lonamiwebs/klooni/game/PieceHolder.java index 144d95b..e510fe1 100644 --- a/core/src/io/github/lonamiwebs/klooni/game/PieceHolder.java +++ b/core/src/io/github/lonamiwebs/klooni/game/PieceHolder.java @@ -2,7 +2,6 @@ package io.github.lonamiwebs.klooni.game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.audio.Sound; -import com.badlogic.gdx.graphics.g2d.NinePatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.math.MathUtils; @@ -188,10 +187,10 @@ public class PieceHolder { } } - public void draw(SpriteBatch batch, NinePatch patch) { + public void draw(SpriteBatch batch) { for (int i = 0; i < count; i++) { if (pieces[i] != null) { - pieces[i].draw(batch, patch); + pieces[i].draw(batch); } } } diff --git a/core/src/io/github/lonamiwebs/klooni/screens/GameScreen.java b/core/src/io/github/lonamiwebs/klooni/screens/GameScreen.java index a96c366..7aa46f1 100644 --- a/core/src/io/github/lonamiwebs/klooni/screens/GameScreen.java +++ b/core/src/io/github/lonamiwebs/klooni/screens/GameScreen.java @@ -70,7 +70,7 @@ public class GameScreen implements Screen, InputProcessor { scorer.draw(batch); board.draw(batch); holder.update(); - holder.draw(batch, board.cellPatch); + holder.draw(batch); batch.end();