001package net.minecraft.client.gui;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import java.util.ArrayList;
006import java.util.Arrays;
007import java.util.HashMap;
008import java.util.Iterator;
009import java.util.List;
010import net.minecraft.block.Block;
011import net.minecraft.client.renderer.entity.RenderItem;
012import net.minecraft.item.Item;
013import net.minecraft.util.StatCollector;
014import net.minecraft.world.biome.BiomeGenBase;
015import net.minecraft.world.gen.FlatGeneratorInfo;
016import net.minecraft.world.gen.FlatLayerInfo;
017import org.lwjgl.input.Keyboard;
018
019@SideOnly(Side.CLIENT)
020public class GuiFlatPresets extends GuiScreen
021{
022    /** RenderItem instance used to render preset icons. */
023    private static RenderItem presetIconRenderer = new RenderItem();
024
025    /** List of defined flat world presets. */
026    private static final List presets = new ArrayList();
027    private final GuiCreateFlatWorld createFlatWorldGui;
028    private String field_82300_d;
029    private String field_82308_m;
030    private String field_82306_n;
031    private GuiFlatPresetsListSlot theFlatPresetsListSlot;
032    private GuiButton theButton;
033    private GuiTextField theTextField;
034
035    public GuiFlatPresets(GuiCreateFlatWorld par1)
036    {
037        this.createFlatWorldGui = par1;
038    }
039
040    /**
041     * Adds the buttons (and other controls) to the screen in question.
042     */
043    public void initGui()
044    {
045        this.controlList.clear();
046        Keyboard.enableRepeatEvents(true);
047        this.field_82300_d = StatCollector.translateToLocal("createWorld.customize.presets.title");
048        this.field_82308_m = StatCollector.translateToLocal("createWorld.customize.presets.share");
049        this.field_82306_n = StatCollector.translateToLocal("createWorld.customize.presets.list");
050        this.theTextField = new GuiTextField(this.fontRenderer, 50, 40, this.width - 100, 20);
051        this.theFlatPresetsListSlot = new GuiFlatPresetsListSlot(this);
052        this.theTextField.setMaxStringLength(1230);
053        this.theTextField.setText(this.createFlatWorldGui.getFlatGeneratorInfo());
054        this.controlList.add(this.theButton = new GuiButton(0, this.width / 2 - 155, this.height - 28, 150, 20, StatCollector.translateToLocal("createWorld.customize.presets.select")));
055        this.controlList.add(new GuiButton(1, this.width / 2 + 5, this.height - 28, 150, 20, StatCollector.translateToLocal("gui.cancel")));
056        this.func_82296_g();
057    }
058
059    /**
060     * Called when the screen is unloaded. Used to disable keyboard repeat events
061     */
062    public void onGuiClosed()
063    {
064        Keyboard.enableRepeatEvents(false);
065    }
066
067    /**
068     * Called when the mouse is clicked.
069     */
070    protected void mouseClicked(int par1, int par2, int par3)
071    {
072        this.theTextField.mouseClicked(par1, par2, par3);
073        super.mouseClicked(par1, par2, par3);
074    }
075
076    /**
077     * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
078     */
079    protected void keyTyped(char par1, int par2)
080    {
081        if (!this.theTextField.textboxKeyTyped(par1, par2))
082        {
083            super.keyTyped(par1, par2);
084        }
085    }
086
087    /**
088     * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
089     */
090    protected void actionPerformed(GuiButton par1GuiButton)
091    {
092        if (par1GuiButton.id == 0 && this.func_82293_j())
093        {
094            this.createFlatWorldGui.setFlatGeneratorInfo(this.theTextField.getText());
095            this.mc.displayGuiScreen(this.createFlatWorldGui);
096        }
097        else if (par1GuiButton.id == 1)
098        {
099            this.mc.displayGuiScreen(this.createFlatWorldGui);
100        }
101    }
102
103    /**
104     * Draws the screen and all the components in it.
105     */
106    public void drawScreen(int par1, int par2, float par3)
107    {
108        this.drawDefaultBackground();
109        this.theFlatPresetsListSlot.drawScreen(par1, par2, par3);
110        this.drawCenteredString(this.fontRenderer, this.field_82300_d, this.width / 2, 8, 16777215);
111        this.drawString(this.fontRenderer, this.field_82308_m, 50, 30, 10526880);
112        this.drawString(this.fontRenderer, this.field_82306_n, 50, 70, 10526880);
113        this.theTextField.drawTextBox();
114        super.drawScreen(par1, par2, par3);
115    }
116
117    /**
118     * Called from the main game loop to update the screen.
119     */
120    public void updateScreen()
121    {
122        this.theTextField.updateCursorCounter();
123        super.updateScreen();
124    }
125
126    public void func_82296_g()
127    {
128        boolean var1 = this.func_82293_j();
129        this.theButton.enabled = var1;
130    }
131
132    private boolean func_82293_j()
133    {
134        return this.theFlatPresetsListSlot.field_82459_a > -1 && this.theFlatPresetsListSlot.field_82459_a < presets.size() || this.theTextField.getText().length() > 1;
135    }
136
137    /**
138     * Add a flat world preset with no world features.
139     */
140    public static void addPresetNoFeatures(String par0Str, int par1, BiomeGenBase par2BiomeGenBase, FlatLayerInfo ... par3ArrayOfFlatLayerInfo)
141    {
142        addPreset(par0Str, par1, par2BiomeGenBase, (List)null, par3ArrayOfFlatLayerInfo);
143    }
144
145    /**
146     * Add a flat world preset.
147     */
148    public static void addPreset(String par0Str, int par1, BiomeGenBase par2BiomeGenBase, List par3List, FlatLayerInfo ... par4ArrayOfFlatLayerInfo)
149    {
150        FlatGeneratorInfo var5 = new FlatGeneratorInfo();
151
152        for (int var6 = par4ArrayOfFlatLayerInfo.length - 1; var6 >= 0; --var6)
153        {
154            var5.getFlatLayers().add(par4ArrayOfFlatLayerInfo[var6]);
155        }
156
157        var5.setBiome(par2BiomeGenBase.biomeID);
158        var5.func_82645_d();
159
160        if (par3List != null)
161        {
162            Iterator var8 = par3List.iterator();
163
164            while (var8.hasNext())
165            {
166                String var7 = (String)var8.next();
167                var5.getWorldFeatures().put(var7, new HashMap());
168            }
169        }
170
171        presets.add(new GuiFlatPresetsItem(par1, par0Str, var5.toString()));
172    }
173
174    /**
175     * Return the RenderItem instance used to render preset icons.
176     */
177    static RenderItem getPresetIconRenderer()
178    {
179        return presetIconRenderer;
180    }
181
182    /**
183     * Return the list of defined flat world presets.
184     */
185    static List getPresets()
186    {
187        return presets;
188    }
189
190    static GuiFlatPresetsListSlot func_82292_a(GuiFlatPresets par0GuiFlatPresets)
191    {
192        return par0GuiFlatPresets.theFlatPresetsListSlot;
193    }
194
195    static GuiTextField func_82298_b(GuiFlatPresets par0GuiFlatPresets)
196    {
197        return par0GuiFlatPresets.theTextField;
198    }
199
200    static
201    {
202        addPreset("Classic Flat", Block.grass.blockID, BiomeGenBase.plains, Arrays.asList(new String[] {"village"}), new FlatLayerInfo[] {new FlatLayerInfo(1, Block.grass.blockID), new FlatLayerInfo(2, Block.dirt.blockID), new FlatLayerInfo(1, Block.bedrock.blockID)});
203        addPreset("Tunnelers\' Dream", Block.stone.blockID, BiomeGenBase.extremeHills, Arrays.asList(new String[] {"biome_1", "dungeon", "decoration", "stronghold", "mineshaft"}), new FlatLayerInfo[] {new FlatLayerInfo(1, Block.grass.blockID), new FlatLayerInfo(5, Block.dirt.blockID), new FlatLayerInfo(230, Block.stone.blockID), new FlatLayerInfo(1, Block.bedrock.blockID)});
204        addPreset("Water World", Block.waterMoving.blockID, BiomeGenBase.plains, Arrays.asList(new String[] {"village", "biome_1"}), new FlatLayerInfo[] {new FlatLayerInfo(90, Block.waterStill.blockID), new FlatLayerInfo(5, Block.sand.blockID), new FlatLayerInfo(5, Block.dirt.blockID), new FlatLayerInfo(5, Block.stone.blockID), new FlatLayerInfo(1, Block.bedrock.blockID)});
205        addPreset("Overworld", Block.tallGrass.blockID, BiomeGenBase.plains, Arrays.asList(new String[] {"village", "biome_1", "decoration", "stronghold", "mineshaft", "dungeon", "lake", "lava_lake"}), new FlatLayerInfo[] {new FlatLayerInfo(1, Block.grass.blockID), new FlatLayerInfo(3, Block.dirt.blockID), new FlatLayerInfo(59, Block.stone.blockID), new FlatLayerInfo(1, Block.bedrock.blockID)});
206        addPreset("Snowy Kingdom", Block.snow.blockID, BiomeGenBase.icePlains, Arrays.asList(new String[] {"village", "biome_1"}), new FlatLayerInfo[] {new FlatLayerInfo(1, Block.snow.blockID), new FlatLayerInfo(1, Block.grass.blockID), new FlatLayerInfo(3, Block.dirt.blockID), new FlatLayerInfo(59, Block.stone.blockID), new FlatLayerInfo(1, Block.bedrock.blockID)});
207        addPreset("Bottomless Pit", Item.feather.itemID, BiomeGenBase.plains, Arrays.asList(new String[] {"village", "biome_1"}), new FlatLayerInfo[] {new FlatLayerInfo(1, Block.grass.blockID), new FlatLayerInfo(3, Block.dirt.blockID), new FlatLayerInfo(2, Block.cobblestone.blockID)});
208        addPreset("Desert", Block.sand.blockID, BiomeGenBase.desert, Arrays.asList(new String[] {"village", "biome_1", "decoration", "stronghold", "mineshaft", "dungeon"}), new FlatLayerInfo[] {new FlatLayerInfo(8, Block.sand.blockID), new FlatLayerInfo(52, Block.sandStone.blockID), new FlatLayerInfo(3, Block.stone.blockID), new FlatLayerInfo(1, Block.bedrock.blockID)});
209        addPresetNoFeatures("Redstone Ready", Item.redstone.itemID, BiomeGenBase.desert, new FlatLayerInfo[] {new FlatLayerInfo(52, Block.sandStone.blockID), new FlatLayerInfo(3, Block.stone.blockID), new FlatLayerInfo(1, Block.bedrock.blockID)});
210    }
211}