List of usage examples for com.badlogic.gdx.scenes.scene2d.ui Label getPrefHeight
public float getPrefHeight()
From source file:com.jmolina.orb.widgets.ui.Credit.java
License:Open Source License
/** * Aade un hiperenlace//from ww w. j a va 2 s .com * * @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.jmolina.orb.widgets.ui.Credit.java
License:Open Source License
/** * Devuelve la altura combinada de todos los hiperenlaces, para calcular la altura del widget. *///w w w .j a v a2s . com private float getLinksPrefHeight() { float height = 0f; for (Label link : links) { height += link.getPrefHeight(); } return height; }
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 w w w . j a va 2s . 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 av a 2s .com*/ 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(); } }
From source file:org.ams.testapps.paintandphysics.cardhouse.CardHouseWithGUI.java
License:Open Source License
/** * Creates the label that shows the height of the card house. * Also prepares a {@link Runnable} that keeps the label updated. *//*w w w . j av a2 s .co m*/ private Label createTopLabel() { // create label final Label label = new Label("", skin); label.setStyle(new Label.LabelStyle(label.getStyle())); label.getStyle().fontColor = cardHouseDef.heightLabelColor; // prepare runnable timer.remove(topUpdater); topUpdater = new Runnable() { Vector2 top = new Vector2(); Vector2 interpolatedTop = new Vector2(0, cardHouseDef.groundY); Vector2 screenPos = new Vector2(); long counter = 0; Body highestBody; @Override public void run() { // find the highest body if (counter % 10 == 0) // its not necessary to find the highest body each frame highestBody = cardHouse.getHighestCard(); // find the height of the highest body if (highestBody != null) top = cardHouse.getHeightOfCard(highestBody, top); else top.set(0, cardHouseDef.groundY); // update the position of the label interpolatedTop.lerp(top, 0.05f); screenPos = CoordinateHelper.getScreenCoordinates(cardHouse.getCamera(), interpolatedTop.x, interpolatedTop.y, screenPos); Vector2 stagePos = stage.screenToStageCoordinates(screenPos); label.setPosition(stagePos.x, stage.getHeight() - stagePos.y + label.getPrefHeight()); // update the text of the label if (counter++ % 10 == 0) { // its not necessary to update the text each frame if (top.y == cardHouseDef.groundY) { label.setText(""); } else { // get height and convert to specified unit float height = top.y - cardHouseDef.groundY; height = height / cardHouseDef.cardHeight; int unit = cardHouseDef.unit; height *= cardHouseDef.houseHeightUnitMultipliers[unit]; int decimalCount = cardHouseDef.decimals[unit]; float n = 1 / (float) (Math.pow(10, decimalCount)); height = Util.roundToNearestN(height, n); // prepare text String decimals = Util.getDecimals(height, decimalCount); int integer = (int) height; String text = integer + "." + decimals; text += cardHouseDef.houseHeightUnits[unit]; label.setText(text); } } } }; timer.runOnRender(topUpdater); return label; }