From d84be03027e80f105b6b0aee84e9f12f15167fbe Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Wed, 9 Apr 2014 23:51:08 -0500 Subject: [PATCH] Large chunk on the pattern terminal. --- client/gui/AEBaseGui.java | 23 +++-- .../gui/implementations/GuiPatternTerm.java | 54 ++++++++-- client/gui/widgets/GuiImgButton.java | 3 +- .../implementations/ContainerPatternTerm.java | 98 +++++++++++++++++-- container/slot/OptionalSlotFake.java | 7 ++ container/slot/SlotPatternTerm.java | 9 +- container/slot/SlotRestrictedInput.java | 9 +- core/localization/ButtonToolTips.java | 2 +- core/localization/GuiText.java | 4 +- core/sync/packets/PacketValueConfig.java | 13 +++ parts/reporting/PartPatternTerminal.java | 29 +++--- 11 files changed, 206 insertions(+), 45 deletions(-) diff --git a/client/gui/AEBaseGui.java b/client/gui/AEBaseGui.java index 3778fa4e..c15da2d2 100644 --- a/client/gui/AEBaseGui.java +++ b/client/gui/AEBaseGui.java @@ -483,16 +483,21 @@ public abstract class AEBaseGui extends GuiContainer if ( o instanceof OptionalSlotFake ) { OptionalSlotFake fs = (OptionalSlotFake) o; - if ( fs.isEnabled() ) - this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.srcX - 1, fs.srcY - 1, 18, 18 ); - else + if ( fs.renderDisabled() ) { - GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); - GL11.glColor4f( 1.0F, 1.0F, 1.0F, 0.4F ); - GL11.glEnable( GL11.GL_BLEND ); - this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.srcX - 1, fs.srcY - 1, 18, 18 ); - GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F ); - GL11.glPopAttrib(); + if ( fs.isEnabled() ) + { + this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.srcX - 1, fs.srcY - 1, 18, 18 ); + } + else + { + GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); + GL11.glColor4f( 1.0F, 1.0F, 1.0F, 0.4F ); + GL11.glEnable( GL11.GL_BLEND ); + this.drawTexturedModalRect( ox + fs.xDisplayPosition - 1, oy + fs.yDisplayPosition - 1, fs.srcX - 1, fs.srcY - 1, 18, 18 ); + GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F ); + GL11.glPopAttrib(); + } } } } diff --git a/client/gui/implementations/GuiPatternTerm.java b/client/gui/implementations/GuiPatternTerm.java index 3b79e38f..6041d0a4 100644 --- a/client/gui/implementations/GuiPatternTerm.java +++ b/client/gui/implementations/GuiPatternTerm.java @@ -1,27 +1,42 @@ package appeng.client.gui.implementations; +import java.io.IOException; + import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; import appeng.api.config.ActionItems; import appeng.api.config.Settings; import appeng.api.storage.ITerminalHost; import appeng.client.gui.widgets.GuiImgButton; +import appeng.client.gui.widgets.GuiTabButton; import appeng.container.implementations.ContainerPatternTerm; import appeng.core.localization.GuiText; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketValueConfig; public class GuiPatternTerm extends GuiMEMonitorable { - GuiImgButton exttractPatternBtn; + ContainerPatternTerm container; + + GuiTabButton tabCraftButton; + GuiTabButton tabProcessButton; GuiImgButton substitutionsBtn; + GuiImgButton encodeBtn; @Override public void initGui() { super.initGui(); - buttonList.add( exttractPatternBtn = new GuiImgButton( this.guiLeft + 6, this.guiTop + this.ySize - 161, Settings.ACTIONS, ActionItems.PULL ) ); - buttonList.add( substitutionsBtn = new GuiImgButton( this.guiLeft + 118, this.guiTop + this.ySize - 161, Settings.ACTIONS, ActionItems.CLOSE ) ); - exttractPatternBtn.halfSize = true; + buttonList.add( tabCraftButton = new GuiTabButton( this.guiLeft + 173, this.guiTop + this.ySize - 179, new ItemStack( Blocks.crafting_table ), + GuiText.CraftingPattern.getLocal(), itemRender ) ); + buttonList.add( tabProcessButton = new GuiTabButton( this.guiLeft + 173, this.guiTop + this.ySize - 179, new ItemStack( Blocks.furnace ), + GuiText.ProcessingPattern.getLocal(), itemRender ) ); + buttonList.add( substitutionsBtn = new GuiImgButton( this.guiLeft + 74, this.guiTop + this.ySize - 163, Settings.ACTIONS, ActionItems.SUBSTITUTION ) ); + buttonList.add( encodeBtn = new GuiImgButton( this.guiLeft + 147, this.guiTop + this.ySize - 144, Settings.ACTIONS, ActionItems.ENCODE ) ); + substitutionsBtn.halfSize = true; } @Override @@ -29,9 +44,22 @@ public class GuiPatternTerm extends GuiMEMonitorable { super.actionPerformed( btn ); - if ( exttractPatternBtn == btn ) + try { + if ( tabCraftButton == btn || tabProcessButton == btn ) + { + NetworkHandler.instance.sendToServer( new PacketValueConfig( "PatternTerminal.CraftMode", tabProcessButton == btn ? "0" : "1" ) ); + } + if ( encodeBtn == btn ) + { + NetworkHandler.instance.sendToServer( new PacketValueConfig( "PatternTerminal.Encode", "1" ) ); + } + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); } if ( substitutionsBtn == btn ) @@ -42,17 +70,31 @@ public class GuiPatternTerm extends GuiMEMonitorable public GuiPatternTerm(InventoryPlayer inventoryPlayer, ITerminalHost te) { super( inventoryPlayer, te, new ContainerPatternTerm( inventoryPlayer, te ) ); + container = (ContainerPatternTerm) this.inventorySlots; reservedSpace = 85; } protected String getBackground() { - return "guis/pattern.png"; + if ( container.craftingMode ) + return "guis/pattern.png"; + return "guis/pattern2.png"; } @Override public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { + if ( !container.craftingMode ) + { + tabCraftButton.visible = true; + tabProcessButton.visible = false; + } + else + { + tabCraftButton.visible = false; + tabProcessButton.visible = true; + } + super.drawFG( offsetX, offsetY, mouseX, mouseY ); fontRendererObj.drawString( GuiText.PatternTerminal.getLocal(), 8, ySize - 96 + 2 - reservedSpace, 4210752 ); } diff --git a/client/gui/widgets/GuiImgButton.java b/client/gui/widgets/GuiImgButton.java index 22a82cc3..f0189398 100644 --- a/client/gui/widgets/GuiImgButton.java +++ b/client/gui/widgets/GuiImgButton.java @@ -156,7 +156,8 @@ public class GuiImgButton extends GuiButton implements ITooltip registerApp( 66, Settings.ACTIONS, ActionItems.WRENCH, ButtonToolTips.PartitionStorage, ButtonToolTips.PartitionStorageHint ); registerApp( 6, Settings.ACTIONS, ActionItems.CLOSE, ButtonToolTips.Clear, ButtonToolTips.ClearSettings ); - registerApp( 7, Settings.ACTIONS, ActionItems.PULL, ButtonToolTips.Pull, ButtonToolTips.PullDescription ); + registerApp( 8, Settings.ACTIONS, ActionItems.ENCODE, ButtonToolTips.Encode, ButtonToolTips.EncodeDescription ); + registerApp( 4 + 3 * 16, Settings.ACTIONS, ActionItems.SUBSTITUTION, ButtonToolTips.Substitutions, ButtonToolTips.SubstitutionsDesc ); registerApp( 16, Settings.VIEW_MODE, ViewItems.STORED, ButtonToolTips.View, ButtonToolTips.StoredItems ); registerApp( 18, Settings.VIEW_MODE, ViewItems.ALL, ButtonToolTips.View, ButtonToolTips.StoredCraftable ); diff --git a/container/implementations/ContainerPatternTerm.java b/container/implementations/ContainerPatternTerm.java index f89a95a0..f721d8ba 100644 --- a/container/implementations/ContainerPatternTerm.java +++ b/container/implementations/ContainerPatternTerm.java @@ -1,9 +1,12 @@ package appeng.container.implementations; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import appeng.api.storage.ITerminalHost; +import appeng.container.slot.IOptionalSlotHost; +import appeng.container.slot.OptionalSlotFake; import appeng.container.slot.SlotFake; import appeng.container.slot.SlotPatternTerm; import appeng.container.slot.SlotRestrictedInput; @@ -13,37 +16,97 @@ import appeng.tile.inventory.AppEngInternalInventory; import appeng.tile.inventory.IAEAppEngInventory; import appeng.tile.inventory.InvOperation; -public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEAppEngInventory +public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost { AppEngInternalInventory craftSlotInv = new AppEngInternalInventory( this, 1 ); SlotFake craftingSlots[] = new SlotFake[9]; - SlotFake outputSlots[] = new SlotFake[3]; - SlotPatternTerm craftSlot; - SlotRestrictedInput patternSlot; + OptionalSlotFake outputSlots[] = new OptionalSlotFake[3]; - PartPatternTerminal ct; + SlotPatternTerm craftSlot; + + SlotRestrictedInput patternSlotIN; + SlotRestrictedInput patternSlotOUT; + + public PartPatternTerminal ct; + public boolean craftingMode = true; public ContainerPatternTerm(InventoryPlayer ip, ITerminalHost montiorable) { super( ip, montiorable, false ); ct = (PartPatternTerminal) montiorable; IInventory patternInv = ct.getInventoryByName( "pattern" ); + IInventory output = ct.getInventoryByName( "output" ); IInventory crafting = ct.getInventoryByName( "crafting" ); for (int y = 0; y < 3; y++) for (int x = 0; x < 3; x++) - addSlotToContainer( craftingSlots[x + y * 3] = new SlotFake( crafting, x + y * 3, 54 + x * 18, -76 + y * 18 ) ); + addSlotToContainer( craftingSlots[x + y * 3] = new SlotFake( crafting, x + y * 3, 18 + x * 18, -76 + y * 18 ) ); + + addSlotToContainer( craftSlot = new SlotPatternTerm( craftSlotInv, this, 0, 110, -76 + 18, 2 ) ); + craftSlot.renderDisabled = false; + craftSlot.IIcon = -1; for (int y = 0; y < 3; y++) - addSlotToContainer( outputSlots[y] = new SlotFake( crafting, 9 + y, 146, -76 + y * 18 ) ); + { + addSlotToContainer( outputSlots[y] = new OptionalSlotFake( output, this, y, 110, -76 + y * 18, 0, 0, 1 ) ); + outputSlots[y].renderDisabled = false; + outputSlots[y].IIcon = -1; + } + addSlotToContainer( patternSlotIN = new SlotRestrictedInput( PlaceableItemType.BLANK_PATTERN, patternInv, 0, 147, -72 - 9 ) ); + addSlotToContainer( patternSlotOUT = new SlotRestrictedInput( PlaceableItemType.ENCODED_PATTERN, patternInv, 1, 147, -72 + 34 ) ); - addSlotToContainer( patternSlot = new SlotRestrictedInput( PlaceableItemType.PATTERN, patternInv, 0, 17, -72 - 9 ) ); - addSlotToContainer( craftSlot = new SlotPatternTerm( craftSlotInv, 0, 17, -72 + 34 ) ); + patternSlotOUT.setStackLimit( 1 ); - patternSlot.setStackLimit( 1 ); bindPlayerInventory( ip, 0, 0 ); + updateOrderOfOutputSlots(); + } + + private void updateOrderOfOutputSlots() + { + if ( !craftingMode ) + { + craftSlot.xDisplayPosition = 0; + + for (int y = 0; y < 3; y++) + outputSlots[y].xDisplayPosition = outputSlots[y].defX; + } + else + { + craftSlot.xDisplayPosition = craftSlot.defX; + + for (int y = 0; y < 3; y++) + outputSlots[y].xDisplayPosition = 0; + } + } + + @Override + public void detectAndSendChanges() + { + super.detectAndSendChanges(); + if ( craftingMode != ct.craftingMode ) + { + craftingMode = ct.craftingMode; + updateOrderOfOutputSlots(); + + for (Object c : this.crafters) + { + if ( c instanceof ICrafting ) + ((ICrafting) c).sendProgressBarUpdate( this, 97, craftingMode ? 1 : 0 ); + } + } + } + + @Override + public void updateProgressBar(int idx, int value) + { + super.updateProgressBar( idx, value ); + if ( idx == 97 ) + { + craftingMode = value == 1; + updateOrderOfOutputSlots(); + } } @Override @@ -57,4 +120,19 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA { } + + public void encode() + { + + } + + @Override + public boolean isSlotEnabled(int idx) + { + if ( idx == 1 ) + return craftingMode == false; + if ( idx == 2 ) + return craftingMode == true; + return false; + } } diff --git a/container/slot/OptionalSlotFake.java b/container/slot/OptionalSlotFake.java index f5b56cd0..587775bc 100644 --- a/container/slot/OptionalSlotFake.java +++ b/container/slot/OptionalSlotFake.java @@ -10,6 +10,8 @@ public class OptionalSlotFake extends SlotFake final int groupNum; IOptionalSlotHost host; + public boolean renderDisabled = true; + public int srcX; public int srcY; @@ -43,4 +45,9 @@ public class OptionalSlotFake extends SlotFake return host.isSlotEnabled( groupNum ); } + public boolean renderDisabled() + { + return renderDisabled; + } + } diff --git a/container/slot/SlotPatternTerm.java b/container/slot/SlotPatternTerm.java index b6fa682f..ab732f8c 100644 --- a/container/slot/SlotPatternTerm.java +++ b/container/slot/SlotPatternTerm.java @@ -4,22 +4,23 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -public class SlotPatternTerm extends AppEngSlot +public class SlotPatternTerm extends OptionalSlotFake { - public SlotPatternTerm(IInventory inv, int idx, int x, int y) { - super( inv, idx, x, y ); + public SlotPatternTerm(IInventory inv, IOptionalSlotHost h, int idx, int x, int y, int grpnum) { + super( inv, h, idx, x, y, 0, 0, grpnum ); } @Override public boolean canTakeStack(EntityPlayer par1EntityPlayer) { - return false; + return super.canTakeStack( par1EntityPlayer ); } @Override public void onPickupFromSlot(EntityPlayer p, ItemStack is) { + super.onPickupFromSlot( p, is ); } } diff --git a/container/slot/SlotRestrictedInput.java b/container/slot/SlotRestrictedInput.java index c48fa2b1..bae19106 100644 --- a/container/slot/SlotRestrictedInput.java +++ b/container/slot/SlotRestrictedInput.java @@ -130,9 +130,14 @@ public class SlotRestrictedInput extends AppEngSlot case VALID_ENCODED_PATTERN_W_OUPUT: case ENCODED_PATTERN_W_OUTPUT: case ENCODED_PATTERN: { - ICraftingPatternDetails pattern = i.getItem() instanceof ICraftingPatternItem ? ((ICraftingPatternItem) i.getItem()).getPatternForItem( i ) : null; - return pattern != null; + if ( i.getItem() instanceof ICraftingPatternItem ) + return true; + // ICraftingPatternDetails pattern = i.getItem() instanceof ICraftingPatternItem ? ((ICraftingPatternItem) + // i.getItem()).getPatternForItem( i ) : null; + return false;// pattern != null; } + case BLANK_PATTERN: + return AEApi.instance().materials().materialBlankPattern.sameAs( i ); case PATTERN: if ( i.getItem() instanceof ICraftingPatternItem ) diff --git a/core/localization/ButtonToolTips.java b/core/localization/ButtonToolTips.java index b86f9a02..e919a52b 100644 --- a/core/localization/ButtonToolTips.java +++ b/core/localization/ButtonToolTips.java @@ -34,7 +34,7 @@ public enum ButtonToolTips LevelType, LevelType_Energy, LevelType_Item, InventoryTweaks, TerminalStyle, TerminalStyle_Full, TerminalStyle_Tall, TerminalStyle_Small, - Pull, PullDescription, Substitutions, SubstitutionsOn, SubstitutionsOff; + Encode, EncodeDescription, Substitutions, SubstitutionsOn, SubstitutionsOff, SubstitutionsDesc; String root; diff --git a/core/localization/GuiText.java b/core/localization/GuiText.java index 69a9a813..dde2f96f 100644 --- a/core/localization/GuiText.java +++ b/core/localization/GuiText.java @@ -26,7 +26,9 @@ public enum GuiText METunnel, ItemTunnel, RedstoneTunnel, MJTunnel, EUTunnel, FluidTunnel, StoredSize, - StoredPower, MaxPower, RequiredPower, Efficiency, CopyMode, CopyModeDesc, PatternTerminal; + StoredPower, MaxPower, RequiredPower, Efficiency, CopyMode, CopyModeDesc, PatternTerminal, + + CraftingPattern, ProcessingPattern; String root; diff --git a/core/sync/packets/PacketValueConfig.java b/core/sync/packets/PacketValueConfig.java index 10e242ca..1435ed77 100644 --- a/core/sync/packets/PacketValueConfig.java +++ b/core/sync/packets/PacketValueConfig.java @@ -17,6 +17,7 @@ import appeng.api.util.IConfigureableObject; import appeng.container.AEBaseContainer; import appeng.container.implementations.ContainerCellWorkbench; import appeng.container.implementations.ContainerLevelEmitter; +import appeng.container.implementations.ContainerPatternTerm; import appeng.container.implementations.ContainerPriority; import appeng.container.implementations.ContainerQuartzKnife; import appeng.container.implementations.ContainerSecurity; @@ -66,6 +67,18 @@ public class PacketValueConfig extends AppEngPacket lvc.setLevel( Long.parseLong( Value ), player ); return; } + else if ( Name.startsWith( "PatternTerminal." ) && c instanceof ContainerPatternTerm ) + { + ContainerPatternTerm cpt = (ContainerPatternTerm) c; + if ( Name.equals( "PatternTerminal.CraftMode" ) ) + { + cpt.ct.craftingMode = Value.equals( "1" ); + } + else if ( Name.equals( "PatternTerminal.Encode" ) ) + { + cpt.encode(); + } + } else if ( Name.startsWith( "CellWorkbench." ) && c instanceof ContainerCellWorkbench ) { ContainerCellWorkbench ccw = (ContainerCellWorkbench) c; diff --git a/parts/reporting/PartPatternTerminal.java b/parts/reporting/PartPatternTerminal.java index acbc14b6..60ebde4d 100644 --- a/parts/reporting/PartPatternTerminal.java +++ b/parts/reporting/PartPatternTerminal.java @@ -14,43 +14,45 @@ import appeng.tile.inventory.InvOperation; public class PartPatternTerminal extends PartTerminal implements IAEAppEngInventory { - AppEngInternalInventory craftingGrid = new AppEngInternalInventory( this, 9 + 3 ); - AppEngInternalInventory pattern = new AppEngInternalInventory( this, 1 ); + AppEngInternalInventory crafting = new AppEngInternalInventory( this, 9 ); + AppEngInternalInventory output = new AppEngInternalInventory( this, 3 ); + AppEngInternalInventory pattern = new AppEngInternalInventory( this, 2 ); + + public boolean craftingMode = true; @Override public void writeToNBT(NBTTagCompound data) { super.writeToNBT( data ); + data.setBoolean( "craftingMode", craftingMode ); pattern.writeToNBT( data, "pattern" ); - craftingGrid.writeToNBT( data, "craftingGrid" ); + output.writeToNBT( data, "outputList" ); + crafting.writeToNBT( data, "craftingGrid" ); } @Override public void readFromNBT(NBTTagCompound data) { super.readFromNBT( data ); + craftingMode = data.getBoolean( "craftingMode" ); pattern.readFromNBT( data, "pattern" ); - craftingGrid.readFromNBT( data, "craftingGrid" ); + output.readFromNBT( data, "outputList" ); + crafting.readFromNBT( data, "craftingGrid" ); } @Override public void getDrops(List drops, boolean wrenched) { - for (ItemStack is : craftingGrid) - if ( is != null ) - drops.add( is ); - for (ItemStack is : pattern) if ( is != null ) drops.add( is ); } public PartPatternTerminal(ItemStack is) { - super( PartPatternTerminal.class, is, true ); + super( PartPatternTerminal.class, is ); frontBright = CableBusTextures.PartPatternTerm_Bright; frontColored = CableBusTextures.PartPatternTerm_Colored; frontDark = CableBusTextures.PartPatternTerm_Dark; - // frontSolid = CableBusTextures.PartPatternTerm_Solid; } public GuiBridge getGui() @@ -62,9 +64,14 @@ public class PartPatternTerminal extends PartTerminal implements IAEAppEngInvent public IInventory getInventoryByName(String name) { if ( name.equals( "crafting" ) ) - return craftingGrid; + return crafting; + + if ( name.equals( "output" ) ) + return output; + if ( name.equals( "pattern" ) ) return pattern; + return super.getInventoryByName( name ); }