add search to grid!
This commit is contained in:
@@ -10,8 +10,8 @@ import storagecraft.util.InventoryUtils;
|
||||
public class GuiExporter extends GuiMachine {
|
||||
private TileExporter exporter;
|
||||
|
||||
private GuiButton compareNBT;
|
||||
private GuiButton compareDamage;
|
||||
private GuiButton compareNBTButton;
|
||||
private GuiButton compareDamageButton;
|
||||
|
||||
public GuiExporter(ContainerExporter container, TileExporter exporter) {
|
||||
super(container, 176, 186, exporter);
|
||||
@@ -23,19 +23,19 @@ public class GuiExporter extends GuiMachine {
|
||||
public void init(int x, int y) {
|
||||
super.init(x, y);
|
||||
|
||||
buttonList.add(compareNBT = new GuiButton(1, x + 7, y + 41, 100, 20, ""));
|
||||
buttonList.add(compareDamage = new GuiButton(2, x + 7, y + 63, 120, 20, ""));
|
||||
buttonList.add(compareNBTButton = new GuiButton(1, x + 7, y + 41, 100, 20, ""));
|
||||
buttonList.add(compareDamageButton = new GuiButton(2, x + 7, y + 63, 120, 20, ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(int x, int y) {
|
||||
super.update(x, y);
|
||||
|
||||
compareNBT.displayString = t("misc.storagecraft:compareNBT") + ": ";
|
||||
compareNBT.displayString += t("misc.storagecraft:" + ((exporter.getCompareFlags() & InventoryUtils.COMPARE_NBT) == InventoryUtils.COMPARE_NBT ? "on" : "off"));
|
||||
compareNBTButton.displayString = t("misc.storagecraft:compareNBT") + ": ";
|
||||
compareNBTButton.displayString += t("misc.storagecraft:" + ((exporter.getCompareFlags() & InventoryUtils.COMPARE_NBT) == InventoryUtils.COMPARE_NBT ? "on" : "off"));
|
||||
|
||||
compareDamage.displayString = t("misc.storagecraft:compareDamage") + ": ";
|
||||
compareDamage.displayString += t("misc.storagecraft:" + ((exporter.getCompareFlags() & InventoryUtils.COMPARE_DAMAGE) == InventoryUtils.COMPARE_DAMAGE ? "on" : "off"));
|
||||
compareDamageButton.displayString = t("misc.storagecraft:compareDamage") + ": ";
|
||||
compareDamageButton.displayString += t("misc.storagecraft:" + ((exporter.getCompareFlags() & InventoryUtils.COMPARE_DAMAGE) == InventoryUtils.COMPARE_DAMAGE ? "on" : "off"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,9 +59,9 @@ public class GuiExporter extends GuiMachine {
|
||||
|
||||
int flags = exporter.getCompareFlags();
|
||||
|
||||
if (button.id == compareNBT.id) {
|
||||
if (button.id == compareNBTButton.id) {
|
||||
flags ^= InventoryUtils.COMPARE_NBT;
|
||||
} else if (button.id == compareDamage.id) {
|
||||
} else if (button.id == compareDamageButton.id) {
|
||||
flags ^= InventoryUtils.COMPARE_DAMAGE;
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,9 @@
|
||||
package storagecraft.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
@@ -7,6 +11,7 @@ import storagecraft.StorageCraft;
|
||||
import storagecraft.container.ContainerGrid;
|
||||
import storagecraft.network.MessageStoragePull;
|
||||
import storagecraft.network.MessageStoragePush;
|
||||
import storagecraft.storage.StorageItem;
|
||||
import storagecraft.tile.TileController;
|
||||
import storagecraft.tile.TileGrid;
|
||||
|
||||
@@ -14,7 +19,11 @@ public class GuiGrid extends GuiMachine {
|
||||
private ContainerGrid container;
|
||||
private TileGrid grid;
|
||||
|
||||
private int hoveringSlot;
|
||||
private GuiTextField searchField;
|
||||
|
||||
private int hoveringSlotId;
|
||||
private int hoveringId;
|
||||
|
||||
private int offset;
|
||||
|
||||
public GuiGrid(ContainerGrid container, TileGrid grid) {
|
||||
@@ -24,6 +33,18 @@ public class GuiGrid extends GuiMachine {
|
||||
this.grid = grid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(int x, int y) {
|
||||
super.init(x, y);
|
||||
|
||||
searchField = new GuiTextField(fontRendererObj, x + 80 + 2, y + 6 + 1, 88 - 6, fontRendererObj.FONT_HEIGHT);
|
||||
searchField.setEnableBackgroundDrawing(false);
|
||||
searchField.setVisible(true);
|
||||
searchField.setTextColor(16777215);
|
||||
searchField.setCanLoseFocus(false);
|
||||
searchField.setFocused(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(int x, int y) {
|
||||
super.update(x, y);
|
||||
@@ -46,7 +67,7 @@ public class GuiGrid extends GuiMachine {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int max = ((int) Math.ceil((float) grid.getController().getItems().size() / (float) 9)) - 4;
|
||||
int max = ((int) Math.ceil((float) getItems().size() / (float) 9)) - 4;
|
||||
|
||||
return max < 0 ? 0 : max;
|
||||
}
|
||||
@@ -60,11 +81,11 @@ public class GuiGrid extends GuiMachine {
|
||||
}
|
||||
|
||||
private boolean isHoveringOverValidSlot() {
|
||||
return grid.isConnected() && isHoveringOverSlot() && hoveringSlot < grid.getController().getItems().size();
|
||||
return grid.isConnected() && isHoveringOverSlot() && hoveringSlotId < getItems().size();
|
||||
}
|
||||
|
||||
private boolean isHoveringOverSlot() {
|
||||
return hoveringSlot >= 0;
|
||||
return hoveringSlotId >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,6 +93,8 @@ public class GuiGrid extends GuiMachine {
|
||||
bindTexture("gui/grid.png");
|
||||
|
||||
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
||||
|
||||
searchField.drawTextBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,17 +107,25 @@ public class GuiGrid extends GuiMachine {
|
||||
int x = 8;
|
||||
int y = 20;
|
||||
|
||||
hoveringSlot = -1;
|
||||
List<StorageItem> items = getItems();
|
||||
|
||||
hoveringSlotId = -1;
|
||||
|
||||
int slot = offset * 9;
|
||||
|
||||
for (int i = 0; i < 9 * 4; ++i) {
|
||||
if (grid.isConnected() && slot < grid.getController().getItems().size()) {
|
||||
drawItem(x, y, grid.getController().getItems().get(slot).toItemStack(), true);
|
||||
if (slot < items.size()) {
|
||||
drawItem(x, y, items.get(slot).toItemStack(), true);
|
||||
}
|
||||
|
||||
if (inBounds(x, y, 16, 16, mouseX, mouseY) || !grid.isConnected()) {
|
||||
hoveringSlot = slot;
|
||||
hoveringSlotId = slot;
|
||||
|
||||
if (slot < items.size()) {
|
||||
// We need to use the ID, because if we filter, the client-side index will change
|
||||
// while the serverside's index will still be the same.
|
||||
hoveringId = items.get(slot).getId();
|
||||
}
|
||||
|
||||
int color = grid.isConnected() ? -2130706433 : 0xFF5B5B5B;
|
||||
|
||||
@@ -114,7 +145,7 @@ public class GuiGrid extends GuiMachine {
|
||||
}
|
||||
|
||||
if (isHoveringOverValidSlot()) {
|
||||
drawTooltip(mouseX, mouseY, grid.getController().getItems().get(hoveringSlot).toItemStack());
|
||||
drawTooltip(mouseX, mouseY, items.get(hoveringSlotId).toItemStack());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +159,7 @@ public class GuiGrid extends GuiMachine {
|
||||
if (isHoveringOverSlot() && container.getPlayer().inventory.getItemStack() != null) {
|
||||
StorageCraft.NETWORK.sendToServer(new MessageStoragePush(controller.xCoord, controller.yCoord, controller.zCoord, -1, clickedButton == 1));
|
||||
} else if (isHoveringOverValidSlot() && container.getPlayer().inventory.getItemStack() == null) {
|
||||
StorageCraft.NETWORK.sendToServer(new MessageStoragePull(controller.xCoord, controller.yCoord, controller.zCoord, hoveringSlot, clickedButton == 1, Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)));
|
||||
StorageCraft.NETWORK.sendToServer(new MessageStoragePull(controller.xCoord, controller.yCoord, controller.zCoord, hoveringId, clickedButton == 1, Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)));
|
||||
} else {
|
||||
for (int i = 0; i < container.inventorySlots.size(); ++i) {
|
||||
Slot slot = (Slot) container.inventorySlots.get(i);
|
||||
@@ -142,4 +173,36 @@ public class GuiGrid extends GuiMachine {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char character, int keyCode) {
|
||||
if (!checkHotbarKeys(keyCode) && searchField.textboxKeyTyped(character, keyCode)) {
|
||||
} else {
|
||||
super.keyTyped(character, keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
public List<StorageItem> getItems() {
|
||||
List<StorageItem> items = new ArrayList<StorageItem>();
|
||||
|
||||
if (!grid.isConnected()) {
|
||||
return items;
|
||||
}
|
||||
|
||||
items.addAll(grid.getController().getItems());
|
||||
|
||||
if (!searchField.getText().trim().isEmpty()) {
|
||||
Iterator<StorageItem> t = items.iterator();
|
||||
|
||||
while (t.hasNext()) {
|
||||
StorageItem item = t.next();
|
||||
|
||||
if (!item.toItemStack().getDisplayName().toLowerCase().contains(searchField.getText().toLowerCase())) {
|
||||
t.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
@@ -10,9 +10,9 @@ import storagecraft.util.InventoryUtils;
|
||||
public class GuiImporter extends GuiMachine {
|
||||
private TileImporter importer;
|
||||
|
||||
private GuiButton compareNBT;
|
||||
private GuiButton compareDamage;
|
||||
private GuiButton mode;
|
||||
private GuiButton compareNBTButton;
|
||||
private GuiButton compareDamageButton;
|
||||
private GuiButton modeButton;
|
||||
|
||||
public GuiImporter(ContainerImporter container, TileImporter importer) {
|
||||
super(container, 176, 201, importer);
|
||||
@@ -24,22 +24,22 @@ public class GuiImporter extends GuiMachine {
|
||||
public void init(int x, int y) {
|
||||
super.init(x, y);
|
||||
|
||||
buttonList.add(compareNBT = new GuiButton(1, x + 7, y + 41, 100, 20, ""));
|
||||
buttonList.add(compareDamage = new GuiButton(2, x + 7, y + 63, 120, 20, ""));
|
||||
buttonList.add(mode = new GuiButton(3, x + 7, y + 85, 80, 20, ""));
|
||||
buttonList.add(compareNBTButton = new GuiButton(1, x + 7, y + 41, 100, 20, ""));
|
||||
buttonList.add(compareDamageButton = new GuiButton(2, x + 7, y + 63, 120, 20, ""));
|
||||
buttonList.add(modeButton = new GuiButton(3, x + 7, y + 85, 80, 20, ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(int x, int y) {
|
||||
super.update(x, y);
|
||||
|
||||
compareNBT.displayString = t("misc.storagecraft:compareNBT") + ": ";
|
||||
compareNBT.displayString += t("misc.storagecraft:" + ((importer.getCompareFlags() & InventoryUtils.COMPARE_NBT) == InventoryUtils.COMPARE_NBT ? "on" : "off"));
|
||||
compareNBTButton.displayString = t("misc.storagecraft:compareNBT") + ": ";
|
||||
compareNBTButton.displayString += t("misc.storagecraft:" + ((importer.getCompareFlags() & InventoryUtils.COMPARE_NBT) == InventoryUtils.COMPARE_NBT ? "on" : "off"));
|
||||
|
||||
compareDamage.displayString = t("misc.storagecraft:compareDamage") + ": ";
|
||||
compareDamage.displayString += t("misc.storagecraft:" + ((importer.getCompareFlags() & InventoryUtils.COMPARE_DAMAGE) == InventoryUtils.COMPARE_DAMAGE ? "on" : "off"));
|
||||
compareDamageButton.displayString = t("misc.storagecraft:compareDamage") + ": ";
|
||||
compareDamageButton.displayString += t("misc.storagecraft:" + ((importer.getCompareFlags() & InventoryUtils.COMPARE_DAMAGE) == InventoryUtils.COMPARE_DAMAGE ? "on" : "off"));
|
||||
|
||||
mode.displayString = t("misc.storagecraft:importer.mode." + importer.getMode());
|
||||
modeButton.displayString = t("misc.storagecraft:importer.mode." + importer.getMode());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,12 +63,12 @@ public class GuiImporter extends GuiMachine {
|
||||
|
||||
int flags = importer.getCompareFlags();
|
||||
|
||||
if (button.id == compareNBT.id) {
|
||||
if (button.id == compareNBTButton.id) {
|
||||
flags ^= InventoryUtils.COMPARE_NBT;
|
||||
} else if (button.id == compareDamage.id) {
|
||||
} else if (button.id == compareDamageButton.id) {
|
||||
flags ^= InventoryUtils.COMPARE_DAMAGE;
|
||||
}
|
||||
|
||||
StorageCraft.NETWORK.sendToServer(new MessageImporterUpdate(importer.xCoord, importer.yCoord, importer.zCoord, flags, button.id == mode.id));
|
||||
StorageCraft.NETWORK.sendToServer(new MessageImporterUpdate(importer.xCoord, importer.yCoord, importer.zCoord, flags, button.id == modeButton.id));
|
||||
}
|
||||
}
|
||||
|
@@ -14,19 +14,18 @@ public class MessageStoragePull implements IMessage, IMessageHandler<MessageStor
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
// @TODO: This won't work when sorting
|
||||
private int slot;
|
||||
private int id;
|
||||
private boolean half;
|
||||
private boolean shift;
|
||||
|
||||
public MessageStoragePull() {
|
||||
}
|
||||
|
||||
public MessageStoragePull(int x, int y, int z, int slot, boolean half, boolean shift) {
|
||||
public MessageStoragePull(int x, int y, int z, int id, boolean half, boolean shift) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.slot = slot;
|
||||
this.id = id;
|
||||
this.half = half;
|
||||
this.shift = shift;
|
||||
}
|
||||
@@ -36,7 +35,7 @@ public class MessageStoragePull implements IMessage, IMessageHandler<MessageStor
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
slot = buf.readInt();
|
||||
id = buf.readInt();
|
||||
half = buf.readBoolean();
|
||||
shift = buf.readBoolean();
|
||||
}
|
||||
@@ -46,7 +45,7 @@ public class MessageStoragePull implements IMessage, IMessageHandler<MessageStor
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeInt(slot);
|
||||
buf.writeInt(id);
|
||||
buf.writeBoolean(half);
|
||||
buf.writeBoolean(shift);
|
||||
}
|
||||
@@ -60,8 +59,8 @@ public class MessageStoragePull implements IMessage, IMessageHandler<MessageStor
|
||||
if (tile instanceof TileController) {
|
||||
TileController controller = (TileController) tile;
|
||||
|
||||
if (message.slot < controller.getItems().size()) {
|
||||
StorageItem item = controller.getItems().get(message.slot);
|
||||
if (message.id < controller.getItems().size()) {
|
||||
StorageItem item = controller.getItems().get(message.id);
|
||||
|
||||
int quantity = 64;
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package storagecraft.storage;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -10,6 +12,8 @@ public class StorageItem {
|
||||
private int quantity;
|
||||
private int damage;
|
||||
private NBTTagCompound tag;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private int id;
|
||||
|
||||
public StorageItem(Item type, int quantity, int damage, NBTTagCompound tag) {
|
||||
this.type = type;
|
||||
@@ -18,6 +22,12 @@ public class StorageItem {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public StorageItem(Item type, int quantity, int damage, NBTTagCompound tag, int id) {
|
||||
this(type, quantity, damage, tag);
|
||||
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public StorageItem(ItemStack stack) {
|
||||
this(stack.getItem(), stack.stackSize, stack.getItemDamage(), stack.stackTagCompound);
|
||||
}
|
||||
@@ -50,6 +60,11 @@ public class StorageItem {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public StorageItem copy() {
|
||||
return copy(quantity);
|
||||
}
|
||||
|
@@ -270,12 +270,13 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
int size = buf.readInt();
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
int id = buf.readInt();
|
||||
Item type = Item.getItemById(buf.readInt());
|
||||
int quantity = buf.readInt();
|
||||
int damage = buf.readInt();
|
||||
NBTTagCompound tag = buf.readBoolean() ? ByteBufUtils.readTag(buf) : null;
|
||||
|
||||
items.add(new StorageItem(type, quantity, damage, tag));
|
||||
items.add(new StorageItem(type, quantity, damage, tag, id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,6 +288,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
buf.writeInt(items.size());
|
||||
|
||||
for (StorageItem item : items) {
|
||||
buf.writeInt(items.indexOf(item));
|
||||
buf.writeInt(Item.getIdFromItem(item.getType()));
|
||||
buf.writeInt(item.getQuantity());
|
||||
buf.writeInt(item.getDamage());
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Reference in New Issue
Block a user