Fix sound button not updating its state

This commit is contained in:
Lonami Exo 2017-02-02 15:46:13 +01:00
parent 6524fe8518
commit 8550359cb7
4 changed files with 14 additions and 15 deletions

View file

@ -13,7 +13,7 @@ public class SoftButton extends ImageButton {
//region Members //region Members
private int styleIndex; private int styleIndex;
private Drawable image; public Drawable image;
//endregion //endregion

View file

@ -10,7 +10,6 @@ import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener; import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup; 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.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup; import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
@ -58,7 +57,7 @@ class CustomizeScreen implements Screen {
optionsGroup.space(12); optionsGroup.space(12);
// Back to the previous screen // Back to the previous screen
final ImageButton backButton = new SoftButton(1, "back_texture"); final SoftButton backButton = new SoftButton(1, "back_texture");
backButton.addListener(new ChangeListener() { backButton.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
@ -68,21 +67,21 @@ class CustomizeScreen implements Screen {
optionsGroup.addActor(backButton); optionsGroup.addActor(backButton);
// Turn sound on/off // Turn sound on/off
final ImageButton soundButton = new SoftButton( final SoftButton soundButton = new SoftButton(
0, Klooni.soundsEnabled() ? "sound_on_texture" : "sound_off_texture"); 0, Klooni.soundsEnabled() ? "sound_on_texture" : "sound_off_texture");
soundButton.addListener(new ChangeListener() { soundButton.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
Klooni.toggleSound(); Klooni.toggleSound();
soundButton.getStyle().imageUp = CustomizeScreen.this.game.skin.getDrawable( soundButton.image = CustomizeScreen.this.game.skin.getDrawable(
Klooni.soundsEnabled() ? "sound_on_texture" : "sound_off_texture"); Klooni.soundsEnabled() ? "sound_on_texture" : "sound_off_texture");
} }
}); });
optionsGroup.addActor(soundButton); optionsGroup.addActor(soundButton);
// Issues // Issues
final ImageButton issuesButton = new SoftButton(3, "issues_texture"); final SoftButton issuesButton = new SoftButton(3, "issues_texture");
issuesButton.addListener(new ChangeListener() { issuesButton.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
@ -92,7 +91,7 @@ class CustomizeScreen implements Screen {
optionsGroup.addActor(issuesButton); optionsGroup.addActor(issuesButton);
// Website // Website
final ImageButton webButton = new SoftButton(2, "web_texture"); final SoftButton webButton = new SoftButton(2, "web_texture");
webButton.addListener(new ChangeListener() { webButton.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {

View file

@ -43,7 +43,7 @@ public class MainMenuScreen extends InputListener implements Screen {
stage.addActor(table); stage.addActor(table);
// Play button // Play button
final ImageButton playButton = new SoftButton(0, "play_texture"); final SoftButton playButton = new SoftButton(0, "play_texture");
playButton.addListener(new ChangeListener() { playButton.addListener(new ChangeListener() {
public void changed (ChangeEvent event, Actor actor) { public void changed (ChangeEvent event, Actor actor) {
MainMenuScreen.this.game.setScreen(new GameScreen(MainMenuScreen.this.game)); MainMenuScreen.this.game.setScreen(new GameScreen(MainMenuScreen.this.game));
@ -55,7 +55,7 @@ public class MainMenuScreen extends InputListener implements Screen {
table.row(); table.row();
// Star button (on GitHub) // Star button (on GitHub)
final ImageButton starButton = new SoftButton(1, "star_texture"); final SoftButton starButton = new SoftButton(1, "star_texture");
starButton.addListener(new ChangeListener() { starButton.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
@ -65,11 +65,11 @@ public class MainMenuScreen extends InputListener implements Screen {
table.add(starButton).space(16); table.add(starButton).space(16);
// Stats button (high scores) // Stats button (high scores)
final ImageButton statsButton = new SoftButton(2, "stats_texture"); final SoftButton statsButton = new SoftButton(2, "stats_texture");
table.add(statsButton).space(16); table.add(statsButton).space(16);
// Palette button (buy colors) // Palette button (buy colors)
final ImageButton paletteButton = new SoftButton(3, "palette_texture"); final SoftButton paletteButton = new SoftButton(3, "palette_texture");
paletteButton.addListener(new ChangeListener() { paletteButton.addListener(new ChangeListener() {
public void changed (ChangeEvent event, Actor actor) { public void changed (ChangeEvent event, Actor actor) {
MainMenuScreen.this.game.setScreen(new CustomizeScreen(MainMenuScreen.this.game, MainMenuScreen.this.game.getScreen())); MainMenuScreen.this.game.setScreen(new CustomizeScreen(MainMenuScreen.this.game, MainMenuScreen.this.game.getScreen()));

View file

@ -56,7 +56,7 @@ class PauseMenuStage extends Stage {
addActor(band); addActor(band);
// Home screen button // Home screen button
final ImageButton homeButton = new SoftButton(3, "home_texture"); final SoftButton homeButton = new SoftButton(3, "home_texture");
table.add(homeButton).space(16); table.add(homeButton).space(16);
homeButton.addListener(new ChangeListener() { homeButton.addListener(new ChangeListener() {
@ -67,7 +67,7 @@ class PauseMenuStage extends Stage {
}); });
// Replay button // Replay button
final ImageButton replayButton = new SoftButton(0, "replay_texture"); final SoftButton replayButton = new SoftButton(0, "replay_texture");
table.add(replayButton).space(16); table.add(replayButton).space(16);
replayButton.addListener(new ChangeListener() { replayButton.addListener(new ChangeListener() {
@ -81,7 +81,7 @@ class PauseMenuStage extends Stage {
table.row(); table.row();
// Palette button (buy colors) // Palette button (buy colors)
final ImageButton paletteButton = new SoftButton(1, "palette_texture"); final SoftButton paletteButton = new SoftButton(1, "palette_texture");
table.add(paletteButton).space(16); table.add(paletteButton).space(16);
paletteButton.addListener(new ChangeListener() { paletteButton.addListener(new ChangeListener() {
@ -94,7 +94,7 @@ class PauseMenuStage extends Stage {
// Continue playing OR share (if game over) button // Continue playing OR share (if game over) button
// TODO Enable both actions for this button? Or leave play? // TODO Enable both actions for this button? Or leave play?
final ImageButton playButton = new SoftButton(2, "play_texture"); final SoftButton playButton = new SoftButton(2, "play_texture");
table.add(playButton).space(16); table.add(playButton).space(16);
playButton.addListener(new ChangeListener() { playButton.addListener(new ChangeListener() {