Add customize screen

This commit is contained in:
Lonami Exo 2017-01-29 18:04:13 +01:00
parent 3f47e5474c
commit eb9b6ee5f1
11 changed files with 185 additions and 1 deletions

BIN
android/assets/ui/back.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 983 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
android/assets/ui/web.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -34,6 +34,12 @@ public class Klooni extends Game {
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")));
skin.add("sound_on_texture", new Texture(Gdx.files.internal("ui/sound_on.png")));
skin.add("sound_off_texture", new Texture(Gdx.files.internal("ui/sound_off.png")));
skin.add("issues_texture", new Texture(Gdx.files.internal("ui/issues.png")));
skin.add("credits_texture", new Texture(Gdx.files.internal("ui/credits.png")));
skin.add("web_texture", new Texture(Gdx.files.internal("ui/web.png")));
skin.add("back_texture", new Texture(Gdx.files.internal("ui/back.png")));
Gdx.input.setCatchBackKey(true); // To show the pause menu
setScreen(new MainMenuScreen(this));
@ -66,5 +72,9 @@ public class Klooni extends Game {
return !prefs.getBoolean("muteSound", false);
}
public static void toggleSound() {
prefs.putBoolean("muteSound", soundsEnabled()).flush();
}
//endregion
}

View file

@ -0,0 +1,156 @@
package io.github.lonamiwebs.klooni.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
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 com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import io.github.lonamiwebs.klooni.Klooni;
public class CustomizeScreen implements Screen {
private Klooni game;
private Stage stage;
public CustomizeScreen(Klooni aGame, final Screen lastScreen) {
game = aGame;
stage = new Stage();
Table table = new Table();
table.setFillParent(true);
stage.addActor(table);
HorizontalGroup optionsGroup = new HorizontalGroup();
optionsGroup.space(12);
// Back to the previous screen
ImageButton.ImageButtonStyle backStyle = new ImageButton.ImageButtonStyle(
game.skin.newDrawable("button_up", Color.GOLD),
game.skin.newDrawable("button_down", Color.GOLD),
null, game.skin.getDrawable("back_texture"), null, null);
final ImageButton backButton = new ImageButton(backStyle);
optionsGroup.addActor(backButton);
backButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
game.setScreen(lastScreen);
dispose();
}
});
// Turn sound on/off
Drawable soundDrawable = game.skin.getDrawable(
Klooni.soundsEnabled() ? "sound_on_texture" : "sound_off_texture");
ImageButton.ImageButtonStyle soundStyle = new ImageButton.ImageButtonStyle(
game.skin.newDrawable("button_up", Color.LIME),
game.skin.newDrawable("button_down", Color.LIME),
null, soundDrawable, null, null);
final ImageButton soundButton = new ImageButton(soundStyle);
optionsGroup.addActor(soundButton);
soundButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Klooni.toggleSound();
soundButton.getStyle().imageUp = game.skin.getDrawable(
Klooni.soundsEnabled() ? "sound_on_texture" : "sound_off_texture");
}
});
// Issues
ImageButton.ImageButtonStyle issuesStyle = new ImageButton.ImageButtonStyle(
game.skin.newDrawable("button_up", Color.FIREBRICK),
game.skin.newDrawable("button_down", Color.FIREBRICK),
null, game.skin.getDrawable("issues_texture"), null, null);
final ImageButton issuesButton = new ImageButton(issuesStyle);
optionsGroup.addActor(issuesButton);
issuesButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Gdx.net.openURI("https://github.com/LonamiWeb/Klooni1010/issues");
}
});
// Website
ImageButton.ImageButtonStyle webStyle = new ImageButton.ImageButtonStyle(
game.skin.newDrawable("button_up", new Color(0x6E99FFFF)),
game.skin.newDrawable("button_down", new Color(0x6E99FFFF)),
null, game.skin.getDrawable("web_texture"), null, null);
final ImageButton webButton = new ImageButton(webStyle);
optionsGroup.addActor(webButton);
webButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Gdx.net.openURI("https://lonamiwebs.github.io");
}
});
table.add(new ScrollPane(optionsGroup)).pad(20, 4, 12, 4);
table.row();
VerticalGroup themesGroup = new VerticalGroup();
themesGroup.space(8);
table.add(themesGroup).expandY();
}
@Override
public void show() {
Gdx.input.setInputProcessor(stage);
}
private static final float minDelta = 1/30f;
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0.7f, 0.9f, 0.9f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(Math.min(Gdx.graphics.getDeltaTime(), minDelta));
stage.draw();
if (Gdx.input.isKeyJustPressed(Input.Keys.BACK)) {
game.setScreen(new MainMenuScreen(game));
dispose();
}
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
stage.dispose();
}
}

View file

@ -54,7 +54,10 @@ public class GameScreen implements Screen, InputProcessor {
@Override
public void show() {
Gdx.input.setInputProcessor(this);
if (pauseMenu.isShown()) // Will happen if we go to the customize menu
Gdx.input.setInputProcessor(pauseMenu);
else
Gdx.input.setInputProcessor(this);
}
@Override

View file

@ -75,6 +75,13 @@ public class MainMenuScreen extends InputListener implements Screen {
final ImageButton paletteButton = new ImageButton(paletteStyle);
table.add(paletteButton).space(16);
paletteButton.addListener(new ChangeListener() {
public void changed (ChangeEvent event, Actor actor) {
game.setScreen(new CustomizeScreen(game, game.getScreen()));
// Don't dispose because then it needs to take us to the previous screen
}
});
}
@Override

View file

@ -85,6 +85,14 @@ public class PauseMenuStage extends Stage {
final ImageButton paletteButton = new ImageButton(paletteStyle);
table.add(paletteButton).space(16);
paletteButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
game.setScreen(new CustomizeScreen(game, game.getScreen()));
// Don't dispose because then it needs to take us to the previous screen
}
});
// Continue playing OR share (if game over) button
// TODO Enable both actions for this button
ImageButton.ImageButtonStyle playStyle = new ImageButton.ImageButtonStyle(