Skip to content

Commit

Permalink
Feature: option to hide "stored" items in ae2 crafting plan (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
lordIcocain authored Dec 23, 2024
1 parent c1dee9a commit 0f57617
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/java/appeng/api/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public enum Settings {
LEVEL_TYPE(EnumSet.allOf(LevelType.class)),

TERMINAL_STYLE(EnumSet.of(TerminalStyle.TALL, TerminalStyle.SMALL)),
HIDE_STORED(EnumSet.of(YesNo.YES, YesNo.NO)),
COPY_MODE(EnumSet.allOf(CopyMode.class)),

INTERFACE_TERMINAL(EnumSet.of(YesNo.YES, YesNo.NO)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@
import com.google.common.base.Joiner;

import appeng.api.AEApi;
import appeng.api.config.Settings;
import appeng.api.config.SortDir;
import appeng.api.config.SortOrder;
import appeng.api.config.ViewItems;
import appeng.api.config.YesNo;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.DimensionalCoord;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.IGuiTooltipHandler;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.gui.widgets.GuiScrollbar;
import appeng.client.gui.widgets.ISortSource;
import appeng.client.gui.widgets.ITooltip;
Expand Down Expand Up @@ -158,6 +161,9 @@ public int getStringWidth() {

protected List<IAEItemStack> visual = new ArrayList<>();
private GuiButton cancel;
protected List<IAEItemStack> visualHiddenStored = new ArrayList<>();
protected GuiImgButton toggleHideStored;
protected boolean hideStored;
private int tooltip = -1;
private final RemainingOperations remainingOperations = new RemainingOperations();
private ItemStack hoveredStack;
Expand All @@ -172,6 +178,7 @@ protected GuiCraftingCPU(final ContainerCraftingCPU container) {
this.craftingCpu = container;
this.ySize = GUI_HEIGHT;
this.xSize = GUI_WIDTH;
this.hideStored = AEConfig.instance.getConfigManager().getSetting(Settings.HIDE_STORED) == YesNo.YES;

final GuiScrollbar scrollbar = new GuiScrollbar();
this.setScrollBar(scrollbar);
Expand All @@ -182,19 +189,27 @@ public void clearItems() {
this.active = AEApi.instance().storage().createItemList();
this.pending = AEApi.instance().storage().createItemList();
this.visual = new ArrayList<>();
this.visualHiddenStored = new ArrayList<>();
}

@Override
protected void actionPerformed(final GuiButton btn) {
super.actionPerformed(btn);

if (this.cancel == btn) {
try {
NetworkHandler.instance.sendToServer(new PacketValueConfig("TileCrafting.Cancel", "Cancel"));
} catch (final IOException e) {
AELog.debug(e);
}
}
if (this.toggleHideStored == btn) {
this.hideStored ^= true;
AEConfig.instance.getConfigManager().putSetting(Settings.HIDE_STORED, hideStored ? YesNo.YES : YesNo.NO);
this.toggleHideStored.set(hideStored ? YesNo.YES : YesNo.NO);
hideStoredSorting();
this.setScrollBar();
}

}

@Override
Expand Down Expand Up @@ -224,12 +239,22 @@ public void initGui() {
CANCEL_WIDTH,
CANCEL_HEIGHT,
GuiText.Cancel.getLocal());
this.toggleHideStored = new GuiImgButton(
this.guiLeft + 221,
this.guiTop + this.ySize - 19,
Settings.HIDE_STORED,
AEConfig.instance.getConfigManager().getSetting(Settings.HIDE_STORED));
this.buttonList.add(this.toggleHideStored);
this.buttonList.add(this.cancel);
}

private void setScrollBar() {
final int size = this.visual.size();

int size;
if (this.hideStored) {
size = this.visualHiddenStored.size();
} else {
size = this.visual.size();
}
this.getScrollBar().setTop(SCROLLBAR_TOP).setLeft(SCROLLBAR_LEFT).setHeight(SCROLLBAR_HEIGHT);
this.getScrollBar().setRange(0, (size + 2) / ITEMS_PER_ROW - rows, 1);
}
Expand Down Expand Up @@ -323,8 +348,14 @@ public void drawFG(final int offsetX, final int offsetY, final int mouseX, final
final int offY = 23;

final ReadableNumberConverter converter = ReadableNumberConverter.INSTANCE;
for (int z = viewStart; z < Math.min(viewEnd, this.visual.size()); z++) {
final IAEItemStack refStack = this.visual.get(z); // repo.getReferenceItem( z );
List<IAEItemStack> visualTemp;
if (this.hideStored) {
visualTemp = this.visualHiddenStored;
} else {
visualTemp = this.visual;
}
for (int z = viewStart; z < Math.min(viewEnd, visualTemp.size()); z++) {
final IAEItemStack refStack = visualTemp.get(z); // repo.getReferenceItem( z );
if (refStack != null) {
GL11.glPushMatrix();
GL11.glScaled(0.5, 0.5, 0.5);
Expand Down Expand Up @@ -533,6 +564,7 @@ public void postUpdate(final List<IAEItemStack> list, final byte ref) {
}
}

if (this.hideStored) this.hideStoredSorting();
this.setScrollBar();
}

Expand Down Expand Up @@ -621,4 +653,18 @@ public Enum getSortDisplay() {
public ItemStack getHoveredStack() {
return hoveredStack;
}

private void hideStoredSorting() {
this.visualHiddenStored = new ArrayList<>();
for (final IAEItemStack refStack : this.visual) {
if (refStack != null) {
final IAEItemStack activeStack = this.active.findPrecise(refStack);
final IAEItemStack pendingStack = this.pending.findPrecise(refStack);
if ((activeStack != null && activeStack.getStackSize() > 0)
|| (pendingStack != null && pendingStack.getStackSize() > 0)) {
this.visualHiddenStored.add(refStack);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,13 @@ protected void actionPerformed(final GuiButton btn) {
NetworkHandler.instance.sendToServer(new PacketSwitchGuis(this.originalGui));
} else if (btn == this.switchTallMode) {
tallMode = !tallMode;
AEConfig.instance.getConfigManager()
.putSetting(Settings.TERMINAL_STYLE, tallMode ? TerminalStyle.TALL : TerminalStyle.SMALL);
switchTallMode.set(tallMode ? TerminalStyle.TALL : TerminalStyle.SMALL);
recalculateScreenSize();
this.setWorldAndResolution(mc, width, height);
} else if (btn == this.toggleHideStored) {
this.setScrollBar();
}
}

Expand Down Expand Up @@ -307,7 +311,12 @@ protected void recalculateScreenSize() {
}

private void setScrollBar() {
final int size = this.visual.size();
int size;
if (this.hideStored) {
size = this.visualHiddenStored.size();
} else {
size = this.visual.size();
}

this.getScrollBar().setTop(SCROLLBAR_TOP).setLeft(SCROLLBAR_LEFT).setHeight(ySize - 47);
this.getScrollBar().setRange(0, (size + 2) / 3 - this.rows, 1);
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/appeng/client/gui/widgets/GuiImgButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,18 @@ public GuiImgButton(final int x, final int y, final Enum idx, final Enum val) {
TerminalStyle.FULL,
ButtonToolTips.TerminalStyle,
ButtonToolTips.TerminalStyle_Full);
this.registerApp(
16 * 13 + 6,
Settings.HIDE_STORED,
YesNo.NO,
ButtonToolTips.HideStored,
ButtonToolTips.Disabled);
this.registerApp(
16 * 13 + 7,
Settings.HIDE_STORED,
YesNo.YES,
ButtonToolTips.HideStored,
ButtonToolTips.Enable);

this.registerApp(64, Settings.SORT_BY, SortOrder.NAME, ButtonToolTips.SortBy, ButtonToolTips.ItemName);
this.registerApp(
Expand Down
1 change: 1 addition & 0 deletions src/main/java/appeng/core/AEConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public AEConfig(final File configFile) {

this.settings.registerSetting(Settings.SEARCH_TOOLTIPS, YesNo.YES);
this.settings.registerSetting(Settings.TERMINAL_STYLE, TerminalStyle.TALL);
this.settings.registerSetting(Settings.HIDE_STORED, YesNo.NO);
this.settings.registerSetting(Settings.SEARCH_MODE, SearchBoxMode.AUTOSEARCH);
this.settings.registerSetting(Settings.SAVE_SEARCH, YesNo.NO);
this.settings.registerSetting(Settings.CRAFTING_STATUS, CraftingStatus.TILE);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/appeng/core/localization/ButtonToolTips.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public enum ButtonToolTips {
TerminalStyle_Tall,
TerminalStyle_Small,
SaveAsImage,
HideStored,

Stash,
StashDesc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ gui.tooltips.appliedenergistics2.TerminalStyle_Full=Full Screen Terminal
gui.tooltips.appliedenergistics2.TerminalStyle_Tall=Tall Centered Terminal
gui.tooltips.appliedenergistics2.TerminalStyle_Small=Small Centered Terminal
gui.tooltips.appliedenergistics2.SaveAsImage=Save as image
gui.tooltips.appliedenergistics2.HideStored=Hide Stored Items

gui.tooltips.appliedenergistics2.DoesntDespawn=This item won't de-spawn.
gui.tooltips.appliedenergistics2.EmitterMode=Crafting Emitter Mode
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0f57617

Please sign in to comment.