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.client.gui.GuiTextField;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.client.gui.AEBaseGui;
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
|
|
|
GuiTextField priority;
|
|
|
|
GuiTabButton originalGuiBtn;
|
|
|
|
|
|
|
|
GuiButton plus1, plus10, plus100, plus1000;
|
|
|
|
GuiButton minus1, minus10, minus100, minus1000;
|
|
|
|
|
|
|
|
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-07-31 19:24:08 +02:00
|
|
|
buttonList.add( plus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 32, 22, 20, "+" + a ) );
|
|
|
|
buttonList.add( plus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 32, 28, 20, "+" + b ) );
|
|
|
|
buttonList.add( plus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 32, 32, 20, "+" + c ) );
|
|
|
|
buttonList.add( plus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 32, 38, 20, "+" + d ) );
|
|
|
|
|
|
|
|
buttonList.add( minus1 = new GuiButton( 0, this.guiLeft + 20, this.guiTop + 69, 22, 20, "-" + a ) );
|
|
|
|
buttonList.add( minus10 = new GuiButton( 0, this.guiLeft + 48, this.guiTop + 69, 28, 20, "-" + b ) );
|
|
|
|
buttonList.add( minus100 = new GuiButton( 0, this.guiLeft + 82, this.guiTop + 69, 32, 20, "-" + c ) );
|
|
|
|
buttonList.add( minus1000 = new GuiButton( 0, this.guiLeft + 120, this.guiTop + 69, 38, 20, "-" + d ) );
|
2014-01-27 05:00:36 +01:00
|
|
|
|
|
|
|
ItemStack myIcon = null;
|
|
|
|
Object target = ((AEBaseContainer) inventorySlots).getTarget();
|
|
|
|
|
|
|
|
if ( target instanceof PartStorageBus )
|
|
|
|
{
|
|
|
|
myIcon = AEApi.instance().parts().partStorageBus.stack( 1 );
|
|
|
|
OriginalGui = GuiBridge.GUI_STORAGEBUS;
|
|
|
|
}
|
|
|
|
|
2014-02-18 18:44:45 +01:00
|
|
|
if ( target instanceof PartFormationPlane )
|
|
|
|
{
|
|
|
|
myIcon = AEApi.instance().parts().partFormationPlane.stack( 1 );
|
|
|
|
OriginalGui = GuiBridge.GUI_FPLANE;
|
|
|
|
}
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
if ( target instanceof TileDrive )
|
|
|
|
{
|
|
|
|
myIcon = AEApi.instance().blocks().blockDrive.stack( 1 );
|
|
|
|
OriginalGui = GuiBridge.GUI_DRIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( target instanceof TileChest )
|
|
|
|
{
|
|
|
|
myIcon = AEApi.instance().blocks().blockChest.stack( 1 );
|
|
|
|
OriginalGui = GuiBridge.GUI_CHEST;
|
|
|
|
}
|
|
|
|
|
2014-07-18 05:38:57 +02:00
|
|
|
if ( target instanceof TileInterface )
|
|
|
|
{
|
|
|
|
myIcon = AEApi.instance().blocks().blockInterface.stack( 1 );
|
|
|
|
OriginalGui = GuiBridge.GUI_INTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( target instanceof PartInterface )
|
|
|
|
{
|
|
|
|
myIcon = AEApi.instance().parts().partInterface.stack( 1 );
|
|
|
|
OriginalGui = GuiBridge.GUI_INTERFACE;
|
|
|
|
}
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
if ( OriginalGui != null )
|
2014-02-09 02:34:52 +01:00
|
|
|
buttonList.add( originalGuiBtn = new GuiTabButton( this.guiLeft + 154, this.guiTop, myIcon, myIcon.getDisplayName(), itemRender ) );
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
priority = new GuiTextField( fontRendererObj, this.guiLeft + 62, this.guiTop + 57, 59, fontRendererObj.FONT_HEIGHT );
|
2014-01-27 05:00:36 +01:00
|
|
|
priority.setEnableBackgroundDrawing( false );
|
|
|
|
priority.setMaxStringLength( 16 );
|
|
|
|
priority.setTextColor( 0xFFFFFF );
|
|
|
|
priority.setVisible( true );
|
|
|
|
priority.setFocused( true );
|
|
|
|
((ContainerPriority) inventorySlots).setTextField( priority );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void actionPerformed(GuiButton btn)
|
|
|
|
{
|
|
|
|
super.actionPerformed( btn );
|
|
|
|
|
|
|
|
if ( btn == originalGuiBtn )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
NetworkHandler.instance.sendToServer( new PacketSwitchGuis( OriginalGui ) );
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-31 19:24:08 +02:00
|
|
|
boolean isPlus = btn == plus1 || btn == plus10 || btn == plus100 || btn == plus1000;
|
|
|
|
boolean isMinus = btn == minus1 || btn == minus10 || btn == minus100 || btn == minus1000;
|
|
|
|
|
|
|
|
if ( isPlus || isMinus )
|
|
|
|
addQty( getQty( btn ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getQty(GuiButton btn)
|
|
|
|
{
|
|
|
|
return Integer.parseInt( btn.displayString );
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addQty(int i)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
String Out = priority.getText();
|
|
|
|
|
|
|
|
boolean Fixed = false;
|
|
|
|
while (Out.startsWith( "0" ) && Out.length() > 1)
|
|
|
|
{
|
|
|
|
Out = Out.substring( 1 );
|
|
|
|
Fixed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( Fixed )
|
|
|
|
priority.setText( Out );
|
|
|
|
|
|
|
|
if ( Out.length() == 0 )
|
|
|
|
Out = "0";
|
|
|
|
|
|
|
|
long result = Long.parseLong( Out );
|
|
|
|
result += i;
|
|
|
|
|
|
|
|
priority.setText( Out = Long.toString( result ) );
|
|
|
|
|
2014-02-09 02:34:52 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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 ))
|
|
|
|
&& priority.textboxKeyTyped( character, key ) )
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
String Out = priority.getText();
|
|
|
|
|
|
|
|
boolean Fixed = false;
|
|
|
|
while (Out.startsWith( "0" ) && Out.length() > 1)
|
|
|
|
{
|
|
|
|
Out = Out.substring( 1 );
|
|
|
|
Fixed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( Fixed )
|
|
|
|
priority.setText( Out );
|
|
|
|
|
|
|
|
if ( Out.length() == 0 )
|
|
|
|
Out = "0";
|
|
|
|
|
2014-02-09 02:34:52 +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)
|
|
|
|
{
|
|
|
|
bindTexture( "guis/priority.png" );
|
|
|
|
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize );
|
|
|
|
|
|
|
|
priority.drawTextBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String getBackground()
|
|
|
|
{
|
|
|
|
return "guis/priority.png";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
fontRendererObj.drawString( GuiText.Priority.getLocal(), 8, 6, 4210752 );
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
}
|