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