Search in sources :

Example 1 with TextButton

use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project libgdx by libgdx.

the class ViewportTest1 method create.

public void create() {
    stage = new Stage();
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    label = new Label("", skin);
    Table root = new Table(skin);
    root.setFillParent(true);
    root.setBackground(skin.getDrawable("default-pane"));
    root.debug().defaults().space(6);
    root.add(new TextButton("Button 1", skin));
    root.add(new TextButton("Button 2", skin)).row();
    root.add("Press spacebar to change the viewport:").colspan(2).row();
    root.add(label).colspan(2);
    stage.addActor(root);
    viewports = getViewports(stage.getCamera());
    names = getViewportNames();
    stage.setViewport(viewports.first());
    label.setText(names.first());
    Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {

        public boolean keyDown(int keycode) {
            if (keycode == Input.Keys.SPACE) {
                int index = (viewports.indexOf(stage.getViewport(), true) + 1) % viewports.size;
                label.setText(names.get(index));
                Viewport viewport = viewports.get(index);
                stage.setViewport(viewport);
                resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
            return false;
        }
    }, stage));
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) InputAdapter(com.badlogic.gdx.InputAdapter) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) StretchViewport(com.badlogic.gdx.utils.viewport.StretchViewport) ExtendViewport(com.badlogic.gdx.utils.viewport.ExtendViewport) ScalingViewport(com.badlogic.gdx.utils.viewport.ScalingViewport) FitViewport(com.badlogic.gdx.utils.viewport.FitViewport) Viewport(com.badlogic.gdx.utils.viewport.Viewport) FillViewport(com.badlogic.gdx.utils.viewport.FillViewport) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 2 with TextButton

use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project libgdx by libgdx.

the class TextButtonTest method create.

@Override
public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    for (int i = 0; i < 1; i++) {
        TextButton t = new TextButton("Button" + i, skin);
        t.setX(MathUtils.random(0, Gdx.graphics.getWidth()));
        t.setY(MathUtils.random(0, Gdx.graphics.getHeight()));
        t.setWidth(MathUtils.random(50, 200));
        t.setHeight(MathUtils.random(0, 100));
        stage.addActor(t);
    }
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 3 with TextButton

use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project libgdx by libgdx.

the class SoundTest method create.

@Override
public void create() {
    sound = Gdx.audio.newSound(Gdx.files.getFileHandle("data/shotgun.ogg", FileType.Internal));
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    ui = new Stage();
    TextButton play = new TextButton("Play", skin);
    TextButton stop = new TextButton("Stop", skin);
    final Slider pitch = new Slider(0.1f, 4, 0.1f, false, skin);
    pitch.setValue(1);
    final Label pitchValue = new Label("1.0", skin);
    final Slider volume = new Slider(0.1f, 1, 0.1f, false, skin);
    volume.setValue(1);
    final Label volumeValue = new Label("1.0", skin);
    Table table = new Table();
    final Slider pan = new Slider(-1f, 1f, 0.1f, false, skin);
    pan.setValue(0);
    final Label panValue = new Label("0.0", skin);
    table.setFillParent(true);
    table.align(Align.center | Align.top);
    table.columnDefaults(0).expandX().right().uniformX();
    table.columnDefaults(2).expandX().left().uniformX();
    table.add(play);
    table.add(stop).left();
    table.row();
    table.add(new Label("Pitch", skin));
    table.add(pitch);
    table.add(pitchValue);
    table.row();
    table.add(new Label("Volume", skin));
    table.add(volume);
    table.add(volumeValue);
    table.row();
    table.add(new Label("Pan", skin));
    table.add(pan);
    table.add(panValue);
    ui.addActor(table);
    play.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            soundId = sound.play(volume.getValue());
            sound.setPitch(soundId, pitch.getValue());
            sound.setPan(soundId, pan.getValue(), volume.getValue());
        }
    });
    stop.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            sound.stop(soundId);
        }
    });
    pitch.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            sound.setPitch(soundId, pitch.getValue());
            pitchValue.setText("" + pitch.getValue());
        }
    });
    volume.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            sound.setVolume(soundId, volume.getValue());
            volumeValue.setText("" + volume.getValue());
        }
    });
    pan.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            sound.setPan(soundId, pan.getValue(), volume.getValue());
            panValue.setText("" + pan.getValue());
        }
    });
    Gdx.input.setInputProcessor(ui);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 4 with TextButton

use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project commons-gdx by gemserk.

the class Actors method threeOptionsDialog.

public static Actor threeOptionsDialog(String[] texts, final DialogListener dialogListener, String titleText, String firstOption, String secondOption, String thirdOption, Skin skin) {
    Window window = new Window(titleText, skin);
    window.setMovable(false);
    TextButton firstOptionButton = new TextButton(firstOption, skin);
    TextButton secondOptionButton = new TextButton(secondOption, skin);
    TextButton thirdOptionButton = new TextButton(thirdOption, skin);
    firstOptionButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            dialogListener.optionSelected(0);
        }
    });
    secondOptionButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            dialogListener.optionSelected(1);
        }
    });
    thirdOptionButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            dialogListener.optionSelected(2);
        }
    });
    window.defaults().spaceBottom(10);
    window.row().fill().expandX();
    for (int i = 0; i < texts.length; i++) {
        window.row().padLeft(20);
        Label label = new Label(texts[i], skin);
        label.setWrap(true);
        window.add(label).align(Align.left).colspan(2).fillX();
    }
    window.row().fill().expandX().padTop(10);
    window.add(firstOptionButton).align(Align.center).padLeft(30).padRight(30);
    window.row().fill().expandX();
    window.add(secondOptionButton).align(Align.center).padLeft(30).padRight(30);
    window.row().fill().expandX();
    window.add(thirdOptionButton).align(Align.center).padLeft(30).padRight(30);
    ScrollPane scrollPane = new ScrollPane(window);
    scrollPane.setWidth(Gdx.graphics.getWidth() * 0.95f);
    scrollPane.setHeight(Gdx.graphics.getHeight() * 0.95f);
    scrollPane.setX(Gdx.graphics.getWidth() * 0.5f - scrollPane.getWidth() * 0.5f);
    scrollPane.setY(Gdx.graphics.getHeight() * 0.5f - scrollPane.getHeight() * 0.5f);
    return scrollPane;
}
Also used : Window(com.badlogic.gdx.scenes.scene2d.ui.Window) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 5 with TextButton

use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project AmazingMaze by TheVirtualMachine.

the class FishMiniGame method dialog.

/**
	 * Displays the results dialog.
	 */
public void dialog() {
    message = formatString(answerField.getText());
    Label.LabelStyle labelStyle = new Label.LabelStyle(game.assets.getFont(Assets.MONO_REGULAR, Assets.SMALL_FONT_SIZE), Color.WHITE);
    final Dialog dialog = new Dialog("Results", game.assets.skin);
    final TextButton okButton = new TextButton("OK", game.assets.skin);
    dialog.getButtonTable().bottom();
    if (checkAnswer() == -1) {
        Label label = new Label("Invalid answer. Please try again.", labelStyle);
        label.setScale(.5f);
        label.setWrap(true);
        label.setAlignment(Align.center);
        dialog.add(label).width(500).pad(50);
        dialog.add(okButton).bottom();
        okButton.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeEvent event, Actor actor) {
                if (okButton.isPressed()) {
                    dialog.hide();
                    canvas.setColor(drawColor);
                }
            }
        });
        dialog.addListener(new InputListener() {

            @Override
            public boolean keyDown(InputEvent event, int keycode) {
                if (keycode == Keys.ENTER) {
                    dialog.hide();
                    return true;
                }
                return false;
            }
        });
    } else {
        Label label = new Label("Your answer was: " + message + ". " + "The correct answer was: " + answer + ". " + "You get " + checkAnswer() + " back!", labelStyle);
        game.save.addScore(checkAnswer());
        game.save.setLives(player.getLives());
        label.setScale(.5f);
        label.setWrap(true);
        label.setAlignment(Align.center);
        dialog.add(label).width(500).pad(50);
        dialog.add(okButton).bottom();
        okButton.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeEvent event, Actor actor) {
                if (okButton.isPressed()) {
                    dialog.cancel();
                    if ((game.save.getLevel() - 1) % 5 == 0) {
                        game.setScreen(new ContinueScreen(game, true));
                    } else {
                        game.setScreen(new MazeScreen(game, false));
                    }
                }
            }
        });
        dialog.addListener(new InputListener() {

            @Override
            public boolean keyDown(InputEvent event, int keycode) {
                if (keycode == Keys.ENTER) {
                    if ((game.save.getLevel() - 1) % 5 == 0) {
                        game.setScreen(new ContinueScreen(game, true));
                    } else {
                        game.setScreen(new MazeScreen(game, false));
                    }
                    return true;
                }
                return false;
            }
        });
    }
    dialog.show(stage);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Aggregations

TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)35 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)23 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)23 Stage (com.badlogic.gdx.scenes.scene2d.Stage)20 Actor (com.badlogic.gdx.scenes.scene2d.Actor)18 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)17 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)17 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)16 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)12 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)9 Texture (com.badlogic.gdx.graphics.Texture)6 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)6 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)6 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)5 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)5 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)5 Slider (com.badlogic.gdx.scenes.scene2d.ui.Slider)5 TextButtonStyle (com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle)5 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)5 Window (com.badlogic.gdx.scenes.scene2d.ui.Window)5