001package net.minecraft.client.gui;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import net.minecraft.client.renderer.entity.RenderItem;
006import net.minecraft.util.StatCollector;
007import net.minecraft.world.gen.FlatGeneratorInfo;
008
009@SideOnly(Side.CLIENT)
010public 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 par1GuiCreateWorld, String par2Str)
024    {
025        this.createWorldGui = par1GuiCreateWorld;
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.buttonList.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.buttonList.add(this.buttonAddLayer = new GuiButton(2, this.width / 2 - 154, this.height - 52, 100, 20, StatCollector.translateToLocal("createWorld.customize.flat.addLayer") + " (NYI)"));
050        this.buttonList.add(this.buttonEditLayer = new GuiButton(3, this.width / 2 - 50, this.height - 52, 100, 20, StatCollector.translateToLocal("createWorld.customize.flat.editLayer") + " (NYI)"));
051        this.buttonList.add(this.buttonRemoveLayer = new GuiButton(4, this.width / 2 - 155, this.height - 52, 150, 20, StatCollector.translateToLocal("createWorld.customize.flat.removeLayer")));
052        this.buttonList.add(new GuiButton(0, this.width / 2 - 155, this.height - 28, 150, 20, StatCollector.translateToLocal("gui.done")));
053        this.buttonList.add(new GuiButton(5, this.width / 2 + 5, this.height - 52, 150, 20, StatCollector.translateToLocal("createWorld.customize.presets")));
054        this.buttonList.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 i = 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.generatorOptionsToUse = 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(i);
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 flag = this.func_82272_i();
093        this.buttonRemoveLayer.enabled = flag;
094        this.buttonEditLayer.enabled = flag;
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 k = this.width / 2 - 92 - 16;
113        this.drawString(this.fontRenderer, this.layerMaterialLabel, k, 32, 16777215);
114        this.drawString(this.fontRenderer, this.heightLabel, k + 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}