Search bar is working, small rendering bug dealing with AIOOB errors with certain ItemStacks that still needs resolving however

This commit is contained in:
Pahimar 2015-02-20 18:51:43 -05:00
parent c9ec087253
commit c0cc0c4154
3 changed files with 45 additions and 16 deletions

View file

@ -6,6 +6,7 @@ import com.pahimar.ee3.network.message.MessageGuiElementClicked;
import com.pahimar.ee3.network.message.MessageGuiElementTextFieldUpdate;
import com.pahimar.ee3.reference.Textures;
import com.pahimar.repackage.cofh.lib.gui.GuiBase;
import com.pahimar.repackage.cofh.lib.gui.GuiColor;
import com.pahimar.repackage.cofh.lib.gui.element.ElementButton;
import com.pahimar.repackage.cofh.lib.gui.element.ElementTextField;
import cpw.mods.fml.relauncher.Side;
@ -17,10 +18,6 @@ import org.lwjgl.opengl.GL11;
@SideOnly(Side.CLIENT)
public class GuiAlchemicalTome extends GuiBase
{
private static final int LEFT_CLICK = 0;
private int pageOffset;
private ElementButton prevPageButton;
private ElementButton nextPageButton;
private ElementTextField searchTextField;
@ -53,6 +50,9 @@ public class GuiAlchemicalTome extends GuiBase
}
}
};
searchTextField.borderColor = new GuiColor(160, 160, 160).getColor();
searchTextField.backgroundColor = new GuiColor(0, 0, 0).getColor();
searchTextField.setFocused(true);
addElement(prevPageButton);
addElement(nextPageButton);

View file

@ -37,7 +37,21 @@ public class ContainerAlchemicalTome extends ContainerEE
{
for (int columnIndex = 0; columnIndex < MAX_COLUMN_INDEX; ++columnIndex)
{
this.addSlotToContainer(new Slot(inventoryTransmutationKnowledge, i, 18 + columnIndex * 20, 18 + rowIndex * 19));
this.addSlotToContainer(new Slot(inventoryTransmutationKnowledge, i, 18 + columnIndex * 20, 18 + rowIndex * 19)
{
@Override
public boolean canTakeStack(EntityPlayer player)
{
return false;
}
@Override
@SideOnly(Side.CLIENT)
public boolean func_111238_b()
{
return false;
}
});
i++;
}
}
@ -47,7 +61,21 @@ public class ContainerAlchemicalTome extends ContainerEE
{
for (int columnIndex = 0; columnIndex < MAX_COLUMN_INDEX; ++columnIndex)
{
this.addSlotToContainer(new Slot(inventoryTransmutationKnowledge, i, 140 + columnIndex * 20, 18 + rowIndex * 19));
this.addSlotToContainer(new Slot(inventoryTransmutationKnowledge, i, 140 + columnIndex * 20, 18 + rowIndex * 19)
{
@Override
public boolean canTakeStack(EntityPlayer player)
{
return false;
}
@Override
@SideOnly(Side.CLIENT)
public boolean func_111238_b()
{
return false;
}
});
i++;
}
}
@ -58,6 +86,7 @@ public class ContainerAlchemicalTome extends ContainerEE
{
super.addCraftingToCrafters(iCrafting);
iCrafting.sendProgressBarUpdate(this, 0, this.pageOffset);
iCrafting.sendProgressBarUpdate(this, 1, this.maxPageOffset);
}
@Override
@ -71,6 +100,7 @@ public class ContainerAlchemicalTome extends ContainerEE
{
ICrafting icrafting = (ICrafting) crafter;
icrafting.sendProgressBarUpdate(this, 0, this.pageOffset);
icrafting.sendProgressBarUpdate(this, 1, this.maxPageOffset);
}
}
}
@ -82,6 +112,10 @@ public class ContainerAlchemicalTome extends ContainerEE
{
this.pageOffset = updatedValue;
}
else if (valueType == 1)
{
this.maxPageOffset = updatedValue;
}
}
public int getInventorySize()
@ -106,13 +140,11 @@ public class ContainerAlchemicalTome extends ContainerEE
{
this.pageOffset--;
updateInventory();
this.requiresUpdate = true;
}
else if (buttonName.equalsIgnoreCase("next") && mouseButton == 0 && this.pageOffset < this.maxPageOffset)
{
this.pageOffset++;
updateInventory();
this.requiresUpdate = true;
}
}
@ -124,17 +156,17 @@ public class ContainerAlchemicalTome extends ContainerEE
this.searchTerm = updatedText;
pageOffset = 0;
updateInventory();
this.requiresUpdate = true;
}
}
private void updateInventory()
{
this.requiresUpdate = true;
boolean shouldUpdateInventory = false;
ItemStack[] newInventory = new ItemStack[80];
List<ItemStack> filteredList = new ArrayList(ItemHelper.filterByNameContains(inventoryTransmutationKnowledge.getKnownTransmutations(), searchTerm));
maxPageOffset = filteredList.size() % 80;
maxPageOffset = filteredList.size() / 80;
if (pageOffset > maxPageOffset)
{
pageOffset = 0;
@ -160,7 +192,7 @@ public class ContainerAlchemicalTome extends ContainerEE
}
else if (pageOffset == maxPageOffset)
{
newInventory = filteredList.subList(pageOffset * 80, filteredList.size()).toArray(newInventory);
newInventory = filteredList.subList(pageOffset * 80, filteredList.size() - 1).toArray(newInventory);
shouldUpdateInventory = true;
}

View file

@ -1,6 +1,5 @@
package com.pahimar.repackage.cofh.lib.gui.element;
import com.pahimar.ee3.util.LogHelper;
import com.pahimar.repackage.cofh.lib.gui.GuiBase;
import com.pahimar.repackage.cofh.lib.gui.GuiColor;
import com.pahimar.repackage.cofh.lib.util.helpers.MathHelper;
@ -15,7 +14,6 @@ import static org.lwjgl.opengl.GL11.*;
public class ElementTextField extends ElementBase
{
public int borderColor = new GuiColor(55, 55, 55).getColor();
public int backgroundColor = new GuiColor(139, 139, 139).getColor();
public int disabledColor = new GuiColor(198, 198, 198).getColor();
@ -374,7 +372,6 @@ public class ElementTextField extends ElementBase
@Override
public boolean onKeyTyped(char charTyped, int keyTyped)
{
LogHelper.info(keyTyped);
if (!isFocused())
{
return false;
@ -662,7 +659,7 @@ public class ElementTextField extends ElementBase
FontRenderer font = getFontRenderer();
char[] text = this.text;
int startX = posX + 1, endX = sizeX - 1, startY = posY + 1, endY = startY + font.FONT_HEIGHT;
int startX = posX + 3, endX = sizeX - 3, startY = posY + 6, endY = startY + font.FONT_HEIGHT;
for (int i = renderStart, width = 0; i <= textLength; ++i)
{
boolean end = i == textLength;
@ -694,7 +691,7 @@ public class ElementTextField extends ElementBase
{
drawModalRect(startX + width, startY, startX + width + charW, endY, selectedLineColor);
}
font.drawString(String.valueOf(text[i]), startX + width, startY, selected ? selectedTextColor : textColor);
font.drawStringWithShadow(String.valueOf(text[i]), startX + width, startY, selected ? selectedTextColor : textColor);
}
if (drawCaret)