Example usage for com.badlogic.gdx.scenes.scene2d.ui ImageTextButton getLabelCell

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui ImageTextButton getLabelCell

Introduction

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

Prototype

public Cell getLabelCell() 

Source Link

Usage

From source file:com.ray3k.libraryinvaders.states.MenuState.java

License:Open Source License

private void showCharacterDialog() {
    Dialog dialog = new Dialog("", skin);

    Label label = new Label("Choose a character...", skin);
    dialog.getContentTable().add(label);

    dialog.getContentTable().row();/*from  w ww . j a v  a  2 s  .c  o  m*/
    Table table = new Table();
    ScrollPane scrollPane = new ScrollPane(table, skin);
    scrollPane.setFadeScrollBars(false);
    dialog.getContentTable().add(scrollPane).grow();

    final ButtonGroup<ImageTextButton> buttons = new ButtonGroup<ImageTextButton>();
    for (String name : getCore().getImagePacks().get(DATA_PATH + "/characters")) {
        Drawable drawable = new TextureRegionDrawable(getCore().getAtlas().findRegion(name));
        Image image = new Image(drawable);
        ImageTextButton imageTextButton = new ImageTextButton(name, skin, "list");
        imageTextButton.getImageCell().setActor(image);
        imageTextButton.getLabelCell().left().expandX();
        table.add(imageTextButton).growX();
        buttons.add(imageTextButton);

        table.row();
    }

    dialog.getContentTable().row();
    TextButton textButton = new TextButton("OK", skin);
    dialog.getContentTable().add(textButton);

    textButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            getCore().getAssetManager().get(Core.DATA_PATH + "/sfx/menu.wav", Sound.class).play();
            ((GameState) getCore().getStateManager().getState("game"))
                    .setSelectedCharacter(buttons.getChecked().getText().toString());

            Gdx.input.setInputProcessor(null);
            Action changeStateAction = new Action() {
                @Override
                public boolean act(float delta) {
                    getCore().getStateManager().loadState("game");
                    return true;
                }
            };
            root.addAction(new SequenceAction(new DelayAction(.5f), changeStateAction));
        }
    });

    dialog.show(stage);
    dialog.setSize(600.0f, 500.0f);
    dialog.setPosition(stage.getWidth() / 2.0f, stage.getHeight() / 2.0f, Align.center);
    stage.setScrollFocus(scrollPane);
}