-
Notifications
You must be signed in to change notification settings - Fork 753
/
SlotButton.java
125 lines (101 loc) · 3.6 KB
/
SlotButton.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package tconstruct.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.gui.GuiButton;
public class SlotButton extends GuiButton {
protected static final ResourceLocation buttonTextures = new ResourceLocation("tinker:textures/gui/slotButton.png");
/** Button width in pixels */
protected int width;
/** Button height in pixels */
protected int height;
/** The x position of this control. */
public int xPosition;
/** The y position of this control. */
public int yPosition;
/** The string displayed on this control. */
public String displayString;
/** ID for this control. */
public int id;
/** True if this control is enabled, false to disable. */
public boolean enabled;
/** Hides the button completely if false. */
public boolean drawButton;
protected boolean field_82253_i;
public SlotButton(int par1, int par2, int par3, String par4Str) {
this(par1, par2, par3, 200, 20, par4Str);
}
public SlotButton(int par1, int par2, int par3, int par4, int par5, String par6Str) {
super(par1, par2, par3, par4, par5, par6Str);
this.width = 200;
this.height = 20;
this.enabled = true;
this.drawButton = true;
this.id = par1;
this.xPosition = par2;
this.yPosition = par3;
this.width = par4;
this.height = par5;
this.displayString = par6Str;
}
/**
* Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over
* this button and 2 if it IS hovering over this button.
*/
protected int getHoverState(boolean par1) {
byte b0 = 1;
if (!this.enabled) {
b0 = 0;
} else if (par1) {
b0 = 2;
}
return b0;
}
/**
* Draws this button to the screen.
*/
public void drawButton(Minecraft par1Minecraft, int par2, int par3) {
if (this.drawButton) {
FontRenderer fontrenderer = par1Minecraft.fontRenderer;
par1Minecraft.getTextureManager().bindTexture(buttonTextures);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.field_82253_i = par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height;
int k = this.getHoverState(this.field_82253_i);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 26, this.width / 2, this.height);
this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + k * 26, this.width / 2, this.height);
this.mouseDragged(par1Minecraft, par2, par3);
int l = 14737632;
if (!this.enabled) {
l = -6250336;
} else if (this.field_82253_i) {
l = 16777120;
}
this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l);
}
}
/**
* Fired when the mouse button is dragged. Equivalent of
* MouseListener.mouseDragged(MouseEvent e).
*/
protected void mouseDragged(Minecraft par1Minecraft, int par2, int par3) {
}
/**
* Fired when the mouse button is released. Equivalent of
* MouseListener.mouseReleased(MouseEvent e).
*/
public void mouseReleased(int par1, int par2) {
}
/**
* Returns true if the mouse has been pressed on this control. Equivalent of
* MouseListener.mousePressed(MouseEvent e).
*/
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
return this.enabled && this.drawButton && par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height;
}
public boolean func_82252_a() {
return this.field_82253_i;
}
public void func_82251_b(int par1, int par2) {
}
}