GuiPanelConfigContainer.java
6.62 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*
* 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 static com.mumfrey.liteloader.gl.GLClippingPlanes.*;
import com.mumfrey.liteloader.LiteMod;
import com.mumfrey.liteloader.modconfig.ConfigPanel;
import com.mumfrey.liteloader.modconfig.ConfigPanelHost;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.resources.I18n;
/**
* Config panel container, this handles drawing the configuration panel chrome
* and also hosts the configuration panels themselves to support scrolling and
* stuff.
*
* @author Adam Mummery-Smith
*/
class GuiPanelConfigContainer extends GuiPanel implements ConfigPanelHost
{
/**
* Panel we are hosting
*/
private ConfigPanel panel;
/**
* Mod being configured, the panel may want a reference to it
*/
private LiteMod mod;
/**
* Scroll bar for the panel
*/
GuiSimpleScrollBar scrollBar = new GuiSimpleScrollBar();
/**
* Panel's internal height (for scrolling)
*/
private int totalHeight = -1;
/**
* @param minecraft
* @param panel
* @param mod
*/
GuiPanelConfigContainer(Minecraft minecraft, ConfigPanel panel, LiteMod mod)
{
super(minecraft);
this.panel = panel;
this.mod = mod;
}
/**
*
*/
String getPanelTitle()
{
String panelTitle = this.panel.getPanelTitle();
return panelTitle != null ? panelTitle : I18n.format("gui.settings.title", this.mod.getName());
}
/* (non-Javadoc)
* @see com.mumfrey.liteloader.modconfig.ConfigPanelHost#getMod()
*/
@SuppressWarnings("unchecked")
@Override
public <TModClass extends LiteMod> TModClass getMod()
{
return (TModClass)this.mod;
}
/* (non-Javadoc)
* @see com.mumfrey.liteloader.modconfig.ConfigPanelHost#getWidth()
*/
@Override
public int getWidth()
{
return this.innerWidth;
}
/* (non-Javadoc)
* @see com.mumfrey.liteloader.modconfig.ConfigPanelHost#getHeight()
*/
@Override
public int getHeight()
{
return this.innerHeight;
}
/**
* Callback from parent screen when window is resized
*
* @param width
* @param height
*/
@Override
void setSize(int width, int height)
{
super.setSize(width, height);
this.panel.onPanelResize(this);
this.controls.add(new GuiButton(0, this.width - 99 - MARGIN, this.height - BOTTOM + 9, 100, 20, I18n.format("gui.saveandclose")));
}
/**
* Callback from parent screen when panel is displayed
*/
@Override
void onShown()
{
try
{
this.panel.onPanelShown(this);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
/**
* Callback from parent screen when panel is hidden
*/
@Override
void onHidden()
{
try
{
this.panel.onPanelHidden();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
/**
* Callback from parent screen every tick
*/
@Override
void onTick()
{
this.panel.onTick(this);
}
/**
* Draw the panel and chrome
*
* @param mouseX
* @param mouseY
* @param partialTicks
*/
@Override
void draw(int mouseX, int mouseY, float partialTicks)
{
// Scroll position
this.innerTop = TOP - this.scrollBar.getValue();
// Draw panel title
this.mc.fontRenderer.drawString(this.getPanelTitle(), MARGIN, TOP - 14, 0xFFFFFFFF);
// Draw top and bottom horizontal bars
drawRect(MARGIN, TOP - 4, this.width - MARGIN, TOP - 3, 0xFF999999);
drawRect(MARGIN, this.height - BOTTOM + 2, this.width - MARGIN, this.height - BOTTOM + 3, 0xFF999999);
// Clip rect
glEnableClipping(MARGIN, this.width - MARGIN - 6, TOP, this.height - BOTTOM);
// Offset by scroll
glPushMatrix();
glTranslatef(MARGIN, this.innerTop, 0.0F);
// Draw panel contents
this.panel.drawPanel(this, mouseX - MARGIN - (this.mouseOverPanel(mouseX, mouseY) ? 0 : 99999), mouseY - this.innerTop, partialTicks);
glClear(GL_DEPTH_BUFFER_BIT);
// Disable clip rect
glDisableClipping();
// Restore transform
glPopMatrix();
// Get total scroll height from panel
this.totalHeight = Math.max(-1, this.panel.getContentHeight());
// Update and draw scroll bar
this.scrollBar.setMaxValue(this.totalHeight - this.innerHeight);
this.scrollBar.drawScrollBar(mouseX, mouseY, partialTicks, this.width - MARGIN - 5, TOP, 5, this.innerHeight,
Math.max(this.innerHeight, this.totalHeight));
// Draw other buttons
super.draw(mouseX, mouseY, partialTicks);
}
/**
* @param control
*/
@Override
void actionPerformed(GuiButton control)
{
if (control.id == 0) this.close();
}
/**
* @param mouseWheelDelta
*/
@Override
void mouseWheelScrolled(int mouseWheelDelta)
{
this.scrollBar.offsetValue(-mouseWheelDelta / 8);
}
/**
* @param mouseX
* @param mouseY
* @param mouseButton
*/
@Override
void mousePressed(int mouseX, int mouseY, int mouseButton)
{
if (mouseButton == 0)
{
if (this.scrollBar.wasMouseOver())
{
this.scrollBar.setDragging(true);
}
}
super.mousePressed(mouseX, mouseY, mouseButton);
if (this.mouseOverPanel(mouseX, mouseY))
{
this.panel.mousePressed(this, mouseX - MARGIN, mouseY - this.innerTop, mouseButton);
}
}
/**
* @param mouseX
* @param mouseY
* @param mouseButton
*/
@Override
void mouseReleased(int mouseX, int mouseY, int mouseButton)
{
if (mouseButton == 0)
{
this.scrollBar.setDragging(false);
}
this.panel.mouseReleased(this, mouseX - MARGIN, mouseY - this.innerTop, mouseButton);
}
/**
* @param mouseX
* @param mouseY
*/
@Override
void mouseMoved(int mouseX, int mouseY)
{
this.panel.mouseMoved(this, mouseX - MARGIN, mouseY - this.innerTop);
}
/**
* @param keyChar
* @param keyCode
*/
@Override
void keyPressed(char keyChar, int keyCode)
{
this.panel.keyPressed(this, keyChar, keyCode);
}
}