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

210 lines
6.8 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;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
2015-06-16 02:44:59 +02:00
import org.lwjgl.input.Mouse;
2014-09-24 02:26:27 +02:00
import appeng.api.config.ActionItems;
import appeng.api.config.CopyMode;
import appeng.api.config.FuzzyMode;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.implementations.items.IUpgradeModule;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiToggleButton;
import appeng.container.implementations.ContainerCellWorkbench;
import appeng.core.localization.GuiText;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.tile.misc.TileCellWorkbench;
import appeng.util.Platform;
2014-09-24 02:26:27 +02:00
public class GuiCellWorkbench extends GuiUpgradeable
{
final ContainerCellWorkbench workbench;
final TileCellWorkbench tcw;
2014-09-24 02:26:27 +02:00
GuiImgButton clear;
GuiImgButton partition;
GuiToggleButton copyMode;
2015-09-30 14:24:40 +02:00
public GuiCellWorkbench( final InventoryPlayer inventoryPlayer, final TileCellWorkbench te )
{
2014-09-24 02:26:27 +02:00
super( new ContainerCellWorkbench( inventoryPlayer, te ) );
2014-12-29 15:13:47 +01:00
this.workbench = (ContainerCellWorkbench) this.inventorySlots;
this.ySize = 251;
this.tcw = te;
2014-09-24 02:26:27 +02:00
}
@Override
protected void addButtons()
2014-09-24 02:26:27 +02:00
{
this.clear = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.ACTIONS, ActionItems.CLOSE );
this.partition = new GuiImgButton( this.guiLeft - 18, this.guiTop + 28, Settings.ACTIONS, ActionItems.WRENCH );
this.copyMode = new GuiToggleButton( this.guiLeft - 18, this.guiTop + 48, 11 * 16 + 5, 12 * 16 + 5, GuiText.CopyMode.getLocal(), GuiText.CopyModeDesc.getLocal() );
this.fuzzyMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 68, Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
this.buttonList.add( this.fuzzyMode );
this.buttonList.add( this.partition );
this.buttonList.add( this.clear );
this.buttonList.add( this.copyMode );
2014-09-24 02:26:27 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
2014-09-24 02:26:27 +02:00
{
2014-12-29 15:13:47 +01:00
this.handleButtonVisibility();
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.bindTexture( this.getBackground() );
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, 211 - 34, this.ySize );
if( this.drawUpgrades() )
2014-09-24 02:26:27 +02:00
{
if( this.workbench.availableUpgrades() <= 8 )
2014-09-24 02:26:27 +02:00
{
2014-12-29 15:13:47 +01:00
this.drawTexturedModalRect( offsetX + 177, offsetY, 177, 0, 35, 7 + this.workbench.availableUpgrades() * 18 );
this.drawTexturedModalRect( offsetX + 177, offsetY + ( 7 + ( this.workbench.availableUpgrades() ) * 18 ), 177, 151, 35, 7 );
2014-09-24 02:26:27 +02:00
}
else if( this.workbench.availableUpgrades() <= 16 )
2014-09-24 02:26:27 +02:00
{
this.drawTexturedModalRect( offsetX + 177, offsetY, 177, 0, 35, 7 + 8 * 18 );
this.drawTexturedModalRect( offsetX + 177, offsetY + ( 7 + ( 8 ) * 18 ), 177, 151, 35, 7 );
2014-09-24 02:26:27 +02:00
2015-09-30 14:24:40 +02:00
final int dx = this.workbench.availableUpgrades() - 8;
2014-09-24 02:26:27 +02:00
this.drawTexturedModalRect( offsetX + 177 + 27, offsetY, 186, 0, 35 - 8, 7 + dx * 18 );
if( dx == 8 )
2015-04-29 02:30:53 +02:00
{
this.drawTexturedModalRect( offsetX + 177 + 27, offsetY + ( 7 + ( dx ) * 18 ), 186, 151, 35 - 8, 7 );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
else
2015-04-29 02:30:53 +02:00
{
this.drawTexturedModalRect( offsetX + 177 + 27 + 4, offsetY + ( 7 + ( dx ) * 18 ), 186 + 4, 151, 35 - 8, 7 );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
else
{
this.drawTexturedModalRect( offsetX + 177, offsetY, 177, 0, 35, 7 + 8 * 18 );
this.drawTexturedModalRect( offsetX + 177, offsetY + ( 7 + ( 8 ) * 18 ), 177, 151, 35, 7 );
2014-09-24 02:26:27 +02:00
this.drawTexturedModalRect( offsetX + 177 + 27, offsetY, 186, 0, 35 - 8, 7 + 8 * 18 );
this.drawTexturedModalRect( offsetX + 177 + 27, offsetY + ( 7 + ( 8 ) * 18 ), 186, 151, 35 - 8, 7 );
2014-09-24 02:26:27 +02:00
2015-09-30 14:24:40 +02:00
final int dx = this.workbench.availableUpgrades() - 16;
2014-09-24 02:26:27 +02:00
this.drawTexturedModalRect( offsetX + 177 + 27 + 18, offsetY, 186, 0, 35 - 8, 7 + dx * 18 );
if( dx == 8 )
2015-04-29 02:30:53 +02:00
{
this.drawTexturedModalRect( offsetX + 177 + 27 + 18, offsetY + ( 7 + ( dx ) * 18 ), 186, 151, 35 - 8, 7 );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
else
2015-04-29 02:30:53 +02:00
{
this.drawTexturedModalRect( offsetX + 177 + 27 + 18 + 4, offsetY + ( 7 + ( dx ) * 18 ), 186 + 4, 151, 35 - 8, 7 );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +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, 161, 68, 68 );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
@Override
2014-09-24 02:26:27 +02:00
protected void handleButtonVisibility()
{
2014-12-29 15:13:47 +01:00
this.copyMode.setState( this.workbench.copyMode == CopyMode.CLEAR_ON_REMOVE );
2014-09-24 02:26:27 +02:00
boolean hasFuzzy = false;
2015-09-30 14:24:40 +02:00
final IInventory inv = this.workbench.getCellUpgradeInventory();
for( int x = 0; x < inv.getSizeInventory(); x++ )
2014-09-24 02:26:27 +02:00
{
2015-09-30 14:24:40 +02:00
final ItemStack is = inv.getStackInSlot( x );
if( is != null && is.getItem() instanceof IUpgradeModule )
2014-09-24 02:26:27 +02:00
{
if( ( (IUpgradeModule) is.getItem() ).getType( is ) == Upgrades.FUZZY )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
hasFuzzy = true;
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.fuzzyMode.setVisibility( hasFuzzy );
2014-09-24 02:26:27 +02:00
}
@Override
2014-09-24 02:26:27 +02:00
protected String getBackground()
{
return "guis/cellworkbench.png";
}
@Override
protected boolean drawUpgrades()
{
return this.workbench.availableUpgrades() > 0;
}
@Override
2014-09-24 02:26:27 +02:00
protected GuiText getName()
{
return GuiText.CellWorkbench;
}
@Override
2015-09-30 14:24:40 +02:00
protected void actionPerformed( final GuiButton btn )
{
try
{
if( btn == this.copyMode )
{
NetworkHandler.instance.sendToServer( new PacketValueConfig( "CellWorkbench.Action", "CopyMode" ) );
}
else if( btn == this.partition )
{
NetworkHandler.instance.sendToServer( new PacketValueConfig( "CellWorkbench.Action", "Partition" ) );
}
else if( btn == this.clear )
{
NetworkHandler.instance.sendToServer( new PacketValueConfig( "CellWorkbench.Action", "Clear" ) );
}
else if( btn == this.fuzzyMode )
{
2015-09-30 14:24:40 +02:00
final boolean backwards = Mouse.isButtonDown( 1 );
FuzzyMode fz = (FuzzyMode) this.fuzzyMode.getCurrentValue();
fz = Platform.rotateEnum( fz, backwards, Settings.FUZZY_MODE.getPossibleValues() );
NetworkHandler.instance.sendToServer( new PacketValueConfig( "CellWorkbench.Fuzzy", fz.name() ) );
}
else
2015-04-29 02:30:53 +02:00
{
super.actionPerformed( btn );
2015-04-29 02:30:53 +02:00
}
}
2015-09-30 14:24:40 +02:00
catch( final IOException ignored )
{
}
}
2014-09-24 02:26:27 +02:00
}