package info.u_team.u_team_core.gui.elements;

import com.mojang.blaze3d.matrix.MatrixStack;

import info.u_team.u_team_core.api.gui.IScaleable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.*;

public class ScalableButton extends UButton implements IScaleable {
	
	protected float scale;
	
	public ScalableButton(int x, int y, int width, int height, ITextComponent text, float scale) {
		this(x, y, width, height, text, scale, EMTPY_PRESSABLE);
	}
	
	public ScalableButton(int x, int y, int width, int height, ITextComponent text, float scale, IPressable pessable) {
		this(x, y, width, height, text, scale, pessable, EMPTY_TOOLTIP);
	}
	
	public ScalableButton(int x, int y, int width, int height, ITextComponent text, float scale, ITooltip tooltip) {
		this(x, y, width, height, text, scale, EMTPY_PRESSABLE, tooltip);
	}
	
	public ScalableButton(int x, int y, int width, int height, ITextComponent text, float scale, IPressable pessable, ITooltip tooltip) {
		super(x, y, width, height, text, pessable, tooltip);
		this.scale = scale;
	}
	
	public float getScale() {
		return scale;
	}
	
	public void setScale(float scale) {
		this.scale = scale;
	}
	
	@Override
	protected void renderForeground(MatrixStack matrixStack, Minecraft minecraft, int mouseX, int mouseY, float partialTicks) {
		if (scale == 1) {
			super.renderForeground(matrixStack, minecraft, mouseX, mouseY, partialTicks);
		} else {
			final FontRenderer fontRenderer = minecraft.fontRenderer;
			
			ITextComponent message = getMessage();
			
			if (message != StringTextComponent.EMPTY) {
				final int messageWidth = MathHelper.ceil(scale * fontRenderer.getStringPropertyWidth(message));
				final int ellipsisWidth = MathHelper.ceil(scale * fontRenderer.getStringWidth("..."));
				
				if (messageWidth > width - 6 && messageWidth > ellipsisWidth) {
					message = new StringTextComponent(fontRenderer.func_238417_a_(message, width - 6 - ellipsisWidth).getString() + "...");
				}
				
				final float positionFactor = 1 / scale;
				
				final float xStart = (x + (width / 2) - messageWidth / 2) * positionFactor;
				final float yStart = (y + ((int) (height - 8 * scale)) / 2) * positionFactor;
				
				matrixStack.push();
				matrixStack.scale(scale, scale, 0);
				fontRenderer.func_243246_a(matrixStack, message, xStart, yStart, getCurrentTextColor(matrixStack, mouseX, mouseY, partialTicks).getColorARGB());
				matrixStack.pop();
			}
		}
	}
}

@@ -130,57 +130,57 @@
 gui.
-IScaleable;%0Aimport net.minecraft.client.Minecraft
+*;%0Aimport info.u_team.u_team_core.util.WidgetUtil
 ;%0Aim
@@ -209,24 +209,17 @@
 ent.
-gui.FontRenderer
+Minecraft
 ;%0Aim
@@ -246,57 +246,27 @@
 til.
-math.MathHelper;%0Aimport net.minecraft.util.text.*
+text.ITextComponent
 ;%0A%0Ap
@@ -329,16 +329,32 @@
 caleable
+, IScaleProvider
  %7B%0A%09%0A%09pr
@@ -1254,24 +1254,21 @@
 rride%0A%09p
-rotected
+ublic
  void re
@@ -1380,52 +1380,42 @@
 %7B%0A%09%09
-if (scale == 1) %7B%0A%09%09%09super.renderForeground(
+WidgetUtil.renderScaledText(this, 
 matr
@@ -1470,965 +1470,89 @@
 );%0A%09
-%09%7D else %7B%0A%09%09%09final FontRenderer fontRenderer = minecraft.fontRenderer;%0A%09%09%09%0A%09%09%09ITextComponent message = getMessage();%0A%09%09%09%0A%09%09%09if (message != StringTextComponent.EMPTY) %7B%0A%09%09%09%09final int messageWidth = MathHelper.ceil(scale * fontRenderer.getStringPropertyWidth(message));%0A%09%09%09%09final int ellipsisWidth = MathHelper.ceil(scale * fontRenderer.getStringWidth(%22...%22));%0A%09%09%09%09%0A%09%09%09%09if (messageWidth %3E width - 6 && messageWidth %3E ellipsisWidth) %7B%0A%09%09%09%09%09message = new StringTextComponent(fontRenderer.func_238417_a_(message, width - 6 - ellipsisWidth).getString() + %22...%22);%0A%09%09%09%09%7D%0A%09%09%09%09%0A%09%09%09%09final float positionFactor = 1 / scale;%0A%09%09%09%09%0A%09%09%09%09final float xStart = (x + (width / 2) - messageWidth / 2) * positionFactor;%0A%09%09%09%09final float yStart = (y + ((int) (height - 8 * scale)) / 2) * positionFactor;%0A%09%09%09%09%0A%09%09%09%09matrixStack.push();%0A%09%09%09%09matrixStack.scale(scale, scale, 0);%0A%09%09%09%09fontRenderer.func_243246_a(matrixStack, message, xStart, yStart, getCurrentTextColor(matrixStack,
+%7D%0A%09%0A%09@Override%0A%09public float getCurrentScale(MatrixStack matrixStack, int
  mouseX,
  mou
@@ -1543,32 +1543,36 @@
  int mouseX,
+ int
  mouseY,
  partialTick
@@ -1551,32 +1551,38 @@
 seX, int mouseY,
+ float
  partialTicks).g
@@ -1583,57 +1583,26 @@
 cks)
-.getColorARGB());%0A%09%09%09%09matrixStack.pop();%0A%09%09%09%7D%0A%09%09%7D
+ %7B%0A%09%09return scale;
 %0A%09%7D%0A

Update scalable button