improve GUI lag when displaying many items on terminals
This commit is contained in:
@@ -319,7 +319,6 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi
|
|||||||
this.searchField.setText(memoryText);
|
this.searchField.setText(memoryText);
|
||||||
this.searchField.selectAll();
|
this.searchField.selectAll();
|
||||||
this.repo.setSearchString(memoryText);
|
this.repo.setSearchString(memoryText);
|
||||||
this.repo.updateView();
|
|
||||||
this.setScrollBar();
|
this.setScrollBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,7 +380,6 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi
|
|||||||
if (btn == 1 && this.searchField.isMouseIn(xCoord, yCoord)) {
|
if (btn == 1 && this.searchField.isMouseIn(xCoord, yCoord)) {
|
||||||
this.searchField.setText("");
|
this.searchField.setText("");
|
||||||
this.repo.setSearchString("");
|
this.repo.setSearchString("");
|
||||||
this.repo.updateView();
|
|
||||||
this.setScrollBar();
|
this.setScrollBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,7 +474,6 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi
|
|||||||
|
|
||||||
if (this.searchField.textboxKeyTyped(character, key)) {
|
if (this.searchField.textboxKeyTyped(character, key)) {
|
||||||
this.repo.setSearchString(this.searchField.getText());
|
this.repo.setSearchString(this.searchField.getText());
|
||||||
this.repo.updateView();
|
|
||||||
this.setScrollBar();
|
this.setScrollBar();
|
||||||
// tell forge the key event is handled and should not be sent out
|
// tell forge the key event is handled and should not be sent out
|
||||||
this.keyHandled = mouseInGui;
|
this.keyHandled = mouseInGui;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import net.minecraft.item.ItemStack;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ import java.util.regex.Pattern;
|
|||||||
public class ItemRepo {
|
public class ItemRepo {
|
||||||
|
|
||||||
private final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
private final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||||
private final ArrayList<IAEItemStack> view = new ArrayList<>();
|
private List<IAEItemStack> view = new ArrayList<>();
|
||||||
private final IScrollSource src;
|
private final IScrollSource src;
|
||||||
private final ISortSource sortSrc;
|
private final ISortSource sortSrc;
|
||||||
|
|
||||||
@@ -56,6 +56,16 @@ public class ItemRepo {
|
|||||||
private String innerSearch = "";
|
private String innerSearch = "";
|
||||||
private boolean hasPower;
|
private boolean hasPower;
|
||||||
|
|
||||||
|
private Enum lastView;
|
||||||
|
private Enum lastSearchMode;
|
||||||
|
private Enum lastSortBy;
|
||||||
|
private Enum lastSortDir;
|
||||||
|
private String lastSearch = "";
|
||||||
|
|
||||||
|
private boolean resort = true;
|
||||||
|
private boolean changed = false;
|
||||||
|
|
||||||
|
|
||||||
public ItemRepo(final IScrollSource src, final ISortSource sortSrc) {
|
public ItemRepo(final IScrollSource src, final ISortSource sortSrc) {
|
||||||
this.src = src;
|
this.src = src;
|
||||||
this.sortSrc = sortSrc;
|
this.sortSrc = sortSrc;
|
||||||
@@ -83,6 +93,8 @@ public class ItemRepo {
|
|||||||
} else {
|
} else {
|
||||||
this.list.add(is);
|
this.list.add(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getItemCount(final IAEItemStack is) {
|
public long getItemCount(final IAEItemStack is) {
|
||||||
@@ -96,18 +108,84 @@ public class ItemRepo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateView() {
|
public void updateView() {
|
||||||
this.view.clear();
|
|
||||||
|
|
||||||
this.view.ensureCapacity(this.list.size());
|
|
||||||
|
|
||||||
final Enum viewMode = this.sortSrc.getSortDisplay();
|
final Enum viewMode = this.sortSrc.getSortDisplay();
|
||||||
|
|
||||||
|
if (lastView != viewMode) {
|
||||||
|
resort = true;
|
||||||
|
lastView = viewMode;
|
||||||
|
}
|
||||||
|
|
||||||
final Enum searchMode = AEConfig.instance().getConfigManager().getSetting(Settings.SEARCH_MODE);
|
final Enum searchMode = AEConfig.instance().getConfigManager().getSetting(Settings.SEARCH_MODE);
|
||||||
final boolean needsZeroCopy = viewMode == ViewItems.CRAFTABLE;
|
if (lastSearchMode != searchMode) {
|
||||||
|
resort = true;
|
||||||
|
lastSearchMode = searchMode;
|
||||||
|
}
|
||||||
|
|
||||||
if (searchMode == SearchBoxMode.JEI_AUTOSEARCH || searchMode == SearchBoxMode.JEI_MANUAL_SEARCH || searchMode == SearchBoxMode.JEI_AUTOSEARCH_KEEP || searchMode == SearchBoxMode.JEI_MANUAL_SEARCH_KEEP) {
|
if (searchMode == SearchBoxMode.JEI_AUTOSEARCH || searchMode == SearchBoxMode.JEI_MANUAL_SEARCH || searchMode == SearchBoxMode.JEI_AUTOSEARCH_KEEP || searchMode == SearchBoxMode.JEI_MANUAL_SEARCH_KEEP) {
|
||||||
this.updateJEI(this.searchString);
|
this.updateJEI(this.searchString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!lastSearch.equals(searchString)) {
|
||||||
|
resort = true;
|
||||||
|
lastSearch = searchString;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Enum sortBy = this.sortSrc.getSortBy();
|
||||||
|
final Enum sortDir = this.sortSrc.getSortDir();
|
||||||
|
|
||||||
|
if (lastSortBy != sortBy) {
|
||||||
|
resort = true;
|
||||||
|
lastSortBy = sortBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastSortDir != sortDir) {
|
||||||
|
resort = true;
|
||||||
|
lastSortDir = sortDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed || resort) {
|
||||||
|
changed = false;
|
||||||
|
resort = false;
|
||||||
|
|
||||||
|
view = new ArrayList<>();
|
||||||
|
|
||||||
|
ItemSorters.setDirection((appeng.api.config.SortDir) sortDir);
|
||||||
|
ItemSorters.init();
|
||||||
|
|
||||||
|
Comparator<IAEItemStack> c = getComparator(sortBy);
|
||||||
|
|
||||||
|
for (IAEItemStack is : this.list) {
|
||||||
|
addIAE(is, viewMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
view.sort(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Comparator<IAEItemStack> getComparator(Enum sortBy) {
|
||||||
|
Comparator<IAEItemStack> c;
|
||||||
|
|
||||||
|
if (sortBy == SortOrder.MOD) {
|
||||||
|
c = ItemSorters.CONFIG_BASED_SORT_BY_MOD;
|
||||||
|
} else if (sortBy == SortOrder.AMOUNT) {
|
||||||
|
c = ItemSorters.CONFIG_BASED_SORT_BY_SIZE;
|
||||||
|
} else if (sortBy == SortOrder.INVTWEAKS) {
|
||||||
|
if (InventoryBogoSortModule.isLoaded()) {
|
||||||
|
c = InventoryBogoSortModule.COMPARATOR;
|
||||||
|
} else {
|
||||||
|
c = ItemSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c = ItemSorters.CONFIG_BASED_SORT_BY_NAME;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addIAE(IAEItemStack is, Enum viewMode) {
|
||||||
|
|
||||||
|
final boolean needsZeroCopy = viewMode == ViewItems.CRAFTABLE;
|
||||||
|
|
||||||
final boolean terminalSearchToolTips = AEConfig.instance().getConfigManager().getSetting(Settings.SEARCH_TOOLTIPS) != YesNo.NO;
|
final boolean terminalSearchToolTips = AEConfig.instance().getConfigManager().getSetting(Settings.SEARCH_TOOLTIPS) != YesNo.NO;
|
||||||
|
|
||||||
boolean searchMod = false;
|
boolean searchMod = false;
|
||||||
@@ -129,76 +207,54 @@ public class ItemRepo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean notDone = false;
|
if (this.myPartitionList != null) {
|
||||||
for (IAEItemStack is : this.list) {
|
if (!this.myPartitionList.isListed(is)) {
|
||||||
if (this.myPartitionList != null) {
|
return;
|
||||||
if (!this.myPartitionList.isListed(is)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (viewMode == ViewItems.CRAFTABLE && !is.isCraftable()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (viewMode == ViewItems.STORED && is.getStackSize() == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String dspName = (searchMod ? Platform.getModId(is) : Platform.getItemDisplayName(is)).toLowerCase();
|
|
||||||
boolean foundMatchingItemStack = true;
|
|
||||||
|
|
||||||
for (String term : innerSearch.split(" ")) {
|
|
||||||
if (term.length() > 1 && (term.startsWith("-") || term.startsWith("!"))) {
|
|
||||||
term = term.substring(1);
|
|
||||||
if (dspName.contains(term)) {
|
|
||||||
foundMatchingItemStack = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (!dspName.contains(term)) {
|
|
||||||
foundMatchingItemStack = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (terminalSearchToolTips && !foundMatchingItemStack) {
|
|
||||||
final List<String> tooltip = Platform.getTooltip(is);
|
|
||||||
for (final String line : tooltip) {
|
|
||||||
if (m.matcher(line).find()) {
|
|
||||||
foundMatchingItemStack = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (foundMatchingItemStack) {
|
|
||||||
if (needsZeroCopy) {
|
|
||||||
is = is.copy();
|
|
||||||
is.setStackSize(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.view.add(is);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Enum SortBy = this.sortSrc.getSortBy();
|
if (viewMode == ViewItems.CRAFTABLE && !is.isCraftable()) {
|
||||||
final Enum SortDir = this.sortSrc.getSortDir();
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ItemSorters.setDirection((appeng.api.config.SortDir) SortDir);
|
if (viewMode == ViewItems.STORED && is.getStackSize() == 0) {
|
||||||
ItemSorters.init();
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (SortBy == SortOrder.MOD) {
|
final String dspName = (searchMod ? Platform.getModId(is) : Platform.getItemDisplayName(is)).toLowerCase();
|
||||||
Collections.sort(this.view, ItemSorters.CONFIG_BASED_SORT_BY_MOD);
|
boolean foundMatchingItemStack = true;
|
||||||
} else if (SortBy == SortOrder.AMOUNT) {
|
|
||||||
Collections.sort(this.view, ItemSorters.CONFIG_BASED_SORT_BY_SIZE);
|
for (String term : innerSearch.split(" ")) {
|
||||||
} else if (SortBy == SortOrder.INVTWEAKS) {
|
if (term.length() > 1 && (term.startsWith("-") || term.startsWith("!"))) {
|
||||||
if (InventoryBogoSortModule.isLoaded()) {
|
term = term.substring(1);
|
||||||
Collections.sort(this.view, InventoryBogoSortModule.COMPARATOR);
|
if (dspName.contains(term)) {
|
||||||
} else {
|
foundMatchingItemStack = false;
|
||||||
Collections.sort(this.view, ItemSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS);
|
break;
|
||||||
|
}
|
||||||
|
} else if (!dspName.contains(term)) {
|
||||||
|
foundMatchingItemStack = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (terminalSearchToolTips && !foundMatchingItemStack) {
|
||||||
|
final List<String> tooltip = Platform.getTooltip(is);
|
||||||
|
for (final String line : tooltip) {
|
||||||
|
if (m.matcher(line).find()) {
|
||||||
|
foundMatchingItemStack = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foundMatchingItemStack) {
|
||||||
|
if (needsZeroCopy) {
|
||||||
|
is = is.copy();
|
||||||
|
is.setStackSize(0);
|
||||||
|
this.view.add(is);
|
||||||
|
} else if (is.getStackSize() > 0) {
|
||||||
|
this.view.add(is);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Collections.sort(this.view, ItemSorters.CONFIG_BASED_SORT_BY_NAME);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user