aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java
diff options
context:
space:
mode:
authorUnknown <shekwancheung0528@gmail.com>2019-01-12 22:58:58 +0800
committerUnknown <shekwancheung0528@gmail.com>2019-01-12 22:58:58 +0800
commitaee1137515d4f74f54c8ea70e71e742661213bf2 (patch)
tree243119ac2f207315d46d3fe63c7e8dae9eae217c /src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java
parent6b36550eba64e31dcfa70dab7440f168d913350c (diff)
downloadRoughlyEnoughItems-2.0.0.35.tar.gz
RoughlyEnoughItems-2.0.0.35.tar.bz2
RoughlyEnoughItems-2.0.0.35.zip
Show Craftables Filterv2.0.0.35
Diffstat (limited to 'src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java')
-rw-r--r--src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java45
1 files changed, 42 insertions, 3 deletions
diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java
index 5a5581597..a1e0a4cf9 100644
--- a/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java
+++ b/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java
@@ -18,7 +18,10 @@ import net.minecraft.util.math.MathHelper;
import java.awt.*;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedList;
import java.util.List;
+import java.util.stream.Collectors;
public class ContainerGuiOverlay extends Gui {
@@ -113,18 +116,34 @@ public class ContainerGuiOverlay extends Gui {
GuiHelper.searchField.setBounds(getTextFieldArea());
this.widgets.add(GuiHelper.searchField);
GuiHelper.searchField.setText(searchTerm);
+ if (RoughlyEnoughItemsCore.getConfigHelper().showCraftableOnlyButton())
+ this.widgets.add(new CraftableToggleButtonWidget(containerGui, getCraftableToggleArea()) {
+ @Override
+ public void onPressed(int button, double mouseX, double mouseY) {
+ RoughlyEnoughItemsCore.getConfigHelper().toggleCraftableOnly();
+ itemListOverlay.updateList(page, searchTerm);
+ }
+ });
this.listeners.addAll(widgets);
}
private Rectangle getTextFieldArea() {
+ int widthRemoved = RoughlyEnoughItemsCore.getConfigHelper().showCraftableOnlyButton() ? 22 : 0;
if (RoughlyEnoughItemsCore.getConfigHelper().sideSearchField())
- return new Rectangle(rectangle.x + 2, window.getScaledHeight() - 22, rectangle.width - 6, 18);
+ return new Rectangle(rectangle.x + 2, window.getScaledHeight() - 22, rectangle.width - 6 - widthRemoved, 18);
if (MinecraftClient.getInstance().currentGui instanceof RecipeViewingWidget) {
RecipeViewingWidget widget = (RecipeViewingWidget) MinecraftClient.getInstance().currentGui;
- return new Rectangle(widget.getBounds().x, window.getScaledHeight() - 22, widget.getBounds().width, 18);
+ return new Rectangle(widget.getBounds().x, window.getScaledHeight() - 22, widget.getBounds().width - widthRemoved, 18);
}
- return new Rectangle(containerGui.getContainerLeft(), window.getScaledHeight() - 22, containerGui.getContainerWidth(), 18);
+ return new Rectangle(containerGui.getContainerLeft(), window.getScaledHeight() - 22, containerGui.getContainerWidth() - widthRemoved, 18);
+ }
+
+ private Rectangle getCraftableToggleArea() {
+ Rectangle searchBoxArea = getTextFieldArea();
+ searchBoxArea.setLocation(searchBoxArea.x + searchBoxArea.width + 4, searchBoxArea.y - 1);
+ searchBoxArea.setSize(20, 20);
+ return searchBoxArea;
}
private String getCheatModeText() {
@@ -140,8 +159,13 @@ public class ContainerGuiOverlay extends Gui {
}
public void render(int mouseX, int mouseY, float partialTicks) {
+ List<ItemStack> currentStacks = ClientHelper.getInventoryItemsTypes();
if (getLeft() != lastLeft)
onInitialized();
+ else if (RoughlyEnoughItemsCore.getConfigHelper().craftableOnly() && (!hasSameListContent(new LinkedList<>(GuiHelper.inventoryStacks), currentStacks) || (currentStacks.size() != GuiHelper.inventoryStacks.size()))) {
+ GuiHelper.inventoryStacks = ClientHelper.getInventoryItemsTypes();
+ itemListOverlay.updateList(page, searchTerm);
+ }
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
GuiLighting.disable();
this.draw(mouseX, mouseY, partialTicks);
@@ -151,6 +175,21 @@ public class ContainerGuiOverlay extends Gui {
GuiLighting.disable();
}
+ private boolean hasSameListContent(List<ItemStack> list1, List<ItemStack> list2) {
+ Collections.sort(list1, (itemStack, t1) -> {
+ return itemStack.getDisplayName().getFormattedText().compareToIgnoreCase(t1.getDisplayName().getFormattedText());
+ });
+ Collections.sort(list2, (itemStack, t1) -> {
+ return itemStack.getDisplayName().getFormattedText().compareToIgnoreCase(t1.getDisplayName().getFormattedText());
+ });
+ String lastString = String.join("", list1.stream().map(itemStack -> {
+ return itemStack.getDisplayName().getFormattedText();
+ }).collect(Collectors.toList())), currentString = String.join("", list2.stream().map(itemStack -> {
+ return itemStack.getDisplayName().getFormattedText();
+ }).collect(Collectors.toList()));
+ return lastString.equals(currentString);
+ }
+
public void setContainerGui(IMixinContainerGui containerGui) {
this.containerGui = containerGui;
}