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

The following examples show how to use com.badlogic.gdx.scenes.scene2d.ui.Label#setColor() . 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
Source File: ShopCard.java    From Klooni1010 with GNU General Public License v3.0 6 votes vote down vote up
ShopCard(final Klooni game, final GameLayout layout,
         final String itemName, final Color backgroundColor) {
    this.game = game;
    Label.LabelStyle labelStyle = new Label.LabelStyle();
    labelStyle.font = game.skin.getFont("font_small");

    priceLabel = new Label("", labelStyle);
    nameLabel = new Label(itemName, labelStyle);

    Color labelColor = Theme.shouldUseWhite(backgroundColor) ? Color.WHITE : Color.BLACK;
    priceLabel.setColor(labelColor);
    nameLabel.setColor(labelColor);

    priceBounds = new Rectangle();
    nameBounds = new Rectangle();

    layout.update(this);
}
 
Example 2
Source File: ShareScoreScreen.java    From Klooni1010 with GNU General Public License v3.0 6 votes vote down vote up
ShareScoreScreen(final Klooni game, final Screen lastScreen,
                 final int score, final boolean timeMode) {
    this.game = game;
    this.lastScreen = lastScreen;

    this.score = score;
    this.timeMode = timeMode;

    final Label.LabelStyle labelStyle = new Label.LabelStyle();
    labelStyle.font = game.skin.getFont("font_small");

    infoLabel = new Label("Generating image...", labelStyle);
    infoLabel.setColor(Klooni.theme.textColor);
    infoLabel.setAlignment(Align.center);
    infoLabel.layout();
    infoLabel.setPosition(
            (Gdx.graphics.getWidth() - infoLabel.getWidth()) * 0.5f,
            (Gdx.graphics.getHeight() - infoLabel.getHeight()) * 0.5f);

    spriteBatch = new SpriteBatch();
}
 
Example 3
Source File: MessageTestBase.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
protected void addSeparator (Table table) {
	Label lbl = new Label("", container.skin);
	lbl.setColor(0.75f, 0.75f, 0.75f, 1);
	lbl.setStyle(new LabelStyle(lbl.getStyle()));
	lbl.getStyle().background = container.skin.newDrawable("white");
	table.add(lbl).colspan(2).height(1).width(220).pad(5, 1, 5, 1);
}
 
Example 4
Source File: SteeringTestBase.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
protected void addSeparator (Table table) {
	Label lbl = new Label("", container.skin);
	lbl.setColor(0.75f, 0.75f, 0.75f, 1);
	lbl.setStyle(new LabelStyle(lbl.getStyle()));
	lbl.getStyle().background = container.skin.newDrawable("white");
	table.add(lbl).colspan(2).height(1).width(220).pad(5, 1, 5, 1);
}
 
Example 5
Source File: PathFinderTestBase.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
protected void addSeparator (Table table) {
	Label lbl = new Label("", container.skin);
	lbl.setColor(0.75f, 0.75f, 0.75f, 1);
	lbl.setStyle(new LabelStyle(lbl.getStyle()));
	lbl.getStyle().background = container.skin.newDrawable("white");
	table.add(lbl).colspan(2).height(1).width(220).pad(5, 1, 5, 1);
}
 
Example 6
Source File: CardViewSmall.java    From Cardshifter with Apache License 2.0 5 votes vote down vote up
@Override
public void set(Object key, Object value) {
    if ("HEALTH".equals(key)) {
        Integer health = (Integer) value;
        Integer oldHealth = (Integer) properties.get(key);
        int diff = health - oldHealth;
        WidgetGroup grp = (WidgetGroup) table.getParent();
        grp.layout();
        
        if (diff != 0) {
            Vector2 pos = new Vector2(table.getWidth() / 2, table.getHeight() / 2);
            table.localToStageCoordinates(pos);
            final Label changeLabel = new Label(String.valueOf(diff), context.getSkin());
            Gdx.app.log("Anim", "Create health animation at " + pos.x + ", " + pos.y);
            changeLabel.setPosition(pos.x, pos.y);
            if (diff > 0) {
            	changeLabel.setColor(Color.GREEN);
            } else {
            	changeLabel.setColor(Color.RED);
            }
            changeLabel.addAction(Actions.sequence(Actions.moveBy(0, this.screenHeight/8, 1.5f), Actions.run(new Runnable() {
                @Override
                public void run() {
                    changeLabel.remove();
                }
            })));
            context.getStage().addActor(changeLabel);
        }
    }
    properties.put((String) key, value);
    cost.update(properties);
    stats.update(properties);
}
 
Example 7
Source File: ShareChallenge.java    From Klooni1010 with GNU General Public License v3.0 4 votes vote down vote up
public boolean saveChallengeImage(final int score, final boolean timeMode) {
    final File saveAt = getShareImageFilePath();
    if (!saveAt.getParentFile().isDirectory())
        if (!saveAt.mkdirs())
            return false;

    final FileHandle output = new FileHandle(saveAt);

    final Texture shareBase = new Texture(Gdx.files.internal("share.png"));
    final int width = shareBase.getWidth();
    final int height = shareBase.getHeight();

    final FrameBuffer frameBuffer = new FrameBuffer(Pixmap.Format.RGB888, width, height, false);
    frameBuffer.begin();

    // Render the base share texture
    final SpriteBatch batch = new SpriteBatch();
    final Matrix4 matrix = new Matrix4();
    matrix.setToOrtho2D(0, 0, width, height);
    batch.setProjectionMatrix(matrix);

    Gdx.gl.glClearColor(Color.GOLD.r, Color.GOLD.g, Color.GOLD.b, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    batch.begin();
    batch.draw(shareBase, 0, 0);

    // Render the achieved score
    final Label.LabelStyle style = new Label.LabelStyle();
    style.font = new BitmapFont(Gdx.files.internal("font/x1.0/geosans-light64.fnt"));
    Label label = new Label("just scored " + score + " on", style);
    label.setColor(Color.BLACK);
    label.setPosition(40, 500);
    label.draw(batch, 1);

    label.setText("try to beat me if you can");
    label.setPosition(40, 40);
    label.draw(batch, 1);

    if (timeMode) {
        Texture timeModeTexture = new Texture("ui/x1.5/stopwatch.png");
        batch.setColor(Color.BLACK);
        batch.draw(timeModeTexture, 200, 340);
    }

    batch.end();

    // Get the framebuffer pixels and write them to a local file
    final byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, width, height, true);

    final Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);

    BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
    PixmapIO.writePNG(output, pixmap);

    // Dispose everything
    pixmap.dispose();
    shareBase.dispose();
    batch.dispose();
    frameBuffer.end();

    return true;
}
 
Example 8
Source File: DefaultSceneScreen.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
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()))));
}