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-01-27 05:00:36 +01:00
|
|
|
package appeng.client.gui.implementations;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.api.AEApi;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.api.definitions.IBlocks;
|
|
|
|
import appeng.api.definitions.IDefinitions;
|
|
|
|
import appeng.api.definitions.IParts;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.client.gui.AEBaseGui;
|
2014-08-08 00:54:22 +02:00
|
|
|
import appeng.client.gui.widgets.GuiNumberBox;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.client.gui.widgets.GuiTabButton;
|
|
|
|
import appeng.container.AEBaseContainer;
|
|
|
|
import appeng.container.implementations.ContainerPriority;
|
2014-07-31 19:24:08 +02:00
|
|
|
import appeng.core.AEConfig;
|
2014-02-07 21:37:22 +01:00
|
|
|
import appeng.core.AELog;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.core.localization.GuiText;
|
|
|
|
import appeng.core.sync.GuiBridge;
|
2014-02-09 02:34:52 +01:00
|
|
|
import appeng.core.sync.network.NetworkHandler;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.core.sync.packets.PacketSwitchGuis;
|
|
|
|
import appeng.core.sync.packets.PacketValueConfig;
|
|
|
|
import appeng.helpers.IPriorityHost;
|
2014-02-18 18:44:45 +01:00
|
|
|
import appeng.parts.automation.PartFormationPlane;
|
2014-07-18 05:38:57 +02:00
|
|
|
import appeng.parts.misc.PartInterface;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.parts.misc.PartStorageBus;
|
2014-07-18 05:38:57 +02:00
|
|
|
import appeng.tile.misc.TileInterface;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.tile.storage.TileChest;
|
|
|
|
import appeng.tile.storage.TileDrive;
|
|
|
|
|
|
|
|
public class GuiPriority extends AEBaseGui
|
|
|
|
{
|
|
|
|
|
2014-08-08 00:54:22 +02:00
|
|
|
GuiNumberBox priority;
|
2014-01-27 05:00:36 +01:00
|
|
|
GuiTabButton originalGuiBtn;
|
|
|
|
|
2015-03-26 12:13:34 +01:00
|
|
|
GuiButton plus1;
|
|
|
|
GuiButton plus10;
|
|
|
|
GuiButton plus100;
|
|
|
|
GuiButton plus1000;
|
|
|
|
GuiButton minus1;
|
|
|
|
GuiButton minus10;
|
|
|
|
GuiButton minus100;
|
|
|
|
GuiButton minus1000;
|
2014-01-27 05:00:36 +01:00
|
|
|
|
|
|
|
GuiBridge OriginalGui;
|
|
|
|
|
|
|
|
public GuiPriority(InventoryPlayer inventoryPlayer, IPriorityHost te) {
|
|
|
|
super( new ContainerPriority( inventoryPlayer, te ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initGui()
|
|
|
|
{
|
|
|
|
super.initGui();
|
|
|
|
|
2014-07-31 19:24:08 +02:00
|
|
|
int a = AEConfig.instance.priorityByStacksAmounts( 0 );
|
|
|
|
int b = AEConfig.instance.priorityByStacksAmounts( 1 );
|
|
|
|
int c = AEConfig.instance.priorityByStacksAmounts( 2 );
|
|
|
|
int d = AEConfig.instance.priorityByStacksAmounts( 3 );
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.buttonList.add( this.plus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 32, 22, 20, "+" + a ) );
|
|
|
|
this.buttonList.add( this.plus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 32, 28, 20, "+" + b ) );
|
|
|
|
this.buttonList.add( this.plus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 32, 32, 20, "+" + c ) );
|
|
|
|
this.buttonList.add( this.plus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 32, 38, 20, "+" + d ) );
|
2014-07-31 19:24:08 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.buttonList.add( this.minus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 69, 22, 20, "-" + a ) );
|
|
|
|
this.buttonList.add( this.minus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 69, 28, 20, "-" + b ) );
|
|
|
|
this.buttonList.add( this.minus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 69, 32, 20, "-" + c ) );
|
|
|
|
this.buttonList.add( this.minus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 69, 38, 20, "-" + d ) );
|
2014-01-27 05:00:36 +01:00
|
|
|
|
|
|
|
ItemStack myIcon = null;
|
2014-12-29 15:13:47 +01:00
|
|
|
Object target = ((AEBaseContainer) this.inventorySlots).getTarget();
|
2015-01-03 02:53:14 +01:00
|
|
|
final IDefinitions definitions = AEApi.instance().definitions();
|
|
|
|
final IParts parts = definitions.parts();
|
|
|
|
final IBlocks blocks = definitions.blocks();
|
2014-01-27 05:00:36 +01:00
|
|
|
|
|
|
|
if ( target instanceof PartStorageBus )
|
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
for ( ItemStack storageBusStack :parts.storageBus().maybeStack( 1 ).asSet() )
|
|
|
|
{
|
|
|
|
myIcon = storageBusStack;
|
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
this.OriginalGui = GuiBridge.GUI_STORAGEBUS;
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
|
2014-02-18 18:44:45 +01:00
|
|
|
if ( target instanceof PartFormationPlane )
|
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
for ( ItemStack formationPlaneStack : parts.formationPlane().maybeStack( 1 ).asSet() )
|
|
|
|
{
|
|
|
|
myIcon = formationPlaneStack;
|
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
this.OriginalGui = GuiBridge.GUI_FORMATION_PLANE;
|
2014-02-18 18:44:45 +01:00
|
|
|
}
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
if ( target instanceof TileDrive )
|
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
for ( ItemStack driveStack : blocks.drive().maybeStack( 1 ).asSet() )
|
|
|
|
{
|
|
|
|
myIcon = driveStack;
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.OriginalGui = GuiBridge.GUI_DRIVE;
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( target instanceof TileChest )
|
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
for ( ItemStack chestStack : blocks.chest().maybeStack( 1 ).asSet() )
|
|
|
|
{
|
|
|
|
myIcon = chestStack;
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.OriginalGui = GuiBridge.GUI_CHEST;
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
|
2014-07-18 05:38:57 +02:00
|
|
|
if ( target instanceof TileInterface )
|
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
for ( ItemStack interfaceStack : blocks.iface().maybeStack( 1 ).asSet() )
|
|
|
|
{
|
|
|
|
myIcon = interfaceStack;
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.OriginalGui = GuiBridge.GUI_INTERFACE;
|
2014-07-18 05:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( target instanceof PartInterface )
|
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
for ( ItemStack interfaceStack : parts.iface().maybeStack( 1 ).asSet() )
|
|
|
|
{
|
|
|
|
myIcon = interfaceStack;
|
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
this.OriginalGui = GuiBridge.GUI_INTERFACE;
|
2014-07-18 05:38:57 +02:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
if ( this.OriginalGui != null && myIcon != null )
|
2014-12-29 15:13:47 +01:00
|
|
|
this.buttonList.add( this.originalGuiBtn = new GuiTabButton( this.guiLeft + 154, this.guiTop, myIcon, myIcon.getDisplayName(), itemRender ) );
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.priority = new GuiNumberBox( this.fontRendererObj, this.guiLeft + 62, this.guiTop + 57, 59, this.fontRendererObj.FONT_HEIGHT, Long.class );
|
|
|
|
this.priority.setEnableBackgroundDrawing( false );
|
|
|
|
this.priority.setMaxStringLength( 16 );
|
|
|
|
this.priority.setTextColor( 0xFFFFFF );
|
|
|
|
this.priority.setVisible( true );
|
|
|
|
this.priority.setFocused( true );
|
|
|
|
((ContainerPriority) this.inventorySlots).setTextField( this.priority );
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void actionPerformed(GuiButton btn)
|
|
|
|
{
|
|
|
|
super.actionPerformed( btn );
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
if ( btn == this.originalGuiBtn )
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
NetworkHandler.instance.sendToServer( new PacketSwitchGuis( this.OriginalGui ) );
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
boolean isPlus = btn == this.plus1 || btn == this.plus10 || btn == this.plus100 || btn == this.plus1000;
|
|
|
|
boolean isMinus = btn == this.minus1 || btn == this.minus10 || btn == this.minus100 || btn == this.minus1000;
|
2014-07-31 19:24:08 +02:00
|
|
|
|
|
|
|
if ( isPlus || isMinus )
|
2014-12-29 15:13:47 +01:00
|
|
|
this.addQty( this.getQty( btn ) );
|
2014-07-31 19:24:08 +02:00
|
|
|
}
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
private void addQty(int i)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
String out = this.priority.getText();
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
boolean fixed = false;
|
|
|
|
while (out.startsWith( "0" ) && out.length() > 1)
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
out = out.substring( 1 );
|
|
|
|
fixed = true;
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
if ( fixed )
|
|
|
|
this.priority.setText( out );
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
if ( out.length() == 0 )
|
|
|
|
out = "0";
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
long result = Long.parseLong( out );
|
2014-01-27 05:00:36 +01:00
|
|
|
result += i;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
this.priority.setText( out = Long.toString( result ) );
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
NetworkHandler.instance.sendToServer( new PacketValueConfig( "PriorityHost.Priority", out ) );
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
2014-08-08 00:54:22 +02:00
|
|
|
catch(NumberFormatException e )
|
|
|
|
{
|
|
|
|
// nope..
|
2014-12-29 15:13:47 +01:00
|
|
|
this.priority.setText( "0" );
|
2014-08-08 00:54:22 +02:00
|
|
|
}
|
2014-01-27 05:00:36 +01:00
|
|
|
catch (IOException e)
|
|
|
|
{
|
2014-02-07 21:37:22 +01:00
|
|
|
AELog.error( e );
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void keyTyped(char character, int key)
|
|
|
|
{
|
|
|
|
if ( !this.checkHotbarKeys( key ) )
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
if ( (key == 211 || key == 205 || key == 203 || key == 14 || character == '-' || Character.isDigit( character ))
|
2014-12-29 15:13:47 +01:00
|
|
|
&& this.priority.textboxKeyTyped( character, key ) )
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
String out = this.priority.getText();
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
boolean fixed = false;
|
|
|
|
while (out.startsWith( "0" ) && out.length() > 1)
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
out = out.substring( 1 );
|
|
|
|
fixed = true;
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
if ( fixed )
|
|
|
|
this.priority.setText( out );
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
if ( out.length() == 0 )
|
|
|
|
out = "0";
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
NetworkHandler.instance.sendToServer( new PacketValueConfig( "PriorityHost.Priority", out ) );
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
{
|
2014-02-07 21:37:22 +01:00
|
|
|
AELog.error( e );
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
super.keyTyped( character, key );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY)
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.bindTexture( "guis/priority.png" );
|
|
|
|
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize );
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.priority.drawTextBox();
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected String getBackground()
|
|
|
|
{
|
|
|
|
return "guis/priority.png";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.fontRendererObj.drawString( GuiText.Priority.getLocal(), 8, 6, 4210752 );
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
}
|