Sorting buttons now work

Got the sorting buttons to work. Clicking on the arrow buttons on a
filter panel will now move that filter up or down in the filter list.
Without having made any changed to how filters are processed, filters
higher in the list will naturally be processed before later filters,
thereby making it like a priority system.
For example, if an item matches two filters, the higher priority filter
will take that item before the lower filter, in that way seperating a
specific item from a broader (wildcard) specified filter.
This commit is contained in:
TehStoneMan 2015-04-05 23:03:56 +10:00
parent 50e72bc381
commit 293b8c08f1
3 changed files with 48 additions and 4 deletions

View file

@ -210,12 +210,28 @@ public class GuiLogisticalSorter extends GuiMekanism
final int arrowX = filterX + filterW - 12;
if( getFilterIndex() + i > 0 )
if( xAxis >= arrowX && xAxis <= arrowX + 10 && yAxis >= yStart + 14 && yAxis <= yStart + 20 )
{
// Process up button click
final ArrayList data = new ArrayList();
data.add( 3 );
data.add( getFilterIndex() + i );
Mekanism.packetHandler.sendToServer( new TileEntityMessage( Coord4D.get( tileEntity ), data ) );
SoundHandler.playSound( "gui.button.press" );
return;
}
if( getFilterIndex() + i < tileEntity.filters.size() - 1 )
if( xAxis >= arrowX && xAxis <= arrowX + 10 && yAxis >= yStart + 21 && yAxis <= yStart + 27 )
{
// Process down button click
final ArrayList data = new ArrayList();
data.add( 4 );
data.add( getFilterIndex() + i );
Mekanism.packetHandler.sendToServer( new TileEntityMessage( Coord4D.get( tileEntity ), data ) );
SoundHandler.playSound( "gui.button.press" );
return;
}
final TransporterFilter filter = tileEntity.filters.get( getFilterIndex() + i );

View file

@ -3,6 +3,8 @@ package mekanism.common;
import java.util.ArrayList;
import java.util.Iterator;
import mekanism.common.content.transporter.TransporterFilter;
public class HashList<T> implements Iterable<T>
{
private ArrayList<T> list = new ArrayList<T>(256);
@ -91,6 +93,19 @@ public class HashList<T> implements Iterable<T>
return list.size();
}
public void swap( int source, int target )
{
// Make sure both source and target ar legal values
if( source == target ) return;
if( source < 0 || target < 0 ) return;
if( source >= list.size() || target >= list.size() ) return;
// Perform swap
T temp = list.get( source );
list.set( source, list.get( target ) );
list.set( target, temp );
}
@Override
public int hashCode()
{

View file

@ -3,6 +3,8 @@ package mekanism.common.tile;
import java.util.ArrayList;
import java.util.EnumSet;
import com.sun.media.jfxmedia.logging.Logger;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.IFilterAccess;
@ -23,7 +25,6 @@ import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.util.InventoryUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.TransporterUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IInventory;
@ -33,7 +34,6 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.Constants.NBT;
import net.minecraftforge.common.util.ForgeDirection;
import io.netty.buffer.ByteBuf;
public class TileEntityLogisticalSorter extends TileEntityElectricBlock implements IRedstoneControl, IActiveState, IFilterAccess, ISustainedData
@ -292,7 +292,20 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
roundRobin = !roundRobin;
rrIndex = 0;
}
else if(type == 3)
{
// Move filter up
int filterIndex = dataStream.readInt();
filters.swap( filterIndex, filterIndex - 1 );
openInventory();
}
else if(type == 4)
{
// Move filter down
int filterIndex = dataStream.readInt();
filters.swap( filterIndex, filterIndex + 1 );
openInventory();
}
return;
}