From 337594e83a74c432c140b3df3287575b81bce467 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Thu, 30 May 2024 18:26:10 +0100 Subject: Complete backend rework of the EIG (#2616) * Complete backend rework of the EIG * Mergening Related Updates Also some loader references refactoring * fix (cherry picked from commit 7fd5d7417bddfb6e49ede3986d9a547f15b21289) * More Mergening fixes Updates the declaration of the stem mixin to match the new format. * Inline EIG IC2 bucket constants addresses: https://github.com/GTNewHorizons/GT5-Unofficial/pull/2616#discussion_r1620596497 * Fix Seed Removal in regular seed simulations Should address https://github.com/GTNewHorizons/GT5-Unofficial/pull/2616#discussion_r1620583338 --------- Co-authored-by: Guillaume Mercier <10gui-gui10@live.ca> Co-authored-by: Martin Robertz --- .../kubatech/api/gui/AutoScalingStackSizeText.java | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/main/java/kubatech/api/gui/AutoScalingStackSizeText.java (limited to 'src/main/java/kubatech/api/gui/AutoScalingStackSizeText.java') diff --git a/src/main/java/kubatech/api/gui/AutoScalingStackSizeText.java b/src/main/java/kubatech/api/gui/AutoScalingStackSizeText.java new file mode 100644 index 0000000000..313610de07 --- /dev/null +++ b/src/main/java/kubatech/api/gui/AutoScalingStackSizeText.java @@ -0,0 +1,72 @@ +package kubatech.api.gui; + +import java.util.Collections; + +import com.gtnewhorizons.modularui.api.NumberFormatMUI; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.drawable.TextRenderer; +import com.gtnewhorizons.modularui.api.math.Alignment; +import com.gtnewhorizons.modularui.api.math.Color; +import com.gtnewhorizons.modularui.common.internal.Theme; + +public class AutoScalingStackSizeText implements IDrawable { + + private static final TextRenderer measuringRenderer = new TextRenderer(); + private static final NumberFormatMUI muiNumberFormat = new NumberFormatMUI(); + private static final TextRenderer renderer = new TextRenderer(); + private Alignment alignment = Alignment.Center; + private final String text; + private int simWidth; + + private int color; + private boolean shadow = false; + + public AutoScalingStackSizeText(long stackSize) { + this.text = muiNumberFormat.formatWithSuffix(stackSize); + this.color = Theme.INSTANCE.getText(); + this.measure(); + } + + public AutoScalingStackSizeText color(int color) { + this.color = Color.withAlpha(color, 255); + return this; + } + + public AutoScalingStackSizeText shadow(boolean shadow) { + this.shadow = shadow; + return this; + } + + public AutoScalingStackSizeText shadow() { + return shadow(true); + } + + public AutoScalingStackSizeText alignment(Alignment alignment) { + this.alignment = alignment; + return this; + } + + public AutoScalingStackSizeText measure() { + this.simWidth = measuringRenderer.getMaxWidth(Collections.singletonList(this.text)); + return this; + } + + public boolean hasColor() { + return Color.getAlpha(color) > 0; + } + + @Override + public void applyThemeColor(int color) { + renderer.setColor(hasColor() ? this.color : Theme.INSTANCE.getText()); + } + + @Override + public void draw(float x, float y, float width, float height, float partialTicks) { + renderer.setPos((int) (x - 0.5), (int) (y - 0.5)); + renderer.setShadow(this.shadow); + renderer.setAlignment(alignment, width, height); + renderer.setColor(this.color); + renderer.setScale(this.simWidth <= 16.0f ? 1.0f : 16.0f / this.simWidth); + renderer.draw(this.text); + } +} -- cgit