Skip to content

Commit

Permalink
hold the shift to stop sort items (#188)
Browse files Browse the repository at this point in the history
Co-authored-by: zy <[email protected]>
  • Loading branch information
asdflj and zy authored Jan 2, 2024
1 parent 6187a73 commit 0bf904f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 33 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
dependencies {
api('com.github.GTNewHorizons:NotEnoughItems:2.4.13-GTNH:dev')
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-306-GTNH:dev')
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-307-GTNH:dev')
api('curse.maven:cofh-core-69162:2388751')
api('com.github.GTNewHorizons:waila:1.6.5:dev')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
protected GuiImgButton terminalStyleBox;
protected GuiImgButton searchStringSave;
protected GuiImgButton typeFilter;
protected boolean hasShiftKeyDown = false;

@SuppressWarnings("unchecked")
public FCGuiMonitor(final InventoryPlayer inventoryPlayer, final ITerminalHost te, final FCContainerMonitor<T> c) {
Expand Down Expand Up @@ -772,4 +773,14 @@ public boolean hideItemPanelSlot(int tx, int ty, int tw, int th) {
public boolean isOverTextField(int mousex, int mousey) {
return searchField.isMouseIn(mousex, mousey);
}

@Override
public void handleKeyboardInput() {
super.handleKeyboardInput();
hasShiftKeyDown |= isShiftKeyDown();
if (hasShiftKeyDown && !Keyboard.getEventKeyState()) { // keyup
this.repo.updateView();
hasShiftKeyDown = false;
}
}
}
36 changes: 20 additions & 16 deletions src/main/java/com/glodblock/github/client/me/EssentiaRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public EssentiaRepo(final IScrollSource src, final ISortSource sortSrc) {

@Override
public void updateView() {
this.view.clear();
if (needUpdateView()) this.view.clear();
this.dsp.clear();

this.view.ensureCapacity(this.list.size());
Expand Down Expand Up @@ -58,7 +58,7 @@ public void updateView() {
}
}

for (IAEItemStack is : this.list) {
for (IAEItemStack is : needUpdateView() ? this.list : this.cache) {
if (this.myPartitionList != null) {
if (!this.myPartitionList.isListed(is)) {
continue;
Expand Down Expand Up @@ -87,26 +87,30 @@ public void updateView() {
this.view.add(is);
}
}

final Enum<?> SortBy = this.sortSrc.getSortBy();
final Enum<?> SortDir = this.sortSrc.getSortDir();

FluidSorters.setDirection((appeng.api.config.SortDir) SortDir);
FluidSorters.init();

if (SortBy == SortOrder.MOD) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_MOD);
} else if (SortBy == SortOrder.AMOUNT) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_SIZE);
} else if (SortBy == SortOrder.INVTWEAKS) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS);
if (needUpdateView()) {
final Enum<?> SortBy = this.sortSrc.getSortBy();
final Enum<?> SortDir = this.sortSrc.getSortDir();

FluidSorters.setDirection((appeng.api.config.SortDir) SortDir);
FluidSorters.init();

if (SortBy == SortOrder.MOD) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_MOD);
} else if (SortBy == SortOrder.AMOUNT) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_SIZE);
} else if (SortBy == SortOrder.INVTWEAKS) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS);
} else {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_NAME);
}
} else {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_NAME);
this.cache.clear();
}

for (final IAEItemStack is : this.view) {
this.dsp.add(is.getItemStack());
}
this.lastSearchString = this.searchString;
Iterator<IAEItemStack> it1 = this.view.iterator();
while (it1.hasNext()) {
IAEFluidStack fluid = ItemFluidDrop.getAeFluidStack(it1.next());
Expand Down
48 changes: 32 additions & 16 deletions src/main/java/com/glodblock/github/client/me/FluidRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

package com.glodblock.github.client.me;

import static net.minecraft.client.gui.GuiScreen.isShiftKeyDown;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
Expand Down Expand Up @@ -45,12 +47,14 @@ public class FluidRepo implements IDisplayRepo {
protected final IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
protected final ArrayList<IAEItemStack> view = new ArrayList<>();
protected final ArrayList<ItemStack> dsp = new ArrayList<>();
protected final ArrayList<IAEItemStack> cache = new ArrayList<>();
protected final IScrollSource src;
protected final ISortSource sortSrc;

protected int rowSize = 9;

protected String searchString = "";
protected String lastSearchString = "";
protected IPartitionList<IAEItemStack> myPartitionList;
private String NEIWord = null;
private boolean hasPower;
Expand Down Expand Up @@ -86,11 +90,19 @@ public void postUpdate(final IAEItemStack is) {
if (st != null) {
st.reset();
st.add(is);
if (isShiftKeyDown() && this.view.contains(st)) {
this.view.get(this.view.indexOf(st)).setStackSize(st.getStackSize());
}
} else {
if (isShiftKeyDown()) this.cache.add(is);
this.list.add(is);
}
}

protected boolean needUpdateView() {
return !isShiftKeyDown() || !this.lastSearchString.equals(this.searchString);
}

@Override
public void setViewCell(final ItemStack[] list) {
this.myPartitionList = ItemViewCell.createFilter(list);
Expand All @@ -99,7 +111,7 @@ public void setViewCell(final ItemStack[] list) {

@Override
public void updateView() {
this.view.clear();
if (needUpdateView()) this.view.clear();
this.dsp.clear();

this.view.ensureCapacity(this.list.size());
Expand Down Expand Up @@ -130,7 +142,7 @@ public void updateView() {
}
}

for (IAEItemStack is : this.list) {
for (IAEItemStack is : needUpdateView() ? this.list : this.cache) {
if (this.myPartitionList != null) {
if (!this.myPartitionList.isListed(is)) {
continue;
Expand Down Expand Up @@ -167,26 +179,30 @@ public void updateView() {
}
}
}

final Enum<?> SortBy = this.sortSrc.getSortBy();
final Enum<?> SortDir = this.sortSrc.getSortDir();

FluidSorters.setDirection((appeng.api.config.SortDir) SortDir);
FluidSorters.init();

if (SortBy == SortOrder.MOD) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_MOD);
} else if (SortBy == SortOrder.AMOUNT) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_SIZE);
} else if (SortBy == SortOrder.INVTWEAKS) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS);
if (needUpdateView()) {
final Enum<?> SortBy = this.sortSrc.getSortBy();
final Enum<?> SortDir = this.sortSrc.getSortDir();

FluidSorters.setDirection((appeng.api.config.SortDir) SortDir);
FluidSorters.init();

if (SortBy == SortOrder.MOD) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_MOD);
} else if (SortBy == SortOrder.AMOUNT) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_SIZE);
} else if (SortBy == SortOrder.INVTWEAKS) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS);
} else {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_NAME);
}
} else {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_NAME);
this.cache.clear();
}

for (final IAEItemStack is : this.view) {
this.dsp.add(is.getItemStack());
}
this.lastSearchString = this.searchString;
}

protected void updateNEI(final String filter) {
Expand Down

0 comments on commit 0bf904f

Please sign in to comment.