Files
FalsePatternLib/src/main/java/com/falsepattern/lib/compat/GuiLabel.java
T

106 lines
3.3 KiB
Java
Raw Normal View History

2022-05-07 13:38:33 +02:00
package com.falsepattern.lib.compat;
import com.google.common.collect.Lists;
import java.util.List;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.resources.I18n;
import org.lwjgl.opengl.GL11;
@SideOnly(Side.CLIENT)
public class GuiLabel extends Gui
{
protected int width;
protected int height;
public int x;
public int y;
private final List<String> labels;
public int id;
private boolean centered;
public boolean visible = true;
private final boolean labelBgEnabled;
private final int textColor;
private final int backColor;
private final int ulColor;
private final int brColor;
private final FontRenderer fontRenderer;
private final int border;
public GuiLabel(FontRenderer fontRendererObj, int p_i45540_2_, int p_i45540_3_, int p_i45540_4_, int p_i45540_5_, int p_i45540_6_, int p_i45540_7_)
{
this.fontRenderer = fontRendererObj;
this.id = p_i45540_2_;
this.x = p_i45540_3_;
this.y = p_i45540_4_;
this.width = p_i45540_5_;
this.height = p_i45540_6_;
this.labels = Lists.newArrayList();
this.centered = false;
this.labelBgEnabled = false;
this.textColor = p_i45540_7_;
this.backColor = -1;
this.ulColor = -1;
this.brColor = -1;
this.border = 0;
}
public void addLine(String p_175202_1_)
{
this.labels.add(I18n.format(p_175202_1_));
}
/**
* Sets the Label to be centered
*/
public GuiLabel setCentered()
{
this.centered = true;
return this;
}
public void drawLabel(Minecraft mc, int mouseX, int mouseY)
{
if (this.visible)
{
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
this.drawLabelBackground(mc, mouseX, mouseY);
int i = this.y + this.height / 2 + this.border / 2;
int j = i - this.labels.size() * 10 / 2;
for (int k = 0; k < this.labels.size(); ++k)
{
if (this.centered)
{
this.drawCenteredString(this.fontRenderer, this.labels.get(k), this.x + this.width / 2, j + k * 10, this.textColor);
}
else
{
this.drawString(this.fontRenderer, this.labels.get(k), this.x, j + k * 10, this.textColor);
}
}
}
}
protected void drawLabelBackground(Minecraft mcIn, int mouseX, int mouseY)
{
if (this.labelBgEnabled)
{
int i = this.width + this.border * 2;
int j = this.height + this.border * 2;
int k = this.x - this.border;
int l = this.y - this.border;
drawRect(k, l, k + i, l + j, this.backColor);
this.drawHorizontalLine(k, k + i, l, this.ulColor);
this.drawHorizontalLine(k, k + i, l + j, this.brColor);
this.drawVerticalLine(k, l, l + j, this.ulColor);
this.drawVerticalLine(k + i, l, l + j, this.brColor);
}
}
}