    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005
    006    @SideOnly(Side.CLIENT)
    007    public class GuiShareToLan extends GuiScreen
    008    {
    009        /**
    010         * A reference to the screen object that created this. Used for navigating between screens.
    011         */
    012        private final GuiScreen parentScreen;
    013        private GuiButton buttonAllowCommandsToggle;
    014        private GuiButton buttonGameMode;
    015
    016        /**
    017         * The currently selected game mode. One of 'survival', 'creative', or 'adventure'
    018         */
    019        private String gameMode = "survival";
    020
    021        /** True if 'Allow Cheats' is currently enabled */
    022        private boolean allowCommands = false;
    023
    024        public GuiShareToLan(GuiScreen par1GuiScreen)
    025        {
    026            this.parentScreen = par1GuiScreen;
    027        }
    028
    029        /**
    030         * Adds the buttons (and other controls) to the screen in question.
    031         */
    032        public void initGui()
    033        {
    034            this.controlList.clear();
    035            this.controlList.add(new GuiButton(101, this.width / 2 - 155, this.height - 28, 150, 20, StatCollector.translateToLocal("lanServer.start")));
    036            this.controlList.add(new GuiButton(102, this.width / 2 + 5, this.height - 28, 150, 20, StatCollector.translateToLocal("gui.cancel")));
    037            this.controlList.add(this.buttonGameMode = new GuiButton(104, this.width / 2 - 155, 100, 150, 20, StatCollector.translateToLocal("selectWorld.gameMode")));
    038            this.controlList.add(this.buttonAllowCommandsToggle = new GuiButton(103, this.width / 2 + 5, 100, 150, 20, StatCollector.translateToLocal("selectWorld.allowCommands")));
    039            this.func_74088_g();
    040        }
    041
    042        private void func_74088_g()
    043        {
    044            StringTranslate var1 = StringTranslate.getInstance();
    045            this.buttonGameMode.displayString = var1.translateKey("selectWorld.gameMode") + " " + var1.translateKey("selectWorld.gameMode." + this.gameMode);
    046            this.buttonAllowCommandsToggle.displayString = var1.translateKey("selectWorld.allowCommands") + " ";
    047
    048            if (this.allowCommands)
    049            {
    050                this.buttonAllowCommandsToggle.displayString = this.buttonAllowCommandsToggle.displayString + var1.translateKey("options.on");
    051            }
    052            else
    053            {
    054                this.buttonAllowCommandsToggle.displayString = this.buttonAllowCommandsToggle.displayString + var1.translateKey("options.off");
    055            }
    056        }
    057
    058        /**
    059         * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    060         */
    061        protected void actionPerformed(GuiButton par1GuiButton)
    062        {
    063            if (par1GuiButton.id == 102)
    064            {
    065                this.mc.displayGuiScreen(this.parentScreen);
    066            }
    067            else if (par1GuiButton.id == 104)
    068            {
    069                if (this.gameMode.equals("survival"))
    070                {
    071                    this.gameMode = "creative";
    072                }
    073                else if (this.gameMode.equals("creative"))
    074                {
    075                    this.gameMode = "adventure";
    076                }
    077                else
    078                {
    079                    this.gameMode = "survival";
    080                }
    081
    082                this.func_74088_g();
    083            }
    084            else if (par1GuiButton.id == 103)
    085            {
    086                this.allowCommands = !this.allowCommands;
    087                this.func_74088_g();
    088            }
    089            else if (par1GuiButton.id == 101)
    090            {
    091                this.mc.displayGuiScreen((GuiScreen)null);
    092                String var2 = this.mc.getIntegratedServer().shareToLAN(EnumGameType.getByName(this.gameMode), this.allowCommands);
    093                String var3 = "";
    094
    095                if (var2 != null)
    096                {
    097                    var3 = this.mc.thePlayer.translateString("commands.publish.started", new Object[] {var2});
    098                }
    099                else
    100                {
    101                    var3 = this.mc.thePlayer.translateString("commands.publish.failed", new Object[0]);
    102                }
    103
    104                this.mc.ingameGUI.getChatGUI().printChatMessage(var3);
    105            }
    106        }
    107
    108        /**
    109         * Draws the screen and all the components in it.
    110         */
    111        public void drawScreen(int par1, int par2, float par3)
    112        {
    113            this.drawDefaultBackground();
    114            this.drawCenteredString(this.fontRenderer, StatCollector.translateToLocal("lanServer.title"), this.width / 2, 50, 16777215);
    115            this.drawCenteredString(this.fontRenderer, StatCollector.translateToLocal("lanServer.otherPlayers"), this.width / 2, 82, 16777215);
    116            super.drawScreen(par1, par2, par3);
    117        }
    118    }