Applied-Energistics-2-tiler.../src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java

524 lines
14 KiB
Java
Raw Normal View History

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-09-24 02:26:27 +02:00
import java.io.IOException;
import java.util.List;
2014-12-29 21:59:05 +01:00
import org.lwjgl.input.Mouse;
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.SearchBoxMode;
import appeng.api.config.Settings;
import appeng.api.config.TerminalStyle;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.implementations.tiles.IMEChest;
import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.client.gui.AEBaseMEGui;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiScrollbar;
import appeng.client.gui.widgets.GuiTabButton;
import appeng.client.gui.widgets.ISortSource;
import appeng.client.gui.widgets.MEGuiTextField;
import appeng.client.me.InternalSlotME;
import appeng.client.me.ItemRepo;
import appeng.container.implementations.ContainerMEMonitorable;
import appeng.container.slot.AppEngSlot;
import appeng.container.slot.SlotCraftingMatrix;
import appeng.container.slot.SlotFakeCraftingMatrix;
import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.core.localization.GuiText;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.integration.IntegrationType;
import appeng.parts.reporting.PartTerminal;
import appeng.tile.misc.TileSecurity;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
2014-09-24 02:26:27 +02:00
public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfigManagerHost
{
public static int CraftingGridOffsetX;
public static int CraftingGridOffsetY;
private static String memoryText = "";
final ItemRepo repo;
final int offsetX = 9;
final int lowerTextureOffset = 0;
final IConfigManager configSrc;
final boolean viewCell;
final ItemStack[] myCurrentViewCells = new ItemStack[5];
final ContainerMEMonitorable monitorableContainer;
GuiTabButton craftingStatusBtn;
MEGuiTextField searchField;
GuiText myName;
2014-09-24 02:26:27 +02:00
int perRow = 9;
int reservedSpace = 0;
boolean customSortOrder = true;
int rows = 0;
int maxRows = Integer.MAX_VALUE;
int standardSize;
GuiImgButton ViewBox;
GuiImgButton SortByBox;
GuiImgButton SortDirBox;
2015-03-26 12:13:34 +01:00
GuiImgButton searchBoxSettings;
GuiImgButton terminalStyleBox;
2014-09-24 02:26:27 +02:00
public GuiMEMonitorable( InventoryPlayer inventoryPlayer, ITerminalHost te )
{
2014-09-24 02:26:27 +02:00
this( inventoryPlayer, te, new ContainerMEMonitorable( inventoryPlayer, te ) );
}
public GuiMEMonitorable( InventoryPlayer inventoryPlayer, ITerminalHost te, ContainerMEMonitorable c )
{
2014-09-24 02:26:27 +02:00
super( c );
2014-12-29 15:13:47 +01:00
this.myScrollBar = new GuiScrollbar();
this.repo = new ItemRepo( this.myScrollBar, this );
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.xSize = 185;
this.ySize = 204;
2014-09-24 02:26:27 +02:00
if( te instanceof IViewCellStorage )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.xSize += 33;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.standardSize = this.xSize;
2014-09-24 02:26:27 +02:00
this.configSrc = ( (IConfigurableObject) this.inventorySlots ).getConfigManager();
( this.monitorableContainer = (ContainerMEMonitorable) this.inventorySlots ).gui = this;
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.viewCell = te instanceof IViewCellStorage;
2014-09-24 02:26:27 +02:00
if( te instanceof TileSecurity )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.myName = GuiText.Security;
2015-04-29 02:30:53 +02:00
}
else if( te instanceof WirelessTerminalGuiObject )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.myName = GuiText.WirelessTerminal;
2015-04-29 02:30:53 +02:00
}
else if( te instanceof IPortableCell )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.myName = GuiText.PortableCell;
2015-04-29 02:30:53 +02:00
}
else if( te instanceof IMEChest )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.myName = GuiText.Chest;
2015-04-29 02:30:53 +02:00
}
else if( te instanceof PartTerminal )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.myName = GuiText.Terminal;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
public void postUpdate( List<IAEItemStack> list )
2014-09-24 02:26:27 +02:00
{
for( IAEItemStack is : list )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.repo.postUpdate( is );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.repo.updateView();
this.setScrollBar();
2014-09-24 02:26:27 +02:00
}
private void setScrollBar()
{
2014-12-29 15:13:47 +01:00
this.myScrollBar.setTop( 18 ).setLeft( 175 ).setHeight( this.rows * 18 - 2 );
this.myScrollBar.setRange( 0, ( this.repo.size() + this.perRow - 1 ) / this.perRow - this.rows, Math.max( 1, this.rows / 6 ) );
2014-09-24 02:26:27 +02:00
}
@Override
protected void actionPerformed( GuiButton btn )
2014-09-24 02:26:27 +02:00
{
if( btn == this.craftingStatusBtn )
{
NetworkHandler.instance.sendToServer( new PacketSwitchGuis( GuiBridge.GUI_CRAFTING_STATUS ) );
}
if( btn instanceof GuiImgButton )
{
boolean backwards = Mouse.isButtonDown( 1 );
GuiImgButton iBtn = (GuiImgButton) btn;
if( iBtn.getSetting() != Settings.ACTIONS )
{
Enum cv = iBtn.getCurrentValue();
Enum next = Platform.rotateEnum( cv, backwards, iBtn.getSetting().getPossibleValues() );
if( btn == this.terminalStyleBox )
2015-04-29 02:30:53 +02:00
{
AEConfig.instance.settings.putSetting( iBtn.getSetting(), next );
2015-04-29 02:30:53 +02:00
}
else if( btn == this.searchBoxSettings )
2015-04-29 02:30:53 +02:00
{
AEConfig.instance.settings.putSetting( iBtn.getSetting(), next );
2015-04-29 02:30:53 +02:00
}
else
{
try
{
NetworkHandler.instance.sendToServer( new PacketValueConfig( iBtn.getSetting().name(), next.name() ) );
}
catch( IOException e )
{
AELog.error( e );
}
}
iBtn.set( next );
if( next.getClass() == SearchBoxMode.class || next.getClass() == TerminalStyle.class )
2015-04-29 02:30:53 +02:00
{
this.re_init();
2015-04-29 02:30:53 +02:00
}
}
}
2014-09-24 02:26:27 +02:00
}
public void re_init()
2014-09-24 02:26:27 +02:00
{
this.buttonList.clear();
this.initGui();
2014-09-24 02:26:27 +02:00
}
@Override
public void initGui()
{
2014-12-29 15:13:47 +01:00
this.maxRows = this.getMaxRows();
this.perRow = AEConfig.instance.getConfigManager().getSetting( Settings.TERMINAL_STYLE ) != TerminalStyle.FULL ? 9 : 9 + ( ( this.width - this.standardSize ) / 18 );
2014-09-24 02:26:27 +02:00
boolean hasNEI = AppEng.instance.isIntegrationEnabled( IntegrationType.NEI );
int NEI = hasNEI ? 0 : 0;
int top = hasNEI ? 22 : 0;
int magicNumber = 114 + 1;
2014-12-29 15:13:47 +01:00
int extraSpace = this.height - magicNumber - NEI - top - this.reservedSpace;
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.rows = (int) Math.floor( extraSpace / 18 );
if( this.rows > this.maxRows )
2014-09-24 02:26:27 +02:00
{
top += ( this.rows - this.maxRows ) * 18 / 2;
2014-12-29 15:13:47 +01:00
this.rows = this.maxRows;
2014-09-24 02:26:27 +02:00
}
if( hasNEI )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.rows--;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
if( this.rows < 3 )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.rows = 3;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.meSlots.clear();
for( int y = 0; y < this.rows; y++ )
2014-09-24 02:26:27 +02:00
{
for( int x = 0; x < this.perRow; x++ )
2014-09-24 02:26:27 +02:00
{
2014-12-29 15:13:47 +01:00
this.meSlots.add( new InternalSlotME( this.repo, x + y * this.perRow, this.offsetX + x * 18, 18 + y * 18 ) );
2014-09-24 02:26:27 +02:00
}
}
if( AEConfig.instance.getConfigManager().getSetting( Settings.TERMINAL_STYLE ) != TerminalStyle.FULL )
2015-04-29 02:30:53 +02:00
{
this.xSize = this.standardSize + ( ( this.perRow - 9 ) * 18 );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
else
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.xSize = this.standardSize;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
super.initGui();
// full size : 204
// extra slots : 72
// slot 18
2014-12-29 15:13:47 +01:00
this.ySize = magicNumber + this.rows * 18 + this.reservedSpace;
2014-09-24 02:26:27 +02:00
// this.guiTop = top;
2014-12-29 15:13:47 +01:00
int unusedSpace = this.height - this.ySize;
this.guiTop = (int) Math.floor( unusedSpace / ( unusedSpace < 0 ? 3.8f : 2.0f ) );
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
int offset = this.guiTop + 8;
2014-09-24 02:26:27 +02:00
if( this.customSortOrder )
2014-09-24 02:26:27 +02:00
{
2014-12-29 15:13:47 +01:00
this.buttonList.add( this.SortByBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_BY, this.configSrc.getSetting( Settings.SORT_BY ) ) );
2014-09-24 02:26:27 +02:00
offset += 20;
}
if( this.viewCell || this instanceof GuiWirelessTerm )
2014-09-24 02:26:27 +02:00
{
2014-12-29 15:13:47 +01:00
this.buttonList.add( this.ViewBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.VIEW_MODE, this.configSrc.getSetting( Settings.VIEW_MODE ) ) );
2014-09-24 02:26:27 +02:00
offset += 20;
}
2014-12-29 15:13:47 +01:00
this.buttonList.add( this.SortDirBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.SORT_DIRECTION, this.configSrc.getSetting( Settings.SORT_DIRECTION ) ) );
2014-09-24 02:26:27 +02:00
offset += 20;
this.buttonList.add( this.searchBoxSettings = new GuiImgButton( this.guiLeft - 18, offset, Settings.SEARCH_MODE, AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE ) ) );
2014-09-24 02:26:27 +02:00
offset += 20;
if( !( this instanceof GuiMEPortableCell ) || this instanceof GuiWirelessTerm )
2014-09-24 02:26:27 +02:00
{
this.buttonList.add( this.terminalStyleBox = new GuiImgButton( this.guiLeft - 18, offset, Settings.TERMINAL_STYLE, AEConfig.instance.settings.getSetting( Settings.TERMINAL_STYLE ) ) );
2014-09-24 02:26:27 +02:00
}
2014-12-29 15:13:47 +01:00
this.searchField = new MEGuiTextField( this.fontRendererObj, this.guiLeft + Math.max( 80, this.offsetX ), this.guiTop + 4, 90, 12 );
this.searchField.setEnableBackgroundDrawing( false );
this.searchField.setMaxStringLength( 25 );
this.searchField.setTextColor( 0xFFFFFF );
this.searchField.setVisible( true );
2014-09-24 02:26:27 +02:00
if( this.viewCell || this instanceof GuiWirelessTerm )
2014-09-24 02:26:27 +02:00
{
this.buttonList.add( this.craftingStatusBtn = new GuiTabButton( this.guiLeft + 170, this.guiTop - 4, 2 + 11 * 16, GuiText.CraftingStatus.getLocal(), itemRender ) );
2014-12-29 15:13:47 +01:00
this.craftingStatusBtn.hideEdge = 13;
2014-09-24 02:26:27 +02:00
}
2015-01-01 22:13:10 +01:00
// Enum setting = AEConfig.INSTANCE.getSetting( "Terminal", SearchBoxMode.class, SearchBoxMode.AUTOSEARCH );
2014-09-24 02:26:27 +02:00
Enum setting = AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE );
2014-12-29 15:13:47 +01:00
this.searchField.setFocused( SearchBoxMode.AUTOSEARCH == setting || SearchBoxMode.NEI_AUTOSEARCH == setting );
2014-09-24 02:26:27 +02:00
if( this.isSubGui() )
2014-09-24 02:26:27 +02:00
{
2014-12-29 15:13:47 +01:00
this.searchField.setText( memoryText );
this.repo.searchString = memoryText;
this.repo.updateView();
this.setScrollBar();
2014-09-24 02:26:27 +02:00
}
CraftingGridOffsetX = Integer.MAX_VALUE;
CraftingGridOffsetY = Integer.MAX_VALUE;
for( Object s : this.inventorySlots.inventorySlots )
2014-09-24 02:26:27 +02:00
{
if( s instanceof AppEngSlot )
2014-09-24 02:26:27 +02:00
{
2015-05-09 00:00:52 +02:00
if( ( (Slot) s ).xDisplayPosition < 197 )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.repositionSlot( (AppEngSlot) s );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
if( s instanceof SlotCraftingMatrix || s instanceof SlotFakeCraftingMatrix )
2014-09-24 02:26:27 +02:00
{
Slot g = (Slot) s;
if( g.xDisplayPosition > 0 && g.yDisplayPosition > 0 )
2014-09-24 02:26:27 +02:00
{
CraftingGridOffsetX = Math.min( CraftingGridOffsetX, g.xDisplayPosition );
CraftingGridOffsetY = Math.min( CraftingGridOffsetY, g.yDisplayPosition );
}
}
}
CraftingGridOffsetX -= 25;
CraftingGridOffsetY -= 6;
}
@Override
public void drawFG( int offsetX, int offsetY, int mouseX, int mouseY )
2014-09-24 02:26:27 +02:00
{
this.fontRendererObj.drawString( this.getGuiDisplayName( this.myName.getLocal() ), 8, 6, 4210752 );
this.fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752 );
2014-09-24 02:26:27 +02:00
}
@Override
protected void mouseClicked( int xCoord, int yCoord, int btn )
2014-09-24 02:26:27 +02:00
{
Enum searchMode = AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE );
if( searchMode != SearchBoxMode.AUTOSEARCH && searchMode != SearchBoxMode.NEI_AUTOSEARCH )
2014-11-26 15:29:25 +01:00
{
2014-12-29 15:13:47 +01:00
this.searchField.mouseClicked( xCoord, yCoord, btn );
2014-11-26 15:29:25 +01:00
}
2014-09-24 02:26:27 +02:00
if( btn == 1 && this.searchField.isMouseIn( xCoord, yCoord ) )
2014-09-24 02:26:27 +02:00
{
2014-12-29 15:13:47 +01:00
this.searchField.setText( "" );
this.repo.searchString = "";
this.repo.updateView();
this.setScrollBar();
2014-09-24 02:26:27 +02:00
}
super.mouseClicked( xCoord, yCoord, btn );
}
@Override
public void onGuiClosed()
2014-09-24 02:26:27 +02:00
{
super.onGuiClosed();
memoryText = this.searchField.getText();
2014-09-24 02:26:27 +02:00
}
@Override
public void drawBG( int offsetX, int offsetY, int mouseX, int mouseY )
2014-09-24 02:26:27 +02:00
{
int x_width = 197;
2014-12-29 15:13:47 +01:00
this.bindTexture( this.getBackground() );
2014-09-24 02:26:27 +02:00
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, x_width, 18 );
if( this.viewCell || ( this instanceof GuiSecurity ) )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
this.drawTexturedModalRect( offsetX + x_width, offsetY, x_width, 0, 46, 128 );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
for( int x = 0; x < this.rows; x++ )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
this.drawTexturedModalRect( offsetX, offsetY + 18 + x * 18, 0, 18, x_width, 18 );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.drawTexturedModalRect( offsetX, offsetY + 16 + this.rows * 18 + this.lowerTextureOffset, 0, 106 - 18 - 18, x_width, 99 + this.reservedSpace - this.lowerTextureOffset );
2014-09-24 02:26:27 +02:00
if( this.viewCell )
2014-09-24 02:26:27 +02:00
{
boolean update = false;
for( int i = 0; i < 5; i++ )
2014-09-24 02:26:27 +02:00
{
if( this.myCurrentViewCells[i] != this.monitorableContainer.cellView[i].getStack() )
2014-09-24 02:26:27 +02:00
{
update = true;
2014-12-29 15:13:47 +01:00
this.myCurrentViewCells[i] = this.monitorableContainer.cellView[i].getStack();
2014-09-24 02:26:27 +02:00
}
}
if( update )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.repo.setViewCell( this.myCurrentViewCells );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
if( this.searchField != null )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.searchField.drawTextBox();
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
protected String getBackground()
{
return "guis/terminal.png";
}
@Override
protected boolean isPowered()
2014-09-24 02:26:27 +02:00
{
return this.repo.hasPower();
}
int getMaxRows()
{
return AEConfig.instance.getConfigManager().getSetting( Settings.TERMINAL_STYLE ) == TerminalStyle.SMALL ? 6 : Integer.MAX_VALUE;
}
protected void repositionSlot( AppEngSlot s )
{
s.yDisplayPosition = s.defY + this.ySize - 78 - 5;
}
@Override
protected void keyTyped( char character, int key )
{
if( !this.checkHotbarKeys( key ) )
{
if( character == ' ' && this.searchField.getText().length() == 0 )
2015-04-29 02:30:53 +02:00
{
return;
2015-04-29 02:30:53 +02:00
}
if( this.searchField.textboxKeyTyped( character, key ) )
{
this.repo.searchString = this.searchField.getText();
this.repo.updateView();
this.setScrollBar();
}
else
{
super.keyTyped( character, key );
}
}
}
@Override
public void updateScreen()
{
this.repo.setPower( this.monitorableContainer.hasPower );
super.updateScreen();
2014-09-24 02:26:27 +02:00
}
@Override
public Enum getSortBy()
{
2014-12-29 15:13:47 +01:00
return this.configSrc.getSetting( Settings.SORT_BY );
2014-09-24 02:26:27 +02:00
}
@Override
public Enum getSortDir()
{
2014-12-29 15:13:47 +01:00
return this.configSrc.getSetting( Settings.SORT_DIRECTION );
2014-09-24 02:26:27 +02:00
}
@Override
public Enum getSortDisplay()
{
2014-12-29 15:13:47 +01:00
return this.configSrc.getSetting( Settings.VIEW_MODE );
2014-09-24 02:26:27 +02:00
}
@Override
public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue )
2014-09-24 02:26:27 +02:00
{
if( this.SortByBox != null )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.SortByBox.set( this.configSrc.getSetting( Settings.SORT_BY ) );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
if( this.SortDirBox != null )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.SortDirBox.set( this.configSrc.getSetting( Settings.SORT_DIRECTION ) );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
if( this.ViewBox != null )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.ViewBox.set( this.configSrc.getSetting( Settings.VIEW_MODE ) );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.repo.updateView();
2014-09-24 02:26:27 +02:00
}
}