2013-12-27 23:59:59 +01:00
|
|
|
package appeng.client.gui.implementations;
|
|
|
|
|
2014-01-05 09:49:08 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2014-01-26 07:44:50 +01:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
2014-02-21 07:10:38 +01:00
|
|
|
|
|
|
|
import org.lwjgl.input.Mouse;
|
|
|
|
|
2014-01-05 09:49:08 +01:00
|
|
|
import appeng.api.config.FuzzyMode;
|
2014-02-21 07:10:38 +01:00
|
|
|
import appeng.api.config.LevelType;
|
2014-01-05 09:49:08 +01:00
|
|
|
import appeng.api.config.RedstoneMode;
|
|
|
|
import appeng.api.config.Settings;
|
|
|
|
import appeng.api.config.Upgrades;
|
2014-08-13 07:33:13 +02:00
|
|
|
import appeng.api.config.YesNo;
|
2014-01-05 09:49:08 +01:00
|
|
|
import appeng.client.gui.widgets.GuiImgButton;
|
2014-08-08 00:54:22 +02:00
|
|
|
import appeng.client.gui.widgets.GuiNumberBox;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.container.implementations.ContainerLevelEmitter;
|
2014-08-01 03:59:24 +02:00
|
|
|
import appeng.core.AEConfig;
|
2014-02-07 21:37:22 +01:00
|
|
|
import appeng.core.AELog;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.core.localization.GuiText;
|
2014-02-09 02:34:52 +01:00
|
|
|
import appeng.core.sync.network.NetworkHandler;
|
2014-02-21 07:10:38 +01:00
|
|
|
import appeng.core.sync.packets.PacketConfigButton;
|
2014-01-05 09:49:08 +01:00
|
|
|
import appeng.core.sync.packets.PacketValueConfig;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.parts.automation.PartLevelEmitter;
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
public class GuiLevelEmitter extends GuiUpgradeable
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2014-08-08 00:54:22 +02:00
|
|
|
GuiNumberBox level;
|
2014-01-05 09:49:08 +01:00
|
|
|
|
2014-01-26 07:44:50 +01:00
|
|
|
GuiButton plus1, plus10, plus100, plus1000;
|
|
|
|
GuiButton minus1, minus10, minus100, minus1000;
|
|
|
|
|
2014-02-21 07:10:38 +01:00
|
|
|
GuiImgButton levelMode;
|
2014-08-13 07:33:13 +02:00
|
|
|
GuiImgButton craftingMode;
|
2014-02-21 07:10:38 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public GuiLevelEmitter(InventoryPlayer inventoryPlayer, PartLevelEmitter te) {
|
|
|
|
super( new ContainerLevelEmitter( inventoryPlayer, te ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-05 09:49:08 +01:00
|
|
|
public void initGui()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-05 09:49:08 +01:00
|
|
|
super.initGui();
|
2014-01-26 07:44:50 +01:00
|
|
|
|
2014-08-08 00:54:22 +02:00
|
|
|
level = new GuiNumberBox( fontRendererObj, this.guiLeft + 24, this.guiTop + 43, 79, fontRendererObj.FONT_HEIGHT, Long.class );
|
2014-01-05 09:49:08 +01:00
|
|
|
level.setEnableBackgroundDrawing( false );
|
|
|
|
level.setMaxStringLength( 16 );
|
|
|
|
level.setTextColor( 0xFFFFFF );
|
|
|
|
level.setVisible( true );
|
|
|
|
level.setFocused( true );
|
|
|
|
((ContainerLevelEmitter) inventorySlots).setTextField( level );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-05 09:49:08 +01:00
|
|
|
protected void addButtons()
|
|
|
|
{
|
2014-02-21 07:10:38 +01:00
|
|
|
levelMode = new GuiImgButton( this.guiLeft - 18, guiTop + 8, Settings.LEVEL_TYPE, LevelType.ITEM_LEVEL );
|
|
|
|
redstoneMode = new GuiImgButton( this.guiLeft - 18, guiTop + 28, Settings.REDSTONE_EMITTER, RedstoneMode.LOW_SIGNAL );
|
|
|
|
fuzzyMode = new GuiImgButton( this.guiLeft - 18, guiTop + 48, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
2014-08-13 07:33:13 +02:00
|
|
|
craftingMode = new GuiImgButton( this.guiLeft - 18, guiTop + 48, Settings.CRAFT_VIA_REDSTONE, YesNo.NO );
|
2014-01-05 09:49:08 +01:00
|
|
|
|
2014-08-01 03:59:24 +02:00
|
|
|
int a = AEConfig.instance.levelByStackAmounts( 0 );
|
|
|
|
int b = AEConfig.instance.levelByStackAmounts( 1 );
|
|
|
|
int c = AEConfig.instance.levelByStackAmounts( 2 );
|
|
|
|
int d = AEConfig.instance.levelByStackAmounts( 3 );
|
2014-01-26 07:44:50 +01:00
|
|
|
|
2014-08-01 03:59:24 +02:00
|
|
|
buttonList.add( plus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 17, 22, 20, "+" + a ) );
|
|
|
|
buttonList.add( plus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 17, 28, 20, "+" + b ) );
|
|
|
|
buttonList.add( plus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 17, 32, 20, "+" + c ) );
|
|
|
|
buttonList.add( plus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 17, 38, 20, "+" + d ) );
|
|
|
|
|
|
|
|
buttonList.add( minus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 59, 22, 20, "-" + a ) );
|
|
|
|
buttonList.add( minus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 59, 28, 20, "-" + b ) );
|
|
|
|
buttonList.add( minus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 59, 32, 20, "-" + c ) );
|
|
|
|
buttonList.add( minus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 59, 38, 20, "-" + d ) );
|
2014-01-26 07:44:50 +01:00
|
|
|
|
2014-02-21 07:10:38 +01:00
|
|
|
buttonList.add( levelMode );
|
2014-01-05 09:49:08 +01:00
|
|
|
buttonList.add( redstoneMode );
|
|
|
|
buttonList.add( fuzzyMode );
|
2014-08-13 07:33:13 +02:00
|
|
|
buttonList.add( craftingMode );
|
2014-01-05 09:49:08 +01:00
|
|
|
}
|
|
|
|
|
2014-01-26 07:44:50 +01:00
|
|
|
@Override
|
|
|
|
protected void actionPerformed(GuiButton btn)
|
|
|
|
{
|
|
|
|
super.actionPerformed( btn );
|
|
|
|
|
2014-02-21 07:10:38 +01:00
|
|
|
boolean backwards = Mouse.isButtonDown( 1 );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2014-08-13 07:33:13 +02:00
|
|
|
if ( btn == craftingMode )
|
|
|
|
NetworkHandler.instance.sendToServer( new PacketConfigButton( craftingMode.getSetting(), backwards ) );
|
|
|
|
|
2014-02-21 07:10:38 +01:00
|
|
|
if ( btn == levelMode )
|
|
|
|
NetworkHandler.instance.sendToServer( new PacketConfigButton( levelMode.getSetting(), backwards ) );
|
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
{
|
|
|
|
AELog.error( e );
|
|
|
|
}
|
|
|
|
|
2014-08-01 03:59:24 +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-02-21 07:10:38 +01:00
|
|
|
private void addQty(long i)
|
2014-01-26 07:44:50 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
String Out = level.getText();
|
|
|
|
|
|
|
|
boolean Fixed = false;
|
|
|
|
while (Out.startsWith( "0" ) && Out.length() > 1)
|
|
|
|
{
|
|
|
|
Out = Out.substring( 1 );
|
|
|
|
Fixed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( Fixed )
|
|
|
|
level.setText( Out );
|
|
|
|
|
|
|
|
if ( Out.length() == 0 )
|
|
|
|
Out = "0";
|
|
|
|
|
|
|
|
long result = Long.parseLong( Out );
|
|
|
|
result += i;
|
|
|
|
if ( result < 0 )
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
level.setText( Out = Long.toString( result ) );
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
NetworkHandler.instance.sendToServer( new PacketValueConfig( "LevelEmitter.Value", Out ) );
|
2014-01-26 07:44:50 +01:00
|
|
|
}
|
2014-08-11 07:08:31 +02:00
|
|
|
catch (NumberFormatException e)
|
2014-08-08 00:54:22 +02:00
|
|
|
{
|
|
|
|
// nope..
|
|
|
|
level.setText( "0" );
|
|
|
|
}
|
2014-01-26 07:44:50 +01:00
|
|
|
catch (IOException e)
|
|
|
|
{
|
2014-02-07 21:37:22 +01:00
|
|
|
AELog.error( e );
|
2014-01-26 07:44:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-21 02:10:27 +02:00
|
|
|
protected void handleButtonVisibility()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-08-13 07:33:13 +02:00
|
|
|
craftingMode.setVisibility( bc.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 );
|
2014-01-05 09:49:08 +01:00
|
|
|
fuzzyMode.setVisibility( bc.getInstalledUpgrades( Upgrades.FUZZY ) > 0 );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-05 09:49:08 +01:00
|
|
|
@Override
|
|
|
|
protected void keyTyped(char character, int key)
|
|
|
|
{
|
|
|
|
if ( !this.checkHotbarKeys( key ) )
|
|
|
|
{
|
|
|
|
if ( (key == 211 || key == 205 || key == 203 || key == 14 || Character.isDigit( character )) && level.textboxKeyTyped( character, key ) )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
String Out = level.getText();
|
|
|
|
|
|
|
|
boolean Fixed = false;
|
|
|
|
while (Out.startsWith( "0" ) && Out.length() > 1)
|
|
|
|
{
|
|
|
|
Out = Out.substring( 1 );
|
|
|
|
Fixed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( Fixed )
|
|
|
|
level.setText( Out );
|
|
|
|
|
|
|
|
if ( Out.length() == 0 )
|
|
|
|
Out = "0";
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
NetworkHandler.instance.sendToServer( new PacketValueConfig( "LevelEmitter.Value", Out ) );
|
2014-01-05 09:49:08 +01:00
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
{
|
2014-02-07 21:37:22 +01:00
|
|
|
AELog.error( e );
|
2014-01-05 09:49:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
super.keyTyped( character, key );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-21 07:10:38 +01:00
|
|
|
@Override
|
|
|
|
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
|
|
|
|
{
|
2014-08-11 07:08:31 +02:00
|
|
|
boolean notCraftingMode = bc.getInstalledUpgrades( Upgrades.CRAFTING ) == 0;
|
|
|
|
|
|
|
|
// configure enabled status...
|
|
|
|
level.setEnabled( notCraftingMode );
|
|
|
|
plus1.enabled = notCraftingMode;
|
|
|
|
plus10.enabled = notCraftingMode;
|
|
|
|
plus100.enabled = notCraftingMode;
|
|
|
|
plus1000.enabled = notCraftingMode;
|
|
|
|
minus1.enabled = notCraftingMode;
|
|
|
|
minus10.enabled = notCraftingMode;
|
|
|
|
minus100.enabled = notCraftingMode;
|
|
|
|
minus1000.enabled = notCraftingMode;
|
|
|
|
levelMode.enabled = notCraftingMode;
|
|
|
|
redstoneMode.enabled = notCraftingMode;
|
|
|
|
|
2014-02-21 07:10:38 +01:00
|
|
|
super.drawFG( offsetX, offsetY, mouseX, mouseY );
|
|
|
|
|
2014-08-13 07:33:13 +02:00
|
|
|
if ( craftingMode != null )
|
|
|
|
craftingMode.set( ((ContainerLevelEmitter) cvb).cmType );
|
|
|
|
|
2014-02-21 07:10:38 +01:00
|
|
|
if ( levelMode != null )
|
|
|
|
levelMode.set( ((ContainerLevelEmitter) cvb).lvType );
|
|
|
|
}
|
|
|
|
|
2014-01-05 09:49:08 +01:00
|
|
|
@Override
|
|
|
|
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY)
|
|
|
|
{
|
|
|
|
super.drawBG( offsetX, offsetY, mouseX, mouseY );
|
|
|
|
level.drawTextBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String getBackground()
|
|
|
|
{
|
|
|
|
return "guis/lvlemitter.png";
|
|
|
|
}
|
|
|
|
|
|
|
|
protected GuiText getName()
|
|
|
|
{
|
|
|
|
return GuiText.LevelEmitter;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|