2014-06-26 03:49:37 +02:00
|
|
|
package appeng.client.gui.implementations;
|
|
|
|
|
2014-06-28 07:20:12 +02:00
|
|
|
import java.io.IOException;
|
2014-06-27 04:47:26 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Iterator;
|
2014-06-28 07:20:12 +02:00
|
|
|
import java.util.LinkedList;
|
2014-06-26 03:49:37 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2014-06-27 04:47:26 +02:00
|
|
|
import appeng.api.AEApi;
|
2014-06-26 03:49:37 +02:00
|
|
|
import appeng.api.config.SortDir;
|
|
|
|
import appeng.api.config.SortOrder;
|
|
|
|
import appeng.api.config.ViewItems;
|
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
2014-06-27 04:47:26 +02:00
|
|
|
import appeng.api.storage.data.IItemList;
|
2014-06-26 03:49:37 +02:00
|
|
|
import appeng.client.gui.AEBaseGui;
|
|
|
|
import appeng.client.gui.widgets.GuiScrollbar;
|
|
|
|
import appeng.client.gui.widgets.ISortSource;
|
|
|
|
import appeng.container.implementations.ContainerCraftingCPU;
|
2014-06-28 07:20:12 +02:00
|
|
|
import appeng.core.AELog;
|
2014-06-26 03:49:37 +02:00
|
|
|
import appeng.core.localization.GuiText;
|
2014-06-28 07:20:12 +02:00
|
|
|
import appeng.core.sync.network.NetworkHandler;
|
|
|
|
import appeng.core.sync.packets.PacketValueConfig;
|
2014-06-26 03:49:37 +02:00
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2014-06-28 07:20:12 +02:00
|
|
|
import com.google.common.base.Joiner;
|
|
|
|
|
2014-06-26 03:49:37 +02:00
|
|
|
public class GuiCraftingCPU extends AEBaseGui implements ISortSource
|
|
|
|
{
|
|
|
|
|
2014-06-27 04:47:26 +02:00
|
|
|
int rows = 6;
|
2014-06-26 03:49:37 +02:00
|
|
|
|
2014-06-27 04:47:26 +02:00
|
|
|
IItemList<IAEItemStack> storage = AEApi.instance().storage().createItemList();
|
|
|
|
IItemList<IAEItemStack> active = AEApi.instance().storage().createItemList();
|
|
|
|
IItemList<IAEItemStack> pending = AEApi.instance().storage().createItemList();
|
|
|
|
|
|
|
|
List<IAEItemStack> visual = new ArrayList();
|
2014-06-26 03:49:37 +02:00
|
|
|
|
2014-08-05 05:33:26 +02:00
|
|
|
public void clearItems()
|
|
|
|
{
|
|
|
|
storage = AEApi.instance().storage().createItemList();
|
|
|
|
active = AEApi.instance().storage().createItemList();
|
|
|
|
pending = AEApi.instance().storage().createItemList();
|
|
|
|
visual = new ArrayList();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected GuiCraftingCPU(ContainerCraftingCPU container) {
|
|
|
|
super( container );
|
2014-06-28 07:20:12 +02:00
|
|
|
this.ySize = 184;
|
|
|
|
this.xSize = 238;
|
2014-06-26 03:49:37 +02:00
|
|
|
myScrollBar = new GuiScrollbar();
|
|
|
|
}
|
|
|
|
|
2014-08-05 05:33:26 +02:00
|
|
|
public GuiCraftingCPU(InventoryPlayer inventoryPlayer, Object te) {
|
|
|
|
this( new ContainerCraftingCPU( inventoryPlayer, te ) );
|
|
|
|
}
|
|
|
|
|
2014-06-28 07:20:12 +02:00
|
|
|
GuiButton cancel;
|
|
|
|
|
2014-06-26 03:49:37 +02:00
|
|
|
@Override
|
|
|
|
protected void actionPerformed(GuiButton btn)
|
|
|
|
{
|
|
|
|
super.actionPerformed( btn );
|
2014-06-28 07:20:12 +02:00
|
|
|
|
|
|
|
if ( cancel == btn )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
NetworkHandler.instance.sendToServer( new PacketValueConfig( "TileCrafting.Cancel", "Cancel" ) );
|
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
{
|
|
|
|
AELog.error( e );
|
|
|
|
}
|
|
|
|
}
|
2014-06-26 03:49:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initGui()
|
|
|
|
{
|
|
|
|
super.initGui();
|
2014-07-05 00:41:39 +02:00
|
|
|
setScrollBar();
|
2014-06-28 07:20:12 +02:00
|
|
|
cancel = new GuiButton( 0, this.guiLeft + 163, this.guiTop + ySize - 25, 50, 20, GuiText.Cancel.getLocal() );
|
|
|
|
buttonList.add( cancel );
|
2014-06-26 03:49:37 +02:00
|
|
|
}
|
|
|
|
|
2014-06-27 04:47:26 +02:00
|
|
|
private long getTotal(IAEItemStack is)
|
2014-06-26 03:49:37 +02:00
|
|
|
{
|
2014-06-27 04:47:26 +02:00
|
|
|
IAEItemStack a = storage.findPrecise( is );
|
|
|
|
IAEItemStack b = active.findPrecise( is );
|
|
|
|
IAEItemStack c = pending.findPrecise( is );
|
|
|
|
|
|
|
|
long total = 0;
|
|
|
|
|
|
|
|
if ( a != null )
|
|
|
|
total += a.getStackSize();
|
|
|
|
|
|
|
|
if ( b != null )
|
|
|
|
total += b.getStackSize();
|
|
|
|
|
|
|
|
if ( c != null )
|
|
|
|
total += c.getStackSize();
|
2014-06-26 03:49:37 +02:00
|
|
|
|
2014-06-27 04:47:26 +02:00
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void postUpdate(List<IAEItemStack> list, byte ref)
|
|
|
|
{
|
|
|
|
switch (ref)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
for (IAEItemStack l : list)
|
|
|
|
handleInput( storage, l );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
for (IAEItemStack l : list)
|
|
|
|
handleInput( active, l );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
for (IAEItemStack l : list)
|
|
|
|
handleInput( pending, l );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (IAEItemStack l : list)
|
|
|
|
{
|
|
|
|
long amt = getTotal( l );
|
|
|
|
|
|
|
|
if ( amt <= 0 )
|
|
|
|
deleteVisualStack( l );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IAEItemStack is = findVisualStack( l );
|
|
|
|
is.setStackSize( amt );
|
|
|
|
}
|
|
|
|
}
|
2014-06-26 03:49:37 +02:00
|
|
|
|
|
|
|
setScrollBar();
|
|
|
|
}
|
|
|
|
|
2014-06-27 04:47:26 +02:00
|
|
|
private void handleInput(IItemList<IAEItemStack> s, IAEItemStack l)
|
|
|
|
{
|
|
|
|
IAEItemStack a = s.findPrecise( l );
|
|
|
|
|
|
|
|
if ( l.getStackSize() <= 0 )
|
|
|
|
{
|
2014-06-27 07:45:29 +02:00
|
|
|
if ( a != null )
|
|
|
|
a.reset();
|
2014-06-27 04:47:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( a == null )
|
|
|
|
{
|
|
|
|
s.add( l.copy() );
|
|
|
|
a = s.findPrecise( l );
|
|
|
|
}
|
|
|
|
|
2014-06-27 07:45:29 +02:00
|
|
|
if ( a != null )
|
|
|
|
a.setStackSize( l.getStackSize() );
|
2014-06-27 04:47:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private IAEItemStack findVisualStack(IAEItemStack l)
|
|
|
|
{
|
|
|
|
Iterator<IAEItemStack> i = visual.iterator();
|
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
IAEItemStack o = i.next();
|
|
|
|
if ( o.equals( l ) )
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
IAEItemStack stack = l.copy();
|
|
|
|
visual.add( stack );
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void deleteVisualStack(IAEItemStack l)
|
|
|
|
{
|
|
|
|
Iterator<IAEItemStack> i = visual.iterator();
|
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
IAEItemStack o = i.next();
|
|
|
|
if ( o.equals( l ) )
|
|
|
|
{
|
|
|
|
i.remove();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-26 03:49:37 +02:00
|
|
|
private void setScrollBar()
|
|
|
|
{
|
2014-06-28 22:18:36 +02:00
|
|
|
int size = visual.size();
|
2014-06-27 04:47:26 +02:00
|
|
|
|
2014-06-28 07:20:12 +02:00
|
|
|
myScrollBar.setTop( 19 ).setLeft( 218 ).setHeight( 137 );
|
|
|
|
myScrollBar.setRange( 0, (size + 2) / 3 - rows, 1 );
|
2014-06-26 03:49:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY)
|
|
|
|
{
|
|
|
|
bindTexture( "guis/craftingcpu.png" );
|
|
|
|
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize );
|
|
|
|
}
|
|
|
|
|
|
|
|
int tooltip = -1;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawScreen(int mouse_x, int mouse_y, float btn)
|
|
|
|
{
|
2014-08-05 05:33:26 +02:00
|
|
|
cancel.enabled = !visual.isEmpty();
|
|
|
|
|
2014-06-26 03:49:37 +02:00
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
|
|
|
|
int gx = (width - xSize) / 2;
|
|
|
|
int gy = (height - ySize) / 2;
|
2014-06-28 07:20:12 +02:00
|
|
|
int yoff = 23;
|
2014-06-26 03:49:37 +02:00
|
|
|
|
|
|
|
tooltip = -1;
|
|
|
|
|
|
|
|
for (int z = 0; z <= 4 * 5; z++)
|
|
|
|
{
|
2014-06-28 07:20:12 +02:00
|
|
|
int minX = gx + 9 + x * 67;
|
|
|
|
int minY = gy + 22 + y * yoff;
|
2014-06-26 03:49:37 +02:00
|
|
|
|
2014-06-28 07:20:12 +02:00
|
|
|
if ( minX < mouse_x && minX + 67 > mouse_x )
|
2014-06-26 03:49:37 +02:00
|
|
|
{
|
2014-06-28 07:20:12 +02:00
|
|
|
if ( minY < mouse_y && minY + yoff - 2 > mouse_y )
|
2014-06-26 03:49:37 +02:00
|
|
|
{
|
|
|
|
tooltip = z;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
x++;
|
|
|
|
|
2014-06-28 07:20:12 +02:00
|
|
|
if ( x > 2 )
|
2014-06-26 03:49:37 +02:00
|
|
|
{
|
|
|
|
y++;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
super.drawScreen( mouse_x, mouse_y, btn );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
|
|
|
|
{
|
2014-07-16 05:26:12 +02:00
|
|
|
fontRendererObj.drawString( getGuiDisplayName( GuiText.CraftingStatus.getLocal() ), 8, 7, 4210752 );
|
2014-06-26 03:49:37 +02:00
|
|
|
|
2014-06-28 07:20:12 +02:00
|
|
|
int sectionLength = 67;
|
2014-06-26 03:49:37 +02:00
|
|
|
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
2014-06-28 07:20:12 +02:00
|
|
|
int xo = 0 + 9;
|
|
|
|
int yo = 0 + 22;
|
|
|
|
int viewStart = myScrollBar.getCurrentScroll() * 3;
|
|
|
|
int viewEnd = viewStart + 3 * 6;
|
2014-06-26 03:49:37 +02:00
|
|
|
|
2014-06-28 07:20:12 +02:00
|
|
|
String dspToolTip = "";
|
|
|
|
List<String> lineList = new LinkedList();
|
2014-06-26 03:49:37 +02:00
|
|
|
int toolPosX = 0;
|
|
|
|
int toolPosY = 0;
|
|
|
|
|
2014-06-28 07:20:12 +02:00
|
|
|
int offY = 23;
|
|
|
|
|
2014-06-27 04:47:26 +02:00
|
|
|
for (int z = viewStart; z < Math.min( viewEnd, visual.size() ); z++)
|
2014-06-26 03:49:37 +02:00
|
|
|
{
|
2014-06-27 04:47:26 +02:00
|
|
|
IAEItemStack refStack = visual.get( z );// repo.getRefrenceItem( z );
|
2014-06-26 03:49:37 +02:00
|
|
|
if ( refStack != null )
|
|
|
|
{
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glScaled( 0.5, 0.5, 0.5 );
|
|
|
|
|
2014-06-28 07:20:12 +02:00
|
|
|
IAEItemStack stored = storage.findPrecise( refStack );
|
|
|
|
IAEItemStack activeStack = active.findPrecise( refStack );
|
|
|
|
IAEItemStack pendingStack = pending.findPrecise( refStack );
|
|
|
|
|
|
|
|
int lines = 0;
|
|
|
|
|
|
|
|
if ( stored != null && stored.getStackSize() > 0 )
|
|
|
|
lines++;
|
|
|
|
if ( activeStack != null && activeStack.getStackSize() > 0 )
|
|
|
|
lines++;
|
|
|
|
if ( pendingStack != null && pendingStack.getStackSize() > 0 )
|
|
|
|
lines++;
|
|
|
|
|
|
|
|
int negY = ((lines - 1) * 5) / 2;
|
|
|
|
int downY = 0;
|
|
|
|
|
|
|
|
if ( stored != null && stored.getStackSize() > 0 )
|
|
|
|
{
|
|
|
|
String str = Long.toString( stored.getStackSize() );
|
|
|
|
if ( stored.getStackSize() >= 10000 )
|
|
|
|
str = Long.toString( stored.getStackSize() / 1000 ) + "k";
|
|
|
|
if ( stored.getStackSize() >= 10000000 )
|
|
|
|
str = Long.toString( stored.getStackSize() / 1000000 ) + "m";
|
|
|
|
|
|
|
|
str = GuiText.Stored.getLocal() + ": " + str;
|
|
|
|
int w = 4 + fontRendererObj.getStringWidth( str );
|
|
|
|
fontRendererObj.drawString( str, (int) ((x * (1 + sectionLength) + xo + sectionLength - 19 - ((float) w * 0.5)) * 2), (int) ((y * offY + yo
|
|
|
|
+ 6 - negY + downY) * 2), 4210752 );
|
|
|
|
|
|
|
|
if ( tooltip == z - viewStart )
|
|
|
|
lineList.add( GuiText.Stored.getLocal() + ": " + Long.toString( stored.getStackSize() ) );
|
|
|
|
|
|
|
|
downY += 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( activeStack != null && activeStack.getStackSize() > 0 )
|
|
|
|
{
|
|
|
|
String str = Long.toString( activeStack.getStackSize() );
|
|
|
|
if ( activeStack.getStackSize() >= 10000 )
|
|
|
|
str = Long.toString( activeStack.getStackSize() / 1000 ) + "k";
|
|
|
|
if ( activeStack.getStackSize() >= 10000000 )
|
|
|
|
str = Long.toString( activeStack.getStackSize() / 1000000 ) + "m";
|
|
|
|
|
|
|
|
str = GuiText.Crafting.getLocal() + ": " + str;
|
|
|
|
int w = 4 + fontRendererObj.getStringWidth( str );
|
|
|
|
fontRendererObj.drawString( str, (int) ((x * (1 + sectionLength) + xo + sectionLength - 19 - ((float) w * 0.5)) * 2), (int) ((y * offY + yo
|
|
|
|
+ 6 - negY + downY) * 2), 4210752 );
|
2014-06-26 03:49:37 +02:00
|
|
|
|
2014-06-28 07:20:12 +02:00
|
|
|
if ( tooltip == z - viewStart )
|
|
|
|
lineList.add( GuiText.Crafting.getLocal() + ": " + Long.toString( activeStack.getStackSize() ) );
|
|
|
|
|
|
|
|
downY += 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( pendingStack != null && pendingStack.getStackSize() > 0 )
|
|
|
|
{
|
|
|
|
String str = Long.toString( pendingStack.getStackSize() );
|
|
|
|
if ( pendingStack.getStackSize() >= 10000 )
|
|
|
|
str = Long.toString( pendingStack.getStackSize() / 1000 ) + "k";
|
|
|
|
if ( pendingStack.getStackSize() >= 10000000 )
|
|
|
|
str = Long.toString( pendingStack.getStackSize() / 1000000 ) + "m";
|
|
|
|
|
|
|
|
str = GuiText.Scheduled.getLocal() + ": " + str;
|
|
|
|
int w = 4 + fontRendererObj.getStringWidth( str );
|
|
|
|
fontRendererObj.drawString( str, (int) ((x * (1 + sectionLength) + xo + sectionLength - 19 - ((float) w * 0.5)) * 2), (int) ((y * offY + yo
|
|
|
|
+ 6 - negY + downY) * 2), 4210752 );
|
|
|
|
|
|
|
|
if ( tooltip == z - viewStart )
|
|
|
|
lineList.add( GuiText.Scheduled.getLocal() + ": " + Long.toString( pendingStack.getStackSize() ) );
|
|
|
|
|
|
|
|
}
|
2014-06-26 03:49:37 +02:00
|
|
|
|
|
|
|
GL11.glPopMatrix();
|
2014-06-28 07:20:12 +02:00
|
|
|
int posX = x * (1 + sectionLength) + xo + sectionLength - 19;
|
|
|
|
int posY = y * offY + yo;
|
2014-06-26 03:49:37 +02:00
|
|
|
|
2014-06-27 04:47:26 +02:00
|
|
|
ItemStack is = refStack.copy().getItemStack();
|
|
|
|
|
2014-06-26 03:49:37 +02:00
|
|
|
if ( tooltip == z - viewStart )
|
|
|
|
{
|
2014-06-28 07:20:12 +02:00
|
|
|
dspToolTip = Platform.getItemDisplayName( is );
|
2014-06-26 03:49:37 +02:00
|
|
|
|
2014-06-28 07:20:12 +02:00
|
|
|
if ( lineList.size() > 0 )
|
|
|
|
dspToolTip = dspToolTip + "\n" + Joiner.on( "\n" ).join( lineList );
|
2014-06-26 03:49:37 +02:00
|
|
|
|
2014-06-28 07:20:12 +02:00
|
|
|
toolPosX = x * (1 + sectionLength) + xo + sectionLength - 8;
|
|
|
|
toolPosY = y * offY + yo;
|
2014-06-26 03:49:37 +02:00
|
|
|
}
|
|
|
|
|
2014-06-27 04:47:26 +02:00
|
|
|
drawItem( posX, posY, is );
|
2014-06-26 03:49:37 +02:00
|
|
|
|
|
|
|
x++;
|
|
|
|
|
2014-06-28 07:20:12 +02:00
|
|
|
if ( x > 2 )
|
2014-06-26 03:49:37 +02:00
|
|
|
{
|
|
|
|
y++;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-06-28 07:20:12 +02:00
|
|
|
if ( tooltip >= 0 && dspToolTip.length() > 0 )
|
2014-06-26 03:49:37 +02:00
|
|
|
{
|
|
|
|
GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS );
|
2014-06-28 07:20:12 +02:00
|
|
|
drawTooltip( toolPosX, toolPosY + 10, 0, dspToolTip );
|
2014-06-26 03:49:37 +02:00
|
|
|
GL11.glPopAttrib();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Enum getSortBy()
|
|
|
|
{
|
|
|
|
return SortOrder.NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Enum getSortDir()
|
|
|
|
{
|
|
|
|
return SortDir.ASCENDING;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Enum getSortDisplay()
|
|
|
|
{
|
|
|
|
return ViewItems.ALL;
|
|
|
|
}
|
2014-08-05 05:33:26 +02:00
|
|
|
|
2014-06-26 03:49:37 +02:00
|
|
|
}
|