001 package net.minecraft.client.gui.achievement;
002
003 import cpw.mods.fml.relauncher.Side;
004 import cpw.mods.fml.relauncher.SideOnly;
005 import net.minecraft.client.Minecraft;
006 import net.minecraft.client.gui.FontRenderer;
007 import net.minecraft.client.gui.GuiButton;
008 import net.minecraft.client.gui.GuiScreen;
009 import net.minecraft.client.gui.GuiSlot;
010 import net.minecraft.client.renderer.RenderHelper;
011 import net.minecraft.client.renderer.Tessellator;
012 import net.minecraft.client.renderer.entity.RenderItem;
013 import net.minecraft.item.ItemStack;
014 import net.minecraft.stats.StatFileWriter;
015 import net.minecraft.util.StatCollector;
016 import net.minecraft.util.StringTranslate;
017 import org.lwjgl.opengl.GL11;
018 import org.lwjgl.opengl.GL12;
019
020 @SideOnly(Side.CLIENT)
021 public class GuiStats extends GuiScreen
022 {
023 private static RenderItem renderItem = new RenderItem();
024 protected GuiScreen parentGui;
025
026 /** The title of the stats screen. */
027 protected String statsTitle = "Select world";
028
029 /** The slot for general stats. */
030 private GuiSlotStatsGeneral slotGeneral;
031
032 /** The slot for item stats. */
033 private GuiSlotStatsItem slotItem;
034
035 /** The slot for block stats. */
036 private GuiSlotStatsBlock slotBlock;
037 private StatFileWriter statFileWriter;
038
039 /** The currently-selected slot. */
040 private GuiSlot selectedSlot = null;
041
042 public GuiStats(GuiScreen par1GuiScreen, StatFileWriter par2StatFileWriter)
043 {
044 this.parentGui = par1GuiScreen;
045 this.statFileWriter = par2StatFileWriter;
046 }
047
048 /**
049 * Adds the buttons (and other controls) to the screen in question.
050 */
051 public void initGui()
052 {
053 this.statsTitle = StatCollector.translateToLocal("gui.stats");
054 this.slotGeneral = new GuiSlotStatsGeneral(this);
055 this.slotGeneral.registerScrollButtons(this.controlList, 1, 1);
056 this.slotItem = new GuiSlotStatsItem(this);
057 this.slotItem.registerScrollButtons(this.controlList, 1, 1);
058 this.slotBlock = new GuiSlotStatsBlock(this);
059 this.slotBlock.registerScrollButtons(this.controlList, 1, 1);
060 this.selectedSlot = this.slotGeneral;
061 this.addHeaderButtons();
062 }
063
064 /**
065 * Creates the buttons that appear at the top of the Stats GUI.
066 */
067 public void addHeaderButtons()
068 {
069 StringTranslate var1 = StringTranslate.getInstance();
070 this.controlList.add(new GuiButton(0, this.width / 2 + 4, this.height - 28, 150, 20, var1.translateKey("gui.done")));
071 this.controlList.add(new GuiButton(1, this.width / 2 - 154, this.height - 52, 100, 20, var1.translateKey("stat.generalButton")));
072 GuiButton var2;
073 this.controlList.add(var2 = new GuiButton(2, this.width / 2 - 46, this.height - 52, 100, 20, var1.translateKey("stat.blocksButton")));
074 GuiButton var3;
075 this.controlList.add(var3 = new GuiButton(3, this.width / 2 + 62, this.height - 52, 100, 20, var1.translateKey("stat.itemsButton")));
076
077 if (this.slotBlock.getSize() == 0)
078 {
079 var2.enabled = false;
080 }
081
082 if (this.slotItem.getSize() == 0)
083 {
084 var3.enabled = false;
085 }
086 }
087
088 /**
089 * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
090 */
091 protected void actionPerformed(GuiButton par1GuiButton)
092 {
093 if (par1GuiButton.enabled)
094 {
095 if (par1GuiButton.id == 0)
096 {
097 this.mc.displayGuiScreen(this.parentGui);
098 }
099 else if (par1GuiButton.id == 1)
100 {
101 this.selectedSlot = this.slotGeneral;
102 }
103 else if (par1GuiButton.id == 3)
104 {
105 this.selectedSlot = this.slotItem;
106 }
107 else if (par1GuiButton.id == 2)
108 {
109 this.selectedSlot = this.slotBlock;
110 }
111 else
112 {
113 this.selectedSlot.actionPerformed(par1GuiButton);
114 }
115 }
116 }
117
118 /**
119 * Draws the screen and all the components in it.
120 */
121 public void drawScreen(int par1, int par2, float par3)
122 {
123 this.selectedSlot.drawScreen(par1, par2, par3);
124 this.drawCenteredString(this.fontRenderer, this.statsTitle, this.width / 2, 20, 16777215);
125 super.drawScreen(par1, par2, par3);
126 }
127
128 /**
129 * Draws the item sprite on top of the background sprite.
130 */
131 private void drawItemSprite(int par1, int par2, int par3)
132 {
133 this.drawButtonBackground(par1 + 1, par2 + 1);
134 GL11.glEnable(GL12.GL_RESCALE_NORMAL);
135 RenderHelper.enableGUIStandardItemLighting();
136 renderItem.renderItemIntoGUI(this.fontRenderer, this.mc.renderEngine, new ItemStack(par3, 1, 0), par1 + 2, par2 + 2);
137 RenderHelper.disableStandardItemLighting();
138 GL11.glDisable(GL12.GL_RESCALE_NORMAL);
139 }
140
141 /**
142 * Draws a gray box that serves as a button background.
143 */
144 private void drawButtonBackground(int par1, int par2)
145 {
146 this.drawSprite(par1, par2, 0, 0);
147 }
148
149 /**
150 * Draws a sprite from /gui/slot.png.
151 */
152 private void drawSprite(int par1, int par2, int par3, int par4)
153 {
154 int var5 = this.mc.renderEngine.getTexture("/gui/slot.png");
155 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
156 this.mc.renderEngine.bindTexture(var5);
157 Tessellator var10 = Tessellator.instance;
158 var10.startDrawingQuads();
159 var10.addVertexWithUV((double)(par1 + 0), (double)(par2 + 18), (double)this.zLevel, (double)((float)(par3 + 0) * 0.0078125F), (double)((float)(par4 + 18) * 0.0078125F));
160 var10.addVertexWithUV((double)(par1 + 18), (double)(par2 + 18), (double)this.zLevel, (double)((float)(par3 + 18) * 0.0078125F), (double)((float)(par4 + 18) * 0.0078125F));
161 var10.addVertexWithUV((double)(par1 + 18), (double)(par2 + 0), (double)this.zLevel, (double)((float)(par3 + 18) * 0.0078125F), (double)((float)(par4 + 0) * 0.0078125F));
162 var10.addVertexWithUV((double)(par1 + 0), (double)(par2 + 0), (double)this.zLevel, (double)((float)(par3 + 0) * 0.0078125F), (double)((float)(par4 + 0) * 0.0078125F));
163 var10.draw();
164 }
165
166 static Minecraft getMinecraft(GuiStats par0GuiStats)
167 {
168 return par0GuiStats.mc;
169 }
170
171 /**
172 * there are 11 identical methods like this
173 */
174 static FontRenderer getFontRenderer1(GuiStats par0GuiStats)
175 {
176 return par0GuiStats.fontRenderer;
177 }
178
179 static StatFileWriter getStatsFileWriter(GuiStats par0GuiStats)
180 {
181 return par0GuiStats.statFileWriter;
182 }
183
184 /**
185 * there are 11 identical methods like this
186 */
187 static FontRenderer getFontRenderer2(GuiStats par0GuiStats)
188 {
189 return par0GuiStats.fontRenderer;
190 }
191
192 /**
193 * there are 11 identical methods like this
194 */
195 static FontRenderer getFontRenderer3(GuiStats par0GuiStats)
196 {
197 return par0GuiStats.fontRenderer;
198 }
199
200 /**
201 * exactly the same as 27141
202 */
203 static Minecraft getMinecraft1(GuiStats par0GuiStats)
204 {
205 return par0GuiStats.mc;
206 }
207
208 /**
209 * Draws a sprite from /gui/slot.png.
210 */
211 static void drawSprite(GuiStats par0GuiStats, int par1, int par2, int par3, int par4)
212 {
213 par0GuiStats.drawSprite(par1, par2, par3, par4);
214 }
215
216 /**
217 * exactly the same as 27141 and 27143
218 */
219 static Minecraft getMinecraft2(GuiStats par0GuiStats)
220 {
221 return par0GuiStats.mc;
222 }
223
224 /**
225 * there are 11 identical methods like this
226 */
227 static FontRenderer getFontRenderer4(GuiStats par0GuiStats)
228 {
229 return par0GuiStats.fontRenderer;
230 }
231
232 /**
233 * there are 11 identical methods like this
234 */
235 static FontRenderer getFontRenderer5(GuiStats par0GuiStats)
236 {
237 return par0GuiStats.fontRenderer;
238 }
239
240 /**
241 * there are 11 identical methods like this
242 */
243 static FontRenderer getFontRenderer6(GuiStats par0GuiStats)
244 {
245 return par0GuiStats.fontRenderer;
246 }
247
248 /**
249 * there are 11 identical methods like this
250 */
251 static FontRenderer getFontRenderer7(GuiStats par0GuiStats)
252 {
253 return par0GuiStats.fontRenderer;
254 }
255
256 /**
257 * there are 11 identical methods like this
258 */
259 static FontRenderer getFontRenderer8(GuiStats par0GuiStats)
260 {
261 return par0GuiStats.fontRenderer;
262 }
263
264 static void drawGradientRect(GuiStats par0GuiStats, int par1, int par2, int par3, int par4, int par5, int par6)
265 {
266 par0GuiStats.drawGradientRect(par1, par2, par3, par4, par5, par6);
267 }
268
269 /**
270 * there are 11 identical methods like this
271 */
272 static FontRenderer getFontRenderer9(GuiStats par0GuiStats)
273 {
274 return par0GuiStats.fontRenderer;
275 }
276
277 /**
278 * there are 11 identical methods like this
279 */
280 static FontRenderer getFontRenderer10(GuiStats par0GuiStats)
281 {
282 return par0GuiStats.fontRenderer;
283 }
284
285 /**
286 * exactly the same as 27129
287 */
288 static void drawGradientRect1(GuiStats par0GuiStats, int par1, int par2, int par3, int par4, int par5, int par6)
289 {
290 par0GuiStats.drawGradientRect(par1, par2, par3, par4, par5, par6);
291 }
292
293 /**
294 * there are 11 identical methods like this
295 */
296 static FontRenderer getFontRenderer11(GuiStats par0GuiStats)
297 {
298 return par0GuiStats.fontRenderer;
299 }
300
301 /**
302 * Draws the item sprite on top of the background sprite.
303 */
304 static void drawItemSprite(GuiStats par0GuiStats, int par1, int par2, int par3)
305 {
306 par0GuiStats.drawItemSprite(par1, par2, par3);
307 }
308 }