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

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

Introduction

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

Prototype

public float getPrefWidth() 

Source Link

Usage

From source file:com.jmolina.orb.widgets.ui.Credit.java

License:Open Source License

/**
 * Aade un hiperenlace/* w  ww . j  a  va 2  s  .c o  m*/
 *
 * @param text Texto visible
 * @param uri URI del enlace
 */
public void addLink(String text, final String uri) {
    Label.LabelStyle style = new Label.LabelStyle();
    style.fontColor = new Color(Var.COLOR_LILAC_MEDIUM);
    style.font = new BitmapFont(Gdx.files.internal(Font.FONT_ROBOTO_REGULAR_30),
            findRegion(Atlas.FONT_ROBOTO_REGULAR_30));

    int linkIndex = links.size() + 1;
    Label link = new Label("[" + linkIndex + "]: " + text, style);
    link.setTouchable(Touchable.enabled);
    link.setPosition(0f, 0f);
    link.setAlignment(Align.left);
    link.setHeight(link.getPrefHeight());
    link.setWidth(link.getPrefWidth());
    link.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            Gdx.net.openURI(uri);
        }
    });

    links.add(link);
    addActor(link);

    header.setY(body.getPrefHeight() + getLinksPrefHeight() + Utils.cell(1));
    body.setY(getLinksPrefHeight() + Utils.cell(1));

    for (Label previouslink : links) {
        previouslink.setY(previouslink.getY() + link.getPrefHeight());
    }

    setHeight(header.getPrefHeight() + body.getPrefHeight() + getLinksPrefHeight() + Utils.cell(1));
}

From source file:com.vlaaad.dice.game.world.view.visualizers.GiveExpVisualizer.java

License:Open Source License

@Override
public IFuture<Void> visualize(final GiveExpResult result) {
    if (result.exp == 0)
        return Future.completed();
    if (result.creature.initialPlayer != visualizer.viewController.world.viewer) {
        return Future.completed();
    }/*from  ww w. ja va2s  .  com*/
    final Future<Void> future = new Future<Void>();
    final ViewController viewController = visualizer.viewController;
    final WorldObjectView view = viewController.getView(result.creature);
    String text = "+" + result.exp + " exp";
    final ProfessionDescription profession = result.creature.description.profession;
    final int currentExp = result.creature.description.exp + result.creature.gainedExp;
    final Label label = new Label(text, Config.skin, "default", Color.WHITE);
    label.setPosition(view.getX() + view.getWidth() / 2 - label.getPrefWidth() / 2,
            view.getY() + view.getHeight() / 2 - label.getPrefHeight() / 2);
    label.addAction(Actions.sequence(
            Actions.parallel(Actions.alpha(0, 1f), Actions.moveBy(0, ViewController.CELL_SIZE / 2, 1f)),
            Actions.run(new Runnable() {
                @Override
                public void run() {
                    label.remove();
                    if (profession.getLevel(currentExp) == profession.getLevel(currentExp + result.exp)) {
                        future.happen();
                        return;
                    }
                    final AnimatedActor circle = new AnimatedActor(0.1f,
                            Config.skin.getAtlas().findRegions("animation/levelup-circle"));
                    circle.setPosition(view.getX() + view.getWidth() / 2 - circle.getWidth() / 2,
                            view.getY() + view.getHeight() / 2 - circle.getHeight() / 2);
                    viewController.selectionLayer.addActor(circle);
                    circle.addListener(new ChangeListener() {
                        @Override
                        public void changed(ChangeEvent event, Actor actor) {
                            circle.remove();
                            final TileSubView image = new TileSubView("animation/levelup-white-cube", -1);
                            view.addSubView(image);
                            image.getActor().getColor().a = 0;
                            image.getActor().addAction(
                                    Actions.sequence(Actions.alpha(1f, 0.4f), Actions.run(new Runnable() {
                                        @Override
                                        public void run() {
                                            SoundManager.instance.playMusicAsSound("level-up");
                                            view.addAction(Actions.sequence(
                                                    Actions.moveBy(0, 20, 0.3f, Interpolation.exp10Out),
                                                    Actions.run(new Runnable() {
                                                        @Override
                                                        public void run() {
                                                            view.addAction(Actions.sequence(Actions.delay(0.2f),
                                                                    Actions.run(new Runnable() {
                                                                        @Override
                                                                        public void run() {
                                                                            Label levelUp = new Label(
                                                                                    "LEVEL UP!", Config.skin,
                                                                                    "default", Color.WHITE);
                                                                            levelUp.setPosition((result.creature
                                                                                    .getX() + 0.5f)
                                                                                    * ViewController.CELL_SIZE
                                                                                    - levelUp.getWidth() / 2,
                                                                                    (result.creature.getY()
                                                                                            + 0.5f)
                                                                                            * ViewController.CELL_SIZE);
                                                                            viewController.notificationLayer
                                                                                    .addActor(levelUp);
                                                                            levelUp.addAction(Actions.moveBy(0,
                                                                                    45, 1.5f));
                                                                            levelUp.addAction(Actions.sequence(
                                                                                    Actions.alpha(0, 1.5f),
                                                                                    Actions.removeActor()));

                                                                        }
                                                                    })));
                                                        }
                                                    }),
                                                    Actions.moveBy(0, -20, 0.4f,
                                                            new Interpolation.BounceOut(2)),
                                                    Actions.run(new Runnable() {
                                                        @Override
                                                        public void run() {
                                                            image.getActor()
                                                                    .addAction(Actions.sequence(
                                                                            Actions.alpha(0, 0.4f),
                                                                            Actions.run(new Runnable() {
                                                                                @Override
                                                                                public void run() {
                                                                                    image.getActor().remove();
                                                                                    GameWindow<GiveExpResult> window = new LevelUpWindow();
                                                                                    window.addListener(
                                                                                            new WindowListener() {
                                                                                                @Override
                                                                                                protected void hidden(
                                                                                                        WindowEvent event) {
                                                                                                    future.happen();
                                                                                                }
                                                                                            });
                                                                                    window.show(result);
                                                                                }
                                                                            })));
                                                        }
                                                    })));
                                        }
                                    })));
                        }
                    });
                }
            })));
    viewController.notificationLayer.addActor(label);
    return future;
}

From source file:io.piotrjastrzebski.sfg.ui.GameOverDialog.java

License:Open Source License

public GameOverDialog(Assets assets, long lastMax) {
    super(assets.getText(Assets.GAME_OVER), assets.getSkin());
    this.assets = assets;
    this.lastMax = lastMax;
    setMovable(false);//from   w ww.j a  v  a2  s . c  o  m

    final Color toxic = assets.getSkin().getColor("toxic");

    scoreLabel = new Label("", assets.getSkin());
    scoreLabel.setColor(toxic);
    maxLabel = new Label("", assets.getSkin());
    maxLabel.setColor(toxic);
    Label newRecordLabel = new Label(assets.getText(Assets.NEW_RECORD), assets.getSkin(), "toxic");
    newRecordGroup = new Group();

    newRecordGroup.setSize(newRecordLabel.getPrefWidth(), newRecordLabel.getPrefHeight());
    newRecordGroup.setOrigin(newRecordLabel.getPrefWidth() / 2, newRecordLabel.getPrefHeight() / 2);
    newRecordGroup.setTransform(true);
    newRecordGroup.addActor(newRecordLabel);

    final Table scores = new Table();
    scores.add(new Label(assets.getText(Assets.SCORE), assets.getSkin())).padRight(10);
    scores.add(scoreLabel);
    scores.add().expandX();
    scores.add(new Label(assets.getText(Assets.RECORD), assets.getSkin())).padRight(10);
    scores.add(maxLabel);

    final Table content = getContentTable();
    content.add(scores).pad(20, 20, 0, 20).expandX().fillX();
    content.row();

    final Table buttons = getButtonTable();
    buttons.add(createRetryButton()).pad(20);
    if (Gdx.app.getType() == Application.ApplicationType.Android) {
        buttons.row();
        if (!Locator.getSettings().isRated()) {
            rateButton = createRateButton();
            buttons.add(rateButton);
            buttons.row();
        }
        Config.Difficulty difficulty = Locator.getConfig().getDifficulty();
        if (Locator.getActionResolver().hasLeaderboard(difficulty)) {
            buttons.add(createLeaderButton()).pad(0, 20, 20, 20);
            buttons.row();
        }
        buttons.add(createAchievButton()).pad(0, 20, 20, 20);
        buttons.row();
        getPremiumTable = createPremiumButton();
    }
}