mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-22 13:10:13 +00:00
remember filter and sort mode, show item count in tooltip for large stacks, fix NEI overlapping with GUI
This commit is contained in:
1 parent
2dd9090220
commit
f607a06656
6 files changed
+171
-6
No files matched your search
@@ -30,6 +30,7 @@ public class BlockInventoryPanel extends AbstractMachineBlock<TileInventoryPanel
|
||||
PacketHandler.INSTANCE.registerMessage(PacketFetchItem.class, PacketFetchItem.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketMoveItems.class, PacketMoveItems.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketDatabaseReset.class, PacketDatabaseReset.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketGuiSettings.class, PacketGuiSettings.class, PacketHandler.nextID(), Side.SERVER);
|
||||
|
||||
BlockInventoryPanel panel = new BlockInventoryPanel();
|
||||
panel.init();
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -11,6 +13,7 @@ import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -38,6 +41,7 @@ import crazypants.gui.GuiToolTip;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.ItemUtil;
|
||||
import crazypants.util.Lang;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
@@ -61,6 +65,7 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
private final MultiIconButtonEIO btnClear;
|
||||
|
||||
private int scrollPos;
|
||||
private int ghostSlotTooltipStacksize;
|
||||
|
||||
private final String headerCrafting;
|
||||
private final String headerReturn;
|
||||
@@ -83,10 +88,18 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
|
||||
this.view = new DatabaseView();
|
||||
|
||||
int sortMode = te.getGuiSortMode();
|
||||
int sortOrderIdx = sortMode >> 1;
|
||||
SortOrder[] orders = SortOrder.values();
|
||||
if(sortOrderIdx >= 0 && te.getGuiSortMode() < orders.length) {
|
||||
view.setSortOrder(orders[sortOrderIdx], (sortMode & 1) != 0);
|
||||
}
|
||||
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
tfFilter = new TextFieldEIO(fr, 108, 11, 106, 10);
|
||||
tfFilter.setEnableBackgroundDrawing(false);
|
||||
tfFilter.setText(te.getGuiFilterString());
|
||||
btnSort = new IconButtonEIO(this, ID_SORT, 233, 27, getSortOrderIcon()) {
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft mc, int x, int y) {
|
||||
@@ -156,6 +169,16 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
int sortMode = (view.getSortOrder().ordinal() << 1);
|
||||
if(view.isSortOrderInverted()) {
|
||||
sortMode |= 1;
|
||||
}
|
||||
getTileEntity().setGuiParameter(sortMode, tfFilter.getText());
|
||||
super.onGuiClosed();
|
||||
}
|
||||
|
||||
public void setCraftingHelper(ICraftingHelper craftingHelper) {
|
||||
this.craftingHelper = craftingHelper;
|
||||
ttRefill.setVisible(craftingHelper != null);
|
||||
@@ -251,13 +274,40 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
font = fontRendererObj;
|
||||
}
|
||||
String str = null;
|
||||
if(stack.stackSize > 999) {
|
||||
str = (stack.stackSize / 1000) + "k";
|
||||
if(stack.stackSize >= 1000) {
|
||||
int value = stack.stackSize / 1000;
|
||||
String unit = "k";
|
||||
if(value >= 1000) {
|
||||
value /= 1000;
|
||||
unit = "m";
|
||||
}
|
||||
str = value + unit;
|
||||
}
|
||||
itemRender.renderItemAndEffectIntoGUI(font, mc.renderEngine, stack, x, y);
|
||||
itemRender.renderItemOverlayIntoGUI(font, mc.renderEngine, stack, x, y, str);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGhostSlotTooltip(GhostSlot slot, int mouseX, int mouseY) {
|
||||
ItemStack stack = slot.getStack();
|
||||
if(stack != null) {
|
||||
ghostSlotTooltipStacksize = stack.stackSize;
|
||||
try {
|
||||
renderToolTip(stack, mouseX, mouseY);
|
||||
} finally {
|
||||
ghostSlotTooltipStacksize = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawHoveringText(List list, int mouseX, int mouseY, FontRenderer font) {
|
||||
if(ghostSlotTooltipStacksize >= 1000) {
|
||||
list.add(EnumChatFormatting.WHITE + Lang.localize("gui.inventorypanel.tooltip.itemsstored", Integer.toString(ghostSlotTooltipStacksize)));
|
||||
}
|
||||
super.drawHoveringText(list, mouseX, mouseY, font);
|
||||
}
|
||||
|
||||
public InventoryPanelContainer getContainer() {
|
||||
return (InventoryPanelContainer) inventorySlots;
|
||||
}
|
||||
@@ -338,6 +388,19 @@ public class GuiInventoryPanel extends GuiMachineBase<TileInventoryPanel> {
|
||||
return 212;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "NotEnoughItems")
|
||||
public boolean hideItemPanelSlot(GuiContainer gc, int x, int y, int w, int h) {
|
||||
// NEI seems to have an issue with the shifted GUI position - so let's work around it
|
||||
if(x+w >= guiLeft && x < guiLeft+xSize && y+h >= guiTop && y < guiTop+49) {
|
||||
return true;
|
||||
}
|
||||
if(x+w >= guiLeft && x < guiLeft+232 && x+h >= guiTop+49 && y < guiTop+ySize) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int button) {
|
||||
super.mouseClicked(x, y, button);
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package crazypants.enderio.machine.invpanel;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class PacketGuiSettings extends MessageTileEntity<TileInventoryPanel> implements IMessageHandler<PacketGuiSettings, IMessage> {
|
||||
|
||||
private int sortMode;
|
||||
private String filterString;
|
||||
|
||||
public PacketGuiSettings() {
|
||||
filterString = "";
|
||||
}
|
||||
|
||||
public PacketGuiSettings(TileInventoryPanel tile, int sortMode, String filterString) {
|
||||
super(tile);
|
||||
this.sortMode = sortMode;
|
||||
this.filterString = filterString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
sortMode = buf.readInt();
|
||||
int len = buf.readUnsignedShort();
|
||||
if(len > 0) {
|
||||
byte[] utf8 = new byte[len];
|
||||
buf.readBytes(utf8);
|
||||
try {
|
||||
filterString = new String(utf8, "UTF8");
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
// should not happen - if it does we can't do anything
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeInt(sortMode);
|
||||
if(filterString.isEmpty()) {
|
||||
buf.writeShort(0);
|
||||
} else {
|
||||
try {
|
||||
byte[] utf8 = filterString.getBytes("UTF8");
|
||||
buf.writeShort((short) utf8.length);
|
||||
buf.writeBytes(utf8);
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
// should not happen - if it does we can't do anything
|
||||
buf.writeShort(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketGuiSettings message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
TileEntity te = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
||||
if(te instanceof TileInventoryPanel) {
|
||||
TileInventoryPanel teInvPanel = (TileInventoryPanel) te;
|
||||
teInvPanel.setGuiParameter(message.sortMode, message.filterString);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,9 @@ public class TileInventoryPanel extends AbstractMachineEntity implements IFluidH
|
||||
public Container eventHandler;
|
||||
private IItemFilter itemFilter;
|
||||
|
||||
private int guiSortMode;
|
||||
private String guiFilterString = "";
|
||||
|
||||
public TileInventoryPanel() {
|
||||
super(new SlotDefinition(0, 8, 11, 20, 21, 20));
|
||||
this.fuelTank = new SmartTank(EnderIO.fluidNutrientDistillation, 2000);
|
||||
@@ -201,16 +204,38 @@ public class TileInventoryPanel extends AbstractMachineEntity implements IFluidH
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getGuiSortMode() {
|
||||
return guiSortMode;
|
||||
}
|
||||
|
||||
public String getGuiFilterString() {
|
||||
return guiFilterString;
|
||||
}
|
||||
|
||||
public void setGuiParameter(int sortMode, String filterString) {
|
||||
this.guiSortMode = sortMode;
|
||||
this.guiFilterString = filterString;
|
||||
if(worldObj != null && worldObj.isRemote) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketGuiSettings(this, sortMode, filterString));
|
||||
} else {
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCommon(NBTTagCompound nbtRoot) {
|
||||
super.writeCommon(nbtRoot);
|
||||
fuelTank.writeCommon("fuelTank", nbtRoot);
|
||||
nbtRoot.setInteger("guiSortMode", guiSortMode);
|
||||
nbtRoot.setString("guiFilterString", guiFilterString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCommon(NBTTagCompound nbtRoot) {
|
||||
super.readCommon(nbtRoot);
|
||||
fuelTank.readCommon("fuelTank", nbtRoot);
|
||||
guiSortMode = nbtRoot.getInteger("guiSortMode");
|
||||
guiFilterString = nbtRoot.getString("guiFilterString");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -337,10 +337,7 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
|
||||
if(draggingScrollbar == null) {
|
||||
if(hoverGhostSlot != null && mc.thePlayer.inventory.getItemStack() == null) {
|
||||
ItemStack stack = hoverGhostSlot.getStack();
|
||||
if(stack != null) {
|
||||
renderToolTip(stack, par1, par2);
|
||||
}
|
||||
drawGhostSlotTooltip(hoverGhostSlot, par1, par2);
|
||||
}
|
||||
|
||||
ttMan.drawTooltips(this, par1, par2);
|
||||
@@ -396,6 +393,13 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
zLevel = 0.0F;
|
||||
}
|
||||
|
||||
protected void drawGhostSlotTooltip(GhostSlot slot, int mouseX, int mouseY) {
|
||||
ItemStack stack = slot.getStack();
|
||||
if(stack != null) {
|
||||
renderToolTip(stack, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawGhostSlots(int mouseX, int mouseY) {
|
||||
if(ghostSlots.isEmpty()) {
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user