Skip to content

Commit 9810a5c

Browse files
committed
GuiLabel backport
1 parent de75812 commit 9810a5c

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.falsepattern.lib.compat;
2+
3+
import com.google.common.collect.Lists;
4+
import java.util.List;
5+
6+
import cpw.mods.fml.relauncher.Side;
7+
import cpw.mods.fml.relauncher.SideOnly;
8+
import net.minecraft.client.Minecraft;
9+
import net.minecraft.client.gui.FontRenderer;
10+
import net.minecraft.client.gui.Gui;
11+
import net.minecraft.client.renderer.OpenGlHelper;
12+
import net.minecraft.client.resources.I18n;
13+
import org.lwjgl.opengl.GL11;
14+
15+
@SideOnly(Side.CLIENT)
16+
public class GuiLabel extends Gui
17+
{
18+
protected int width;
19+
protected int height;
20+
public int x;
21+
public int y;
22+
private final List<String> labels;
23+
public int id;
24+
private boolean centered;
25+
public boolean visible = true;
26+
private final boolean labelBgEnabled;
27+
private final int textColor;
28+
private final int backColor;
29+
private final int ulColor;
30+
private final int brColor;
31+
private final FontRenderer fontRenderer;
32+
private final int border;
33+
34+
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_)
35+
{
36+
this.fontRenderer = fontRendererObj;
37+
this.id = p_i45540_2_;
38+
this.x = p_i45540_3_;
39+
this.y = p_i45540_4_;
40+
this.width = p_i45540_5_;
41+
this.height = p_i45540_6_;
42+
this.labels = Lists.newArrayList();
43+
this.centered = false;
44+
this.labelBgEnabled = false;
45+
this.textColor = p_i45540_7_;
46+
this.backColor = -1;
47+
this.ulColor = -1;
48+
this.brColor = -1;
49+
this.border = 0;
50+
}
51+
52+
public void addLine(String p_175202_1_)
53+
{
54+
this.labels.add(I18n.format(p_175202_1_));
55+
}
56+
57+
/**
58+
* Sets the Label to be centered
59+
*/
60+
public GuiLabel setCentered()
61+
{
62+
this.centered = true;
63+
return this;
64+
}
65+
66+
public void drawLabel(Minecraft mc, int mouseX, int mouseY)
67+
{
68+
if (this.visible)
69+
{
70+
GL11.glEnable(GL11.GL_BLEND);
71+
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
72+
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
73+
this.drawLabelBackground(mc, mouseX, mouseY);
74+
int i = this.y + this.height / 2 + this.border / 2;
75+
int j = i - this.labels.size() * 10 / 2;
76+
77+
for (int k = 0; k < this.labels.size(); ++k)
78+
{
79+
if (this.centered)
80+
{
81+
this.drawCenteredString(this.fontRenderer, this.labels.get(k), this.x + this.width / 2, j + k * 10, this.textColor);
82+
}
83+
else
84+
{
85+
this.drawString(this.fontRenderer, this.labels.get(k), this.x, j + k * 10, this.textColor);
86+
}
87+
}
88+
}
89+
}
90+
91+
protected void drawLabelBackground(Minecraft mcIn, int mouseX, int mouseY)
92+
{
93+
if (this.labelBgEnabled)
94+
{
95+
int i = this.width + this.border * 2;
96+
int j = this.height + this.border * 2;
97+
int k = this.x - this.border;
98+
int l = this.y - this.border;
99+
drawRect(k, l, k + i, l + j, this.backColor);
100+
this.drawHorizontalLine(k, k + i, l, this.ulColor);
101+
this.drawHorizontalLine(k, k + i, l + j, this.brColor);
102+
this.drawVerticalLine(k, l, l + j, this.ulColor);
103+
this.drawVerticalLine(k + i, l, l + j, this.brColor);
104+
}
105+
}
106+
}

0 commit comments

Comments
 (0)