MORE Gui work for crafting

This commit is contained in:
AlgorithmX2 2014-06-29 04:06:07 -05:00
parent 85f607b76f
commit 36f81cf0b7
7 changed files with 234 additions and 44 deletions

View file

@ -118,7 +118,7 @@ public class GuiCraftAmount extends AEBaseGui
try
{
NetworkHandler.instance.sendToServer( new PacketCraftRequest( inventorySlots.getSlot( 0 ).getStack(), Integer.parseInt( this.amountToCraft
.getText() ) ) );
.getText() ), isShiftKeyDown() ) );
}
catch (Throwable e)
{
@ -185,6 +185,10 @@ public class GuiCraftAmount extends AEBaseGui
{
if ( !this.checkHotbarKeys( key ) )
{
if ( key == 28 )
{
actionPerformed( next );
}
if ( (key == 211 || key == 205 || key == 203 || key == 14 || character == '-' || Character.isDigit( character ))
&& amountToCraft.textboxKeyTyped( character, key ) )
{
@ -226,6 +230,8 @@ public class GuiCraftAmount extends AEBaseGui
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY)
{
next.displayString = isShiftKeyDown() ? GuiText.Start.getLocal() : GuiText.Next.getLocal();
bindTexture( "guis/craftAmt.png" );
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize );

View file

@ -1,5 +1,6 @@
package appeng.client.gui.implementations;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Iterator;
@ -19,7 +20,16 @@ import appeng.api.storage.data.IItemList;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiScrollbar;
import appeng.container.implementations.ContainerCraftConfirm;
import appeng.core.AELog;
import appeng.core.localization.GuiText;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.parts.reporting.PartCraftingTerminal;
import appeng.parts.reporting.PartPatternTerminal;
import appeng.parts.reporting.PartTerminal;
import appeng.util.Platform;
import com.google.common.base.Joiner;
@ -31,14 +41,40 @@ public class GuiCraftConfirm extends AEBaseGui
IItemList<IAEItemStack> storage = AEApi.instance().storage().createItemList();
IItemList<IAEItemStack> pending = AEApi.instance().storage().createItemList();
IItemList<IAEItemStack> missing = AEApi.instance().storage().createItemList();
List<IAEItemStack> visual = new ArrayList();
GuiBridge OriginalGui;
boolean isAutoStart()
{
return ((ContainerCraftConfirm) inventorySlots).autoStart;
}
boolean isSimulation()
{
return ((ContainerCraftConfirm) inventorySlots).simulation;
}
public GuiCraftConfirm(InventoryPlayer inventoryPlayer, ITerminalHost te) {
super( new ContainerCraftConfirm( inventoryPlayer, te ) );
xSize = 238;
ySize = 206;
myScrollBar = new GuiScrollbar();
if ( te instanceof WirelessTerminalGuiObject )
OriginalGui = GuiBridge.GUI_WIRELESS_TERM;
if ( te instanceof PartTerminal )
OriginalGui = GuiBridge.GUI_ME;
if ( te instanceof PartCraftingTerminal )
OriginalGui = GuiBridge.GUI_CRAFTING_TERMINAL;
if ( te instanceof PartPatternTerminal )
OriginalGui = GuiBridge.GUI_PATTERN_TERMINAL;
}
GuiButton cancel;
@ -51,13 +87,17 @@ public class GuiCraftConfirm extends AEBaseGui
super.initGui();
start = new GuiButton( 0, this.guiLeft + 162, this.guiTop + ySize - 25, 50, 20, GuiText.Start.getLocal() );
start.enabled = false;
buttonList.add( start );
selectcpu = new GuiButton( 0, this.guiLeft + (219 - 150) / 2, this.guiTop + ySize - 68, 150, 20, GuiText.CraftingCPU.getLocal() + ": "
+ GuiText.Automatic );
selectcpu.enabled = false;
buttonList.add( selectcpu );
cancel = new GuiButton( 0, this.guiLeft + 6, this.guiTop + ySize - 25, 50, 20, GuiText.Cancel.getLocal() );
if ( OriginalGui != null )
cancel = new GuiButton( 0, this.guiLeft + 6, this.guiTop + ySize - 25, 50, 20, GuiText.Cancel.getLocal() );
buttonList.add( cancel );
}
@ -65,12 +105,38 @@ public class GuiCraftConfirm extends AEBaseGui
protected void actionPerformed(GuiButton btn)
{
super.actionPerformed( btn );
if ( btn == cancel )
{
try
{
NetworkHandler.instance.sendToServer( new PacketSwitchGuis( OriginalGui ) );
}
catch (IOException e)
{
AELog.error( e );
}
}
if ( btn == start )
{
try
{
NetworkHandler.instance.sendToServer( new PacketValueConfig( "Terminal.Start", "Start" ) );
}
catch (Throwable e)
{
AELog.error( e );
}
}
}
private long getTotal(IAEItemStack is)
{
IAEItemStack a = storage.findPrecise( is );
IAEItemStack c = pending.findPrecise( is );
IAEItemStack m = missing.findPrecise( is );
long total = 0;
@ -80,6 +146,9 @@ public class GuiCraftConfirm extends AEBaseGui
if ( c != null )
total += c.getStackSize();
if ( m != null )
total += m.getStackSize();
return total;
}
@ -96,6 +165,11 @@ public class GuiCraftConfirm extends AEBaseGui
for (IAEItemStack l : list)
handleInput( pending, l );
break;
case 2:
for (IAEItemStack l : list)
handleInput( missing, l );
break;
}
for (IAEItemStack l : list)
@ -173,6 +247,19 @@ public class GuiCraftConfirm extends AEBaseGui
myScrollBar.setRange( 0, (size + 2) / 3 - rows, 1 );
}
@Override
protected void keyTyped(char character, int key)
{
if ( !this.checkHotbarKeys( key ) )
{
if ( key == 28 )
{
actionPerformed( start );
}
super.keyTyped( character, key );
}
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY)
{
@ -186,6 +273,9 @@ public class GuiCraftConfirm extends AEBaseGui
@Override
public void drawScreen(int mouse_x, int mouse_y, float btn)
{
start.enabled = isSimulation() ? false : true;
selectcpu.enabled = isSimulation() ? false : true;
int x = 0;
int y = 0;
@ -232,8 +322,14 @@ public class GuiCraftConfirm extends AEBaseGui
String Add = BytesUsed > 0 ? (byteUsed + " " + GuiText.BytesUsed.getLocal()) : GuiText.CalculatingWait.getLocal();
fontRendererObj.drawString( GuiText.CraftingPlan.getLocal() + " - " + Add, 8, 7, 4210752 );
String dsp = c.cpuBytesAvail > 0 ? (GuiText.Bytes.getLocal() + ": " + c.cpuBytesAvail + " : " + GuiText.CoProcessors.getLocal() + ": " + c.cpuCoProcessors)
: GuiText.Bytes.getLocal() + ": N/A : " + GuiText.CoProcessors.getLocal() + ": N/A";
String dsp = null;
if ( isSimulation() )
dsp = GuiText.Simulation.getLocal();
else
dsp = c.cpuBytesAvail > 0 ? (GuiText.Bytes.getLocal() + ": " + c.cpuBytesAvail + " : " + GuiText.CoProcessors.getLocal() + ": " + c.cpuCoProcessors)
: GuiText.Bytes.getLocal() + ": N/A : " + GuiText.CoProcessors.getLocal() + ": N/A";
int offset = (219 - fontRendererObj.getStringWidth( dsp )) / 2;
fontRendererObj.drawString( dsp, offset, 165, 4210752 );
@ -263,6 +359,7 @@ public class GuiCraftConfirm extends AEBaseGui
IAEItemStack stored = storage.findPrecise( refStack );
IAEItemStack pendingStack = pending.findPrecise( refStack );
IAEItemStack missingStack = missing.findPrecise( refStack );
int lines = 0;
@ -270,6 +367,8 @@ public class GuiCraftConfirm extends AEBaseGui
lines++;
if ( pendingStack != null && pendingStack.getStackSize() > 0 )
lines++;
if ( pendingStack != null && pendingStack.getStackSize() > 0 )
lines++;
int negY = ((lines - 1) * 5) / 2;
int downY = 0;
@ -293,6 +392,25 @@ public class GuiCraftConfirm extends AEBaseGui
downY += 5;
}
if ( missingStack != null && missingStack.getStackSize() > 0 )
{
String str = Long.toString( missingStack.getStackSize() );
if ( missingStack.getStackSize() >= 10000 )
str = Long.toString( missingStack.getStackSize() / 1000 ) + "k";
if ( missingStack.getStackSize() >= 10000000 )
str = Long.toString( missingStack.getStackSize() / 1000000 ) + "m";
str = GuiText.Missing.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.Missing.getLocal() + ": " + Long.toString( missingStack.getStackSize() ) );
downY += 5;
}
if ( pendingStack != null && pendingStack.getStackSize() > 0 )
{
String str = Long.toString( pendingStack.getStackSize() );

View file

@ -10,11 +10,14 @@ import net.minecraft.inventory.ICrafting;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.PlayerSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
@ -25,6 +28,7 @@ import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.crafting.CraftingJob;
import appeng.crafting.ICraftingHost;
import appeng.me.cache.CraftingCache;
public class ContainerCraftConfirm extends AEBaseContainer implements ICraftingHost
{
@ -42,6 +46,12 @@ public class ContainerCraftConfirm extends AEBaseContainer implements ICraftingH
@GuiSync(2)
public int cpuCoProcessors;
@GuiSync(3)
public boolean autoStart = false;
@GuiSync(4)
public boolean simulation = true;
public ContainerCraftConfirm(InventoryPlayer ip, ITerminalHost te) {
super( ip, te );
priHost = te;
@ -56,53 +66,83 @@ public class ContainerCraftConfirm extends AEBaseContainer implements ICraftingH
try
{
result = job.get();
if ( !result.isSimulation() )
{
try
simulation = false;
if ( autoStart )
{
PacketMEInventoryUpdate a = new PacketMEInventoryUpdate( (byte) 0 );
PacketMEInventoryUpdate b = new PacketMEInventoryUpdate( (byte) 1 );
startJob();
return;
}
}
else
simulation = true;
IItemList<IAEItemStack> plan = AEApi.instance().storage().createItemList();
result.tree.getPlan( plan );
try
{
PacketMEInventoryUpdate a = new PacketMEInventoryUpdate( (byte) 0 );
PacketMEInventoryUpdate b = new PacketMEInventoryUpdate( (byte) 1 );
PacketMEInventoryUpdate c = result.isSimulation() ? new PacketMEInventoryUpdate( (byte) 2 ) : null;
bytesUsed = result.getByteTotal();
IItemList<IAEItemStack> plan = AEApi.instance().storage().createItemList();
result.tree.getPlan( plan );
for (IAEItemStack out : plan)
bytesUsed = result.getByteTotal();
for (IAEItemStack out : plan)
{
IAEItemStack m = null;
IAEItemStack o = out.copy();
o.reset();
o.setStackSize( out.getStackSize() );
IAEItemStack p = out.copy();
p.reset();
p.setStackSize( out.getCountRequestable() );
IStorageGrid sg = getGrid().getCache( IStorageGrid.class );
IMEInventory<IAEItemStack> itemsg = sg.getItemInventory();
if ( c != null && result.isSimulation() )
{
IAEItemStack o = out.copy();
o.reset();
o.setStackSize( out.getStackSize() );
m = o.copy();
o = itemsg.extractItems( o, Actionable.SIMULATE, mySrc );
IAEItemStack p = out.copy();
p.reset();
p.setStackSize( out.getCountRequestable() );
if ( o.getStackSize() > 0 )
a.appendItem( o );
if ( p.getStackSize() > 0 )
b.appendItem( p );
}
for (Object g : this.crafters)
{
if ( g instanceof EntityPlayer )
if ( o == null )
{
NetworkHandler.instance.sendTo( a, (EntityPlayerMP) g );
NetworkHandler.instance.sendTo( b, (EntityPlayerMP) g );
o = m.copy();
o.setStackSize( 0 );
}
m.setStackSize( m.getStackSize() - o.getStackSize() );
}
}
catch (IOException e)
{
// :P
if ( o.getStackSize() > 0 )
a.appendItem( o );
if ( p.getStackSize() > 0 )
b.appendItem( p );
if ( c != null && m != null && m.getStackSize() > 0 )
c.appendItem( m );
}
// CraftingCache cc = getGrid().getCache( CraftingCache.class );
// cc.submitJob( result, null, getActionSrc() );
// AELog.info( "Job info is ready!" );
// this.isContainerValid = false;
for (Object g : this.crafters)
{
if ( g instanceof EntityPlayer )
{
NetworkHandler.instance.sendTo( a, (EntityPlayerMP) g );
NetworkHandler.instance.sendTo( b, (EntityPlayerMP) g );
if ( c != null )
NetworkHandler.instance.sendTo( c, (EntityPlayerMP) g );
}
}
}
catch (IOException e)
{
// :P
}
}
catch (Throwable e)
@ -118,6 +158,16 @@ public class ContainerCraftConfirm extends AEBaseContainer implements ICraftingH
verifyPermissions( SecurityPermissions.CRAFT, false );
}
public void startJob()
{
if ( result != null && simulation == false )
{
CraftingCache cc = getGrid().getCache( CraftingCache.class );
cc.submitJob( result, null, getActionSrc() );
this.isContainerValid = false;
}
}
@Override
public void onContainerClosed(EntityPlayer par1EntityPlayer)
{

View file

@ -32,7 +32,7 @@ public enum GuiText
OfSecondOutput, NoSecondOutput, RFTunnel, Stores, Next, SelectAmount, Lumen, Empty, ConfirmCrafting,
Stored, Crafting, Scheduled, CraftingStatus, Cancel, FromStorage, ToCraft, CraftingPlan, CalculatingWait, Start, Bytes, CraftingCPU, Automatic, CoProcessors;
Stored, Crafting, Scheduled, CraftingStatus, Cancel, FromStorage, ToCraft, CraftingPlan, CalculatingWait, Start, Bytes, CraftingCPU, Automatic, CoProcessors, Simulation, Missing;
String root;

View file

@ -26,7 +26,6 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.INetworkInfo;
import appeng.crafting.CraftingJob;
import appeng.me.cache.CraftingCache;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
@ -34,6 +33,7 @@ public class PacketCraftRequest extends AppEngPacket
{
final public IAEItemStack slotItem;
final public boolean heldShift;
final public static ExecutorService craftingPool;
static
@ -53,6 +53,7 @@ public class PacketCraftRequest extends AppEngPacket
// automatic.
public PacketCraftRequest(ByteBuf stream) throws IOException {
heldShift = stream.readBoolean();
slotItem = AEItemStack.loadItemStackFromPacket( stream );
}
@ -74,8 +75,6 @@ public class PacketCraftRequest extends AppEngPacket
if ( g == null )
return;
CraftingCache cc = g.getCache( CraftingCache.class );
try
{
CraftingJob cj = new CraftingJob( cca.getWorld(), cca, slotItem, Actionable.SIMULATE );
@ -89,6 +88,7 @@ public class PacketCraftRequest extends AppEngPacket
if ( player.openContainer instanceof ContainerCraftConfirm )
{
ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer;
ccc.autoStart = heldShift;
ccc.job = craftingPool.submit( cj, cj );
cca.detectAndSendChanges();
}
@ -103,13 +103,15 @@ public class PacketCraftRequest extends AppEngPacket
}
}
public PacketCraftRequest(ItemStack stack, int parseInt) throws IOException {
public PacketCraftRequest(ItemStack stack, int parseInt, boolean shift) throws IOException {
this.slotItem = AEApi.instance().storage().createItemStack( stack );
this.slotItem.setStackSize( parseInt );
this.heldShift = shift;
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeBoolean( shift );
slotItem.writeToPacket( data );
configureWrite( data );

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.ContainerCraftConfirm;
import appeng.container.implementations.ContainerCraftingCPU;
import appeng.container.implementations.ContainerLevelEmitter;
import appeng.container.implementations.ContainerPatternTerm;
@ -54,6 +55,12 @@ public class PacketValueConfig extends AppEngPacket
si.onWheel( is, Value.equals( "WheelUp" ) );
return;
}
else if ( Name.equals( "Terminal.Start" ) && c instanceof ContainerCraftConfirm )
{
ContainerCraftConfirm qk = (ContainerCraftConfirm) c;
qk.startJob();
return;
}
else if ( Name.equals( "TileCrafting.Cancel" ) && c instanceof ContainerCraftingCPU )
{
ContainerCraftingCPU qk = (ContainerCraftingCPU) c;

View file

@ -193,7 +193,7 @@ public class CraftingTreeNode
{
if ( missing > 0 )
job.addMissing( getStack( missing ) );
missing = 0;
// missing = 0;
job.addBytes( 8 + bytes );
@ -231,6 +231,13 @@ public class CraftingTreeNode
public void getPlan(IItemList<IAEItemStack> plan)
{
if ( missing > 0 )
{
IAEItemStack o = what.copy();
o.setStackSize( missing );
plan.add( o );
}
for (IAEItemStack i : used)
plan.add( i.copy() );