2022-05-07 13:38:33 +02:00
|
|
|
package com.falsepattern.lib.compat;
|
|
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
2022-05-31 10:09:16 +01:00
|
|
|
|
2022-05-07 13:38:33 +02:00
|
|
|
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)
|
2022-05-31 10:09:16 +01:00
|
|
|
public class GuiLabel extends Gui {
|
2022-05-07 13:38:33 +02:00
|
|
|
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;
|
|
|
|
|
|
2022-05-31 10:09:16 +01:00
|
|
|
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_) {
|
2022-05-07 13:38:33 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 10:09:16 +01:00
|
|
|
public void addLine(String p_175202_1_) {
|
2022-05-07 13:38:33 +02:00
|
|
|
this.labels.add(I18n.format(p_175202_1_));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the Label to be centered
|
|
|
|
|
*/
|
2022-05-31 10:09:16 +01:00
|
|
|
public GuiLabel setCentered() {
|
2022-05-07 13:38:33 +02:00
|
|
|
this.centered = true;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 10:09:16 +01:00
|
|
|
public void drawLabel(Minecraft mc, int mouseX, int mouseY) {
|
|
|
|
|
if (this.visible) {
|
2022-05-07 13:38:33 +02:00
|
|
|
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;
|
|
|
|
|
|
2022-05-31 10:09:16 +01:00
|
|
|
for (int k = 0; k < this.labels.size(); ++k) {
|
|
|
|
|
if (this.centered) {
|
2022-05-07 13:38:33 +02:00
|
|
|
this.drawCenteredString(this.fontRenderer, this.labels.get(k), this.x + this.width / 2, j + k * 10, this.textColor);
|
2022-05-31 10:09:16 +01:00
|
|
|
} else {
|
2022-05-07 13:38:33 +02:00
|
|
|
this.drawString(this.fontRenderer, this.labels.get(k), this.x, j + k * 10, this.textColor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 10:09:16 +01:00
|
|
|
protected void drawLabelBackground(Minecraft mcIn, int mouseX, int mouseY) {
|
|
|
|
|
if (this.labelBgEnabled) {
|
2022-05-07 13:38:33 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|