Finished Crafting CPU Gui.

This commit is contained in:
AlgorithmX2 2014-06-28 00:20:12 -05:00
parent db8fa143ed
commit c99964dad6
7 changed files with 188 additions and 53 deletions

View file

@ -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<String> 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();
}

View file

@ -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 )

View file

@ -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;

View file

@ -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;

View file

@ -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<CraftingCPUCluster> cpuClusters = new HashSet();
HashSet<ICraftingProvider> providers = new HashSet();
IGrid grid;
IStorageGrid sg;
IEnergyGrid eg;
HashMap<ICraftingPatternDetails, List<ICraftingMedium>> craftingMethods = new HashMap();
HashMap<IAEItemStack, Set<ICraftingPatternDetails>> 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())
{

View file

@ -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<IAEItemStack
return true;
}
public void updateCraftingLogic(IGrid grid, CraftingCache cc)
public void cancel()
{
isComplete = true;
tasks.clear();
waitingFor.resetStatus();
}
public void updateCraftingLogic(IGrid grid, IEnergyGrid eg, CraftingCache cc)
{
if ( isComplete )
{
@ -377,7 +386,7 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor<IAEItemStack
if ( waiting || tasks.isEmpty() ) // nothing to do here...
return;
int remainingOperations = accelerator + 1;
int remainingOperations = accelerator + 1 + 90;
boolean didsomething = false;
for (Entry<ICraftingPatternDetails, TaskProgress> e : tasks.entrySet())
@ -399,10 +408,22 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor<IAEItemStack
{
if ( ic == null )
{
IAEItemStack[] input = details.getInputs();
double sum = 0;
for (int x = 0; x < input.length; x++)
{
if ( input[x] != null )
sum += input[x].getStackSize();
}
// power...
if ( eg.extractAEPower( sum, Actionable.MODULATE, PowerMultiplier.CONFIG ) < sum - 0.01 )
continue;
ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
boolean found = false;
IAEItemStack[] input = details.getInputs();
for (int x = 0; x < input.length; x++)
{
@ -609,4 +630,5 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor<IAEItemStack
is.setStackSize( 0 );
return is;
}
}

View file

@ -55,12 +55,12 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IAEAppEn
{
static final int[] sides = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
static final ItemStack is = AEApi.instance().blocks().blockMolecularAssembler.stack( 1 );
static final ItemStack assemblerStack = AEApi.instance().blocks().blockMolecularAssembler.stack( 1 );
private InventoryCrafting craftingInv = new InventoryCrafting( new ContainerNull(), 3, 3 );
private AppEngInternalInventory inv = new AppEngInternalInventory( this, 9 + 2 );
private IConfigManager settings = new ConfigManager( this );
private UpgradeInventory upgrades = new UpgradeInventory( is, this, getUpgradeSlots() );
private UpgradeInventory upgrades = new UpgradeInventory( assemblerStack, this, getUpgradeSlots() );
private ForgeDirection pushDirection = ForgeDirection.UNKNOWN;
private ItemStack myPattern = null;
@ -216,8 +216,8 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IAEAppEn
if ( myPat != null && myPat.getItem() instanceof ItemEncodedPattern )
{
World w = getWorldObj();
ItemEncodedPattern iep = (ItemEncodedPattern) is.getItem();
ICraftingPatternDetails ph = iep.getPatternForItem( is, w );
ItemEncodedPattern iep = (ItemEncodedPattern) myPat.getItem();
ICraftingPatternDetails ph = iep.getPatternForItem( myPat, w );
if ( ph != null )
{
forcePlan = true;
@ -391,22 +391,22 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IAEAppEn
switch (upgrades.getInstalledUpgrades( Upgrades.SPEED ))
{
case 0:
progress += userPower( TicksSinceLastCall * 10 );
progress += userPower( TicksSinceLastCall, 10, 1.0 );
break;
case 1:
progress += userPower( TicksSinceLastCall * 13 );
progress += userPower( TicksSinceLastCall, 13, 1.3 );
break;
case 2:
progress += userPower( TicksSinceLastCall * 17 );
progress += userPower( TicksSinceLastCall, 17, 1.7 );
break;
case 3:
progress += userPower( TicksSinceLastCall * 20 );
progress += userPower( TicksSinceLastCall, 20, 2.0 );
break;
case 4:
progress += userPower( TicksSinceLastCall * 25 );
progress += userPower( TicksSinceLastCall, 25, 2.5 );
break;
case 5:
progress += userPower( TicksSinceLastCall * 50 );
progress += userPower( TicksSinceLastCall, 50, 5.0 );
break;
}
@ -459,11 +459,11 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IAEAppEn
}
}
private int userPower(int i)
private int userPower(int ticksPassed, int bonusValue, double acceleratorTax)
{
try
{
return (int) gridProxy.getEnergy().extractAEPower( i, Actionable.MODULATE, PowerMultiplier.CONFIG );
return (int) (gridProxy.getEnergy().extractAEPower( ticksPassed * bonusValue * acceleratorTax, Actionable.MODULATE, PowerMultiplier.CONFIG ) / acceleratorTax);
}
catch (GridAccessException e)
{