diff options
| author | moller21 <42100910+moller21@users.noreply.github.com> | 2020-06-01 17:02:56 +0200 |
|---|---|---|
| committer | moller21 <42100910+moller21@users.noreply.github.com> | 2020-06-01 17:02:56 +0200 |
| commit | e4bd293915ea20359dc228a623c08f7a1055d843 (patch) | |
| tree | e3b94ffec17ef15648091d40ff62bad2637cbe8d /src/main/java/gregtech | |
| parent | 2194d12d4a378707cc25704a45052044edbe428c (diff) | |
| download | GT5-Unofficial-e4bd293915ea20359dc228a623c08f7a1055d843.tar.gz GT5-Unofficial-e4bd293915ea20359dc228a623c08f7a1055d843.tar.bz2 GT5-Unofficial-e4bd293915ea20359dc228a623c08f7a1055d843.zip | |
Added gui's for the rest of em covers.
Diffstat (limited to 'src/main/java/gregtech')
19 files changed, 1625 insertions, 40 deletions
diff --git a/src/main/java/gregtech/api/gui/GT_GUICover.java b/src/main/java/gregtech/api/gui/GT_GUICover.java index 94346186a8..f1232c9432 100644 --- a/src/main/java/gregtech/api/gui/GT_GUICover.java +++ b/src/main/java/gregtech/api/gui/GT_GUICover.java @@ -157,8 +157,10 @@ public abstract class GT_GUICover extends GuiScreen implements GT_IToolTipRender public void mouseClicked(int x, int y, int button) { for (GT_GuiIntegerTextBox tBox : textBoxes) { boolean hadFocus = tBox.isFocused(); - tBox.mouseClicked(x,y,button); - if (tBox.isFocused() && button == 1) //rightclick -> lcear it + if (tBox.isEnabled() || hadFocus) + tBox.mouseClicked(x,y,button); + + if (tBox.isFocused() && button == 1 && tBox.isEnabled()) //rightclick -> lcear it tBox.setText("0"); else if (hadFocus && !tBox.isFocused()) applyTextBox(tBox); @@ -193,6 +195,9 @@ public abstract class GT_GUICover extends GuiScreen implements GT_IToolTipRender return; } } + if (textBoxes.size() > 0 ) + setFocusedTextBox(textBoxes.get(0)); + return; } if (focusedTextBox != null && focusedTextBox.textboxKeyTyped(c, key)){ @@ -239,7 +244,7 @@ public abstract class GT_GUICover extends GuiScreen implements GT_IToolTipRender */ private void setFocusedTextBox(GT_GuiIntegerTextBox boxToFocus) { for (GT_GuiIntegerTextBox textBox : textBoxes) { - textBox.setFocused(textBox.equals(boxToFocus)); + textBox.setFocused(textBox.equals(boxToFocus) && textBox.isEnabled()); } } public void applyTextBox(GT_GuiIntegerTextBox box) { diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java index 1c31462e62..41e851054d 100644 --- a/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java +++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java @@ -18,6 +18,7 @@ public enum GT_GuiIcon { CROSS (0, 32*4, 32), WHITELIST (0, 32*5, 32), BLACKLIST (0, 32*6, 32), + PROGRESS (0, 32*7, 32), EXPORT (0, 0, 32*2), IMPORT (0, 32, 32*2), diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java index f68962f58f..e081c4227d 100644 --- a/src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java +++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java @@ -12,7 +12,7 @@ public class GT_GuiIconButton extends GuiButton implements IGuiScreen.IGuiElemen protected GT_GuiIcon icon; private int x0, y0; - private IGuiScreen gui; + protected IGuiScreen gui; private String[] tooltipText; private GT_GuiTooltip tooltip; @@ -56,7 +56,7 @@ public class GT_GuiIconButton extends GuiButton implements IGuiScreen.IGuiElemen int x = xPosition; int y = yPosition; if(!this.field_146123_n) { - GL11.glColor4f(200F/255F, 210F/255F, 1, 1); + // GL11.glColor4f(200F/255F, 210F/255F, 1, 1); } else GL11.glColor4f(1, 1, 1, 1); @@ -84,13 +84,17 @@ public class GT_GuiIconButton extends GuiButton implements IGuiScreen.IGuiElemen return GT_GuiIcon.BUTTON_DISABLED; if (this.equals(this.gui.getSelectedButton())) return mouseOver ? GT_GuiIcon.BUTTON_HIGHLIGHT_DOWN : GT_GuiIcon.BUTTON_DOWN; - else - return mouseOver ? GT_GuiIcon.BUTTON_HIGHLIGHT : GT_GuiIcon.BUTTON_NORMAL; + + return mouseOver ? GT_GuiIcon.BUTTON_HIGHLIGHT : GT_GuiIcon.BUTTON_NORMAL; } public GT_GuiIcon getIcon() { return icon; } + public GT_GuiIconButton setIcon(GT_GuiIcon icon) { + this.icon = icon; + return this; + } public GT_GuiTooltip getTooltip() { return tooltip; diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiIconCheckButton.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiIconCheckButton.java new file mode 100644 index 0000000000..4e6fd86f55 --- /dev/null +++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiIconCheckButton.java @@ -0,0 +1,31 @@ +package gregtech.api.gui.widgets; + +import gregtech.api.interfaces.IGuiScreen; + +public class GT_GuiIconCheckButton extends GT_GuiIconButton { + private GT_GuiIcon checkedIcon, normalIcon; + private boolean checked = false; + + public GT_GuiIconCheckButton(IGuiScreen gui, int id, int x, int y, GT_GuiIcon checkedIcon, GT_GuiIcon normalIcon) { + super(gui, id, x, y, normalIcon); + this.checkedIcon = checkedIcon; + this.normalIcon = normalIcon; + } + + public GT_GuiIcon getButtonTexture(boolean mouseOver) { + if (!enabled) + return GT_GuiIcon.BUTTON_DISABLED; + if (this.equals(super.gui.getSelectedButton())) + return mouseOver ? GT_GuiIcon.BUTTON_HIGHLIGHT_DOWN : GT_GuiIcon.BUTTON_DOWN; + return mouseOver ? GT_GuiIcon.BUTTON_HIGHLIGHT : GT_GuiIcon.BUTTON_NORMAL; + } + + public boolean isChecked() { + return checked; + } + + public void setChecked(boolean checked) { + super.setIcon(checked ? checkedIcon : normalIcon); + this.checked = checked; + } +} diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiIntegerTextBox.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiIntegerTextBox.java index 3f6fe64e73..e2ba53e4c9 100644 --- a/src/main/java/gregtech/api/gui/widgets/GT_GuiIntegerTextBox.java +++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiIntegerTextBox.java @@ -10,6 +10,7 @@ public class GT_GuiIntegerTextBox extends GuiTextField implements IGuiScreen.IGu private final int x0, y0; private final IGuiScreen gui; public final int id; + private boolean enabled; public GT_GuiIntegerTextBox(IGuiScreen gui, int id, int x, int y, int width, int height) { super(Minecraft.getMinecraft().fontRenderer, x, y, width, height); @@ -18,6 +19,7 @@ public class GT_GuiIntegerTextBox extends GuiTextField implements IGuiScreen.IGu x0 = x; y0 = y; this.gui = gui; + enabled = true; gui.addElement(this); } @@ -47,4 +49,14 @@ public class GT_GuiIntegerTextBox extends GuiTextField implements IGuiScreen.IGu } return false; } + + @Override + public void setEnabled(boolean p_146184_1_) { + super.setEnabled(p_146184_1_); + enabled = p_146184_1_; + } + + public boolean isEnabled() { + return enabled; + } } diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 8584e849bb..f5dfb42a2c 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -665,6 +665,64 @@ public class GT_Utility { return 0; } + /** + * Moves Stack from Inv-Side to Inv-Slot. + * + * @return the Amount of moved Items + */ + public static byte moveFromSlotToSide(IInventory fromTile, Object toTile, int aGrabFrom, byte aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, boolean aDoCheckChests) { + if (fromTile == null || aGrabFrom < 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce) + return 0; + + if (!listContainsItem(aFilter, fromTile.getStackInSlot(aGrabFrom), true, aInvertFilter) || + !isAllowedToTakeFromSlot(fromTile, aGrabFrom, (byte) 6, fromTile.getStackInSlot(aGrabFrom))) + return 0; + + if (toTile instanceof IInventory) { + int[] tPutSlots = null; + if (toTile instanceof ISidedInventory) + tPutSlots = ((ISidedInventory) toTile).getAccessibleSlotsFromSide(aPutTo); + + if (tPutSlots == null) { + tPutSlots = new int[((IInventory) toTile).getSizeInventory()]; + for (int i = 0; i < tPutSlots.length; i++) tPutSlots[i] = i; + } + + byte tMovedItemCount = 0; + for (int tPutSlot : tPutSlots) { + if (isAllowedToPutIntoSlot((IInventory) toTile, tPutSlot, aPutTo, fromTile.getStackInSlot(aGrabFrom), aMaxTargetStackSize)) { + tMovedItemCount += moveStackFromSlotAToSlotB(fromTile, (IInventory) toTile, aGrabFrom, tPutSlot, aMaxTargetStackSize, aMinTargetStackSize, (byte) (aMaxMoveAtOnce - tMovedItemCount), aMinMoveAtOnce); + if (tMovedItemCount >= aMaxMoveAtOnce) { + return tMovedItemCount; + + } + } + } + if (tMovedItemCount > 0) return tMovedItemCount; + + if (aDoCheckChests && toTile instanceof TileEntityChest) { + TileEntityChest tTileEntity2 = (TileEntityChest) toTile; + if (tTileEntity2.adjacentChestChecked) { + if (tTileEntity2.adjacentChestXNeg != null) { + tMovedItemCount = moveFromSlotToSide(fromTile, tTileEntity2.adjacentChestXNeg, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); + } else if (tTileEntity2.adjacentChestZNeg != null) { + tMovedItemCount = moveFromSlotToSide(fromTile, tTileEntity2.adjacentChestZNeg, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); + } else if (tTileEntity2.adjacentChestXPos != null) { + tMovedItemCount = moveFromSlotToSide(fromTile, tTileEntity2.adjacentChestXPos, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); + } else if (tTileEntity2.adjacentChestZPos != null) { + tMovedItemCount = moveFromSlotToSide(fromTile, tTileEntity2.adjacentChestZPos, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false); + } + if (tMovedItemCount > 0) return tMovedItemCount; + } + } + } + return moveStackIntoPipe(fromTile, toTile, new int[]{aGrabFrom}, (byte) 6, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, aDoCheckChests); + } + + public static byte moveFromSlotToSide(IInventory fromTile, Object toTile, int aGrabFrom, byte aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { + return moveFromSlotToSide(fromTile, toTile, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, true); + } + public static boolean listContainsItem(Collection<ItemStack> aList, ItemStack aStack, boolean aTIfListEmpty, boolean aInvertFilter) { if (aStack == null || aStack.stackSize < 1) return false; if (aList == null) return aTIfListEmpty; diff --git a/src/main/java/gregtech/common/covers/GT_Cover_Arm.java b/src/main/java/gregtech/common/covers/GT_Cover_Arm.java index 70d0340d1f..c86f80e530 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_Arm.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_Arm.java @@ -1,10 +1,19 @@ package gregtech.common.covers; +import gregtech.api.enums.GT_Values; +import gregtech.api.gui.GT_GUICover; +import gregtech.api.gui.widgets.GT_GuiFakeItemButton; +import gregtech.api.gui.widgets.GT_GuiIcon; +import gregtech.api.gui.widgets.GT_GuiIconButton; +import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IMachineProgress; +import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; +import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.fluids.Fluid; @@ -12,47 +21,135 @@ public class GT_Cover_Arm extends GT_CoverBehavior { public final int mTickRate; + //msb unused, 2nd : direction (1=export) + //right 15 bits: internalSlot, next 15 bits adjSlot, 0 = all, slot = -1 + protected final static int EXPORT_MASK = 0x40000000; + protected final static int SLOT_ID_MASK = 0x7FFF; + protected final static int SLOT_ID_MIN = 0; + public GT_Cover_Arm(int aTickRate) { this.mTickRate = aTickRate; } public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { - if ((aCoverVariable == 0) || (((aTileEntity instanceof IMachineProgress)) && (!((IMachineProgress) aTileEntity).isAllowedToWork()))) { + if ((((aTileEntity instanceof IMachineProgress)) && (!((IMachineProgress) aTileEntity).isAllowedToWork()))) { return aCoverVariable; } - TileEntity tTileEntity = aTileEntity.getTileEntityAtSide(aSide); - //aTileEntity.decreaseStoredEnergyUnits(1L, true); + + boolean usePower = false; if (aTileEntity.getUniversalEnergyCapacity() >= 128L) { if (aTileEntity.isUniversalEnergyStored(256L)) { - aTileEntity.decreaseStoredEnergyUnits(4 * GT_Utility.moveOneItemStackIntoSlot(aCoverVariable > 0 ? aTileEntity : tTileEntity, aCoverVariable > 0 ? tTileEntity : aTileEntity, aCoverVariable > 0 ? aSide : GT_Utility.getOppositeSide(aSide), Math.abs(aCoverVariable) - 1, null, false, (byte) 64, (byte) 1, (byte) 64, (byte) 1), true); + usePower = true; + } else { + return aCoverVariable; } + } + + TileEntity toTile, fromTile; + int toSlot, fromSlot; + + if ((aCoverVariable & EXPORT_MASK) > 0) { + fromTile = (TileEntity) aTileEntity; + toTile = aTileEntity.getTileEntityAtSide(aSide); + fromSlot = aCoverVariable & SLOT_ID_MASK; + toSlot = (aCoverVariable>>15) & SLOT_ID_MASK; } else { - GT_Utility.moveOneItemStackIntoSlot(aCoverVariable > 0 ? aTileEntity : tTileEntity, aCoverVariable > 0 ? tTileEntity : aTileEntity, aCoverVariable > 0 ? aSide : GT_Utility.getOppositeSide(aSide), Math.abs(aCoverVariable) - 1, null, false, (byte) 64, (byte) 1, (byte) 64, (byte) 1); + fromTile = aTileEntity.getTileEntityAtSide(aSide); + toTile = (TileEntity) aTileEntity; + fromSlot = (aCoverVariable>>15) & SLOT_ID_MASK; + toSlot = aCoverVariable & SLOT_ID_MASK; } + + byte movedItems = 0; + if(fromSlot > 0 && toSlot > 0) { + if (fromTile instanceof IInventory && toTile instanceof IInventory) + movedItems = GT_Utility.moveFromSlotToSlot((IInventory) fromTile, (IInventory) toTile, fromSlot-1, toSlot-1, null, false, (byte)64, (byte)1, (byte)64, (byte)1); + } else if (toSlot > 0) { + byte side; + if ((aCoverVariable & EXPORT_MASK) > 0) + side = aSide; + else + side = GT_Utility.getOppositeSide(aSide); + movedItems = GT_Utility.moveOneItemStackIntoSlot(fromTile, toTile, side, toSlot-1, null, false, (byte)64, (byte)1, (byte)64, (byte)1); + } else if (fromSlot > 0) { + byte toSide; + if ((aCoverVariable & EXPORT_MASK) > 0) + toSide = aSide; + else + toSide = GT_Utility.getOppositeSide(aSide); + if (fromTile instanceof IInventory) + movedItems = GT_Utility.moveFromSlotToSide((IInventory) fromTile, toTile, fromSlot-1, toSide, null, false, (byte)64, (byte)1, (byte)64, (byte)1); + } else { + byte fromSide, toSide; + if ((aCoverVariable & EXPORT_MASK) > 0) { + fromSide = aSide; + toSide = GT_Utility.getOppositeSide(aSide); + } else { + fromSide = GT_Utility.getOppositeSide(aSide); + toSide = aSide; + } + movedItems = GT_Utility.moveOneItemStack(fromTile, toTile, fromSide, toSide, null, false, (byte)64, (byte)1, (byte)64, (byte)1); + } + + if (usePower) + aTileEntity.decreaseStoredEnergyUnits(4*movedItems, true); + return aCoverVariable; } public int onCoverScrewdriverclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + int step = 0; if (GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ)[0] >= 0.5F) { - aCoverVariable += aPlayer.isSneaking() ? 256 : 16; + step += aPlayer.isSneaking() ? 256 : 16; } else { - aCoverVariable += aPlayer.isSneaking() ? 256 : 16; + step -= aPlayer.isSneaking() ? 256 : 16; } - GT_Utility.sendChatToPlayer(aPlayer, (aCoverVariable > 0 ? trans("001","Puts out into adjacent Slot #") : trans("002","Grabs in for own Slot #")) + (Math.abs(aCoverVariable) - 1)); + aCoverVariable = getNewVar(aCoverVariable, step); + sendMessageToPlayer(aPlayer, aCoverVariable); return aCoverVariable; } public boolean onCoverRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ)[0] >= 0.5F) { - aCoverVariable++; - } else { - aCoverVariable--; - } - GT_Utility.sendChatToPlayer(aPlayer, (aCoverVariable > 0 ? trans("001","Puts out into adjacent Slot #") : trans("002","Grabs in for own Slot #")) + (Math.abs(aCoverVariable) - 1)); + int step = (GT_Utility.getClickedFacingCoords(aSide, aX, aY, aZ)[0] >= 0.5F) ? 1 : -1; + aCoverVariable = getNewVar(aCoverVariable, step); + sendMessageToPlayer(aPlayer, aCoverVariable); aTileEntity.setCoverDataAtSide(aSide, aCoverVariable); return true; } + private void sendMessageToPlayer(EntityPlayer aPlayer, int var) { + if ((var & EXPORT_MASK) != 0) + GT_Utility.sendChatToPlayer(aPlayer, trans("001","Puts out into adjacent Slot #") + (((var >> 15) & SLOT_ID_MASK) - 1)); + else + GT_Utility.sendChatToPlayer(aPlayer, trans("002","Grabs in for own Slot #") + ((var & SLOT_ID_MASK) - 1)); + } + + private int getNewVar(int var, int step) { + int intSlot = (var & SLOT_ID_MASK); + int adjSlot = (var >> 15) & SLOT_ID_MASK; + if ((var & EXPORT_MASK) == 0) { + int x = (intSlot + step); + if (x > SLOT_ID_MASK ) + return createVar(0, SLOT_ID_MASK, 0); + else if (x < 1) + return createVar(- step - intSlot + 1, 0, 1); + else + return createVar(0, x, 0); + } else { + int x = (adjSlot - step); + if (x > SLOT_ID_MASK ) + return createVar(SLOT_ID_MASK, 0, 1); + else if (x < 1) + return createVar(0, + step - adjSlot + 1, 0); + else + return createVar(x, 0, 1); + } + } + + private int createVar(int adjSlot, int intSlot, int export){ + return ((export & 0x1) << 30) | ((adjSlot & SLOT_ID_MASK) << 15) | (intSlot & SLOT_ID_MASK); + } + public boolean letsRedstoneGoIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return true; } @@ -92,4 +189,239 @@ public class GT_Cover_Arm public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return this.mTickRate; } + + /** + * GUI Stuff + */ + + @Override + public boolean hasCoverGUI() { + return true; + } + + @Override + public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { + return new GT_Cover_Arm.GUI(aSide, aCoverID, coverData, aTileEntity); + } + + private class GUI extends GT_GUICover { + private final byte side; + private final int coverID; + private GT_GuiIntegerTextBox intSlot, adjSlot; + private GT_GuiFakeItemButton intSlotIcon, adjSlotIcon; + private int coverVariable; + + private final static int startX = 10; + private final static int startY = 25; + private final static int spaceX = 18; + private final static int spaceY = 18; + + private final String ANY_TEXT = trans("ANY", "Any"); + + private boolean export; + private int internalSlotID, adjacentSlotID; + + private final int maxIntSlot, maxAdjSlot; + + public GUI(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); + this.side = aSide; + this.coverID = aCoverID; + this.coverVariable = aCoverVariable; + + export = (coverVariable & EXPORT_MASK) > 0; + internalSlotID = (coverVariable & SLOT_ID_MASK); + adjacentSlotID = (coverVariable >> 15) & SLOT_ID_MASK; + + new GT_GuiIconButton(this, 0, startX + spaceX * 0, startY + spaceY * 0, GT_GuiIcon.EXPORT).setTooltipText(trans("006", "Export")); + new GT_GuiIconButton(this, 1, startX + spaceX * 1, startY + spaceY * 0, GT_GuiIcon.IMPORT).setTooltipText(trans("007", "Import")); + + intSlot = new GT_GuiIntegerTextBox(this, 2, startX + spaceX * 0, startY + spaceY * 1 + 2, spaceX * 2+5, 12); + setBoxText(intSlot, internalSlotID-1); + intSlot.setMaxStringLength(6); + + adjSlot = new GT_GuiIntegerTextBox(this, 3, startX + spaceX * 0, startY + spaceY * 2 + 2, spaceX * 2+5, 12); + setBoxText(adjSlot, adjacentSlotID-1); + adjSlot.setMaxStringLength(6); + + //intSlotIcon = new GT_GuiFakeItemButton(this, startX + spaceX * 8-4, startY + spaceY * 1, GT_GuiIcon.SLOT_GRAY); + //adjSlotIcon = new GT_GuiFakeItemButton(this, startX + spaceX * 8-4, startY + spaceY * 2, GT_GuiIcon.SLOT_GRAY); + + if (super.tile instanceof TileEntity && !super.tile.isDead()) { + maxIntSlot = tile.getSizeInventory()-1; + + TileEntity adj = super.tile.getTileEntityAtSide(side); + if (adj instanceof IInventory) + maxAdjSlot = ((IInventory) adj).getSizeInventory()-1; + else + maxAdjSlot = -1; + } else { + maxIntSlot = -1; + maxAdjSlot = -1; + } + } + + @Override + public void drawExtras(int mouseX, int mouseY, float parTicks) { + super.drawExtras(mouseX, mouseY, parTicks); + if (export) + this.getFontRenderer().drawString(trans("006", "Export"), startX + spaceX*3, 4+startY+spaceY*0, 0xFF555555); + else + this.getFontRenderer().drawString(trans("007", "Import"), startX + spaceX*3, 4+startY+spaceY*0, 0xFF555555); + + this.getFontRenderer().drawString(trans("254", "Internal slot#"), startX + spaceX*3, 4+startY+spaceY*1, 0xFF555555); + this.getFontRenderer().drawString(trans("255", "Adjacent slot#"), startX + spaceX*3, 4+startY+spaceY*2, 0xFF555555); + } + + @Override + protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { + intSlot.setFocused(true); + updateButtons(); + + //updateInventorySlots(); + } + + @Override + public void buttonClicked(GuiButton btn) { + if (buttonClickable(btn.id)) { + export = btn.id == 0; + coverVariable = getNewCoverVariable(); + GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); + } + updateButtons(); + } + + private void updateButtons() { + GuiButton b; + for (Object o : buttonList) { + b = (GuiButton) o; + b.enabled = buttonClickable(b.id); + } + } + + @Override + public void onMouseWheel(int x, int y, int delta) { + for (GT_GuiIntegerTextBox box : textBoxes) { + if (box.isFocused()) { + int step = Math.max(1, Math.abs(delta / 120)); + step = (isShiftKeyDown() ? 50 : isCtrlKeyDown() ? 5 : 1) * (delta > 0 ? step : -step); + int maxSlot = box.id == 3 ? maxAdjSlot : maxIntSlot; + int val = parseTextBox(box, maxSlot); + if (val < 0) + val = -1; + val = val + step; + + if (maxSlot < val) + if (maxSlot < 0) + val = -1; + else + val = maxSlot; + else if (val < SLOT_ID_MIN) + val = -1; + + setBoxText(box, val); + return; + } + } + } + + @Override + public void applyTextBox(GT_GuiIntegerTextBox box) { + int val = -1; + + if (box.id == 2) { + val = parseTextBox(box, maxIntSlot); + internalSlotID = val+1; + } + else if (box.id == 3) { + val = parseTextBox(box, maxAdjSlot); + adjacentSlotID = val+1; + } + + setBoxText(box, val); + coverVariable = getNewCoverVariable(); + GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); + //updateInventorySlots(); + } + + @Override + public void resetTextBox(GT_GuiIntegerTextBox box) { + int val = 0; + if (box.id == 2) + val = internalSlotID-1; + else if (box.id == 3) + val = adjacentSlotID-1; + setBoxText(box, val); + } + + private void setBoxText(GT_GuiIntegerTextBox box, int val) { + box.setText( val < 0 ? ANY_TEXT : String.valueOf(val)); + } + + private int parseTextBox(GT_GuiIntegerTextBox box, int maxSlot) { + String text = box.getText(); + if (text == null) + return -1; + text = text.trim(); + if (text.startsWith(ANY_TEXT)) + text = text.substring(ANY_TEXT.length()); + + if (text.isEmpty()) + return -1; + + int val; + try { + val = Integer.parseInt(text); + } catch (NumberFormatException e) { + return -1; + } + + if (maxSlot < val) + if (maxSlot < 0) + return -1; + else + return maxSlot; + else if (val < SLOT_ID_MIN) + return SLOT_ID_MIN; + return val; + } + + private int getNewCoverVariable() { + return (export ? EXPORT_MASK : 0) | ((adjacentSlotID & SLOT_ID_MASK) << 15) | (internalSlotID & SLOT_ID_MASK); + } + + private boolean buttonClickable(int id) { + if (id == 0) + return !export; + return export; + } + +// getStackInSlot wasn't available client side.. +// private void updateInventorySlots() { +// updateInventorySlot(intSlotIcon, internalSlotID, true); +// updateInventorySlot(adjSlotIcon, adjacentSlotID, false); +// } +// +// private void updateInventorySlot(GT_GuiFakeItemButton button, int slotID, boolean internal) { +// if (slotID == SLOT_ID_ANY) { +// button.setItem(null); +// return; +// } +// +// if (super.tile instanceof TileEntity && !super.tile.isDead()) { +// TileEntity tile; +// if (internal) +// tile = (TileEntity) super.tile; +// else +// tile = super.tile.getTileEntityAtSide(side); +// +// if (tile instanceof IInventory && ((IInventory) tile).getSizeInventory() >= slotID) { +// ItemStack item = ((IInventory) tile).getStackInSlot(slotID); +// button.setItem(item); +// return; +// } +// } +// button.setItem(null); +// } + } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java b/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java index 96a2d4a2b8..9624b68464 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java @@ -1,9 +1,15 @@ package gregtech.common.covers; +import gregtech.api.enums.GT_Values; +import gregtech.api.gui.GT_GUICover; +import gregtech.api.gui.widgets.GT_GuiIcon; +import gregtech.api.gui.widgets.GT_GuiIconButton; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IMachineProgress; +import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; +import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.fluids.Fluid; @@ -70,4 +76,78 @@ public class GT_Cover_ControlsWork public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return 1; } + + /** + * GUI Stuff + */ + + @Override + public boolean hasCoverGUI() { + return true; + } + + @Override + public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { + return new GT_Cover_ControlsWork.GUI(aSide, aCoverID, coverData, aTileEntity); + } + + private class GUI extends GT_GUICover { + private final byte side; + private final int coverID; + private int coverVariable; + + private final static int startX = 10; + private final static int startY = 25; + private final static int spaceX = 18; + private final static int spaceY = 18; + + public GUI(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); + this.side = aSide; + this.coverID = aCoverID; + this.coverVariable = aCoverVariable; + |
