#1458 Add button to merge inventory content with existing snapshot

This commit is contained in:
Matthias Mann committed 2015-01-07 23:22:44 +01:00
1 parent cc80a483b1
commit 173821524d
4 files changed
+93 -45

No files matched your search

@@ -39,6 +39,7 @@ public class ExistingItemFilterGui implements IItemFilterGui {
private static final int ID_SNAPSHOT = GuiExternalConnection.nextButtonId();
private static final int ID_CLEAR = GuiExternalConnection.nextButtonId();
private static final int ID_SHOW = GuiExternalConnection.nextButtonId();
private static final int ID_MERGE = GuiExternalConnection.nextButtonId();
private IItemConduit itemConduit;
@@ -52,6 +53,7 @@ public class ExistingItemFilterGui implements IItemFilterGui {
private GuiButton snapshotB;
private GuiButton clearB;
private GuiButton showB;
private GuiButton mergeB;
private SnapshotOverlay snapshotOverlay;
boolean isInput;
@@ -99,7 +101,12 @@ public class ExistingItemFilterGui implements IItemFilterGui {
useOreDictB.setSelectedToolTip(Lang.localize("gui.conduit.item.oreDicEnabled"));
useOreDictB.setUnselectedToolTip(Lang.localize("gui.conduit.item.oreDicDisabled"));
useOreDictB.setPaintSelectedBorder(false);
snapshotB = new GuiButton(ID_SNAPSHOT, 0, 0, 60, 20, "Snapshot");
mergeB = new GuiButton(ID_MERGE, 0, 0, 40, 20, "Merge");
clearB = new GuiButton(ID_CLEAR, 0, 0, 60, 20, "Clear");
showB = new GuiButton(ID_SHOW, 0, 0, 40, 20, "Show");
snapshotOverlay = new SnapshotOverlay();
gui.addOverlay(snapshotOverlay);
@@ -128,29 +135,36 @@ public class ExistingItemFilterGui implements IItemFilterGui {
useMetaB.onGuiInit();
useMetaB.setSelected(activeFilter.isMatchMeta());
int x = gui.getGuiLeft() + 80;
int y = gui.getGuiTop() + 65;
snapshotB = new GuiButton(ID_SNAPSHOT, x, y, 60, 20, "Snapshot");
x += 65;
showB = new GuiButton(ID_SHOW, x, y, 40, 20, "Show");
x = gui.getGuiLeft() + 80;
y += 22;
clearB = new GuiButton(ID_CLEAR, x, y, 60, 20, "Clear");
clearB.enabled = filter.getSnapshot() != null;
int x0 = gui.getGuiLeft() + 80;
int y0 = gui.getGuiTop() + 65;
int x1 = x0 + 65;
int y1 = y0 + 22;
snapshotB.xPosition = x0;
snapshotB.yPosition = y0;
mergeB.xPosition = x1;
mergeB.yPosition = y0;
clearB.xPosition = x0;
clearB.yPosition = y1;
showB.xPosition = x1;
showB.yPosition = y1;
clearB.enabled = filter.getSnapshot() != null;
showB.enabled = clearB.enabled;
mergeB.enabled = filter.getSnapshot() != null;
gui.addButton(snapshotB);
gui.addButton(clearB);
gui.addButton(showB);
gui.addButton(mergeB);
}
@Override
public void actionPerformed(GuiButton guiButton) {
if(guiButton.id == ID_META) {
filter.setMatchMeta(useMetaB.isSelected());
sendFilterChange();
@@ -164,9 +178,11 @@ public class ExistingItemFilterGui implements IItemFilterGui {
filter.setUseOreDict(useOreDictB.isSelected());
sendFilterChange();
} else if(guiButton.id == ID_SNAPSHOT) {
sendSnapshotPacket(false);
sendSnapshotPacket(PacketExistingItemFilterSnapshot.Opcode.SET);
} else if(guiButton.id == ID_CLEAR) {
sendSnapshotPacket(true);
sendSnapshotPacket(PacketExistingItemFilterSnapshot.Opcode.CLEAR);
} else if(guiButton.id == ID_MERGE) {
sendSnapshotPacket(PacketExistingItemFilterSnapshot.Opcode.MERGE);
} else if(guiButton.id == ID_SHOW) {
showSnapshotOverlay();
}
@@ -176,8 +192,8 @@ public class ExistingItemFilterGui implements IItemFilterGui {
snapshotOverlay.setVisible(true);
}
private void sendSnapshotPacket(boolean isClear) {
PacketHandler.INSTANCE.sendToServer(new PacketExistingItemFilterSnapshot(itemConduit, gui.getDir(),isInput,isClear));
private void sendSnapshotPacket(PacketExistingItemFilterSnapshot.Opcode opcode) {
PacketHandler.INSTANCE.sendToServer(new PacketExistingItemFilterSnapshot(itemConduit, gui.getDir(),isInput,opcode));
}
private void sendFilterChange() {
@@ -193,6 +209,7 @@ public class ExistingItemFilterGui implements IItemFilterGui {
gui.removeButton(snapshotB);
gui.removeButton(clearB);
gui.removeButton(showB);
gui.removeButton(mergeB);
}
public void renderCustomOptions(int top, float par1, int par2, int par3) {
@@ -18,18 +18,24 @@ import crazypants.enderio.conduit.packet.ConTypeEnum;
public class PacketExistingItemFilterSnapshot extends AbstractConduitPacket<IItemConduit> implements IMessageHandler<PacketExistingItemFilterSnapshot, IMessage> {
public static enum Opcode {
CLEAR,
SET,
MERGE
}
private ForgeDirection dir;
private boolean isClear;
private Opcode opcode;
private boolean isInput;
public PacketExistingItemFilterSnapshot() {
public PacketExistingItemFilterSnapshot() {
}
public PacketExistingItemFilterSnapshot(IItemConduit con, ForgeDirection dir, boolean isInput, boolean isClear) {
public PacketExistingItemFilterSnapshot(IItemConduit con, ForgeDirection dir, boolean isInput, Opcode opcode) {
super(con.getBundle().getEntity(), ConTypeEnum.ITEM);
this.dir = dir;
this.isInput= isInput;
this.isClear = isClear;
this.opcode = opcode;
}
@Override
@@ -37,7 +43,7 @@ public class PacketExistingItemFilterSnapshot extends AbstractConduitPacket<IIte
super.fromBytes(buf);
dir = ForgeDirection.values()[buf.readShort()];
isInput = buf.readBoolean();
isClear = buf.readBoolean();
opcode = Opcode.values()[buf.readByte() & 255];
}
@Override
@@ -45,7 +51,7 @@ public class PacketExistingItemFilterSnapshot extends AbstractConduitPacket<IIte
super.toBytes(buf);
buf.writeShort(dir.ordinal());
buf.writeBoolean(isInput);
buf.writeBoolean(isClear);
buf.writeByte(opcode.ordinal());
}
@Override
@@ -61,15 +67,30 @@ public class PacketExistingItemFilterSnapshot extends AbstractConduitPacket<IIte
filter = (ExistingItemFilter)conduit.getOutputFilter(message.dir);
}
if(message.isClear) {
filter.setSnapshot((List<ItemStack>)null);
System.out.println("PacketExistingItemFilterSnapshot.onMessage: Cleared snapshot");
} else {
ItemConduitNetwork icn = (ItemConduitNetwork)conduit.getNetwork();
NetworkedInventory inv = icn.getInventory(conduit, message.dir);
filter.setSnapshot(inv);
switch (message.opcode) {
case CLEAR:
filter.setSnapshot((List<ItemStack>)null);
System.out.println("PacketExistingItemFilterSnapshot.onMessage: Cleared snapshot");
break;
case SET: {
ItemConduitNetwork icn = (ItemConduitNetwork)conduit.getNetwork();
NetworkedInventory inv = icn.getInventory(conduit, message.dir);
filter.setSnapshot(inv);
break;
}
case MERGE: {
ItemConduitNetwork icn = (ItemConduitNetwork)conduit.getNetwork();
NetworkedInventory inv = icn.getInventory(conduit, message.dir);
filter.mergeSnapshot(inv);
break;
}
default:
throw new AssertionError();
}
if(message.isInput) {
conduit.setInputFilter(message.dir, filter);
} else {
@@ -39,10 +39,15 @@ public class ExistingItemFilter implements IItemFilter {
}
}
} else {
for(ItemStack stack : snapshot) {
if(stackEqual(item, stack)) {
return true;
}
return isStackInSnapshot(item);
}
return false;
}
boolean isStackInSnapshot(ItemStack item) {
for(ItemStack stack : snapshot) {
if(stackEqual(item, stack)) {
return true;
}
}
return false;
@@ -93,10 +98,17 @@ public class ExistingItemFilter implements IItemFilter {
public void setSnapshot(NetworkedInventory ni) {
snapshot = new ArrayList<ItemStack>();
mergeSnapshot(ni);
}
public void mergeSnapshot(NetworkedInventory ni) {
if(snapshot == null) {
snapshot = new ArrayList<ItemStack>();
}
int[] slots = ni.getInventory().getAccessibleSlotsFromSide(ni.getInventorySide());
for (int i = 0; i < slots.length; i++) {
ItemStack stack = ni.getInventory().getStackInSlot(i);
if(stack != null) {
if(stack != null && !isStackInSnapshot(stack)) {
snapshot.add(stack);
}
}
@@ -59,14 +59,12 @@ public class ItemExistingItemFilter extends Item implements IItemFilterUpgrade,
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
if(FilterRegister.isFilterSet(par1ItemStack)) {
if(TooltipAddera.instance.showAdvancedTooltips()) {
if(FilterRegister.isFilterSet(par1ItemStack)) {
if(TooltipAddera.showAdvancedTooltips()) {
par3List.add(EnumChatFormatting.ITALIC + Lang.localize("itemConduitFilterUpgrade.configured"));
par3List.add(EnumChatFormatting.ITALIC + Lang.localize("itemConduitFilterUpgrade.clearConfigMethod"));
}
}
}
}
//par3List.add(EnumChatFormatting.ITALIC + Lang.localize("itemConduitFilterUpgrade.clearConfigMethod"));
}