2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
package appeng.client.gui.implementations;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
import appeng.api.AEApi;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.api.definitions.IDefinitions;
|
|
|
|
import appeng.api.definitions.IParts;
|
2014-05-24 06:20:56 +02:00
|
|
|
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.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;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.helpers.Reflected;
|
2014-05-24 06:20:56 +02:00
|
|
|
import appeng.helpers.WirelessTerminalGuiObject;
|
|
|
|
import appeng.parts.reporting.PartCraftingTerminal;
|
|
|
|
import appeng.parts.reporting.PartPatternTerminal;
|
|
|
|
import appeng.parts.reporting.PartTerminal;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
public class GuiCraftAmount extends AEBaseGui
|
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
private GuiNumberBox amountToCraft;
|
|
|
|
private GuiTabButton originalGuiBtn;
|
2014-05-24 06:20:56 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
private GuiButton next;
|
2014-05-24 06:20:56 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
private GuiButton plus1;
|
|
|
|
private GuiButton plus10;
|
|
|
|
private GuiButton plus100;
|
|
|
|
private GuiButton plus1000;
|
|
|
|
private GuiButton minus1;
|
|
|
|
private GuiButton minus10;
|
|
|
|
private GuiButton minus100;
|
|
|
|
private GuiButton minus1000;
|
2014-05-24 23:16:22 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
private GuiBridge originalGui;
|
2014-05-24 06:20:56 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
@Reflected
|
2015-04-03 08:54:31 +02:00
|
|
|
public GuiCraftAmount( InventoryPlayer inventoryPlayer, ITerminalHost te )
|
|
|
|
{
|
2014-05-24 06:20:56 +02:00
|
|
|
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 );
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.buttonList.add( this.plus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 26, 22, 20, "+" + a ) );
|
|
|
|
this.buttonList.add( this.plus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 26, 28, 20, "+" + b ) );
|
|
|
|
this.buttonList.add( this.plus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 26, 32, 20, "+" + c ) );
|
|
|
|
this.buttonList.add( this.plus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 26, 38, 20, "+" + d ) );
|
2014-05-24 23:16:22 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.buttonList.add( this.minus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 75, 22, 20, "-" + a ) );
|
|
|
|
this.buttonList.add( this.minus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 75, 28, 20, "-" + b ) );
|
|
|
|
this.buttonList.add( this.minus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 75, 32, 20, "-" + c ) );
|
|
|
|
this.buttonList.add( this.minus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 75, 38, 20, "-" + d ) );
|
2014-05-24 06:20:56 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.buttonList.add( this.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;
|
2015-04-03 08:54:31 +02:00
|
|
|
Object target = ( (AEBaseContainer) this.inventorySlots ).getTarget();
|
2015-01-03 02:53:14 +01:00
|
|
|
final IDefinitions definitions = AEApi.instance().definitions();
|
|
|
|
final IParts parts = definitions.parts();
|
2014-05-24 06:20:56 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( target instanceof WirelessTerminalGuiObject )
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack wirelessTerminalStack : definitions.items().wirelessTerminal().maybeStack( 1 ).asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
myIcon = wirelessTerminalStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.originalGui = GuiBridge.GUI_WIRELESS_TERM;
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( target instanceof PartTerminal )
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack stack : parts.terminal().maybeStack( 1 ).asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
myIcon = stack;
|
|
|
|
}
|
|
|
|
this.originalGui = GuiBridge.GUI_ME;
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( target instanceof PartCraftingTerminal )
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack stack : parts.craftingTerminal().maybeStack( 1 ).asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
myIcon = stack;
|
|
|
|
}
|
|
|
|
this.originalGui = GuiBridge.GUI_CRAFTING_TERMINAL;
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( target instanceof PartPatternTerminal )
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack stack : parts.patternTerminal().maybeStack( 1 ).asSet() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
myIcon = stack;
|
|
|
|
}
|
|
|
|
this.originalGui = GuiBridge.GUI_PATTERN_TERMINAL;
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.originalGui != null && myIcon != null )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.buttonList.add( this.originalGuiBtn = new GuiTabButton( this.guiLeft + 154, this.guiTop, myIcon, myIcon.getDisplayName(), itemRender ) );
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2014-05-24 06:20:56 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.amountToCraft = new GuiNumberBox( this.fontRendererObj, this.guiLeft + 62, this.guiTop + 57, 59, this.fontRendererObj.FONT_HEIGHT, Integer.class );
|
|
|
|
this.amountToCraft.setEnableBackgroundDrawing( false );
|
|
|
|
this.amountToCraft.setMaxStringLength( 16 );
|
|
|
|
this.amountToCraft.setTextColor( 0xFFFFFF );
|
|
|
|
this.amountToCraft.setVisible( true );
|
|
|
|
this.amountToCraft.setFocused( true );
|
|
|
|
this.amountToCraft.setText( "1" );
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void drawFG( int offsetX, int offsetY, int mouseX, int mouseY )
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.fontRendererObj.drawString( GuiText.SelectAmount.getLocal(), 8, 6, 4210752 );
|
2014-07-31 19:24:08 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public void drawBG( int offsetX, int offsetY, int mouseX, int mouseY )
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.next.displayString = isShiftKeyDown() ? GuiText.Start.getLocal() : GuiText.Next.getLocal();
|
2014-05-24 23:16:22 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
this.bindTexture( "guis/craftAmt.png" );
|
|
|
|
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize );
|
2014-08-13 07:25:21 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Long.parseLong( this.amountToCraft.getText() );
|
|
|
|
this.next.enabled = this.amountToCraft.getText().length() > 0;
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( NumberFormatException e )
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.next.enabled = false;
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
this.amountToCraft.drawTextBox();
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
protected void keyTyped( char character, int key )
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !this.checkHotbarKeys( key ) )
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( key == 28 )
|
2014-06-29 11:06:07 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.actionPerformed( this.next );
|
2014-06-29 11:06:07 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ( key == 211 || key == 205 || key == 203 || key == 14 || character == '-' || Character.isDigit( character ) ) && this.amountToCraft.textboxKeyTyped( character, key ) )
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
String out = this.amountToCraft.getText();
|
2014-05-24 06:20:56 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
boolean fixed = false;
|
2015-04-03 08:54:31 +02:00
|
|
|
while( out.startsWith( "0" ) && out.length() > 1 )
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
out = out.substring( 1 );
|
|
|
|
fixed = true;
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( fixed )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.amountToCraft.setText( out );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-05-24 06:20:56 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( out.length() == 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
out = "0";
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-05-24 06:20:56 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
long result = Long.parseLong( out );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( result < 0 )
|
2014-05-24 23:16:22 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.amountToCraft.setText( "1" );
|
2014-05-24 23:16:22 +02:00
|
|
|
}
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +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
|
2015-04-03 08:54:31 +02:00
|
|
|
protected void actionPerformed( GuiButton btn )
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
super.actionPerformed( btn );
|
2014-05-24 06:20:56 +02:00
|
|
|
|
2014-05-24 23:16:22 +02:00
|
|
|
try
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
if( btn == this.originalGuiBtn )
|
|
|
|
{
|
|
|
|
NetworkHandler.instance.sendToServer( new PacketSwitchGuis( this.originalGui ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( btn == this.next )
|
|
|
|
{
|
|
|
|
NetworkHandler.instance.sendToServer( new PacketCraftRequest( Integer.parseInt( this.amountToCraft.getText() ), isShiftKeyDown() ) );
|
|
|
|
}
|
2014-05-24 23:16:22 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( NumberFormatException e )
|
2014-05-24 23:16:22 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
// nope..
|
|
|
|
this.amountToCraft.setText( "1" );
|
2014-05-24 23:16:22 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
boolean isPlus = btn == this.plus1 || btn == this.plus10 || btn == this.plus100 || btn == this.plus1000;
|
|
|
|
boolean isMinus = btn == this.minus1 || btn == this.minus10 || btn == this.minus100 || btn == this.minus1000;
|
|
|
|
|
|
|
|
if( isPlus || isMinus )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.addQty( this.getQty( btn ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private void addQty( int i )
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
String out = this.amountToCraft.getText();
|
|
|
|
|
|
|
|
boolean fixed = false;
|
|
|
|
while( out.startsWith( "0" ) && out.length() > 1 )
|
|
|
|
{
|
|
|
|
out = out.substring( 1 );
|
|
|
|
fixed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( fixed )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.amountToCraft.setText( out );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
if( out.length() == 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
out = "0";
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
long result = Integer.parseInt( out );
|
|
|
|
|
|
|
|
if( result == 1 && i > 1 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
result = 0;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
result += i;
|
|
|
|
if( result < 1 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
result = 1;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
out = Long.toString( result );
|
|
|
|
Integer.parseInt( out );
|
|
|
|
this.amountToCraft.setText( out );
|
|
|
|
}
|
|
|
|
catch( NumberFormatException e )
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
protected String getBackground()
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return "guis/craftAmt.png";
|
2014-05-24 06:20:56 +02:00
|
|
|
}
|
|
|
|
}
|