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
+121 -3
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() );