11package com .falsepattern .lib .compat ;
22
3- import com .google .common .collect .Lists ;
4-
3+ import java .util .ArrayList ;
54import java .util .List ;
65
76import cpw .mods .fml .relauncher .Side ;
87import cpw .mods .fml .relauncher .SideOnly ;
8+ import lombok .*;
99import net .minecraft .client .Minecraft ;
1010import net .minecraft .client .gui .FontRenderer ;
1111import net .minecraft .client .gui .Gui ;
1515
1616@ SideOnly (Side .CLIENT )
1717public class GuiLabel extends Gui {
18+ private final List <String > lines = new ArrayList <>();
19+ private final FontRenderer fontRenderer ;
20+ private final int textColor ;
21+
22+ private boolean centered = false ;
1823 protected int width ;
1924 protected int height ;
25+ public int id ;
2026 public int x ;
2127 public int y ;
22- private final List <String > labels ;
23- public int id ;
24- private boolean centered ;
2528 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 ;
3329
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- this .fontRenderer = fontRendererObj ;
36- this .id = p_i45540_2_ ;
37- this .x = p_i45540_3_ ;
38- this .y = p_i45540_4_ ;
39- this .width = p_i45540_5_ ;
40- this .height = p_i45540_6_ ;
41- this .labels = Lists .newArrayList ();
42- this .centered = false ;
43- this .labelBgEnabled = false ;
44- this .textColor = p_i45540_7_ ;
45- this .backColor = -1 ;
46- this .ulColor = -1 ;
47- this .brColor = -1 ;
48- this .border = 0 ;
30+ /**
31+ * Instantiates a new Gui label.
32+ *
33+ * @param fontRenderer the minecraft font renderer
34+ * @param id the id
35+ * @param x the x
36+ * @param y the y
37+ * @param width the width
38+ * @param height the height
39+ * @param textColour the text colour
40+ */
41+ public GuiLabel (@ NonNull FontRenderer fontRenderer , int id , int x , int y , int width , int height , int textColour ) {
42+ this .fontRenderer = fontRenderer ;
43+ this .id = id ;
44+ this .x = x ;
45+ this .y = y ;
46+ this .width = width ;
47+ this .height = height ;
48+ this .textColor = textColour ;
4949 }
5050
51- public void addLine (String p_175202_1_ ) {
52- this .labels .add (I18n .format (p_175202_1_ ));
51+ /**
52+ * Add a line of text to the GuiLabel.
53+ *
54+ * @param text string to add.
55+ */
56+ public void addLine (@ NonNull String text ) {
57+ lines .add (I18n .format (text ));
5358 }
5459
5560 /**
56- * Sets the Label to be centered
61+ * Sets the label text to render centred with respect to the x and y.
62+ *
63+ * @return the GuiLabel.
5764 */
5865 public GuiLabel setCentered () {
59- this . centered = true ;
66+ centered = true ;
6067 return this ;
6168 }
6269
63- public void drawLabel (Minecraft mc , int mouseX , int mouseY ) {
64- if (this .visible ) {
65- GL11 .glEnable (GL11 .GL_BLEND );
66- OpenGlHelper .glBlendFunc (770 , 771 , 1 , 0 );
67- GL11 .glBlendFunc (GL11 .GL_SRC_ALPHA , GL11 .GL_ONE_MINUS_SRC_ALPHA );
68- this .drawLabelBackground (mc , mouseX , mouseY );
69- int i = this .y + this .height / 2 + this .border / 2 ;
70- int j = i - this .labels .size () * 10 / 2 ;
7170
72- for (int k = 0 ; k < this .labels .size (); ++k ) {
73- if (this .centered ) {
74- this .drawCenteredString (this .fontRenderer , this .labels .get (k ), this .x + this .width / 2 , j + k * 10 , this .textColor );
75- } else {
76- this .drawString (this .fontRenderer , this .labels .get (k ), this .x , j + k * 10 , this .textColor );
77- }
78- }
79- }
80- }
71+ /**
72+ * Draw label.
73+ *
74+ * @param minecraft the minecraft
75+ * @param mouseX the mouse x
76+ * @param mouseY the mouse y
77+ */
78+ public void drawLabel (@ NonNull Minecraft minecraft , int mouseX , int mouseY ) {
79+ if (!visible )
80+ return ;
81+ GL11 .glEnable (GL11 .GL_BLEND );
82+ OpenGlHelper .glBlendFunc (GL11 .GL_SRC_ALPHA , GL11 .GL_ONE_MINUS_SRC_ALPHA , GL11 .GL_ONE , GL11 .GL_ZERO );
8183
82- protected void drawLabelBackground (Minecraft mcIn , int mouseX , int mouseY ) {
83- if (this .labelBgEnabled ) {
84- int i = this .width + this .border * 2 ;
85- int j = this .height + this .border * 2 ;
86- int k = this .x - this .border ;
87- int l = this .y - this .border ;
88- drawRect (k , l , k + i , l + j , this .backColor );
89- this .drawHorizontalLine (k , k + i , l , this .ulColor );
90- this .drawHorizontalLine (k , k + i , l + j , this .brColor );
91- this .drawVerticalLine (k , l , l + j , this .ulColor );
92- this .drawVerticalLine (k + i , l , l + j , this .brColor );
84+ val topLeftY = y + height / 2 - lines .size () * 10 / 2 ;
85+ for (var i = 0 ; i < lines .size (); ++i ) {
86+ if (centered ) {
87+ drawCenteredString (fontRenderer , lines .get (i ), x + width / 2 , topLeftY + i * 10 , textColor );
88+ } else {
89+ drawString (fontRenderer , lines .get (i ), x , topLeftY + i * 10 , textColor );
90+ }
9391 }
9492 }
9593}
0 commit comments