Example usage for com.badlogic.gdx.scenes.scene2d.ui Label Label

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

Introduction

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

Prototype

public Label(CharSequence text, Skin skin, String styleName) 

Source Link

Usage

From source file:at.highstreeto.xnllayoutparser.element.LabelParser.java

License:Apache License

@Override
public Actor load(Element element, LayoutParserContext context) throws LayoutParseException {
    String text = element.getText();

    Label label = new Label(text == null ? "" : text, context.getSkin(), ElementParserHelper.getStyle(element));

    context.addActor(label, element);//from ww w .jav  a  2 s.co  m
    ElementParserHelper.setActorName(element, label);

    return label;
}

From source file:ca.hiphiparray.amazingmaze.ContinueScreen.java

License:Open Source License

/**
 * The constructor for ContinueScreen.//  ww w .ja  v a 2s.co m
 *
 * @param game the {@link AmazingMazeGame} instance that is managing this screen.
 * @param won if the player won.
 */
public ContinueScreen(final AmazingMazeGame game, final boolean won) {
    this.game = game;

    stage = new Stage(new ScreenViewport(), this.game.batch);
    labelTable = new Table();
    optionTable = new Table();
    labelTable.setFillParent(true);
    labelTable.top().center();
    optionTable.setFillParent(true);
    optionTable.bottom();
    labelTable.background(new TextureRegionDrawable(
            new TextureRegion(this.game.assets.manager.get(Assets.MINI_BACKGROUND, Texture.class))));

    if (won) {
        resultLabel = new Label("You got the antidote!", game.assets.skin, Assets.WHITE_SANS_STYLE);
        resultDescriptionLabel = new Label("Continute searching for more to help others or quit the maze?",
                game.assets.skin, Assets.WHITE_SANS_STYLE);
    } else {
        resultLabel = new Label("You lose!", game.assets.skin, Assets.WHITE_SANS_STYLE);
        resultDescriptionLabel = new Label("Go back to last checkpoint or quit?", game.assets.skin,
                Assets.WHITE_SANS_STYLE);
    }
    currentScoreLabel = new Label("Your current score: " + game.save.getScore(), game.assets.skin,
            Assets.WHITE_SANS_STYLE);

    continueButton = new TextButton("Continue", game.assets.skin);
    continueButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (continueButton.isPressed()) {
                if (!won) {
                    int nextLevel = 5 * (game.save.getLevel() / 5) + 1;
                    int startScore = game.save.getStartScore();
                    game.save.resetSave();
                    game.save.setLevel(nextLevel);
                    game.save.setStartScore(startScore);
                    game.save.setScore(startScore);
                } else {
                    game.save.setStartScore(game.save.getScore());
                }
                game.setScreen(new MazeScreen(game, false));
            }
        }
    });

    quitButton = new TextButton("Quit", game.assets.skin);
    quitButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (quitButton.isPressed()) {
                highScoreDialog();
            }
        }
    });

    labelTable.add(resultLabel).pad(20);
    labelTable.row();
    labelTable.add(resultDescriptionLabel).pad(20);
    labelTable.row();
    labelTable.add(currentScoreLabel).pad(20);
    optionTable.add(continueButton).minSize(Gdx.graphics.getWidth() / 8, Gdx.graphics.getHeight() / 20)
            .maxSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() / 8)
            .prefSize(Gdx.graphics.getWidth() / 5, Gdx.graphics.getHeight() / 10).padBottom(10).pad(20);
    optionTable.row();
    optionTable.add(quitButton).minSize(Gdx.graphics.getWidth() / 8, Gdx.graphics.getHeight() / 20)
            .maxSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() / 8)
            .prefSize(Gdx.graphics.getWidth() / 5, Gdx.graphics.getHeight() / 10).pad(20).padBottom(40);
    stage.addActor(labelTable);
    stage.addActor(optionTable);
}

From source file:ca.hiphiparray.amazingmaze.CreditsScreen.java

License:Open Source License

/**
 * Instantiate the stage and its actors for the credits screen.
 * Add all actors to the stage.//from  ww w .  j  a  v  a  2 s .  c  o m
 */
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));
}

From source file:ca.hiphiparray.amazingmaze.CreditsScreen.java

License:Open Source License

/**
 * 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.
 *///from  w  w w.  ja va 2s .  c o m
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;
}

From source file:ca.hiphiparray.amazingmaze.HelpScreen.java

License:Open Source License

/**
 * Creates the help screen./*from   w  w w.  j a va 2  s .c o m*/
 *
 * @param game The instance for the AmazingMazeGame used.
 */
public HelpScreen(final AmazingMazeGame game) {
    super(game, true);
    instruct = new Label(
            "Check the logic gates to find the state of each wire and make your way through the maze. Be careful to avoid\nany wires that are on, as that means that they are electrified!",
            game.assets.skin, Assets.HUD_STYLE);
    instruct.setAlignment(Align.center);
    clicks = new Label(
            "Mark the wires by clicking on the gates. Left click = on. Right click = off. Middle click = unknown.",
            game.assets.skin, Assets.HUD_STYLE);
    clicks.setAlignment(Align.center);

    super.hud = new Stage(new ScreenViewport(), game.batch);

    table = new Table();
    table.top();
    table.setFillParent(true);
    super.hud.addActor(table);

    table.add(instruct).top().pad(10);
    table.row();
    table.add(clicks).pad(10);
    table.row();
    table.add().expand();
    table.row();

    gates = new Label[] { new Label("AND Gate", game.assets.skin, Assets.HUD_STYLE),
            new Label("NAND Gate", game.assets.skin, Assets.HUD_STYLE),
            new Label("OR Gate", game.assets.skin, Assets.HUD_STYLE),
            new Label("NOR Gate", game.assets.skin, Assets.HUD_STYLE),
            new Label("XOR Gate", game.assets.skin, Assets.HUD_STYLE) };

    TextureAtlas atlas = game.assets.manager.get(Assets.GAME_ATLAS_LOCATION, TextureAtlas.class); // Reference used for readability.
    gatePics = new Image[] {
            new Image(atlas.findRegion(Assets.AND_GATE + Assets.UNKNOWN_MODIFIER + Assets.UP_MODIFIER)),
            new Image(atlas.findRegion(Assets.NAND_GATE + Assets.UNKNOWN_MODIFIER + Assets.UP_MODIFIER)),
            new Image(atlas.findRegion(Assets.OR_GATE + Assets.UNKNOWN_MODIFIER + Assets.UP_MODIFIER)),
            new Image(atlas.findRegion(Assets.NOR_GATE + Assets.UNKNOWN_MODIFIER + Assets.UP_MODIFIER)),
            new Image(atlas.findRegion(Assets.XOR_GATE + Assets.UNKNOWN_MODIFIER + Assets.UP_MODIFIER)), };

    truthTable = new Table();
    truthTable.top().center();
    table.add(truthTable).bottom().pad(10);

    truthTable.add();
    for (int x = 0; x < gatePics.length; x++) {
        truthTable.add(gatePics[x]).size(gatePics[x].getWidth() * 2, gatePics[x].getHeight() * 2).pad(5);
    }
    truthTable.row();
    truthTable.add();
    for (int x = 0; x < gates.length; x++) {
        truthTable.add(gates[x]).pad(5);
    }
    truthTable.row();

    truth = new Label[][] {
            { new Label("false and false", game.assets.skin, Assets.HUD_STYLE),
                    new Label("off", game.assets.skin, Assets.HUD_STYLE),
                    new Label("on", game.assets.skin, Assets.HUD_STYLE),
                    new Label("off", game.assets.skin, Assets.HUD_STYLE),
                    new Label("on", game.assets.skin, Assets.HUD_STYLE),
                    new Label("off", game.assets.skin, Assets.HUD_STYLE) },
            { new Label("true and false", game.assets.skin, Assets.HUD_STYLE),
                    new Label("off", game.assets.skin, Assets.HUD_STYLE),
                    new Label("on", game.assets.skin, Assets.HUD_STYLE),
                    new Label("on", game.assets.skin, Assets.HUD_STYLE),
                    new Label("off", game.assets.skin, Assets.HUD_STYLE),
                    new Label("on", game.assets.skin, Assets.HUD_STYLE) },
            { new Label("true and true", game.assets.skin, Assets.HUD_STYLE),
                    new Label("on", game.assets.skin, Assets.HUD_STYLE),
                    new Label("off", game.assets.skin, Assets.HUD_STYLE),
                    new Label("on", game.assets.skin, Assets.HUD_STYLE),
                    new Label("off", game.assets.skin, Assets.HUD_STYLE),
                    new Label("off", game.assets.skin, Assets.HUD_STYLE) } };

    for (int x = 0; x < truth.length; x++) {
        for (int y = 0; y < truth[x].length; y++) {
            truthTable.add(truth[x][y]).pad(5);
        }
        truthTable.row();
    }
}

From source file:ca.hiphiparray.amazingmaze.HighScoresScreen.java

License:Open Source License

@Override
public void show() {
    Gdx.input.setInputProcessor(stage);//from w w  w  . ja  va  2s  .  c o  m
    game.music.setSong(Song.MENU);
    stage.clear();

    table = new Table();
    table.setFillParent(true);
    table.top();
    stage.addActor(table);

    Label header = new Label("High Scores", game.assets.skin, Assets.SANS_HEADER_STYLE);
    table.add(header).pad(Gdx.graphics.getHeight() / 20).colspan(3);
    table.row();

    HighScore[] scores = game.save.getHighScores();
    for (int i = 0; i < scores.length; i++) {
        Label position = new Label(Integer.toString(i + 1) + ". ", game.assets.skin);
        Label name = new Label(scores[i].getName(), game.assets.skin);
        Label score = new Label(Integer.toString(scores[i].getScore()), game.assets.skin);
        if (scores[i].getScore() < 0) {
            score.setText("");
        }

        table.add(position).padBottom(Gdx.graphics.getHeight() / 50);
        table.add(name).left().padBottom(Gdx.graphics.getHeight() / 50).padRight(Gdx.graphics.getWidth() / 32);
        table.add(score).padBottom(Gdx.graphics.getHeight() / 50).right();
        table.row();
    }

    final TextButton resetButton = new TextButton("Reset High Scores", game.assets.skin);
    resetButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (resetButton.isPressed()) {
                game.save.resetScores();
                game.setScreen(game.highScoresScreen);
            }
        }
    });
    table.add(resetButton).colspan(3);
    table.row();

    final TextButton menuButton = new TextButton("Main Menu", game.assets.skin);
    menuButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (menuButton.isPressed()) {
                game.setScreen(game.menuScreen);
            }
        }
    });
    table.add(menuButton).colspan(3).pad(10);
}

From source file:ca.hiphiparray.amazingmaze.MazeScreen.java

License:Open Source License

/** Create the game HUD. */
private void setupHUD() {
    hud = new Stage(new ScreenViewport(), game.batch);

    Table table = new Table();
    table.setFillParent(true);//from   w ww .j a  va 2  s  . c om
    table.top().left();
    hud.addActor(table);

    Label level = new Label("Level " + game.save.getLevel(), game.assets.skin, Assets.HUD_STYLE);
    table.add(level).colspan(2);
    table.row();

    Image lifeIcon = new Image(game.assets.manager.get(Assets.LIFE_HUD_IMAGE, Texture.class));
    table.add(lifeIcon).pad(Gdx.graphics.getWidth() / 128).left();

    livesLeft = new Label("", game.assets.skin, Assets.HUD_STYLE);
    table.add(livesLeft);

    updateLives(-2);
}

From source file:ca.hiphiparray.amazingmaze.SettingsScreen.java

License:Open Source License

/**
 * Create a new SettingsScreen.//from w w w .  j  a  va2  s.c  o m
 *
 * @param game Instance of AmazingMazeGame to be used
 */
public SettingsScreen(final AmazingMazeGame game) {
    this.game = game;
    this.sourceScreen = game.menuScreen;
    settings = new Stage(new ScreenViewport(), this.game.batch);
    multiplexer = new InputMultiplexer();
    multiplexer.addProcessor(settings);
    multiplexer.addProcessor(this);
    table = new Table();
    table.top();
    table.setFillParent(true);
    controlsTable = new Table();

    settings.addActor(table);

    Skin skin = game.assets.skin;

    screenHeader = new Label("Settings", game.assets.skin, Assets.SANS_HEADER_STYLE);

    musicSlider = new Slider(0, 1, 0.1f, false, game.assets.skin);
    musicSlider.setValue(game.save.getMusicLevel());
    musicSlider.setAnimateDuration(0.25f);

    musicSlider.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            game.music.setVolume(musicSlider.getValue());
            game.save.setMusicLevel(game.music.getVolume());
        }
    });
    musicSliderLabel = new Label("Music Volume", game.assets.skin);

    controlsHeader = new Label("Controls", game.assets.skin);

    actions = new Label[] { new Label("Up", game.assets.skin), new Label("Down", game.assets.skin),
            new Label("Left", game.assets.skin), new Label("Right", game.assets.skin),
            new Label("Pause", game.assets.skin) };

    actionControls = new TextButton[] { new TextButton(Keys.toString(game.save.getUpButton()), skin),
            new TextButton(Keys.toString(game.save.getDownButton()), skin),
            new TextButton(Keys.toString(game.save.getLeftButton()), skin),
            new TextButton(Keys.toString(game.save.getRightButton()), skin),
            new TextButton(Keys.toString(game.save.getPauseButton()), skin) };

    actionControls[0].addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (actionControls[0].isPressed()) {
                updateControls(0);
            }
        }

    });

    actionControls[1].addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (actionControls[1].isPressed()) {
                updateControls(1);
            }
        }

    });

    actionControls[2].addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (actionControls[2].isPressed()) {
                updateControls(2);
            }
        }

    });

    actionControls[3].addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (actionControls[3].isPressed()) {
                updateControls(3);
            }
        }

    });

    actionControls[4].addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (actionControls[4].isPressed()) {
                updateControls(4);
            }
        }
    });

    // Reset settings button
    resetSettingsButton = new TextButton("Reset Settings", skin);
    resetSettingsButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (resetSettingsButton.isPressed()) {
                game.save.resetSettings();
                musicSlider.setValue(game.save.getMusicLevel());
                resetActionControlsLabels();
            }
        }
    });

    // Reset save button.
    resetSaveButton = new TextButton("Reset Save", skin);
    resetSaveButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (resetSaveButton.isPressed()) {
                game.save.resetSave();
            }
        }
    });

    backButton = new TextButton("Back", skin);

}

From source file:ca.hiphiparray.amazingmaze.StoryScreen.java

License:Open Source License

/** Helper method to setup the UI. */
private void setupUI() {
    stage = new Stage(new ScreenViewport(), game.batch);

    table = new Table();
    table.top().center();/* w  w  w . j  a v  a  2s. c  o  m*/
    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();
}

From source file:com.agateau.pixelwheels.racescreen.HudContent.java

License:Open Source License

public HudContent(Assets assets, GameWorld gameWorld, Hud hud) {
    mAssets = assets;//  w  ww  . j  a va2s  .  co  m
    mGameWorld = gameWorld;
    mHud = hud;
    Skin skin = assets.ui.skin;

    AnchorGroup root = hud.getRoot();

    createPlayerLabels(root);

    mCountDownLabel = new Label("", skin, "hudCountDown");
    mCountDownLabel.setAlignment(Align.bottom);

    root.addPositionRule(mCountDownLabel, Anchor.BOTTOM_CENTER, root, Anchor.CENTER);
}