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