diff --git a/src/main/java/techreborn/client/gui/GuiIDSU.java b/src/main/java/techreborn/client/gui/GuiIDSU.java index 8b76ad827..06ed8ca48 100644 --- a/src/main/java/techreborn/client/gui/GuiIDSU.java +++ b/src/main/java/techreborn/client/gui/GuiIDSU.java @@ -48,13 +48,14 @@ public class GuiIDSU extends GuiBase { @Override public void initGui() { super.initGui(); - this.buttonList.clear(); - int k = (this.width - this.xSize) / 2; - int l = (this.height - this.ySize) / 2; - this.buttonList.add(new GuiButton(0, k + 96, l + 8, 18, 20, "++")); - this.buttonList.add(new GuiButton(1, k + 96, l + 8 + 22, 18, 20, "+")); - this.buttonList.add(new GuiButton(2, k + 96, l + 8 + (22*2), 18, 20, "-")); - this.buttonList.add(new GuiButton(3, k + 96, l + 8 + (22*3), 18, 20, "--")); +// this.buttonList.clear(); +// int k = (this.width - this.xSize) / 2; +// int l = (this.height - this.ySize) / 2; +// this.buttonList.add(new GuiButton(0, k + 96, l + 8, 18, 20, "++")); +// this.buttonList.add(new GuiButton(1, k + 96, l + 8 + 22, 18, 20, "+")); +// this.buttonList.add(new GuiButton(2, k + 96, l + 8 + (22*2), 18, 20, "-")); +// this.buttonList.add(new GuiButton(3, k + 96, l + 8 + (22*3), 18, 20, "--")); + listBox = new ElementListBox(this, 20, 20, 60, 60); for (int i = 0; i < 15; i++) { listBox.add(new ListBoxElementText("Name " + i)); diff --git a/src/main/java/techreborn/cofhLib/gui/GuiBase.java b/src/main/java/techreborn/cofhLib/gui/GuiBase.java index adbb411ea..7a38965e2 100755 --- a/src/main/java/techreborn/cofhLib/gui/GuiBase.java +++ b/src/main/java/techreborn/cofhLib/gui/GuiBase.java @@ -1,6 +1,9 @@ package techreborn.cofhLib.gui; +import techreborn.cofhLib.audio.SoundBase; +import techreborn.cofhLib.gui.element.ElementBase; import techreborn.cofhLib.gui.element.TabBase; +import techreborn.cofhLib.gui.slot.SlotFalseCopy; import techreborn.cofhLib.render.RenderHelper; import techreborn.cofhLib.util.helpers.StringHelper; import cpw.mods.fml.client.FMLClientHandler; @@ -29,850 +32,732 @@ import java.util.List; * * @author King Lemming */ -public abstract class GuiBase extends GuiContainer -{ +public abstract class GuiBase extends GuiContainer { - public static final SoundHandler guiSoundManager = FMLClientHandler.instance().getClient().getSoundHandler(); + public static final SoundHandler guiSoundManager = FMLClientHandler.instance().getClient().getSoundHandler(); - protected boolean drawTitle = true; - protected boolean drawInventory = true; - protected int mouseX = 0; - protected int mouseY = 0; + protected boolean drawTitle = true; + protected boolean drawInventory = true; + protected int mouseX = 0; + protected int mouseY = 0; - protected int lastIndex = -1; - - protected String name; - protected ResourceLocation texture; - - public ArrayList tabs = new ArrayList(); - protected ArrayList elements = new ArrayList(); - - protected List tooltip = new LinkedList(); - protected boolean tooltips = true; - - public static void playSound(String name, float volume, float pitch) - { - - guiSoundManager.playSound(new techreborn.cofhLib.audio.SoundBase(name, volume, pitch)); - } - - public GuiBase(Container container) - { - - super(container); - } - - public GuiBase(Container container, ResourceLocation texture) - { - - super(container); - this.texture = texture; - } - - @Override - public void initGui() - { - - super.initGui(); - tabs.clear(); - elements.clear(); - } - - @Override - public void drawScreen(int x, int y, float partialTick) - { - - updateElementInformation(); - - super.drawScreen(x, y, partialTick); - - if (tooltips && mc.thePlayer.inventory.getItemStack() == null) - { - addTooltips(tooltip); - drawTooltip(tooltip); - } - mouseX = x - guiLeft; - mouseY = y - guiTop; - - updateElements(); - } - - @Override - protected void drawGuiContainerForegroundLayer(int x, int y) - { - - if (drawTitle) - { - fontRendererObj.drawString(StringHelper.localize(name), getCenteredOffset(StringHelper.localize(name)), 6, 0x404040); - } - if (drawInventory) - { - fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 3, 0x404040); - } - drawElements(0, true); - drawTabs(0, true); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float partialTick, int x, int y) - { - - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - bindTexture(texture); - drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); - - mouseX = x - guiLeft; - mouseY = y - guiTop; - - GL11.glPushMatrix(); - GL11.glTranslatef(guiLeft, guiTop, 0.0F); - drawElements(partialTick, false); - drawTabs(partialTick, false); - GL11.glPopMatrix(); - } - - @Override - protected void keyTyped(char characterTyped, int keyPressed) - { - - for (int i = elements.size(); i-- > 0; ) - { - techreborn.cofhLib.gui.element.ElementBase c = elements.get(i); - if (!c.isVisible() || !c.isEnabled()) - { - continue; - } - if (c.onKeyTyped(characterTyped, keyPressed)) - { - return; - } - } - super.keyTyped(characterTyped, keyPressed); - } - - @Override - public void handleMouseInput() - { - - int x = Mouse.getEventX() * width / mc.displayWidth; - int y = height - Mouse.getEventY() * height / mc.displayHeight - 1; - - mouseX = x - guiLeft; - mouseY = y - guiTop; - - int wheelMovement = Mouse.getEventDWheel(); - - if (wheelMovement != 0) - { - for (int i = elements.size(); i-- > 0; ) - { - techreborn.cofhLib.gui.element.ElementBase c = elements.get(i); - if (!c.isVisible() || !c.isEnabled() || !c.intersectsWith(mouseX, mouseY)) - { - continue; - } - if (c.onMouseWheel(mouseX, mouseY, wheelMovement)) - { - return; - } - } - TabBase tab = getTabAtPosition(mouseX, mouseY); - - if (tab != null && tab.onMouseWheel(mouseX, mouseY, wheelMovement)) - { - return; - } - } - super.handleMouseInput(); - } - - @Override - protected void mouseClicked(int mX, int mY, int mouseButton) - { - - mX -= guiLeft; - mY -= guiTop; - - for (int i = elements.size(); i-- > 0; ) - { - techreborn.cofhLib.gui.element.ElementBase c = elements.get(i); - if (!c.isVisible() || !c.isEnabled() || !c.intersectsWith(mX, mY)) - { - continue; - } - if (c.onMousePressed(mX, mY, mouseButton)) - { - return; - } - } - - TabBase tab = getTabAtPosition(mX, mY); - if (tab != null) - { - int tMx = mX; - - if (!tab.onMousePressed(tMx, mY, mouseButton)) - { - for (int i = tabs.size(); i-- > 0; ) - { - TabBase other = tabs.get(i); - if (other != tab && other.open && other.side == tab.side) - { - other.toggleOpen(); - } - } - tab.toggleOpen(); - return; - } - } - - mX += guiLeft; - mY += guiTop; - - if (tab != null) - { - switch (tab.side) - { - case TabBase.LEFT: - guiLeft -= tab.currentWidth; - break; - case TabBase.RIGHT: - xSize += tab.currentWidth; - break; - } - } - super.mouseClicked(mX, mY, mouseButton); - if (tab != null) - { - switch (tab.side) - { - case TabBase.LEFT: - guiLeft += tab.currentWidth; - break; - case TabBase.RIGHT: - xSize -= tab.currentWidth; - break; - } - } - } - - @Override - protected void mouseMovedOrUp(int mX, int mY, int mouseButton) - { - - mX -= guiLeft; - mY -= guiTop; - - if (mouseButton >= 0 && mouseButton <= 2) - { // 0:left, 1:right, 2: middle - for (int i = elements.size(); i-- > 0; ) - { - techreborn.cofhLib.gui.element.ElementBase c = elements.get(i); - if (!c.isVisible() || !c.isEnabled()) - { // no bounds checking on mouseUp events - continue; - } - c.onMouseReleased(mX, mY); - } - } - mX += guiLeft; - mY += guiTop; - - super.mouseMovedOrUp(mX, mY, mouseButton); - } - - @Override - protected void mouseClickMove(int mX, int mY, int lastClick, long timeSinceClick) - { - - Slot slot = getSlotAtPosition(mX, mY); - ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack(); - - if (this.field_147007_t && slot != null && itemstack != null && slot instanceof techreborn.cofhLib.gui.slot.SlotFalseCopy) - { - if (lastIndex != slot.slotNumber) - { - lastIndex = slot.slotNumber; - this.handleMouseClick(slot, slot.slotNumber, 0, 0); - } - } - else - { - lastIndex = -1; - super.mouseClickMove(mX, mY, lastClick, timeSinceClick); - } - } - - public Slot getSlotAtPosition(int xCoord, int yCoord) - { - - for (int k = 0; k < this.inventorySlots.inventorySlots.size(); ++k) - { - Slot slot = (Slot) this.inventorySlots.inventorySlots.get(k); - - if (this.isMouseOverSlot(slot, xCoord, yCoord)) - { - return slot; - } - } - return null; - } - - public boolean isMouseOverSlot(Slot theSlot, int xCoord, int yCoord) - { - - return this.func_146978_c(theSlot.xDisplayPosition, theSlot.yDisplayPosition, 16, 16, xCoord, yCoord); - } - - /** - * Draws the elements for this GUI. - */ - protected void drawElements(float partialTick, boolean foreground) - { - - if (foreground) - { - for (int i = 0; i < elements.size(); i++) - { - techreborn.cofhLib.gui.element.ElementBase element = elements.get(i); - if (element.isVisible()) - { - element.drawForeground(mouseX, mouseY); - } - } - } - else - { - for (int i = 0; i < elements.size(); i++) - { - techreborn.cofhLib.gui.element.ElementBase element = elements.get(i); - if (element.isVisible()) - { - element.drawBackground(mouseX, mouseY, partialTick); - } - } - } - } - - /** - * Draws the tabs for this GUI. Handles Tab open/close animation. - */ - protected void drawTabs(float partialTick, boolean foreground) - { - - if (foreground) - { - return; - } - int yPosRight = 4; - int yPosLeft = 4; - - for (int i = 0; i < tabs.size(); i++) - { - TabBase tab = tabs.get(i); - tab.update(); - if (!tab.isVisible()) - { - continue; - } - if (tab.side == TabBase.LEFT) - { - tab.draw(0, yPosLeft); - yPosLeft += tab.currentHeight; - } - else - { - tab.draw(xSize, yPosRight); - yPosRight += tab.currentHeight; - } - } - } - - /** - * Called by NEI if installed - */ - // @Override - public List handleTooltip(int mousex, int mousey, List tooltip) - { - - if (mc.thePlayer.inventory.getItemStack() == null) - { - addTooltips(tooltip); - } - return tooltip; - } - - public void addTooltips(List tooltip) - { - - TabBase tab = getTabAtPosition(mouseX, mouseY); - - if (tab != null) - { - tab.addTooltip(tooltip); - } - techreborn.cofhLib.gui.element.ElementBase element = getElementAtPosition(mouseX, mouseY); - - if (element != null) - { - element.addTooltip(tooltip); - } - } - - /* ELEMENTS */ - public techreborn.cofhLib.gui.element.ElementBase addElement(techreborn.cofhLib.gui.element.ElementBase element) - { - - elements.add(element); - return element; - } - - public TabBase addTab(TabBase tab) - { - - int yOffset = 4; - for (int i = 0; i < tabs.size(); i++) - { - if (tabs.get(i).side == tab.side && tabs.get(i).isVisible()) - { - yOffset += tabs.get(i).currentHeight; - } - } - tab.setPosition(tab.side == TabBase.LEFT ? 0 : xSize, yOffset); - tabs.add(tab); - - if (TabTracker.getOpenedLeftTab() != null && tab.getClass().equals(TabTracker.getOpenedLeftTab())) - { - tab.setFullyOpen(); - } - else if (TabTracker.getOpenedRightTab() != null && tab.getClass().equals(TabTracker.getOpenedRightTab())) - { - tab.setFullyOpen(); - } - return tab; - } - - protected techreborn.cofhLib.gui.element.ElementBase getElementAtPosition(int mX, int mY) - { - - for (int i = elements.size(); i-- > 0; ) - { - techreborn.cofhLib.gui.element.ElementBase element = elements.get(i); - if (element.intersectsWith(mX, mY)) - { - return element; - } - } - return null; - } - - protected TabBase getTabAtPosition(int mX, int mY) - { - - int xShift = 0; - int yShift = 4; - - for (int i = 0; i < tabs.size(); i++) - { - TabBase tab = tabs.get(i); - if (!tab.isVisible() || tab.side == TabBase.RIGHT) - { - continue; - } - tab.setCurrentShift(xShift, yShift); - if (tab.intersectsWith(mX, mY, xShift, yShift)) - { - return tab; - } - yShift += tab.currentHeight; - } - - xShift = xSize; - yShift = 4; - - for (int i = 0; i < tabs.size(); i++) - { - TabBase tab = tabs.get(i); - if (!tab.isVisible() || tab.side == TabBase.LEFT) - { - continue; - } - tab.setCurrentShift(xShift, yShift); - if (tab.intersectsWith(mX, mY, xShift, yShift)) - { - return tab; - } - yShift += tab.currentHeight; - } - return null; - } - - protected final void updateElements() - { - - for (int i = elements.size(); i-- > 0; ) - { - techreborn.cofhLib.gui.element.ElementBase c = elements.get(i); - if (c.isVisible() && c.isEnabled()) - { - c.update(mouseX, mouseY); - } - } - } - - protected void updateElementInformation() - { - - } - - public void handleElementButtonClick(String buttonName, int mouseButton) - { - - } - - /* HELPERS */ - public void bindTexture(ResourceLocation texture) - { - - mc.renderEngine.bindTexture(texture); - } - - /** - * Abstract method to retrieve icons by name from a registry. You must override this if you use any of the String methods below. - */ - public IIcon getIcon(String name) - { - - return null; - } - - /** - * Essentially a placeholder method for tabs to use should they need to draw a button. - */ - public void drawButton(IIcon icon, int x, int y, int spriteSheet, int mode) - { - - drawIcon(icon, x, y, spriteSheet); - } - - public void drawButton(String iconName, int x, int y, int spriteSheet, int mode) - { - - drawButton(getIcon(iconName), x, y, spriteSheet, mode); - } - - /** - * Simple method used to draw a fluid of arbitrary size. - */ - public void drawFluid(int x, int y, FluidStack fluid, int width, int height) - { - - if (fluid == null || fluid.getFluid() == null) - { - return; - } - RenderHelper.setBlockTextureSheet(); - RenderHelper.setColor3ub(fluid.getFluid().getColor(fluid)); - - drawTiledTexture(x, y, fluid.getFluid().getIcon(fluid), width, height); - } - - public void drawTiledTexture(int x, int y, IIcon icon, int width, int height) - { - - int i = 0; - int j = 0; - - int drawHeight = 0; - int drawWidth = 0; - - for (i = 0; i < width; i += 16) - { - for (j = 0; j < height; j += 16) - { - drawWidth = Math.min(width - i, 16); - drawHeight = Math.min(height - j, 16); - drawScaledTexturedModelRectFromIcon(x + i, y + j, icon, drawWidth, drawHeight); - } - } - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F); - } - - public void drawIcon(IIcon icon, int x, int y, int spriteSheet) - { - - if (spriteSheet == 0) - { - RenderHelper.setBlockTextureSheet(); - } - else - { - RenderHelper.setItemTextureSheet(); - } - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F); - drawTexturedModelRectFromIcon(x, y, icon, 16, 16); - } - - public void drawColorIcon(IIcon icon, int x, int y, int spriteSheet) - { - - if (spriteSheet == 0) - { - RenderHelper.setBlockTextureSheet(); - } - else - { - RenderHelper.setItemTextureSheet(); - } - drawTexturedModelRectFromIcon(x, y, icon, 16, 16); - } - - public void drawIcon(String iconName, int x, int y, int spriteSheet) - { - - drawIcon(getIcon(iconName), x, y, spriteSheet); - } - - public void drawSizedModalRect(int x1, int y1, int x2, int y2, int color) - { - - int temp; - - if (x1 < x2) - { - temp = x1; - x1 = x2; - x2 = temp; - } - if (y1 < y2) - { - temp = y1; - y1 = y2; - y2 = temp; - } - - float a = (color >> 24 & 255) / 255.0F; - float r = (color >> 16 & 255) / 255.0F; - float g = (color >> 8 & 255) / 255.0F; - float b = (color & 255) / 255.0F; - Tessellator tessellator = Tessellator.instance; - GL11.glEnable(GL11.GL_BLEND); - GL11.glDisable(GL11.GL_TEXTURE_2D); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GL11.glColor4f(r, g, b, a); - tessellator.startDrawingQuads(); - tessellator.addVertex(x1, y2, this.zLevel); - tessellator.addVertex(x2, y2, this.zLevel); - tessellator.addVertex(x2, y1, this.zLevel); - tessellator.addVertex(x1, y1, this.zLevel); - tessellator.draw(); - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL11.glDisable(GL11.GL_BLEND); - } - - public void drawSizedRect(int x1, int y1, int x2, int y2, int color) - { - - int temp; - - if (x1 < x2) - { - temp = x1; - x1 = x2; - x2 = temp; - } - if (y1 < y2) - { - temp = y1; - y1 = y2; - y2 = temp; - } - - float a = (color >> 24 & 255) / 255.0F; - float r = (color >> 16 & 255) / 255.0F; - float g = (color >> 8 & 255) / 255.0F; - float b = (color & 255) / 255.0F; - Tessellator tessellator = Tessellator.instance; - GL11.glDisable(GL11.GL_TEXTURE_2D); - GL11.glColor4f(r, g, b, a); - tessellator.startDrawingQuads(); - tessellator.addVertex(x1, y2, this.zLevel); - tessellator.addVertex(x2, y2, this.zLevel); - tessellator.addVertex(x2, y1, this.zLevel); - tessellator.addVertex(x1, y1, this.zLevel); - tessellator.draw(); - GL11.glEnable(GL11.GL_TEXTURE_2D); - } - - public void drawSizedTexturedModalRect(int x, int y, int u, int v, int width, int height, float texW, float texH) - { - - float texU = 1 / texW; - float texV = 1 / texH; - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawingQuads(); - tessellator.addVertexWithUV(x + 0, y + height, this.zLevel, (u + 0) * texU, (v + height) * texV); - tessellator.addVertexWithUV(x + width, y + height, this.zLevel, (u + width) * texU, (v + height) * texV); - tessellator.addVertexWithUV(x + width, y + 0, this.zLevel, (u + width) * texU, (v + 0) * texV); - tessellator.addVertexWithUV(x + 0, y + 0, this.zLevel, (u + 0) * texU, (v + 0) * texV); - tessellator.draw(); - } - - public void drawScaledTexturedModelRectFromIcon(int x, int y, IIcon icon, int width, int height) - { - - if (icon == null) - { - return; - } - double minU = icon.getMinU(); - double maxU = icon.getMaxU(); - double minV = icon.getMinV(); - double maxV = icon.getMaxV(); - - Tessellator tessellator = Tessellator.instance; - tessellator.startDrawingQuads(); - tessellator.addVertexWithUV(x + 0, y + height, this.zLevel, minU, minV + (maxV - minV) * height / 16F); - tessellator.addVertexWithUV(x + width, y + height, this.zLevel, minU + (maxU - minU) * width / 16F, minV + (maxV - minV) * height / 16F); - tessellator.addVertexWithUV(x + width, y + 0, this.zLevel, minU + (maxU - minU) * width / 16F, minV); - tessellator.addVertexWithUV(x + 0, y + 0, this.zLevel, minU, minV); - tessellator.draw(); - } - - public void drawTooltip(List list) - { - - drawTooltipHoveringText(list, mouseX + guiLeft, mouseY + guiTop, fontRendererObj); - tooltip.clear(); - } - - @SuppressWarnings("rawtypes") - protected void drawTooltipHoveringText(List list, int x, int y, FontRenderer font) - { - - if (list == null || list.isEmpty()) - { - return; - } - GL11.glDisable(GL12.GL_RESCALE_NORMAL); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_DEPTH_TEST); - int k = 0; - Iterator iterator = list.iterator(); - - while (iterator.hasNext()) - { - String s = (String) iterator.next(); - int l = font.getStringWidth(s); - - if (l > k) - { - k = l; - } - } - int i1 = x + 12; - int j1 = y - 12; - int k1 = 8; - - if (list.size() > 1) - { - k1 += 2 + (list.size() - 1) * 10; - } - if (i1 + k > this.width) - { - i1 -= 28 + k; - } - if (j1 + k1 + 6 > this.height) - { - j1 = this.height - k1 - 6; - } - this.zLevel = 300.0F; - itemRender.zLevel = 300.0F; - int l1 = -267386864; - this.drawGradientRect(i1 - 3, j1 - 4, i1 + k + 3, j1 - 3, l1, l1); - this.drawGradientRect(i1 - 3, j1 + k1 + 3, i1 + k + 3, j1 + k1 + 4, l1, l1); - this.drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 + k1 + 3, l1, l1); - this.drawGradientRect(i1 - 4, j1 - 3, i1 - 3, j1 + k1 + 3, l1, l1); - this.drawGradientRect(i1 + k + 3, j1 - 3, i1 + k + 4, j1 + k1 + 3, l1, l1); - int i2 = 1347420415; - int j2 = (i2 & 16711422) >> 1 | i2 & -16777216; - this.drawGradientRect(i1 - 3, j1 - 3 + 1, i1 - 3 + 1, j1 + k1 + 3 - 1, i2, j2); - this.drawGradientRect(i1 + k + 2, j1 - 3 + 1, i1 + k + 3, j1 + k1 + 3 - 1, i2, j2); - this.drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 - 3 + 1, i2, i2); - this.drawGradientRect(i1 - 3, j1 + k1 + 2, i1 + k + 3, j1 + k1 + 3, j2, j2); - - for (int k2 = 0; k2 < list.size(); ++k2) - { - String s1 = (String) list.get(k2); - font.drawStringWithShadow(s1, i1, j1, -1); - - if (k2 == 0) - { - j1 += 2; - } - j1 += 10; - } - this.zLevel = 0.0F; - itemRender.zLevel = 0.0F; - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_DEPTH_TEST); - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - } - - /** - * Passthrough method for tab use. - */ - public void mouseClicked(int mouseButton) - { - - super.mouseClicked(guiLeft + mouseX, guiTop + mouseY, mouseButton); - } - - public FontRenderer getFontRenderer() - { - - return fontRendererObj; - } - - protected int getCenteredOffset(String string) - { - - return this.getCenteredOffset(string, xSize); - } - - protected int getCenteredOffset(String string, int xWidth) - { - - return (xWidth - fontRendererObj.getStringWidth(string)) / 2; - } - - public int getGuiLeft() - { - - return guiLeft; - } - - public int getGuiTop() - { - - return guiTop; - } - - public int getMouseX() - { - - return mouseX; - } - - public int getMouseY() - { - - return mouseY; - } - - public void overlayRecipe() - { - - } - -} + protected int lastIndex = -1; + + protected String name; + protected ResourceLocation texture; + + public ArrayList tabs = new ArrayList(); + protected ArrayList elements = new ArrayList(); + + protected List tooltip = new LinkedList(); + protected boolean tooltips = true; + + public static void playSound(String name, float volume, float pitch) { + + guiSoundManager.playSound(new SoundBase(name, volume, pitch)); + } + + public GuiBase(Container container) { + + super(container); + } + + public GuiBase(Container container, ResourceLocation texture) { + + super(container); + this.texture = texture; + } + + @Override + public void initGui() { + + super.initGui(); + tabs.clear(); + elements.clear(); + } + + @Override + public void drawScreen(int x, int y, float partialTick) { + + updateElementInformation(); + + super.drawScreen(x, y, partialTick); + + if (tooltips && mc.thePlayer.inventory.getItemStack() == null) { + addTooltips(tooltip); + drawTooltip(tooltip); + } + mouseX = x - guiLeft; + mouseY = y - guiTop; + + updateElements(); + } + + @Override + protected void drawGuiContainerForegroundLayer(int x, int y) { + + if (drawTitle) { + fontRendererObj.drawString(StringHelper.localize(name), getCenteredOffset(StringHelper.localize(name)), 6, 0x404040); + } + if (drawInventory) { + fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 3, 0x404040); + } + drawElements(0, true); + drawTabs(0, true); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float partialTick, int x, int y) { + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + bindTexture(texture); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); + + mouseX = x - guiLeft; + mouseY = y - guiTop; + + GL11.glPushMatrix(); + GL11.glTranslatef(guiLeft, guiTop, 0.0F); + drawElements(partialTick, false); + drawTabs(partialTick, false); + GL11.glPopMatrix(); + } + + @Override + protected void keyTyped(char characterTyped, int keyPressed) { + + for (int i = elements.size(); i-- > 0;) { + ElementBase c = elements.get(i); + if (!c.isVisible() || !c.isEnabled()) { + continue; + } + if (c.onKeyTyped(characterTyped, keyPressed)) { + return; + } + } + super.keyTyped(characterTyped, keyPressed); + } + + @Override + public void handleMouseInput() { + + int x = Mouse.getEventX() * width / mc.displayWidth; + int y = height - Mouse.getEventY() * height / mc.displayHeight - 1; + + mouseX = x - guiLeft; + mouseY = y - guiTop; + + int wheelMovement = Mouse.getEventDWheel(); + + if (wheelMovement != 0) { + for (int i = elements.size(); i-- > 0;) { + ElementBase c = elements.get(i); + if (!c.isVisible() || !c.isEnabled() || !c.intersectsWith(mouseX, mouseY)) { + continue; + } + if (c.onMouseWheel(mouseX, mouseY, wheelMovement)) { + return; + } + } + TabBase tab = getTabAtPosition(mouseX, mouseY); + + if (tab != null && tab.onMouseWheel(mouseX, mouseY, wheelMovement)) { + return; + } + } + super.handleMouseInput(); + } + + @Override + protected void mouseClicked(int mX, int mY, int mouseButton) { + + mX -= guiLeft; + mY -= guiTop; + + for (int i = elements.size(); i-- > 0;) { + ElementBase c = elements.get(i); + if (!c.isVisible() || !c.isEnabled() || !c.intersectsWith(mX, mY)) { + continue; + } + if (c.onMousePressed(mX, mY, mouseButton)) { + return; + } + } + + TabBase tab = getTabAtPosition(mX, mY); + if (tab != null) { + int tMx = mX; + + if (!tab.onMousePressed(tMx, mY, mouseButton)) { + for (int i = tabs.size(); i-- > 0;) { + TabBase other = tabs.get(i); + if (other != tab && other.open && other.side == tab.side) { + other.toggleOpen(); + } + } + tab.toggleOpen(); + return; + } + } + + mX += guiLeft; + mY += guiTop; + + if (tab != null) { + switch (tab.side) { + case TabBase.LEFT: + // guiLeft -= tab.currentWidth; + break; + case TabBase.RIGHT: + xSize += tab.currentWidth; + break; + } + } + super.mouseClicked(mX, mY, mouseButton); + if (tab != null) { + switch (tab.side) { + case TabBase.LEFT: + // guiLeft += tab.currentWidth; + break; + case TabBase.RIGHT: + xSize -= tab.currentWidth; + break; + } + } + } + + @Override + protected void mouseMovedOrUp(int mX, int mY, int mouseButton) { + + mX -= guiLeft; + mY -= guiTop; + + if (mouseButton >= 0 && mouseButton <= 2) { // 0:left, 1:right, 2: middle + for (int i = elements.size(); i-- > 0;) { + ElementBase c = elements.get(i); + if (!c.isVisible() || !c.isEnabled()) { // no bounds checking on mouseUp events + continue; + } + c.onMouseReleased(mX, mY); + } + } + mX += guiLeft; + mY += guiTop; + + super.mouseMovedOrUp(mX, mY, mouseButton); + } + + @Override + protected void mouseClickMove(int mX, int mY, int lastClick, long timeSinceClick) { + + Slot slot = getSlotAtPosition(mX, mY); + ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack(); + + if (this.field_147007_t && slot != null && itemstack != null && slot instanceof SlotFalseCopy) { + if (lastIndex != slot.slotNumber) { + lastIndex = slot.slotNumber; + this.handleMouseClick(slot, slot.slotNumber, 0, 0); + } + } else { + lastIndex = -1; + super.mouseClickMove(mX, mY, lastClick, timeSinceClick); + } + } + + public Slot getSlotAtPosition(int xCoord, int yCoord) { + + for (int k = 0; k < this.inventorySlots.inventorySlots.size(); ++k) { + Slot slot = (Slot) this.inventorySlots.inventorySlots.get(k); + + if (this.isMouseOverSlot(slot, xCoord, yCoord)) { + return slot; + } + } + return null; + } + + public boolean isMouseOverSlot(Slot theSlot, int xCoord, int yCoord) { + + return this.func_146978_c(theSlot.xDisplayPosition, theSlot.yDisplayPosition, 16, 16, xCoord, yCoord); + } + + /** + * Draws the elements for this GUI. + */ + protected void drawElements(float partialTick, boolean foreground) { + + if (foreground) { + for (int i = 0; i < elements.size(); i++) { + ElementBase element = elements.get(i); + if (element.isVisible()) { + element.drawForeground(mouseX, mouseY); + } + } + } else { + for (int i = 0; i < elements.size(); i++) { + ElementBase element = elements.get(i); + if (element.isVisible()) { + element.drawBackground(mouseX, mouseY, partialTick); + } + } + } + } + + /** + * Draws the tabs for this GUI. Handles Tab open/close animation. + */ + protected void drawTabs(float partialTick, boolean foreground) { + + int yPosRight = 4; + int yPosLeft = 4; + + if (foreground) { + for (int i = 0; i < tabs.size(); i++) { + TabBase tab = tabs.get(i); + tab.update(); + if (!tab.isVisible()) { + continue; + } + if (tab.side == TabBase.LEFT) { + tab.drawForeground(mouseX, mouseY); + yPosLeft += tab.currentHeight; + } else { + tab.drawForeground(mouseX, mouseY); + yPosRight += tab.currentHeight; + } + } + } else { + for (int i = 0; i < tabs.size(); i++) { + TabBase tab = tabs.get(i); + tab.update(); + if (!tab.isVisible()) { + continue; + } + if (tab.side == TabBase.LEFT) { + tab.setPosition(0, yPosLeft); + tab.drawBackground(mouseX, mouseY, partialTick); + yPosLeft += tab.currentHeight; + } else { + tab.setPosition(xSize, yPosRight); + tab.drawBackground(mouseX, mouseY, partialTick); + yPosRight += tab.currentHeight; + } + } + } + } + + /** + * Called by NEI if installed + */ + // @Override + public List handleTooltip(int mousex, int mousey, List tooltip) { + + if (mc.thePlayer.inventory.getItemStack() == null) { + addTooltips(tooltip); + } + return tooltip; + } + + public void addTooltips(List tooltip) { + + TabBase tab = getTabAtPosition(mouseX, mouseY); + + if (tab != null) { + tab.addTooltip(tooltip); + } + ElementBase element = getElementAtPosition(mouseX, mouseY); + + if (element != null && element.isVisible()) { + element.addTooltip(tooltip); + } + } + + /* ELEMENTS */ + public ElementBase addElement(ElementBase element) { + + elements.add(element); + return element; + } + + public TabBase addTab(TabBase tab) { + + int yOffset = 4; + for (int i = 0; i < tabs.size(); i++) { + if (tabs.get(i).side == tab.side && tabs.get(i).isVisible()) { + yOffset += tabs.get(i).currentHeight; + } + } + tab.setPosition(tab.side == TabBase.LEFT ? 0 : xSize, yOffset); + tabs.add(tab); + + if (TabTracker.getOpenedLeftTab() != null && tab.getClass().equals(TabTracker.getOpenedLeftTab())) { + tab.setFullyOpen(); + } else if (TabTracker.getOpenedRightTab() != null && tab.getClass().equals(TabTracker.getOpenedRightTab())) { + tab.setFullyOpen(); + } + return tab; + } + + protected ElementBase getElementAtPosition(int mX, int mY) { + + for (int i = elements.size(); i-- > 0;) { + ElementBase element = elements.get(i); + if (element.intersectsWith(mX, mY)) { + return element; + } + } + return null; + } + + protected TabBase getTabAtPosition(int mX, int mY) { + + int xShift = 0; + int yShift = 4; + + for (int i = 0; i < tabs.size(); i++) { + TabBase tab = tabs.get(i); + if (!tab.isVisible() || tab.side == TabBase.RIGHT) { + continue; + } + tab.setCurrentShift(xShift, yShift); + if (tab.intersectsWith(mX, mY, xShift, yShift)) { + return tab; + } + yShift += tab.currentHeight; + } + + xShift = xSize; + yShift = 4; + + for (int i = 0; i < tabs.size(); i++) { + TabBase tab = tabs.get(i); + if (!tab.isVisible() || tab.side == TabBase.LEFT) { + continue; + } + tab.setCurrentShift(xShift, yShift); + if (tab.intersectsWith(mX, mY, xShift, yShift)) { + return tab; + } + yShift += tab.currentHeight; + } + return null; + } + + protected final void updateElements() { + + for (int i = elements.size(); i-- > 0;) { + ElementBase c = elements.get(i); + if (c.isVisible() && c.isEnabled()) { + c.update(mouseX, mouseY); + } + } + } + + protected void updateElementInformation() { + + } + + public void handleElementButtonClick(String buttonName, int mouseButton) { + + } + + /* HELPERS */ + public void bindTexture(ResourceLocation texture) { + + mc.renderEngine.bindTexture(texture); + } + + /** + * Abstract method to retrieve icons by name from a registry. You must override this if you use any of the String methods below. + */ + public IIcon getIcon(String name) { + + return null; + } + + /** + * Essentially a placeholder method for tabs to use should they need to draw a button. + */ + public void drawButton(IIcon icon, int x, int y, int spriteSheet, int mode) { + + drawIcon(icon, x, y, spriteSheet); + } + + public void drawButton(String iconName, int x, int y, int spriteSheet, int mode) { + + drawButton(getIcon(iconName), x, y, spriteSheet, mode); + } + + /** + * Simple method used to draw a fluid of arbitrary size. + */ + public void drawFluid(int x, int y, FluidStack fluid, int width, int height) { + + if (fluid == null || fluid.getFluid() == null) { + return; + } + RenderHelper.setBlockTextureSheet(); + RenderHelper.setColor3ub(fluid.getFluid().getColor(fluid)); + + drawTiledTexture(x, y, fluid.getFluid().getIcon(fluid), width, height); + } + + public void drawTiledTexture(int x, int y, IIcon icon, int width, int height) { + + int i = 0; + int j = 0; + + int drawHeight = 0; + int drawWidth = 0; + + for (i = 0; i < width; i += 16) { + for (j = 0; j < height; j += 16) { + drawWidth = Math.min(width - i, 16); + drawHeight = Math.min(height - j, 16); + drawScaledTexturedModelRectFromIcon(x + i, y + j, icon, drawWidth, drawHeight); + } + } + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F); + } + + public void drawIcon(IIcon icon, int x, int y, int spriteSheet) { + + if (spriteSheet == 0) { + RenderHelper.setBlockTextureSheet(); + } else { + RenderHelper.setItemTextureSheet(); + } + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F); + drawTexturedModelRectFromIcon(x, y, icon, 16, 16); + } + + public void drawColorIcon(IIcon icon, int x, int y, int spriteSheet) { + + if (spriteSheet == 0) { + RenderHelper.setBlockTextureSheet(); + } else { + RenderHelper.setItemTextureSheet(); + } + drawTexturedModelRectFromIcon(x, y, icon, 16, 16); + } + + public void drawIcon(String iconName, int x, int y, int spriteSheet) { + + drawIcon(getIcon(iconName), x, y, spriteSheet); + } + + public void drawSizedModalRect(int x1, int y1, int x2, int y2, int color) { + + int temp; + + if (x1 < x2) { + temp = x1; + x1 = x2; + x2 = temp; + } + if (y1 < y2) { + temp = y1; + y1 = y2; + y2 = temp; + } + + float a = (color >> 24 & 255) / 255.0F; + float r = (color >> 16 & 255) / 255.0F; + float g = (color >> 8 & 255) / 255.0F; + float b = (color & 255) / 255.0F; + Tessellator tessellator = Tessellator.instance; + GL11.glEnable(GL11.GL_BLEND); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glColor4f(r, g, b, a); + tessellator.startDrawingQuads(); + tessellator.addVertex(x1, y2, this.zLevel); + tessellator.addVertex(x2, y2, this.zLevel); + tessellator.addVertex(x2, y1, this.zLevel); + tessellator.addVertex(x1, y1, this.zLevel); + tessellator.draw(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_BLEND); + } + + public void drawSizedRect(int x1, int y1, int x2, int y2, int color) { + + int temp; + + if (x1 < x2) { + temp = x1; + x1 = x2; + x2 = temp; + } + if (y1 < y2) { + temp = y1; + y1 = y2; + y2 = temp; + } + + float a = (color >> 24 & 255) / 255.0F; + float r = (color >> 16 & 255) / 255.0F; + float g = (color >> 8 & 255) / 255.0F; + float b = (color & 255) / 255.0F; + Tessellator tessellator = Tessellator.instance; + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glColor4f(r, g, b, a); + tessellator.startDrawingQuads(); + tessellator.addVertex(x1, y2, this.zLevel); + tessellator.addVertex(x2, y2, this.zLevel); + tessellator.addVertex(x2, y1, this.zLevel); + tessellator.addVertex(x1, y1, this.zLevel); + tessellator.draw(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + } + + public void drawSizedTexturedModalRect(int x, int y, int u, int v, int width, int height, float texW, float texH) { + + float texU = 1 / texW; + float texV = 1 / texH; + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV(x + 0, y + height, this.zLevel, (u + 0) * texU, (v + height) * texV); + tessellator.addVertexWithUV(x + width, y + height, this.zLevel, (u + width) * texU, (v + height) * texV); + tessellator.addVertexWithUV(x + width, y + 0, this.zLevel, (u + width) * texU, (v + 0) * texV); + tessellator.addVertexWithUV(x + 0, y + 0, this.zLevel, (u + 0) * texU, (v + 0) * texV); + tessellator.draw(); + } + + public void drawScaledTexturedModelRectFromIcon(int x, int y, IIcon icon, int width, int height) { + + if (icon == null) { + return; + } + double minU = icon.getMinU(); + double maxU = icon.getMaxU(); + double minV = icon.getMinV(); + double maxV = icon.getMaxV(); + + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV(x + 0, y + height, this.zLevel, minU, minV + (maxV - minV) * height / 16F); + tessellator.addVertexWithUV(x + width, y + height, this.zLevel, minU + (maxU - minU) * width / 16F, minV + (maxV - minV) * height / 16F); + tessellator.addVertexWithUV(x + width, y + 0, this.zLevel, minU + (maxU - minU) * width / 16F, minV); + tessellator.addVertexWithUV(x + 0, y + 0, this.zLevel, minU, minV); + tessellator.draw(); + } + + public void drawTooltip(List list) { + + drawTooltipHoveringText(list, mouseX + guiLeft, mouseY + guiTop, fontRendererObj); + tooltip.clear(); + } + + @SuppressWarnings("rawtypes") + protected void drawTooltipHoveringText(List list, int x, int y, FontRenderer font) { + + if (list == null || list.isEmpty()) { + return; + } + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_DEPTH_TEST); + int k = 0; + Iterator iterator = list.iterator(); + + while (iterator.hasNext()) { + String s = (String) iterator.next(); + int l = font.getStringWidth(s); + + if (l > k) { + k = l; + } + } + int i1 = x + 12; + int j1 = y - 12; + int k1 = 8; + + if (list.size() > 1) { + k1 += 2 + (list.size() - 1) * 10; + } + if (i1 + k > this.width) { + i1 -= 28 + k; + } + if (j1 + k1 + 6 > this.height) { + j1 = this.height - k1 - 6; + } + this.zLevel = 300.0F; + itemRender.zLevel = 300.0F; + int l1 = -267386864; + this.drawGradientRect(i1 - 3, j1 - 4, i1 + k + 3, j1 - 3, l1, l1); + this.drawGradientRect(i1 - 3, j1 + k1 + 3, i1 + k + 3, j1 + k1 + 4, l1, l1); + this.drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 + k1 + 3, l1, l1); + this.drawGradientRect(i1 - 4, j1 - 3, i1 - 3, j1 + k1 + 3, l1, l1); + this.drawGradientRect(i1 + k + 3, j1 - 3, i1 + k + 4, j1 + k1 + 3, l1, l1); + int i2 = 1347420415; + int j2 = (i2 & 16711422) >> 1 | i2 & -16777216; + this.drawGradientRect(i1 - 3, j1 - 3 + 1, i1 - 3 + 1, j1 + k1 + 3 - 1, i2, j2); + this.drawGradientRect(i1 + k + 2, j1 - 3 + 1, i1 + k + 3, j1 + k1 + 3 - 1, i2, j2); + this.drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 - 3 + 1, i2, i2); + this.drawGradientRect(i1 - 3, j1 + k1 + 2, i1 + k + 3, j1 + k1 + 3, j2, j2); + + for (int k2 = 0; k2 < list.size(); ++k2) { + String s1 = (String) list.get(k2); + font.drawStringWithShadow(s1, i1, j1, -1); + + if (k2 == 0) { + j1 += 2; + } + j1 += 10; + } + this.zLevel = 0.0F; + itemRender.zLevel = 0.0F; + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + } + + /** + * Passthrough method for tab use. + */ + public void mouseClicked(int mouseButton) { + + super.mouseClicked(guiLeft + mouseX, guiTop + mouseY, mouseButton); + } + + public FontRenderer getFontRenderer() { + + return fontRendererObj; + } + + protected int getCenteredOffset(String string) { + + return this.getCenteredOffset(string, xSize); + } + + protected int getCenteredOffset(String string, int xWidth) { + + return (xWidth - fontRendererObj.getStringWidth(string)) / 2; + } + + public int getGuiLeft() { + + return guiLeft; + } + + public int getGuiTop() { + + return guiTop; + } + + public int getMouseX() { + + return mouseX; + } + + public int getMouseY() { + + return mouseY; + } + + public void overlayRecipe() { + + } + +} \ No newline at end of file diff --git a/src/main/java/techreborn/cofhLib/gui/element/ElementListBox.java b/src/main/java/techreborn/cofhLib/gui/element/ElementListBox.java index ce0f02028..49596570a 100755 --- a/src/main/java/techreborn/cofhLib/gui/element/ElementListBox.java +++ b/src/main/java/techreborn/cofhLib/gui/element/ElementListBox.java @@ -1,367 +1,339 @@ package techreborn.cofhLib.gui.element; +import techreborn.cofhLib.gui.GuiBase; +import techreborn.cofhLib.gui.GuiColor; +import techreborn.cofhLib.gui.element.listbox.IListBoxElement; import techreborn.cofhLib.util.helpers.StringHelper; -import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.*; import java.util.Collection; import java.util.LinkedList; import java.util.List; -public class ElementListBox extends ElementBase -{ +public class ElementListBox extends ElementBase { - public int borderColor = new techreborn.cofhLib.gui.GuiColor(120, 120, 120, 255).getColor(); - public int backgroundColor = new techreborn.cofhLib.gui.GuiColor(0, 0, 0, 255).getColor(); - public int selectedLineColor = new techreborn.cofhLib.gui.GuiColor(0, 0, 0, 255).getColor(); - public int textColor = new techreborn.cofhLib.gui.GuiColor(150, 150, 150, 255).getColor(); - public int selectedTextColor = new techreborn.cofhLib.gui.GuiColor(255, 255, 255, 255).getColor(); + public int borderColor = new GuiColor(120, 120, 120, 255).getColor(); + public int backgroundColor = new GuiColor(0, 0, 0, 255).getColor(); + public int selectedLineColor = new GuiColor(0, 0, 0, 255).getColor(); + public int textColor = new GuiColor(150, 150, 150, 255).getColor(); + public int selectedTextColor = new GuiColor(255, 255, 255, 255).getColor(); - private final int _marginTop = 2; - private final int _marginLeft = 2; - private final int _marginRight = 2; - private final int _marginBottom = 2; + private final int _marginTop = 2; + private final int _marginLeft = 2; + private final int _marginRight = 2; + private final int _marginBottom = 2; - private final List _elements = new LinkedList(); + private final List _elements = new LinkedList(); - private int _firstIndexDisplayed; - private int _selectedIndex; - private int scrollHoriz; + private int _firstIndexDisplayed; + private int _selectedIndex; + private int scrollHoriz; - public ElementListBox(techreborn.cofhLib.gui.GuiBase containerScreen, int x, int y, int width, int height) - { + public ElementListBox(GuiBase containerScreen, int x, int y, int width, int height) { - super(containerScreen, x, y, width, height); - } + super(containerScreen, x, y, width, height); + } - public void add(techreborn.cofhLib.gui.element.listbox.IListBoxElement element) - { + public void add(IListBoxElement element) { - _elements.add(element); - } + _elements.add(element); + } - public void add(Collection elements) - { + public void add(Collection elements) { - _elements.addAll(elements); - } + _elements.addAll(elements); + } - public void remove(techreborn.cofhLib.gui.element.listbox.IListBoxElement element) - { + public void remove(IListBoxElement element) { - _elements.remove(element); - } + _elements.remove(element); + } - public void removeAt(int index) - { + public void removeAt(int index) { - _elements.remove(index); - } + _elements.remove(index); + } - public int getInternalWidth() - { + public void removeAll() { - int width = 0; - for (int i = 0; i < _elements.size(); i++) - { - width = Math.max(_elements.get(i).getWidth(), width); - } - return width; - } + _elements.clear(); + } - public int getInternalHeight() - { + public int getInternalWidth() { - int height = 0; - for (int i = 0; i < _elements.size(); i++) - { - height += _elements.get(i).getHeight(); - } - return height; - } - - public int getContentWidth() - { + int width = 0; + for (int i = 0; i < _elements.size(); i++) { + width = Math.max(_elements.get(i).getWidth(), width); + } + return width; + } - return sizeX - _marginLeft - _marginRight; - } - - public int getContentHeight() - { - - return sizeY - _marginTop - _marginBottom; - } - - public int getContentTop() - { - - return posY + _marginTop; - } - - public int getContentLeft() - { - - return posX + _marginLeft; - } - - public final int getContentBottom() - { - - return getContentTop() + getContentHeight(); - } - - public final int getContentRight() - { - - return getContentLeft() + getContentWidth(); - } - - @Override - public void drawBackground(int mouseX, int mouseY, float gameTicks) - { - - drawModalRect(posX - 1, posY - 1, posX + sizeX + 1, posY + sizeY + 1, borderColor); - drawModalRect(posX, posY, posX + sizeX, posY + sizeY, backgroundColor); - } - - @Override - public void drawForeground(int mouseX, int mouseY) - { - - int heightDrawn = 0; - int nextElement = _firstIndexDisplayed; - - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glPushMatrix(); - - GL11.glEnable(GL11.GL_STENCIL_TEST); - GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT); - drawStencil(getContentLeft(), getContentTop(), getContentRight(), getContentBottom(), 1); - - GL11.glTranslated(-scrollHoriz, 0, 0); - - int e = _elements.size(); - while (nextElement < e && heightDrawn <= getContentHeight()) - { - if (nextElement == _selectedIndex) - { - _elements.get(nextElement).draw(this, getContentLeft(), getContentTop() + heightDrawn, selectedLineColor, selectedTextColor); - } - else - { - _elements.get(nextElement).draw(this, getContentLeft(), getContentTop() + heightDrawn, backgroundColor, textColor); - } - heightDrawn += _elements.get(nextElement).getHeight(); - nextElement++; - } - - GL11.glDisable(GL11.GL_STENCIL_TEST); - - GL11.glPopMatrix(); - } - - @Override - public boolean onMousePressed(int mouseX, int mouseY, int mouseButton) - { - - int heightChecked = 0; - for (int i = _firstIndexDisplayed; i < _elements.size(); i++) - { - if (heightChecked > getContentHeight()) - { - break; - } - int elementHeight = _elements.get(i).getHeight(); - if (getContentTop() + heightChecked <= mouseY && getContentTop() + heightChecked + elementHeight >= mouseY) - { - setSelectedIndex(i); - onElementClicked(_elements.get(i)); - break; - } - heightChecked += elementHeight; - } - return true; - } - - @Override - public boolean onMouseWheel(int mouseX, int mouseY, int movement) - { - - if (StringHelper.isControlKeyDown()) - { - if (movement > 0) - { - scrollLeft(); - } - else if (movement < 0) - { - scrollRight(); - } - } - else - { - if (movement > 0) - { - scrollUp(); - } - else if (movement < 0) - { - scrollDown(); - } - } - return true; - } - - public void scrollDown() - { - - int heightDisplayed = 0; - int elementsDisplayed = 0; - for (int i = _firstIndexDisplayed; i < _elements.size(); i++) - { - if (heightDisplayed + _elements.get(i).getHeight() > sizeY) - { - break; - } - heightDisplayed += _elements.get(i).getHeight(); - elementsDisplayed++; - } - - if (_firstIndexDisplayed + elementsDisplayed < _elements.size()) - { - _firstIndexDisplayed++; - } - - onScrollV(_firstIndexDisplayed); - } - - public void scrollUp() - { - - if (_firstIndexDisplayed > 0) - { - _firstIndexDisplayed--; - } - onScrollV(_firstIndexDisplayed); - } - - public void scrollLeft() - { - - scrollHoriz = Math.max(scrollHoriz - 15, 0); - onScrollH(scrollHoriz); - } - - public void scrollRight() - { - - scrollHoriz = Math.min(scrollHoriz + 15, getLastScrollPositionH()); - onScrollH(scrollHoriz); - } - - public int getLastScrollPosition() - { - - int position = _elements.size() - 1; - int heightUsed = _elements.get(position).getHeight(); - - while (position > 0 && heightUsed < sizeY) - { - position--; - heightUsed += _elements.get(position).getHeight(); - } - - return position + 1; - } - - public int getLastScrollPositionH() - { - - return Math.max(getInternalWidth() - getContentWidth(), 0); - } - - public int getSelectedIndex() - { - - return _selectedIndex; - } - - public int getIndexOf(Object value) - { - - for (int i = 0; i < _elements.size(); i++) - { - if (_elements.get(i).getValue().equals(value)) - { - return i; - } - } - return -1; - } - - public techreborn.cofhLib.gui.element.listbox.IListBoxElement getSelectedElement() - { + public int getInternalHeight() { - return _elements.get(_selectedIndex); - } + int height = 0; + for (int i = 0; i < _elements.size(); i++) { + height += _elements.get(i).getHeight(); + } + return height; + } - public void setSelectedIndex(int index) - { + public int getContentWidth() { - if (index >= 0 && index < _elements.size() && index != _selectedIndex) - { - _selectedIndex = index; - onSelectionChanged(_selectedIndex, getSelectedElement()); - } - } + return sizeX - _marginLeft - _marginRight; + } - public techreborn.cofhLib.gui.element.listbox.IListBoxElement getElement(int index) - { + public int getContentHeight() { - return _elements.get(index); - } + return sizeY - _marginTop - _marginBottom; + } - public int getElementCount() - { + public int getContentTop() { - return _elements.size(); - } + return posY + _marginTop; + } - public void scrollToV(int index) - { + public int getContentLeft() { - if (index >= 0 && index < _elements.size()) - { - _firstIndexDisplayed = index; - } - } + return posX + _marginLeft; + } - public void scrollToH(int index) - { + public final int getContentBottom() { - if (index >= 0 && index <= getLastScrollPositionH()) - { - scrollHoriz = index; - } - } + return getContentTop() + getContentHeight(); + } - protected void onElementClicked(techreborn.cofhLib.gui.element.listbox.IListBoxElement element) - { + public final int getContentRight() { - } + return getContentLeft() + getContentWidth(); + } - protected void onScrollV(int newStartIndex) - { + public ElementListBox setTextColor(Number textColor, Number selectedTextColor) { - } + if (textColor != null) { + this.textColor = textColor.intValue(); + } + if (selectedTextColor != null) { + this.selectedTextColor = selectedTextColor.intValue(); + } + return this; + } - protected void onScrollH(int newStartIndex) - { + public ElementListBox setSelectionColor(Number selectedLineColor) { - } + if (selectedLineColor != null) { + this.selectedLineColor = selectedLineColor.intValue(); + } + return this; + } + + public ElementListBox setBackgroundColor(Number backgroundColor, Number borderColor) { + + if (backgroundColor != null) { + this.backgroundColor = backgroundColor.intValue(); + } + if (borderColor != null) { + this.borderColor = borderColor.intValue(); + } + return this; + } + + @Override + public void drawBackground(int mouseX, int mouseY, float gameTicks) { + + drawModalRect(posX - 1, posY - 1, posX + sizeX + 1, posY + sizeY + 1, borderColor); + drawModalRect(posX, posY, posX + sizeX, posY + sizeY, backgroundColor); + } + + @Override + public void drawForeground(int mouseX, int mouseY) { + + int heightDrawn = 0; + int nextElement = _firstIndexDisplayed; + + glPushMatrix(); + glDisable(GL_LIGHTING); + + glEnable(GL_STENCIL_TEST); + glClear(GL_STENCIL_BUFFER_BIT); + drawStencil(getContentLeft(), getContentTop(), getContentRight(), getContentBottom(), 1); + + glTranslated(-scrollHoriz, 0, 0); + + int e = _elements.size(); + while (nextElement < e && heightDrawn <= getContentHeight()) { + if (nextElement == _selectedIndex) { + _elements.get(nextElement).draw(this, getContentLeft(), getContentTop() + heightDrawn, selectedLineColor, selectedTextColor); + } else { + _elements.get(nextElement).draw(this, getContentLeft(), getContentTop() + heightDrawn, backgroundColor, textColor); + } + heightDrawn += _elements.get(nextElement).getHeight(); + nextElement++; + } + glDisable(GL_STENCIL_TEST); + glPopMatrix(); + } + + @Override + public boolean onMousePressed(int mouseX, int mouseY, int mouseButton) { + + int heightChecked = 0; + for (int i = _firstIndexDisplayed; i < _elements.size(); i++) { + if (heightChecked > getContentHeight()) { + break; + } + int elementHeight = _elements.get(i).getHeight(); + if (getContentTop() + heightChecked <= mouseY && getContentTop() + heightChecked + elementHeight >= mouseY) { + setSelectedIndex(i); + onElementClicked(_elements.get(i)); + break; + } + heightChecked += elementHeight; + } + return true; + } + + @Override + public boolean onMouseWheel(int mouseX, int mouseY, int movement) { + + if (StringHelper.isControlKeyDown()) { + if (movement > 0) { + scrollLeft(); + } else if (movement < 0) { + scrollRight(); + } + } else { + if (movement > 0) { + scrollUp(); + } else if (movement < 0) { + scrollDown(); + } + } + return true; + } + + public void scrollDown() { + + int heightDisplayed = 0; + int elementsDisplayed = 0; + for (int i = _firstIndexDisplayed; i < _elements.size(); i++) { + if (heightDisplayed + _elements.get(i).getHeight() > sizeY) { + break; + } + heightDisplayed += _elements.get(i).getHeight(); + elementsDisplayed++; + } + if (_firstIndexDisplayed + elementsDisplayed < _elements.size()) { + _firstIndexDisplayed++; + } + onScrollV(_firstIndexDisplayed); + } + + public void scrollUp() { + + if (_firstIndexDisplayed > 0) { + _firstIndexDisplayed--; + } + onScrollV(_firstIndexDisplayed); + } - protected void onSelectionChanged(int newIndex, techreborn.cofhLib.gui.element.listbox.IListBoxElement newElement) - { + public void scrollLeft() { + + scrollHoriz = Math.max(scrollHoriz - 15, 0); + onScrollH(scrollHoriz); + } + + public void scrollRight() { - } + scrollHoriz = Math.min(scrollHoriz + 15, getLastScrollPositionH()); + onScrollH(scrollHoriz); + } + + public int getLastScrollPosition() { + + int position = _elements.size() - 1; + int heightUsed = _elements.get(position).getHeight(); + + while (position > 0 && heightUsed < sizeY) { + position--; + heightUsed += _elements.get(position).getHeight(); + } + return position + 1; + } + + public int getLastScrollPositionH() { + + return Math.max(getInternalWidth() - getContentWidth(), 0); + } + + public int getSelectedIndex() { -} + return _selectedIndex; + } + + public int getIndexOf(Object value) { + + for (int i = 0; i < _elements.size(); i++) { + if (_elements.get(i).getValue().equals(value)) { + return i; + } + } + return -1; + } + + public IListBoxElement getSelectedElement() { + + if (_selectedIndex == -1 || _selectedIndex == _elements.size()) { + return null; + } + return _elements.get(_selectedIndex); + } + + public void setSelectedIndex(int index) { + + if (index >= -1 && index != _selectedIndex && index < _elements.size()) { + _selectedIndex = index; + onSelectionChanged(_selectedIndex, getSelectedElement()); + } + } + + public IListBoxElement getElement(int index) { + + return _elements.get(index); + } + + public int getElementCount() { + + return _elements.size(); + } + + public void scrollToV(int index) { + + if (index >= 0 && index < _elements.size()) { + _firstIndexDisplayed = index; + } + } + + public void scrollToH(int index) { + + if (index >= 0 && index <= getLastScrollPositionH()) { + scrollHoriz = index; + } + } + + protected void onElementClicked(IListBoxElement element) { + + } + + protected void onScrollV(int newStartIndex) { + + } + + protected void onScrollH(int newStartIndex) { + + } + + protected void onSelectionChanged(int newIndex, IListBoxElement newElement) { + + } + +} \ No newline at end of file