Search in sources :

Example 11 with Label

use of com.badlogic.gdx.scenes.scene2d.ui.Label 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 12 with Label

use of com.badlogic.gdx.scenes.scene2d.ui.Label 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)

Example 13 with Label

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

the class ContinueScreen method highScoreDialog.

/**
	 * Displays the high score dialog.
	 */
public void highScoreDialog() {
    Label.LabelStyle labelStyle = new Label.LabelStyle(game.assets.getFont(Assets.MONO_REGULAR, Assets.SMALL_FONT_SIZE), Color.WHITE);
    final Dialog dialog = new Dialog("High Score", game.assets.skin);
    final TextButton okButton = new TextButton("OK", game.assets.skin);
    dialog.getButtonTable().bottom();
    Label label = new Label("Enter your name:", labelStyle);
    label.setScale(.5f);
    label.setWrap(true);
    label.setAlignment(Align.center);
    final TextField nameField = new TextField("", game.assets.skin);
    dialog.add(label).width(500).pad(50);
    dialog.add(nameField);
    dialog.add(okButton).bottom();
    nameField.setTextFieldListener(new TextFieldListener() {

        @Override
        public void keyTyped(TextField textField, char key) {
            name = formatString(nameField.getText());
            if (!name.equals("")) {
                if (key == (char) 13) {
                    displayHighScores(name);
                }
            }
        }
    });
    okButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            name = formatString(nameField.getText());
            if (!name.equals("")) {
                if (okButton.isPressed()) {
                    dialog.hide();
                    displayHighScores(name);
                }
            }
        }
    });
    dialog.addListener(new InputListener() {

        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            name = formatString(nameField.getText());
            if (!name.equals("")) {
                if (keycode == Keys.ENTER) {
                    displayHighScores(name);
                    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) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) TextFieldListener(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Example 14 with Label

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

the class CreditsScreen method setupComponents.

/**
	 * Instantiate the stage and its actors for the credits screen.
	 * Add all actors to the stage.
	 */
private void setupComponents() {
    stage = new Stage();
    table = new Table();
    table.top();
    table.setFillParent(true);
    stage.addActor(table);
    gameLogo = new Image(game.assets.manager.get(Assets.GAME_LOGO, Texture.class));
    header = new Label("", game.assets.skin, Assets.SERIF_HEADER_STYLE);
    codeGroup = setupCreditsLabel(CODE, Assets.CREDITS_CONTENTS);
    artGroup = setupCreditsLabel(ART, Assets.CREDITS_CONTENTS);
    storyGroup = setupCreditsLabel(STORY, Assets.CREDITS_CONTENTS);
    musicGroup = setupCreditsLabel(MUSIC, Assets.SMALL_CREDITS_CONTENTS);
    thanksGroup = setupCreditsLabel(THANKS, Assets.CREDITS_CONTENTS);
    companyLogo = new Image(game.assets.manager.get(Assets.COMPANY_LOGO, Texture.class));
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Image(com.badlogic.gdx.scenes.scene2d.ui.Image)

Example 15 with Label

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

the class CreditsScreen method setupCreditsLabel.

/**
	 * Helper method to create centred labels.
	 *
	 * @param lines the lines to put in the label. Assumed to have at least one element.
	 * @param skin the skin to load the style from.
	 * @return a new {@link Label} with the given properties.
	 */
private Label setupCreditsLabel(String[] lines, String style) {
    String s = lines[0];
    for (int i = 1; i < lines.length; i++) {
        s += "\n" + lines[i];
    }
    Label label = new Label(s, game.assets.skin, style);
    label.setAlignment(Align.center);
    return label;
}
Also used : Label(com.badlogic.gdx.scenes.scene2d.ui.Label)

Aggregations

Label (com.badlogic.gdx.scenes.scene2d.ui.Label)43 Stage (com.badlogic.gdx.scenes.scene2d.Stage)25 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)24 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)23 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)20 Actor (com.badlogic.gdx.scenes.scene2d.Actor)18 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)16 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)16 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)10 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)10 Texture (com.badlogic.gdx.graphics.Texture)9 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)9 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)9 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)8 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)8 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)7 Window (com.badlogic.gdx.scenes.scene2d.ui.Window)7 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)6 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)5 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)5