Example usage for com.badlogic.gdx.scenes.scene2d.ui Table getBackground

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui Table getBackground

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.ui Table getBackground.

Prototype

public Drawable getBackground() 

Source Link

Usage

From source file:io.piotrjastrzebski.sfg.screen.SkinSelectScreen.java

License:Open Source License

private void refreshUI() {
    contTable.clearChildren();//from w  w w.ja v  a  2s  . co m
    skinLabels.clear();
    skinTables.clear();

    PlayerStats.Skin current = playerStats.getPlayerSkin();

    final Array<PlayerStats.Skin> skins = playerStats.getSkins();
    int size = skins.size;
    // dont show last skin on non android
    if (!(Gdx.app.getType() == Application.ApplicationType.Android)) {
        size -= 1;
    }
    for (int i = 0; i < size; i++) {
        final PlayerStats.Skin skin = skins.get(i);
        final Table skinTable = createSkinItem(skin);
        final Label skinLabel = skinLabels.get(i);
        if (current.id == skin.id)
            skinTable.setBackground(select);
        skinTables.add(skinTable);
        skinTable.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                if (skin.isUnlocked()) {
                    if (skinTable.getBackground() == empty) {
                        clearSelect();
                        skinTable.setBackground(select);
                        playerStats.setPlayerSkin(skin);
                    } else {
                        skinTable.setBackground(empty);
                        playerStats.setDefaultPlayerSkin();
                        selectDefault();
                    }
                    skinLabel.clearActions();
                    skinLabel.addAction(
                            Actions.sequence(Actions.color(assets.getSkin().getColor("toxic"), 0.33f),
                                    Actions.color(Color.WHITE, 0.33f)));
                    contTable.invalidateHierarchy();
                } else {
                    if (skin.id == PlayerStats.SKIN_RUBY) {
                        playerStats.buyPremium();
                    } else {
                        skinLabel.clearActions();
                        skinLabel.addAction(Actions.sequence(Actions.color(Color.RED, 0.25f),
                                Actions.color(Color.WHITE, 0.25f)));
                    }
                }
                playButtonPressSound();
            }
        });
        contTable.add(skinTable).expandX().fillX();
        contTable.row();
    }
}