    001package net.minecraft.client.gui;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.net.URI;
    006import net.minecraft.client.settings.GameSettings;
    007import net.minecraft.util.StatCollector;
    008import org.lwjgl.input.Keyboard;
    009import org.lwjgl.opengl.GL11;
    010
    011@SideOnly(Side.CLIENT)
    012public class GuiScreenDemo extends GuiScreen
    013{
    014    /**
    015     * Adds the buttons (and other controls) to the screen in question.
    016     */
    017    public void initGui()
    018    {
    019        this.buttonList.clear();
    020        byte b0 = -16;
    021        this.buttonList.add(new GuiButton(1, this.width / 2 - 116, this.height / 2 + 62 + b0, 114, 20, StatCollector.translateToLocal("demo.help.buy")));
    022        this.buttonList.add(new GuiButton(2, this.width / 2 + 2, this.height / 2 + 62 + b0, 114, 20, StatCollector.translateToLocal("demo.help.later")));
    023    }
    024
    025    /**
    026     * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    027     */
    028    protected void actionPerformed(GuiButton par1GuiButton)
    029    {
    030        switch (par1GuiButton.id)
    031        {
    032            case 1:
    033                par1GuiButton.enabled = false;
    034
    035                try
    036                {
    037                    Class oclass = Class.forName("java.awt.Desktop");
    038                    Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
    039                    oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {new URI("http://www.minecraft.net/store?source=demo")});
    040                }
    041                catch (Throwable throwable)
    042                {
    043                    throwable.printStackTrace();
    044                }
    045
    046                break;
    047            case 2:
    048                this.mc.displayGuiScreen((GuiScreen)null);
    049                this.mc.setIngameFocus();
    050        }
    051    }
    052
    053    /**
    054     * Called from the main game loop to update the screen.
    055     */
    056    public void updateScreen()
    057    {
    058        super.updateScreen();
    059    }
    060
    061    /**
    062     * Draws either a gradient over the background screen (when it exists) or a flat gradient over background.png
    063     */
    064    public void drawDefaultBackground()
    065    {
    066        super.drawDefaultBackground();
    067        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    068        this.mc.renderEngine.bindTexture("/gui/demo_bg.png");
    069        int i = (this.width - 248) / 2;
    070        int j = (this.height - 166) / 2;
    071        this.drawTexturedModalRect(i, j, 0, 0, 248, 166);
    072    }
    073
    074    /**
    075     * Draws the screen and all the components in it.
    076     */
    077    public void drawScreen(int par1, int par2, float par3)
    078    {
    079        this.drawDefaultBackground();
    080        int k = (this.width - 248) / 2 + 10;
    081        int l = (this.height - 166) / 2 + 8;
    082        this.fontRenderer.drawString(StatCollector.translateToLocal("demo.help.title"), k, l, 2039583);
    083        l += 12;
    084        GameSettings gamesettings = this.mc.gameSettings;
    085        String s = StatCollector.translateToLocal("demo.help.movementShort");
    086        s = String.format(s, new Object[] {Keyboard.getKeyName(gamesettings.keyBindForward.keyCode), Keyboard.getKeyName(gamesettings.keyBindLeft.keyCode), Keyboard.getKeyName(gamesettings.keyBindBack.keyCode), Keyboard.getKeyName(gamesettings.keyBindRight.keyCode)});
    087        this.fontRenderer.drawString(s, k, l, 5197647);
    088        s = StatCollector.translateToLocal("demo.help.movementMouse");
    089        this.fontRenderer.drawString(s, k, l + 12, 5197647);
    090        s = StatCollector.translateToLocal("demo.help.jump");
    091        s = String.format(s, new Object[] {Keyboard.getKeyName(gamesettings.keyBindJump.keyCode)});
    092        this.fontRenderer.drawString(s, k, l + 24, 5197647);
    093        s = StatCollector.translateToLocal("demo.help.inventory");
    094        s = String.format(s, new Object[] {Keyboard.getKeyName(gamesettings.keyBindInventory.keyCode)});
    095        this.fontRenderer.drawString(s, k, l + 36, 5197647);
    096        this.fontRenderer.drawSplitString(StatCollector.translateToLocal("demo.help.fullWrapped"), k, l + 68, 218, 2039583);
    097        super.drawScreen(par1, par2, par3);
    098    }
    099}