diff --git a/src/main/java/net/pietru/omni_power/ui/CustomScreen.java b/src/main/java/net/pietru/omni_power/ui/CustomScreen.java index d7e174f..e1bd617 100644 --- a/src/main/java/net/pietru/omni_power/ui/CustomScreen.java +++ b/src/main/java/net/pietru/omni_power/ui/CustomScreen.java @@ -137,8 +137,7 @@ public class CustomScreen extends BaseItemScreen { .height(data.getFloat("height",10F)); }); components.put("label",(table,screen,data)->{ - Label lbl = new Label(data.getString("text",""),skin); - lbl.setFontScale(data.getFloat("font_scale",1F)); + LabelWidget lbl = new LabelWidget(data.getString("text","")); table.add(lbl); }); components.put("change_ui_text_button",(table,screen,data)->{ diff --git a/src/main/java/net/pietru/omni_power/ui/LabelWidget.java b/src/main/java/net/pietru/omni_power/ui/LabelWidget.java new file mode 100644 index 0000000..04e7211 --- /dev/null +++ b/src/main/java/net/pietru/omni_power/ui/LabelWidget.java @@ -0,0 +1,55 @@ +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; + + public LabelWidget(String text) { + this.textDim = new Vector2(); + this.text = text; + this.setWidth(text.length()*4); + } + + public void setText(String text) { + this.text = text; + this.setWidth(text.length()*4); + } + + public String getText() { + return text; + } + + public void draw(Batch batch, float parentAlpha){ + super.draw(batch,parentAlpha); + batch.setColor(Color.WHITE); + drawLabelTextWithDropShadow(batch,0,0,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, -2.0F); + batch.setColor(oldR, oldG, oldB, oldA); + this.drawLabelText(batch, 0.0F, 0.0F); + } + + 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); + } +}