Give up on the ShapeRenderer (Band and ThemeCard)
This commit is contained in:
parent
d8825b0f27
commit
6cff9d5968
6 changed files with 39 additions and 41 deletions
|
@ -15,7 +15,7 @@ public class Theme {
|
||||||
private String displayName;
|
private String displayName;
|
||||||
private String name;
|
private String name;
|
||||||
private int price;
|
private int price;
|
||||||
private Color background;
|
public Color background;
|
||||||
private Color[] cells;
|
private Color[] cells;
|
||||||
private Color[] buttons;
|
private Color[] buttons;
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,12 @@ package io.github.lonamiwebs.klooni.actors;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||||
import com.badlogic.gdx.utils.Align;
|
import com.badlogic.gdx.utils.Align;
|
||||||
|
@ -17,8 +19,7 @@ import io.github.lonamiwebs.klooni.game.Scorer;
|
||||||
public class Band extends Actor {
|
public class Band extends Actor {
|
||||||
|
|
||||||
private final Scorer scorer;
|
private final Scorer scorer;
|
||||||
private final ShapeRenderer shapeRenderer; // To draw the horizontal "Band"
|
private final Texture bandTexture;
|
||||||
private final Color bandColor;
|
|
||||||
|
|
||||||
public final Rectangle scoreBounds;
|
public final Rectangle scoreBounds;
|
||||||
public final Rectangle infoBounds;
|
public final Rectangle infoBounds;
|
||||||
|
@ -26,10 +27,14 @@ public class Band extends Actor {
|
||||||
public final Label infoLabel;
|
public final Label infoLabel;
|
||||||
public final Label scoreLabel;
|
public final Label scoreLabel;
|
||||||
|
|
||||||
public Band(final GameLayout layout, final Scorer aScorer, final Color aBandColor) {
|
public Band(final GameLayout layout, final Scorer aScorer, final Color bandColor) {
|
||||||
scorer = aScorer;
|
scorer = aScorer;
|
||||||
bandColor = aBandColor;
|
|
||||||
shapeRenderer = new ShapeRenderer(20); // Only 20 vertex are required, maybe less
|
Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
|
||||||
|
pixmap.setColor(bandColor);
|
||||||
|
pixmap.fill();
|
||||||
|
bandTexture = new Texture(pixmap);
|
||||||
|
pixmap.dispose();
|
||||||
|
|
||||||
Label.LabelStyle scoreStyle = new Label.LabelStyle();
|
Label.LabelStyle scoreStyle = new Label.LabelStyle();
|
||||||
scoreStyle.font = new BitmapFont(Gdx.files.internal("font/geosans-light.fnt"));
|
scoreStyle.font = new BitmapFont(Gdx.files.internal("font/geosans-light.fnt"));
|
||||||
|
@ -50,20 +55,13 @@ public class Band extends Actor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Batch batch, float parentAlpha) {
|
public void draw(Batch batch, float parentAlpha) {
|
||||||
// We need to end (thus flush) the batch or things will mess up!
|
|
||||||
batch.end();
|
|
||||||
|
|
||||||
float w = getWidth();
|
|
||||||
float h = getHeight();
|
|
||||||
|
|
||||||
// TODO This is not the best way to apply the transformation, but, oh well
|
// TODO This is not the best way to apply the transformation, but, oh well
|
||||||
float x = getParent().getX();
|
float x = getParent().getX();
|
||||||
float y = getParent().getY();
|
float y = getParent().getY();
|
||||||
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
|
|
||||||
shapeRenderer.setColor(bandColor);
|
// TODO For some strange reason, the texture coordinates and label coordinates are different
|
||||||
shapeRenderer.rect(x + getX(), y + getY(), w, h);
|
Vector2 pos = localToStageCoordinates(new Vector2(x, y));
|
||||||
shapeRenderer.end();
|
batch.draw(bandTexture, pos.x, pos.y, getWidth(), getHeight());
|
||||||
batch.begin();
|
|
||||||
|
|
||||||
scoreLabel.setBounds(x + scoreBounds.x, y + scoreBounds.y, scoreBounds.width, scoreBounds.height);
|
scoreLabel.setBounds(x + scoreBounds.x, y + scoreBounds.y, scoreBounds.width, scoreBounds.height);
|
||||||
scoreLabel.setText(Integer.toString(scorer.getCurrentScore()));
|
scoreLabel.setText(Integer.toString(scorer.getCurrentScore()));
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package io.github.lonamiwebs.klooni.actors;
|
package io.github.lonamiwebs.klooni.actors;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
|
||||||
import com.badlogic.gdx.math.Vector2;
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||||
|
|
||||||
import io.github.lonamiwebs.klooni.Theme;
|
import io.github.lonamiwebs.klooni.Theme;
|
||||||
|
@ -13,34 +13,30 @@ import io.github.lonamiwebs.klooni.game.GameLayout;
|
||||||
|
|
||||||
public class ThemeCard extends Actor {
|
public class ThemeCard extends Actor {
|
||||||
|
|
||||||
private final ShapeRenderer shapeRenderer;
|
|
||||||
|
|
||||||
public final Theme theme;
|
public final Theme theme;
|
||||||
|
private final Texture background;
|
||||||
|
|
||||||
public ThemeCard(final GameLayout layout, final Theme theme) {
|
public ThemeCard(final GameLayout layout, final Theme theme) {
|
||||||
shapeRenderer = new ShapeRenderer(20);
|
// TODO We could also use white color and then batch.setColor(theme.background)
|
||||||
|
Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
|
||||||
|
pixmap.setColor(theme.background);
|
||||||
|
pixmap.fill();
|
||||||
|
background = new Texture(pixmap);
|
||||||
|
pixmap.dispose();
|
||||||
|
|
||||||
this.theme = theme;
|
this.theme = theme;
|
||||||
layout.update(this);
|
layout.update(this);
|
||||||
|
|
||||||
|
setWidth(Gdx.graphics.getWidth());
|
||||||
|
setScaleX(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Batch batch, float parentAlpha) {
|
public void draw(Batch batch, float parentAlpha) {
|
||||||
batch.end();
|
|
||||||
|
|
||||||
final float x = getX(), y = getY();
|
final float x = getX(), y = getY();
|
||||||
|
|
||||||
Vector2 pos = localToStageCoordinates(new Vector2(x, y));
|
batch.setColor(Color.WHITE);
|
||||||
|
batch.draw(background, x, y, getWidth(), getHeight());
|
||||||
// TODO Something is wrong with this code, shape renderer fills one yes one no if multiple themes
|
|
||||||
Gdx.gl.glEnable(GL20.GL_BLEND);
|
|
||||||
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
|
|
||||||
shapeRenderer.setColor(0.5f, 0.5f, 0.5f, 0.3f);
|
|
||||||
shapeRenderer.rect(pos.x, pos.y, getWidth(), getHeight());
|
|
||||||
shapeRenderer.end();
|
|
||||||
Gdx.gl.glDisable(GL20.GL_BLEND);
|
|
||||||
|
|
||||||
batch.begin();
|
|
||||||
|
|
||||||
// Consider 5 cells on the available size (1/5 height each)
|
// Consider 5 cells on the available size (1/5 height each)
|
||||||
// Do not draw on the borders to add some padding, colors used:
|
// Do not draw on the borders to add some padding, colors used:
|
||||||
// 0 7 7
|
// 0 7 7
|
||||||
|
|
|
@ -92,6 +92,6 @@ public class GameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(ThemeCard card) {
|
public void update(ThemeCard card) {
|
||||||
card.setSize(availableWidth, logoHeight);
|
card.setSize(availableWidth - marginWidth, scoreHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,7 @@ public class CustomizeScreen implements Screen {
|
||||||
}
|
}
|
||||||
|
|
||||||
themesGroup.space(8);
|
themesGroup.space(8);
|
||||||
table.add(new ScrollPane(themesGroup)).expandY();
|
table.add(new ScrollPane(themesGroup)).expand().fill();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -27,12 +27,16 @@ public class PauseMenuStage extends Stage {
|
||||||
private boolean shown;
|
private boolean shown;
|
||||||
private boolean hiding;
|
private boolean hiding;
|
||||||
|
|
||||||
|
private final ShapeRenderer shapeRenderer;
|
||||||
|
|
||||||
private final Band band;
|
private final Band band;
|
||||||
private final Scorer scorer;
|
private final Scorer scorer;
|
||||||
|
|
||||||
public PauseMenuStage(final GameLayout layout, final Klooni game, final Scorer aScorer) {
|
public PauseMenuStage(final GameLayout layout, final Klooni game, final Scorer aScorer) {
|
||||||
scorer = aScorer;
|
scorer = aScorer;
|
||||||
|
|
||||||
|
shapeRenderer = new ShapeRenderer(20); // 20 vertex seems to be enough for a rectangle
|
||||||
|
|
||||||
Table table = new Table();
|
Table table = new Table();
|
||||||
table.setFillParent(true);
|
table.setFillParent(true);
|
||||||
addActor(table);
|
addActor(table);
|
||||||
|
@ -133,8 +137,8 @@ public class PauseMenuStage extends Stage {
|
||||||
@Override
|
@Override
|
||||||
public void draw() {
|
public void draw() {
|
||||||
// Draw an overlay rectangle with not all the opacity
|
// Draw an overlay rectangle with not all the opacity
|
||||||
|
// This is the only place where ShapeRenderer is OK because the batch hasn't started
|
||||||
if (shown) {
|
if (shown) {
|
||||||
ShapeRenderer shapeRenderer = new ShapeRenderer(20);
|
|
||||||
Gdx.gl.glEnable(GL20.GL_BLEND);
|
Gdx.gl.glEnable(GL20.GL_BLEND);
|
||||||
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
|
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
|
||||||
shapeRenderer.setColor(1f, 1f, 1f, 0.3f);
|
shapeRenderer.setColor(1f, 1f, 1f, 0.3f);
|
||||||
|
|
Loading…
Reference in a new issue