001package net.minecraft.client.gui; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import net.minecraft.client.Minecraft; 006import net.minecraft.client.renderer.Tessellator; 007import net.minecraft.util.IProgressUpdate; 008import net.minecraft.util.MinecraftError; 009import org.lwjgl.opengl.Display; 010import org.lwjgl.opengl.GL11; 011 012@SideOnly(Side.CLIENT) 013public class LoadingScreenRenderer implements IProgressUpdate 014{ 015 private String field_73727_a = ""; 016 017 /** A reference to the Minecraft object. */ 018 private Minecraft mc; 019 020 /** 021 * The text currently displayed (i.e. the argument to the last call to printText or func_73722_d) 022 */ 023 private String currentlyDisplayedText = ""; 024 private long field_73723_d = Minecraft.getSystemTime(); 025 private boolean field_73724_e = false; 026 027 public LoadingScreenRenderer(Minecraft par1Minecraft) 028 { 029 this.mc = par1Minecraft; 030 } 031 032 /** 033 * this string, followed by "working..." and then the "% complete" are the 3 lines shown. This resets progress to 0, 034 * and the WorkingString to "working...". 035 */ 036 public void resetProgressAndMessage(String par1Str) 037 { 038 this.field_73724_e = false; 039 this.func_73722_d(par1Str); 040 } 041 042 /** 043 * "Saving level", or the loading,or downloading equivelent 044 */ 045 public void displayProgressMessage(String par1Str) 046 { 047 this.field_73724_e = true; 048 this.func_73722_d(par1Str); 049 } 050 051 public void func_73722_d(String par1Str) 052 { 053 this.currentlyDisplayedText = par1Str; 054 055 if (!this.mc.running) 056 { 057 if (!this.field_73724_e) 058 { 059 throw new MinecraftError(); 060 } 061 } 062 else 063 { 064 ScaledResolution scaledresolution = new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight); 065 GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); 066 GL11.glMatrixMode(GL11.GL_PROJECTION); 067 GL11.glLoadIdentity(); 068 GL11.glOrtho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 100.0D, 300.0D); 069 GL11.glMatrixMode(GL11.GL_MODELVIEW); 070 GL11.glLoadIdentity(); 071 GL11.glTranslatef(0.0F, 0.0F, -200.0F); 072 } 073 } 074 075 /** 076 * This is called with "Working..." by resetProgressAndMessage 077 */ 078 public void resetProgresAndWorkingMessage(String par1Str) 079 { 080 if (!this.mc.running) 081 { 082 if (!this.field_73724_e) 083 { 084 throw new MinecraftError(); 085 } 086 } 087 else 088 { 089 this.field_73723_d = 0L; 090 this.field_73727_a = par1Str; 091 this.setLoadingProgress(-1); 092 this.field_73723_d = 0L; 093 } 094 } 095 096 /** 097 * Updates the progress bar on the loading screen to the specified amount. Args: loadProgress 098 */ 099 public void setLoadingProgress(int par1) 100 { 101 if (!this.mc.running) 102 { 103 if (!this.field_73724_e) 104 { 105 throw new MinecraftError(); 106 } 107 } 108 else 109 { 110 long j = Minecraft.getSystemTime(); 111 112 if (j - this.field_73723_d >= 100L) 113 { 114 this.field_73723_d = j; 115 ScaledResolution scaledresolution = new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight); 116 int k = scaledresolution.getScaledWidth(); 117 int l = scaledresolution.getScaledHeight(); 118 GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); 119 GL11.glMatrixMode(GL11.GL_PROJECTION); 120 GL11.glLoadIdentity(); 121 GL11.glOrtho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 100.0D, 300.0D); 122 GL11.glMatrixMode(GL11.GL_MODELVIEW); 123 GL11.glLoadIdentity(); 124 GL11.glTranslatef(0.0F, 0.0F, -200.0F); 125 GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); 126 Tessellator tessellator = Tessellator.instance; 127 this.mc.renderEngine.func_98187_b("/gui/background.png"); 128 float f = 32.0F; 129 tessellator.startDrawingQuads(); 130 tessellator.setColorOpaque_I(4210752); 131 tessellator.addVertexWithUV(0.0D, (double)l, 0.0D, 0.0D, (double)((float)l / f)); 132 tessellator.addVertexWithUV((double)k, (double)l, 0.0D, (double)((float)k / f), (double)((float)l / f)); 133 tessellator.addVertexWithUV((double)k, 0.0D, 0.0D, (double)((float)k / f), 0.0D); 134 tessellator.addVertexWithUV(0.0D, 0.0D, 0.0D, 0.0D, 0.0D); 135 tessellator.draw(); 136 137 if (par1 >= 0) 138 { 139 byte b0 = 100; 140 byte b1 = 2; 141 int i1 = k / 2 - b0 / 2; 142 int j1 = l / 2 + 16; 143 GL11.glDisable(GL11.GL_TEXTURE_2D); 144 tessellator.startDrawingQuads(); 145 tessellator.setColorOpaque_I(8421504); 146 tessellator.addVertex((double)i1, (double)j1, 0.0D); 147 tessellator.addVertex((double)i1, (double)(j1 + b1), 0.0D); 148 tessellator.addVertex((double)(i1 + b0), (double)(j1 + b1), 0.0D); 149 tessellator.addVertex((double)(i1 + b0), (double)j1, 0.0D); 150 tessellator.setColorOpaque_I(8454016); 151 tessellator.addVertex((double)i1, (double)j1, 0.0D); 152 tessellator.addVertex((double)i1, (double)(j1 + b1), 0.0D); 153 tessellator.addVertex((double)(i1 + par1), (double)(j1 + b1), 0.0D); 154 tessellator.addVertex((double)(i1 + par1), (double)j1, 0.0D); 155 tessellator.draw(); 156 GL11.glEnable(GL11.GL_TEXTURE_2D); 157 } 158 159 this.mc.fontRenderer.drawStringWithShadow(this.currentlyDisplayedText, (k - this.mc.fontRenderer.getStringWidth(this.currentlyDisplayedText)) / 2, l / 2 - 4 - 16, 16777215); 160 this.mc.fontRenderer.drawStringWithShadow(this.field_73727_a, (k - this.mc.fontRenderer.getStringWidth(this.field_73727_a)) / 2, l / 2 - 4 + 8, 16777215); 161 Display.update(); 162 163 try 164 { 165 Thread.yield(); 166 } 167 catch (Exception exception) 168 { 169 ; 170 } 171 } 172 } 173 } 174 175 /** 176 * called when there is no more progress to be had, both on completion and failure 177 */ 178 public void onNoMoreProgress() {} 179}