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.ITextComponent;
import net.minecraftforge.fml.client.gui.GuiUtils;

/**
 * A button that fixes vanilla not drawing the continuous border if the button is smaller than 20 The code is adapted
 * from the 1.13.2 GuiButtonExt.
 * 
 * @author HyCraftHD
 */
public class UButton extends Button {
	
	protected static IPressable EMTPY_PRESSABLE = button -> {
	};
	
	public UButton(int x, int y, int width, int height, ITextComponent display) {
		super(x, y, width, height, display, EMTPY_PRESSABLE);
	}
	
	public UButton(int x, int y, int width, int height, ITextComponent display, IPressable pessable) {
		super(x, y, width, height, display, pessable);
	}
	
	public void setPressable(IPressable pressable) {
		onPress = pressable;
	}
	
	public void setPressable(Runnable runnable) {
		onPress = button -> runnable.run();
	}
	
	@Override
	public void renderButton(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
		final Minecraft minecraft = Minecraft.getInstance();
		final FontRenderer fontRenderer = minecraft.fontRenderer;
		
		String message = getMessage().getString();
		
		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.getStringWidth(message);
		final int ellipsisWidth = fontRenderer.getStringWidth("...");
		
		if (messageWidth > width - 6 && messageWidth > ellipsisWidth) {
			message = fontRenderer.func_238412_a_(message, width - 6 - ellipsisWidth).trim() + "...";
		}
		
		drawCenteredString(matrixStack, fontRenderer, message, x + width / 2, y + (height - 8) / 2, getFGColor());
	}
}

@@ -257,30 +257,17 @@
 il.text.
-ITextComponent
+*
 ;%0Aimport
@@ -417,60 +417,8 @@
 n 20
- The code is adapted%0A * from the 1.13.2 GuiButtonExt
 .%0A *
@@ -549,16 +549,78 @@
 %7B%0A%09%7D;%0A%09%0A
+%09protected static ITooltip EMPTY_TOOLTIP = field_238486_s_;%0A%09%0A
 %09public 
@@ -688,29 +688,28 @@
 isplay) %7B%0A%09%09
-super
+this
 (x, y, width
@@ -850,16 +850,202 @@
 able) %7B%0A
+%09%09this(x, y, width, height, display, pessable, EMPTY_TOOLTIP);%0A%09%7D%0A%09%0A%09public UButton(int x, int y, int width, int height, ITextComponent display, IPressable pessable, ITooltip tooltip) %7B%0A
 %09%09super(
@@ -1258,16 +1258,88 @@
 );%0A%09%7D%0A%09%0A
+%09public void setTooltip(ITooltip tooltip) %7B%0A%09%09onTooltip = tooltip;%0A%09%7D%0A%09%0A
 %09@Overri
@@ -1558,22 +1558,30 @@
 r;%0A%09%09%0A%09%09
-String
+ITextComponent
  message
@@ -1599,20 +1599,8 @@
 ge()
-.getString()
 ;%0A%09%09
@@ -1851,24 +1851,32 @@
 er.getString
+Property
 Width(messag
@@ -2025,16 +2025,40 @@
 ssage = 
+new StringTextComponent(
 fontRend
@@ -2072,17 +2072,17 @@
 nc_23841
-2
+7
 _a_(mess
@@ -2117,12 +2117,17 @@
 th).
+getS
 tri
-m
+ng
 () +
@@ -2132,16 +2132,17 @@
  + %22...%22
+)
 ;%0A%09%09%7D%0A%09%09

Extend ubutton with ITooltip and update code in render button