updated some CofhLib Files trying to fix text rendering, still not working

This commit is contained in:
modmuss50 2015-06-17 11:24:41 +01:00
parent 74525d260a
commit d8e6e88797
3 changed files with 1029 additions and 1171 deletions

View file

@ -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));

View file

@ -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,8 +32,7 @@ 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();
@ -45,33 +47,29 @@ public abstract class GuiBase extends GuiContainer
protected ResourceLocation texture;
public ArrayList<TabBase> tabs = new ArrayList<TabBase>();
protected ArrayList<techreborn.cofhLib.gui.element.ElementBase> elements = new ArrayList<techreborn.cofhLib.gui.element.ElementBase>();
protected ArrayList<ElementBase> elements = new ArrayList<ElementBase>();
protected List<String> tooltip = new LinkedList<String>();
protected boolean tooltips = true;
public static void playSound(String name, float volume, float pitch)
{
public static void playSound(String name, float volume, float pitch) {
guiSoundManager.playSound(new techreborn.cofhLib.audio.SoundBase(name, volume, pitch));
guiSoundManager.playSound(new SoundBase(name, volume, pitch));
}
public GuiBase(Container container)
{
public GuiBase(Container container) {
super(container);
}
public GuiBase(Container container, ResourceLocation texture)
{
public GuiBase(Container container, ResourceLocation texture) {
super(container);
this.texture = texture;
}
@Override
public void initGui()
{
public void initGui() {
super.initGui();
tabs.clear();
@ -79,15 +77,13 @@ public abstract class GuiBase extends GuiContainer
}
@Override
public void drawScreen(int x, int y, float partialTick)
{
public void drawScreen(int x, int y, float partialTick) {
updateElementInformation();
super.drawScreen(x, y, partialTick);
if (tooltips && mc.thePlayer.inventory.getItemStack() == null)
{
if (tooltips && mc.thePlayer.inventory.getItemStack() == null) {
addTooltips(tooltip);
drawTooltip(tooltip);
}
@ -98,15 +94,12 @@ public abstract class GuiBase extends GuiContainer
}
@Override
protected void drawGuiContainerForegroundLayer(int x, int y)
{
protected void drawGuiContainerForegroundLayer(int x, int y) {
if (drawTitle)
{
if (drawTitle) {
fontRendererObj.drawString(StringHelper.localize(name), getCenteredOffset(StringHelper.localize(name)), 6, 0x404040);
}
if (drawInventory)
{
if (drawInventory) {
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 3, 0x404040);
}
drawElements(0, true);
@ -114,8 +107,7 @@ public abstract class GuiBase extends GuiContainer
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTick, int x, int y)
{
protected void drawGuiContainerBackgroundLayer(float partialTick, int x, int y) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
bindTexture(texture);
@ -132,18 +124,14 @@ public abstract class GuiBase extends GuiContainer
}
@Override
protected void keyTyped(char characterTyped, int keyPressed)
{
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())
{
for (int i = elements.size(); i-- > 0;) {
ElementBase c = elements.get(i);
if (!c.isVisible() || !c.isEnabled()) {
continue;
}
if (c.onKeyTyped(characterTyped, keyPressed))
{
if (c.onKeyTyped(characterTyped, keyPressed)) {
return;
}
}
@ -151,8 +139,7 @@ public abstract class GuiBase extends GuiContainer
}
@Override
public void handleMouseInput()
{
public void handleMouseInput() {
int x = Mouse.getEventX() * width / mc.displayWidth;
int y = height - Mouse.getEventY() * height / mc.displayHeight - 1;
@ -162,24 +149,19 @@ public abstract class GuiBase extends GuiContainer
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))
{
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))
{
if (c.onMouseWheel(mouseX, mouseY, wheelMovement)) {
return;
}
}
TabBase tab = getTabAtPosition(mouseX, mouseY);
if (tab != null && tab.onMouseWheel(mouseX, mouseY, wheelMovement))
{
if (tab != null && tab.onMouseWheel(mouseX, mouseY, wheelMovement)) {
return;
}
}
@ -187,37 +169,29 @@ public abstract class GuiBase extends GuiContainer
}
@Override
protected void mouseClicked(int mX, int mY, int mouseButton)
{
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))
{
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))
{
if (c.onMousePressed(mX, mY, mouseButton)) {
return;
}
}
TabBase tab = getTabAtPosition(mX, mY);
if (tab != null)
{
if (tab != null) {
int tMx = mX;
if (!tab.onMousePressed(tMx, mY, mouseButton))
{
for (int i = tabs.size(); i-- > 0; )
{
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)
{
if (other != tab && other.open && other.side == tab.side) {
other.toggleOpen();
}
}
@ -229,12 +203,10 @@ public abstract class GuiBase extends GuiContainer
mX += guiLeft;
mY += guiTop;
if (tab != null)
{
switch (tab.side)
{
if (tab != null) {
switch (tab.side) {
case TabBase.LEFT:
guiLeft -= tab.currentWidth;
// guiLeft -= tab.currentWidth;
break;
case TabBase.RIGHT:
xSize += tab.currentWidth;
@ -242,12 +214,10 @@ public abstract class GuiBase extends GuiContainer
}
}
super.mouseClicked(mX, mY, mouseButton);
if (tab != null)
{
switch (tab.side)
{
if (tab != null) {
switch (tab.side) {
case TabBase.LEFT:
guiLeft += tab.currentWidth;
// guiLeft += tab.currentWidth;
break;
case TabBase.RIGHT:
xSize -= tab.currentWidth;
@ -257,19 +227,15 @@ public abstract class GuiBase extends GuiContainer
}
@Override
protected void mouseMovedOrUp(int mX, int mY, int mouseButton)
{
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
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);
@ -282,44 +248,35 @@ public abstract class GuiBase extends GuiContainer
}
@Override
protected void mouseClickMove(int mX, int mY, int lastClick, long timeSinceClick)
{
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)
{
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
{
} else {
lastIndex = -1;
super.mouseClickMove(mX, mY, lastClick, timeSinceClick);
}
}
public Slot getSlotAtPosition(int xCoord, int yCoord)
{
public Slot getSlotAtPosition(int xCoord, int yCoord) {
for (int k = 0; k < this.inventorySlots.inventorySlots.size(); ++k)
{
for (int k = 0; k < this.inventorySlots.inventorySlots.size(); ++k) {
Slot slot = (Slot) this.inventorySlots.inventorySlots.get(k);
if (this.isMouseOverSlot(slot, xCoord, yCoord))
{
if (this.isMouseOverSlot(slot, xCoord, yCoord)) {
return slot;
}
}
return null;
}
public boolean isMouseOverSlot(Slot theSlot, int xCoord, int yCoord)
{
public boolean isMouseOverSlot(Slot theSlot, int xCoord, int yCoord) {
return this.func_146978_c(theSlot.xDisplayPosition, theSlot.yDisplayPosition, 16, 16, xCoord, yCoord);
}
@ -327,27 +284,19 @@ public abstract class GuiBase extends GuiContainer
/**
* Draws the elements for this GUI.
*/
protected void drawElements(float partialTick, boolean foreground)
{
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())
{
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++)
{
techreborn.cofhLib.gui.element.ElementBase element = elements.get(i);
if (element.isVisible())
{
} else {
for (int i = 0; i < elements.size(); i++) {
ElementBase element = elements.get(i);
if (element.isVisible()) {
element.drawBackground(mouseX, mouseY, partialTick);
}
}
@ -357,131 +306,121 @@ public abstract class GuiBase extends GuiContainer
/**
* Draws the tabs for this GUI. Handles Tab open/close animation.
*/
protected void drawTabs(float partialTick, boolean foreground)
{
protected void drawTabs(float partialTick, boolean foreground) {
if (foreground)
{
return;
}
int yPosRight = 4;
int yPosLeft = 4;
for (int i = 0; i < tabs.size(); i++)
{
if (foreground) {
for (int i = 0; i < tabs.size(); i++) {
TabBase tab = tabs.get(i);
tab.update();
if (!tab.isVisible())
{
if (!tab.isVisible()) {
continue;
}
if (tab.side == TabBase.LEFT)
{
tab.draw(0, yPosLeft);
if (tab.side == TabBase.LEFT) {
tab.drawForeground(mouseX, mouseY);
yPosLeft += tab.currentHeight;
}
else
{
tab.draw(xSize, yPosRight);
} 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<String> handleTooltip(int mousex, int mousey, List<String> tooltip)
{
public List<String> handleTooltip(int mousex, int mousey, List<String> tooltip) {
if (mc.thePlayer.inventory.getItemStack() == null)
{
if (mc.thePlayer.inventory.getItemStack() == null) {
addTooltips(tooltip);
}
return tooltip;
}
public void addTooltips(List<String> tooltip)
{
public void addTooltips(List<String> tooltip) {
TabBase tab = getTabAtPosition(mouseX, mouseY);
if (tab != null)
{
if (tab != null) {
tab.addTooltip(tooltip);
}
techreborn.cofhLib.gui.element.ElementBase element = getElementAtPosition(mouseX, mouseY);
ElementBase element = getElementAtPosition(mouseX, mouseY);
if (element != null)
{
if (element != null && element.isVisible()) {
element.addTooltip(tooltip);
}
}
/* ELEMENTS */
public techreborn.cofhLib.gui.element.ElementBase addElement(techreborn.cofhLib.gui.element.ElementBase element)
{
public ElementBase addElement(ElementBase element) {
elements.add(element);
return element;
}
public TabBase addTab(TabBase tab)
{
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())
{
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()))
{
if (TabTracker.getOpenedLeftTab() != null && tab.getClass().equals(TabTracker.getOpenedLeftTab())) {
tab.setFullyOpen();
}
else if (TabTracker.getOpenedRightTab() != null && tab.getClass().equals(TabTracker.getOpenedRightTab()))
{
} 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)
{
protected 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))
{
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)
{
protected TabBase getTabAtPosition(int mX, int mY) {
int xShift = 0;
int yShift = 4;
for (int i = 0; i < tabs.size(); i++)
{
for (int i = 0; i < tabs.size(); i++) {
TabBase tab = tabs.get(i);
if (!tab.isVisible() || tab.side == TabBase.RIGHT)
{
if (!tab.isVisible() || tab.side == TabBase.RIGHT) {
continue;
}
tab.setCurrentShift(xShift, yShift);
if (tab.intersectsWith(mX, mY, xShift, yShift))
{
if (tab.intersectsWith(mX, mY, xShift, yShift)) {
return tab;
}
yShift += tab.currentHeight;
@ -490,16 +429,13 @@ public abstract class GuiBase extends GuiContainer
xShift = xSize;
yShift = 4;
for (int i = 0; i < tabs.size(); i++)
{
for (int i = 0; i < tabs.size(); i++) {
TabBase tab = tabs.get(i);
if (!tab.isVisible() || tab.side == TabBase.LEFT)
{
if (!tab.isVisible() || tab.side == TabBase.LEFT) {
continue;
}
tab.setCurrentShift(xShift, yShift);
if (tab.intersectsWith(mX, mY, xShift, yShift))
{
if (tab.intersectsWith(mX, mY, xShift, yShift)) {
return tab;
}
yShift += tab.currentHeight;
@ -507,32 +443,26 @@ public abstract class GuiBase extends GuiContainer
return null;
}
protected final void updateElements()
{
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())
{
for (int i = elements.size(); i-- > 0;) {
ElementBase c = elements.get(i);
if (c.isVisible() && c.isEnabled()) {
c.update(mouseX, mouseY);
}
}
}
protected void updateElementInformation()
{
protected void updateElementInformation() {
}
public void handleElementButtonClick(String buttonName, int mouseButton)
{
public void handleElementButtonClick(String buttonName, int mouseButton) {
}
/* HELPERS */
public void bindTexture(ResourceLocation texture)
{
public void bindTexture(ResourceLocation texture) {
mc.renderEngine.bindTexture(texture);
}
@ -540,8 +470,7 @@ public abstract class GuiBase extends GuiContainer
/**
* 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)
{
public IIcon getIcon(String name) {
return null;
}
@ -549,14 +478,12 @@ public abstract class GuiBase extends GuiContainer
/**
* 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)
{
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)
{
public void drawButton(String iconName, int x, int y, int spriteSheet, int mode) {
drawButton(getIcon(iconName), x, y, spriteSheet, mode);
}
@ -564,11 +491,9 @@ public abstract class GuiBase extends GuiContainer
/**
* Simple method used to draw a fluid of arbitrary size.
*/
public void drawFluid(int x, int y, FluidStack fluid, int width, int height)
{
public void drawFluid(int x, int y, FluidStack fluid, int width, int height) {
if (fluid == null || fluid.getFluid() == null)
{
if (fluid == null || fluid.getFluid() == null) {
return;
}
RenderHelper.setBlockTextureSheet();
@ -577,8 +502,7 @@ public abstract class GuiBase extends GuiContainer
drawTiledTexture(x, y, fluid.getFluid().getIcon(fluid), width, height);
}
public void drawTiledTexture(int x, int y, IIcon icon, int width, int height)
{
public void drawTiledTexture(int x, int y, IIcon icon, int width, int height) {
int i = 0;
int j = 0;
@ -586,10 +510,8 @@ public abstract class GuiBase extends GuiContainer
int drawHeight = 0;
int drawWidth = 0;
for (i = 0; i < width; i += 16)
{
for (j = 0; j < height; j += 16)
{
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);
@ -598,54 +520,42 @@ public abstract class GuiBase extends GuiContainer
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F);
}
public void drawIcon(IIcon icon, int x, int y, int spriteSheet)
{
public void drawIcon(IIcon icon, int x, int y, int spriteSheet) {
if (spriteSheet == 0)
{
if (spriteSheet == 0) {
RenderHelper.setBlockTextureSheet();
}
else
{
} 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)
{
public void drawColorIcon(IIcon icon, int x, int y, int spriteSheet) {
if (spriteSheet == 0)
{
if (spriteSheet == 0) {
RenderHelper.setBlockTextureSheet();
}
else
{
} else {
RenderHelper.setItemTextureSheet();
}
drawTexturedModelRectFromIcon(x, y, icon, 16, 16);
}
public void drawIcon(String iconName, int x, int y, int spriteSheet)
{
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)
{
public void drawSizedModalRect(int x1, int y1, int x2, int y2, int color) {
int temp;
if (x1 < x2)
{
if (x1 < x2) {
temp = x1;
x1 = x2;
x2 = temp;
}
if (y1 < y2)
{
if (y1 < y2) {
temp = y1;
y1 = y2;
y2 = temp;
@ -670,19 +580,16 @@ public abstract class GuiBase extends GuiContainer
GL11.glDisable(GL11.GL_BLEND);
}
public void drawSizedRect(int x1, int y1, int x2, int y2, int color)
{
public void drawSizedRect(int x1, int y1, int x2, int y2, int color) {
int temp;
if (x1 < x2)
{
if (x1 < x2) {
temp = x1;
x1 = x2;
x2 = temp;
}
if (y1 < y2)
{
if (y1 < y2) {
temp = y1;
y1 = y2;
y2 = temp;
@ -704,8 +611,7 @@ public abstract class GuiBase extends GuiContainer
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)
{
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;
@ -718,11 +624,9 @@ public abstract class GuiBase extends GuiContainer
tessellator.draw();
}
public void drawScaledTexturedModelRectFromIcon(int x, int y, IIcon icon, int width, int height)
{
public void drawScaledTexturedModelRectFromIcon(int x, int y, IIcon icon, int width, int height) {
if (icon == null)
{
if (icon == null) {
return;
}
double minU = icon.getMinU();
@ -739,19 +643,16 @@ public abstract class GuiBase extends GuiContainer
tessellator.draw();
}
public void drawTooltip(List<String> list)
{
public void drawTooltip(List<String> list) {
drawTooltipHoveringText(list, mouseX + guiLeft, mouseY + guiTop, fontRendererObj);
tooltip.clear();
}
@SuppressWarnings("rawtypes")
protected void drawTooltipHoveringText(List list, int x, int y, FontRenderer font)
{
protected void drawTooltipHoveringText(List list, int x, int y, FontRenderer font) {
if (list == null || list.isEmpty())
{
if (list == null || list.isEmpty()) {
return;
}
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
@ -760,13 +661,11 @@ public abstract class GuiBase extends GuiContainer
int k = 0;
Iterator iterator = list.iterator();
while (iterator.hasNext())
{
while (iterator.hasNext()) {
String s = (String) iterator.next();
int l = font.getStringWidth(s);
if (l > k)
{
if (l > k) {
k = l;
}
}
@ -774,16 +673,13 @@ public abstract class GuiBase extends GuiContainer
int j1 = y - 12;
int k1 = 8;
if (list.size() > 1)
{
if (list.size() > 1) {
k1 += 2 + (list.size() - 1) * 10;
}
if (i1 + k > this.width)
{
if (i1 + k > this.width) {
i1 -= 28 + k;
}
if (j1 + k1 + 6 > this.height)
{
if (j1 + k1 + 6 > this.height) {
j1 = this.height - k1 - 6;
}
this.zLevel = 300.0F;
@ -801,13 +697,11 @@ public abstract class GuiBase extends GuiContainer
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)
{
for (int k2 = 0; k2 < list.size(); ++k2) {
String s1 = (String) list.get(k2);
font.drawStringWithShadow(s1, i1, j1, -1);
if (k2 == 0)
{
if (k2 == 0) {
j1 += 2;
}
j1 += 10;
@ -822,56 +716,47 @@ public abstract class GuiBase extends GuiContainer
/**
* Passthrough method for tab use.
*/
public void mouseClicked(int mouseButton)
{
public void mouseClicked(int mouseButton) {
super.mouseClicked(guiLeft + mouseX, guiTop + mouseY, mouseButton);
}
public FontRenderer getFontRenderer()
{
public FontRenderer getFontRenderer() {
return fontRendererObj;
}
protected int getCenteredOffset(String string)
{
protected int getCenteredOffset(String string) {
return this.getCenteredOffset(string, xSize);
}
protected int getCenteredOffset(String string, int xWidth)
{
protected int getCenteredOffset(String string, int xWidth) {
return (xWidth - fontRendererObj.getStringWidth(string)) / 2;
}
public int getGuiLeft()
{
public int getGuiLeft() {
return guiLeft;
}
public int getGuiTop()
{
public int getGuiTop() {
return guiTop;
}
public int getMouseX()
{
public int getMouseX() {
return mouseX;
}
public int getMouseY()
{
public int getMouseY() {
return mouseY;
}
public void overlayRecipe()
{
public void overlayRecipe() {
}

View file

@ -1,178 +1,188 @@
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 List<techreborn.cofhLib.gui.element.listbox.IListBoxElement> _elements = new LinkedList<techreborn.cofhLib.gui.element.listbox.IListBoxElement>();
private final List<IListBoxElement> _elements = new LinkedList<IListBoxElement>();
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);
}
public void add(techreborn.cofhLib.gui.element.listbox.IListBoxElement element)
{
public void add(IListBoxElement element) {
_elements.add(element);
}
public void add(Collection<? extends techreborn.cofhLib.gui.element.listbox.IListBoxElement> elements)
{
public void add(Collection<? extends IListBoxElement> elements) {
_elements.addAll(elements);
}
public void remove(techreborn.cofhLib.gui.element.listbox.IListBoxElement element)
{
public void remove(IListBoxElement element) {
_elements.remove(element);
}
public void removeAt(int index)
{
public void removeAt(int index) {
_elements.remove(index);
}
public int getInternalWidth()
{
public void removeAll() {
_elements.clear();
}
public int getInternalWidth() {
int width = 0;
for (int i = 0; i < _elements.size(); i++)
{
for (int i = 0; i < _elements.size(); i++) {
width = Math.max(_elements.get(i).getWidth(), width);
}
return width;
}
public int getInternalHeight()
{
public int getInternalHeight() {
int height = 0;
for (int i = 0; i < _elements.size(); i++)
{
for (int i = 0; i < _elements.size(); i++) {
height += _elements.get(i).getHeight();
}
return height;
}
public int getContentWidth()
{
public int getContentWidth() {
return sizeX - _marginLeft - _marginRight;
}
public int getContentHeight()
{
public int getContentHeight() {
return sizeY - _marginTop - _marginBottom;
}
public int getContentTop()
{
public int getContentTop() {
return posY + _marginTop;
}
public int getContentLeft()
{
public int getContentLeft() {
return posX + _marginLeft;
}
public final int getContentBottom()
{
public final int getContentBottom() {
return getContentTop() + getContentHeight();
}
public final int getContentRight()
{
public final int getContentRight() {
return getContentLeft() + getContentWidth();
}
public ElementListBox setTextColor(Number textColor, Number selectedTextColor) {
if (textColor != null) {
this.textColor = textColor.intValue();
}
if (selectedTextColor != null) {
this.selectedTextColor = selectedTextColor.intValue();
}
return this;
}
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)
{
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)
{
public void drawForeground(int mouseX, int mouseY) {
int heightDrawn = 0;
int nextElement = _firstIndexDisplayed;
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glPushMatrix();
glPushMatrix();
glDisable(GL_LIGHTING);
GL11.glEnable(GL11.GL_STENCIL_TEST);
GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT);
glEnable(GL_STENCIL_TEST);
glClear(GL_STENCIL_BUFFER_BIT);
drawStencil(getContentLeft(), getContentTop(), getContentRight(), getContentBottom(), 1);
GL11.glTranslated(-scrollHoriz, 0, 0);
glTranslated(-scrollHoriz, 0, 0);
int e = _elements.size();
while (nextElement < e && heightDrawn <= getContentHeight())
{
if (nextElement == _selectedIndex)
{
while (nextElement < e && heightDrawn <= getContentHeight()) {
if (nextElement == _selectedIndex) {
_elements.get(nextElement).draw(this, getContentLeft(), getContentTop() + heightDrawn, selectedLineColor, selectedTextColor);
}
else
{
} 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();
glDisable(GL_STENCIL_TEST);
glPopMatrix();
}
@Override
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton)
{
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton) {
int heightChecked = 0;
for (int i = _firstIndexDisplayed; i < _elements.size(); i++)
{
if (heightChecked > getContentHeight())
{
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)
{
if (getContentTop() + heightChecked <= mouseY && getContentTop() + heightChecked + elementHeight >= mouseY) {
setSelectedIndex(i);
onElementClicked(_elements.get(i));
break;
@ -183,184 +193,146 @@ public class ElementListBox extends ElementBase
}
@Override
public boolean onMouseWheel(int mouseX, int mouseY, int movement)
{
public boolean onMouseWheel(int mouseX, int mouseY, int movement) {
if (StringHelper.isControlKeyDown())
{
if (movement > 0)
{
if (StringHelper.isControlKeyDown()) {
if (movement > 0) {
scrollLeft();
}
else if (movement < 0)
{
} else if (movement < 0) {
scrollRight();
}
}
else
{
if (movement > 0)
{
} else {
if (movement > 0) {
scrollUp();
}
else if (movement < 0)
{
} else if (movement < 0) {
scrollDown();
}
}
return true;
}
public void scrollDown()
{
public void scrollDown() {
int heightDisplayed = 0;
int elementsDisplayed = 0;
for (int i = _firstIndexDisplayed; i < _elements.size(); i++)
{
if (heightDisplayed + _elements.get(i).getHeight() > sizeY)
{
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())
{
if (_firstIndexDisplayed + elementsDisplayed < _elements.size()) {
_firstIndexDisplayed++;
}
onScrollV(_firstIndexDisplayed);
}
public void scrollUp()
{
public void scrollUp() {
if (_firstIndexDisplayed > 0)
{
if (_firstIndexDisplayed > 0) {
_firstIndexDisplayed--;
}
onScrollV(_firstIndexDisplayed);
}
public void scrollLeft()
{
public void scrollLeft() {
scrollHoriz = Math.max(scrollHoriz - 15, 0);
onScrollH(scrollHoriz);
}
public void scrollRight()
{
public void scrollRight() {
scrollHoriz = Math.min(scrollHoriz + 15, getLastScrollPositionH());
onScrollH(scrollHoriz);
}
public int getLastScrollPosition()
{
public int getLastScrollPosition() {
int position = _elements.size() - 1;
int heightUsed = _elements.get(position).getHeight();
while (position > 0 && heightUsed < sizeY)
{
while (position > 0 && heightUsed < sizeY) {
position--;
heightUsed += _elements.get(position).getHeight();
}
return position + 1;
}
public int getLastScrollPositionH()
{
public int getLastScrollPositionH() {
return Math.max(getInternalWidth() - getContentWidth(), 0);
}
public int getSelectedIndex()
{
public int getSelectedIndex() {
return _selectedIndex;
}
public int getIndexOf(Object value)
{
public int getIndexOf(Object value) {
for (int i = 0; i < _elements.size(); i++)
{
if (_elements.get(i).getValue().equals(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 IListBoxElement getSelectedElement() {
if (_selectedIndex == -1 || _selectedIndex == _elements.size()) {
return null;
}
return _elements.get(_selectedIndex);
}
public void setSelectedIndex(int index)
{
public void setSelectedIndex(int index) {
if (index >= 0 && index < _elements.size() && index != _selectedIndex)
{
if (index >= -1 && index != _selectedIndex && index < _elements.size()) {
_selectedIndex = index;
onSelectionChanged(_selectedIndex, getSelectedElement());
}
}
public techreborn.cofhLib.gui.element.listbox.IListBoxElement getElement(int index)
{
public IListBoxElement getElement(int index) {
return _elements.get(index);
}
public int getElementCount()
{
public int getElementCount() {
return _elements.size();
}
public void scrollToV(int index)
{
public void scrollToV(int index) {
if (index >= 0 && index < _elements.size())
{
if (index >= 0 && index < _elements.size()) {
_firstIndexDisplayed = index;
}
}
public void scrollToH(int index)
{
public void scrollToH(int index) {
if (index >= 0 && index <= getLastScrollPositionH())
{
if (index >= 0 && index <= getLastScrollPositionH()) {
scrollHoriz = index;
}
}
protected void onElementClicked(techreborn.cofhLib.gui.element.listbox.IListBoxElement element)
{
protected void onElementClicked(IListBoxElement element) {
}
protected void onScrollV(int newStartIndex)
{
protected void onScrollV(int newStartIndex) {
}
protected void onScrollH(int newStartIndex)
{
protected void onScrollH(int newStartIndex) {
}
protected void onSelectionChanged(int newIndex, techreborn.cofhLib.gui.element.listbox.IListBoxElement newElement)
{
protected void onSelectionChanged(int newIndex, IListBoxElement newElement) {
}