2013-12-27 23:59:59 +01:00
|
|
|
package appeng.client.me;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2014-03-04 08:52:07 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-02-21 21:36:40 +01:00
|
|
|
import appeng.api.AEApi;
|
2014-03-04 08:52:07 +01:00
|
|
|
import appeng.api.config.FuzzyMode;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.config.Settings;
|
|
|
|
import appeng.api.config.SortOrder;
|
2014-03-04 08:52:07 +01:00
|
|
|
import appeng.api.config.Upgrades;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.config.YesNo;
|
2014-03-04 08:52:07 +01:00
|
|
|
import appeng.api.implementations.items.IUpgradeModule;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
import appeng.api.storage.data.IItemList;
|
|
|
|
import appeng.client.gui.widgets.IScrollSource;
|
2014-02-06 06:08:05 +01:00
|
|
|
import appeng.client.gui.widgets.ISortSource;
|
2014-02-09 06:08:27 +01:00
|
|
|
import appeng.core.AEConfig;
|
2014-03-04 08:52:07 +01:00
|
|
|
import appeng.items.storage.ItemViewCell;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.util.ItemSorters;
|
|
|
|
import appeng.util.Platform;
|
2014-03-04 08:52:07 +01:00
|
|
|
import appeng.util.item.AEItemStack;
|
|
|
|
import appeng.util.prioitylist.FuzzyPriorityList;
|
|
|
|
import appeng.util.prioitylist.IPartitionList;
|
2014-03-05 04:12:23 +01:00
|
|
|
import appeng.util.prioitylist.MergedPriorityList;
|
2014-03-04 08:52:07 +01:00
|
|
|
import appeng.util.prioitylist.PrecisePriorityList;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
public class ItemRepo
|
|
|
|
{
|
|
|
|
|
2014-02-21 21:36:40 +01:00
|
|
|
final private IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
|
|
|
|
final private ArrayList<IAEItemStack> view = new ArrayList<IAEItemStack>();
|
|
|
|
final private ArrayList<ItemStack> dsp = new ArrayList<ItemStack>();
|
2013-12-27 23:59:59 +01:00
|
|
|
final private IScrollSource src;
|
2014-02-06 06:08:05 +01:00
|
|
|
final private ISortSource sortSrc;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
public int rowSize = 9;
|
|
|
|
|
|
|
|
public String searchString = "";
|
|
|
|
|
2014-02-06 06:08:05 +01:00
|
|
|
public ItemRepo(IScrollSource src, ISortSource sortSrc) {
|
2013-12-27 23:59:59 +01:00
|
|
|
this.src = src;
|
2014-02-06 06:08:05 +01:00
|
|
|
this.sortSrc = sortSrc;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public IAEItemStack getRefrenceItem(int idx)
|
|
|
|
{
|
|
|
|
idx += src.getCurrentScroll() * rowSize;
|
|
|
|
|
|
|
|
if ( idx >= view.size() )
|
|
|
|
return null;
|
|
|
|
return view.get( idx );
|
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack getItem(int idx)
|
|
|
|
{
|
|
|
|
idx += src.getCurrentScroll() * rowSize;
|
|
|
|
|
|
|
|
if ( idx >= dsp.size() )
|
|
|
|
return null;
|
|
|
|
return dsp.get( idx );
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSearch(String search)
|
|
|
|
{
|
|
|
|
searchString = search == null ? "" : search;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void postUpdate(IAEItemStack is)
|
|
|
|
{
|
|
|
|
IAEItemStack st = list.findPrecise( is );
|
|
|
|
|
|
|
|
if ( st != null )
|
|
|
|
{
|
|
|
|
st.reset();
|
|
|
|
st.add( is );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
list.add( is );
|
|
|
|
}
|
|
|
|
|
2014-03-04 08:52:07 +01:00
|
|
|
IPartitionList<IAEItemStack> myPartitionList;
|
|
|
|
|
2014-03-05 04:12:23 +01:00
|
|
|
public void setViewCell(ItemStack[] list)
|
2014-03-04 08:52:07 +01:00
|
|
|
{
|
2014-03-05 04:12:23 +01:00
|
|
|
myPartitionList = null;
|
|
|
|
MergedPriorityList<IAEItemStack> myMergedList = new MergedPriorityList<IAEItemStack>();
|
|
|
|
|
|
|
|
for (ItemStack currentViewCell : list)
|
2014-03-04 08:52:07 +01:00
|
|
|
{
|
2014-03-05 04:12:23 +01:00
|
|
|
if ( currentViewCell == null )
|
|
|
|
continue;
|
2014-03-04 08:52:07 +01:00
|
|
|
|
2014-03-05 04:12:23 +01:00
|
|
|
if ( (currentViewCell.getItem() instanceof ItemViewCell) )
|
|
|
|
{
|
|
|
|
boolean hasInverter = false;
|
|
|
|
boolean hasFuzzy = false;
|
|
|
|
IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
|
2014-03-04 08:52:07 +01:00
|
|
|
|
2014-03-05 04:12:23 +01:00
|
|
|
ItemViewCell vc = (ItemViewCell) currentViewCell.getItem();
|
|
|
|
IInventory upgrades = vc.getUpgradesInventory( currentViewCell );
|
|
|
|
IInventory config = vc.getConfigInventory( currentViewCell );
|
|
|
|
FuzzyMode fzMode = vc.getFuzzyMode( currentViewCell );
|
2014-03-04 08:52:07 +01:00
|
|
|
|
2014-03-05 04:12:23 +01:00
|
|
|
hasInverter = false;
|
|
|
|
hasFuzzy = false;
|
|
|
|
|
|
|
|
for (int x = 0; x < upgrades.getSizeInventory(); x++)
|
2014-03-04 08:52:07 +01:00
|
|
|
{
|
2014-03-05 04:12:23 +01:00
|
|
|
ItemStack is = upgrades.getStackInSlot( x );
|
|
|
|
if ( is != null && is.getItem() instanceof IUpgradeModule )
|
2014-03-04 08:52:07 +01:00
|
|
|
{
|
2014-03-05 04:12:23 +01:00
|
|
|
Upgrades u = ((IUpgradeModule) is.getItem()).getType( is );
|
|
|
|
if ( u != null )
|
2014-03-04 08:52:07 +01:00
|
|
|
{
|
2014-03-05 04:12:23 +01:00
|
|
|
switch (u)
|
|
|
|
{
|
|
|
|
case FUZZY:
|
|
|
|
hasFuzzy = true;
|
|
|
|
break;
|
|
|
|
case INVERTER:
|
|
|
|
hasInverter = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
2014-03-04 08:52:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 04:12:23 +01:00
|
|
|
for (int x = 0; x < config.getSizeInventory(); x++)
|
|
|
|
{
|
|
|
|
ItemStack is = config.getStackInSlot( x );
|
|
|
|
if ( is != null )
|
|
|
|
priorityList.add( AEItemStack.create( is ) );
|
|
|
|
}
|
2014-03-04 08:52:07 +01:00
|
|
|
|
2014-03-05 04:12:23 +01:00
|
|
|
if ( !priorityList.isEmpty() )
|
|
|
|
{
|
|
|
|
if ( hasFuzzy )
|
|
|
|
myMergedList.addNewList( new FuzzyPriorityList<IAEItemStack>( priorityList, fzMode ), !hasInverter );
|
|
|
|
else
|
|
|
|
myMergedList.addNewList( new PrecisePriorityList<IAEItemStack>( priorityList ), !hasInverter );
|
2014-03-04 08:52:07 +01:00
|
|
|
|
2014-03-05 04:12:23 +01:00
|
|
|
myPartitionList = myMergedList;
|
|
|
|
}
|
2014-03-04 08:52:07 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-05 04:12:23 +01:00
|
|
|
|
2014-03-04 08:52:07 +01:00
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public void updateView()
|
|
|
|
{
|
|
|
|
view.clear();
|
|
|
|
dsp.clear();
|
|
|
|
|
|
|
|
view.ensureCapacity( list.size() );
|
|
|
|
dsp.ensureCapacity( list.size() );
|
|
|
|
|
2014-02-09 06:08:27 +01:00
|
|
|
boolean terminalSearchToolTips = AEConfig.instance.settings.getSetting( Settings.SEARCH_TOOLTIPS ) != YesNo.NO;
|
2013-12-27 23:59:59 +01:00
|
|
|
// boolean terminalSearchMods = Configuration.instance.settings.getSetting( Settings.SEARCH_MODS ) != YesNo.NO;
|
|
|
|
|
|
|
|
Pattern m = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
m = Pattern.compile( searchString.toLowerCase(), Pattern.CASE_INSENSITIVE );
|
|
|
|
}
|
|
|
|
catch (Throwable _)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
m = Pattern.compile( Pattern.quote( searchString.toLowerCase() ), Pattern.CASE_INSENSITIVE );
|
|
|
|
}
|
|
|
|
catch (Throwable __)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean notDone = false;
|
|
|
|
for (IAEItemStack is : list)
|
|
|
|
{
|
2014-03-04 08:52:07 +01:00
|
|
|
if ( myPartitionList != null )
|
|
|
|
{
|
2014-03-05 04:12:23 +01:00
|
|
|
if ( !myPartitionList.isListed( is ) )
|
2014-03-04 08:52:07 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
String dspName = Platform.getItemDisplayName( is );
|
|
|
|
notDone = true;
|
|
|
|
|
2014-02-07 03:44:37 +01:00
|
|
|
if ( m.matcher( dspName ).find() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
view.add( is );
|
|
|
|
notDone = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( terminalSearchToolTips && notDone )
|
|
|
|
{
|
|
|
|
for (Object lp : Platform.getTooltip( is ))
|
|
|
|
if ( lp instanceof String && m.matcher( (String) lp ).find() )
|
|
|
|
{
|
|
|
|
view.add( is );
|
|
|
|
notDone = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if ( terminalSearchMods && notDone ) { if ( m.matcher( Platform.getMod( is.getItemStack() ) ).find() ) {
|
|
|
|
* view.add( is ); notDone = false; } }
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2014-02-06 06:08:05 +01:00
|
|
|
Enum SortBy = sortSrc.getSortBy();
|
|
|
|
Enum SortDir = sortSrc.getSortDir();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
ItemSorters.Direction = (appeng.api.config.SortDir) SortDir;
|
2014-02-27 08:10:11 +01:00
|
|
|
ItemSorters.init();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
if ( SortBy == SortOrder.AMOUNT )
|
|
|
|
Collections.sort( view, ItemSorters.ConfigBased_SortBySize );
|
2014-02-27 08:10:11 +01:00
|
|
|
else if ( SortBy == SortOrder.INVTWEAKS )
|
|
|
|
Collections.sort( view, ItemSorters.ConfigBased_SortByInvTweaks );
|
2013-12-27 23:59:59 +01:00
|
|
|
else
|
|
|
|
Collections.sort( view, ItemSorters.ConfigBased_SortByName );
|
|
|
|
|
|
|
|
for (IAEItemStack is : view)
|
|
|
|
dsp.add( is.getItemStack() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public int size()
|
|
|
|
{
|
|
|
|
return view.size();
|
|
|
|
}
|
2014-01-23 17:28:12 +01:00
|
|
|
|
|
|
|
public void clear()
|
|
|
|
{
|
|
|
|
list.resetStatus();
|
|
|
|
}
|
2014-03-04 08:52:07 +01:00
|
|
|
|
2014-03-28 05:31:06 +01:00
|
|
|
private boolean hasPower;
|
|
|
|
|
|
|
|
public boolean hasPower()
|
|
|
|
{
|
|
|
|
return hasPower;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPower(boolean hasPower)
|
|
|
|
{
|
|
|
|
this.hasPower = hasPower;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|