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