2014-05-24 06:20:56 +02:00
|
|
|
package appeng.client.gui.implementations;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.api.storage.ITerminalHost;
|
|
|
|
import appeng.client.gui.AEBaseGui;
|
2014-08-08 00:54:22 +02:00
|
|
|
import appeng.client.gui.widgets.GuiNumberBox;
|
2014-05-24 06:20:56 +02:00
|
|
|
import appeng.client.gui.widgets.GuiTabButton;
|
|
|
|
import appeng.container.AEBaseContainer;
|
|
|
|
import appeng.container.implementations.ContainerCraftAmount;
|
2014-07-31 19:24:08 +02:00
|
|
|
import appeng.core.AEConfig;
|
2014-05-24 06:20:56 +02:00
|
|
|
import appeng.core.AELog;
|
|
|
|
import appeng.core.localization.GuiText;
|
|
|
|
import appeng.core.sync.GuiBridge;
|
|
|
|
import appeng.core.sync.network.NetworkHandler;
|
2014-06-16 07:48:43 +02:00
|
|
|
import appeng.core.sync.packets.PacketCraftRequest;
|
2014-05-24 06:20:56 +02:00
|
|
|
import appeng.core.sync.packets.PacketSwitchGuis;
|
|
|
|
import appeng.helpers.WirelessTerminalGuiObject;
|
|
|
|
import appeng.parts.reporting.PartCraftingTerminal;
|
|
|
|
import appeng.parts.reporting.PartPatternTerminal;
|
|
|
|
import appeng.parts.reporting.PartTerminal;
|
|
|
|
|
|
|
|
public class GuiCraftAmount extends AEBaseGui
|
|
|
|
{
|
|
|
|
|
2014-08-08 00:54:22 +02:00
|
|
|
GuiNumberBox amountToCraft;
|
2014-05-24 06:20:56 +02:00
|
|
|
GuiTabButton originalGuiBtn;
|
|
|
|
|
2014-05-24 23:16:22 +02:00
|
|
|
GuiButton next;
|
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GuiButton plus1, plus10, plus100, plus1000;
|
|
|
|
GuiButton minus1, minus10, minus100, minus1000;
|
|
|
|
|
|
|
|
GuiBridge OriginalGui;
|
|
|
|
|
|
|
|
public GuiCraftAmount(InventoryPlayer inventoryPlayer, ITerminalHost te) {
|
|
|
|
super( new ContainerCraftAmount( inventoryPlayer, te ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initGui()
|
|
|
|
{
|
|
|
|
super.initGui();
|
|
|
|
|
2014-07-31 19:24:08 +02:00
|
|
|
int a = AEConfig.instance.craftItemsByStackAmounts( 0 );
|
|
|
|
int b = AEConfig.instance.craftItemsByStackAmounts( 1 );
|
|
|
|
int c = AEConfig.instance.craftItemsByStackAmounts( 2 );
|
|
|
|
int d = AEConfig.instance.craftItemsByStackAmounts( 3 );
|
|
|
|
|
|
|
|
buttonList.add( plus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 26, 22, 20, "+" + a ) );
|
|
|
|
buttonList.add( plus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 26, 28, 20, "+" + b ) );
|
|
|
|
buttonList.add( plus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 26, 32, 20, "+" + c ) );
|
|
|
|
buttonList.add( plus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 26, 38, 20, "+" + d ) );
|
2014-05-24 23:16:22 +02:00
|
|
|
|
2014-07-31 19:24:08 +02:00
|
|
|
buttonList.add( minus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 75, 22, 20, "-" + a ) );
|
|
|
|
buttonList.add( minus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 75, 28, 20, "-" + b ) );
|
|
|
|
buttonList.add( minus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 75, 32, 20, "-" + c ) );
|
|
|
|
buttonList.add( minus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 75, 38, 20, "-" + d ) );
|
2014-05-24 06:20:56 +02:00
|
|
|
|
2014-07-31 19:24:08 +02:00
|
|
|
buttonList.add( next = new GuiButton( 0, this.guiLeft + 128, this.guiTop + 51, 38, 20, GuiText.Next.getLocal() ) );
|
2014-05-24 06:20:56 +02:00
|
|
|
|
|
|
|
ItemStack myIcon = null;
|
|
|
|
Object target = ((AEBaseContainer) inventorySlots).getTarget();
|
|
|
|
|
|
|
|
if ( target instanceof WirelessTerminalGuiObject )
|
|
|
|
{
|
|
|
|
myIcon = AEApi.instance().items().itemWirelessTerminal.stack( 1 );
|
|
|
|
OriginalGui = GuiBridge.GUI_WIRELESS_TERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( target instanceof PartTerminal )
|
|
|
|
{
|
|
|
|
myIcon = AEApi.instance().parts().partTerminal.stack( 1 );
|
|
|
|
OriginalGui = GuiBridge.GUI_ME;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( target instanceof PartCraftingTerminal )
|
|
|
|
{
|
|
|
|
myIcon = AEApi.instance().parts().partCraftingTerminal.stack( 1 );
|
|
|
|
OriginalGui = GuiBridge.GUI_CRAFTING_TERMINAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( target instanceof PartPatternTerminal )
|
|
|
|
{
|
|
|
|
myIcon = AEApi.instance().parts().partPatternTerminal.stack( 1 );
|
|
|
|
OriginalGui = GuiBridge.GUI_PATTERN_TERMINAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( OriginalGui != null )
|
|
|
|
buttonList.add( originalGuiBtn = new GuiTabButton( this.guiLeft + 154, this.guiTop, myIcon, myIcon.getDisplayName(), itemRender ) );
|
|
|
|
|
2014-08-08 00:54:22 +02:00
|
|
|
amountToCraft = new GuiNumberBox( fontRendererObj, this.guiLeft + 62, this.guiTop + 57, 59, fontRendererObj.FONT_HEIGHT, Integer.class );
|
2014-05-24 06:20:56 +02:00
|
|
|
amountToCraft.setEnableBackgroundDrawing( false );
|
|
|
|
amountToCraft.setMaxStringLength( 16 );
|
|
|
|
amountToCraft.setTextColor( 0xFFFFFF );
|
|
|
|
amountToCraft.setVisible( true );
|
|
|
|
amountToCraft.setFocused( true );
|
2014-05-24 23:16:22 +02:00
|
|
|
amountToCraft.setText( "1" );
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void actionPerformed(GuiButton btn)
|
|
|
|
{
|
|
|
|
super.actionPerformed( btn );
|
|
|
|
|
2014-07-31 19:24:08 +02:00
|
|
|
try
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
2014-08-13 07:25:21 +02:00
|
|
|
|
2014-07-31 19:24:08 +02:00
|
|
|
if ( btn == originalGuiBtn )
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
|
|
|
NetworkHandler.instance.sendToServer( new PacketSwitchGuis( OriginalGui ) );
|
|
|
|
}
|
|
|
|
|
2014-07-31 19:24:08 +02:00
|
|
|
if ( btn == next )
|
2014-06-16 07:48:43 +02:00
|
|
|
{
|
2014-08-21 06:02:31 +02:00
|
|
|
NetworkHandler.instance.sendToServer( new PacketCraftRequest( Integer.parseInt( this.amountToCraft.getText() ), isShiftKeyDown() ) );
|
2014-06-16 07:48:43 +02:00
|
|
|
}
|
2014-07-31 19:24:08 +02:00
|
|
|
|
|
|
|
}
|
2014-08-13 07:25:21 +02:00
|
|
|
catch (NumberFormatException e)
|
2014-08-08 00:54:22 +02:00
|
|
|
{
|
|
|
|
// nope..
|
|
|
|
amountToCraft.setText( "1" );
|
|
|
|
}
|
2014-07-31 19:24:08 +02:00
|
|
|
catch (IOException e)
|
|
|
|
{
|
|
|
|
AELog.error( e );
|
2014-06-16 07:48:43 +02:00
|
|
|
}
|
|
|
|
|
2014-07-31 19:24:08 +02:00
|
|
|
boolean isPlus = btn == plus1 || btn == plus10 || btn == plus100 || btn == plus1000;
|
|
|
|
boolean isMinus = btn == minus1 || btn == minus10 || btn == minus100 || btn == minus1000;
|
|
|
|
|
|
|
|
if ( isPlus || isMinus )
|
|
|
|
addQty( getQty( btn ) );
|
|
|
|
}
|
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
private void addQty(int i)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
String Out = amountToCraft.getText();
|
|
|
|
|
|
|
|
boolean Fixed = false;
|
|
|
|
while (Out.startsWith( "0" ) && Out.length() > 1)
|
|
|
|
{
|
|
|
|
Out = Out.substring( 1 );
|
|
|
|
Fixed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( Fixed )
|
|
|
|
amountToCraft.setText( Out );
|
|
|
|
|
|
|
|
if ( Out.length() == 0 )
|
|
|
|
Out = "0";
|
|
|
|
|
2014-08-08 00:54:22 +02:00
|
|
|
long result = Integer.parseInt( Out );
|
2014-05-24 23:16:22 +02:00
|
|
|
|
|
|
|
if ( result == 1 && i > 1 )
|
|
|
|
result = 0;
|
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
result += i;
|
2014-05-24 23:16:22 +02:00
|
|
|
if ( result < 1 )
|
|
|
|
result = 1;
|
2014-08-13 07:25:21 +02:00
|
|
|
|
2014-08-08 00:54:22 +02:00
|
|
|
Out = Long.toString( result );
|
|
|
|
Integer.parseInt( Out );
|
|
|
|
amountToCraft.setText( Out );
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
2014-05-24 23:16:22 +02:00
|
|
|
catch (NumberFormatException e)
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
2014-05-24 23:16:22 +02:00
|
|
|
// :P
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void keyTyped(char character, int key)
|
|
|
|
{
|
|
|
|
if ( !this.checkHotbarKeys( key ) )
|
|
|
|
{
|
2014-06-29 11:06:07 +02:00
|
|
|
if ( key == 28 )
|
|
|
|
{
|
|
|
|
actionPerformed( next );
|
|
|
|
}
|
2014-05-24 06:20:56 +02:00
|
|
|
if ( (key == 211 || key == 205 || key == 203 || key == 14 || character == '-' || Character.isDigit( character ))
|
|
|
|
&& amountToCraft.textboxKeyTyped( character, key ) )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
String Out = amountToCraft.getText();
|
|
|
|
|
|
|
|
boolean Fixed = false;
|
|
|
|
while (Out.startsWith( "0" ) && Out.length() > 1)
|
|
|
|
{
|
|
|
|
Out = Out.substring( 1 );
|
|
|
|
Fixed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( Fixed )
|
|
|
|
amountToCraft.setText( Out );
|
|
|
|
|
|
|
|
if ( Out.length() == 0 )
|
|
|
|
Out = "0";
|
|
|
|
|
2014-05-24 23:16:22 +02:00
|
|
|
long result = Long.parseLong( Out );
|
|
|
|
if ( result < 0 )
|
|
|
|
{
|
|
|
|
amountToCraft.setText( "1" );
|
|
|
|
}
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
2014-05-24 23:16:22 +02:00
|
|
|
catch (NumberFormatException e)
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
2014-05-24 23:16:22 +02:00
|
|
|
// :P
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
super.keyTyped( character, key );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY)
|
|
|
|
{
|
2014-06-29 11:06:07 +02:00
|
|
|
next.displayString = isShiftKeyDown() ? GuiText.Start.getLocal() : GuiText.Next.getLocal();
|
|
|
|
|
2014-05-24 23:16:22 +02:00
|
|
|
bindTexture( "guis/craftAmt.png" );
|
2014-05-24 06:20:56 +02:00
|
|
|
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize );
|
|
|
|
|
2014-05-24 23:16:22 +02:00
|
|
|
try
|
|
|
|
{
|
2014-05-26 00:43:17 +02:00
|
|
|
Long.parseLong( amountToCraft.getText() );
|
2014-05-24 23:16:22 +02:00
|
|
|
next.enabled = amountToCraft.getText().length() > 0;
|
|
|
|
}
|
|
|
|
catch (NumberFormatException e)
|
|
|
|
{
|
|
|
|
next.enabled = false;
|
|
|
|
}
|
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
amountToCraft.drawTextBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String getBackground()
|
|
|
|
{
|
2014-05-24 23:16:22 +02:00
|
|
|
return "guis/craftAmt.png";
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
|
|
|
|
{
|
2014-05-24 23:16:22 +02:00
|
|
|
fontRendererObj.drawString( GuiText.SelectAmount.getLocal(), 8, 6, 4210752 );
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
|
|
|
}
|