package info.u_team.u_team_core.gui.elements;

import com.mojang.blaze3d.matrix.MatrixStack;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.*;
import net.minecraftforge.fml.client.gui.GuiUtils;

/**
 * A button that fixes vanilla not drawing the continuous border if the button is smaller than 20.
 * 
 * @author HyCraftHD
 */
public class UButton extends Button {
	
	protected static IPressable EMTPY_PRESSABLE = button -> {
	};
	
	protected static ITooltip EMPTY_TOOLTIP = field_238486_s_;
	
	public UButton(int x, int y, int width, int height, ITextComponent display) {
		this(x, y, width, height, display, EMTPY_PRESSABLE);
	}
	
	public UButton(int x, int y, int width, int height, ITextComponent display, IPressable pessable) {
		this(x, y, width, height, display, pessable, EMPTY_TOOLTIP);
	}
	
	public UButton(int x, int y, int width, int height, ITextComponent display, ITooltip tooltip) {
		this(x, y, width, height, display, EMTPY_PRESSABLE, tooltip);
	}
	
	public UButton(int x, int y, int width, int height, ITextComponent display, IPressable pessable, ITooltip tooltip) {
		super(x, y, width, height, display, pessable);
	}
	
	public void setPressable(IPressable pressable) {
		onPress = pressable;
	}
	
	public void setPressable(Runnable runnable) {
		onPress = button -> runnable.run();
	}
	
	public void setTooltip(ITooltip tooltip) {
		onTooltip = tooltip;
	}
	
	@Override
	public void renderButton(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
		final Minecraft minecraft = Minecraft.getInstance();
		final FontRenderer fontRenderer = minecraft.fontRenderer;
		
		ITextComponent message = getMessage();
		
		GuiUtils.drawContinuousTexturedBox(matrixStack, WIDGETS_LOCATION, x, y, 0, 46 + getYImage(isHovered()) * 20, width, height, 200, 20, 2, 3, 2, 2, 0);
		renderBg(matrixStack, minecraft, mouseX, mouseY);
		
		final int messageWidth = fontRenderer.getStringPropertyWidth(message);
		final int ellipsisWidth = fontRenderer.getStringWidth("...");
		
		if (messageWidth > width - 6 && messageWidth > ellipsisWidth) {
			message = new StringTextComponent(fontRenderer.func_238417_a_(message, width - 6 - ellipsisWidth).getString() + "...");
		}
		
		final float xStart = (x + (width / 2) - messageWidth / 2);
		final float yStart = (y + ((int) (height - 8)) / 2);
		
		fontRenderer.func_243246_a(matrixStack, message, xStart, yStart, getFGColor());
	}
}

@@ -87,16 +87,55 @@
 Stack;%0A%0A
+import info.u_team.u_team_core.util.*;%0A
 import n
@@ -302,59 +302,8 @@
 t.*;
-%0Aimport net.minecraftforge.fml.client.gui.GuiUtils;
 %0A%0A/*
@@ -402,16 +402,95 @@
 than 20.
+ Also adds utility%0A * methods to add an %7B@link IPressable%7D and %7B@link ITooltip%7D
 %0A * %0A * 
@@ -678,16 +678,47 @@
 6_s_;%0A%09%0A
+%09protected RGBA buttonColor;%0A%09%0A
 %09public 
@@ -1349,16 +1349,44 @@
 sable);%0A
+%09%09buttonColor = RGBA.WHITE;%0A
 %09%7D%0A%09%0A%09pu
@@ -1622,16 +1622,162 @@
 p;%0A%09%7D%0A%09%0A
+%09public RGBA getButtonColor() %7B%0A%09%09return buttonColor;%0A%09%7D%0A%09%0A%09public void setButtonColor(RGBA buttonColor) %7B%0A%09%09this.buttonColor = buttonColor;%0A%09%7D%0A%09%0A
 %09@Overri
@@ -2047,17 +2047,16 @@
 %09GuiUtil
-s
 .drawCon
@@ -2185,18 +2185,39 @@
  2, 2, 0
-);
+, getButtonColor());%0A%09%09
 %0A%09%09rende

Add button color to the ubutton