GuiPanel.java
4.47 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
* This file is part of LiteLoader.
* Copyright (C) 2012-16 Adam Mummery-Smith
* All Rights Reserved.
*/
package com.mumfrey.liteloader.client.gui;
import static com.mumfrey.liteloader.gl.GL.*;
import java.util.ArrayList;
import java.util.List;
import com.mumfrey.liteloader.client.api.LiteLoaderBrandingProvider;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
/**
* Base class for panels
*
* @author Adam Mummery-Smith
*/
public abstract class GuiPanel extends Gui
{
protected static final int TOP = 26;
protected static final int BOTTOM = 40;
protected static final int MARGIN = 12;
/**
* Minecraft
*/
protected Minecraft mc;
/**
* Buttons
*/
protected List<GuiButton> controls = new ArrayList<GuiButton>();
/**
* Current available width
*/
protected int width = 0;
/**
* Current available height
*/
protected int height = 0;
/**
* Current inner pane width (width - margins)
*/
protected int innerWidth = 0;
/**
* Current inner pane visible height (height - chrome)
*/
protected int innerHeight = 0;
/**
* Panel Y position (for scroll)
*/
protected int innerTop = TOP;
/**
* True if the client wants to close the panel
*/
private boolean closeRequested;
/**
* @param minecraft
*/
public GuiPanel(Minecraft minecraft)
{
this.mc = minecraft;
}
boolean stealFocus()
{
return true;
}
/**
* Called by the containing screen to set the panel size
*
* @param width
* @param height
*/
void setSize(int width, int height)
{
this.controls.clear();
this.width = width;
this.height = height;
this.innerHeight = this.height - TOP - BOTTOM;
this.innerWidth = this.width - (MARGIN * 2) - 6;
}
/**
* @param mouseX
* @param mouseY
* @param partialTicks
*/
void draw(int mouseX, int mouseY, float partialTicks)
{
for (GuiButton control : this.controls)
{
control.func_191745_a(this.mc, mouseX, mouseY, partialTicks); // drawButton
}
}
/**
*
*/
public void close()
{
this.closeRequested = true;
}
/**
* Get whether the client wants to close the panel
*/
boolean isCloseRequested()
{
return this.closeRequested;
}
/**
* @param mouseX
* @param mouseY
* @param mouseButton
*/
void mousePressed(int mouseX, int mouseY, int mouseButton)
{
if (mouseButton == 0)
{
for (GuiButton control : this.controls)
{
if (control.mousePressed(this.mc, mouseX, mouseY))
{
control.playPressSound(this.mc.getSoundHandler());
this.actionPerformed(control);
}
}
}
}
/**
* @param mouseX
* @param mouseY
*/
boolean mouseOverPanel(int mouseX, int mouseY)
{
return mouseX > MARGIN && mouseX <= this.width - MARGIN && mouseY > TOP && mouseY <= this.height - BOTTOM;
}
/**
* Called every tick
*/
abstract void onTick();
/**
* Called after the screen is hidden
*/
abstract void onHidden();
/**
* Called when the panel is shown
*/
abstract void onShown();
/**
* @param keyChar
* @param keyCode
*/
abstract void keyPressed(char keyChar, int keyCode);
/**
* @param mouseX
* @param mouseY
*/
abstract void mouseMoved(int mouseX, int mouseY);
/**
* @param mouseX
* @param mouseY
* @param mouseButton
*/
abstract void mouseReleased(int mouseX, int mouseY, int mouseButton);
/**
* @param mouseWheelDelta
*/
abstract void mouseWheelScrolled(int mouseWheelDelta);
/**
* @param control
*/
abstract void actionPerformed(GuiButton control);
/**
* @param x
* @param y
* @param frame
*/
protected void drawThrobber(int x, int y, int frame)
{
glEnableBlend();
glAlphaFunc(GL_GREATER, 0.0F);
this.mc.getTextureManager().bindTexture(LiteLoaderBrandingProvider.ABOUT_TEXTURE);
this.drawTexturedModalRect(x, y, (frame % 4) * 16, 171 + (((frame / 4) % 3) * 16), 16, 16);
glAlphaFunc(GL_GREATER, 0.1F);
glDisableBlend();
}
}