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.renderer.entity.RenderItem;
006    import net.minecraft.util.StatCollector;
007    import net.minecraft.world.gen.FlatGeneratorInfo;
008    
009    @SideOnly(Side.CLIENT)
010    public class GuiCreateFlatWorld extends GuiScreen
011    {
012        private static RenderItem theRenderItem = new RenderItem();
013        private final GuiCreateWorld createWorldGui;
014        private FlatGeneratorInfo theFlatGeneratorInfo = FlatGeneratorInfo.getDefaultFlatGenerator();
015        private String customizationTitle;
016        private String layerMaterialLabel;
017        private String heightLabel;
018        private GuiCreateFlatWorldListSlot createFlatWorldListSlotGui;
019        private GuiButton buttonAddLayer;
020        private GuiButton buttonEditLayer;
021        private GuiButton buttonRemoveLayer;
022    
023        public GuiCreateFlatWorld(GuiCreateWorld par1, String par2Str)
024        {
025            this.createWorldGui = par1;
026            this.setFlatGeneratorInfo(par2Str);
027        }
028    
029        public String getFlatGeneratorInfo()
030        {
031            return this.theFlatGeneratorInfo.toString();
032        }
033    
034        public void setFlatGeneratorInfo(String par1Str)
035        {
036            this.theFlatGeneratorInfo = FlatGeneratorInfo.createFlatGeneratorFromString(par1Str);
037        }
038    
039        /**
040         * Adds the buttons (and other controls) to the screen in question.
041         */
042        public void initGui()
043        {
044            this.controlList.clear();
045            this.customizationTitle = StatCollector.translateToLocal("createWorld.customize.flat.title");
046            this.layerMaterialLabel = StatCollector.translateToLocal("createWorld.customize.flat.tile");
047            this.heightLabel = StatCollector.translateToLocal("createWorld.customize.flat.height");
048            this.createFlatWorldListSlotGui = new GuiCreateFlatWorldListSlot(this);
049            this.controlList.add(this.buttonAddLayer = new GuiButton(2, this.width / 2 - 154, this.height - 52, 100, 20, StatCollector.translateToLocal("createWorld.customize.flat.addLayer") + " (NYI)"));
050            this.controlList.add(this.buttonEditLayer = new GuiButton(3, this.width / 2 - 50, this.height - 52, 100, 20, StatCollector.translateToLocal("createWorld.customize.flat.editLayer") + " (NYI)"));
051            this.controlList.add(this.buttonRemoveLayer = new GuiButton(4, this.width / 2 - 155, this.height - 52, 150, 20, StatCollector.translateToLocal("createWorld.customize.flat.removeLayer")));
052            this.controlList.add(new GuiButton(0, this.width / 2 - 155, this.height - 28, 150, 20, StatCollector.translateToLocal("gui.done")));
053            this.controlList.add(new GuiButton(5, this.width / 2 + 5, this.height - 52, 150, 20, StatCollector.translateToLocal("createWorld.customize.presets")));
054            this.controlList.add(new GuiButton(1, this.width / 2 + 5, this.height - 28, 150, 20, StatCollector.translateToLocal("gui.cancel")));
055            this.buttonAddLayer.drawButton = this.buttonEditLayer.drawButton = false;
056            this.theFlatGeneratorInfo.func_82645_d();
057            this.func_82270_g();
058        }
059    
060        /**
061         * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
062         */
063        protected void actionPerformed(GuiButton par1GuiButton)
064        {
065            int var2 = this.theFlatGeneratorInfo.getFlatLayers().size() - this.createFlatWorldListSlotGui.field_82454_a - 1;
066    
067            if (par1GuiButton.id == 1)
068            {
069                this.mc.displayGuiScreen(this.createWorldGui);
070            }
071            else if (par1GuiButton.id == 0)
072            {
073                this.createWorldGui.field_82290_a = this.getFlatGeneratorInfo();
074                this.mc.displayGuiScreen(this.createWorldGui);
075            }
076            else if (par1GuiButton.id == 5)
077            {
078                this.mc.displayGuiScreen(new GuiFlatPresets(this));
079            }
080            else if (par1GuiButton.id == 4 && this.func_82272_i())
081            {
082                this.theFlatGeneratorInfo.getFlatLayers().remove(var2);
083                this.createFlatWorldListSlotGui.field_82454_a = Math.min(this.createFlatWorldListSlotGui.field_82454_a, this.theFlatGeneratorInfo.getFlatLayers().size() - 1);
084            }
085    
086            this.theFlatGeneratorInfo.func_82645_d();
087            this.func_82270_g();
088        }
089    
090        public void func_82270_g()
091        {
092            boolean var1 = this.func_82272_i();
093            this.buttonRemoveLayer.enabled = var1;
094            this.buttonEditLayer.enabled = var1;
095            this.buttonEditLayer.enabled = false;
096            this.buttonAddLayer.enabled = false;
097        }
098    
099        private boolean func_82272_i()
100        {
101            return this.createFlatWorldListSlotGui.field_82454_a > -1 && this.createFlatWorldListSlotGui.field_82454_a < this.theFlatGeneratorInfo.getFlatLayers().size();
102        }
103    
104        /**
105         * Draws the screen and all the components in it.
106         */
107        public void drawScreen(int par1, int par2, float par3)
108        {
109            this.drawDefaultBackground();
110            this.createFlatWorldListSlotGui.drawScreen(par1, par2, par3);
111            this.drawCenteredString(this.fontRenderer, this.customizationTitle, this.width / 2, 8, 16777215);
112            int var4 = this.width / 2 - 92 - 16;
113            this.drawString(this.fontRenderer, this.layerMaterialLabel, var4, 32, 16777215);
114            this.drawString(this.fontRenderer, this.heightLabel, var4 + 2 + 213 - this.fontRenderer.getStringWidth(this.heightLabel), 32, 16777215);
115            super.drawScreen(par1, par2, par3);
116        }
117    
118        static RenderItem getRenderItem()
119        {
120            return theRenderItem;
121        }
122    
123        static FlatGeneratorInfo func_82271_a(GuiCreateFlatWorld par0GuiCreateFlatWorld)
124        {
125            return par0GuiCreateFlatWorld.theFlatGeneratorInfo;
126        }
127    }