    001    package net.minecraft.client.gui;
    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.renderer.Tessellator;
    007    import net.minecraft.util.IProgressUpdate;
    008    import net.minecraft.util.MinecraftError;
    009    import org.lwjgl.opengl.Display;
    010    import org.lwjgl.opengl.GL11;
    011
    012    @SideOnly(Side.CLIENT)
    013    public 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 var2 = new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight);
    065                GL11.glClear(256);
    066                GL11.glMatrixMode(GL11.GL_PROJECTION);
    067                GL11.glLoadIdentity();
    068                GL11.glOrtho(0.0D, var2.getScaledWidth_double(), var2.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 var2 = Minecraft.getSystemTime();
    111
    112                if (var2 - this.field_73723_d >= 100L)
    113                {
    114                    this.field_73723_d = var2;
    115                    ScaledResolution var4 = new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight);
    116                    int var5 = var4.getScaledWidth();
    117                    int var6 = var4.getScaledHeight();
    118                    GL11.glClear(256);
    119                    GL11.glMatrixMode(GL11.GL_PROJECTION);
    120                    GL11.glLoadIdentity();
    121                    GL11.glOrtho(0.0D, var4.getScaledWidth_double(), var4.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(16640);
    126                    Tessellator var7 = Tessellator.instance;
    127                    int var8 = this.mc.renderEngine.getTexture("/gui/background.png");
    128                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, var8);
    129                    float var9 = 32.0F;
    130                    var7.startDrawingQuads();
    131                    var7.setColorOpaque_I(4210752);
    132                    var7.addVertexWithUV(0.0D, (double)var6, 0.0D, 0.0D, (double)((float)var6 / var9));
    133                    var7.addVertexWithUV((double)var5, (double)var6, 0.0D, (double)((float)var5 / var9), (double)((float)var6 / var9));
    134                    var7.addVertexWithUV((double)var5, 0.0D, 0.0D, (double)((float)var5 / var9), 0.0D);
    135                    var7.addVertexWithUV(0.0D, 0.0D, 0.0D, 0.0D, 0.0D);
    136                    var7.draw();
    137
    138                    if (par1 >= 0)
    139                    {
    140                        byte var10 = 100;
    141                        byte var11 = 2;
    142                        int var12 = var5 / 2 - var10 / 2;
    143                        int var13 = var6 / 2 + 16;
    144                        GL11.glDisable(GL11.GL_TEXTURE_2D);
    145                        var7.startDrawingQuads();
    146                        var7.setColorOpaque_I(8421504);
    147                        var7.addVertex((double)var12, (double)var13, 0.0D);
    148                        var7.addVertex((double)var12, (double)(var13 + var11), 0.0D);
    149                        var7.addVertex((double)(var12 + var10), (double)(var13 + var11), 0.0D);
    150                        var7.addVertex((double)(var12 + var10), (double)var13, 0.0D);
    151                        var7.setColorOpaque_I(8454016);
    152                        var7.addVertex((double)var12, (double)var13, 0.0D);
    153                        var7.addVertex((double)var12, (double)(var13 + var11), 0.0D);
    154                        var7.addVertex((double)(var12 + par1), (double)(var13 + var11), 0.0D);
    155                        var7.addVertex((double)(var12 + par1), (double)var13, 0.0D);
    156                        var7.draw();
    157                        GL11.glEnable(GL11.GL_TEXTURE_2D);
    158                    }
    159
    160                    this.mc.fontRenderer.drawStringWithShadow(this.currentlyDisplayedText, (var5 - this.mc.fontRenderer.getStringWidth(this.currentlyDisplayedText)) / 2, var6 / 2 - 4 - 16, 16777215);
    161                    this.mc.fontRenderer.drawStringWithShadow(this.field_73727_a, (var5 - this.mc.fontRenderer.getStringWidth(this.field_73727_a)) / 2, var6 / 2 - 4 + 8, 16777215);
    162                    Display.update();
    163
    164                    try
    165                    {
    166                        Thread.yield();
    167                    }
    168                    catch (Exception var14)
    169                    {
    170                        ;
    171                    }
    172                }
    173            }
    174        }
    175
    176        /**
    177         * called when there is no more progress to be had, both on completion and failure
    178         */
    179        public void onNoMoreProgress() {}
    180    }