Trying to figure out search boxes and scroll bars. Holy hell Minecraft
This commit is contained in:
parent
9edf1409a3
commit
e70eecb11f
|
@ -1,31 +1,118 @@
|
|||
package com.pahimar.ee3.client.gui.inventory;
|
||||
|
||||
import com.pahimar.ee3.inventory.ContainerAlchemicalTome;
|
||||
import com.pahimar.ee3.inventory.InventoryAlchemicalTome;
|
||||
import com.pahimar.ee3.reference.Textures;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.renderer.InventoryEffectRenderer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.InventoryBasic;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiAlchemicalTome extends GuiContainer
|
||||
public class GuiAlchemicalTome extends InventoryEffectRenderer
|
||||
{
|
||||
private InventoryAlchemicalTome inventoryAlchemicalTome;
|
||||
// private InventoryAlchemicalTome inventoryAlchemicalTome;
|
||||
private InventoryPlayer inventoryPlayer;
|
||||
public static InventoryBasic tempInventory = new InventoryBasic("tmp", true, 81);
|
||||
|
||||
public GuiAlchemicalTome(InventoryAlchemicalTome inventoryAlchemicalTome)
|
||||
private float currentScroll;
|
||||
private boolean isScrolling;
|
||||
private boolean wasClicking;
|
||||
private GuiTextField searchField;
|
||||
|
||||
private Slot field_147064_C;
|
||||
private boolean field_147057_D;
|
||||
|
||||
public GuiAlchemicalTome(EntityPlayer entityPlayer)
|
||||
{
|
||||
super(new ContainerAlchemicalTome(inventoryAlchemicalTome));
|
||||
this.inventoryAlchemicalTome = inventoryAlchemicalTome;
|
||||
ySize = 209;
|
||||
super(new ContainerAlchemicalTome(entityPlayer.inventory));
|
||||
this.inventoryPlayer = entityPlayer.inventory;
|
||||
entityPlayer.openContainer = this.inventorySlots;
|
||||
this.allowUserInput = true;
|
||||
xSize = 209;
|
||||
ySize = 200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
this.searchField = new GuiTextField(this.fontRendererObj, this.guiLeft + 90, this.guiTop + 19, 96, this.fontRendererObj.FONT_HEIGHT);
|
||||
this.searchField.setMaxStringLength(32);
|
||||
this.searchField.setEnableBackgroundDrawing(false);
|
||||
this.searchField.setVisible(true);
|
||||
this.searchField.setFocused(true);
|
||||
this.searchField.setCanLoseFocus(false);
|
||||
this.searchField.setText("");
|
||||
this.searchField.setTextColor(16777215);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed()
|
||||
{
|
||||
super.onGuiClosed();
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
}
|
||||
|
||||
public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_)
|
||||
{
|
||||
boolean flag = Mouse.isButtonDown(0);
|
||||
int k = this.guiLeft;
|
||||
int l = this.guiTop;
|
||||
int i1 = k + 175;
|
||||
int j1 = l + 18;
|
||||
int k1 = i1 + 14;
|
||||
int l1 = j1 + 112;
|
||||
|
||||
if (!this.wasClicking && flag && p_73863_1_ >= i1 && p_73863_2_ >= j1 && p_73863_1_ < k1 && p_73863_2_ < l1)
|
||||
{
|
||||
this.isScrolling = this.needsScrollBars();
|
||||
}
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
this.isScrolling = false;
|
||||
}
|
||||
|
||||
this.wasClicking = flag;
|
||||
|
||||
if (this.isScrolling)
|
||||
{
|
||||
this.currentScroll = ((float) (p_73863_2_ - j1) - 7.5F) / ((float) (l1 - j1) - 15.0F);
|
||||
|
||||
if (this.currentScroll < 0.0F)
|
||||
{
|
||||
this.currentScroll = 0.0F;
|
||||
}
|
||||
|
||||
if (this.currentScroll > 1.0F)
|
||||
{
|
||||
this.currentScroll = 1.0F;
|
||||
}
|
||||
|
||||
((ContainerAlchemicalTome) this.inventorySlots).scrollTo(this.currentScroll);
|
||||
}
|
||||
|
||||
super.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_);
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int x, int y)
|
||||
{
|
||||
String containerName = StatCollector.translateToLocal(inventoryAlchemicalTome.getInventoryName());
|
||||
String containerName = StatCollector.translateToLocal(inventoryPlayer.getInventoryName());
|
||||
fontRendererObj.drawString(containerName, xSize / 2 - fontRendererObj.getStringWidth(containerName) / 2, 6, 4210752);
|
||||
fontRendererObj.drawString("Search Items", 16, 20, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,5 +123,78 @@ public class GuiAlchemicalTome extends GuiContainer
|
|||
int xStart = (width - xSize) / 2;
|
||||
int yStart = (height - ySize) / 2;
|
||||
this.drawTexturedModalRect(xStart, yStart, 0, 0, xSize, ySize);
|
||||
this.searchField.drawTextBox();
|
||||
}
|
||||
|
||||
protected void keyTyped(char p_73869_1_, int p_73869_2_)
|
||||
{
|
||||
if (this.field_147057_D)
|
||||
{
|
||||
this.field_147057_D = false;
|
||||
this.searchField.setText("");
|
||||
}
|
||||
|
||||
if (!this.checkHotbarKeys(p_73869_2_))
|
||||
{
|
||||
if (this.searchField.textboxKeyTyped(p_73869_1_, p_73869_2_))
|
||||
{
|
||||
this.updateSearch();
|
||||
}
|
||||
else
|
||||
{
|
||||
super.keyTyped(p_73869_1_, p_73869_2_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSearch()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void updateFilteredItems(ContainerAlchemicalTome containerAlchemicalTome)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput()
|
||||
{
|
||||
super.handleMouseInput();
|
||||
int i = Mouse.getEventDWheel();
|
||||
|
||||
if (i != 0 && this.needsScrollBars())
|
||||
{
|
||||
int j = ((ContainerAlchemicalTome) this.inventorySlots).itemList.size() / 9 - 5 + 1;
|
||||
|
||||
if (i > 0)
|
||||
{
|
||||
i = 1;
|
||||
}
|
||||
|
||||
if (i < 0)
|
||||
{
|
||||
i = -1;
|
||||
}
|
||||
|
||||
this.currentScroll = (float) ((double) this.currentScroll - (double) i / (double) j);
|
||||
|
||||
if (this.currentScroll < 0.0F)
|
||||
{
|
||||
this.currentScroll = 0.0F;
|
||||
}
|
||||
|
||||
if (this.currentScroll > 1.0F)
|
||||
{
|
||||
this.currentScroll = 1.0F;
|
||||
}
|
||||
|
||||
((ContainerAlchemicalTome) this.inventorySlots).scrollTo(this.currentScroll);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean needsScrollBars()
|
||||
{
|
||||
return ((ContainerAlchemicalTome) this.inventorySlots).isScrollable();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,8 @@ public class GuiHandler implements IGuiHandler
|
|||
}
|
||||
else if (id == GuiId.ALCHEMICAL_TOME.ordinal())
|
||||
{
|
||||
return new ContainerAlchemicalTome(new InventoryAlchemicalTome(entityPlayer.getHeldItem()));
|
||||
// return new ContainerAlchemicalTome(new InventoryAlchemicalTome(entityPlayer.getHeldItem()));
|
||||
return new ContainerAlchemicalTome(entityPlayer.inventory);
|
||||
}
|
||||
else if (id == GuiId.CALCINATOR.ordinal())
|
||||
{
|
||||
|
@ -79,7 +80,8 @@ public class GuiHandler implements IGuiHandler
|
|||
}
|
||||
else if (id == GuiId.ALCHEMICAL_TOME.ordinal())
|
||||
{
|
||||
return new GuiAlchemicalTome(new InventoryAlchemicalTome(entityPlayer.getHeldItem()));
|
||||
// return new GuiAlchemicalTome(new InventoryAlchemicalTome(entityPlayer.getHeldItem()));
|
||||
return new GuiAlchemicalTome(entityPlayer);
|
||||
}
|
||||
else if (id == GuiId.CALCINATOR.ordinal())
|
||||
{
|
||||
|
|
|
@ -1,31 +1,110 @@
|
|||
package com.pahimar.ee3.inventory;
|
||||
|
||||
import com.pahimar.ee3.client.gui.inventory.GuiAlchemicalTome;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ContainerAlchemicalTome extends ContainerEE
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ContainerAlchemicalTome extends Container
|
||||
{
|
||||
private InventoryAlchemicalTome inventoryAlchemicalTome;
|
||||
/**
|
||||
* the list of items in this container
|
||||
*/
|
||||
public List itemList = new ArrayList();
|
||||
|
||||
public ContainerAlchemicalTome(InventoryAlchemicalTome inventoryAlchemicalTome)
|
||||
public ContainerAlchemicalTome(InventoryPlayer inventoryPlayer)
|
||||
{
|
||||
this.inventoryAlchemicalTome = inventoryAlchemicalTome;
|
||||
|
||||
for (int x = 0; x < 9; ++x)
|
||||
for (int x = 0; x < 9; x++)
|
||||
{
|
||||
for (int y = 0; y < 9; ++y)
|
||||
for (int y = 0; y < 9; y++)
|
||||
{
|
||||
if (y + x * 9 < inventoryAlchemicalTome.getSizeInventory())
|
||||
this.addSlotToContainer(new Slot(GuiAlchemicalTome.tempInventory, x * 9 + y, 16 + y * 18, 32 + x * 18));
|
||||
}
|
||||
}
|
||||
|
||||
this.scrollTo(0.0F);
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityPlayer p_75145_1_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the gui slots ItemStack's based on scroll position.
|
||||
*/
|
||||
public void scrollTo(float p_148329_1_)
|
||||
{
|
||||
int i = this.itemList.size() / 9 - 5 + 1;
|
||||
int j = (int) ((double) (p_148329_1_ * (float) i) + 0.5D);
|
||||
|
||||
if (j < 0)
|
||||
{
|
||||
j = 0;
|
||||
}
|
||||
|
||||
for (int k = 0; k < 5; ++k)
|
||||
{
|
||||
for (int l = 0; l < 9; ++l)
|
||||
{
|
||||
int i1 = l + (k + j) * 9;
|
||||
|
||||
if (i1 >= 0 && i1 < this.itemList.size())
|
||||
{
|
||||
this.addSlotToContainer(new Slot(inventoryAlchemicalTome, y + x * 9, 8 + y * 18, 18 + x * 18)
|
||||
{
|
||||
public boolean canTakeStack(EntityPlayer entityPlayer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
});
|
||||
GuiAlchemicalTome.tempInventory.setInventorySlotContents(l + k * 9, (ItemStack) this.itemList.get(i1));
|
||||
}
|
||||
else
|
||||
{
|
||||
GuiAlchemicalTome.tempInventory.setInventorySlotContents(l + k * 9, (ItemStack) null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isScrollable()
|
||||
{
|
||||
return this.itemList.size() > 81;
|
||||
}
|
||||
|
||||
protected void retrySlotClick(int p_75133_1_, int p_75133_2_, boolean p_75133_3_, EntityPlayer p_75133_4_)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does
|
||||
* that.
|
||||
*/
|
||||
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_)
|
||||
{
|
||||
if (p_82846_2_ >= this.inventorySlots.size() - 9 && p_82846_2_ < this.inventorySlots.size())
|
||||
{
|
||||
Slot slot = (Slot) this.inventorySlots.get(p_82846_2_);
|
||||
|
||||
if (slot != null && slot.getHasStack())
|
||||
{
|
||||
slot.putStack((ItemStack) null);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean func_94530_a(ItemStack p_94530_1_, Slot p_94530_2_)
|
||||
{
|
||||
return p_94530_2_.yDisplayPosition > 90;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the player can "drag-spilt" items into this slot,. returns true by default. Called to
|
||||
* check if the slot can be added to a list of Slots to split the held ItemStack across.
|
||||
*/
|
||||
public boolean canDragIntoSlot(Slot p_94531_1_)
|
||||
{
|
||||
return p_94531_1_.inventory instanceof InventoryPlayer || p_94531_1_.yDisplayPosition > 90 && p_94531_1_.xDisplayPosition <= 162;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ public class InventoryAlchemicalTome implements IInventory
|
|||
|
||||
public InventoryAlchemicalTome(ItemStack itemStack)
|
||||
{
|
||||
// TODO Handle case where there the NBTTagCompound of the ItemStack is invalid/uninitialized
|
||||
this(PlayerKnowledge.readPlayerKnowledgeFromNBT(itemStack.getTagCompound()));
|
||||
}
|
||||
|
||||
|
|
|
@ -98,6 +98,14 @@ public class PlayerKnowledge implements INBTTaggable
|
|||
knownItemStacks.add(itemStack);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
knownItemStacks = new TreeSet<ItemStack>(ItemHelper.comparator);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
knownItemStacks = new TreeSet<ItemStack>(ItemHelper.comparator);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Binary file not shown.
Loading…
Reference in a new issue