Applied-Energistics-2-tiler.../client/gui/implementations/GuiUpgradeable.java

139 lines
3.5 KiB
Java
Raw Normal View History

2013-12-30 06:56:43 +01:00
package appeng.client.gui.implementations;
import java.io.IOException;
import net.minecraft.client.gui.GuiButton;
2013-12-30 06:56:43 +01:00
import net.minecraft.entity.player.InventoryPlayer;
2014-01-05 09:48:20 +01:00
import org.lwjgl.input.Mouse;
import appeng.api.config.FuzzyMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
2014-01-23 20:02:48 +01:00
import appeng.api.implementations.IUpgradeableHost;
2013-12-30 06:56:43 +01:00
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.widgets.GuiImgButton;
2014-01-20 17:41:37 +01:00
import appeng.container.implementations.ContainerUpgradeable;
import appeng.core.AELog;
2013-12-30 06:56:43 +01:00
import appeng.core.localization.GuiText;
2014-02-09 02:34:52 +01:00
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketConfigButton;
import appeng.parts.automation.PartImportBus;
2013-12-30 06:56:43 +01:00
2014-01-20 17:41:37 +01:00
public class GuiUpgradeable extends AEBaseGui
2013-12-30 06:56:43 +01:00
{
2014-01-20 17:41:37 +01:00
ContainerUpgradeable cvb;
2014-01-23 20:02:48 +01:00
IUpgradeableHost bc;
GuiImgButton redstoneMode;
GuiImgButton fuzzyMode;
2014-01-23 20:02:48 +01:00
public GuiUpgradeable(InventoryPlayer inventoryPlayer, IUpgradeableHost te) {
2014-01-20 17:41:37 +01:00
this( new ContainerUpgradeable( inventoryPlayer, te ) );
2014-01-05 09:48:20 +01:00
}
2014-01-20 17:41:37 +01:00
public GuiUpgradeable(ContainerUpgradeable te) {
2014-01-05 09:48:20 +01:00
super( te );
2014-01-20 17:41:37 +01:00
cvb = (ContainerUpgradeable) te;
2014-01-05 09:48:20 +01:00
2014-01-23 20:02:48 +01:00
bc = (IUpgradeableHost) te.getTarget();
2013-12-30 06:56:43 +01:00
this.xSize = hasToolbox() ? 246 : 211;
this.ySize = 184;
}
@Override
public void initGui()
{
super.initGui();
2014-01-05 09:48:20 +01:00
addButtons();
}
2014-01-05 09:48:20 +01:00
protected void addButtons()
{
2014-01-26 07:44:50 +01:00
redstoneMode = new GuiImgButton( this.guiLeft - 18, guiTop + 8, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
fuzzyMode = new GuiImgButton( this.guiLeft - 18, guiTop + 28, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
buttonList.add( redstoneMode );
buttonList.add( fuzzyMode );
}
@Override
protected void actionPerformed(GuiButton btn)
{
super.actionPerformed( btn );
2014-01-05 09:48:20 +01:00
boolean backwards = Mouse.isButtonDown( 1 );
try
{
if ( btn == redstoneMode )
2014-02-09 02:34:52 +01:00
NetworkHandler.instance.sendToServer( new PacketConfigButton( redstoneMode.getSetting(), backwards ) );
if ( btn == fuzzyMode )
2014-02-09 02:34:52 +01:00
NetworkHandler.instance.sendToServer( new PacketConfigButton( fuzzyMode.getSetting(), backwards ) );
}
catch (IOException e)
{
AELog.error( e );
}
}
2014-01-20 17:41:37 +01:00
protected boolean hasToolbox()
2013-12-30 06:56:43 +01:00
{
2014-01-20 17:41:37 +01:00
return ((ContainerUpgradeable) inventorySlots).hasToolbox();
2013-12-30 06:56:43 +01:00
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY)
{
2014-01-05 09:48:20 +01:00
handleButtonVisiblity();
2014-01-05 09:48:20 +01:00
bindTexture( getBackground() );
2014-01-20 17:41:37 +01:00
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, 211 - 34, ySize );
if ( drawUpgrades() )
2014-01-23 17:28:12 +01:00
this.drawTexturedModalRect( offsetX + 177, offsetY, 177, 0, 35, 14 + cvb.availableUpgrades() * 18 );
2013-12-30 06:56:43 +01:00
if ( hasToolbox() )
2014-01-20 17:41:37 +01:00
this.drawTexturedModalRect( offsetX + 178, offsetY + ySize - 90, 178, ySize - 90, 68, 68 );
}
protected boolean drawUpgrades()
{
return true;
2013-12-30 06:56:43 +01:00
}
2014-01-05 09:48:20 +01:00
protected String getBackground()
{
return "guis/bus.png";
}
protected void handleButtonVisiblity()
{
2014-01-20 17:41:37 +01:00
if ( redstoneMode != null )
redstoneMode.setVisibility( bc.getInstalledUpgrades( Upgrades.REDSTONE ) > 0 );
if ( fuzzyMode != null )
fuzzyMode.setVisibility( bc.getInstalledUpgrades( Upgrades.FUZZY ) > 0 );
2014-01-05 09:48:20 +01:00
}
2013-12-30 06:56:43 +01:00
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
{
fontRendererObj.drawString( getGuiDisplayName( getName().getLocal() ), 8, 6, 4210752 );
2014-02-09 02:34:52 +01:00
fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 );
2014-01-06 07:54:25 +01:00
if ( redstoneMode != null )
redstoneMode.set( cvb.rsMode );
if ( fuzzyMode != null )
fuzzyMode.set( cvb.fzMode );
2013-12-30 06:56:43 +01:00
}
2014-01-05 09:48:20 +01:00
protected GuiText getName()
{
return bc instanceof PartImportBus ? GuiText.ImportBus : GuiText.ExportBus;
}
2013-12-30 06:56:43 +01:00
}