    001package net.minecraftforge.client;
    002
    003import org.lwjgl.input.Mouse;
    004import org.lwjgl.opengl.GL11;
    005
    006import net.minecraft.client.Minecraft;
    007import net.minecraft.client.settings.GameSettings;
    008import net.minecraft.client.gui.GuiControls;
    009import net.minecraft.client.gui.GuiSlot;
    010import net.minecraft.client.settings.KeyBinding;
    011import net.minecraft.client.renderer.Tessellator;
    012import net.minecraft.util.EnumChatFormatting;
    013
    014public class GuiControlsScrollPanel extends GuiSlot
    015{
    016    private GuiControls controls;
    017    private GameSettings options;
    018    private Minecraft mc;
    019    private String[] message;
    020    private int _mouseX;
    021    private int _mouseY;
    022    private int selected = -1;
    023
    024    public GuiControlsScrollPanel(GuiControls controls, GameSettings options, Minecraft mc)
    025    {
    026        super(mc, controls.width, controls.height, 16, (controls.height - 32) + 4, 25);
    027        this.controls = controls;
    028        this.options = options;
    029        this.mc = mc;
    030    }
    031
    032    @Override
    033    protected int getSize()
    034    {
    035        return options.keyBindings.length;
    036    }
    037
    038    @Override
    039    protected void elementClicked(int i, boolean flag)
    040    {
    041        if (!flag)
    042        {
    043            if (selected == -1)
    044            {
    045                selected = i;
    046            }
    047            else
    048            {
    049                options.setKeyBinding(selected, -100);
    050                selected = -1;
    051                KeyBinding.resetKeyBindingArrayAndHash();
    052            }
    053        }
    054    }
    055
    056    @Override
    057    protected boolean isSelected(int i)
    058    {
    059        return false;
    060    }
    061
    062    @Override
    063    protected void drawBackground() {}
    064
    065    @Override
    066    public void drawScreen(int mX, int mY, float f)
    067    {
    068        _mouseX = mX;
    069        _mouseY = mY;
    070
    071        if (selected != -1 && !Mouse.isButtonDown(0) && Mouse.getDWheel() == 0)
    072        {
    073            if (Mouse.next() && Mouse.getEventButtonState())
    074            {
    075                System.out.println(Mouse.getEventButton());
    076                options.setKeyBinding(selected, -100 + Mouse.getEventButton());
    077                selected = -1;
    078                KeyBinding.resetKeyBindingArrayAndHash();
    079            }
    080        }
    081
    082        super.drawScreen(mX, mY, f);
    083    }
    084
    085    @Override
    086    protected void drawSlot(int index, int xPosition, int yPosition, int l, Tessellator tessellator)
    087    {
    088        int width = 70;
    089        int height = 20;
    090        xPosition -= 20;
    091        boolean flag = _mouseX >= xPosition && _mouseY >= yPosition && _mouseX < xPosition + width && _mouseY < yPosition + height;
    092        int k = (flag ? 2 : 1);
    093
    094        mc.renderEngine.bindTexture("/gui/gui.png");
    095        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    096        controls.drawTexturedModalRect(xPosition, yPosition, 0, 46 + k * 20, width / 2, height);
    097        controls.drawTexturedModalRect(xPosition + width / 2, yPosition, 200 - width / 2, 46 + k * 20, width / 2, height);
    098        controls.drawString(mc.fontRenderer, options.getKeyBindingDescription(index), xPosition + width + 4, yPosition + 6, 0xFFFFFFFF);
    099
    100        boolean conflict = false;
    101        for (int x = 0; x < options.keyBindings.length; x++)
    102        {
    103            if (x != index && options.keyBindings[x].keyCode == options.keyBindings[index].keyCode)
    104            {
    105                conflict = true;
    106                break;
    107            }
    108        }
    109
    110        String str = (conflict ? EnumChatFormatting.RED : "") + options.getOptionDisplayString(index);
    111        str = (index == selected ? EnumChatFormatting.WHITE + "> " + EnumChatFormatting.YELLOW + "??? " + EnumChatFormatting.WHITE + "<" : str);
    112        controls.drawCenteredString(mc.fontRenderer, str, xPosition + (width / 2), yPosition + (height - 8) / 2, 0xFFFFFFFF);
    113    }
    114
    115    public boolean keyTyped(char c, int i)
    116    {
    117        if (selected != -1)
    118        {
    119            options.setKeyBinding(selected, i);
    120            selected = -1;
    121            KeyBinding.resetKeyBindingArrayAndHash();
    122            return false;
    123        }
    124        return true;
    125    }
    126}