From c99964dad68f5ccb6d1f40f89baa1881105ba421 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Sat, 28 Jun 2014 00:20:12 -0500 Subject: [PATCH] Finished Crafting CPU Gui. --- .../gui/implementations/GuiCraftingCPU.java | 158 ++++++++++++++---- .../implementations/ContainerCraftingCPU.java | 8 + core/localization/GuiText.java | 4 +- core/sync/packets/PacketValueConfig.java | 7 + me/cache/CraftingCache.java | 12 +- .../implementations/CraftingCPUCluster.java | 28 +++- tile/crafting/TileMolecularAssembler.java | 24 +-- 7 files changed, 188 insertions(+), 53 deletions(-) diff --git a/client/gui/implementations/GuiCraftingCPU.java b/client/gui/implementations/GuiCraftingCPU.java index 17c7b1772..5b78732b3 100644 --- a/client/gui/implementations/GuiCraftingCPU.java +++ b/client/gui/implementations/GuiCraftingCPU.java @@ -1,7 +1,9 @@ package appeng.client.gui.implementations; +import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import net.minecraft.client.gui.GuiButton; @@ -20,10 +22,15 @@ import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiScrollbar; import appeng.client.gui.widgets.ISortSource; import appeng.container.implementations.ContainerCraftingCPU; +import appeng.core.AELog; import appeng.core.localization.GuiText; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketValueConfig; import appeng.tile.crafting.TileCraftingTile; import appeng.util.Platform; +import com.google.common.base.Joiner; + public class GuiCraftingCPU extends AEBaseGui implements ISortSource { @@ -37,21 +44,38 @@ public class GuiCraftingCPU extends AEBaseGui implements ISortSource public GuiCraftingCPU(InventoryPlayer inventoryPlayer, TileCraftingTile te) { super( new ContainerCraftingCPU( inventoryPlayer, te ) ); - this.ySize = 153; - this.xSize = 195; + this.ySize = 184; + this.xSize = 238; myScrollBar = new GuiScrollbar(); } + GuiButton cancel; + @Override protected void actionPerformed(GuiButton btn) { super.actionPerformed( btn ); + + if ( cancel == btn ) + { + try + { + NetworkHandler.instance.sendToServer( new PacketValueConfig( "TileCrafting.Cancel", "Cancel" ) ); + } + catch (IOException e) + { + AELog.error( e ); + } + } } @Override public void initGui() { super.initGui(); + + cancel = new GuiButton( 0, this.guiLeft + 163, this.guiTop + ySize - 25, 50, 20, GuiText.Cancel.getLocal() ); + buttonList.add( cancel ); } private long getTotal(IAEItemStack is) @@ -167,13 +191,14 @@ public class GuiCraftingCPU extends AEBaseGui implements ISortSource for (IAEItemStack l : visual) size++; - myScrollBar.setTop( 39 ).setLeft( 175 ).setHeight( 78 ); - myScrollBar.setRange( 0, (size + 4) / 5 - rows, 1 ); + myScrollBar.setTop( 19 ).setLeft( 218 ).setHeight( 137 ); + myScrollBar.setRange( 0, (size + 2) / 3 - rows, 1 ); } @Override public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) { + setScrollBar(); bindTexture( "guis/craftingcpu.png" ); this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize ); } @@ -188,17 +213,18 @@ public class GuiCraftingCPU extends AEBaseGui implements ISortSource int gx = (width - xSize) / 2; int gy = (height - ySize) / 2; + int yoff = 23; tooltip = -1; for (int z = 0; z <= 4 * 5; z++) { - int minX = gx + 14 + x * 31; - int minY = gy + 41 + y * 18; + int minX = gx + 9 + x * 67; + int minY = gy + 22 + y * yoff; - if ( minX < mouse_x && minX + 28 > mouse_x ) + if ( minX < mouse_x && minX + 67 > mouse_x ) { - if ( minY < mouse_y && minY + 20 > mouse_y ) + if ( minY < mouse_y && minY + yoff - 2 > mouse_y ) { tooltip = z; break; @@ -208,7 +234,7 @@ public class GuiCraftingCPU extends AEBaseGui implements ISortSource x++; - if ( x > 4 ) + if ( x > 2 ) { y++; x = 0; @@ -221,21 +247,24 @@ public class GuiCraftingCPU extends AEBaseGui implements ISortSource @Override public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { - fontRendererObj.drawString( GuiText.NetworkDetails.getLocal(), 8, 7, 4210752 ); + fontRendererObj.drawString( GuiText.CraftingStatus.getLocal(), 8, 7, 4210752 ); - int sectionLength = 30; + int sectionLength = 67; int x = 0; int y = 0; - int xo = 0 + 12; - int yo = 0 + 42; - int viewStart = 0;// myScrollBar.getCurrentScroll() * 5; - int viewEnd = viewStart + 5 * 4; + int xo = 0 + 9; + int yo = 0 + 22; + int viewStart = myScrollBar.getCurrentScroll() * 3; + int viewEnd = viewStart + 3 * 6; - String ToolTip = ""; + String dspToolTip = ""; + List lineList = new LinkedList(); int toolPosX = 0; int toolPosY = 0; + int offY = 23; + for (int z = viewStart; z < Math.min( viewEnd, visual.size() ); z++) { IAEItemStack refStack = visual.get( z );// repo.getRefrenceItem( z ); @@ -244,37 +273,100 @@ public class GuiCraftingCPU extends AEBaseGui implements ISortSource GL11.glPushMatrix(); GL11.glScaled( 0.5, 0.5, 0.5 ); - String str = Long.toString( refStack.getStackSize() ); - if ( refStack.getStackSize() >= 10000 ) - str = Long.toString( refStack.getStackSize() / 1000 ) + "k"; + IAEItemStack stored = storage.findPrecise( refStack ); + IAEItemStack activeStack = active.findPrecise( refStack ); + IAEItemStack pendingStack = pending.findPrecise( refStack ); - int w = fontRendererObj.getStringWidth( str ); - fontRendererObj.drawString( str, (int) ((x * sectionLength + xo + sectionLength - 19 - ((float) w * 0.5)) * 2), (int) ((y * 18 + yo + 6) * 2), - 4210752 ); + int lines = 0; + + if ( stored != null && stored.getStackSize() > 0 ) + lines++; + if ( activeStack != null && activeStack.getStackSize() > 0 ) + lines++; + if ( pendingStack != null && pendingStack.getStackSize() > 0 ) + lines++; + + int negY = ((lines - 1) * 5) / 2; + int downY = 0; + + if ( stored != null && stored.getStackSize() > 0 ) + { + String str = Long.toString( stored.getStackSize() ); + if ( stored.getStackSize() >= 10000 ) + str = Long.toString( stored.getStackSize() / 1000 ) + "k"; + if ( stored.getStackSize() >= 10000000 ) + str = Long.toString( stored.getStackSize() / 1000000 ) + "m"; + + str = GuiText.Stored.getLocal() + ": " + str; + int w = 4 + fontRendererObj.getStringWidth( str ); + fontRendererObj.drawString( str, (int) ((x * (1 + sectionLength) + xo + sectionLength - 19 - ((float) w * 0.5)) * 2), (int) ((y * offY + yo + + 6 - negY + downY) * 2), 4210752 ); + + if ( tooltip == z - viewStart ) + lineList.add( GuiText.Stored.getLocal() + ": " + Long.toString( stored.getStackSize() ) ); + + downY += 5; + } + + if ( activeStack != null && activeStack.getStackSize() > 0 ) + { + String str = Long.toString( activeStack.getStackSize() ); + if ( activeStack.getStackSize() >= 10000 ) + str = Long.toString( activeStack.getStackSize() / 1000 ) + "k"; + if ( activeStack.getStackSize() >= 10000000 ) + str = Long.toString( activeStack.getStackSize() / 1000000 ) + "m"; + + str = GuiText.Crafting.getLocal() + ": " + str; + int w = 4 + fontRendererObj.getStringWidth( str ); + fontRendererObj.drawString( str, (int) ((x * (1 + sectionLength) + xo + sectionLength - 19 - ((float) w * 0.5)) * 2), (int) ((y * offY + yo + + 6 - negY + downY) * 2), 4210752 ); + + if ( tooltip == z - viewStart ) + lineList.add( GuiText.Crafting.getLocal() + ": " + Long.toString( activeStack.getStackSize() ) ); + + downY += 5; + } + + if ( pendingStack != null && pendingStack.getStackSize() > 0 ) + { + String str = Long.toString( pendingStack.getStackSize() ); + if ( pendingStack.getStackSize() >= 10000 ) + str = Long.toString( pendingStack.getStackSize() / 1000 ) + "k"; + if ( pendingStack.getStackSize() >= 10000000 ) + str = Long.toString( pendingStack.getStackSize() / 1000000 ) + "m"; + + str = GuiText.Scheduled.getLocal() + ": " + str; + int w = 4 + fontRendererObj.getStringWidth( str ); + fontRendererObj.drawString( str, (int) ((x * (1 + sectionLength) + xo + sectionLength - 19 - ((float) w * 0.5)) * 2), (int) ((y * offY + yo + + 6 - negY + downY) * 2), 4210752 ); + + if ( tooltip == z - viewStart ) + lineList.add( GuiText.Scheduled.getLocal() + ": " + Long.toString( pendingStack.getStackSize() ) ); + + } GL11.glPopMatrix(); - int posX = x * sectionLength + xo + sectionLength - 18; - int posY = y * 18 + yo; + int posX = x * (1 + sectionLength) + xo + sectionLength - 19; + int posY = y * offY + yo; ItemStack is = refStack.copy().getItemStack(); if ( tooltip == z - viewStart ) { - ToolTip = Platform.getItemDisplayName( is ); + dspToolTip = Platform.getItemDisplayName( is ); - ToolTip = ToolTip + ("\n" + GuiText.Installed.getLocal() + ": " + (refStack.getStackSize())); - if ( refStack.getCountRequestable() > 0 ) - ToolTip = ToolTip + ("\n" + GuiText.EnergyDrain.getLocal() + ": " + Platform.formatPowerLong( refStack.getCountRequestable(), true )); + if ( lineList.size() > 0 ) + dspToolTip = dspToolTip + "\n" + Joiner.on( "\n" ).join( lineList ); - toolPosX = x * sectionLength + xo + sectionLength - 8; - toolPosY = y * 18 + yo; + toolPosX = x * (1 + sectionLength) + xo + sectionLength - 8; + toolPosY = y * offY + yo; } drawItem( posX, posY, is ); x++; - if ( x > 4 ) + if ( x > 2 ) { y++; x = 0; @@ -283,10 +375,10 @@ public class GuiCraftingCPU extends AEBaseGui implements ISortSource } - if ( tooltip >= 0 && ToolTip.length() > 0 ) + if ( tooltip >= 0 && dspToolTip.length() > 0 ) { GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS ); - drawTooltip( toolPosX, toolPosY + 10, 0, ToolTip ); + drawTooltip( toolPosX, toolPosY + 10, 0, dspToolTip ); GL11.glPopAttrib(); } diff --git a/container/implementations/ContainerCraftingCPU.java b/container/implementations/ContainerCraftingCPU.java index 4a8db72bf..a0697a329 100644 --- a/container/implementations/ContainerCraftingCPU.java +++ b/container/implementations/ContainerCraftingCPU.java @@ -62,6 +62,14 @@ public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorH isContainerValid = false; } + public void cancelCrafting() + { + if ( monitor != null ) + { + monitor.cancel(); + } + } + private void findNode(IGridHost host, ForgeDirection d) { if ( network == null ) diff --git a/core/localization/GuiText.java b/core/localization/GuiText.java index 075463a6a..366924e9f 100644 --- a/core/localization/GuiText.java +++ b/core/localization/GuiText.java @@ -30,7 +30,9 @@ public enum GuiText StoredPower, MaxPower, RequiredPower, Efficiency, InWorldCrafting, inWorldFluix, inWorldPurificationCertus, inWorldPurificationNether, inWorldPurificationFluix, inWorldSingularity, ChargedQuartz, - OfSecondOutput, NoSecondOutput, RFTunnel, Stores, Next, SelectAmount, Lumen, Empty, ConfirmCrafting; + OfSecondOutput, NoSecondOutput, RFTunnel, Stores, Next, SelectAmount, Lumen, Empty, ConfirmCrafting, + + Stored, Crafting, Scheduled, CraftingStatus, Cancel; String root; diff --git a/core/sync/packets/PacketValueConfig.java b/core/sync/packets/PacketValueConfig.java index 6ee0b386b..b58cfe693 100644 --- a/core/sync/packets/PacketValueConfig.java +++ b/core/sync/packets/PacketValueConfig.java @@ -17,6 +17,7 @@ import appeng.api.util.IConfigManager; import appeng.api.util.IConfigureableObject; import appeng.container.AEBaseContainer; import appeng.container.implementations.ContainerCellWorkbench; +import appeng.container.implementations.ContainerCraftingCPU; import appeng.container.implementations.ContainerLevelEmitter; import appeng.container.implementations.ContainerPatternTerm; import appeng.container.implementations.ContainerPriority; @@ -53,6 +54,12 @@ public class PacketValueConfig extends AppEngPacket si.onWheel( is, Value.equals( "WheelUp" ) ); return; } + else if ( Name.equals( "TileCrafting.Cancel" ) && c instanceof ContainerCraftingCPU ) + { + ContainerCraftingCPU qk = (ContainerCraftingCPU) c; + qk.cancelCrafting(); + return; + } else if ( Name.equals( "QuartzKnife.Name" ) && c instanceof ContainerQuartzKnife ) { ContainerQuartzKnife qk = (ContainerQuartzKnife) c; diff --git a/me/cache/CraftingCache.java b/me/cache/CraftingCache.java index 5185e042a..f1c2fc39b 100644 --- a/me/cache/CraftingCache.java +++ b/me/cache/CraftingCache.java @@ -18,6 +18,7 @@ import appeng.api.networking.crafting.ICraftingMedium; import appeng.api.networking.crafting.ICraftingPatternDetails; import appeng.api.networking.crafting.ICraftingProvider; import appeng.api.networking.crafting.ICraftingProviderHelper; +import appeng.api.networking.energy.IEnergyGrid; import appeng.api.networking.events.MENetworkCraftingCpuChange; import appeng.api.networking.events.MENetworkCraftingPatternChange; import appeng.api.networking.events.MENetworkEventSubscribe; @@ -43,7 +44,10 @@ public class CraftingCache implements IGridCache, ICraftingProviderHelper, ICell HashSet cpuClusters = new HashSet(); HashSet providers = new HashSet(); + IGrid grid; + IStorageGrid sg; + IEnergyGrid eg; HashMap> craftingMethods = new HashMap(); HashMap> craftableItems = new HashMap(); @@ -57,7 +61,9 @@ public class CraftingCache implements IGridCache, ICraftingProviderHelper, ICell @MENetworkEventSubscribe public void afterCacheConstruction(MENetworkPostCacheConstruction cc) { - IStorageGrid sg = grid.getCache( IStorageGrid.class ); + sg = grid.getCache( IStorageGrid.class ); + eg = grid.getCache( IEnergyGrid.class ); + sg.registerCellProvider( this ); } @@ -71,7 +77,7 @@ public class CraftingCache implements IGridCache, ICraftingProviderHelper, ICell } for (CraftingCPUCluster cpu : cpuClusters) - cpu.updateCraftingLogic( grid, this ); + cpu.updateCraftingLogic( grid, eg, this ); } @MENetworkEventSubscribe @@ -138,8 +144,6 @@ public class CraftingCache implements IGridCache, ICraftingProviderHelper, ICell private void updatePatterns() { - IStorageGrid sg = grid.getCache( IStorageGrid.class ); - // update the stuff that was in the list... for (IAEItemStack out : craftableItems.keySet()) { diff --git a/me/cluster/implementations/CraftingCPUCluster.java b/me/cluster/implementations/CraftingCPUCluster.java index 3adf1fec7..b218613ce 100644 --- a/me/cluster/implementations/CraftingCPUCluster.java +++ b/me/cluster/implementations/CraftingCPUCluster.java @@ -13,12 +13,14 @@ import net.minecraft.world.WorldServer; import appeng.api.AEApi; import appeng.api.config.Actionable; import appeng.api.config.FuzzyMode; +import appeng.api.config.PowerMultiplier; import appeng.api.networking.IGrid; import appeng.api.networking.IGridHost; import appeng.api.networking.IGridNode; import appeng.api.networking.crafting.CraftingItemList; import appeng.api.networking.crafting.ICraftingMedium; import appeng.api.networking.crafting.ICraftingPatternDetails; +import appeng.api.networking.energy.IEnergyGrid; import appeng.api.networking.events.MENetworkCraftingCpuChange; import appeng.api.networking.security.BaseActionSource; import appeng.api.networking.storage.IBaseMonitor; @@ -346,7 +348,14 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor e : tasks.entrySet()) @@ -399,10 +408,22 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor