diff options
Diffstat (limited to 'src/main/java/me/shedaniel/rei/gui')
| -rw-r--r-- | src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java | 64 | ||||
| -rw-r--r-- | src/main/java/me/shedaniel/rei/gui/widget/ConfigWidget.java | 3 | ||||
| -rw-r--r-- | src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java | 12 | ||||
| -rw-r--r-- | src/main/java/me/shedaniel/rei/gui/widget/HighlightableWidget.java | 10 | ||||
| -rw-r--r-- | src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java | 43 | ||||
| -rw-r--r-- | src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java | 35 | ||||
| -rw-r--r-- | src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidgetGui.java (renamed from src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java) | 123 | ||||
| -rw-r--r-- | src/main/java/me/shedaniel/rei/gui/widget/SpeedCraftingButtonWidget.java | 42 | ||||
| -rw-r--r-- | src/main/java/me/shedaniel/rei/gui/widget/TabWidget.java | 6 |
9 files changed, 163 insertions, 175 deletions
diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java index b840a473d..ac78abbf0 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerGuiOverlay.java @@ -1,11 +1,11 @@ package me.shedaniel.rei.gui; +import com.google.common.collect.Lists; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.client.ClientHelper; import me.shedaniel.rei.client.GuiHelper; import me.shedaniel.rei.client.KeyBindHelper; import me.shedaniel.rei.gui.widget.*; -import me.shedaniel.rei.listeners.IMixinGuiContainer; import net.minecraft.client.MainWindow; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; @@ -18,7 +18,6 @@ import net.minecraft.item.ItemStack; 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; @@ -26,34 +25,26 @@ import java.util.stream.Collectors; public class ContainerGuiOverlay extends GuiScreen { + private static final List<QueuedTooltip> QUEUED_TOOLTIPS = Lists.newArrayList(); public static String searchTerm = ""; private static int page = 0; private static ItemListOverlay itemListOverlay; - private final List<IWidget> widgets; - private final List<QueuedTooltip> queuedTooltips; + private final List<IWidget> widgets = Lists.newArrayList(); private Rectangle rectangle; - private IMixinGuiContainer containerGui; private MainWindow window; private ButtonWidget buttonLeft, buttonRight; private int lastLeft; - public ContainerGuiOverlay(GuiContainer containerGui) { - this.queuedTooltips = new ArrayList<>(); - this.containerGui = (IMixinGuiContainer) containerGui; - this.widgets = new ArrayList<>(); - } - public void onInitialized() { //Update Variables this.widgets.clear(); this.window = Minecraft.getInstance().mainWindow; - if (Minecraft.getInstance().currentScreen instanceof GuiContainer) - this.containerGui = (IMixinGuiContainer) Minecraft.getInstance().currentScreen; this.rectangle = calculateBoundary(); - widgets.add(this.itemListOverlay = new ItemListOverlay(containerGui, page)); this.lastLeft = getLeft(); + widgets.add(this.itemListOverlay = new ItemListOverlay(page)); this.itemListOverlay.updateList(getItemListArea(), page, searchTerm); + widgets.add(buttonLeft = new ButtonWidget(rectangle.x, rectangle.y + 5, 16, 16, "<") { @Override public void onPressed(int button, double mouseX, double mouseY) { @@ -88,7 +79,7 @@ public class ContainerGuiOverlay extends GuiScreen { widgets.add(new ButtonWidget(10, 35, 40, 20, I18n.format("text.rei.config")) { @Override public void onPressed(int button, double mouseX, double mouseY) { - ClientHelper.openConfigWindow(containerGui.getContainerGui()); + ClientHelper.openConfigWindow(GuiHelper.getLastGuiContainer()); } }); this.widgets.add(new LabelWidget(rectangle.x + (rectangle.width / 2), rectangle.y + 10, "") { @@ -118,7 +109,7 @@ public class ContainerGuiOverlay extends GuiScreen { this.widgets.add(GuiHelper.searchField); GuiHelper.searchField.setText(searchTerm); if (RoughlyEnoughItemsCore.getConfigHelper().showCraftableOnlyButton()) - this.widgets.add(new CraftableToggleButtonWidget(containerGui, getCraftableToggleArea()) { + this.widgets.add(new CraftableToggleButtonWidget(getCraftableToggleArea()) { @Override public void onPressed(int button, double mouseX, double mouseY) { RoughlyEnoughItemsCore.getConfigHelper().toggleCraftableOnly(); @@ -126,6 +117,7 @@ public class ContainerGuiOverlay extends GuiScreen { } }); + this.itemListOverlay.updateList(getItemListArea(), page, searchTerm); this.children.addAll(widgets); } @@ -133,11 +125,11 @@ public class ContainerGuiOverlay extends GuiScreen { int widthRemoved = RoughlyEnoughItemsCore.getConfigHelper().showCraftableOnlyButton() ? 22 : 0; if (RoughlyEnoughItemsCore.getConfigHelper().sideSearchField()) return new Rectangle(rectangle.x + 2, window.getScaledHeight() - 22, rectangle.width - 6 - widthRemoved, 18); - if (Minecraft.getInstance().currentScreen instanceof RecipeViewingWidget) { - RecipeViewingWidget widget = (RecipeViewingWidget) Minecraft.getInstance().currentScreen; + if (Minecraft.getInstance().currentScreen instanceof RecipeViewingWidgetGui) { + RecipeViewingWidgetGui widget = (RecipeViewingWidgetGui) Minecraft.getInstance().currentScreen; return new Rectangle(widget.getBounds().x, window.getScaledHeight() - 22, widget.getBounds().width - widthRemoved, 18); } - return new Rectangle(containerGui.getContainerLeft(), window.getScaledHeight() - 22, containerGui.getContainerWidth() - widthRemoved, 18); + return new Rectangle(GuiHelper.getLastMixinGuiContainer().getContainerLeft(), window.getScaledHeight() - 22, GuiHelper.getLastMixinGuiContainer().getContainerWidth() - widthRemoved, 18); } private Rectangle getCraftableToggleArea() { @@ -171,8 +163,8 @@ public class ContainerGuiOverlay extends GuiScreen { RenderHelper.disableStandardItemLighting(); this.render(mouseX, mouseY, partialTicks); RenderHelper.disableStandardItemLighting(); - queuedTooltips.forEach(queuedTooltip -> containerGui.getContainerGui().drawHoveringText(queuedTooltip.text, queuedTooltip.mouse.x, queuedTooltip.mouse.y)); - queuedTooltips.clear(); + QUEUED_TOOLTIPS.stream().filter(queuedTooltip -> queuedTooltip != null).forEach(queuedTooltip -> Minecraft.getInstance().currentScreen.drawHoveringText(queuedTooltip.text, queuedTooltip.mouse.x, queuedTooltip.mouse.y)); + QUEUED_TOOLTIPS.clear(); RenderHelper.disableStandardItemLighting(); } @@ -191,12 +183,8 @@ public class ContainerGuiOverlay extends GuiScreen { return lastString.equals(currentString); } - public void setContainerGui(IMixinGuiContainer containerGui) { - this.containerGui = containerGui; - } - public void addTooltip(QueuedTooltip queuedTooltip) { - queuedTooltips.add(queuedTooltip); + QUEUED_TOOLTIPS.add(queuedTooltip); } @Override @@ -214,10 +202,10 @@ public class ContainerGuiOverlay extends GuiScreen { } private Rectangle calculateBoundary() { - int startX = containerGui.getContainerLeft() + containerGui.getContainerWidth() + 10; + int startX = GuiHelper.getLastMixinGuiContainer().getContainerLeft() + GuiHelper.getLastMixinGuiContainer().getContainerWidth() + 10; int width = window.getScaledWidth() - startX; - if (Minecraft.getInstance().currentScreen instanceof RecipeViewingWidget) { - RecipeViewingWidget widget = (RecipeViewingWidget) Minecraft.getInstance().currentScreen; + if (Minecraft.getInstance().currentScreen instanceof RecipeViewingWidgetGui) { + RecipeViewingWidgetGui widget = (RecipeViewingWidgetGui) Minecraft.getInstance().currentScreen; startX = widget.getBounds().x + widget.getBounds().width + 10; width = window.getScaledWidth() - startX; } @@ -225,11 +213,11 @@ public class ContainerGuiOverlay extends GuiScreen { } private int getLeft() { - if (Minecraft.getInstance().currentScreen instanceof RecipeViewingWidget) { - RecipeViewingWidget widget = (RecipeViewingWidget) Minecraft.getInstance().currentScreen; + if (Minecraft.getInstance().currentScreen instanceof RecipeViewingWidgetGui) { + RecipeViewingWidgetGui widget = (RecipeViewingWidgetGui) Minecraft.getInstance().currentScreen; return widget.getBounds().x; } - return containerGui.getContainerLeft(); + return GuiHelper.getLastMixinGuiContainer().getContainerLeft(); } private int getTotalPage() { @@ -265,8 +253,8 @@ public class ContainerGuiOverlay extends GuiScreen { itemStack = ((ItemSlotWidget) widget).getCurrentStack(); break; } - if (itemStack == null && Minecraft.getInstance().currentScreen instanceof RecipeViewingWidget) { - RecipeViewingWidget recipeViewingWidget = (RecipeViewingWidget) Minecraft.getInstance().currentScreen; + if (itemStack == null && Minecraft.getInstance().currentScreen instanceof RecipeViewingWidgetGui) { + RecipeViewingWidgetGui recipeViewingWidget = (RecipeViewingWidgetGui) Minecraft.getInstance().currentScreen; for(IGuiEventListener entry : recipeViewingWidget.getChildren()) if (entry instanceof ItemSlotWidget && ((ItemSlotWidget) entry).isHighlighted(point.x, point.y)) { itemStack = ((ItemSlotWidget) entry).getCurrentStack(); @@ -274,13 +262,13 @@ public class ContainerGuiOverlay extends GuiScreen { } } if (itemStack == null && Minecraft.getInstance().currentScreen instanceof GuiContainer) - if (containerGui.getHoveredSlot() != null) - itemStack = containerGui.getHoveredSlot().getStack(); + if (GuiHelper.getLastMixinGuiContainer().getHoveredSlot() != null) + itemStack = GuiHelper.getLastMixinGuiContainer().getHoveredSlot().getStack(); if (itemStack != null && !itemStack.isEmpty()) { if (KeyBindHelper.RECIPE.matchesKey(int_1, int_2)) - return ClientHelper.executeRecipeKeyBind(this, itemStack, containerGui); + return ClientHelper.executeRecipeKeyBind(this, itemStack); else if (KeyBindHelper.USAGE.matchesKey(int_1, int_2)) - return ClientHelper.executeUsageKeyBind(this, itemStack, containerGui); + return ClientHelper.executeUsageKeyBind(this, itemStack); } if (KeyBindHelper.HIDE.matchesKey(int_1, int_2)) { GuiHelper.toggleOverlayVisible(); diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ConfigWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/ConfigWidget.java index 93e41c655..1b5e01052 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ConfigWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ConfigWidget.java @@ -100,8 +100,7 @@ public class ConfigWidget extends GuiScreen { @Override public void draw(int int_1, int int_2, float float_1) { RenderHelper.disableStandardItemLighting(); - this.text = I18n.format("text.rei.list_ordering_button", I18n.format(RoughlyEnoughItemsCore.getConfigHelper().getItemListOrdering().getNameTranslationKey()), - I18n.format(RoughlyEnoughItemsCore.getConfigHelper().isAscending() ? "ordering.rei.ascending" : "ordering.rei.descending")); + this.text = I18n.format("text.rei.list_ordering_button", I18n.format(RoughlyEnoughItemsCore.getConfigHelper().getItemListOrdering().getNameTranslationKey()), I18n.format(RoughlyEnoughItemsCore.getConfigHelper().isAscending() ? "ordering.rei.ascending" : "ordering.rei.descending")); String t = I18n.format("text.rei.list_ordering") + ": "; drawString(Minecraft.getInstance().fontRenderer, t, parent.width / 2 - 95 - Minecraft.getInstance().fontRenderer.getStringWidth(t), 90 + 6, -1); super.draw(int_1, int_2, float_1); diff --git a/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java index 88f3ca694..035d5cac6 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java @@ -3,7 +3,6 @@ package me.shedaniel.rei.gui.widget; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.client.ClientHelper; import me.shedaniel.rei.client.GuiHelper; -import me.shedaniel.rei.listeners.IMixinGuiContainer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.ItemRenderer; @@ -20,14 +19,13 @@ public abstract class CraftableToggleButtonWidget extends ButtonWidget { protected static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer.png"); private ItemRenderer itemRenderer; - private IMixinGuiContainer containerGui; - public CraftableToggleButtonWidget(IMixinGuiContainer containerGui, Rectangle rectangle) { - this(containerGui, rectangle.x, rectangle.y, rectangle.width, rectangle.height); + public CraftableToggleButtonWidget(Rectangle rectangle) { + this(rectangle.x, rectangle.y, rectangle.width, rectangle.height); this.itemRenderer = Minecraft.getInstance().getItemRenderer(); } - public CraftableToggleButtonWidget(IMixinGuiContainer containerGui, int x, int y, int width, int height) { + public CraftableToggleButtonWidget(int x, int y, int width, int height) { super(x, y, width, height, ""); this.itemRenderer = Minecraft.getInstance().getItemRenderer(); } @@ -51,9 +49,7 @@ public abstract class CraftableToggleButtonWidget extends ButtonWidget { } private void drawTooltip() { - GuiHelper.getLastOverlay() - .addTooltip(new QueuedTooltip(ClientHelper.getMouseLocation(), Arrays.asList(I18n.format(RoughlyEnoughItemsCore.getConfigHelper().craftableOnly() - ? "text.rei.showing_craftable" : "text.rei.showing_all")))); + GuiHelper.getLastOverlay().addTooltip(new QueuedTooltip(ClientHelper.getMouseLocation(), Arrays.asList(I18n.format(RoughlyEnoughItemsCore.getConfigHelper().craftableOnly() ? "text.rei.showing_craftable" : "text.rei.showing_all")))); } } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/HighlightableWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/HighlightableWidget.java index 97d097d94..da18cfc97 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/HighlightableWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/HighlightableWidget.java @@ -7,7 +7,15 @@ public interface HighlightableWidget extends IWidget { public Rectangle getBounds(); default boolean isHighlighted(int mouseX, int mouseY) { - return getBounds().contains(new Point(mouseX, mouseY)); + return getBounds().contains(mouseX, mouseY); + } + + default boolean isHighlighted(Point point) { + return this.isHighlighted(point.x, point.y); + } + + default boolean isHighlighted(double mouseX, double mouseY) { + return this.isHighlighted((int) mouseX, (int) mouseY); } } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java b/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java index 06bf4d687..d2c7ef467 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java @@ -3,8 +3,6 @@ package me.shedaniel.rei.gui.widget; import com.google.common.collect.Lists; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.client.*; -import me.shedaniel.rei.listeners.ClientLoaded; -import me.shedaniel.rei.listeners.IMixinGuiContainer; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.Gui; @@ -24,15 +22,13 @@ import java.util.stream.Stream; public class ItemListOverlay extends Gui implements IWidget { - private IMixinGuiContainer containerGui; private List<IWidget> widgets = new ArrayList<>(); private int width, height, page; - private Rectangle rectangle; + private Rectangle rectangle, listArea; private List<ItemStack> currentDisplayed; - public ItemListOverlay(IMixinGuiContainer containerGui, int page) { + public ItemListOverlay(int page) { this.currentDisplayed = Lists.newArrayList(); - this.containerGui = containerGui; this.width = 0; this.height = 0; this.page = page; @@ -47,28 +43,29 @@ public class ItemListOverlay extends Gui implements IWidget { widgets.forEach(widget -> widget.draw(int_1, int_2, float_1)); EntityPlayerSP player = Minecraft.getInstance().player; if (rectangle.contains(ClientHelper.getMouseLocation()) && ClientHelper.isCheating() && !player.inventory.getItemStack().isEmpty() && Minecraft.getInstance().isSingleplayer()) - GuiHelper.getOverlay(containerGui.getContainerGui()).addTooltip(new QueuedTooltip(ClientHelper.getMouseLocation(), Arrays.asList(I18n.format("text.rei.delete_items")))); + GuiHelper.getLastOverlay().addTooltip(new QueuedTooltip(ClientHelper.getMouseLocation(), Arrays.asList(I18n.format("text.rei.delete_items")))); } public void updateList(int page, String searchTerm) { updateList(rectangle, page, searchTerm); } - public void updateList(Rectangle rect, int page, String searchTerm) { - this.rectangle = rect; + public void updateList(Rectangle bounds, int page, String searchTerm) { + this.rectangle = bounds; if (ClientHelper.getItemList().isEmpty()) - RoughlyEnoughItemsCore.getListeners(ClientLoaded.class).forEach(ClientLoaded::clientLoaded); + RoughlyEnoughItemsCore.getClientHelper().clientLoaded(); currentDisplayed = processSearchTerm(searchTerm, ClientHelper.getItemList(), GuiHelper.inventoryStacks); this.widgets.clear(); this.page = page; - calculateListSize(rect); - double startX = rect.getCenterX() - width * 9; - double startY = rect.getCenterY() - height * 9; + calculateListSize(rectangle); + double startX = rectangle.getCenterX() - width * 9; + double startY = rectangle.getCenterY() - height * 9; + this.listArea = new Rectangle((int) startX, (int) startY, width * 18, height * 18); for(int i = 0; i < getTotalSlotsPerPage(); i++) { int j = i + page * getTotalSlotsPerPage(); if (j >= currentDisplayed.size()) break; - widgets.add(new ItemSlotWidget((int) (startX + (i % width) * 18), (int) (startY + MathHelper.floor(i / width) * 18), currentDisplayed.get(j), false, true, containerGui) { + ItemSlotWidget slotWidget = new ItemSlotWidget((int) (startX + (i % width) * 18), (int) (startY + MathHelper.floor(i / width) * 18), currentDisplayed.get(j), false, true) { @Override protected void drawToolTip(ItemStack itemStack) { EntityPlayerSP player = Minecraft.getInstance().player; @@ -78,23 +75,23 @@ public class ItemListOverlay extends Gui implements IWidget { @Override public boolean onMouseClick(int button, double mouseX, double mouseY) { - if (getBounds().contains(mouseX, mouseY)) { + if (isHighlighted(mouseX, mouseY)) { if (ClientHelper.isCheating()) { if (getCurrentStack() != null && !getCurrentStack().isEmpty()) { ItemStack cheatedStack = getCurrentStack().copy(); cheatedStack.setCount(button == 0 ? 1 : button == 1 ? cheatedStack.getMaxStackSize() : cheatedStack.getCount()); return ClientHelper.tryCheatingStack(cheatedStack); } - } else { - if (button == 0) - return ClientHelper.executeRecipeKeyBind(GuiHelper.getOverlay(containerGui.getContainerGui()), getCurrentStack().copy(), containerGui); - else if (button == 1) - return ClientHelper.executeUsageKeyBind(GuiHelper.getOverlay(containerGui.getContainerGui()), getCurrentStack().copy(), containerGui); - } + } else if (button == 0) + return ClientHelper.executeRecipeKeyBind(GuiHelper.getLastOverlay(), getCurrentStack().copy()); + else if (button == 1) + return ClientHelper.executeUsageKeyBind(GuiHelper.getLastOverlay(), getCurrentStack().copy()); } return false; } - }); + }; + if (this.rectangle.contains(slotWidget.getBounds())) + widgets.add(slotWidget); } } @@ -140,7 +137,7 @@ public class ItemListOverlay extends Gui implements IWidget { stacks.addAll(os); List<ItemStack> workingItems = RoughlyEnoughItemsCore.getConfigHelper().craftableOnly() && inventoryItems.size() > 0 ? new ArrayList<>() : new LinkedList<>(ol); if (RoughlyEnoughItemsCore.getConfigHelper().craftableOnly()) { - RecipeHelper.findCraftableByItems(inventoryItems).forEach(workingItems::add); + RecipeHelper.getInstance().findCraftableByItems(inventoryItems).forEach(workingItems::add); workingItems.addAll(inventoryItems); } final List<ItemStack> finalWorkingItems = workingItems; diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java index e2d6a6bdb..127341a39 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java @@ -3,7 +3,6 @@ package me.shedaniel.rei.gui.widget; import com.google.common.collect.Lists; import me.shedaniel.rei.client.ClientHelper; import me.shedaniel.rei.client.GuiHelper; -import me.shedaniel.rei.listeners.IMixinGuiContainer; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.ItemRenderer; @@ -26,24 +25,22 @@ public class ItemSlotWidget extends Gui implements HighlightableWidget { private List<ItemStack> itemList = new LinkedList<>(); private boolean drawBackground, showToolTips, clickToMoreRecipes; private int x, y; - private IMixinGuiContainer containerGui; - public ItemSlotWidget(int x, int y, ItemStack itemStack, boolean drawBackground, boolean showToolTips, IMixinGuiContainer containerGui) { - this(x, y, Arrays.asList(itemStack), drawBackground, showToolTips, containerGui); + public ItemSlotWidget(int x, int y, ItemStack itemStack, boolean drawBackground, boolean showToolTips) { + this(x, y, Arrays.asList(itemStack), drawBackground, showToolTips); } - public ItemSlotWidget(int x, int y, List<ItemStack> itemList, boolean drawBackground, boolean showToolTips, IMixinGuiContainer containerGui) { + public ItemSlotWidget(int x, int y, List<ItemStack> itemList, boolean drawBackground, boolean showToolTips) { this.itemList = itemList; this.drawBackground = drawBackground; this.showToolTips = showToolTips; this.x = x; this.y = y; - this.containerGui = containerGui; this.clickToMoreRecipes = false; } - public ItemSlotWidget(int x, int y, List<ItemStack> itemList, boolean drawBackground, boolean showToolTips, IMixinGuiContainer containerGui, boolean clickToMoreRecipes) { - this(x, y, itemList, drawBackground, showToolTips, containerGui); + public ItemSlotWidget(int x, int y, List<ItemStack> itemList, boolean drawBackground, boolean showToolTips, boolean clickToMoreRecipes) { + this(x, y, itemList, drawBackground, showToolTips); this.clickToMoreRecipes = clickToMoreRecipes; } @@ -69,11 +66,7 @@ public class ItemSlotWidget extends Gui implements HighlightableWidget { ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer(); itemRenderer.zLevel = 200.0F; itemRenderer.renderItemAndEffectIntoGUI(itemStack, x, y); - assert containerGui != null; - if (containerGui.getDraggedStack().isEmpty()) - itemRenderer.renderItemOverlayIntoGUI(Minecraft.getInstance().fontRenderer, itemStack, x, y - 0, getItemCountOverlay(itemStack)); - else - itemRenderer.renderItemOverlayIntoGUI(Minecraft.getInstance().fontRenderer, itemStack, x, y - 8, getItemCountOverlay(itemStack)); + itemRenderer.renderItemOverlayIntoGUI(Minecraft.getInstance().fontRenderer, itemStack, x, y, getItemCountOverlay(itemStack)); itemRenderer.zLevel = 0.0F; if (isHighlighted(mouseX, mouseY) && showToolTips) drawToolTip(itemStack); @@ -81,16 +74,18 @@ public class ItemSlotWidget extends Gui implements HighlightableWidget { protected void drawToolTip(ItemStack itemStack) { List<String> toolTip = getTooltip(itemStack); - GuiHelper.getOverlay(containerGui.getContainerGui()).addTooltip(new QueuedTooltip(ClientHelper.getMouseLocation(), toolTip)); + GuiHelper.getLastOverlay().addTooltip(new QueuedTooltip(ClientHelper.getMouseLocation(), toolTip)); } protected List<String> getTooltip(ItemStack itemStack) { final String modString = "§9§o" + ClientHelper.getModFromItemStack(itemStack); Minecraft mc = Minecraft.getInstance(); List<String> toolTip = Lists.newArrayList(); - if (containerGui != null) - toolTip = containerGui.getContainerGui().getItemToolTip(itemStack).stream().filter(s -> !s.equals(modString)).collect(Collectors.toList()); - else toolTip.add(itemStack.getDisplayName().getFormattedText()); + try { + toolTip = GuiHelper.getLastOverlay().getItemToolTip(itemStack).stream().filter(s -> !s.equals(modString)).collect(Collectors.toList()); + } catch (Exception e) { + toolTip.add(itemStack.getDisplayName().getFormattedText()); + } toolTip.addAll(getExtraToolTips(itemStack)); toolTip.add(modString); return toolTip; @@ -116,7 +111,7 @@ public class ItemSlotWidget extends Gui implements HighlightableWidget { @Override public Rectangle getBounds() { - return new Rectangle(this.x, this.y, 18, 18); + return new Rectangle(this.x - 1, this.y - 1, 18, 18); } @Override @@ -125,9 +120,9 @@ public class ItemSlotWidget extends Gui implements HighlightableWidget { return false; if (getBounds().contains(mouseX, mouseY)) { if (button == 0) - return ClientHelper.executeRecipeKeyBind(GuiHelper.getOverlay(containerGui.getContainerGui()), getCurrentStack().copy(), containerGui); + return ClientHelper.executeRecipeKeyBind(GuiHelper.getLastOverlay(), getCurrentStack().copy()); else if (button == 1) - return ClientHelper.executeUsageKeyBind(GuiHelper.getOverlay(containerGui.getContainerGui()), getCurrentStack().copy(), containerGui); + return ClientHelper.executeUsageKeyBind(GuiHelper.getLastOverlay(), getCurrentStack().copy()); } return false; } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidgetGui.java index f376c2e3e..a1b810b98 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidgetGui.java @@ -8,26 +8,25 @@ import me.shedaniel.rei.api.SpeedCraftFunctional; import me.shedaniel.rei.client.ClientHelper; import me.shedaniel.rei.client.GuiHelper; import me.shedaniel.rei.client.RecipeHelper; -import me.shedaniel.rei.listeners.IMixinGuiContainer; import net.minecraft.client.MainWindow; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.SimpleSound; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.IGuiEventListener; +import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.resources.I18n; import net.minecraft.init.SoundEvents; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.MathHelper; import java.awt.*; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.function.Supplier; -public class RecipeViewingWidget extends GuiScreen { +public class RecipeViewingWidgetGui extends GuiScreen { public static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer.png"); private static final ResourceLocation CREATIVE_INVENTORY_TABS = new ResourceLocation("textures/gui/container/creative_inventory/tabs.png"); @@ -41,19 +40,17 @@ public class RecipeViewingWidget extends GuiScreen { private Map<IRecipeCategory, List<IRecipeDisplay>> categoriesMap; private List<IRecipeCategory> categories; private IRecipeCategory selectedCategory; - private IMixinGuiContainer parent; private int page, categoryPages; private ButtonWidget recipeBack, recipeNext, categoryBack, categoryNext; - public RecipeViewingWidget(MainWindow window, IMixinGuiContainer parent, Map<IRecipeCategory, List<IRecipeDisplay>> categoriesMap) { + public RecipeViewingWidgetGui(MainWindow window, Map<IRecipeCategory, List<IRecipeDisplay>> categoriesMap) { this.categoryPages = 0; - this.parent = parent; this.window = window; this.widgets = Lists.newArrayList(); this.bounds = new Rectangle(window.getScaledWidth() / 2 - guiWidth / 2, window.getScaledHeight() / 2 - guiHeight / 2, guiWidth, guiHeight); this.categoriesMap = categoriesMap; this.categories = Lists.newArrayList(); - RecipeHelper.getCategories().forEach(category -> { + RecipeHelper.getInstance().getCategories().forEach(category -> { if (categoriesMap.containsKey(category)) categories.add(category); }); @@ -61,14 +58,18 @@ public class RecipeViewingWidget extends GuiScreen { this.tabs = new ArrayList<>(); } - public IMixinGuiContainer getParent() { - return parent; + public static SpeedCraftFunctional getSpeedCraftFunctionalByCategory(GuiContainer guiContainer, IRecipeCategory category) { + for(SpeedCraftFunctional functional : RecipeHelper.getInstance().getSpeedCraftFunctional(category)) + for(Class aClass : functional.getFunctioningFor()) + if (guiContainer.getClass().isAssignableFrom(aClass)) + return functional; + return null; } @Override public boolean keyPressed(int int_1, int int_2, int int_3) { if ((int_1 == 256 || mc.gameSettings.keyBindInventory.matchesKey(int_1, int_2)) && this.allowCloseWithEscape()) { - Minecraft.getInstance().displayGuiScreen(parent.getContainerGui()); + Minecraft.getInstance().displayGuiScreen(GuiHelper.getLastGuiContainer()); return true; } for(IGuiEventListener listener : children) @@ -83,11 +84,6 @@ public class RecipeViewingWidget extends GuiScreen { } @Override - public void onGuiClosed() { - GuiHelper.resetOverlay(); - } - - @Override protected void initGui() { super.initGui(); this.tabs.clear(); @@ -103,7 +99,7 @@ public class RecipeViewingWidget extends GuiScreen { currentCategoryIndex = categories.size() - 1; selectedCategory = categories.get(currentCategoryIndex); categoryPages = MathHelper.floor(currentCategoryIndex / 6d); - RecipeViewingWidget.this.initGui(); + RecipeViewingWidgetGui.this.initGui(); } }); widgets.add(categoryNext = new ButtonWidget((int) bounds.getX() + 159, (int) bounds.getY() + 5, 12, 12, ">") { @@ -115,7 +111,7 @@ public class RecipeViewingWidget extends GuiScreen { currentCategoryIndex = 0; selectedCategory = categories.get(currentCategoryIndex); categoryPages = MathHelper.floor(currentCategoryIndex / 6d); - RecipeViewingWidget.this.initGui(); + RecipeViewingWidgetGui.this.initGui(); } }); categoryBack.enabled = categories.size() > 1; @@ -127,7 +123,7 @@ public class RecipeViewingWidget extends GuiScreen { page--; if (page < 0) page = getTotalPages(selectedCategory) - 1; - RecipeViewingWidget.this.initGui(); + RecipeViewingWidgetGui.this.initGui(); } }); widgets.add(recipeNext = new ButtonWidget((int) bounds.getX() + 159, (int) bounds.getY() + 21, 12, 12, ">") { @@ -136,7 +132,7 @@ public class RecipeViewingWidget extends GuiScreen { page++; if (page >= getTotalPages(selectedCategory)) page = 0; - RecipeViewingWidget.this.initGui(); + RecipeViewingWidgetGui.this.initGui(); } }); recipeBack.enabled = categoriesMap.get(selectedCategory).size() > getRecipesPerPage(); @@ -169,7 +165,7 @@ public class RecipeViewingWidget extends GuiScreen { return false; selectedCategory = categories.get(getId() + categoryPages * 6); page = 0; - RecipeViewingWidget.this.initGui(); + RecipeViewingWidgetGui.this.initGui(); return true; } return false; @@ -178,70 +174,29 @@ public class RecipeViewingWidget extends GuiScreen { tab.setItem(categories.get(j).getCategoryIcon(), categories.get(j).getCategoryName(), tab.getId() + categoryPages * 6 == categories.indexOf(selectedCategory)); } } - SpeedCraftAreaSupplier supplier = RecipeHelper.getSpeedCraftButtonArea(selectedCategory); - final SpeedCraftFunctional[] functional0 = {null}; - RecipeHelper.getSpeedCraftFunctional(selectedCategory).forEach(functional1 -> { - for(Class aClass : functional1.getFunctioningFor()) - if (parent.getContainerGui().getClass().isAssignableFrom(aClass)) { - functional0[0] = functional1; - break; - } - }); - final SpeedCraftFunctional functional = functional0[0]; + + SpeedCraftAreaSupplier supplier = RecipeHelper.getInstance().getSpeedCraftButtonArea(selectedCategory); + final SpeedCraftFunctional functional = getSpeedCraftFunctionalByCategory(GuiHelper.getLastGuiContainer(), selectedCategory); if (page * getRecipesPerPage() < categoriesMap.get(selectedCategory).size()) { - IRecipeDisplay topDisplay = categoriesMap.get(selectedCategory).get(page * getRecipesPerPage()); - widgets.addAll(selectedCategory.setupDisplay(getParent(), topDisplay, new Rectangle((int) getBounds().getCenterX() - 75, getBounds().y + 40, 150, selectedCategory.usesFullPage() ? 140 : 66))); - if (supplier != null) { - ButtonWidget btn; - widgets.add(btn = new ButtonWidget(supplier.get(new Rectangle((int) getBounds().getCenterX() - 75, getBounds().y + 40, 150, selectedCategory.usesFullPage() ? 140 : 66)), "+") { - @Override - public void onPressed(int button, double mouseX, double mouseY) { - Minecraft.getInstance().displayGuiScreen(parent.getContainerGui()); - functional.performAutoCraft(parent.getContainerGui(), topDisplay); - } - - @Override - public void draw(int mouseX, int mouseY, float partialTicks) { - super.draw(mouseX, mouseY, partialTicks); - if (getBounds().contains(mouseX, mouseY)) - if (enabled) - GuiHelper.getLastOverlay().addTooltip(new QueuedTooltip(ClientHelper.getMouseLocation(), Arrays.asList(I18n.format("text.speed_craft.move_items")))); - else - GuiHelper.getLastOverlay().addTooltip(new QueuedTooltip(ClientHelper.getMouseLocation(), Arrays.asList(I18n.format("text.speed_craft.failed_move_items")))); - } - }); - btn.enabled = functional != null && functional.acceptRecipe(parent.getContainerGui(), topDisplay); - } + final Supplier<IRecipeDisplay> topDisplaySupplier = () -> categoriesMap.get( |
