Java Code Examples for com.badlogic.gdx.scenes.scene2d.ui.Label#setSize()

The following examples show how to use com.badlogic.gdx.scenes.scene2d.ui.Label#setSize() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override public IFuture<Void> visualize(DroppedItem drop) {
    final Future<Void> future = new Future<Void>();

    Group group = new Group();
    Tile image = new Tile("item/" + drop.item.name);
    Label counter = new Label(String.valueOf(drop.count), Config.skin);
    counter.setSize(image.getWidth(), image.getHeight());
    counter.setAlignment(Align.right | Align.bottom);
    group.addActor(image);
    group.addActor(counter);
    group.setTransform(false);
    visualizer.viewController.notificationLayer.addActor(group);
    group.setPosition(drop.target.getX() * ViewController.CELL_SIZE, drop.target.getY() * ViewController.CELL_SIZE);
    group.addAction(Actions.parallel(
        Actions.moveBy(0, 30, 1f, Interpolation.fade),
        Actions.alpha(0, 1f, Interpolation.fade),
        Actions.delay(0.4f, Actions.run(new Runnable() {
            @Override public void run() {
                future.happen();
            }
        }))
    ));
    return future;
}
 
Example 2
Source Project: Unlucky   File: MenuScreen.java    License: MIT License 5 votes vote down vote up
public MenuScreen(final Unlucky game, final ResourceManager rm) {
    super(game, rm);

    menuStyle = new Label.LabelStyle(rm.pixel10, new Color(79 / 255.f, 79 / 255.f, 117 / 255.f, 1));

    // one for each letter
    titleMoves = new Moving[7];
    letters = new Image[7];
    for (int i = 0; i < 7; i++) {
        titleMoves[i] = new Moving(new Vector2(), new Vector2(), 0);
        letters[i] = new Image(rm.title[i]);
        stage.addActor(letters[i]);
    }

    handlePlayButton();
    handleOptionButtons();

    battleLabel = new Label("Battle", menuStyle);
    battleLabel.setSize(80, 40);
    battleLabel.setFontScale(1.5f);
    battleLabel.setTouchable(Touchable.disabled);
    battleLabel.setAlignment(Align.center);
    battleLabel.setPosition(60, 35);

    stage.addActor(battleLabel);

    createCreditsScreen();

    // menu music
    rm.menuTheme.setLooping(true);
    rm.menuTheme.play();
}
 
Example 3
Source Project: graphicsfuzz   File: Main.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void create() {

  if(this.overrideLogger != null){
    Gdx.app.setApplicationLogger(overrideLogger);
  }

  // Only DesktopLauncher sets this.
  if(gl30 == null) {
    // Gdx.gl30 could also be null though.
    gl30 = Gdx.gl30;
  }

  Gdx.graphics.getGL20().glEnable(GL20.GL_TEXTURE_2D);
  Gdx.graphics.getGL20().glEnable(GL20.GL_DEPTH_TEST);
  Gdx.graphics.getGL20().glDepthFunc(GL20.GL_LESS);

  standardMesh = buildFullScreenQuadMesh();

  if(standaloneRenderJob != null) {
    if (standaloneRenderJob.isSetComputeSource()) {
      updateState(WorkerState.COMPUTE_STANDALONE_PREPARE);
    } else {
      updateState(WorkerState.IMAGE_STANDALONE_PREPARE);
    }
    return;
  }

  PlatformInfoUtil.getPlatformDetails(platformInfoJson);
  PlatformInfoUtil.getGlVersionInfo(platformInfoJson, gl30);

  sanityReferenceImage = createPixelBuffer();
  sanityCheckImage = createPixelBuffer();
  sanityCheckImageTmp = createPixelBuffer();

  GdxStage = new Stage(new ScreenViewport());
  Label.LabelStyle label1Style = new Label.LabelStyle();
  label1Style.font = new BitmapFont();
  label1Style.fontColor = Color.WHITE;

  DisplayContent = new StringBuilder();
  DisplayLabel = new Label(DisplayContent.toString(), label1Style);
  DisplayLabel.setPosition(WIDTH + DISPLAY_TXT_MARGIN, 0);
  DisplayLabel
      .setSize(Gdx.graphics.getWidth() - WIDTH - DISPLAY_TXT_MARGIN - 10, Gdx.graphics.getHeight() - 10);
  DisplayLabel.setAlignment(Align.topLeft);
  DisplayContent = new StringBuilder();
  GdxStage.addActor(DisplayLabel);
}
 
Example 4
Source Project: Unlucky   File: BattleScene.java    License: MIT License 4 votes vote down vote up
public BattleScene(GameScreen gameScreen, TileMap tileMap, Player player, Battle battle,
                   BattleUIHandler uiHandler, Stage stage, ResourceManager rm) {
    super(gameScreen, tileMap, player, battle, uiHandler, rm);

    this.stage = stage;

    BitmapFont font = rm.pixel10;
    Label.LabelStyle ls = new Label.LabelStyle(font, new Color(255, 255, 255, 255));

    weakest = new Label.LabelStyle(font, new Color(200 / 255.f, 200 / 255.f, 200 / 255.f, 1));
    weaker = new Label.LabelStyle(font, new Color(0, 225 / 255.f, 0, 1));
    same = new Label.LabelStyle(font, new Color(1, 1, 1, 1));
    stronger = new Label.LabelStyle(font, new Color(1, 175 / 255.f, 0, 1));
    strongest = new Label.LabelStyle(font, new Color(225 / 255.f, 0, 0, 1));

    // create player hud
    playerHud = new MovingImageUI(rm.playerhpbar145x40, new Vector2(-72, 100), new Vector2(0, 100), 100.f, 72, 20);
    playerHpBar = new HealthBar(player, stage, shapeRenderer, 48, 4, new Vector2(), new Color(0, 225 / 255.f, 0, 1));
    playerHudLabel = new Label("", ls);
    playerHudLabel.setFontScale(0.5f);
    playerHudLabel.setSize(49, 6);
    playerHudLabel.setTouchable(Touchable.disabled);

    // create enemy hud
    enemyHud = new MovingImageUI(rm.enemyhpbar145x40, new Vector2(200, 100), new Vector2(128, 100), 100.f, 72, 20);
    enemyHpBar = new HealthBar(null, stage, shapeRenderer, 48, 4, new Vector2(), new Color(225 / 255.f, 0, 0, 1));
    enemyHudLabel = new Label("", ls);
    enemyHudLabel.setFontScale(0.5f);
    enemyHudLabel.setSize(49, 6);
    enemyHudLabel.setTouchable(Touchable.disabled);

    // create player sprite
    playerSprite = new Moving(PLAYER_ORIGIN, new Vector2(35, 50), 75.f);
    // create enemy sprite
    enemySprite = new Moving(ENEMY_ORIGIN, new Vector2(120, 50), 75.f);

    // create animations
    attackAnims = new AnimationManager[3];
    for (int i = 0; i < 3; i++) {
        attackAnims[i] = new AnimationManager(rm.battleAttacks64x64, 3, i, 1 / 6f);
    }
    healAnim = new AnimationManager(rm.battleHeal96x96, 3, 0, 1 / 5f);

    factory = new ParticleFactory((OrthographicCamera) stage.getCamera(), rm);

    stage.addActor(playerHud);
    stage.addActor(playerHudLabel);
    stage.addActor(enemyHud);
    stage.addActor(enemyHudLabel);
}
 
Example 5
Source Project: Unlucky   File: BattleEventHandler.java    License: MIT License 4 votes vote down vote up
public BattleEventHandler(GameScreen gameScreen, TileMap tileMap, Player player, Battle battle,
                          BattleUIHandler uiHandler, Stage stage, final ResourceManager rm) {
    super(gameScreen, tileMap, player, battle, uiHandler, rm);

    this.stage = stage;

    // create main UI
    ui = new Image(rm.dialogBox400x80);
    ui.setSize(200, 40);
    ui.setPosition(0, 0);
    ui.setTouchable(Touchable.disabled);

    stage.addActor(ui);

    // create Labels
    BitmapFont bitmapFont = rm.pixel10;
    Label.LabelStyle font = new Label.LabelStyle(bitmapFont, new Color(0, 0, 0, 255));

    textLabel = new Label("", font);
    textLabel.setWrap(true);
    textLabel.setTouchable(Touchable.disabled);
    textLabel.setFontScale(1.7f / 2);
    textLabel.setPosition(8, 6);
    textLabel.setSize(175, 26);
    textLabel.setAlignment(Align.topLeft);
    stage.addActor(textLabel);

    clickLabel = new Label("", font);
    clickLabel.setSize(200, 120);
    clickLabel.setPosition(0, 0);

    final Player p = player;
    clickLabel.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (dialogIndex + 1 == currentDialog.length && endCycle) {
                if (!p.settings.muteSfx) rm.textprogression.play(p.settings.sfxVolume);
                // the text animation has run through every element of the text array
                endDialog();
                handleBattleEvent(nextEvent);
            }
            // after a cycle of text animation ends, clicking the UI goes to the next cycle
            else if (endCycle && dialogIndex < currentDialog.length) {
                if (!p.settings.muteSfx) rm.textprogression.play(p.settings.sfxVolume);
                dialogIndex++;
                reset();
                currentText = currentDialog[dialogIndex];
                anim = currentText.split("");
                beginCycle = true;
            }
            // clicking on the box during a text animation completes it early
            else if (beginCycle && !endCycle) {
                resultingText = currentText;
                textLabel.setText(resultingText);
                beginCycle = false;
                endCycle = true;
            }
        }
    });
    stage.addActor(clickLabel);
}
 
Example 6
Source Project: Unlucky   File: LevelUpScreen.java    License: MIT License 4 votes vote down vote up
public LevelUpScreen(GameScreen gameScreen, TileMap tileMap, Player player, ResourceManager rm) {
    super(gameScreen, tileMap, player, rm);

    // create bg
    ImageButton.ImageButtonStyle style = new ImageButton.ImageButtonStyle();
    style.imageUp = new TextureRegionDrawable(rm.levelupscreen400x240);
    ui = new ImageButton(style);
    ui.setSize(200, 120);
    ui.setPosition(0, 0);
    ui.setTouchable(Touchable.disabled);
    stage.addActor(ui);

    handleClick();

    // create animation
    levelUpAnim = new AnimationManager(rm.levelUp96x96, 4, 0, 1 / 4f);

    // create labels
    BitmapFont font = rm.pixel10;
    Label.LabelStyle titleFont = new Label.LabelStyle(font, new Color(0, 205 / 255.f, 20 / 255.f, 1));
    Label.LabelStyle stdWhite = new Label.LabelStyle(font, new Color(1, 1, 1, 1));
    Label.LabelStyle yellow = new Label.LabelStyle(font, new Color(1, 212 / 255.f, 0, 1));
    Label.LabelStyle blue = new Label.LabelStyle(font, new Color(0, 190 / 255.f, 1, 1));

    title = new Label("LEVEL UP!", titleFont);
    title.setSize(200, 20);
    title.setPosition(0, 95);
    title.setFontScale(2.5f);
    title.setAlignment(Align.center);
    title.setTouchable(Touchable.disabled);
    stage.addActor(title);

    levelDesc = new Label("You reached level 1", stdWhite);
    levelDesc.setSize(200, 20);
    levelDesc.setPosition(0, 80);
    levelDesc.setAlignment(Align.center);
    levelDesc.setTouchable(Touchable.disabled);
    stage.addActor(levelDesc);

    statsDescs = new Label[statNames.length];
    stats = new Label[statNames.length];
    increases = new Label[statNames.length];

    for (int i = 0; i < statNames.length; i++) {
        statsDescs[i] = new Label(statNames[i], stdWhite);
        statsDescs[i].setSize(10, 10);
        statsDescs[i].setFontScale(1.3f / 2);
        statsDescs[i].setPosition(100, 17 + (i * 12));
        statsDescs[i].setAlignment(Align.left);
        statsDescs[i].setTouchable(Touchable.disabled);
        stage.addActor(statsDescs[i]);

        stats[i] = new Label("1330", blue);
        stats[i].setSize(10, 10);
        stats[i].setFontScale(1.3f / 2);
        stats[i].setPosition(140, 17 + (i * 12));
        stats[i].setAlignment(Align.left);
        stats[i].setTouchable(Touchable.disabled);
        stage.addActor(stats[i]);

        increases[i] = new Label("+20", yellow);
        increases[i].setSize(10, 10);
        increases[i].setFontScale(1.3f / 2);
        increases[i].setPosition(170, 17 + (i * 12));
        increases[i].setAlignment(Align.left);
        increases[i].setTouchable(Touchable.disabled);
        stage.addActor(increases[i]);
    }

    clickToContinue = new Label("Click to continue", stdWhite);
    clickToContinue.setSize(200, 10);
    clickToContinue.setFontScale(0.5f);
    clickToContinue.setPosition(0, 2);
    clickToContinue.setAlignment(Align.center);
    clickToContinue.setTouchable(Touchable.disabled);
    stage.addActor(clickToContinue);
}
 
Example 7
Source Project: Unlucky   File: DialogScreen.java    License: MIT License 4 votes vote down vote up
public DialogScreen(GameScreen gameScreen, TileMap tileMap, Player player, final ResourceManager rm) {
    super(gameScreen, tileMap, player, rm);

    // create main UI
    ui = new Image(rm.dialogBox400x80);
    ui.setSize(200, 40);
    ui.setPosition(0, 0);
    ui.setTouchable(Touchable.disabled);

    stage.addActor(ui);

    // create Labels
    BitmapFont bitmapFont = rm.pixel10;
    Label.LabelStyle font = new Label.LabelStyle(bitmapFont, new Color(0, 0, 0, 255));

    textLabel = new Label("", font);
    textLabel.setWrap(true);
    textLabel.setTouchable(Touchable.disabled);
    textLabel.setFontScale(1.7f / 2);
    textLabel.setPosition(8, 6);
    textLabel.setSize(350 / 2, 52 / 2);
    textLabel.setAlignment(Align.topLeft);
    stage.addActor(textLabel);

    clickLabel = new Label("", font);
    clickLabel.setSize(200, 120);
    clickLabel.setPosition(0, 0);

    final Player p = player;
    clickLabel.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (dialogIndex + 1 == currentDialog.length && endCycle) {
                if (!p.settings.muteSfx) rm.textprogression.play(p.settings.sfxVolume);
                // the text animation has run through every element of the text array
                endDialog();
                handleEvent(nextEvent);
            }
            // after a cycle of text animation ends, clicking the UI goes to the next cycle
            else if (endCycle && dialogIndex < currentDialog.length) {
                if (!p.settings.muteSfx) rm.textprogression.play(p.settings.sfxVolume);
                dialogIndex++;
                reset();
                currentText = currentDialog[dialogIndex];
                anim = currentText.split("");
                beginCycle = true;
            }
            // clicking on the box during a text animation completes it early
            else if (beginCycle && !endCycle) {
                resultingText = currentText;
                textLabel.setText(resultingText);
                beginCycle = false;
                endCycle = true;
            }
        }
    });
    stage.addActor(clickLabel);
}
 
Example 8
Source Project: Unlucky   File: SettingsScreen.java    License: MIT License 4 votes vote down vote up
public SettingsScreen(final Unlucky game, final ResourceManager rm) {
    super(game, rm);

    // exit button
    stage.addActor(exitButton);
    exitButton.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            if (!game.player.settings.muteSfx) rm.buttonclick0.play(game.player.settings.sfxVolume);
            if (inGame) {
                game.gameScreen.resetGame = false;
                setFadeScreen(game.gameScreen);
                game.gameScreen.hud.settingsDialog.show(game.gameScreen.hud.getStage());
            }
            else {
                game.menuScreen.transitionIn = 2;
                setSlideScreen(game.menuScreen, false);
            }
        }
    });

    // create title label
    banner = new Image(rm.skin, "default-slider");
    banner.setPosition(8, 102);
    banner.setSize(164, 12);
    stage.addActor(banner);

    bannerLabel = new Label("SETTINGS", rm.skin);
    bannerLabel.setStyle(new Label.LabelStyle(rm.pixel10, new Color(1, 212 / 255.f, 0, 1)));
    bannerLabel.setSize(50, 12);
    bannerLabel.setTouchable(Touchable.disabled);
    bannerLabel.setPosition(14, 102);
    bannerLabel.setAlignment(Align.left);
    stage.addActor(bannerLabel);

    bg = new Image(rm.skin, "default-slider");
    bg.setPosition(8, 8);
    bg.setSize(184, 88);
    stage.addActor(bg);

    white = new Label.LabelStyle(rm.pixel10, Color.WHITE);
    description = new Label("SOUND                                 MISC",
        new Label.LabelStyle(rm.pixel10, new Color(1, 212 / 255.f, 0, 1)));
    description.setFontScale(0.75f);
    description.setTouchable(Touchable.disabled);
    description.setPosition(14, 85);
    stage.addActor(description);

    // create settings labels
    settingLabels = new Label[7];
    String[] settingStrs = new String[] {
        "MUSIC VOLUME", "SFX VOLUME", "MUTE MUSIC:", "MUTE SFX:",
        "SHOW ENEMY LEVELS:", "WEATHER ANIMATIONS:", "SHOW FPS:"
    };
    for (int i = 0; i < 7; i++) {
        settingLabels[i] = new Label(settingStrs[i], white);
        settingLabels[i].setTouchable(Touchable.disabled);
        settingLabels[i].setFontScale(0.5f);
        stage.addActor(settingLabels[i]);
    }
    for (int i = 0; i < 2; i++) settingLabels[i].setPosition(14, 76 - i * 24);
    for (int i = 2; i < 4; i++) settingLabels[i].setPosition(14, 26 - (i - 2) * 14);
    for (int i = 4; i < 7; i++) settingLabels[i].setPosition(111, 72 - (i - 4) * 16);

    createSliders();
    createCheckboxes();
}
 
Example 9
void showUIText(Text t) {
	// Type UI texts will show at the same time that TextManagerUI texts.

	String style = t.style == null ? "ui-text" : t.style;
	Label msg = new Label(t.str, getUI().getSkin(), style);

	msg.setWrap(true);
	msg.setAlignment(Align.center, Align.center);

	if (t.color != null)
		msg.setColor(t.color);

	msg.setSize(msg.getWidth() + DPIUtils.getMarginSize() * 2, msg.getHeight() + DPIUtils.getMarginSize() * 2);

	stage.addActor(msg);
	unprojectTmp.set(t.x, t.y, 0);
	getWorld().getSceneCamera().scene2screen(getStage().getViewport(), unprojectTmp);

	float posx, posy;

	if (t.x == TextManager.POS_CENTER) {
		posx = (getStage().getViewport().getScreenWidth() - msg.getWidth()) / 2;
	} else if (t.x == TextManager.POS_SUBTITLE) {
		posx = DPIUtils.getMarginSize();
	} else {
		posx = unprojectTmp.x;
	}

	if (t.y == TextManager.POS_CENTER) {
		posy = (getStage().getViewport().getScreenHeight() - msg.getHeight()) / 2;
	} else if (t.y == TextManager.POS_SUBTITLE) {
		posy = getStage().getViewport().getScreenHeight() - msg.getHeight() - DPIUtils.getMarginSize() * 3;
	} else {
		posy = unprojectTmp.y;
	}

	msg.setPosition(posx, posy);
	msg.getColor().a = 0;
	msg.addAction(sequence(Actions.fadeIn(0.4f, Interpolation.fade),
			Actions.delay(t.time, sequence(fadeOut(0.4f, Interpolation.fade), Actions.removeActor()))));
}