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