    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.awt.Toolkit;
    006    import java.awt.datatransfer.ClipboardOwner;
    007    import java.awt.datatransfer.DataFlavor;
    008    import java.awt.datatransfer.StringSelection;
    009    import java.awt.datatransfer.Transferable;
    010    import java.util.ArrayList;
    011    import java.util.List;
    012    import net.minecraft.client.Minecraft;
    013    import org.lwjgl.input.Keyboard;
    014    import org.lwjgl.input.Mouse;
    015    import org.lwjgl.opengl.GL11;
    016
    017    @SideOnly(Side.CLIENT)
    018    public class GuiScreen extends Gui
    019    {
    020        public static final boolean field_90017_e = Minecraft.getOs() == EnumOS.MACOS;
    021
    022        /** Reference to the Minecraft object. */
    023        protected Minecraft mc;
    024
    025        /** The width of the screen object. */
    026        public int width;
    027
    028        /** The height of the screen object. */
    029        public int height;
    030
    031        /** A list of all the controls added to this container. */
    032        protected List controlList = new ArrayList();
    033        public boolean allowUserInput = false;
    034
    035        /** The FontRenderer used by GuiScreen */
    036        protected FontRenderer fontRenderer;
    037        public GuiParticle guiParticles;
    038
    039        /** The button that was just pressed. */
    040        private GuiButton selectedButton = null;
    041        private int field_85042_b = 0;
    042        private long field_85043_c = 0L;
    043
    044        /**
    045         * Draws the screen and all the components in it.
    046         */
    047        public void drawScreen(int par1, int par2, float par3)
    048        {
    049            for (int var4 = 0; var4 < this.controlList.size(); ++var4)
    050            {
    051                GuiButton var5 = (GuiButton)this.controlList.get(var4);
    052                var5.drawButton(this.mc, par1, par2);
    053            }
    054        }
    055
    056        /**
    057         * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
    058         */
    059        protected void keyTyped(char par1, int par2)
    060        {
    061            if (par2 == 1)
    062            {
    063                this.mc.displayGuiScreen((GuiScreen)null);
    064                this.mc.setIngameFocus();
    065            }
    066        }
    067
    068        /**
    069         * Returns a string stored in the system clipboard.
    070         */
    071        public static String getClipboardString()
    072        {
    073            try
    074            {
    075                Transferable var0 = Toolkit.getDefaultToolkit().getSystemClipboard().getContents((Object)null);
    076
    077                if (var0 != null && var0.isDataFlavorSupported(DataFlavor.stringFlavor))
    078                {
    079                    return (String)var0.getTransferData(DataFlavor.stringFlavor);
    080                }
    081            }
    082            catch (Exception var1)
    083            {
    084                ;
    085            }
    086
    087            return "";
    088        }
    089
    090        /**
    091         * store a string in the system clipboard
    092         */
    093        public static void setClipboardString(String par0Str)
    094        {
    095            try
    096            {
    097                StringSelection var1 = new StringSelection(par0Str);
    098                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(var1, (ClipboardOwner)null);
    099            }
    100            catch (Exception var2)
    101            {
    102                ;
    103            }
    104        }
    105
    106        /**
    107         * Called when the mouse is clicked.
    108         */
    109        protected void mouseClicked(int par1, int par2, int par3)
    110        {
    111            if (par3 == 0)
    112            {
    113                for (int var4 = 0; var4 < this.controlList.size(); ++var4)
    114                {
    115                    GuiButton var5 = (GuiButton)this.controlList.get(var4);
    116
    117                    if (var5.mousePressed(this.mc, par1, par2))
    118                    {
    119                        this.selectedButton = var5;
    120                        this.mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
    121                        this.actionPerformed(var5);
    122                    }
    123                }
    124            }
    125        }
    126
    127        /**
    128         * Called when the mouse is moved or a mouse button is released.  Signature: (mouseX, mouseY, which) which==-1 is
    129         * mouseMove, which==0 or which==1 is mouseUp
    130         */
    131        protected void mouseMovedOrUp(int par1, int par2, int par3)
    132        {
    133            if (this.selectedButton != null && par3 == 0)
    134            {
    135                this.selectedButton.mouseReleased(par1, par2);
    136                this.selectedButton = null;
    137            }
    138        }
    139
    140        protected void func_85041_a(int par1, int par2, int par3, long par4) {}
    141
    142        /**
    143         * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    144         */
    145        protected void actionPerformed(GuiButton par1GuiButton) {}
    146
    147        /**
    148         * Causes the screen to lay out its subcomponents again. This is the equivalent of the Java call
    149         * Container.validate()
    150         */
    151        public void setWorldAndResolution(Minecraft par1Minecraft, int par2, int par3)
    152        {
    153            this.guiParticles = new GuiParticle(par1Minecraft);
    154            this.mc = par1Minecraft;
    155            this.fontRenderer = par1Minecraft.fontRenderer;
    156            this.width = par2;
    157            this.height = par3;
    158            this.controlList.clear();
    159            this.initGui();
    160        }
    161
    162        /**
    163         * Adds the buttons (and other controls) to the screen in question.
    164         */
    165        public void initGui() {}
    166
    167        /**
    168         * Delegates mouse and keyboard input.
    169         */
    170        public void handleInput()
    171        {
    172            while (Mouse.next())
    173            {
    174                this.handleMouseInput();
    175            }
    176
    177            while (Keyboard.next())
    178            {
    179                this.handleKeyboardInput();
    180            }
    181        }
    182
    183        /**
    184         * Handles mouse input.
    185         */
    186        public void handleMouseInput()
    187        {
    188            int var1 = Mouse.getEventX() * this.width / this.mc.displayWidth;
    189            int var2 = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
    190
    191            if (Mouse.getEventButtonState())
    192            {
    193                this.field_85042_b = Mouse.getEventButton();
    194                this.field_85043_c = Minecraft.getSystemTime();
    195                this.mouseClicked(var1, var2, this.field_85042_b);
    196            }
    197            else if (Mouse.getEventButton() != -1)
    198            {
    199                this.field_85042_b = -1;
    200                this.mouseMovedOrUp(var1, var2, Mouse.getEventButton());
    201            }
    202            else if (this.mc.gameSettings.field_85185_A && this.field_85042_b != -1 && this.field_85043_c > 0L)
    203            {
    204                long var3 = Minecraft.getSystemTime() - this.field_85043_c;
    205                this.func_85041_a(var1, var2, this.field_85042_b, var3);
    206            }
    207        }
    208
    209        /**
    210         * Handles keyboard input.
    211         */
    212        public void handleKeyboardInput()
    213        {
    214            if (Keyboard.getEventKeyState())
    215            {
    216                int var1 = Keyboard.getEventKey();
    217                char var2 = Keyboard.getEventCharacter();
    218
    219                if (var1 == 87)
    220                {
    221                    this.mc.toggleFullscreen();
    222                    return;
    223                }
    224
    225                if (field_90017_e && var1 == 28 && var2 == 0)
    226                {
    227                    var1 = 29;
    228                }
    229
    230                this.keyTyped(var2, var1);
    231            }
    232        }
    233
    234        /**
    235         * Called from the main game loop to update the screen.
    236         */
    237        public void updateScreen() {}
    238
    239        /**
    240         * Called when the screen is unloaded. Used to disable keyboard repeat events
    241         */
    242        public void onGuiClosed() {}
    243
    244        /**
    245         * Draws either a gradient over the background screen (when it exists) or a flat gradient over background.png
    246         */
    247        public void drawDefaultBackground()
    248        {
    249            this.drawWorldBackground(0);
    250        }
    251
    252        public void drawWorldBackground(int par1)
    253        {
    254            if (this.mc.theWorld != null)
    255            {
    256                this.drawGradientRect(0, 0, this.width, this.height, -1072689136, -804253680);
    257            }
    258            else
    259            {
    260                this.drawBackground(par1);
    261            }
    262        }
    263
    264        /**
    265         * Draws the background (i is always 0 as of 1.2.2)
    266         */
    267        public void drawBackground(int par1)
    268        {
    269            GL11.glDisable(GL11.GL_LIGHTING);
    270            GL11.glDisable(GL11.GL_FOG);
    271            Tessellator var2 = Tessellator.instance;
    272            GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/gui/background.png"));
    273            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    274            float var3 = 32.0F;
    275            var2.startDrawingQuads();
    276            var2.setColorOpaque_I(4210752);
    277            var2.addVertexWithUV(0.0D, (double)this.height, 0.0D, 0.0D, (double)((float)this.height / var3 + (float)par1));
    278            var2.addVertexWithUV((double)this.width, (double)this.height, 0.0D, (double)((float)this.width / var3), (double)((float)this.height / var3 + (float)par1));
    279            var2.addVertexWithUV((double)this.width, 0.0D, 0.0D, (double)((float)this.width / var3), (double)par1);
    280            var2.addVertexWithUV(0.0D, 0.0D, 0.0D, 0.0D, (double)par1);
    281            var2.draw();
    282        }
    283
    284        /**
    285         * Returns true if this GUI should pause the game when it is displayed in single-player
    286         */
    287        public boolean doesGuiPauseGame()
    288        {
    289            return true;
    290        }
    291
    292        public void confirmClicked(boolean par1, int par2) {}
    293
    294        public static boolean isCtrlKeyDown()
    295        {
    296            boolean var0 = Keyboard.isKeyDown(28) && Keyboard.getEventCharacter() == 0;
    297            return Keyboard.isKeyDown(29) || Keyboard.isKeyDown(157) || field_90017_e && (var0 || Keyboard.isKeyDown(219) || Keyboard.isKeyDown(220));
    298        }
    299
    300        public static boolean isShiftKeyDown()
    301        {
    302            return Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54);
    303        }
    304    }