Add fully-functional pause menu, move skin creation
This commit is contained in:
parent
2d6c66a701
commit
b6b7590cf4
7 changed files with 200 additions and 35 deletions
BIN
android/assets/ui/home.png
Normal file
BIN
android/assets/ui/home.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
android/assets/ui/replay.png
Normal file
BIN
android/assets/ui/replay.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
BIN
android/assets/ui/share.png
Normal file
BIN
android/assets/ui/share.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
|
@ -1,17 +1,37 @@
|
||||||
package io.github.lonamiwebs.klooni;
|
package io.github.lonamiwebs.klooni;
|
||||||
|
|
||||||
import com.badlogic.gdx.Game;
|
import com.badlogic.gdx.Game;
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.NinePatch;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||||
|
|
||||||
import io.github.lonamiwebs.klooni.screens.MainMenuScreen;
|
import io.github.lonamiwebs.klooni.screens.MainMenuScreen;
|
||||||
|
|
||||||
public class Klooni extends Game {
|
public class Klooni extends Game {
|
||||||
|
|
||||||
public static Skin skin;
|
public Skin skin;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
//skin = new Skin(Gdx.files.internal("skin/craftacular-ui.json"));
|
// TODO Better way to have this skin somewhere
|
||||||
|
// Gotta create that darn .json…!
|
||||||
|
skin = new Skin(Gdx.files.internal("skin/uiskin.json"));
|
||||||
|
|
||||||
|
skin.add("button_up", new NinePatch(new Texture(
|
||||||
|
Gdx.files.internal("ui/button_up.png")), 28, 28, 28, 28));
|
||||||
|
|
||||||
|
skin.add("button_down", new NinePatch(new Texture(
|
||||||
|
Gdx.files.internal("ui/button_down.png")), 28, 28, 28, 28));
|
||||||
|
|
||||||
|
skin.add("play_texture", new Texture(Gdx.files.internal("ui/play.png")));
|
||||||
|
skin.add("star_texture", new Texture(Gdx.files.internal("ui/star.png")));
|
||||||
|
skin.add("stats_texture", new Texture(Gdx.files.internal("ui/stats.png")));
|
||||||
|
skin.add("palette_texture", new Texture(Gdx.files.internal("ui/palette.png")));
|
||||||
|
skin.add("home_texture", new Texture(Gdx.files.internal("ui/home.png")));
|
||||||
|
skin.add("replay_texture", new Texture(Gdx.files.internal("ui/replay.png")));
|
||||||
|
skin.add("share_texture", new Texture(Gdx.files.internal("ui/share.png")));
|
||||||
|
|
||||||
setScreen(new MainMenuScreen(this));
|
setScreen(new MainMenuScreen(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,5 +43,6 @@ public class Klooni extends Game {
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
skin.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package io.github.lonamiwebs.klooni.screens;
|
package io.github.lonamiwebs.klooni.screens;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.Input;
|
||||||
import com.badlogic.gdx.InputProcessor;
|
import com.badlogic.gdx.InputProcessor;
|
||||||
import com.badlogic.gdx.Screen;
|
import com.badlogic.gdx.Screen;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
|
||||||
|
|
||||||
import io.github.lonamiwebs.klooni.Klooni;
|
import io.github.lonamiwebs.klooni.Klooni;
|
||||||
import io.github.lonamiwebs.klooni.game.Board;
|
import io.github.lonamiwebs.klooni.game.Board;
|
||||||
|
@ -30,22 +30,21 @@ public class GameScreen implements Screen, InputProcessor {
|
||||||
private final Color clearColor;
|
private final Color clearColor;
|
||||||
private int score;
|
private int score;
|
||||||
|
|
||||||
|
private final PauseMenuStage pauseMenu;
|
||||||
|
|
||||||
public GameScreen(Klooni aGame) {
|
public GameScreen(Klooni aGame) {
|
||||||
game = aGame;
|
game = aGame;
|
||||||
score = 0;
|
score = 0;
|
||||||
clearColor = new Color(0.9f, 0.9f, 0.7f, 1f);
|
clearColor = new Color(0.9f, 0.9f, 0.7f, 1f);
|
||||||
batch = new SpriteBatch();
|
batch = new SpriteBatch();
|
||||||
|
|
||||||
|
pauseMenu = new PauseMenuStage(game);
|
||||||
|
|
||||||
layout = new GameLayout();
|
layout = new GameLayout();
|
||||||
|
|
||||||
scorer = new Scorer(layout, 10);
|
scorer = new Scorer(layout, 10);
|
||||||
board = new Board(layout, 10);
|
board = new Board(layout, 10);
|
||||||
holder = new PieceHolder(layout, 3);
|
holder = new PieceHolder(layout, 3);
|
||||||
|
|
||||||
// Fill some random pieces
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
board.putPiece(Piece.random(), MathUtils.random(10), MathUtils.random(10));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isGameOver() {
|
boolean isGameOver() {
|
||||||
|
@ -77,6 +76,11 @@ public class GameScreen implements Screen, InputProcessor {
|
||||||
holder.draw(batch, board.cellPatch);
|
holder.draw(batch, board.cellPatch);
|
||||||
|
|
||||||
batch.end();
|
batch.end();
|
||||||
|
|
||||||
|
if (pauseMenu.isShown() || pauseMenu.isHiding()) {
|
||||||
|
pauseMenu.act(delta);
|
||||||
|
pauseMenu.draw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -101,7 +105,7 @@ public class GameScreen implements Screen, InputProcessor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
|
pauseMenu.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
@ -115,6 +119,9 @@ public class GameScreen implements Screen, InputProcessor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyUp(int keycode) {
|
public boolean keyUp(int keycode) {
|
||||||
|
if (keycode == Input.Keys.P) // Pause
|
||||||
|
pauseMenu.show();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +144,7 @@ public class GameScreen implements Screen, InputProcessor {
|
||||||
|
|
||||||
// After the piece was put, check if it's game over
|
// After the piece was put, check if it's game over
|
||||||
if (isGameOver()) {
|
if (isGameOver()) {
|
||||||
clearColor.set(0.4f, 0.1f, 0.1f, 1f);
|
pauseMenu.show();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,13 +4,10 @@ import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Screen;
|
import com.badlogic.gdx.Screen;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.NinePatch;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
|
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||||
|
|
||||||
|
@ -19,7 +16,6 @@ import io.github.lonamiwebs.klooni.Klooni;
|
||||||
public class MainMenuScreen implements Screen {
|
public class MainMenuScreen implements Screen {
|
||||||
private Klooni game;
|
private Klooni game;
|
||||||
|
|
||||||
Skin skin;
|
|
||||||
Stage stage;
|
Stage stage;
|
||||||
SpriteBatch batch;
|
SpriteBatch batch;
|
||||||
|
|
||||||
|
@ -28,27 +24,16 @@ public class MainMenuScreen implements Screen {
|
||||||
|
|
||||||
batch = new SpriteBatch();
|
batch = new SpriteBatch();
|
||||||
stage = new Stage();
|
stage = new Stage();
|
||||||
skin = new Skin(Gdx.files.internal("skin/uiskin.json"));
|
|
||||||
|
|
||||||
Table table = new Table();
|
Table table = new Table();
|
||||||
table.setFillParent(true);
|
table.setFillParent(true);
|
||||||
stage.addActor(table);
|
stage.addActor(table);
|
||||||
|
|
||||||
skin.add("button_up", new NinePatch(new Texture(
|
|
||||||
Gdx.files.internal("ui/button_up.png")), 28, 28, 28, 28));
|
|
||||||
|
|
||||||
skin.add("button_down", new NinePatch(new Texture(
|
|
||||||
Gdx.files.internal("ui/button_down.png")), 28, 28, 28, 28));
|
|
||||||
|
|
||||||
skin.add("play_texture", new Texture(Gdx.files.internal("ui/play.png")));
|
|
||||||
skin.add("star_texture", new Texture(Gdx.files.internal("ui/star.png")));
|
|
||||||
skin.add("stats_texture", new Texture(Gdx.files.internal("ui/stats.png")));
|
|
||||||
skin.add("palette_texture", new Texture(Gdx.files.internal("ui/palette.png")));
|
|
||||||
|
|
||||||
// Play button
|
// Play button
|
||||||
ImageButton.ImageButtonStyle playStyle = new ImageButton.ImageButtonStyle(
|
ImageButton.ImageButtonStyle playStyle = new ImageButton.ImageButtonStyle(
|
||||||
skin.newDrawable("button_up", Color.GREEN), skin.newDrawable("button_down", Color.GREEN),
|
game.skin.newDrawable("button_up", Color.GREEN),
|
||||||
null, skin.getDrawable("play_texture"), null, null);
|
game.skin.newDrawable("button_down", Color.GREEN),
|
||||||
|
null, game.skin.getDrawable("play_texture"), null, null);
|
||||||
|
|
||||||
final ImageButton playButton = new ImageButton(playStyle);
|
final ImageButton playButton = new ImageButton(playStyle);
|
||||||
table.add(playButton).colspan(3).fill().space(16);
|
table.add(playButton).colspan(3).fill().space(16);
|
||||||
|
@ -64,24 +49,27 @@ public class MainMenuScreen implements Screen {
|
||||||
|
|
||||||
// Star button (on GitHub)
|
// Star button (on GitHub)
|
||||||
ImageButton.ImageButtonStyle starStyle = new ImageButton.ImageButtonStyle(
|
ImageButton.ImageButtonStyle starStyle = new ImageButton.ImageButtonStyle(
|
||||||
skin.newDrawable("button_up", Color.YELLOW), skin.newDrawable("button_down", Color.YELLOW),
|
game.skin.newDrawable("button_up", Color.YELLOW),
|
||||||
null, skin.getDrawable("star_texture"), null, null);
|
game.skin.newDrawable("button_down", Color.YELLOW),
|
||||||
|
null, game.skin.getDrawable("star_texture"), null, null);
|
||||||
|
|
||||||
final ImageButton starButton = new ImageButton(starStyle);
|
final ImageButton starButton = new ImageButton(starStyle);
|
||||||
table.add(starButton).space(16);
|
table.add(starButton).space(16);
|
||||||
|
|
||||||
// Stats button (high scores)
|
// Stats button (high scores)
|
||||||
ImageButton.ImageButtonStyle statsStyle = new ImageButton.ImageButtonStyle(
|
ImageButton.ImageButtonStyle statsStyle = new ImageButton.ImageButtonStyle(
|
||||||
skin.newDrawable("button_up", Color.BLUE), skin.newDrawable("button_down", Color.BLUE),
|
game.skin.newDrawable("button_up", Color.BLUE),
|
||||||
null, skin.getDrawable("stats_texture"), null, null);
|
game.skin.newDrawable("button_down", Color.BLUE),
|
||||||
|
null, game.skin.getDrawable("stats_texture"), null, null);
|
||||||
|
|
||||||
final ImageButton statsButton = new ImageButton(statsStyle);
|
final ImageButton statsButton = new ImageButton(statsStyle);
|
||||||
table.add(statsButton).space(16);
|
table.add(statsButton).space(16);
|
||||||
|
|
||||||
// Palette button (buy colors)
|
// Palette button (buy colors)
|
||||||
ImageButton.ImageButtonStyle paletteStyle = new ImageButton.ImageButtonStyle(
|
ImageButton.ImageButtonStyle paletteStyle = new ImageButton.ImageButtonStyle(
|
||||||
skin.newDrawable("button_up", Color.FIREBRICK), skin.newDrawable("button_down", Color.FIREBRICK),
|
game.skin.newDrawable("button_up", Color.FIREBRICK),
|
||||||
null, skin.getDrawable("palette_texture"), null, null);
|
game.skin.newDrawable("button_down", Color.FIREBRICK),
|
||||||
|
null, game.skin.getDrawable("palette_texture"), null, null);
|
||||||
|
|
||||||
final ImageButton paletteButton = new ImageButton(paletteStyle);
|
final ImageButton paletteButton = new ImageButton(paletteStyle);
|
||||||
table.add(paletteButton).space(16);
|
table.add(paletteButton).space(16);
|
||||||
|
@ -125,6 +113,5 @@ public class MainMenuScreen implements Screen {
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
stage.dispose();
|
stage.dispose();
|
||||||
skin.dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
150
core/src/io/github/lonamiwebs/klooni/screens/PauseMenuStage.java
Normal file
150
core/src/io/github/lonamiwebs/klooni/screens/PauseMenuStage.java
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
package io.github.lonamiwebs.klooni.screens;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.Input;
|
||||||
|
import com.badlogic.gdx.InputProcessor;
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||||
|
import com.badlogic.gdx.math.Interpolation;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.actions.RunnableAction;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||||
|
|
||||||
|
import io.github.lonamiwebs.klooni.Klooni;
|
||||||
|
|
||||||
|
public class PauseMenuStage extends Stage {
|
||||||
|
|
||||||
|
private InputProcessor lastInputProcessor;
|
||||||
|
private boolean shown;
|
||||||
|
private boolean hiding;
|
||||||
|
|
||||||
|
public PauseMenuStage(final Klooni game) {
|
||||||
|
|
||||||
|
Table table = new Table();
|
||||||
|
table.setFillParent(true);
|
||||||
|
addActor(table);
|
||||||
|
|
||||||
|
// Home screen button
|
||||||
|
ImageButton.ImageButtonStyle homeStyle = new ImageButton.ImageButtonStyle(
|
||||||
|
game.skin.newDrawable("button_up", Color.FIREBRICK),
|
||||||
|
game.skin.newDrawable("button_down", Color.FIREBRICK),
|
||||||
|
null, game.skin.getDrawable("home_texture"), null, null);
|
||||||
|
|
||||||
|
final ImageButton homeButton = new ImageButton(homeStyle);
|
||||||
|
table.add(homeButton).space(16);
|
||||||
|
|
||||||
|
homeButton.addListener(new ChangeListener() {
|
||||||
|
public void changed (ChangeEvent event, Actor actor) {
|
||||||
|
game.setScreen(new MainMenuScreen(game));
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Replay button
|
||||||
|
ImageButton.ImageButtonStyle replayStyle = new ImageButton.ImageButtonStyle(
|
||||||
|
game.skin.newDrawable("button_up", Color.GREEN),
|
||||||
|
game.skin.newDrawable("button_down", Color.GREEN),
|
||||||
|
null, game.skin.getDrawable("replay_texture"), null, null);
|
||||||
|
|
||||||
|
final ImageButton replayButton = new ImageButton(replayStyle);
|
||||||
|
table.add(replayButton).space(16);
|
||||||
|
|
||||||
|
replayButton.addListener(new ChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void changed(ChangeEvent event, Actor actor) {
|
||||||
|
game.setScreen(new GameScreen(game));
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
table.row();
|
||||||
|
|
||||||
|
// Palette button (buy colors)
|
||||||
|
ImageButton.ImageButtonStyle paletteStyle = new ImageButton.ImageButtonStyle(
|
||||||
|
game.skin.newDrawable("button_up", Color.YELLOW),
|
||||||
|
game.skin.newDrawable("button_down", Color.YELLOW),
|
||||||
|
null, game.skin.getDrawable("palette_texture"), null, null);
|
||||||
|
|
||||||
|
final ImageButton paletteButton = new ImageButton(paletteStyle);
|
||||||
|
table.add(paletteButton).space(16);
|
||||||
|
|
||||||
|
// Continue playing OR share (if game over) button
|
||||||
|
// TODO Enable both actions for this button
|
||||||
|
ImageButton.ImageButtonStyle playStyle = new ImageButton.ImageButtonStyle(
|
||||||
|
game.skin.newDrawable("button_up", Color.BLUE),
|
||||||
|
game.skin.newDrawable("button_down", Color.BLUE),
|
||||||
|
null, game.skin.getDrawable("play_texture"), null, null);
|
||||||
|
|
||||||
|
final ImageButton playButton = new ImageButton(playStyle);
|
||||||
|
table.add(playButton).space(16);
|
||||||
|
|
||||||
|
playButton.addListener(new ChangeListener() {
|
||||||
|
public void changed (ChangeEvent event, Actor actor) {
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void show() {
|
||||||
|
lastInputProcessor = Gdx.input.getInputProcessor();
|
||||||
|
Gdx.input.setInputProcessor(this);
|
||||||
|
shown = true;
|
||||||
|
hiding = false;
|
||||||
|
|
||||||
|
addAction(Actions.moveTo(0, Gdx.graphics.getHeight()));
|
||||||
|
addAction(Actions.moveTo(0, 0, 0.75f, Interpolation.swingOut));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hide() {
|
||||||
|
shown = false;
|
||||||
|
hiding = true;
|
||||||
|
Gdx.input.setInputProcessor(lastInputProcessor);
|
||||||
|
|
||||||
|
addAction(Actions.sequence(
|
||||||
|
Actions.moveTo(0, Gdx.graphics.getHeight(), 0.5f, Interpolation.swingIn),
|
||||||
|
new RunnableAction() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
hiding = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isShown() {
|
||||||
|
return shown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHiding() {
|
||||||
|
return hiding;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw() {
|
||||||
|
// Draw an overlay rectangle with not all the opacity
|
||||||
|
if (shown) {
|
||||||
|
ShapeRenderer shapeRenderer = new ShapeRenderer(20);
|
||||||
|
|
||||||
|
Gdx.gl.glEnable(GL20.GL_BLEND);
|
||||||
|
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
|
||||||
|
shapeRenderer.setColor(1f, 1f, 1f, 0.3f);
|
||||||
|
shapeRenderer.rect(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
|
shapeRenderer.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
super.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyUp(int keyCode) {
|
||||||
|
if (keyCode == Input.Keys.P) // Pause
|
||||||
|
hide();
|
||||||
|
|
||||||
|
return super.keyUp(keyCode);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue