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-11-28 04:36:46 +01:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2014-11-28 04:36:46 +01:00
|
|
|
import org.lwjgl.input.Mouse;
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.inventory.Slot;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
|
|
import appeng.api.config.Settings;
|
|
|
|
import appeng.api.config.SortDir;
|
|
|
|
import appeng.api.config.SortOrder;
|
|
|
|
import appeng.api.config.ViewItems;
|
|
|
|
import appeng.api.implementations.guiobjects.INetworkTool;
|
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
import appeng.client.gui.AEBaseGui;
|
|
|
|
import appeng.client.gui.widgets.GuiImgButton;
|
|
|
|
import appeng.client.gui.widgets.GuiScrollbar;
|
|
|
|
import appeng.client.gui.widgets.ISortSource;
|
|
|
|
import appeng.client.me.ItemRepo;
|
|
|
|
import appeng.client.me.SlotME;
|
|
|
|
import appeng.container.implementations.ContainerNetworkStatus;
|
|
|
|
import appeng.core.AEConfig;
|
|
|
|
import appeng.core.localization.GuiText;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
public class GuiNetworkStatus extends AEBaseGui implements ISortSource
|
|
|
|
{
|
|
|
|
|
2014-09-29 09:54:34 +02:00
|
|
|
final ItemRepo repo;
|
|
|
|
final int rows = 4;
|
2015-04-03 08:54:31 +02:00
|
|
|
GuiImgButton units;
|
|
|
|
int tooltip = -1;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public GuiNetworkStatus( InventoryPlayer inventoryPlayer, INetworkTool te )
|
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
super( new ContainerNetworkStatus( inventoryPlayer, te ) );
|
|
|
|
this.ySize = 153;
|
|
|
|
this.xSize = 195;
|
2014-12-29 15:13:47 +01:00
|
|
|
this.myScrollBar = new GuiScrollbar();
|
|
|
|
this.repo = new ItemRepo( this.myScrollBar, this );
|
|
|
|
this.repo.rowSize = 5;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
protected void actionPerformed( GuiButton btn )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
super.actionPerformed( btn );
|
|
|
|
|
|
|
|
boolean backwards = Mouse.isButtonDown( 1 );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( btn == this.units )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
AEConfig.instance.nextPowerUnit( backwards );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.units.set( AEConfig.instance.selectedPowerUnit() );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initGui()
|
|
|
|
{
|
|
|
|
super.initGui();
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.units = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.POWER_UNITS, AEConfig.instance.selectedPowerUnit() );
|
|
|
|
this.buttonList.add( this.units );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void drawScreen( int mouse_x, int mouse_y, float btn )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
int gx = ( this.width - this.xSize ) / 2;
|
|
|
|
int gy = ( this.height - this.ySize ) / 2;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tooltip = -1;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int z = 0; z <= 4 * 5; z++ )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
int minX = gx + 14 + x * 31;
|
|
|
|
int minY = gy + 41 + y * 18;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( minX < mouse_x && minX + 28 > mouse_x )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( minY < mouse_y && minY + 20 > mouse_y )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tooltip = z;
|
2014-09-24 02:26:27 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
x++;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( x > 4 )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
y++;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
super.drawScreen( mouse_x, mouse_y, btn );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void drawFG( int offsetX, int offsetY, int mouseX, int mouseY )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
ContainerNetworkStatus ns = (ContainerNetworkStatus) this.inventorySlots;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.fontRendererObj.drawString( GuiText.NetworkDetails.getLocal(), 8, 6, 4210752 );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.fontRendererObj.drawString( GuiText.StoredPower.getLocal() + ": " + Platform.formatPowerLong( ns.currentPower, false ), 13, 16, 4210752 );
|
|
|
|
this.fontRendererObj.drawString( GuiText.MaxPower.getLocal() + ": " + Platform.formatPowerLong( ns.maxPower, false ), 13, 26, 4210752 );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.fontRendererObj.drawString( GuiText.PowerInputRate.getLocal() + ": " + Platform.formatPowerLong( ns.avgAddition, true ), 13, 143 - 10, 4210752 );
|
|
|
|
this.fontRendererObj.drawString( GuiText.PowerUsageRate.getLocal() + ": " + Platform.formatPowerLong( ns.powerUsage, true ), 13, 143 - 20, 4210752 );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
int sectionLength = 30;
|
|
|
|
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
2014-10-09 21:12:43 +02:00
|
|
|
int xo = 12;
|
|
|
|
int yo = 42;
|
2014-09-24 02:26:27 +02:00
|
|
|
int viewStart = 0;// myScrollBar.getCurrentScroll() * 5;
|
|
|
|
int viewEnd = viewStart + 5 * 4;
|
|
|
|
|
2015-03-26 10:41:45 +01:00
|
|
|
String toolTip = "";
|
2014-09-24 02:26:27 +02:00
|
|
|
int toolPosX = 0;
|
|
|
|
int toolPosY = 0;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int z = viewStart; z < Math.min( viewEnd, this.repo.size() ); z++ )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
IAEItemStack refStack = this.repo.getReferenceItem( z );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( refStack != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glScaled( 0.5, 0.5, 0.5 );
|
|
|
|
|
|
|
|
String str = Long.toString( refStack.getStackSize() );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( refStack.getStackSize() >= 10000 )
|
2014-11-28 04:36:46 +01:00
|
|
|
str = Long.toString( refStack.getStackSize() / 1000 ) + 'k';
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
int w = this.fontRendererObj.getStringWidth( str );
|
2015-04-03 08:54:31 +02:00
|
|
|
this.fontRendererObj.drawString( str, (int) ( ( x * sectionLength + xo + sectionLength - 19 - ( w * 0.5 ) ) * 2 ), ( y * 18 + yo + 6 ) * 2, 4210752 );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
GL11.glPopMatrix();
|
|
|
|
int posX = x * sectionLength + xo + sectionLength - 18;
|
|
|
|
int posY = y * 18 + yo;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.tooltip == z - viewStart )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-26 10:41:45 +01:00
|
|
|
toolTip = Platform.getItemDisplayName( this.repo.getItem( z ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-03-26 10:41:45 +01:00
|
|
|
toolTip += ( '\n' + GuiText.Installed.getLocal() + ": " + ( refStack.getStackSize() ) );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( refStack.getCountRequestable() > 0 )
|
2015-03-26 10:41:45 +01:00
|
|
|
toolTip += ( '\n' + GuiText.EnergyDrain.getLocal() + ": " + Platform.formatPowerLong( refStack.getCountRequestable(), true ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
toolPosX = x * sectionLength + xo + sectionLength - 8;
|
|
|
|
toolPosY = y * 18 + yo;
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.drawItem( posX, posY, this.repo.getItem( z ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
x++;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( x > 4 )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
y++;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.tooltip >= 0 && toolTip.length() > 0 )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS );
|
2015-03-26 10:41:45 +01:00
|
|
|
this.drawTooltip( toolPosX, toolPosY + 10, 0, toolTip );
|
2014-09-24 02:26:27 +02:00
|
|
|
GL11.glPopAttrib();
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawBG( int offsetX, int offsetY, int mouseX, int mouseY )
|
|
|
|
{
|
|
|
|
this.bindTexture( "guis/networkstatus.png" );
|
|
|
|
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void postUpdate( List<IAEItemStack> list )
|
|
|
|
{
|
|
|
|
this.repo.clear();
|
|
|
|
|
|
|
|
for( IAEItemStack is : list )
|
|
|
|
this.repo.postUpdate( is );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
this.repo.updateView();
|
|
|
|
this.setScrollBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setScrollBar()
|
|
|
|
{
|
|
|
|
int size = this.repo.size();
|
|
|
|
this.myScrollBar.setTop( 39 ).setLeft( 175 ).setHeight( 78 );
|
|
|
|
this.myScrollBar.setRange( 0, ( size + 4 ) / 5 - this.rows, 1 );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// @Override - NEI
|
2015-04-03 08:54:31 +02:00
|
|
|
public List<String> handleItemTooltip( ItemStack stack, int mouseX, int mouseY, List<String> currentToolTip )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( stack != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
Slot s = this.getSlot( mouseX, mouseY );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( s instanceof SlotME )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
IAEItemStack myStack = null;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
SlotME theSlotField = (SlotME) s;
|
|
|
|
myStack = theSlotField.getAEStack();
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable ignore )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( myStack != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
while( currentToolTip.size() > 1 )
|
2014-09-28 11:47:17 +02:00
|
|
|
currentToolTip.remove( 1 );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-28 11:47:17 +02:00
|
|
|
return currentToolTip;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Vanilla version...
|
2015-04-03 08:54:31 +02:00
|
|
|
protected void drawItemStackTooltip( ItemStack stack, int x, int y )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
Slot s = this.getSlot( x, y );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( s instanceof SlotME && stack != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
IAEItemStack myStack = null;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
SlotME theSlotField = (SlotME) s;
|
|
|
|
myStack = theSlotField.getAEStack();
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable ignore )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( myStack != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
List currentToolTip = stack.getTooltip( this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
while( currentToolTip.size() > 1 )
|
2014-09-28 11:47:17 +02:00
|
|
|
currentToolTip.remove( 1 );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
currentToolTip.add( GuiText.Installed.getLocal() + ": " + ( myStack.getStackSize() ) );
|
2014-09-28 11:47:17 +02:00
|
|
|
currentToolTip.add( GuiText.EnergyDrain.getLocal() + ": " + Platform.formatPowerLong( myStack.getCountRequestable(), true ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.drawTooltip( x, y, 0, join( currentToolTip, "\n" ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// super.drawItemStackTooltip( stack, x, y );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Enum getSortBy()
|
|
|
|
{
|
|
|
|
return SortOrder.NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Enum getSortDir()
|
|
|
|
{
|
|
|
|
return SortDir.ASCENDING;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Enum getSortDisplay()
|
|
|
|
{
|
|
|
|
return ViewItems.ALL;
|
|
|
|
}
|
|
|
|
}
|