mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-19 11:59:17 +00:00
Merge pull request #1918 from MatthiasMann/itemconduit_gui
rewrote item filter GUI to use GhostSlots
This commit is contained in:
commit
a5ff6dd96a
15 files changed
+120
-237
No files matched your search
@@ -17,33 +17,22 @@ import crazypants.enderio.conduit.gui.item.InventoryFilterUpgrade;
|
||||
import crazypants.enderio.conduit.gui.item.InventorySpeedUpgrades;
|
||||
import crazypants.enderio.conduit.item.IItemConduit;
|
||||
import crazypants.enderio.conduit.item.SpeedUpgrade;
|
||||
import crazypants.enderio.conduit.item.filter.IItemFilter;
|
||||
|
||||
public class ExternalConnectionContainer extends Container {
|
||||
|
||||
private InventoryPlayer playerInv;
|
||||
private IConduitBundle bundle;
|
||||
private ForgeDirection dir;
|
||||
private IItemConduit itemConduit;
|
||||
private final IItemConduit itemConduit;
|
||||
|
||||
private int speedUpgradeSlotLimit = 15;
|
||||
private IItemFilter inputFilter;
|
||||
private IItemFilter outputFilter;
|
||||
|
||||
private int outputFilterUpgradeSlot = 36;
|
||||
private int inputFilterUpgradeSlot = 37;
|
||||
private int speedUpgradeSlot = 38;
|
||||
private int startFilterSlot = 39;
|
||||
|
||||
private List<Point> slotLocations = new ArrayList<Point>();
|
||||
|
||||
List<FilterChangeListener> filterListeners = new ArrayList<FilterChangeListener>();
|
||||
|
||||
public ExternalConnectionContainer(InventoryPlayer playerInv, IConduitBundle bundle, ForgeDirection dir) {
|
||||
this.playerInv = playerInv;
|
||||
this.bundle = bundle;
|
||||
this.dir = dir;
|
||||
|
||||
int x;
|
||||
int y;
|
||||
|
||||
@@ -67,7 +56,6 @@ public class ExternalConnectionContainer extends Container {
|
||||
|
||||
itemConduit = bundle.getConduit(IItemConduit.class);
|
||||
if(itemConduit != null) {
|
||||
|
||||
x = 10;
|
||||
y = 47;
|
||||
InventoryFilterUpgrade fi = new InventoryFilterUpgrade(itemConduit, dir, false);
|
||||
@@ -96,48 +84,14 @@ public class ExternalConnectionContainer extends Container {
|
||||
}
|
||||
});
|
||||
slotLocations.add(new Point(x, y));
|
||||
|
||||
addFilterSlots(dir);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addFilterListener(FilterChangeListener list) {
|
||||
filterListeners.add(list);
|
||||
}
|
||||
|
||||
private void addFilterSlots(ForgeDirection dir) {
|
||||
|
||||
List<Slot> slots;
|
||||
inputFilter = itemConduit.getInputFilter(dir);
|
||||
if(inputFilter != null && inputFilter.getSlotCount() > 0) {
|
||||
slots = inputFilter.getSlots(33, 69);
|
||||
for (Slot slot : slots) {
|
||||
addSlotToContainer(slot);
|
||||
slotLocations.add(new Point(slot.xDisplayPosition, slot.yDisplayPosition));
|
||||
}
|
||||
}
|
||||
|
||||
outputFilter = itemConduit.getOutputFilter(dir);
|
||||
if(outputFilter != null && outputFilter.getSlotCount() > 0) {
|
||||
slots = outputFilter.getSlots(33, 69);
|
||||
for (Slot slot : slots) {
|
||||
addSlotToContainer(slot);
|
||||
slotLocations.add(new Point(slot.xDisplayPosition, slot.yDisplayPosition));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void filterChanged() {
|
||||
int slotsToRemove = inventorySlots.size() - startFilterSlot;
|
||||
for (int i = 0; i < slotsToRemove; i++) {
|
||||
int removeIndex = inventorySlots.size() - 1;
|
||||
inventorySlots.remove(removeIndex);
|
||||
inventoryItemStacks.remove(removeIndex);
|
||||
slotLocations.remove(removeIndex);
|
||||
}
|
||||
addFilterSlots(dir);
|
||||
|
||||
for (FilterChangeListener list : filterListeners) {
|
||||
list.onFilterChanged();
|
||||
}
|
||||
@@ -149,31 +103,14 @@ public class ExternalConnectionContainer extends Container {
|
||||
}
|
||||
setSlotsVisible(visible, inputFilterUpgradeSlot, inputFilterUpgradeSlot + 1);
|
||||
setSlotsVisible(visible, speedUpgradeSlot, speedUpgradeSlot + 1);
|
||||
|
||||
if(inputFilter == null || inputFilter.getSlotCount() == 0) {
|
||||
return;
|
||||
}
|
||||
int startIndex = startFilterSlot;
|
||||
int endIndex = inputFilter.getSlotCount() + startIndex;
|
||||
setSlotsVisible(visible, startIndex, endIndex);
|
||||
|
||||
}
|
||||
|
||||
public void setOutputSlotsVisible(boolean visible) {
|
||||
|
||||
if(itemConduit == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSlotsVisible(visible, outputFilterUpgradeSlot, outputFilterUpgradeSlot + 1);
|
||||
|
||||
if(outputFilter == null || outputFilter.getSlotCount() == 0) {
|
||||
return;
|
||||
}
|
||||
int startIndex = startFilterSlot + (inputFilter == null ? 0 : inputFilter.getSlotCount());
|
||||
int endIndex = startIndex + outputFilter.getSlotCount();
|
||||
setSlotsVisible(visible, startIndex, endIndex);
|
||||
|
||||
}
|
||||
|
||||
public void setInventorySlotsVisible(boolean visible) {
|
||||
@@ -205,12 +142,6 @@ public class ExternalConnectionContainer extends Container {
|
||||
SpeedUpgrade speedUpgrade = EnderIO.itemExtractSpeedUpgrade.getSpeedUpgrade(st);
|
||||
speedUpgradeSlotLimit = speedUpgrade.maxStackSize;
|
||||
}
|
||||
if(par4EntityPlayer.worldObj != null) {
|
||||
if(par1 >= startFilterSlot && itemConduit != null) {
|
||||
itemConduit.setInputFilter(dir, inputFilter);
|
||||
itemConduit.setOutputFilter(dir, outputFilter);
|
||||
}
|
||||
}
|
||||
try {
|
||||
return super.slotClick(par1, par2, par3, par4EntityPlayer);
|
||||
} catch (Exception e) {
|
||||
@@ -226,9 +157,8 @@ public class ExternalConnectionContainer extends Container {
|
||||
}
|
||||
|
||||
private class FilterSlot extends Slot {
|
||||
final boolean isInput;
|
||||
|
||||
boolean isInput;
|
||||
|
||||
public FilterSlot(IInventory par1iInventory, int par2, int par3, int par4, boolean isInput) {
|
||||
super(par1iInventory, par2, par3, par4);
|
||||
this.isInput = isInput;
|
||||
|
||||
@@ -199,6 +199,7 @@ public class GuiExternalConnection extends GuiContainerBase {
|
||||
tes.draw();
|
||||
}
|
||||
|
||||
super.drawGuiContainerBackgroundLayer(par1, par2, par3);
|
||||
}
|
||||
|
||||
public ForgeDirection getDir() {
|
||||
|
||||
@@ -21,19 +21,19 @@ public class BasicItemFilterGui implements IItemFilterGui {
|
||||
private static final int ID_ORE_DICT = GuiExternalConnection.nextButtonId();
|
||||
private static final int ID_STICKY = GuiExternalConnection.nextButtonId();
|
||||
|
||||
private GuiContainerBase gui;
|
||||
private final GuiContainerBase gui;
|
||||
|
||||
private ToggleButtonEIO useMetaB;
|
||||
private ToggleButtonEIO useNbtB;
|
||||
private IconButtonEIO whiteListB;
|
||||
private ToggleButtonEIO useOreDictB;
|
||||
private ToggleButtonEIO stickyB;
|
||||
private final ToggleButtonEIO useMetaB;
|
||||
private final ToggleButtonEIO useNbtB;
|
||||
private final IconButtonEIO whiteListB;
|
||||
private final ToggleButtonEIO useOreDictB;
|
||||
private final ToggleButtonEIO stickyB;
|
||||
|
||||
boolean isAdvanced;
|
||||
boolean isStickyModeAvailable;
|
||||
final boolean isAdvanced;
|
||||
final boolean isStickyModeAvailable;
|
||||
|
||||
private IItemFilterContainer filterContainer;
|
||||
private ItemFilter filter;
|
||||
private final IItemFilterContainer filterContainer;
|
||||
private final ItemFilter filter;
|
||||
|
||||
private int buttonIdOffset;
|
||||
private int xOffset;
|
||||
@@ -58,8 +58,8 @@ public class BasicItemFilterGui implements IItemFilterGui {
|
||||
isAdvanced = filter.isAdvanced();
|
||||
|
||||
int butLeft = xOffset + 92;
|
||||
int x = butLeft ;
|
||||
int y = yOffset;
|
||||
int x = butLeft;
|
||||
int y = yOffset + 1;
|
||||
whiteListB = new IconButtonEIO(gui, ID_WHITELIST + buttonIdOffset, x, y, IconEIO.FILTER_WHITELIST);
|
||||
whiteListB.setToolTip(Lang.localize("gui.conduit.item.whitelist"));
|
||||
|
||||
@@ -91,6 +91,15 @@ public class BasicItemFilterGui implements IItemFilterGui {
|
||||
useOreDictB.setUnselectedToolTip(Lang.localize("gui.conduit.item.oreDicDisabled"));
|
||||
useOreDictB.setPaintSelectedBorder(false);
|
||||
}
|
||||
|
||||
public void createFilterSlots() {
|
||||
filter.createGhostSlots(gui.getGhostSlots(), xOffset+1, yOffset+1, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendFilterChange();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int x, int y, int par3) {
|
||||
@@ -98,9 +107,8 @@ public class BasicItemFilterGui implements IItemFilterGui {
|
||||
|
||||
@Override
|
||||
public void updateButtons() {
|
||||
|
||||
ItemFilter activeFilter = filter;
|
||||
|
||||
|
||||
if(isAdvanced) {
|
||||
useNbtB.onGuiInit();
|
||||
useNbtB.setSelected(activeFilter.isMatchNBT());
|
||||
|
||||
@@ -54,16 +54,16 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
private String inputHeading;
|
||||
private String outputHeading;
|
||||
|
||||
private IconButtonEIO nextFilterB;
|
||||
private final IconButtonEIO nextFilterB;
|
||||
|
||||
private ToggleButtonEIO loopB;
|
||||
private ToggleButtonEIO roundRobinB;
|
||||
private final ToggleButtonEIO loopB;
|
||||
private final ToggleButtonEIO roundRobinB;
|
||||
|
||||
private IconButtonEIO priUpB;
|
||||
private IconButtonEIO priDownB;
|
||||
private final IconButtonEIO priUpB;
|
||||
private final IconButtonEIO priDownB;
|
||||
|
||||
private RedstoneModeButton rsB;
|
||||
private ColorButton colorB;
|
||||
private final RedstoneModeButton rsB;
|
||||
private final ColorButton colorB;
|
||||
|
||||
private ColorButton channelB;
|
||||
|
||||
@@ -74,9 +74,9 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
private int priLeft;
|
||||
private int priWidth = 32;
|
||||
|
||||
private GuiToolTip priorityTooltip;
|
||||
private GuiToolTip speedUpgradeTooltip;
|
||||
private GuiToolTip filterUpgradeTooltip;
|
||||
private final GuiToolTip priorityTooltip;
|
||||
private final GuiToolTip speedUpgradeTooltip;
|
||||
private final GuiToolTip filterUpgradeTooltip;
|
||||
|
||||
private IItemFilterGui filterGui;
|
||||
|
||||
@@ -150,12 +150,10 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
priDownB.setSize(8, 8);
|
||||
|
||||
gui.getContainer().addFilterListener(new FilterChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onFilterChanged() {
|
||||
filtersChanged();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
@@ -180,9 +178,12 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
}
|
||||
|
||||
private void updateGuiVisibility() {
|
||||
|
||||
deactivate();
|
||||
createFilterGUI();
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
private void createFilterGUI() {
|
||||
boolean showInput = false;
|
||||
boolean showOutput = false;
|
||||
|
||||
@@ -191,15 +192,10 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
showInput = true;
|
||||
} else if(mode == ConnectionMode.OUTPUT) {
|
||||
showOutput = true;
|
||||
|
||||
} else if(mode == ConnectionMode.IN_OUT) {
|
||||
|
||||
if(nextFilterB != null) {
|
||||
nextFilterB.onGuiInit();
|
||||
}
|
||||
nextFilterB.onGuiInit();
|
||||
showInput = inOutShowIn;
|
||||
showOutput = !inOutShowIn;
|
||||
|
||||
}
|
||||
|
||||
if(!showInput && !showOutput) {
|
||||
@@ -212,7 +208,6 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
gui.getContainer().setOutputSlotsVisible(false);
|
||||
if(activeFilter != null) {
|
||||
filterGui = getFilterGui(activeFilter, true);
|
||||
|
||||
}
|
||||
} else if(showOutput) {
|
||||
activeFilter = itemConduit.getOutputFilter(gui.getDir());
|
||||
@@ -223,54 +218,24 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
filterGui = getFilterGui(activeFilter, false);
|
||||
}
|
||||
}
|
||||
|
||||
updateButtons();
|
||||
|
||||
}
|
||||
|
||||
private void filtersChanged() {
|
||||
if(filterGui != null) {
|
||||
filterGui.deactivate();
|
||||
filterGui = null;
|
||||
}
|
||||
deactiveFilterGUI();
|
||||
createFilterGUI();
|
||||
|
||||
ConnectionMode mode = con.getConnectionMode(gui.getDir());
|
||||
if(mode == ConnectionMode.DISABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean showInput = mode == ConnectionMode.INPUT || (mode == ConnectionMode.IN_OUT && inOutShowIn);
|
||||
if(showInput) {
|
||||
gui.getContainer().setInventorySlotsVisible(true);
|
||||
gui.getContainer().setInputSlotsVisible(true);
|
||||
gui.getContainer().setOutputSlotsVisible(false);
|
||||
|
||||
activeFilter = itemConduit.getInputFilter(gui.getDir());
|
||||
if(activeFilter != null) {
|
||||
filterGui = getFilterGui(activeFilter, true);
|
||||
}
|
||||
} else {
|
||||
gui.getContainer().setInventorySlotsVisible(true);
|
||||
gui.getContainer().setInputSlotsVisible(false);
|
||||
gui.getContainer().setOutputSlotsVisible(true);
|
||||
|
||||
activeFilter = itemConduit.getOutputFilter(gui.getDir());
|
||||
if(activeFilter != null) {
|
||||
filterGui = getFilterGui(activeFilter, false);
|
||||
}
|
||||
|
||||
}
|
||||
if(filterGui != null) {
|
||||
filterGui.updateButtons();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private IItemFilterGui getFilterGui(IItemFilter filter, boolean isInput) {
|
||||
//TODO: move to a factory
|
||||
if(filter instanceof ItemFilter) {
|
||||
ItemConduitFilterContainer cont = new ItemConduitFilterContainer(itemConduit, gui.getDir(), isInput);
|
||||
return new BasicItemFilterGui(gui, cont, !isInput);
|
||||
BasicItemFilterGui basicItemFilterGui = new BasicItemFilterGui(gui, cont, !isInput);
|
||||
basicItemFilterGui.createFilterSlots();
|
||||
return basicItemFilterGui;
|
||||
} else if(filter instanceof ExistingItemFilter) {
|
||||
return new ExistingItemFilterGui(gui, itemConduit, isInput);
|
||||
} else if(filter instanceof ModItemFilter) {
|
||||
@@ -329,7 +294,6 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
if(filterGui != null) {
|
||||
filterGui.updateButtons();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -343,37 +307,35 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketExtractMode(itemConduit, gui.getDir()));
|
||||
} else if(guiButton.id == ID_LOOP) {
|
||||
itemConduit.setSelfFeedEnabled(gui.getDir(), !itemConduit.isSelfFeedEnabled(gui.getDir()));
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketItemConduitFilter(itemConduit, gui.getDir()));
|
||||
sendFilterChange();
|
||||
} else if(guiButton.id == ID_ROUND_ROBIN) {
|
||||
itemConduit.setRoundRobinEnabled(gui.getDir(), !itemConduit.isRoundRobinEnabled(gui.getDir()));
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketItemConduitFilter(itemConduit, gui.getDir()));
|
||||
sendFilterChange();
|
||||
} else if(guiButton.id == ID_PRIORITY_UP) {
|
||||
itemConduit.setOutputPriority(gui.getDir(), itemConduit.getOutputPriority(gui.getDir()) + 1);
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketItemConduitFilter(itemConduit, gui.getDir()));
|
||||
sendFilterChange();
|
||||
} else if(guiButton.id == ID_PRIORITY_DOWN) {
|
||||
itemConduit.setOutputPriority(gui.getDir(), itemConduit.getOutputPriority(gui.getDir()) - 1);
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketItemConduitFilter(itemConduit, gui.getDir()));
|
||||
sendFilterChange();
|
||||
} else if(guiButton.id == ID_CHANNEL) {
|
||||
|
||||
DyeColor col = DyeColor.values()[channelB.getColorIndex()];
|
||||
boolean input;
|
||||
if(isInputVisible()) {
|
||||
col = DyeColor.values()[channelB.getColorIndex()];
|
||||
itemConduit.setInputColor(gui.getDir(), col);
|
||||
input = true;
|
||||
} else {
|
||||
itemConduit.setOutputColor(gui.getDir(), DyeColor.values()[channelB.getColorIndex()]);
|
||||
input = false;
|
||||
itemConduit.setOutputColor(gui.getDir(), col);
|
||||
}
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketItemConduitFilter(itemConduit, gui.getDir()));
|
||||
sendFilterChange();
|
||||
}
|
||||
|
||||
if(filterGui != null) {
|
||||
filterGui.actionPerformed(guiButton);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void sendFilterChange() {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketItemConduitFilter(itemConduit, gui.getDir()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int x, int y, int par3) {
|
||||
@@ -406,7 +368,6 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
|
||||
FontRenderer fr = gui.getFontRenderer();
|
||||
String heading = getHeading();
|
||||
int headingWidth = fr.getStringWidth(heading);
|
||||
int x = 0;
|
||||
int rgb = ColorUtil.getRGB(Color.darkGray);
|
||||
fr.drawString(heading, left + x, top, rgb);
|
||||
@@ -433,7 +394,6 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
if(filterGui != null) {
|
||||
filterGui.renderCustomOptions(top, par1, par2, par3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -452,11 +412,15 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
gui.removeToolTip(speedUpgradeTooltip);
|
||||
gui.removeToolTip(filterUpgradeTooltip);
|
||||
channelB.detach();
|
||||
deactiveFilterGUI();
|
||||
}
|
||||
|
||||
private void deactiveFilterGUI() {
|
||||
if(filterGui != null) {
|
||||
filterGui.deactivate();
|
||||
filterGui = null;
|
||||
}
|
||||
gui.getGhostSlots().clear();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,10 +3,8 @@ package crazypants.enderio.conduit.item.filter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -14,6 +12,7 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import crazypants.enderio.conduit.item.NetworkedInventory;
|
||||
import crazypants.enderio.network.NetworkUtil;
|
||||
import crazypants.gui.GhostSlot;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
||||
public class ExistingItemFilter implements IItemFilter {
|
||||
@@ -88,8 +87,7 @@ public class ExistingItemFilter implements IItemFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Slot> getSlots(int xOffset, int yOffset) {
|
||||
return Collections.emptyList();
|
||||
public void createGhostSlots(List<GhostSlot> slots, int xOffset, int yOffset, Runnable cb) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,10 +4,10 @@ import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import crazypants.enderio.conduit.item.NetworkedInventory;
|
||||
import crazypants.gui.GhostSlot;
|
||||
|
||||
public interface IItemFilter {
|
||||
|
||||
@@ -27,7 +27,7 @@ public interface IItemFilter {
|
||||
|
||||
boolean isSticky();
|
||||
|
||||
List<Slot> getSlots(int xOffset, int yOffset);
|
||||
void createGhostSlots(List<GhostSlot> slots, int xOffset, int yOffset, Runnable cb);
|
||||
|
||||
int getSlotCount();
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
@@ -16,7 +15,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import crazypants.enderio.conduit.item.NetworkedInventory;
|
||||
import crazypants.enderio.network.NetworkUtil;
|
||||
import crazypants.gui.TemplateSlot;
|
||||
import crazypants.gui.GhostSlot;
|
||||
|
||||
public class ItemFilter implements IInventory, IItemFilter {
|
||||
|
||||
@@ -340,9 +339,7 @@ public class ItemFilter implements IInventory, IItemFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Slot> getSlots(int xOffset, int yOffset) {
|
||||
List<Slot> result = new ArrayList<Slot>();
|
||||
|
||||
public void createGhostSlots(List<GhostSlot> slots, int xOffset, int yOffset, Runnable cb) {
|
||||
int topY = yOffset;
|
||||
int leftX = xOffset;
|
||||
int index = 0;
|
||||
@@ -351,13 +348,12 @@ public class ItemFilter implements IInventory, IItemFilter {
|
||||
for (int col = 0; col < 5; ++col) {
|
||||
int x = leftX + col * 18;
|
||||
int y = topY + row * 20;
|
||||
result.add(new TemplateSlot(this, index, x, y));
|
||||
slots.add(new ItemFilterGhostSlot(index, x, y, cb));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getSlotCount() {
|
||||
return getSizeInventory();
|
||||
@@ -381,7 +377,31 @@ public class ItemFilter implements IInventory, IItemFilter {
|
||||
// + sticky + ", items=" + Arrays.toString(items) + ", oreIds=" + Arrays.toString(oreIds) + ", isAdvanced=" + isAdvanced + "]";
|
||||
return "ItemFilter [isAdvanced=" + isAdvanced + ", items=" + Arrays.toString(items) + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
class ItemFilterGhostSlot extends GhostSlot {
|
||||
private final int slot;
|
||||
private final Runnable cb;
|
||||
|
||||
ItemFilterGhostSlot(int slot, int x, int y, Runnable cb) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.slot = slot;
|
||||
this.cb = cb;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void putStack(ItemStack stack) {
|
||||
if(stack != null) {
|
||||
stack = stack.copy();
|
||||
stack.stackSize = 1;
|
||||
}
|
||||
items[slot] = stack;
|
||||
cb.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getStack() {
|
||||
return items[slot];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,15 @@ package crazypants.enderio.conduit.item.filter;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
|
||||
import crazypants.enderio.conduit.item.NetworkedInventory;
|
||||
import crazypants.enderio.network.NetworkUtil;
|
||||
import crazypants.gui.GhostSlot;
|
||||
|
||||
public class ModItemFilter implements IItemFilter {
|
||||
|
||||
@@ -91,8 +90,7 @@ public class ModItemFilter implements IItemFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Slot> getSlots(int xOffset, int yOffset) {
|
||||
return Collections.emptyList();
|
||||
public void createGhostSlots(List<GhostSlot> slots, int xOffset, int yOffset, Runnable cb) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import crazypants.enderio.conduit.item.NetworkedInventory;
|
||||
import crazypants.enderio.network.NetworkUtil;
|
||||
import crazypants.gui.GhostSlot;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -80,8 +81,7 @@ public class PowerItemFilter implements IItemFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Slot> getSlots(int xOffset, int yOffset) {
|
||||
return Collections.emptyList();
|
||||
public void createGhostSlots(List<GhostSlot> slots, int xOffset, int yOffset, Runnable cb) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -96,6 +96,8 @@ public abstract class GuiMachineBase<T extends AbstractMachineEntity> extends Gu
|
||||
}
|
||||
|
||||
renderSlotHighlights();
|
||||
|
||||
super.drawGuiContainerBackgroundLayer(par1, par2, par3);
|
||||
}
|
||||
|
||||
public void renderSlotHighlights() {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package crazypants.enderio.machine.transceiver.gui;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -29,9 +26,6 @@ public class ContainerTransceiver extends AbstractMachineContainer {
|
||||
|
||||
private TileTransceiver trans;
|
||||
|
||||
private Map<Slot, Point> sendFilterLocs;
|
||||
private Map<Slot, Point> recFilterLocs;
|
||||
|
||||
public ContainerTransceiver(InventoryPlayer inventory, TileTransceiver te) {
|
||||
super(inventory, te);
|
||||
trans = te;
|
||||
@@ -61,22 +55,6 @@ public class ContainerTransceiver extends AbstractMachineContainer {
|
||||
});
|
||||
}
|
||||
setItemSlotLocations(getItemInventoryOffset());
|
||||
|
||||
List<Slot> sendFilterSlots = trans.getSendItemFilter().getSlots(0, 0);
|
||||
sendFilterLocs = new HashMap<Slot, Point>();
|
||||
for (Slot slot : sendFilterSlots) {
|
||||
addSlotToContainer(slot);
|
||||
sendFilterLocs.put(slot, new Point(slot.xDisplayPosition, slot.yDisplayPosition));
|
||||
}
|
||||
List<Slot> recFilterSlots = trans.getReceiveItemFilter().getSlots(0, 0);
|
||||
recFilterLocs = new HashMap<Slot, Point>();
|
||||
for (Slot slot : recFilterSlots) {
|
||||
addSlotToContainer(slot);
|
||||
recFilterLocs.put(slot, new Point(slot.xDisplayPosition, slot.yDisplayPosition));
|
||||
}
|
||||
setSendFilterSlotsVisible(false);
|
||||
setReceiveFilterSlotsVisible(false);
|
||||
|
||||
}
|
||||
|
||||
public void setPlayerInventoryVisible(boolean visible) {
|
||||
@@ -92,25 +70,6 @@ public class ContainerTransceiver extends AbstractMachineContainer {
|
||||
setItemSlotLocations(itemOffset);
|
||||
}
|
||||
|
||||
public void setSendFilterSlotsVisible(boolean visible) {
|
||||
setFilterSlotsVisible(sendFilterLocs, visible);
|
||||
}
|
||||
|
||||
public void setReceiveFilterSlotsVisible(boolean visible) {
|
||||
setFilterSlotsVisible(recFilterLocs, visible);
|
||||
}
|
||||
|
||||
public void setFilterSlotsVisible(Map<Slot, Point> slots, boolean visible) {
|
||||
Point offset = HIDDEN_OFFSET;
|
||||
if(visible) {
|
||||
offset = FILTER_OFFSET;
|
||||
}
|
||||
for (Entry<Slot, Point> entry : slots.entrySet()) {
|
||||
entry.getKey().xDisplayPosition = offset.x + entry.getValue().x + 1;
|
||||
entry.getKey().yDisplayPosition = offset.y + entry.getValue().y + 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void setItemSlotLocations(Point offset) {
|
||||
int i;
|
||||
int x = offset.x;
|
||||
@@ -164,7 +123,7 @@ public class ContainerTransceiver extends AbstractMachineContainer {
|
||||
|
||||
@Override
|
||||
protected int getIndexOfFirstPlayerInvSlot(SlotDefinition slotDef) {
|
||||
return slotDef.getNumSlots() + sendFilterLocs.size() + recFilterLocs.size();
|
||||
return slotDef.getNumSlots();
|
||||
}
|
||||
|
||||
public static class FilterSlot extends Slot {
|
||||
|
||||
@@ -23,12 +23,12 @@ import crazypants.util.Lang;
|
||||
|
||||
public class FilterTab implements ITabPanel {
|
||||
|
||||
GuiTransceiver parent;
|
||||
ContainerTransceiver container;
|
||||
BasicItemFilterGui sendGui;
|
||||
BasicItemFilterGui recGui;
|
||||
private final GuiTransceiver parent;
|
||||
private final ContainerTransceiver container;
|
||||
private final BasicItemFilterGui sendGui;
|
||||
private final BasicItemFilterGui recGui;
|
||||
|
||||
IconButtonEIO sendRecB;
|
||||
private final IconButtonEIO sendRecB;
|
||||
|
||||
boolean showSend = true;
|
||||
|
||||
@@ -37,7 +37,7 @@ public class FilterTab implements ITabPanel {
|
||||
container = parent.getContainer();
|
||||
sendGui = new BasicItemFilterGui(parent, new FilterContainer(parent.getTransciever(), true), false, container.getFilterOffset().x,
|
||||
container.getFilterOffset().y, 0);
|
||||
recGui = new BasicItemFilterGui(parent, new FilterContainer(parent.getTransciever(), true), false, container.getFilterOffset().x,
|
||||
recGui = new BasicItemFilterGui(parent, new FilterContainer(parent.getTransciever(), false), false, container.getFilterOffset().x,
|
||||
container.getFilterOffset().y, 20);
|
||||
|
||||
sendRecB = new IconButtonEIO(parent, 8888, container.getFilterOffset().x + 79, container.getFilterOffset().y - 20, IconEIO.RIGHT_ARROW);
|
||||
@@ -49,28 +49,24 @@ public class FilterTab implements ITabPanel {
|
||||
parent.getContainer().setPlayerInventoryVisible(true);
|
||||
sendRecB.onGuiInit();
|
||||
updateSendRecieve();
|
||||
|
||||
}
|
||||
|
||||
protected void updateSendRecieve() {
|
||||
parent.getGhostSlots().clear();
|
||||
if(showSend) {
|
||||
parent.getContainer().setSendFilterSlotsVisible(true);
|
||||
parent.getContainer().setReceiveFilterSlotsVisible(false);
|
||||
sendGui.updateButtons();
|
||||
recGui.deactivate();
|
||||
sendGui.createFilterSlots();
|
||||
} else {
|
||||
parent.getContainer().setSendFilterSlotsVisible(false);
|
||||
parent.getContainer().setReceiveFilterSlotsVisible(true);
|
||||
sendGui.deactivate();
|
||||
recGui.updateButtons();
|
||||
recGui.createFilterSlots();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivate() {
|
||||
parent.getContainer().setPlayerInventoryVisible(false);
|
||||
parent.getContainer().setSendFilterSlotsVisible(false);
|
||||
parent.getContainer().setReceiveFilterSlotsVisible(false);
|
||||
sendGui.deactivate();
|
||||
recGui.deactivate();
|
||||
sendRecB.detach();
|
||||
@@ -144,8 +140,8 @@ public class FilterTab implements ITabPanel {
|
||||
|
||||
private static class FilterContainer implements IItemFilterContainer {
|
||||
|
||||
private TileTransceiver trans;
|
||||
private boolean isSend;
|
||||
private final TileTransceiver trans;
|
||||
private final boolean isSend;
|
||||
|
||||
private FilterContainer(TileTransceiver trans, boolean isSend) {
|
||||
this.trans = trans;
|
||||
|
||||
@@ -98,6 +98,7 @@ public class GuiTransceiver extends GuiPoweredMachineBase<TileTransceiver> {
|
||||
tabs.get(i).deactivate();
|
||||
}
|
||||
}
|
||||
ghostSlots.clear();
|
||||
for (int i = 0; i < tabs.size(); i++) {
|
||||
if(i == activeTab) {
|
||||
tabs.get(i).onGuiInit(guiLeft + 10, guiTop, xSize - 20, ySize - 20);
|
||||
@@ -190,7 +191,6 @@ public class GuiTransceiver extends GuiPoweredMachineBase<TileTransceiver> {
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
int sx = (width - xSize) / 2;
|
||||
|
||||
@@ -250,6 +250,11 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GhostSlot> getGhostSlots() {
|
||||
return ghostSlots;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if(!ghostSlots.isEmpty()) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package crazypants.gui;
|
||||
|
||||
import java.util.List;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
public interface IGuiScreen {
|
||||
@@ -24,5 +25,6 @@ public interface IGuiScreen {
|
||||
|
||||
void doActionPerformed(GuiButton but);
|
||||
|
||||
List<GhostSlot> getGhostSlots();
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user