Fix buttons using wrong drawable (after Customize screen)
This commit is contained in:
parent
4706cb221e
commit
d8825b0f27
5 changed files with 55 additions and 17 deletions
|
@ -74,7 +74,8 @@ public class Theme {
|
|||
if (buttonStyles[i] == null) {
|
||||
buttonStyles[i] = new ImageButton.ImageButtonStyle();
|
||||
}
|
||||
|
||||
// Update the style. Since every button uses an instance from this
|
||||
// array, the changes will appear on screen automatically.
|
||||
buttonStyles[i].up = skin.newDrawable("button_up", buttons[i]);
|
||||
buttonStyles[i].down = skin.newDrawable("button_down", buttons[i]);
|
||||
}
|
||||
|
@ -92,9 +93,7 @@ public class Theme {
|
|||
return this;
|
||||
}
|
||||
|
||||
// TODO Avoid creating game.skin.newDrawable all the time without disposing…
|
||||
public ImageButton.ImageButtonStyle getStyle(final Skin skin, int button, final String imageName) {
|
||||
buttonStyles[button].imageUp = skin.getDrawable(imageName);
|
||||
public ImageButton.ImageButtonStyle getStyle(int button) {
|
||||
return buttonStyles[button];
|
||||
}
|
||||
|
||||
|
@ -113,4 +112,9 @@ public class Theme {
|
|||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void updateStyle(ImageButton.ImageButtonStyle style, int styleIndex) {
|
||||
style.imageUp = buttonStyles[styleIndex].imageUp;
|
||||
style.imageDown = buttonStyles[styleIndex].imageDown;
|
||||
}
|
||||
}
|
||||
|
|
31
core/src/io/github/lonamiwebs/klooni/actors/SoftButton.java
Normal file
31
core/src/io/github/lonamiwebs/klooni/actors/SoftButton.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package io.github.lonamiwebs.klooni.actors;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
|
||||
|
||||
import io.github.lonamiwebs.klooni.Klooni;
|
||||
import io.github.lonamiwebs.klooni.Theme;
|
||||
|
||||
public class SoftButton extends ImageButton {
|
||||
|
||||
private int styleIndex;
|
||||
private Drawable image;
|
||||
|
||||
public SoftButton(int styleIndex, String imageName) {
|
||||
super(Klooni.theme.getStyle(styleIndex));
|
||||
|
||||
this.styleIndex = styleIndex;
|
||||
image = Theme.skin.getDrawable(imageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
// Always update the style to make sure we're using the right colors
|
||||
ImageButtonStyle style = getStyle();
|
||||
Klooni.theme.updateStyle(style, styleIndex);
|
||||
style.imageUp = image;
|
||||
|
||||
super.draw(batch, parentAlpha);
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
|||
|
||||
import io.github.lonamiwebs.klooni.Klooni;
|
||||
import io.github.lonamiwebs.klooni.Theme;
|
||||
import io.github.lonamiwebs.klooni.actors.SoftButton;
|
||||
import io.github.lonamiwebs.klooni.actors.ThemeCard;
|
||||
import io.github.lonamiwebs.klooni.game.GameLayout;
|
||||
|
||||
|
@ -40,7 +41,7 @@ public class CustomizeScreen implements Screen {
|
|||
optionsGroup.space(12);
|
||||
|
||||
// Back to the previous screen
|
||||
final ImageButton backButton = new ImageButton(Klooni.theme.getStyle(game.skin, 1, "back_texture"));
|
||||
final ImageButton backButton = new SoftButton(1, "back_texture");
|
||||
backButton.addListener(new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
|
@ -51,8 +52,8 @@ public class CustomizeScreen implements Screen {
|
|||
optionsGroup.addActor(backButton);
|
||||
|
||||
// Turn sound on/off
|
||||
final ImageButton soundButton = new ImageButton(Klooni.theme.getStyle(
|
||||
game.skin, 0, Klooni.soundsEnabled() ? "sound_on_texture" : "sound_off_texture"));
|
||||
final ImageButton soundButton = new SoftButton(
|
||||
0, Klooni.soundsEnabled() ? "sound_on_texture" : "sound_off_texture");
|
||||
|
||||
soundButton.addListener(new ChangeListener() {
|
||||
@Override
|
||||
|
@ -65,7 +66,7 @@ public class CustomizeScreen implements Screen {
|
|||
optionsGroup.addActor(soundButton);
|
||||
|
||||
// Issues
|
||||
final ImageButton issuesButton = new ImageButton(Klooni.theme.getStyle(game.skin, 3, "issues_texture"));
|
||||
final ImageButton issuesButton = new SoftButton(3, "issues_texture");
|
||||
issuesButton.addListener(new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
|
@ -75,7 +76,7 @@ public class CustomizeScreen implements Screen {
|
|||
optionsGroup.addActor(issuesButton);
|
||||
|
||||
// Website
|
||||
final ImageButton webButton = new ImageButton(Klooni.theme.getStyle(game.skin, 2, "web_texture"));
|
||||
final ImageButton webButton = new SoftButton(2, "web_texture");
|
||||
webButton.addListener(new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
|||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
|
||||
import io.github.lonamiwebs.klooni.Klooni;
|
||||
import io.github.lonamiwebs.klooni.actors.SoftButton;
|
||||
|
||||
public class MainMenuScreen extends InputListener implements Screen {
|
||||
private Klooni game;
|
||||
|
@ -31,7 +32,7 @@ public class MainMenuScreen extends InputListener implements Screen {
|
|||
stage.addActor(table);
|
||||
|
||||
// Play button
|
||||
final ImageButton playButton = new ImageButton(Klooni.theme.getStyle(game.skin, 0, "play_texture"));
|
||||
final ImageButton playButton = new SoftButton(0, "play_texture");
|
||||
playButton.addListener(new ChangeListener() {
|
||||
public void changed (ChangeEvent event, Actor actor) {
|
||||
game.setScreen(new GameScreen(game));
|
||||
|
@ -43,15 +44,15 @@ public class MainMenuScreen extends InputListener implements Screen {
|
|||
table.row();
|
||||
|
||||
// Star button (on GitHub)
|
||||
final ImageButton starButton = new ImageButton(Klooni.theme.getStyle(game.skin, 1, "star_texture"));
|
||||
final ImageButton starButton = new SoftButton(1, "star_texture");
|
||||
table.add(starButton).space(16);
|
||||
|
||||
// Stats button (high scores)
|
||||
final ImageButton statsButton = new ImageButton(Klooni.theme.getStyle(game.skin, 2, "stats_texture"));
|
||||
final ImageButton statsButton = new SoftButton(2, "stats_texture");
|
||||
table.add(statsButton).space(16);
|
||||
|
||||
// Palette button (buy colors)
|
||||
final ImageButton paletteButton = new ImageButton(Klooni.theme.getStyle(game.skin, 3, "palette_texture"));
|
||||
final ImageButton paletteButton = new SoftButton(3, "palette_texture");
|
||||
paletteButton.addListener(new ChangeListener() {
|
||||
public void changed (ChangeEvent event, Actor actor) {
|
||||
game.setScreen(new CustomizeScreen(game, game.getScreen()));
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
|||
|
||||
import io.github.lonamiwebs.klooni.Klooni;
|
||||
import io.github.lonamiwebs.klooni.actors.Band;
|
||||
import io.github.lonamiwebs.klooni.actors.SoftButton;
|
||||
import io.github.lonamiwebs.klooni.game.GameLayout;
|
||||
import io.github.lonamiwebs.klooni.game.Scorer;
|
||||
|
||||
|
@ -42,7 +43,7 @@ public class PauseMenuStage extends Stage {
|
|||
addActor(band);
|
||||
|
||||
// Home screen button
|
||||
final ImageButton homeButton = new ImageButton(Klooni.theme.getStyle(game.skin, 3, "home_texture"));
|
||||
final ImageButton homeButton = new SoftButton(3, "home_texture");
|
||||
table.add(homeButton).space(16);
|
||||
|
||||
homeButton.addListener(new ChangeListener() {
|
||||
|
@ -53,7 +54,7 @@ public class PauseMenuStage extends Stage {
|
|||
});
|
||||
|
||||
// Replay button
|
||||
final ImageButton replayButton = new ImageButton(Klooni.theme.getStyle(game.skin, 0, "replay_texture"));
|
||||
final ImageButton replayButton = new SoftButton(0, "replay_texture");
|
||||
table.add(replayButton).space(16);
|
||||
|
||||
replayButton.addListener(new ChangeListener() {
|
||||
|
@ -67,7 +68,7 @@ public class PauseMenuStage extends Stage {
|
|||
table.row();
|
||||
|
||||
// Palette button (buy colors)
|
||||
final ImageButton paletteButton = new ImageButton(Klooni.theme.getStyle(game.skin, 1, "palette_texture"));
|
||||
final ImageButton paletteButton = new SoftButton(1, "palette_texture");
|
||||
table.add(paletteButton).space(16);
|
||||
|
||||
paletteButton.addListener(new ChangeListener() {
|
||||
|
@ -80,7 +81,7 @@ public class PauseMenuStage extends Stage {
|
|||
|
||||
// Continue playing OR share (if game over) button
|
||||
// TODO Enable both actions for this button
|
||||
final ImageButton playButton = new ImageButton(Klooni.theme.getStyle(game.skin, 2, "play_texture"));
|
||||
final ImageButton playButton = new SoftButton(2, "play_texture");
|
||||
table.add(playButton).space(16);
|
||||
|
||||
playButton.addListener(new ChangeListener() {
|
||||
|
|
Loading…
Reference in a new issue