Applied-Energistics-2-tiler.../src/main/java/appeng/client/gui/implementations/GuiLevelEmitter.java

282 lines
8.3 KiB
Java
Raw Normal View History

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