2014-07-08 05:48:21 +02:00
|
|
|
package appeng.client.gui.implementations;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
2014-07-09 10:17:11 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.LinkedList;
|
2014-07-08 05:48:21 +02:00
|
|
|
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-07-09 10:17:11 +02:00
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2014-07-08 05:48:21 +02:00
|
|
|
import appeng.client.gui.AEBaseGui;
|
2014-07-09 10:17:11 +02:00
|
|
|
import appeng.client.gui.widgets.GuiScrollbar;
|
|
|
|
import appeng.client.me.ClientDCInternalInv;
|
|
|
|
import appeng.client.me.SlotDisconnected;
|
2014-07-08 05:48:21 +02:00
|
|
|
import appeng.container.implementations.ContainerInterfaceTerminal;
|
|
|
|
import appeng.core.localization.GuiText;
|
|
|
|
import appeng.parts.reporting.PartMonitor;
|
|
|
|
|
|
|
|
import com.google.common.collect.HashMultimap;
|
|
|
|
|
|
|
|
public class GuiInterfaceTerminal extends AEBaseGui
|
|
|
|
{
|
|
|
|
|
2014-07-09 10:17:11 +02:00
|
|
|
HashMap<Long, ClientDCInternalInv> byId = new HashMap();
|
|
|
|
HashMultimap<String, ClientDCInternalInv> byName = HashMultimap.create();
|
|
|
|
ArrayList<String> names = new ArrayList();
|
2014-07-08 05:48:21 +02:00
|
|
|
|
2014-07-09 10:17:11 +02:00
|
|
|
ArrayList<Object> lines = new ArrayList();
|
2014-07-08 05:48:21 +02:00
|
|
|
|
2014-07-09 10:17:11 +02:00
|
|
|
private int getTotalRows()
|
|
|
|
{
|
|
|
|
return names.size() + byId.size();// unique names, and each inv row.
|
|
|
|
}
|
2014-07-08 05:48:21 +02:00
|
|
|
|
|
|
|
public GuiInterfaceTerminal(InventoryPlayer inventoryPlayer, PartMonitor te) {
|
|
|
|
super( new ContainerInterfaceTerminal( inventoryPlayer, te ) );
|
2014-07-09 10:17:11 +02:00
|
|
|
myScrollBar = new GuiScrollbar();
|
2014-07-08 05:48:21 +02:00
|
|
|
xSize = 195;
|
|
|
|
ySize = 222;
|
|
|
|
}
|
|
|
|
|
2014-07-09 10:17:11 +02:00
|
|
|
LinkedList<SlotDisconnected> dcSlots = new LinkedList();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initGui()
|
|
|
|
{
|
|
|
|
super.initGui();
|
|
|
|
myScrollBar.setLeft( 175 );
|
|
|
|
myScrollBar.setHeight( 106 );
|
|
|
|
myScrollBar.setTop( 18 );
|
|
|
|
}
|
|
|
|
|
2014-07-08 05:48:21 +02:00
|
|
|
@Override
|
|
|
|
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY)
|
|
|
|
{
|
|
|
|
bindTexture( "guis/interfaceterminal.png" );
|
|
|
|
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize );
|
2014-07-09 10:17:11 +02:00
|
|
|
|
|
|
|
int offset = 17;
|
|
|
|
int ex = myScrollBar.getCurrentScroll();
|
|
|
|
int linesOnPage = 6;
|
|
|
|
|
|
|
|
for (int x = 0; x < linesOnPage; x++)
|
|
|
|
{
|
|
|
|
if ( ex + x < lines.size() )
|
|
|
|
{
|
|
|
|
Object lineObj = lines.get( ex + x );
|
|
|
|
if ( lineObj instanceof ClientDCInternalInv )
|
|
|
|
{
|
|
|
|
ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
|
|
|
|
|
|
|
|
GL11.glColor4f( 1, 1, 1, 1 );
|
|
|
|
for (int z = 0; z < inv.inv.getSizeInventory(); z++)
|
|
|
|
this.drawTexturedModalRect( offsetX + z * 18 + 7, offsetY + offset, 7, 139, 18, 18 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
offset += 18;
|
|
|
|
}
|
2014-07-08 05:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
|
|
|
|
{
|
|
|
|
fontRendererObj.drawString( getGuiDisplayName( GuiText.InterfaceTerminal.getLocal() ), 8, 6, 4210752 );
|
|
|
|
fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 );
|
|
|
|
|
2014-07-09 10:17:11 +02:00
|
|
|
int offset = 17;
|
2014-07-08 05:48:21 +02:00
|
|
|
|
2014-07-09 10:17:11 +02:00
|
|
|
// for (String name : lines)
|
|
|
|
int ex = myScrollBar.getCurrentScroll();
|
|
|
|
int linesOnPage = 6;
|
|
|
|
|
|
|
|
Iterator<Object> o = inventorySlots.inventorySlots.iterator();
|
|
|
|
while (o.hasNext())
|
2014-07-08 05:48:21 +02:00
|
|
|
{
|
2014-07-09 10:17:11 +02:00
|
|
|
if ( o.next() instanceof SlotDisconnected )
|
|
|
|
o.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int x = 0; x < linesOnPage; x++)
|
|
|
|
{
|
|
|
|
if ( ex + x < lines.size() )
|
|
|
|
{
|
|
|
|
Object lineObj = lines.get( ex + x );
|
|
|
|
if ( lineObj instanceof ClientDCInternalInv )
|
|
|
|
{
|
|
|
|
ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
|
|
|
|
for (int z = 0; z < inv.inv.getSizeInventory(); z++)
|
|
|
|
{
|
|
|
|
inventorySlots.inventorySlots.add( new SlotDisconnected( inv, z, z * 18 + 8, 1 + offset ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( lineObj instanceof String )
|
|
|
|
{
|
|
|
|
String name = (String) lineObj;
|
|
|
|
int rows = byName.get( name ).size();
|
|
|
|
if ( rows > 1 )
|
|
|
|
name = name + " (" + rows + ")";
|
|
|
|
|
|
|
|
while (name.length() > 2 && fontRendererObj.getStringWidth( name ) > 155)
|
|
|
|
name = name.substring( 0, name.length() - 1 );
|
|
|
|
|
|
|
|
fontRendererObj.drawString( name, 10, 6 + offset, 4210752 );
|
|
|
|
}
|
|
|
|
offset += 18;
|
|
|
|
}
|
2014-07-08 05:48:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean refreshList = false;
|
|
|
|
|
|
|
|
public void postUpdate(NBTTagCompound in)
|
|
|
|
{
|
|
|
|
if ( in.getBoolean( "clear" ) )
|
2014-07-09 10:17:11 +02:00
|
|
|
{
|
2014-07-08 05:48:21 +02:00
|
|
|
byId.clear();
|
2014-07-09 10:17:11 +02:00
|
|
|
refreshList = true;
|
|
|
|
}
|
2014-07-08 05:48:21 +02:00
|
|
|
|
|
|
|
for (Object oKey : in.func_150296_c())
|
|
|
|
{
|
|
|
|
String key = (String) oKey;
|
|
|
|
if ( key.startsWith( "=" ) )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
long id = Long.parseLong( key.substring( 1 ), Character.MAX_RADIX );
|
|
|
|
NBTTagCompound invData = in.getCompoundTag( key );
|
2014-07-13 03:20:21 +02:00
|
|
|
ClientDCInternalInv current = getById( id, invData.getLong( "sortBy" ), invData.getString( "un" ) );
|
2014-07-08 05:48:21 +02:00
|
|
|
|
|
|
|
for (int x = 0; x < current.inv.getSizeInventory(); x++)
|
|
|
|
{
|
|
|
|
String which = Integer.toString( x );
|
|
|
|
if ( invData.hasKey( which ) )
|
|
|
|
current.inv.setInventorySlotContents( x, ItemStack.loadItemStackFromNBT( invData.getCompoundTag( which ) ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (NumberFormatException ex)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( refreshList )
|
|
|
|
{
|
2014-07-09 10:17:11 +02:00
|
|
|
refreshList = false;
|
|
|
|
|
2014-07-08 05:48:21 +02:00
|
|
|
byName.clear();
|
2014-07-09 10:17:11 +02:00
|
|
|
for (ClientDCInternalInv o : byId.values())
|
2014-07-08 05:48:21 +02:00
|
|
|
byName.put( o.getName(), o );
|
|
|
|
|
|
|
|
names.clear();
|
|
|
|
names.addAll( byName.keySet() );
|
|
|
|
|
|
|
|
Collections.sort( names );
|
2014-07-09 10:17:11 +02:00
|
|
|
|
|
|
|
lines = new ArrayList( getTotalRows() );
|
|
|
|
for (String n : names)
|
|
|
|
{
|
|
|
|
lines.add( n );
|
2014-07-13 03:20:21 +02:00
|
|
|
|
|
|
|
ArrayList<ClientDCInternalInv> lset = new ArrayList();
|
|
|
|
lset.addAll( byName.get( n ) );
|
|
|
|
|
|
|
|
Collections.sort( lset );
|
|
|
|
|
|
|
|
for (ClientDCInternalInv i : lset)
|
|
|
|
{
|
2014-07-09 10:17:11 +02:00
|
|
|
lines.add( i );
|
2014-07-13 03:20:21 +02:00
|
|
|
}
|
2014-07-09 10:17:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
myScrollBar.setRange( 0, getTotalRows() - 6, 2 );
|
2014-07-08 05:48:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-13 03:20:21 +02:00
|
|
|
private ClientDCInternalInv getById(long id, long sortBy, String string)
|
2014-07-08 05:48:21 +02:00
|
|
|
{
|
2014-07-09 10:17:11 +02:00
|
|
|
ClientDCInternalInv o = byId.get( id );
|
2014-07-08 05:48:21 +02:00
|
|
|
|
|
|
|
if ( o == null )
|
|
|
|
{
|
2014-07-13 03:20:21 +02:00
|
|
|
byId.put( id, o = new ClientDCInternalInv( 9, id, sortBy, string ) );
|
2014-07-08 05:48:21 +02:00
|
|
|
refreshList = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
}
|