Use per-theme cell texture

This commit is contained in:
Lonami Exo 2017-01-30 19:08:40 +01:00
parent 02c8290c29
commit 4706cb221e
7 changed files with 29 additions and 37 deletions

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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);
}
}
}

View file

@ -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() {

View file

@ -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);
}
}

View file

@ -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);
}
}
}

View file

@ -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();