Merge pull request #203 from yueh/feature-129
Adds filter by machine name to interface terminals
This commit is contained in:
commit
da34968249
2 changed files with 148 additions and 68 deletions
|
@ -4,8 +4,8 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
@ -14,6 +14,7 @@ import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import appeng.client.gui.AEBaseGui;
|
import appeng.client.gui.AEBaseGui;
|
||||||
import appeng.client.gui.widgets.GuiScrollbar;
|
import appeng.client.gui.widgets.GuiScrollbar;
|
||||||
|
import appeng.client.gui.widgets.MEGuiTextField;
|
||||||
import appeng.client.me.ClientDCInternalInv;
|
import appeng.client.me.ClientDCInternalInv;
|
||||||
import appeng.client.me.SlotDisconnected;
|
import appeng.client.me.SlotDisconnected;
|
||||||
import appeng.container.implementations.ContainerInterfaceTerminal;
|
import appeng.container.implementations.ContainerInterfaceTerminal;
|
||||||
|
@ -25,33 +26,77 @@ import com.google.common.collect.HashMultimap;
|
||||||
public class GuiInterfaceTerminal extends AEBaseGui
|
public class GuiInterfaceTerminal extends AEBaseGui
|
||||||
{
|
{
|
||||||
|
|
||||||
final HashMap<Long, ClientDCInternalInv> byId = new HashMap<Long, ClientDCInternalInv>();
|
private static final int LINES_ON_PAGE = 6;
|
||||||
final HashMultimap<String, ClientDCInternalInv> byName = HashMultimap.create();
|
|
||||||
final ArrayList<String> names = new ArrayList<String>();
|
|
||||||
|
|
||||||
ArrayList<Object> lines = new ArrayList<Object>();
|
// TODO: copied from GuiMEMonitorable. It looks not changed, maybe unneeded?
|
||||||
|
int offsetX = 9;
|
||||||
|
|
||||||
private int getTotalRows()
|
private final HashMap<Long, ClientDCInternalInv> byId = new HashMap<Long, ClientDCInternalInv>();
|
||||||
|
private final HashMultimap<String, ClientDCInternalInv> byName = HashMultimap.create();
|
||||||
|
private final ArrayList<String> names = new ArrayList<String>();
|
||||||
|
private final ArrayList<Object> lines = new ArrayList<Object>();
|
||||||
|
private final EntityPlayer player;
|
||||||
|
|
||||||
|
private boolean refreshList = false;
|
||||||
|
private MEGuiTextField searchField;
|
||||||
|
|
||||||
|
public GuiInterfaceTerminal(InventoryPlayer inventoryPlayer, PartMonitor te)
|
||||||
{
|
{
|
||||||
return names.size() + byId.size();// unique names, and each inv row.
|
|
||||||
}
|
|
||||||
|
|
||||||
public GuiInterfaceTerminal(InventoryPlayer inventoryPlayer, PartMonitor te) {
|
|
||||||
super( new ContainerInterfaceTerminal( inventoryPlayer, te ) );
|
super( new ContainerInterfaceTerminal( inventoryPlayer, te ) );
|
||||||
|
this.player = inventoryPlayer.player;
|
||||||
myScrollBar = new GuiScrollbar();
|
myScrollBar = new GuiScrollbar();
|
||||||
xSize = 195;
|
xSize = 195;
|
||||||
ySize = 222;
|
ySize = 222;
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkedList<SlotDisconnected> dcSlots = new LinkedList<SlotDisconnected>();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initGui()
|
public void initGui()
|
||||||
{
|
{
|
||||||
super.initGui();
|
super.initGui();
|
||||||
|
|
||||||
myScrollBar.setLeft( 175 );
|
myScrollBar.setLeft( 175 );
|
||||||
myScrollBar.setHeight( 106 );
|
myScrollBar.setHeight( 106 );
|
||||||
myScrollBar.setTop( 18 );
|
myScrollBar.setTop( 18 );
|
||||||
|
|
||||||
|
searchField = new MEGuiTextField( fontRendererObj, this.guiLeft + Math.max( 107, offsetX ), this.guiTop + 6, 64, fontRendererObj.FONT_HEIGHT );
|
||||||
|
searchField.setEnableBackgroundDrawing( false );
|
||||||
|
searchField.setMaxStringLength( 25 );
|
||||||
|
searchField.setTextColor( 0xFFFFFF );
|
||||||
|
searchField.setVisible( true );
|
||||||
|
searchField.setFocused( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void mouseClicked(int xCoord, int yCoord, int btn)
|
||||||
|
{
|
||||||
|
searchField.mouseClicked( xCoord, yCoord, btn );
|
||||||
|
|
||||||
|
if ( btn == 1 && searchField.isMouseIn( xCoord, yCoord ) )
|
||||||
|
{
|
||||||
|
searchField.setText( "" );
|
||||||
|
refreshList();
|
||||||
|
}
|
||||||
|
|
||||||
|
super.mouseClicked( xCoord, yCoord, btn );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void keyTyped(char character, int key)
|
||||||
|
{
|
||||||
|
if ( !this.checkHotbarKeys( key ) )
|
||||||
|
{
|
||||||
|
if ( character == ' ' && this.searchField.getText().length() == 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( searchField.textboxKeyTyped( character, key ) )
|
||||||
|
{
|
||||||
|
refreshList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
super.keyTyped( character, key );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -62,24 +107,23 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||||
|
|
||||||
int offset = 17;
|
int offset = 17;
|
||||||
int ex = myScrollBar.getCurrentScroll();
|
int ex = myScrollBar.getCurrentScroll();
|
||||||
int linesOnPage = 6;
|
|
||||||
|
|
||||||
for (int x = 0; x < linesOnPage; x++)
|
for (int x = 0; x < LINES_ON_PAGE && ex + x < lines.size(); x++)
|
||||||
{
|
{
|
||||||
if ( ex + x < lines.size() )
|
Object lineObj = lines.get( ex + x );
|
||||||
|
if ( lineObj instanceof ClientDCInternalInv )
|
||||||
{
|
{
|
||||||
Object lineObj = lines.get( ex + x );
|
ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
|
||||||
if ( lineObj instanceof ClientDCInternalInv )
|
|
||||||
{
|
|
||||||
ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
|
|
||||||
|
|
||||||
GL11.glColor4f( 1, 1, 1, 1 );
|
GL11.glColor4f( 1, 1, 1, 1 );
|
||||||
for (int z = 0; z < inv.inv.getSizeInventory(); z++)
|
for (int z = 0; z < inv.inv.getSizeInventory(); z++)
|
||||||
this.drawTexturedModalRect( offsetX + z * 18 + 7, offsetY + offset, 7, 139, 18, 18 );
|
this.drawTexturedModalRect( offsetX + z * 18 + 7, offsetY + offset, 7, 139, 18, 18 );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
offset += 18;
|
offset += 18;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( searchField != null )
|
||||||
|
searchField.drawTextBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -89,10 +133,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||||
fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 );
|
fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 );
|
||||||
|
|
||||||
int offset = 17;
|
int offset = 17;
|
||||||
|
|
||||||
// for (String name : lines)
|
|
||||||
int ex = myScrollBar.getCurrentScroll();
|
int ex = myScrollBar.getCurrentScroll();
|
||||||
int linesOnPage = 6;
|
|
||||||
|
|
||||||
Iterator<Object> o = inventorySlots.inventorySlots.iterator();
|
Iterator<Object> o = inventorySlots.inventorySlots.iterator();
|
||||||
while (o.hasNext())
|
while (o.hasNext())
|
||||||
|
@ -101,38 +142,33 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||||
o.remove();
|
o.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int x = 0; x < linesOnPage; x++)
|
for (int x = 0; x < LINES_ON_PAGE && ex + x < lines.size(); x++)
|
||||||
{
|
{
|
||||||
if ( ex + x < lines.size() )
|
Object lineObj = lines.get( ex + x );
|
||||||
|
if ( lineObj instanceof ClientDCInternalInv )
|
||||||
{
|
{
|
||||||
Object lineObj = lines.get( ex + x );
|
ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
|
||||||
if ( lineObj instanceof ClientDCInternalInv )
|
for (int z = 0; z < inv.inv.getSizeInventory(); z++)
|
||||||
{
|
{
|
||||||
ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
|
inventorySlots.inventorySlots.add( new SlotDisconnected( inv, z, z * 18 + 8, 1 + offset ) );
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean refreshList = false;
|
|
||||||
|
|
||||||
public void postUpdate(NBTTagCompound in)
|
public void postUpdate(NBTTagCompound in)
|
||||||
{
|
{
|
||||||
if ( in.getBoolean( "clear" ) )
|
if ( in.getBoolean( "clear" ) )
|
||||||
|
@ -168,34 +204,78 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||||
if ( refreshList )
|
if ( refreshList )
|
||||||
{
|
{
|
||||||
refreshList = false;
|
refreshList = false;
|
||||||
|
refreshList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
byName.clear();
|
/**
|
||||||
for (ClientDCInternalInv o : byId.values())
|
* rebuilds the list of interfaces.
|
||||||
byName.put( o.getName(), o );
|
*
|
||||||
|
* Respects a search term if present (ignores case) and adding only matching patterns.
|
||||||
|
*/
|
||||||
|
private void refreshList()
|
||||||
|
{
|
||||||
|
byName.clear();
|
||||||
|
|
||||||
names.clear();
|
final String searchFilterLowerCase = searchField.getText().toLowerCase();
|
||||||
names.addAll( byName.keySet() );
|
|
||||||
|
|
||||||
Collections.sort( names );
|
for (ClientDCInternalInv entry : byId.values())
|
||||||
|
{
|
||||||
|
// Shortcut to skip any filter if search term is ""/empty
|
||||||
|
boolean found = searchFilterLowerCase.isEmpty();
|
||||||
|
|
||||||
lines = new ArrayList<Object>( getTotalRows() );
|
// Search if the current inventory holds a pattern containing the search term.
|
||||||
for (String n : names)
|
if ( !found && !searchFilterLowerCase.equals( "" ) )
|
||||||
{
|
{
|
||||||
lines.add( n );
|
for (ItemStack itemStack : entry.inv)
|
||||||
|
|
||||||
ArrayList<ClientDCInternalInv> clientInventories = new ArrayList<ClientDCInternalInv>();
|
|
||||||
clientInventories.addAll( byName.get( n ) );
|
|
||||||
|
|
||||||
Collections.sort( clientInventories );
|
|
||||||
|
|
||||||
for (ClientDCInternalInv i : clientInventories)
|
|
||||||
{
|
{
|
||||||
lines.add( i );
|
if ( itemStack != null )
|
||||||
|
{
|
||||||
|
String tooltipLowerCase = String.valueOf( itemStack.getTooltip( player, false ) ).toLowerCase();
|
||||||
|
if ( tooltipLowerCase.contains( searchFilterLowerCase ) )
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
myScrollBar.setRange( 0, getTotalRows() - 6, 2 );
|
// if found, filter skipped or machine name matching the search term, add it
|
||||||
|
if ( found || entry.getName().toLowerCase().contains( searchFilterLowerCase ) )
|
||||||
|
byName.put( entry.getName(), entry );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
names.clear();
|
||||||
|
names.addAll( byName.keySet() );
|
||||||
|
|
||||||
|
Collections.sort( names );
|
||||||
|
|
||||||
|
lines.clear();
|
||||||
|
lines.ensureCapacity( getMaxRows() );
|
||||||
|
|
||||||
|
for (String n : names)
|
||||||
|
{
|
||||||
|
lines.add( n );
|
||||||
|
|
||||||
|
ArrayList<ClientDCInternalInv> clientInventories = new ArrayList<ClientDCInternalInv>();
|
||||||
|
clientInventories.addAll( byName.get( n ) );
|
||||||
|
|
||||||
|
Collections.sort( clientInventories );
|
||||||
|
lines.addAll( clientInventories );
|
||||||
|
}
|
||||||
|
|
||||||
|
myScrollBar.setRange( 0, lines.size() - LINES_ON_PAGE, 2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The max amount of unique names and each inv row. Not affected by the filtering.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int getMaxRows()
|
||||||
|
{
|
||||||
|
return names.size() + byId.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClientDCInternalInv getById(long id, long sortBy, String string)
|
private ClientDCInternalInv getById(long id, long sortBy, String string)
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 1.9 KiB |
Loading…
Reference in a new issue