Search in sources :

Example 1 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 2 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 3 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 4 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)

Example 5 with Label

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

the class StoryScreen method setupUI.

/** Helper method to setup the UI. */
private void setupUI() {
    stage = new Stage(new ScreenViewport(), game.batch);
    table = new Table();
    table.top().center();
    table.setFillParent(true);
    stage.addActor(table);
    header = new Label("Story", game.assets.skin, Assets.SERIF_HEADER_STYLE);
    table.add(header).padTop(Gdx.graphics.getHeight() / 25f);
    storyLabel = new Label(readStory(), game.assets.skin, Assets.STORY_STYLE);
    storyLabel.setWrap(true);
    table.row();
    table.add(storyLabel).maxWidth(Gdx.graphics.getWidth()).prefWidth(Gdx.graphics.getWidth() / 1.125f).pad(Gdx.graphics.getHeight() / 25f);
    continueButton = new TextButton("Continue...", game.assets.skin);
    continueButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (continueButton.isPressed()) {
                game.setScreen(new MazeScreen(game, false));
            }
        }
    });
    table.row();
    table.add(continueButton).width(Gdx.graphics.getWidth() / 4f).pad(Gdx.graphics.getHeight() / 25f).expandY().bottom().fillY();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport)

Aggregations

Label (com.badlogic.gdx.scenes.scene2d.ui.Label)115 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)54 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)52 Actor (com.badlogic.gdx.scenes.scene2d.Actor)48 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)43 Stage (com.badlogic.gdx.scenes.scene2d.Stage)38 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)34 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)28 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)27 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)22 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)21 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)21 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)19 Texture (com.badlogic.gdx.graphics.Texture)16 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)16 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)15 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)14 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)14 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)14 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)12