package net.pietru.omni_power.ui;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.Widget;
import com.badlogic.gdx.utils.viewport.Viewport;
import finalforeach.cosmicreach.ui.FontRenderer;

public class LabelWidget extends Widget {
    private static final Vector2 tmpVec = new Vector2();
    Vector2 textDim;
    String text;
    float x_off = 0;
    float y_off = -2;

    public LabelWidget(String text, float xoff, float yoff) {
        this.textDim = new Vector2();
        this.text = text;
        this.x_off=xoff;
        this.y_off=yoff;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getText() {
        return text;
    }

    public void draw(Batch batch, float parentAlpha){
        super.draw(batch,parentAlpha);
        this.setWidth(text.length()*10);
        batch.setColor(Color.WHITE);
        drawLabelTextWithDropShadow(batch,x_off,y_off,Color.GRAY);
    }

    public void drawLabelTextWithDropShadow(Batch batch, float xOff, float yOff, Color dropShadowColor) {
        Color batchColor = batch.getColor();
        float oldR = batchColor.r;
        float oldG = batchColor.g;
        float oldB = batchColor.b;
        float oldA = batchColor.a;
        batch.setColor(dropShadowColor);
        this.drawLabelText(batch, 2.0F+xOff, -2.0F+yOff);
        batch.setColor(oldR, oldG, oldB, oldA);
        this.drawLabelText(batch, 0.0F+xOff, 0.0F+yOff);
    }

    public void drawLabelText(Batch batch, float xOff, float yOff) {
        Viewport viewport = this.getStage().getViewport();
        FontRenderer.getTextDimensions(viewport, this.text, this.textDim);
        float x = this.getX();//- this.textDim.x;
        float y = this.getY();
        FontRenderer.drawText(batch, viewport, this.text, x + xOff, y + yOff, true);
    }
}
