Search in sources :

Example 26 with TextButton

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

the class ParticleEmittersTest method setupUI.

private void setupUI() {
    ui = new Stage(new ExtendViewport(640, 480));
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    skipCleanup = new CheckBox("Skip blend function clean-up", skin);
    skipCleanup.setTransform(false);
    skipCleanup.addListener(listener);
    logLabel = new Label("", skin.get(LabelStyle.class));
    clearEmitters = new TextButton("Clear screen", skin);
    clearEmitters.setTransform(false);
    clearEmitters.addListener(listener);
    Table table = new Table();
    table.setTransform(false);
    table.setFillParent(true);
    table.defaults().padTop(5).left();
    table.top().left().padLeft(5);
    table.add(skipCleanup).row();
    table.add(clearEmitters).row();
    table.add(logLabel);
    ui.addActor(table);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ExtendViewport(com.badlogic.gdx.utils.viewport.ExtendViewport) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 27 with TextButton

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

the class GwtTestWrapper method create.

@Override
public void create() {
    Gdx.app.setLogLevel(Application.LOG_DEBUG);
    Gdx.app.log("GdxTestGwt", "Setting up for " + tests.length + " tests.");
    ui = new Stage();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    container = new Table();
    ui.addActor(container);
    container.debug();
    Table table = new Table();
    ScrollPane scroll = new ScrollPane(table);
    container.add(scroll).expand().fill();
    table.pad(10).defaults().expandX().space(4);
    Arrays.sort(tests, new Comparator<Instancer>() {

        @Override
        public int compare(Instancer o1, Instancer o2) {
            return o1.instance().getClass().getName().compareTo(o2.instance().getClass().getName());
        }
    });
    for (final Instancer instancer : tests) {
        table.row();
        TextButton button = new TextButton(instancer.instance().getClass().getName(), skin);
        button.addListener(new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                ((InputWrapper) Gdx.input).multiplexer.removeProcessor(ui);
                test = instancer.instance();
                Gdx.app.log("GdxTestGwt", "Clicked on " + test.getClass().getName());
                test.create();
                test.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
        });
        table.add(button).expandX().fillX();
    }
    container.row();
    container.add(new Label("Click on a test to start it, press ESC to close it.", new LabelStyle(font, Color.WHITE))).pad(5, 5, 5, 5);
    Gdx.input = new InputWrapper(Gdx.input) {

        @Override
        public boolean keyUp(int keycode) {
            if (keycode == Keys.ESCAPE) {
                if (test != null) {
                    Gdx.app.log("GdxTestGwt", "Exiting current test.");
                    dispose = true;
                }
            }
            return false;
        }

        @Override
        public boolean touchDown(int screenX, int screenY, int pointer, int button) {
            if (screenX < Gdx.graphics.getWidth() / 10.0 && screenY < Gdx.graphics.getHeight() / 10.0) {
                if (test != null) {
                    dispose = true;
                }
            }
            return false;
        }
    };
    ((InputWrapper) Gdx.input).multiplexer.addProcessor(ui);
    Gdx.app.log("GdxTestGwt", "Test picker UI setup complete.");
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 28 with TextButton

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

the class NetAPITest method create.

@Override
public void create() {
    batch = new SpriteBatch();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    font = new BitmapFont();
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    {
        statusLabel = new Label("", skin);
        statusLabel.setWrap(true);
        statusLabel.setWidth(Gdx.graphics.getWidth() * 0.96f);
        statusLabel.setAlignment(Align.center);
        statusLabel.setPosition(Gdx.graphics.getWidth() * 0.5f - statusLabel.getWidth() * 0.5f, 30f);
        statusLabel.setColor(Color.CYAN);
        stage.addActor(statusLabel);
    }
    {
        ClickListener clickListener = new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                super.clicked(event, x, y);
                clickedButton = event.getListenerActor();
                setButtonDisabled(true);
                if (texture != null)
                    texture.dispose();
                texture = null;
                text = null;
                String url;
                String httpMethod = Net.HttpMethods.GET;
                String requestContent = null;
                if (clickedButton == btnDownloadImage)
                    url = "http://i.imgur.com/vxomF.jpg";
                else if (clickedButton == btnDownloadText)
                    url = "http://www.apache.org/licenses/LICENSE-2.0.txt";
                else if (clickedButton == btnDownloadLarge)
                    url = "http://libgdx.badlogicgames.com/releases/libgdx-1.2.0.zip";
                else if (clickedButton == btnDownloadError)
                    url = "http://www.badlogicgames.com/doesnotexist";
                else if (clickedButton == btnOpenUri) {
                    Gdx.net.openURI("http://libgdx.badlogicgames.com/");
                    return;
                } else {
                    url = "http://posttestserver.com/post.php?dump";
                    httpMethod = Net.HttpMethods.POST;
                    requestContent = "name1=value1&name2=value2";
                }
                httpRequest = new HttpRequest(httpMethod);
                httpRequest.setUrl(url);
                httpRequest.setContent(requestContent);
                Gdx.net.sendHttpRequest(httpRequest, NetAPITest.this);
                statusLabel.setText("Downloading data from " + httpRequest.getUrl());
            }
        };
        ClickListener cancelListener = new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                super.clicked(event, x, y);
                if (httpRequest != null) {
                    Gdx.net.cancelHttpRequest(httpRequest);
                    Gdx.app.log("NetAPITest", "Cancelling request " + httpRequest.getUrl());
                    statusLabel.setText("Cancelling request " + httpRequest.getUrl());
                }
            }
        };
        btnCancel = new TextButton("Cancel", skin);
        btnCancel.setPosition(Gdx.graphics.getWidth() * 0.10f, 60f);
        btnCancel.addListener(cancelListener);
        stage.addActor(btnCancel);
        btnDownloadImage = new TextButton("GET Image", skin);
        btnDownloadImage.setPosition(btnCancel.getX() + btnCancel.getWidth() + 10, 60f);
        btnDownloadImage.addListener(clickListener);
        stage.addActor(btnDownloadImage);
        btnDownloadText = new TextButton("GET Text", skin);
        btnDownloadText.setPosition(btnDownloadImage.getX() + btnDownloadImage.getWidth() + 10, 60f);
        btnDownloadText.addListener(clickListener);
        stage.addActor(btnDownloadText);
        btnDownloadLarge = new TextButton("GET Large", skin);
        btnDownloadLarge.setPosition(btnDownloadText.getX() + btnDownloadText.getWidth() + 10, 60f);
        btnDownloadLarge.addListener(clickListener);
        stage.addActor(btnDownloadLarge);
        btnDownloadError = new TextButton("GET Error", skin);
        btnDownloadError.setPosition(btnDownloadLarge.getX() + btnDownloadLarge.getWidth() + 10, 60f);
        btnDownloadError.addListener(clickListener);
        stage.addActor(btnDownloadError);
        btnPost = new TextButton("POST", skin);
        btnPost.setPosition(btnDownloadError.getX() + btnDownloadError.getWidth() + 10, 60f);
        btnPost.addListener(clickListener);
        stage.addActor(btnPost);
        btnOpenUri = new TextButton("Open URI", skin);
        btnOpenUri.setPosition(btnPost.getX() + btnPost.getWidth() + 10, 60f);
        btnOpenUri.addListener(clickListener);
        stage.addActor(btnOpenUri);
    }
}
Also used : HttpRequest(com.badlogic.gdx.Net.HttpRequest) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 29 with TextButton

use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project Catacomb-Snatch by Catacomb-Snatch.

the class OptionsScene method init.

public void init(final OptionGroup group) {
    if (group != null)
        for (String k : group.getKeys()) {
            final String key = group.getCurrentPath() + k;
            final Object o = group.get(key);
            if (o instanceof OptionGroup) {
                addTextButton(Language.get("option." + key), 0, 0).addAction(new ReusableAction() {

                    @Override
                    public boolean use(float delta) {
                        OptionsScene scene = SceneManager.switchTo(OptionsScene.class);
                        scene.init((OptionGroup) o);
                        return true;
                    }
                });
            } else if (o instanceof Boolean) {
                final boolean b = (Boolean) o;
                final DefaultOptions option = DefaultOptions.getOption(key);
                final TextButton button = addTextButton(Language.get("option." + key + (b ? ".disable" : ".enable")), 0, 0);
                button.addAction(new ReusableAction() {

                    private boolean down = b;

                    @Override
                    public boolean use(float delta) {
                        down = !down;
                        if (option != null)
                            option.set(down);
                        else
                            group.set(key, down);
                        button.setText(Language.get("option." + key + (down ? ".disable" : ".enable")));
                        return true;
                    }
                });
            }
        // TODO add missing types
        }
    super.init();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) OptionGroup(net.catacombsnatch.game.resource.options.OptionGroup) ReusableAction(net.catacombsnatch.game.scene.ReusableAction) DefaultOptions(net.catacombsnatch.game.resource.options.DefaultOptions)

Example 30 with TextButton

use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project Entitas-Java by Rubentxu.

the class MenuState method init.

@Override
public void init() {
    Gdx.app.log("Menu", "Init");
    int pad = (int) (20 * SMGUIManager.ScaleUtil.getSizeRatio());
    int pad2 = (int) (60 * SMGUIManager.ScaleUtil.getSizeRatio());
    final TextButton btnStart = new TextButton("Comenzar", skin);
    btnStart.pad(pad, pad2, pad, pad2);
    final TextButton btnOptions = new TextButton("Opciones", skin);
    btnOptions.pad(pad, pad2, pad, pad2);
    final TextButton btnScores = new TextButton("Puntuaciones", skin);
    btnScores.pad(pad, pad2, pad, pad2);
    final TextButton button3 = new TextButton("Creditos", skin);
    button3.pad(pad, pad2, pad, pad2);
    button3.setChecked(false);
    btnStart.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            System.out.println("Click Comenzar...");
        }
    });
    btnOptions.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            System.out.println("Click optionScreen...");
            SMGame.ebus.post((ChangeStateCommand<SMGame>) (nameState, game) -> game.changeState(game.getOptionState(), game.getFadeTransition()));
        }
    });
    btnScores.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            System.out.println("Click highScoreScreen...");
            SMGame.ebus.post((ChangeStateCommand<SMGame>) (nameState, game) -> game.changeState(game.getScoresState(), game.getSlideTransition()));
        }
    });
    Label label = new Label("SUPER MARIANO", skin, "header", Color.CYAN);
    label.setAlignment(Align.center, Align.center);
    mainTable.defaults().padBottom(pad);
    if (Gdx.graphics.getHeight() < 480)
        mainTable.defaults().height(Gdx.graphics.getHeight() / 5f - pad);
    mainTable.add(label);
    mainTable.row();
    mainTable.add(btnStart);
    mainTable.row();
    mainTable.add(btnOptions);
    mainTable.row();
    mainTable.add(btnScores);
    mainTable.row();
    mainTable.add(button3);
    mainTable.row();
    mainTable.setBackground(new SpriteDrawable(new Sprite((Texture) assetsManager.getTexture(SMGUIManager.MENU_BACKGROUND))));
    mainTable.row();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) ChangeStateCommand(com.ilargia.games.entitas.egdx.api.ChangeStateCommand) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

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