Example usage for com.badlogic.gdx.scenes.scene2d.ui List getSelection

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

Introduction

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

Prototype

public ArraySelection<T> getSelection() 

Source Link

Usage

From source file:de.cwclan.gdxtest.core.screens.LevelMenu.java

@Override
public void show() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);/*from  w ww.  ja va 2 s . c  om*/

    skin = new Skin(Gdx.files.internal("ui/menuSkin.json"), new TextureAtlas("ui/atlas.pack"));

    List list = new List(new String[] { "de.cwclan.gdxtest.core.games.CarGame",
            "de.cwclan.gdxtest.core.games.JumperGame", "de.cwclan.gdxtest.core.games.TiledGame" }, skin);
    list.setSelectedIndex(0);
    ScrollPane scrollPane = new ScrollPane(list, skin);
    scrollPane.setWidth(30);

    TextButton playButton = new TextButton("Druf da", skin);
    playButton.pad(5);
    playButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {

            try {
                Class<? extends Screen> clazz = (Class<? extends Screen>) Class.forName(list.getSelection());
                Screen screen = clazz.newInstance();
                ((Game) Gdx.app.getApplicationListener()).setScreen(screen);
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
                System.err.println(ex.getMessage());
            }

        }

    });

    TextButton backButton = new TextButton("zurck", skin, "small");
    backButton.pad(5);
    backButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            ((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu());
        }
    });

    table = new Table(skin);
    table.setFillParent(true);
    table.debug();
    table.setFillParent(true);
    table.add("Select Level", "big").colspan(3).expandX().spaceBottom(50).row();
    table.add(scrollPane).uniformX().left().expandY();
    table.add(playButton).uniformX();
    table.add(backButton).uniformY().bottom().right();
    stage.addActor(table);

}