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

202 lines
5.9 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>.
*/
2013-12-30 06:56:43 +01:00
package appeng.client.gui.implementations;
2014-12-29 21:59:05 +01:00
import org.lwjgl.input.Mouse;
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 appeng.api.config.FuzzyMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SchedulingMode;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.config.YesNo;
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;
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.PartExportBus;
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
{
protected final ContainerUpgradeable cvb;
protected final IUpgradeableHost bc;
protected GuiImgButton redstoneMode;
protected GuiImgButton fuzzyMode;
protected GuiImgButton craftMode;
protected GuiImgButton schedulingMode;
public GuiUpgradeable( final InventoryPlayer inventoryPlayer, final IUpgradeableHost te )
{
2014-01-20 17:41:37 +01:00
this( new ContainerUpgradeable( inventoryPlayer, te ) );
2014-01-05 09:48:20 +01:00
}
public GuiUpgradeable( final ContainerUpgradeable te )
{
2014-01-05 09:48:20 +01:00
super( te );
2014-12-29 15:13:47 +01:00
this.cvb = te;
2014-01-05 09:48:20 +01:00
2014-12-29 15:13:47 +01:00
this.bc = (IUpgradeableHost) te.getTarget();
this.xSize = this.hasToolbox() ? 246 : 211;
2013-12-30 06:56:43 +01:00
this.ySize = 184;
}
protected boolean hasToolbox()
{
return ( (ContainerUpgradeable) this.inventorySlots ).hasToolbox();
}
@Override
public void initGui()
{
super.initGui();
2014-12-29 15:13:47 +01:00
this.addButtons();
2014-01-05 09:48:20 +01:00
}
2014-01-05 09:48:20 +01:00
protected void addButtons()
{
2014-12-29 15:13:47 +01:00
this.redstoneMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
this.craftMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 48, Settings.CRAFT_ONLY, YesNo.NO );
this.schedulingMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 68, Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT );
2014-12-29 15:13:47 +01:00
this.buttonList.add( this.craftMode );
this.buttonList.add( this.redstoneMode );
this.buttonList.add( this.fuzzyMode );
this.buttonList.add( this.schedulingMode );
}
@Override
public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
{
this.fontRendererObj.drawString( this.getGuiDisplayName( this.getName().getLocal() ), 8, 6, 4210752 );
this.fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752 );
if( this.redstoneMode != null )
2015-04-29 02:30:53 +02:00
{
this.redstoneMode.set( this.cvb.getRedStoneMode() );
2015-04-29 02:30:53 +02:00
}
if( this.fuzzyMode != null )
2015-04-29 02:30:53 +02:00
{
this.fuzzyMode.set( this.cvb.getFuzzyMode() );
2015-04-29 02:30:53 +02:00
}
if( this.craftMode != null )
2015-04-29 02:30:53 +02:00
{
this.craftMode.set( this.cvb.getCraftingMode() );
2015-04-29 02:30:53 +02:00
}
if( this.schedulingMode != null )
{
this.schedulingMode.set( this.cvb.getSchedulingMode() );
}
2013-12-30 06:56:43 +01:00
}
@Override
public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
2013-12-30 06:56:43 +01:00
{
2014-12-29 15:13:47 +01:00
this.handleButtonVisibility();
this.bindTexture( this.getBackground() );
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, 211 - 34, this.ySize );
if( this.drawUpgrades() )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.drawTexturedModalRect( offsetX + 177, offsetY, 177, 0, 35, 14 + this.cvb.availableUpgrades() * 18 );
2015-04-29 02:30:53 +02:00
}
if( this.hasToolbox() )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.drawTexturedModalRect( offsetX + 178, offsetY + this.ySize - 90, 178, this.ySize - 90, 68, 68 );
2015-04-29 02:30:53 +02:00
}
2014-01-20 17:41:37 +01:00
}
protected void handleButtonVisibility()
2014-01-20 17:41:37 +01:00
{
if( this.redstoneMode != null )
2015-04-29 02:30:53 +02:00
{
this.redstoneMode.setVisibility( this.bc.getInstalledUpgrades( Upgrades.REDSTONE ) > 0 );
2015-04-29 02:30:53 +02:00
}
if( this.fuzzyMode != null )
2015-04-29 02:30:53 +02:00
{
this.fuzzyMode.setVisibility( this.bc.getInstalledUpgrades( Upgrades.FUZZY ) > 0 );
2015-04-29 02:30:53 +02:00
}
if( this.craftMode != null )
2015-04-29 02:30:53 +02:00
{
this.craftMode.setVisibility( this.bc.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 );
2015-04-29 02:30:53 +02:00
}
if( this.schedulingMode != null )
{
this.schedulingMode.setVisibility(this.bc.getInstalledUpgrades( Upgrades.CAPACITY ) > 0 && this.bc instanceof PartExportBus );
}
2013-12-30 06:56:43 +01:00
}
2014-01-05 09:48:20 +01:00
protected String getBackground()
{
return "guis/bus.png";
}
protected boolean drawUpgrades()
2014-01-05 09:48:20 +01:00
{
return true;
}
protected GuiText getName()
{
return this.bc instanceof PartImportBus ? GuiText.ImportBus : GuiText.ExportBus;
2014-01-05 09:48:20 +01:00
}
2013-12-30 06:56:43 +01:00
@Override
protected void actionPerformed( final GuiButton btn )
2013-12-30 06:56:43 +01:00
{
super.actionPerformed( btn );
final boolean backwards = Mouse.isButtonDown( 1 );
2014-01-06 07:54:25 +01:00
if( btn == this.redstoneMode )
2015-04-29 02:30:53 +02:00
{
NetworkHandler.instance.sendToServer( new PacketConfigButton( this.redstoneMode.getSetting(), backwards ) );
2015-04-29 02:30:53 +02:00
}
if( btn == this.craftMode )
2015-04-29 02:30:53 +02:00
{
NetworkHandler.instance.sendToServer( new PacketConfigButton( this.craftMode.getSetting(), backwards ) );
2015-04-29 02:30:53 +02:00
}
2013-12-30 06:56:43 +01:00
if( btn == this.fuzzyMode )
2015-04-29 02:30:53 +02:00
{
NetworkHandler.instance.sendToServer( new PacketConfigButton( this.fuzzyMode.getSetting(), backwards ) );
2015-04-29 02:30:53 +02:00
}
if( btn == this.schedulingMode )
{
NetworkHandler.instance.sendToServer( new PacketConfigButton( this.schedulingMode.getSetting(), backwards ) );
}
2014-01-05 09:48:20 +01:00
}
2013-12-30 06:56:43 +01:00
}