1
1
package com .falsepattern .lib .compat ;
2
2
3
- import com .google .common .collect .Lists ;
4
-
3
+ import java .util .ArrayList ;
5
4
import java .util .List ;
6
5
7
6
import cpw .mods .fml .relauncher .Side ;
8
7
import cpw .mods .fml .relauncher .SideOnly ;
8
+ import lombok .*;
9
9
import net .minecraft .client .Minecraft ;
10
10
import net .minecraft .client .gui .FontRenderer ;
11
11
import net .minecraft .client .gui .Gui ;
15
15
16
16
@ SideOnly (Side .CLIENT )
17
17
public 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 ;
18
23
protected int width ;
19
24
protected int height ;
25
+ public int id ;
20
26
public int x ;
21
27
public int y ;
22
- private final List <String > labels ;
23
- public int id ;
24
- private boolean centered ;
25
28
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
29
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 ;
49
49
}
50
50
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 ));
53
58
}
54
59
55
60
/**
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.
57
64
*/
58
65
public GuiLabel setCentered () {
59
- this . centered = true ;
66
+ centered = true ;
60
67
return this ;
61
68
}
62
69
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 ;
71
70
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 );
81
83
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
+ }
93
91
}
94
92
}
95
93
}
0 commit comments