diff --git a/src/main/java/codechicken/nei/BookmarkPanel.java b/src/main/java/codechicken/nei/BookmarkPanel.java index e22cf986..52b8ab54 100644 --- a/src/main/java/codechicken/nei/BookmarkPanel.java +++ b/src/main/java/codechicken/nei/BookmarkPanel.java @@ -5,15 +5,19 @@ import codechicken.lib.vec.Rectangle4i; import codechicken.nei.util.NBTJson; import codechicken.nei.recipe.StackInfo; import codechicken.nei.recipe.BookmarkRecipeId; +import codechicken.nei.ItemPanel.ItemPanelSlot; import codechicken.nei.guihook.GuiContainerManager; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; + +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import org.apache.commons.io.IOUtils; +import org.lwjgl.opengl.GL11; import static codechicken.lib.gui.GuiDraw.getMousePosition; import static codechicken.lib.gui.GuiDraw.drawRect; @@ -31,7 +35,7 @@ import java.util.List; import java.util.Map; import java.util.HashMap; -public class BookmarkPanel extends ItemPanel +public class BookmarkPanel extends PanelWidget { protected File bookmarkFile; @@ -46,7 +50,7 @@ public class BookmarkPanel extends ItemPanel protected ArrayList namespaces = new ArrayList<>(); - public int activeNamespaceIndex = 0; + protected int activeNamespaceIndex = 0; protected static class BookmarkStackMeta @@ -54,13 +58,15 @@ public class BookmarkPanel extends ItemPanel public int factor; public BookmarkRecipeId recipeId; public boolean ingredient = false; + public boolean fluidDisplay = false; - public BookmarkStackMeta(BookmarkRecipeId recipeId, int count, boolean ingredient) + public BookmarkStackMeta(BookmarkRecipeId recipeId, int count, boolean ingredient, boolean fluidDisplay) { this.recipeId = recipeId; this.factor = count; this.ingredient = ingredient; + this.fluidDisplay = fluidDisplay; } } @@ -118,7 +124,7 @@ public class BookmarkPanel extends ItemPanel for (int slotIndex = metadata.size() - 1; slotIndex >= 0; slotIndex--) { recipeIdB = getRecipeId(slotIndex); - if (recipeIdB != null && recipeIdA.equals(recipeIdB)) { + if (recipeIdB != null && recipeIdB.equals(recipeIdA)) { removeItem(slotIndex); } @@ -164,26 +170,49 @@ public class BookmarkPanel extends ItemPanel if (LayoutManager.bookmarkPanel.sortedNamespaceIndex == LayoutManager.bookmarkPanel.activeNamespaceIndex && LayoutManager.bookmarkPanel.sortedStackIndex == idx) { drawRect(rect.x, rect.y, rect.w, rect.h, 0xee555555);//highlight } else { + final ItemStack stack = getItem(idx); + final BookmarkStackMeta meta = getMetadata(idx); if (focus != null) { - if (focus.slotIndex == idx) { - drawRect(rect.x, rect.y, rect.w, rect.h, 0xee555555);//highlight - } else if ( + if ( LayoutManager.bookmarkPanel.sortedStackIndex == -1 && //disabled when sorting NEIClientUtils.shiftKey() && //show only with shift key getRecipeId(focus.slotIndex) != null && getRecipeId(idx) != null && getRecipeId(focus.slotIndex).equals(getRecipeId(idx))//is some recipeId ) { - drawRect(rect.x, rect.y, rect.w, rect.h, getMetadata(idx).ingredient? 0x88b3b300: 0x88009933);//highlight recipe + drawRect(rect.x, rect.y, rect.w, rect.h, meta.ingredient? 0x88b3b300: 0x88009933);//highlight recipe + } else if (focus.slotIndex == idx) { + drawRect(rect.x, rect.y, rect.w, rect.h, 0xee555555);//highlight } - + + } + + GuiContainerManager.drawItem(rect.x + 1, rect.y + 1, stack, true, meta.factor < 0 || meta.fluidDisplay? "": String.valueOf(stack.stackSize)); + + if (meta.recipeId != null && !meta.ingredient && NEIClientConfig.showRecipeMarker()) { + drawRecipeMarker(rect.x, rect.y, GuiContainerManager.getFontRenderer(stack)); } - GuiContainerManager.drawItem(rect.x + 1, rect.y + 1, getItem(idx), true); } } + protected void drawRecipeMarker(int offsetX, int offsetY, FontRenderer fontRenderer ) + { + final float scaleFactor = fontRenderer.getUnicodeFlag() ? 0.85f : 0.5f; + final float inverseScaleFactor = 1.0f / scaleFactor; + + GuiContainerManager.enable2DRender(); + GL11.glScaled(scaleFactor, scaleFactor, scaleFactor); + + final int X = (int) ( ( (float) offsetX + 1.0f) * inverseScaleFactor ); + final int Y = (int) ( ( (float) offsetY + 1.0f) * inverseScaleFactor ); + fontRenderer.drawStringWithShadow("R", X, Y, 0xA0A0A0); + + GL11.glScaled(inverseScaleFactor, inverseScaleFactor, inverseScaleFactor); + GuiContainerManager.enable3DRender(); + } + } @@ -192,6 +221,7 @@ public class BookmarkPanel extends ItemPanel grid = new BookmarkGrid(); } + @Override public void init() { super.init(); @@ -242,9 +272,10 @@ public class BookmarkPanel extends ItemPanel @Override public String getLabelText() { - return super.getLabelText() + " [" + grid.size() + "]"; + return String.format("(%d/%d) [%d]", getPage(), Math.max(1, getNumPages()), grid.size()); } + public void addOrRemoveItem(ItemStack stackA) { addOrRemoveItem(stackA, "", null); @@ -267,7 +298,7 @@ public class BookmarkPanel extends ItemPanel final ItemStack normalizedA = StackInfo.loadFromNBT(nbTagA); BookmarkRecipeId recipeId = null; - if (NEIClientConfig.saveCurrentRecipeInBookmarksEnabled() && handlerName != "" && ingredients != null && ingredients.size() > 0) { + if (NEIClientConfig.saveCurrentRecipeInBookmarksEnabled() && handlerName != "" && ingredients != null && !ingredients.isEmpty()) { recipeId = new BookmarkRecipeId(handlerName, ingredients); } @@ -277,7 +308,7 @@ public class BookmarkPanel extends ItemPanel BGrid.removeRecipe(idx, addFullRecipe); } else { - if (addFullRecipe && handlerName != "" && ingredients != null) { + if (addFullRecipe && handlerName != "" && ingredients != null && !ingredients.isEmpty()) { final Map unique = new HashMap<>(); final ArrayList sorted = new ArrayList<>(); @@ -297,12 +328,12 @@ public class BookmarkPanel extends ItemPanel for (NBTTagCompound nbTag : sorted) { nbTag.setInteger("Count", nbTag.getInteger("Count") * unique.get(nbTag)); - BGrid.addItem(StackInfo.loadFromNBT(nbTag), new BookmarkStackMeta(recipeId, nbTag.getInteger("Count"), true)); + BGrid.addItem(StackInfo.loadFromNBT(nbTag), new BookmarkStackMeta(recipeId, (saveStackSize ? 1: -1) * nbTag.getInteger("Count"), true, nbTag.hasKey("gtFluidName"))); } } - BGrid.addItem(normalizedA, new BookmarkStackMeta(recipeId, nbTagA.getInteger("Count"), false)); + BGrid.addItem(normalizedA, new BookmarkStackMeta(recipeId, (saveStackSize ? 1: -1) * nbTagA.getInteger("Count"), false, nbTagA.hasKey("gtFluidName"))); } @@ -560,8 +591,9 @@ public class BookmarkPanel extends ItemPanel if (itemStack != null) { namespaces.get(activeNamespaceIndex).addItem(itemStack, new BookmarkStackMeta( recipeId, - jsonObject.has("factor")? jsonObject.get("factor").getAsInt(): 1, - jsonObject.has("ingredient")? jsonObject.get("ingredient").getAsBoolean(): false + jsonObject.has("factor")? jsonObject.get("factor").getAsInt(): 0, + jsonObject.has("ingredient")? jsonObject.get("ingredient").getAsBoolean(): false, + itemStackNBT.hasKey("gtFluidName") )); } else { NEIClientConfig.logger.warn("Failed to load bookmarked ItemStack from json string, the item no longer exists:\n{}", itemStr); @@ -585,19 +617,38 @@ public class BookmarkPanel extends ItemPanel { loadBookmarksIfNeeded(); super.resize(gui); + } - final int buttonHeight = 16; - final int buttonWidth = 16; - final int buttonTop = gui.height - buttonHeight - 2; - final int leftBorder = LayoutManager.bookmarksButton.x + LayoutManager.bookmarksButton.w + 2; + @Override + protected int resizeHeader(GuiContainer gui) + { + final LayoutStyleMinecraft layout = (LayoutStyleMinecraft) LayoutManager.getLayoutStyle(); + final int rows = (int) Math.ceil((double) layout.buttonCount / layout.numButtons); + final int diff = rows * 18 + getMarginTop(gui) - y; + + if (diff > 0) { + y += diff; + h -= diff; + } + + return super.resizeHeader(gui); + } + + @Override + protected int resizeFooter(GuiContainer gui) + { + final int BUTTON_SIZE = 16; + + final ButtonCycled button = LayoutManager.bookmarksButton; + final int leftBorder = y + h > button.y? button.x + button.w + 2: x; final int rightBorder = x + w; - final int center = leftBorder + (rightBorder - leftBorder) / 2; + final int center = leftBorder + Math.max(0, (rightBorder - leftBorder) / 2); int labelWidth = 2; - namespacePrev.h = namespaceNext.h = buttonHeight; - namespacePrev.w = namespaceNext.w = buttonWidth; - namespacePrev.y = namespaceNext.y = buttonTop; + namespacePrev.h = namespaceNext.h = BUTTON_SIZE; + namespacePrev.w = namespaceNext.w = BUTTON_SIZE; + namespacePrev.y = namespaceNext.y = y + h - BUTTON_SIZE; if (rightBorder - leftBorder >= 70) { @@ -608,12 +659,13 @@ public class BookmarkPanel extends ItemPanel namespaceLabel.text = getNamespaceLabelText(true); } - namespaceLabel.y = buttonTop + 5; + namespaceLabel.y = namespacePrev.y + 5; namespaceLabel.x = center; namespacePrev.x = center - labelWidth / 2 - 2 - namespacePrev.w; namespaceNext.x = center + labelWidth / 2 + 2; + return BUTTON_SIZE + 2; } @Override @@ -621,38 +673,62 @@ public class BookmarkPanel extends ItemPanel { super.setVisible(); - LayoutManager.addWidget(namespacePrev); - LayoutManager.addWidget(namespaceNext); - LayoutManager.addWidget(namespaceLabel); + if (grid.getPerPage() > 0) { + LayoutManager.addWidget(namespacePrev); + LayoutManager.addWidget(namespaceNext); + LayoutManager.addWidget(namespaceLabel); + } + } + + protected String getPositioningSettingName() + { + return "world.panels.bookmarks"; } - @Override public int getMarginLeft(GuiContainer gui) { - return 5; + return PADDING; } - @Override public int getMarginTop(GuiContainer gui) { - LayoutStyleMinecraft layout = (LayoutStyleMinecraft)LayoutManager.getLayoutStyle(); - return 2 + (((int)Math.ceil((double)layout.buttonCount / layout.numButtons)) * 18); + return PADDING; } - @Override public int getWidth(GuiContainer gui) { - return LayoutManager.getLeftSize(gui) - ((gui.xSize + gui.width) / 2 + 3) - 16; + return gui.width - (gui.xSize + gui.width) / 2 - PADDING * 2; } - @Override public int getHeight(GuiContainer gui) { - // - 19 = 22 + 1 -> input in bottom - return gui.height - getMarginTop(gui) - 23; + return gui.height - getMarginTop(gui) - PADDING; } + protected ItemStack getDraggedStackWithQuantity(int mouseDownSlot) + { + final ItemStack stack = grid.getItem(mouseDownSlot); + + if (stack == null) { + return null; + } + + final BookmarkStackMeta meta = ((BookmarkGrid) grid).getMetadata(mouseDownSlot); + int amount = stack.stackSize; + + if (meta.factor < 0 && !meta.fluidDisplay) { + amount = NEIClientConfig.getItemQuantity(); + + if (amount == 0) { + amount = stack.getMaxStackSize(); + } + + } + + return NEIServerUtils.copyStack(stack, amount); + } + @Override public void mouseDragged(int mousex, int mousey, int button, long heldTime) { @@ -737,13 +813,6 @@ public class BookmarkPanel extends ItemPanel super.postDraw(mousex, mousey); } - @Override - protected ItemStack getDraggedStackWithQuantity(int mouseDownSlot) - { - ItemStack stack = grid.getItem(mouseDownSlot); - - return stack != null? stack.copy(): null; - } @Override public void mouseUp(int mousex, int mousey, int button) @@ -784,7 +853,6 @@ public class BookmarkPanel extends ItemPanel if (slot != null) { final BookmarkGrid BGrid = (BookmarkGrid)grid; final BookmarkRecipeId recipeId = BGrid.getRecipeId(slot.slotIndex); - final BookmarkStackMeta meta = BGrid.getMetadata(slot.slotIndex); final boolean addFullRecipe = NEIClientUtils.shiftKey(); if (addFullRecipe) { @@ -793,19 +861,15 @@ public class BookmarkPanel extends ItemPanel for (int slotIndex = grid.size() - 1; slotIndex >= 0; slotIndex--) { iMeta = BGrid.getMetadata(slotIndex); - if (iMeta.recipeId != null && iMeta.recipeId.equals(recipeId)) { - NBTTagCompound nbTag = StackInfo.itemStackToNBT(BGrid.getItem(slotIndex), true); - nbTag.setInteger("Count", Math.max(nbTag.getInteger("Count") + iMeta.factor * shift, iMeta.factor)); - BGrid.replaceItem(slotIndex, StackInfo.loadFromNBT(nbTag)); + if (iMeta.recipeId != null && iMeta.recipeId.equals(recipeId) && slotIndex != slot.slotIndex) { + shiftStackSize(slotIndex, shift); } } } - NBTTagCompound nbTag = StackInfo.itemStackToNBT(slot.item, true); - nbTag.setInteger("Count", Math.max(nbTag.getInteger("Count") + meta.factor * shift, meta.factor)); - BGrid.replaceItem(slot.slotIndex, StackInfo.loadFromNBT(nbTag)); + shiftStackSize(slot.slotIndex, shift); saveBookmarks(); @@ -817,4 +881,21 @@ public class BookmarkPanel extends ItemPanel return super.onMouseWheel(shift, mousex, mousey); } + protected void shiftStackSize(int slotIndex, int shift) + { + final BookmarkGrid BGrid = (BookmarkGrid)grid; + final NBTTagCompound nbTag = StackInfo.itemStackToNBT(BGrid.getItem(slotIndex), true); + final BookmarkStackMeta meta = BGrid.getMetadata(slotIndex); + final int factor = Math.abs(meta.factor); + + if (nbTag.getInteger("Count") == factor && meta.factor < 0 && shift > 0) { + meta.factor = factor; + } else { + meta.factor = nbTag.getInteger("Count") == factor && shift < 0? -1 * factor: factor; + nbTag.setInteger("Count", Math.max(nbTag.getInteger("Count") + factor * shift, factor)); + BGrid.replaceItem(slotIndex, StackInfo.loadFromNBT(nbTag)); + } + + } + } diff --git a/src/main/java/codechicken/nei/GuiExtendedCreativeInv.java b/src/main/java/codechicken/nei/GuiExtendedCreativeInv.java index b22f789c..47b97663 100644 --- a/src/main/java/codechicken/nei/GuiExtendedCreativeInv.java +++ b/src/main/java/codechicken/nei/GuiExtendedCreativeInv.java @@ -1,10 +1,12 @@ package codechicken.nei; import codechicken.lib.render.CCRenderState; +import codechicken.lib.vec.Rectangle4i; import codechicken.nei.api.INEIGuiHandler; import codechicken.nei.api.TaggedInventoryArea; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import org.lwjgl.opengl.GL11; @@ -50,7 +52,21 @@ public class GuiExtendedCreativeInv extends GuiContainer implements INEIGuiHandl } @Override - public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) { - return false; + public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) + { + return (new Rectangle4i(guiLeft - 15, guiTop + 18, 18, 18 * 4 + 4)).intersects(new Rectangle4i(x, y, w, h)); } + + @Override + protected void handleMouseClick(Slot p_146984_1_, int p_146984_2_, int p_146984_3_, int p_146984_4_) + { + + //Hack for armor slots, because they are outside the container + if (p_146984_1_ != null && p_146984_4_ == 4 && p_146984_1_.xDisplayPosition < 0) { + p_146984_4_ = 0; + } + + super.handleMouseClick(p_146984_1_, p_146984_2_, p_146984_3_, p_146984_4_); + } + } diff --git a/src/main/java/codechicken/nei/ItemPanel.java b/src/main/java/codechicken/nei/ItemPanel.java index 58d3cb91..ba5cb485 100644 --- a/src/main/java/codechicken/nei/ItemPanel.java +++ b/src/main/java/codechicken/nei/ItemPanel.java @@ -1,37 +1,16 @@ package codechicken.nei; import codechicken.lib.vec.Rectangle4i; -import codechicken.nei.api.GuiInfo; -import codechicken.nei.api.INEIGuiHandler; -import codechicken.nei.guihook.GuiContainerManager; -import codechicken.nei.recipe.GuiCraftingRecipe; -import codechicken.nei.recipe.GuiRecipe; -import codechicken.nei.recipe.GuiUsageRecipe; -import codechicken.nei.recipe.StackInfo; import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.gui.inventory.GuiContainerCreative; -import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.IFluidContainerItem; import static codechicken.lib.gui.GuiDraw.drawRect; -import static codechicken.nei.LayoutManager.searchField; import java.util.ArrayList; -import java.util.regex.Pattern; -public class ItemPanel extends Widget +public class ItemPanel extends PanelWidget { - - public ItemStack draggedStack; - public int mouseDownSlot = -1; - - public Button pagePrev; - public Button pageNext; - public Label pageLabel; - + /** * Backwards compat :-/ */ @@ -44,7 +23,9 @@ public class ItemPanel extends Widget @Deprecated public ArrayList realItems = new ArrayList<>(); - protected Pattern SPECIAL_REGEX_CHARS = Pattern.compile("[{}()\\[\\].+*?^$\\\\|]"); + public Button more; + public Button less; + public ItemQuantityField quantity; public static class ItemPanelSlot { @@ -99,11 +80,9 @@ public class ItemPanel extends Widget } - protected ItemsGrid grid = new ItemPanelGrid(); - - public ArrayList getItems() + public ItemPanel() { - return grid.getItems(); + grid = new ItemPanelGrid(); } public static void updateItemList(ArrayList newItems) @@ -112,149 +91,116 @@ public class ItemPanel extends Widget ItemPanels.itemPanel.realItems = newItems; } + @Override + public void init() + { + super.init(); + + more = new Button("+") + { + @Override + public boolean onButtonPress(boolean rightclick) { + if (rightclick) + return false; + + int modifier = NEIClientUtils.controlKey() ? 64 : NEIClientUtils.shiftKey() ? 10 : 1; + int quantity = NEIClientConfig.getItemQuantity() + modifier; + + if (quantity < 0) { + quantity = 0; + } + + ItemPanels.itemPanel.quantity.setText(Integer.toString(quantity)); + return true; + } + }; + less = new Button("-") + { + @Override + public boolean onButtonPress(boolean rightclick) { + if (rightclick) + return false; + + int modifier = NEIClientUtils.controlKey() ? -64 : NEIClientUtils.shiftKey() ? -10 : -1; + int quantity = NEIClientConfig.getItemQuantity() + modifier; + + if (quantity < 0) { + quantity = 0; + } + + ItemPanels.itemPanel.quantity.setText(Integer.toString(quantity)); + return true; + } + }; + + quantity = new ItemQuantityField("quantity"); + + } + @Deprecated public void scroll(int i) { grid.shiftPage(i); } - - public ItemsGrid getGrid() + + public String getLabelText() { - return grid; + return String.format("(%d/%d)", getPage(), Math.max(1, getNumPages())); } - public void init() { - pageLabel = new Label("(0/0)", true); - - pagePrev = new Button("Prev") - { - public boolean onButtonPress(boolean rightclick) { - if (!rightclick) { - grid.shiftPage(-1); - return true; - } - return false; - } - - @Override - public String getRenderLabel() { - return "<"; - } - }; - pageNext = new Button("Next") - { - public boolean onButtonPress(boolean rightclick) { - if (!rightclick) { - grid.shiftPage(1); - return true; - } - return false; - } - - @Override - public String getRenderLabel() { - return ">"; - } - }; - + protected String getPositioningSettingName() + { + return "world.panels.items"; } public int getMarginLeft(GuiContainer gui) { - if (gui instanceof GuiContainerCreative && NEIClientUtils.getGamemode() == 2) { - //then activate creative+ first render creative gui and oly then creative+ - return (gui.width + 176) / 2 + 2; - } - - return (gui.width + gui.xSize) / 2 + 2; + return (gui.width + gui.xSize) / 2 + PADDING; } public int getMarginTop(GuiContainer gui) { - return 2; + return PADDING; } public int getWidth(GuiContainer gui) { - return LayoutManager.getSideWidth(gui) - getMarginLeft(gui); + return gui.width - (gui.xSize + gui.width) / 2 - PADDING * 2; } public int getHeight(GuiContainer gui) { - // - 19 = 2 + 16 + 1 -> input in bottom - return gui.height - getMarginTop(gui) - 19; + return gui.height - getMarginTop(gui) - PADDING; } - public String getLabelText() + protected int resizeFooter(GuiContainer gui) { - return "(" + getPage() + "/" + Math.max(1, getNumPages()) + ")"; - } - - public void resize(GuiContainer gui) - { - final int marginLeft = getMarginLeft(gui); - final int marginTop = getMarginTop(gui); - final int width = getWidth(gui); - final int height = getHeight(gui); - final int buttonHeight = 16; - final int buttonWidth = 16; - - pagePrev.w = pageNext.w = buttonWidth; - pagePrev.h = pageNext.h = buttonHeight; - pagePrev.y = pageNext.y = marginTop; - - pagePrev.x = marginLeft; - pageNext.x = marginLeft + width - buttonWidth; - - pageLabel.x = marginLeft + width / 2; - pageLabel.y = marginTop + 5; - pageLabel.text = getLabelText(); - - - y = marginTop + buttonHeight + 2; - x = marginLeft; - w = width; - h = height - buttonHeight - 2; - - grid.setGridSize(x, y, w, h); - grid.refresh(gui); - + final int BUTTON_SIZE = 16; + + more.w = less.w = BUTTON_SIZE; + more.h = less.h = quantity.h = BUTTON_SIZE; + + less.x = x; + more.x = x + w - BUTTON_SIZE; + more.y = less.y = quantity.y = y + h - BUTTON_SIZE; + + quantity.x = x + BUTTON_SIZE + 2; + quantity.w = more.x - quantity.x - 2; + + return BUTTON_SIZE + 2; } + @Override public void setVisible() { - LayoutManager.addWidget(pagePrev); - LayoutManager.addWidget(pageNext); - LayoutManager.addWidget(pageLabel); - } - - @Override - public void draw(int mousex, int mousey) - { - grid.draw(mousex, mousey); - } - - @Override - public void postDraw(int mousex, int mousey) { - if (draggedStack != null) { - GuiContainerManager.drawItems.zLevel += 100; - GuiContainerManager.drawItem(mousex - 8, mousey - 8, draggedStack, true); - GuiContainerManager.drawItems.zLevel -= 100; - } - } - - @Override - public void mouseDragged(int mousex, int mousey, int button, long heldTime) { - if (mouseDownSlot >= 0 && draggedStack == null && NEIClientUtils.getHeldItem() == null && - NEIClientConfig.hasSMPCounterPart() && !GuiInfo.hasCustomSlots(NEIClientUtils.getGuiContainer())) { - ItemPanelSlot mouseOverSlot = getSlotMouseOver(mousex, mousey); - - if (mouseOverSlot == null || mouseOverSlot.slotIndex != mouseDownSlot || heldTime > 500) { - draggedStack = getDraggedStackWithQuantity(mouseDownSlot); - mouseDownSlot = -1; - } - + super.setVisible(); + + if (grid.getPerPage() > 0) { + LayoutManager.addWidget(more); + LayoutManager.addWidget(less); + LayoutManager.addWidget(quantity); } + } protected ItemStack getDraggedStackWithQuantity(int mouseDownSlot) @@ -274,288 +220,4 @@ public class ItemPanel extends Widget return null; } - @Override - public boolean handleClick(int mousex, int mousey, int button) - { - - if (handleClickExt(mousex, mousey, button)) - return true; - - if (NEIClientUtils.getHeldItem() != null) { - - if (!grid.contains(mousex, mousey)) { - return false; - } - - if (NEIClientConfig.canPerformAction("delete") && NEIClientConfig.canPerformAction("item")) - if (button == 1) - NEIClientUtils.decreaseSlotStack(-999); - else - NEIClientUtils.deleteHeldItem(); - else - NEIClientUtils.dropHeldItem(); - - return true; - } - - ItemPanelSlot hoverSlot = getSlotMouseOver(mousex, mousey); - if (hoverSlot != null) { - - if (button == 2) { - - if (hoverSlot.item != null) { - draggedStack = getDraggedStackWithQuantity(hoverSlot.slotIndex); - } - - } else { - mouseDownSlot = hoverSlot.slotIndex; - } - - return true; - } - return false; - } - - @Override - public boolean handleClickExt(int mouseX, int mouseY, int button) - { - if (ItemPanels.itemPanel.draggedStack != null) { - return ItemPanels.itemPanel.handleDraggedClick(mouseX, mouseY, button); - } - - if (ItemPanels.bookmarkPanel.draggedStack != null) { - return ItemPanels.bookmarkPanel.handleDraggedClick(mouseX, mouseY, button); - } - - return false; - } - - protected boolean handleDraggedClick(int mouseX, int mouseY, int button) - { - if (draggedStack == null) { - return false; - } - - if (handleFillFluidContainerClick(mouseX, mouseY, button)) { - return true; - } - - if (handleSearchInputClick(mouseX, mouseY, button)) { - return true; - } - - if (handleGUIContainerClick(mouseX, mouseY, button)) { - return true; - } - - if (handleCheatItemClick(mouseX, mouseY, button)) { - return true; - } - - final GuiContainer gui = NEIClientUtils.getGuiContainer(); - if (mouseX < gui.guiLeft || mouseY < gui.guiTop || mouseX >= gui.guiLeft + gui.xSize || mouseY >= gui.guiTop + gui.ySize) { - draggedStack = null; - } - - return true; - } - - protected boolean handleFillFluidContainerClick(int mouseX, int mouseY, int button) - { - - if (button == 2) { - return false; - } - - ItemPanelSlot mouseOverSlot = ItemPanels.itemPanel.getSlotMouseOver(mouseX, mouseY); - - if (mouseOverSlot == null) { - mouseOverSlot = ItemPanels.bookmarkPanel.getSlotMouseOver(mouseX, mouseY); - } - - if (mouseOverSlot != null && draggedStack.getItem() instanceof IFluidContainerItem) { - FluidStack fluidStack = StackInfo.getFluid(mouseOverSlot.item); - - if (fluidStack != null) { - final int stackSize = draggedStack.stackSize; - - fluidStack = fluidStack.copy(); - - if (fluidStack.amount == 0) { - fluidStack.amount = 1000; - } - - if (mouseOverSlot.item.stackSize > 1) { - fluidStack.amount *= mouseOverSlot.item.stackSize; - } - - draggedStack.stackSize = 1; - ((IFluidContainerItem) draggedStack.getItem()).fill(draggedStack, fluidStack, true); - draggedStack.stackSize = stackSize; - - if (button == 1 && ((IFluidContainerItem) draggedStack.getItem()).getFluid(draggedStack) != null) { - ItemPanels.bookmarkPanel.addOrRemoveItem(draggedStack.copy()); - } - - } - - return true; - } - - return false; - } - - protected boolean handleGUIContainerClick(int mouseX, int mouseY, int button) - { - final GuiContainer gui = NEIClientUtils.getGuiContainer(); - boolean handled = false; - - try { - GuiInfo.readLock.lock(); - for (INEIGuiHandler handler : GuiInfo.guiHandlers) { - if (handler.handleDragNDrop(gui, mouseX, mouseY, draggedStack, button)) { - handled = true; - break; - } - } - } finally { - GuiInfo.readLock.unlock(); - } - - if (draggedStack.stackSize == 0) { - draggedStack = null; - } - - return handled; - } - - protected boolean handleCheatItemClick(int mouseX, int mouseY, int button) - { - final GuiContainer gui = NEIClientUtils.getGuiContainer(); - final Slot overSlot = gui.getSlotAtPosition(mouseX, mouseY); - - if (overSlot != null && overSlot.isItemValid(draggedStack)) { - - if (NEIClientConfig.canCheatItem(draggedStack)) { - int contents = overSlot.getHasStack() ? overSlot.getStack().stackSize : 0; - final int add = button == 0 ? draggedStack.stackSize : 1; - - if (overSlot.getHasStack() && !NEIServerUtils.areStacksSameType(draggedStack, overSlot.getStack())) { - contents = 0; - } - - final int total = Math.min(contents + add, Math.min(overSlot.getSlotStackLimit(), draggedStack.getMaxStackSize())); - - if (total > contents) { - NEIClientUtils.setSlotContents(overSlot.slotNumber, NEIServerUtils.copyStack(draggedStack, total), true); - NEICPH.sendGiveItem(NEIServerUtils.copyStack(draggedStack, total), false, false); - draggedStack.stackSize -= total - contents; - } - - if (draggedStack.stackSize == 0) { - draggedStack = null; - } - - } else { - draggedStack = null; - } - - return true; - } - - return false; - } - - protected boolean handleSearchInputClick(int mouseX, int mouseY, int button) - { - - if (searchField.contains(mouseX, mouseY)) { - final FluidStack fluidStack = StackInfo.getFluid(draggedStack); - - if (fluidStack != null) { - searchField.setText(SPECIAL_REGEX_CHARS.matcher(EnumChatFormatting.getTextWithoutFormattingCodes(fluidStack.getLocalizedName())).replaceAll("\\\\$0")); - } else { - searchField.setText(SPECIAL_REGEX_CHARS.matcher(EnumChatFormatting.getTextWithoutFormattingCodes(draggedStack.getDisplayName())).replaceAll("\\\\$0")); - } - - return true; - } - - return false; - } - - @Override - public void mouseUp(int mousex, int mousey, int button) { - ItemPanelSlot hoverSlot = getSlotMouseOver(mousex, mousey); - - if (hoverSlot != null && hoverSlot.slotIndex == mouseDownSlot && draggedStack == null) { - ItemStack item = hoverSlot.item; - - if (NEIController.manager.window instanceof GuiRecipe || !NEIClientConfig.canCheatItem(item)) { - - if (button == 0) - GuiCraftingRecipe.openRecipeGui("item", item); - else if (button == 1) - GuiUsageRecipe.openRecipeGui("item", item); - - mouseDownSlot = -1; - return; - } - - NEIClientUtils.cheatItem(getDraggedStackWithQuantity(hoverSlot.slotIndex), button, -1); - } - - mouseDownSlot = -1; - } - - @Override - public boolean onMouseWheel(int i, int mousex, int mousey) { - if (!contains(mousex, mousey)) - return false; - - grid.shiftPage(-i); - return true; - } - - @Override - public boolean handleKeyPress(int keyID, char keyChar) { - - if (keyID == NEIClientConfig.getKeyBinding("gui.next")) { - grid.shiftPage(1); - return true; - } - - if (keyID == NEIClientConfig.getKeyBinding("gui.prev")) { - grid.shiftPage(-1); - return true; - } - - return false; - } - - @Override - public ItemStack getStackMouseOver(int mousex, int mousey) { - ItemPanelSlot slot = getSlotMouseOver(mousex, mousey); - return slot == null ? null : slot.item; - } - - public ItemPanelSlot getSlotMouseOver(int mousex, int mousey) - { - return grid.getSlotMouseOver(mousex, mousey); - } - - public int getPage() { - return grid.page + 1; - } - - public int getNumPages() { - return grid.numPages; - } - - @Override - public boolean contains(int px, int py) - { - return grid.contains(px, py); - } - } diff --git a/src/main/java/codechicken/nei/ItemsGrid.java b/src/main/java/codechicken/nei/ItemsGrid.java index abd55d30..868f0c83 100644 --- a/src/main/java/codechicken/nei/ItemsGrid.java +++ b/src/main/java/codechicken/nei/ItemsGrid.java @@ -22,6 +22,8 @@ public class ItemsGrid protected int marginLeft; protected int marginTop; + protected int paddingLeft; + protected ArrayList realItems = new ArrayList<>(); protected int page; @@ -100,6 +102,7 @@ public class ItemsGrid columns = width / SLOT_SIZE; rows = height / SLOT_SIZE; + paddingLeft = (width % SLOT_SIZE) / 2; } public void shiftPage(int shift) @@ -150,7 +153,7 @@ public class ItemsGrid for (int r = 0; r < rows; r++) { final int idx = columns * r + c; - if (!slotValid(gui, r, c) && idx >= 0 && idx < invalidSlotMap.length && !invalidSlotMap[idx]) { + if (GuiInfo.hideItemPanelSlot(gui, getSlotRect(r, c)) && idx >= 0 && idx < invalidSlotMap.length && !invalidSlotMap[idx]) { invalidSlotMap[idx] = true; validColumn = false; perPage--; @@ -162,22 +165,6 @@ public class ItemsGrid } - private boolean slotValid(GuiContainer gui, int row, int column) - { - Rectangle4i rect = getSlotRect(row, column); - - try { - GuiInfo.readLock.lock(); - if (GuiInfo.guiHandlers.stream().anyMatch(handler -> handler.hideItemPanelSlot(gui, rect.x, rect.y, rect.w, rect.h))) { - return false; - } - } finally { - GuiInfo.readLock.unlock(); - } - - return true; - } - public Rectangle4i getSlotRect(int i) { return getSlotRect(i / columns, i % columns); @@ -185,7 +172,7 @@ public class ItemsGrid public Rectangle4i getSlotRect(int row, int column) { - return new Rectangle4i(marginLeft + (width % SLOT_SIZE) / 2 + column * SLOT_SIZE, marginTop + row * SLOT_SIZE, SLOT_SIZE, SLOT_SIZE); + return new Rectangle4i(marginLeft + paddingLeft + column * SLOT_SIZE, marginTop + row * SLOT_SIZE, SLOT_SIZE, SLOT_SIZE); } public boolean isInvalidSlot(int idx) @@ -233,7 +220,7 @@ public class ItemsGrid } final int overRow = (int) ((mousey - marginTop) / SLOT_SIZE); - final int overColumn = (int) ((mousex - marginLeft - (width % SLOT_SIZE) / 2) / SLOT_SIZE); + final int overColumn = (int) ((mousex - marginLeft - paddingLeft) / SLOT_SIZE); final int slt = columns * overRow + overColumn; int idx = page * perPage + slt; @@ -253,12 +240,12 @@ public class ItemsGrid public boolean contains(int px, int py) { - if (!(new Rectangle4i(marginLeft, marginTop, width, height)).contains(px, py)) { + if (!(new Rectangle4i(marginLeft + paddingLeft, marginTop, columns * SLOT_SIZE, height)).contains(px, py)) { return false; } final int r = (int) ((py - marginTop) / SLOT_SIZE); - final int c = (int) ((px - marginLeft - (width % SLOT_SIZE) / 2) / SLOT_SIZE); + final int c = (int) ((px - marginLeft - paddingLeft) / SLOT_SIZE); final int slt = columns * r + c; return r >= rows || c >= columns || !invalidSlotMap[slt]; diff --git a/src/main/java/codechicken/nei/LayoutManager.java b/src/main/java/codechicken/nei/LayoutManager.java index 0de6c23b..642f17c3 100644 --- a/src/main/java/codechicken/nei/LayoutManager.java +++ b/src/main/java/codechicken/nei/LayoutManager.java @@ -37,7 +37,6 @@ import static codechicken.lib.gui.GuiDraw.drawRect; import static codechicken.lib.gui.GuiDraw.drawTexturedModalRect; import static codechicken.nei.NEIClientConfig.canPerformAction; import static codechicken.nei.NEIClientConfig.disabledActions; -import static codechicken.nei.NEIClientConfig.getItemQuantity; import static codechicken.nei.NEIClientConfig.getKeyBinding; import static codechicken.nei.NEIClientConfig.getOptionList; import static codechicken.nei.NEIClientConfig.getSearchExpression; @@ -49,7 +48,6 @@ import static codechicken.nei.NEIClientConfig.isHidden; import static codechicken.nei.NEIClientConfig.showIDs; import static codechicken.nei.NEIClientConfig.toggleBooleanSetting; import static codechicken.nei.NEIClientConfig.world; -import static codechicken.nei.NEIClientUtils.controlKey; import static codechicken.nei.NEIClientUtils.cycleGamemode; import static codechicken.nei.NEIClientUtils.decreaseSlotStack; import static codechicken.nei.NEIClientUtils.deleteEverything; @@ -92,8 +90,11 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH public static ButtonCycled options; public static ButtonCycled bookmarksButton; + @Deprecated public static Button more; + @Deprecated public static Button less; + @Deprecated public static ItemQuantityField quantity; public static Button delete; @@ -142,9 +143,12 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH } } + @Deprecated public static int getSideWidth(GuiContainer gui) { return gui.width - 3; } + + @Deprecated public static int getLeftSize(GuiContainer gui) { return getSideWidth(gui); } @@ -307,6 +311,7 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH public static void layout(GuiContainer gui) { VisiblityData visiblity = new VisiblityData(); + if (isHidden()) visiblity.showNEI = false; @@ -324,6 +329,7 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH if (gui.guiLeft - 4 < 76) visiblity.showWidgets = false; + try { GuiInfo.readLock.lock(); GuiInfo.guiHandlers.forEach(handler -> handler.modifyVisiblity(gui, visiblity)); @@ -419,43 +425,10 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH return translate("bookmark.toggle"); } }; - more = new Button("+") - { - @Override - public boolean onButtonPress(boolean rightclick) { - if (rightclick) - return false; - - int modifier = controlKey() ? 64 : shiftKey() ? 10 : 1; - - int quantity = getItemQuantity() + modifier; - if (quantity < 0) - quantity = 0; - - LayoutManager.quantity.setText(Integer.toString(quantity)); - return true; - } - }; - less = new Button("-") - { - @Override - public boolean onButtonPress(boolean rightclick) { - if (rightclick) - return false; - - int modifier = controlKey() ? -64 : shiftKey() ? -10 : -1; - - int quantity = getItemQuantity() + modifier; - if (quantity < 0) - quantity = 0; - - LayoutManager.quantity.setText(Integer.toString(quantity)); - return true; - } - }; - quantity = new ItemQuantityField("quantity"); - + more = ItemPanels.itemPanel.more; + less = ItemPanels.itemPanel.less; + quantity = ItemPanels.itemPanel.quantity; delete = new Button() { @Override @@ -687,10 +660,6 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH } itemPanel.setVisible(); - - addWidget(more); - addWidget(less); - addWidget(quantity); } if (visiblity.showBookmarkPanel) { @@ -805,7 +774,7 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH @Override public void renderSlotOverlay(GuiContainer window, Slot slot) { ItemStack item = slot.getStack(); - if (world.nbt.getBoolean("searchinventories") && (item == null ? !getSearchExpression().equals("") : !ItemList.getItemListFilter().matches(item))) { + if (world.nbt.getBoolean("searchinventories") && (item == null ? !getSearchExpression().equals("") : !((SearchField) searchField).getFilter().matches(item))) { GL11.glDisable(GL11.GL_LIGHTING); GL11.glTranslatef(0, 0, 150); drawRect(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, 0x80000000); diff --git a/src/main/java/codechicken/nei/LayoutStyleMinecraft.java b/src/main/java/codechicken/nei/LayoutStyleMinecraft.java index e7118825..708ea1f6 100644 --- a/src/main/java/codechicken/nei/LayoutStyleMinecraft.java +++ b/src/main/java/codechicken/nei/LayoutStyleMinecraft.java @@ -10,15 +10,13 @@ import static codechicken.nei.LayoutManager.bookmarkPanel; import static codechicken.nei.LayoutManager.bookmarksButton; import static codechicken.nei.LayoutManager.delete; import static codechicken.nei.LayoutManager.dropDown; +import static codechicken.nei.LayoutManager.presetsPanel; import static codechicken.nei.LayoutManager.gamemode; import static codechicken.nei.LayoutManager.heal; import static codechicken.nei.LayoutManager.itemPanel; import static codechicken.nei.LayoutManager.itemPresenceOverlays; -import static codechicken.nei.LayoutManager.less; import static codechicken.nei.LayoutManager.magnet; -import static codechicken.nei.LayoutManager.more; import static codechicken.nei.LayoutManager.options; -import static codechicken.nei.LayoutManager.quantity; import static codechicken.nei.LayoutManager.rain; import static codechicken.nei.LayoutManager.searchField; import static codechicken.nei.LayoutManager.timeButtons; @@ -118,16 +116,6 @@ public class LayoutStyleMinecraft extends LayoutStyle itemPanel.resize(gui); bookmarkPanel.resize(gui); - more.w = more.h = less.w = less.h = 16; - less.x = itemPanel.pagePrev.x; - more.x = gui.width - less.w - 2; - more.y = less.y = gui.height - more.h - 2; - - quantity.x = less.x + less.w + 2; - quantity.y = less.y; - quantity.w = more.x - quantity.x - 2; - quantity.h = less.h; - options.x = isEnabled() ? 0 : 6; options.y = isEnabled() ? gui.height - 22 : gui.height - 28; options.w = 22; @@ -138,15 +126,20 @@ public class LayoutStyleMinecraft extends LayoutStyle bookmarksButton.w = 22; bookmarksButton.h = 22; - searchField.y = gui.height - searchField.h - 2; + dropDown.h = 18; + dropDown.w = 150; + dropDown.y = 0; + dropDown.x = (gui.width - gui.xSize) / 2 + gui.xSize - dropDown.w; - dropDown.x = Math.min(numButtons, buttonCount) * 20 + 3; - dropDown.h = 20; - dropDown.w = itemPanel.x - dropDown.x - 3; + presetsPanel.h = 16; + presetsPanel.w = 150; + presetsPanel.y = 2; + presetsPanel.x = (gui.width - gui.xSize) / 2 + gui.xSize - presetsPanel.w; searchField.h = 20; searchField.w = 150; searchField.x = (gui.width - searchField.w) / 2; + searchField.y = gui.height - searchField.h - 2; if (!visiblity.showItemSection) { searchField.setFocus(false); @@ -155,8 +148,8 @@ public class LayoutStyleMinecraft extends LayoutStyle } public void layoutButton(Button button) { - button.x = 2 + (buttonCount % numButtons) * 20; - button.y = (buttonCount / numButtons) * 18; + button.x = 2 + (buttonCount % numButtons) * 19; + button.y = 2 + (buttonCount / numButtons) * 18; button.h = 17; button.w = button.contentWidth() + 6; diff --git a/src/main/java/codechicken/nei/NEIClientConfig.java b/src/main/java/codechicken/nei/NEIClientConfig.java index 319c3e5e..9bd12dc8 100644 --- a/src/main/java/codechicken/nei/NEIClientConfig.java +++ b/src/main/java/codechicken/nei/NEIClientConfig.java @@ -16,6 +16,7 @@ import codechicken.nei.config.ConfigSet; import codechicken.nei.config.GuiHighlightTips; import codechicken.nei.config.GuiNEIOptionList; import codechicken.nei.config.GuiOptionList; +import codechicken.nei.config.GuiPanelSettings; import codechicken.nei.config.OptionCycled; import codechicken.nei.config.OptionGamemodes; import codechicken.nei.config.OptionList; @@ -154,6 +155,20 @@ public class NEIClientConfig { tag.getTag("world.highlight_tips.y").getIntValue(100); API.addOption(new OptionOpenGui("world.highlight_tips", GuiHighlightTips.class)); + + tag.getTag("world.panels.bookmarks.left").getIntValue(0); + tag.getTag("world.panels.bookmarks.right").getIntValue(0); + tag.getTag("world.panels.bookmarks.top").getIntValue(0); + tag.getTag("world.panels.bookmarks.bottom").getIntValue(0); + + tag.getTag("world.panels.items.left").getIntValue(0); + tag.getTag("world.panels.items.right").getIntValue(0); + tag.getTag("world.panels.items.top").getIntValue(0); + tag.getTag("world.panels.items.bottom").getIntValue(0); + + API.addOption(new OptionOpenGui("world.panels", GuiPanelSettings.class)); + + tag.getTag("inventory.profileRecipes").getBooleanValue(false); API.addOption(new OptionToggleButton("inventory.profileRecipes", true)); @@ -207,6 +222,8 @@ public class NEIClientConfig { API.addOption(new OptionToggleButton("inventory.saveCurrentRecipeInBookmarksEnabled", true)); tag.getTag("inventory.useNBTInBookmarks").setComment("Use NBT in Bookmarks").getBooleanValue(true); API.addOption(new OptionToggleButton("inventory.useNBTInBookmarks", true)); + tag.getTag("inventory.showRecipeMarker").setComment("Show Recipe Marker").getBooleanValue(false); + API.addOption(new OptionToggleButton("inventory.showRecipeMarker", true)); tag.getTag("inventory.jei_style_tabs").setComment("Enable/disable JEI Style Tabs").getBooleanValue(true); API.addOption(new OptionToggleButtonBoubs("inventory.jei_style_tabs", true)); @@ -325,7 +342,7 @@ public class NEIClientConfig { setWorldDefaults(); creativeInv = new ItemStack[54]; LayoutManager.searchField.setText(getSearchExpression()); - LayoutManager.quantity.setText(Integer.toString(getItemQuantity())); + ItemPanels.itemPanel.quantity.setText(Integer.toString(getItemQuantity())); SubsetWidget.loadHidden(); if (newWorld && Minecraft.getMinecraft().isSingleplayer()) @@ -434,6 +451,9 @@ public class NEIClientConfig { public static boolean useNBTInBookmarks() { return getBooleanSetting("inventory.useNBTInBookmarks"); } + public static boolean showRecipeMarker() { + return getBooleanSetting("inventory.showRecipeMarker"); + } public static boolean areJEIStyleTabsVisible() { return getBooleanSetting("inventory.jei_style_tabs"); } diff --git a/src/main/java/codechicken/nei/PanelWidget.java b/src/main/java/codechicken/nei/PanelWidget.java new file mode 100644 index 00000000..7033a503 --- /dev/null +++ b/src/main/java/codechicken/nei/PanelWidget.java @@ -0,0 +1,375 @@ +package codechicken.nei; + +import codechicken.nei.api.GuiInfo; +import codechicken.nei.api.INEIGuiHandler; +import codechicken.nei.guihook.GuiContainerManager; +import codechicken.nei.recipe.GuiCraftingRecipe; +import codechicken.nei.recipe.GuiRecipe; +import codechicken.nei.recipe.GuiUsageRecipe; +import codechicken.lib.vec.Rectangle4i; +import codechicken.nei.ItemPanel.ItemPanelSlot; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.item.ItemStack; + +import java.util.ArrayList; + +public abstract class PanelWidget extends Widget +{ + protected static final int PADDING = 2; + + public ItemStack draggedStack; + public int mouseDownSlot = -1; + + public Button pagePrev; + public Button pageNext; + public Label pageLabel; + + protected ItemsGrid grid; + + public ArrayList getItems() + { + return grid.getItems(); + } + + public ItemsGrid getGrid() + { + return grid; + } + + public void init() { + pageLabel = new Label("0/0", true); + + pagePrev = new Button("Prev") + { + public boolean onButtonPress(boolean rightclick) { + if (!rightclick) { + grid.shiftPage(-1); + return true; + } + return false; + } + + @Override + public String getRenderLabel() { + return "<"; + } + }; + pageNext = new Button("Next") + { + public boolean onButtonPress(boolean rightclick) { + if (!rightclick) { + grid.shiftPage(1); + return true; + } + return false; + } + + @Override + public String getRenderLabel() { + return ">"; + } + }; + + } + + + public abstract String getLabelText(); + + protected abstract String getPositioningSettingName(); + + public abstract int getMarginLeft(GuiContainer gui); + + public abstract int getMarginTop(GuiContainer gui); + + public abstract int getWidth(GuiContainer gui); + + public abstract int getHeight(GuiContainer gui); + + public void resize(GuiContainer gui) + { + final Rectangle4i margin = new Rectangle4i(getMarginLeft(gui), getMarginTop(gui), getWidth(gui), getHeight(gui)); + + + final int minWidth = 5 * ItemsGrid.SLOT_SIZE; + final int minHeight = 9 * ItemsGrid.SLOT_SIZE; + + final String settingName = getPositioningSettingName(); + int paddingLeft = (int)Math.ceil(margin.w * NEIClientConfig.getSetting(settingName + ".left").getIntValue() / 100000.0); + int paddingTop = (int)Math.ceil(margin.h * NEIClientConfig.getSetting(settingName + ".top").getIntValue() / 100000.0); + int paddingRight = (int)Math.ceil(margin.w * NEIClientConfig.getSetting(settingName + ".right").getIntValue()/ 100000.0); + int paddingBottom = (int)Math.ceil(margin.h * NEIClientConfig.getSetting(settingName + ".bottom").getIntValue() / 100000.0); + + int deltaHeight = Math.min(0, margin.h - paddingTop - paddingBottom - minHeight) / 2; + + paddingLeft = Math.min(paddingLeft, Math.max(0, margin.w - paddingRight - minWidth)); + paddingRight = Math.min(paddingRight, Math.max(0, margin.w - paddingLeft - minWidth)); + paddingTop = Math.min(margin.h - minHeight, Math.max(0, paddingTop + deltaHeight)); + paddingBottom = Math.min(margin.h - paddingTop - minHeight, Math.max(0, paddingBottom - deltaHeight)); + + x = margin.x + paddingLeft; + y = margin.y + paddingTop; + w = margin.w - paddingLeft - paddingRight; + h = margin.h - paddingTop - paddingBottom; + + final int header = resizeHeader(gui); + final int footer = resizeFooter(gui); + + grid.setGridSize(x, y + header, w, h - header - footer); + grid.refresh(gui); + } + + protected int resizeHeader(GuiContainer gui) + { + final int BUTTON_SIZE = 16; + int paddingLeft = 0; + int paddingRight = 0; + + while (paddingLeft < w && GuiInfo.hideItemPanelSlot(gui, new Rectangle4i(x + paddingLeft, y, ItemsGrid.SLOT_SIZE, ItemsGrid.SLOT_SIZE))) { + paddingLeft += ItemsGrid.SLOT_SIZE; + } + + while (paddingRight < w && GuiInfo.hideItemPanelSlot(gui, new Rectangle4i(x + w - paddingRight - ItemsGrid.SLOT_SIZE, y, ItemsGrid.SLOT_SIZE, ItemsGrid.SLOT_SIZE))) { + paddingRight += ItemsGrid.SLOT_SIZE; + } + + if (paddingLeft + paddingRight >= w) { + return 0; + } + + pagePrev.w = pageNext.w = BUTTON_SIZE; + pagePrev.h = pageNext.h = BUTTON_SIZE; + pagePrev.y = pageNext.y = y; + + pagePrev.x = x + paddingLeft; + pageNext.x = x + w - pageNext.w - paddingRight; + + pageLabel.x = x + paddingLeft + (w - paddingLeft - paddingRight) / 2; + pageLabel.y = y + 5; + pageLabel.text = getLabelText(); + + return BUTTON_SIZE + 2; + } + + protected abstract int resizeFooter(GuiContainer gui); + + public void setVisible() + { + if (grid.getPerPage() > 0) { + LayoutManager.addWidget(pagePrev); + LayoutManager.addWidget(pageNext); + LayoutManager.addWidget(pageLabel); + } + } + + @Override + public void draw(int mousex, int mousey) + { + grid.draw(mousex, mousey); + } + + @Override + public void postDraw(int mousex, int mousey) + { + if (draggedStack != null) { + GuiContainerManager.drawItems.zLevel += 100; + GuiContainerManager.drawItem(mousex - 8, mousey - 8, draggedStack); + GuiContainerManager.drawItems.zLevel -= 100; + } + } + + @Override + public void mouseDragged(int mousex, int mousey, int button, long heldTime) + { + if (mouseDownSlot >= 0 && draggedStack == null && NEIClientUtils.getHeldItem() == null && + NEIClientConfig.hasSMPCounterPart() && !GuiInfo.hasCustomSlots(NEIClientUtils.getGuiContainer())) { + ItemPanelSlot mouseOverSlot = getSlotMouseOver(mousex, mousey); + + if (mouseOverSlot == null || mouseOverSlot.slotIndex != mouseDownSlot || heldTime > 500) { + draggedStack = getDraggedStackWithQuantity(mouseDownSlot); + mouseDownSlot = -1; + } + + } + } + + protected abstract ItemStack getDraggedStackWithQuantity(int mouseDownSlot); + + @Override + public boolean handleClick(int mousex, int mousey, int button) + { + + if (handleClickExt(mousex, mousey, button)) + return true; + + if (NEIClientUtils.getHeldItem() != null) { + + if (!grid.contains(mousex, mousey)) { + return false; + } + + if (NEIClientConfig.canPerformAction("delete") && NEIClientConfig.canPerformAction("item")) + if (button == 1) + NEIClientUtils.decreaseSlotStack(-999); + else + NEIClientUtils.deleteHeldItem(); + else + NEIClientUtils.dropHeldItem(); + + return true; + } + + ItemPanelSlot hoverSlot = getSlotMouseOver(mousex, mousey); + if (hoverSlot != null) { + + if (button == 2) { + + if (hoverSlot.item != null) { + draggedStack = getDraggedStackWithQuantity(hoverSlot.slotIndex); + } + + } else { + mouseDownSlot = hoverSlot.slotIndex; + } + + return true; + } + + return false; + } + + @Override + public boolean handleClickExt(int mouseX, int mouseY, int button) + { + if (ItemPanels.itemPanel.draggedStack != null) { + return ItemPanels.itemPanel.handleDraggedClick(mouseX, mouseY, button); + } + + if (ItemPanels.bookmarkPanel.draggedStack != null) { + return ItemPanels.bookmarkPanel.handleDraggedClick(mouseX, mouseY, button); + } + + return false; + } + + protected boolean handleDraggedClick(int mouseX, int mouseY, int button) + { + if (draggedStack == null) { + return false; + } + + if (handleGUIContainerClick(mouseX, mouseY, button)) { + return true; + } + + final GuiContainer gui = NEIClientUtils.getGuiContainer(); + if (mouseX < gui.guiLeft || mouseY < gui.guiTop || mouseX >= gui.guiLeft + gui.xSize || mouseY >= gui.guiTop + gui.ySize) { + draggedStack = null; + } + + return true; + } + + protected boolean handleGUIContainerClick(int mouseX, int mouseY, int button) + { + final GuiContainer gui = NEIClientUtils.getGuiContainer(); + boolean handled = false; + + try { + GuiInfo.readLock.lock(); + for (INEIGuiHandler handler : GuiInfo.guiHandlers) { + if (handler.handleDragNDrop(gui, mouseX, mouseY, draggedStack, button)) { + handled = true; + break; + } + } + } finally { + GuiInfo.readLock.unlock(); + } + + if (draggedStack.stackSize == 0) { + draggedStack = null; + } + + return handled; + } + + @Override + public void mouseUp(int mousex, int mousey, int button) + { + ItemPanelSlot hoverSlot = getSlotMouseOver(mousex, mousey); + + if (hoverSlot != null && hoverSlot.slotIndex == mouseDownSlot && draggedStack == null) { + ItemStack item = hoverSlot.item; + + if (NEIController.manager.window instanceof GuiRecipe || !NEIClientConfig.canCheatItem(item)) { + + if (button == 0) { + GuiCraftingRecipe.openRecipeGui("item", item); + } else if (button == 1) { + GuiUsageRecipe.openRecipeGui("item", item); + } + + mouseDownSlot = -1; + return; + } + + NEIClientUtils.cheatItem(getDraggedStackWithQuantity(hoverSlot.slotIndex), button, -1); + } + + mouseDownSlot = -1; + } + + @Override + public boolean onMouseWheel(int i, int mousex, int mousey) + { + if (!contains(mousex, mousey)) + return false; + + grid.shiftPage(-i); + return true; + } + + @Override + public boolean handleKeyPress(int keyID, char keyChar) + { + + if (keyID == NEIClientConfig.getKeyBinding("gui.next")) { + grid.shiftPage(1); + return true; + } + + if (keyID == NEIClientConfig.getKeyBinding("gui.prev")) { + grid.shiftPage(-1); + return true; + } + + return false; + } + + @Override + public ItemStack getStackMouseOver(int mousex, int mousey) + { + ItemPanelSlot slot = getSlotMouseOver(mousex, mousey); + return slot == null ? null : slot.item; + } + + public ItemPanelSlot getSlotMouseOver(int mousex, int mousey) + { + return grid.getSlotMouseOver(mousex, mousey); + } + + public int getPage() { + return grid.page + 1; + } + + public int getNumPages() { + return grid.numPages; + } + + @Override + public boolean contains(int px, int py) + { + return grid.contains(px, py); + } + +} diff --git a/src/main/java/codechicken/nei/PresetsWidget.java b/src/main/java/codechicken/nei/PresetsWidget.java index 6dbec7a6..559ee35c 100644 --- a/src/main/java/codechicken/nei/PresetsWidget.java +++ b/src/main/java/codechicken/nei/PresetsWidget.java @@ -4,11 +4,7 @@ import codechicken.core.CommonUtils; import codechicken.core.gui.GuiScrollSlot; import codechicken.lib.gui.GuiDraw; import codechicken.lib.vec.Rectangle4i; -import codechicken.nei.ItemList.AllMultiItemFilter; -import codechicken.nei.ItemList.EverythingItemFilter; import codechicken.nei.ItemPanel.ItemPanelSlot; -import codechicken.nei.api.API; -import codechicken.nei.api.ItemFilter.ItemFilterProvider; import codechicken.nei.api.ItemFilter; import codechicken.nei.recipe.GuiRecipe; import codechicken.nei.recipe.StackInfo; @@ -36,7 +32,7 @@ import org.apache.commons.io.IOUtils; import org.lwjgl.input.Keyboard; import static codechicken.nei.NEIClientUtils.translate; -public class PresetsWidget extends Widget// implements ItemFilterProvider +public class PresetsWidget extends Widget { public static class PresetTag implements ItemFilter @@ -511,7 +507,7 @@ public class PresetsWidget extends Widget// implements ItemFilterProvider @Override public List handleTooltip(int mx, int my, List tooltip) { - if (contains(mx, my)) { + if (contains(mx, my) && listbox.getSelected().size() <= 1) { tooltip.add(translate("presets.label.tooltip")); } @@ -631,17 +627,16 @@ public class PresetsWidget extends Widget// implements ItemFilterProvider public static boolean isHidden(final ItemStack item) { - if (edit != null || listbox.getSelected().isEmpty()) { + if (edit != null) { - if (edit != null) { - - if (mouseSelection != null && mouseSelection.items.contains(item)) { - return mouseSelection.append != edit.whitelist; - } - - return !edit.matches(item); + if (mouseSelection != null && mouseSelection.items.contains(item)) { + return mouseSelection.append != edit.whitelist; } + return !edit.matches(item); + } + + if (!listbox.getSelected().isEmpty()) { final List selected = listbox.getSelected(); for (int idx = 0; idx < selected.size(); idx++) { @@ -736,33 +731,21 @@ public class PresetsWidget extends Widget// implements ItemFilterProvider ItemList.updateFilter.restart(); } - // public PresetsWidget() - // { - // API.addItemFilter(this); - // } - @Override public void draw(int mx, int my) { - final int panelHeight = 16; - final int panelWidth = 153; - w = panelWidth; - h = panelHeight; - y = 2; - x = ItemPanels.itemPanel.x - 4 - w; - if (edit != null) { selectedState.x = x; selectedState.y = y; - selectedState.w = selectedState.h = panelHeight; + selectedState.w = selectedState.h = h; selectedState.draw(mx, my); selectedDisplayName.y = y; selectedDisplayName.h = h; selectedDisplayName.x = selectedState.x + selectedState.w + 1; - selectedDisplayName.w = w - panelHeight * 2 - 5; + selectedDisplayName.w = w - h * 2 - 5; selectedDisplayName.draw(mx, my); } else { @@ -772,7 +755,7 @@ public class PresetsWidget extends Widget// implements ItemFilterProvider selectedValue.text = size> 1? translate("presets.label.selected", size): (size == 1? selected.get(0).displayName: ""); selectedValue.y = y; selectedValue.h = h; - selectedValue.w = w - panelHeight - 4; + selectedValue.w = w - h - 4; selectedValue.x = x; selectedValue.draw(mx, my); @@ -780,7 +763,7 @@ public class PresetsWidget extends Widget// implements ItemFilterProvider dropdown.y = y; - dropdown.w = dropdown.h = panelHeight; + dropdown.w = dropdown.h = h; dropdown.x = x + w - dropdown.w; dropdown.state = edit != null || listbox.getNumSlots() == 0? 2: 0; dropdown.draw(mx, my); @@ -1018,6 +1001,11 @@ public class PresetsWidget extends Widget// implements ItemFilterProvider public static boolean matches(ItemStack stack) { + + if (edit != null) { + return true; + } + final List selected = listbox.getSelected(); for (int idx = 0; idx < selected.size(); idx++) { diff --git a/src/main/java/codechicken/nei/SubsetWidget.java b/src/main/java/codechicken/nei/SubsetWidget.java index 9789099b..3697b139 100644 --- a/src/main/java/codechicken/nei/SubsetWidget.java +++ b/src/main/java/codechicken/nei/SubsetWidget.java @@ -217,6 +217,7 @@ public class SubsetWidget extends Button implements ItemFilterProvider, ItemsLoa for(SubsetTag tag : sorted) tag.cacheState(); } + public void addFiltersWithItem(List filters, String itemSearch) { if(itemSearch == null) { addFilters(filters); @@ -229,6 +230,7 @@ public class SubsetWidget extends Button implements ItemFilterProvider, ItemsLoa } } + public void addFilters(List filters) { if(filter != null) filters.add(filter); diff --git a/src/main/java/codechicken/nei/api/GuiInfo.java b/src/main/java/codechicken/nei/api/GuiInfo.java index 759828b9..d59688a9 100644 --- a/src/main/java/codechicken/nei/api/GuiInfo.java +++ b/src/main/java/codechicken/nei/api/GuiInfo.java @@ -1,9 +1,14 @@ package codechicken.nei.api; +import codechicken.lib.vec.Rectangle4i; import codechicken.nei.NEIChestGuiHandler; import codechicken.nei.NEICreativeGuiHandler; import codechicken.nei.NEIDummySlotHandler; import codechicken.nei.recipe.GuiRecipeCatalyst; +import codechicken.nei.recipe.SearchInputDropHandler; +import codechicken.nei.recipe.FillFluidContainerHandler; +import codechicken.nei.recipe.CheatItemHandler; +import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiContainerCreative; @@ -25,6 +30,9 @@ public class GuiInfo { API.registerNEIGuiHandler(new NEIChestGuiHandler()); API.registerNEIGuiHandler(new NEIDummySlotHandler()); API.registerNEIGuiHandler(new GuiRecipeCatalyst(null)); + API.registerNEIGuiHandler(new SearchInputDropHandler()); + API.registerNEIGuiHandler(new FillFluidContainerHandler()); + API.registerNEIGuiHandler(new CheatItemHandler()); customSlotGuis.add(GuiContainerCreative.class); } @@ -40,4 +48,28 @@ public class GuiInfo { public static boolean hasCustomSlots(GuiContainer gui) { return customSlotGuis.contains(gui.getClass()); } + + public static boolean hideItemPanelSlot(GuiContainer gui, Rectangle4i rect) + { + try { + readLock.lock(); + if (guiHandlers.stream().anyMatch(handler -> handler.hideItemPanelSlot(gui, rect.x, rect.y, rect.w, rect.h))) { + return true; + } + } finally { + readLock.unlock(); + } + + for (Object item : gui.buttonList) { + GuiButton button = (GuiButton) item; + + if ((new Rectangle4i(button.xPosition, button.yPosition, button.width, button.height)).intersects(rect)) { + return true; + } + + } + + return false; + } + } diff --git a/src/main/java/codechicken/nei/config/GuiPanelSettings.java b/src/main/java/codechicken/nei/config/GuiPanelSettings.java new file mode 100644 index 00000000..44704171 --- /dev/null +++ b/src/main/java/codechicken/nei/config/GuiPanelSettings.java @@ -0,0 +1,317 @@ +package codechicken.nei.config; + +import codechicken.core.gui.GuiScreenWidget; +import codechicken.lib.render.CCRenderState; +import codechicken.lib.vec.Rectangle4i; +import codechicken.nei.ItemPanels; +import codechicken.nei.ItemsGrid; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.item.ItemStack; +import codechicken.nei.guihook.GuiContainerManager; + +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import java.awt.Point; +import java.util.ArrayList; + +import static codechicken.lib.gui.GuiDraw.getMousePosition; + +public class GuiPanelSettings extends GuiScreenWidget +{ + private final Option opt; + + private PanelPlaceholder bookmarksPanel; + private PanelPlaceholder itemsPanel; + + protected static class PanelResizeButton + { + private int x; + private int y; + private int w; + private int h; + + public PanelResizeButton(int w, int h) + { + this.w = w; + this.h = h; + } + + public void draw(int mousex, int mousey) + { + drawRect(x, y, x + w, y + h, 0xbbaaaaaa); + drawRect(x + 2, y + 2, x + w - 2, y + h - 2, contains(mousex, mousey)? 0xFF000000: 0xbb000000); + } + + public boolean contains(int pointX, int pointY) + { + return (new Rectangle4i(x, y, w, h)).contains(pointX, pointY); + } + + } + + protected static class PanelPlaceholder + { + protected static int PANEL_SIZE = 16; + + private final Option opt; + private final String name; + private Rectangle4i margin; + private Point dragDown; + private String dragDir; + private int x = 0; + private int y = 0; + private int w = 0; + private int h = 0; + + private PanelResizeButton leftButton = new PanelResizeButton(PANEL_SIZE, PANEL_SIZE * 2); + private PanelResizeButton topButton = new PanelResizeButton(PANEL_SIZE * 2, PANEL_SIZE); + private PanelResizeButton rightButton = new PanelResizeButton(PANEL_SIZE, PANEL_SIZE * 2); + private PanelResizeButton bottomButton = new PanelResizeButton(PANEL_SIZE * 2, PANEL_SIZE); + + public PanelPlaceholder(Option opt, String name) + { + this.opt = opt; + this.name = name; + } + + public void resize(Rectangle4i margin) + { + this.margin = margin; + int[] padding = getPaddings(); + + x = margin.x + padding[0]; + y = margin.y + padding[1]; + w = margin.w - padding[2] - padding[0]; + h = margin.h - padding[3] - padding[1]; + + leftButton.x = x; + leftButton.y = y + h / 2 - PANEL_SIZE; + + rightButton.x = x + w - PANEL_SIZE; + rightButton.y = y + h / 2 - PANEL_SIZE; + + topButton.x = x + w / 2 - PANEL_SIZE; + topButton.y = y; + + bottomButton.x = x + w / 2 - PANEL_SIZE; + bottomButton.y = y + h - PANEL_SIZE; + } + + public void draw(int mousex, int mousey) + { + drawRect(x, y, x + w, y + PANEL_SIZE, 0xbbaaaaaa); //top-panel + drawRect(x, y + h - PANEL_SIZE, x + w, y + h, 0xbbaaaaaa); //bottom-panel + + drawRect(x, y, x + 2, y + h, 0xbbaaaaaa); //border left + drawRect(x + w, y, x + w - 2, y + h, 0xbbaaaaaa); //border right + + drawRect(x, y, x + w, y + 2, 0xbbaaaaaa); //border top + drawRect(x, y + h, x + w, y + h - 2, 0xbbaaaaaa); //border bottom + + drawItems(); + + leftButton.draw(mousex, mousey); + rightButton.draw(mousex, mousey); + topButton.draw(mousex, mousey); + bottomButton.draw(mousex, mousey); + } + + protected int[] getPaddings() + { + final int minWidth = 5 * ItemsGrid.SLOT_SIZE; + final int minHeight = 9 * ItemsGrid.SLOT_SIZE; + + int paddingLeft = (int)Math.ceil(margin.w * opt.renderTag(name + ".left").getIntValue() / 100000.0); + int paddingTop = (int)Math.ceil(margin.h * opt.renderTag(name + ".top").getIntValue() / 100000.0); + int paddingRight = (int)Math.ceil(margin.w * opt.renderTag(name + ".right").getIntValue() / 100000.0); + int paddingBottom = (int)Math.ceil(margin.h * opt.renderTag(name + ".bottom").getIntValue() / 100000.0); + + if (dragDir != null) { + final Point mouse = getMousePosition(); + Point drag = new Point(mouse.x - dragDown.x, mouse.y - dragDown.y); + + if (dragDir == "left") { + paddingLeft = Math.min(Math.max(0, margin.w - paddingRight - minWidth), Math.max(0, paddingLeft + drag.x)); + } else if (dragDir == "right") { + paddingRight = Math.min(Math.max(0, margin.w - paddingLeft - minWidth), Math.max(0, paddingRight - drag.x)); + } else if (dragDir == "top") { + paddingTop = Math.min(Math.max(0, margin.h - paddingBottom - minHeight), Math.max(0, paddingTop + drag.y)); + } else if (dragDir == "bottom") { + paddingBottom = Math.min(Math.max(0, margin.h - paddingTop - minHeight), Math.max(0, paddingBottom - drag.y)); + } else if (dragDir == "move") { + int width = margin.w - paddingRight - paddingLeft; + int height = margin.h - paddingTop - paddingBottom; + + paddingLeft = Math.min(Math.max(0, margin.w - width), Math.max(0, paddingLeft + drag.x)); + paddingTop = Math.min(Math.max(0, margin.h - height), Math.max(0, paddingTop + drag.y)); + + paddingRight = margin.w - paddingLeft - width; + paddingBottom = margin.h - paddingTop - height; + } + + } + + int deltaHeight = Math.min(0, margin.h - paddingTop - paddingBottom - minHeight) / 2; + + paddingLeft = Math.min(paddingLeft, Math.max(0, margin.w - paddingRight - minWidth)); + paddingRight = Math.min(paddingRight, Math.max(0, margin.w - paddingLeft - minWidth)); + paddingTop = Math.min(margin.h - minHeight, Math.max(0, paddingTop + deltaHeight)); + paddingBottom = Math.min(margin.h - paddingTop - minHeight, Math.max(0, paddingBottom - deltaHeight)); + + + return new int[]{ paddingLeft, paddingTop, paddingRight, paddingBottom }; + } + + protected void drawItems() + { + final int columns = w / ItemsGrid.SLOT_SIZE; + final int rows = (h - (PANEL_SIZE + 2) * 2) / ItemsGrid.SLOT_SIZE; + final int paddingLeft = (w % ItemsGrid.SLOT_SIZE) / 2; + final ArrayList items = ItemPanels.itemPanel.getItems(); + + for (int r = 0; r < rows; r ++) { + for (int c = 0; c < columns; c++) { + + GuiContainerManager.drawItem( + x + paddingLeft + ItemsGrid.SLOT_SIZE * c + 1, + y + PANEL_SIZE + 2 + ItemsGrid.SLOT_SIZE * r + 1, + items.get((r * columns + c) % items.size()) + ); + + } + } + + } + + public boolean contains(int pointX, int pointY) + { + return (new Rectangle4i(x, y, w, h)).contains(pointX, pointY); + } + + protected void mouseClicked(int x, int y, int button) + { + + if (contains(x, y)) { + dragDown = getMousePosition(); + + if (leftButton.contains(x, y)) { + dragDir = "left"; + } else if (rightButton.contains(x, y)) { + dragDir = "right"; + } else if (topButton.contains(x, y)) { + dragDir = "top"; + } else if (bottomButton.contains(x, y)) { + dragDir = "bottom"; + } else { + dragDir = "move"; + } + } + + } + + protected void mouseMovedOrUp(int x, int y, int button) + { + + if (button == 0 && dragDown != null) { + int[] padding = getPaddings(); + + opt.renderTag(name + ".left").setIntValue(padding[0] * 100000 / margin.w); + opt.renderTag(name + ".top").setIntValue(padding[1] * 100000 / margin.h); + opt.renderTag(name + ".right").setIntValue(padding[2] * 100000 / margin.w); + opt.renderTag(name + ".bottom").setIntValue(padding[3] * 100000 / margin.h); + + dragDir = null; + dragDown = null; + } + + } + + } + + public GuiPanelSettings(Option opt) { + super(176, 198); + this.opt = opt; + + bookmarksPanel = new PanelPlaceholder(opt, opt.name + ".bookmarks"); + itemsPanel = new PanelPlaceholder(opt, opt.name + ".items"); + } + + @Override + public boolean doesGuiPauseGame() + { + return true; + } + + @Override + public void keyTyped(char c, int keycode) + { + + if (keycode == Keyboard.KEY_ESCAPE || keycode == Keyboard.KEY_BACK) { + Minecraft.getMinecraft().displayGuiScreen(opt.slot.getGui()); + return; + } + + super.keyTyped(c, keycode); + } + + + protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) { + GL11.glColor4f(1, 1, 1, 1); + CCRenderState.changeTexture("nei:textures/gui/inv.png"); + + int x = guiLeft; + int y = guiTop - 4; + + drawTexturedModalRect(x - 23, y, 0, 0, 199, 204); + } + + @Override + public void drawScreen(int mousex, int mousey, float f) + { + + drawGuiContainerBackgroundLayer(f, mousex, mousey); + drawDefaultBackground(); + + RenderHelper.enableGUIStandardItemLighting(); + GL11.glPushMatrix(); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + + bookmarksPanel.resize(getBookmarkDefaultSize()); + itemsPanel.resize(getItemsDefaultSize()); + + bookmarksPanel.draw(mousex, mousey); + itemsPanel.draw(mousex, mousey); + + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + GL11.glPopMatrix(); + RenderHelper.enableStandardItemLighting(); + } + + private Rectangle4i getBookmarkDefaultSize() + { + return new Rectangle4i(2, 2, guiLeft - 4, height - 4); + } + + protected Rectangle4i getItemsDefaultSize() + { + return new Rectangle4i(guiLeft + xSize + 2, 2, width - (guiLeft + xSize + 4), height - 4); + } + + @Override + protected void mouseClicked(int x, int y, int button) + { + bookmarksPanel.mouseClicked(x, y, button); + itemsPanel.mouseClicked(x, y, button); + } + + @Override + protected void mouseMovedOrUp(int x, int y, int button) + { + bookmarksPanel.mouseMovedOrUp(x, y, button); + itemsPanel.mouseMovedOrUp(x, y, button); + } + +} diff --git a/src/main/java/codechicken/nei/config/OptionToggleButtonBoubs.java b/src/main/java/codechicken/nei/config/OptionToggleButtonBoubs.java index 1fcbbaf4..717356da 100644 --- a/src/main/java/codechicken/nei/config/OptionToggleButtonBoubs.java +++ b/src/main/java/codechicken/nei/config/OptionToggleButtonBoubs.java @@ -4,8 +4,6 @@ import codechicken.nei.Image; import codechicken.nei.LayoutManager; import codechicken.nei.drawable.DrawableBuilder; import codechicken.nei.drawable.DrawableResource; -import org.lwjgl.opengl.GL11; - import java.awt.Rectangle; public class OptionToggleButtonBoubs extends OptionButton { diff --git a/src/main/java/codechicken/nei/guihook/GuiContainerManager.java b/src/main/java/codechicken/nei/guihook/GuiContainerManager.java index 7b0fcf0d..e9c3ef45 100644 --- a/src/main/java/codechicken/nei/guihook/GuiContainerManager.java +++ b/src/main/java/codechicken/nei/guihook/GuiContainerManager.java @@ -14,6 +14,7 @@ import net.minecraft.util.EnumChatFormatting; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; import java.awt.Point; import java.io.PrintWriter; @@ -179,30 +180,47 @@ public class GuiContainerManager } public static void drawItem(int i, int j, ItemStack itemstack) { - drawItem(i, j, itemstack, getFontRenderer(itemstack)); + drawItem(i, j, itemstack, false); } public static void drawItem(int i, int j, ItemStack itemstack, boolean smallAmount) { - drawItem(i, j, itemstack, getFontRenderer(itemstack), smallAmount); + drawItem(i, j, itemstack, smallAmount, null); + } + + public static void drawItem(int i, int j, ItemStack itemstack, boolean smallAmount, String stackSize) { + drawItem(i, j, itemstack, getFontRenderer(itemstack), smallAmount, stackSize); } public static void drawItem(int i, int j, ItemStack itemstack, FontRenderer fontRenderer) { - drawItem(i, j, itemstack, fontRenderer, false); + drawItem(i, j, itemstack, fontRenderer, false, null); } private static int modelviewDepth = -1; private static final HashSet stackTraces = new HashSet<>(); - public static void drawItem(int i, int j, ItemStack itemstack, FontRenderer fontRenderer, boolean smallAmount) { + public static void drawItem(int i, int j, ItemStack itemstack, FontRenderer fontRenderer, boolean smallAmount, String stackSize) { enable3DRender(); + //for lighting correction + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + float zLevel = drawItems.zLevel += 100F; try { drawItems.renderItemAndEffectIntoGUI(fontRenderer, renderEngine, itemstack, i, j); - if (!smallAmount) { - drawItems.renderItemOverlayIntoGUI(fontRenderer, renderEngine, itemstack, i, j); - } else if (itemstack.stackSize > 1) { - drawBigStackSize(i, j, itemstack.stackSize); + if (stackSize == null) { + stackSize = itemstack.stackSize > 1? String.valueOf(itemstack.stackSize): ""; + } + + if (smallAmount) { + + if (!stackSize.isEmpty()) { + drawBigStackSize(i, j, stackSize); + } + + // stackSize = "". it needed for correct draw item with alpha and blend + drawItems.renderItemOverlayIntoGUI(fontRenderer, renderEngine, itemstack, i, j, ""); + } else { + drawItems.renderItemOverlayIntoGUI(fontRenderer, renderEngine, itemstack, i, j, stackSize); } if (!checkMatrixStack()) @@ -227,29 +245,27 @@ public class GuiContainerManager drawItems.renderItemIntoGUI(fontRenderer, renderEngine, new ItemStack(Blocks.fire), i, j); } + GL11.glDisable(GL12.GL_RESCALE_NORMAL); enable2DRender(); drawItems.zLevel = zLevel - 100; } //copy from appeng.client.render.AppEngRenderItem - protected static void drawBigStackSize(int offsetX, int offsetY, int amount) + protected static void drawBigStackSize(int offsetX, int offsetY, String stackSize) { final float scaleFactor = fontRenderer.getUnicodeFlag() ? 0.85f : 0.5f; final float inverseScaleFactor = 1.0f / scaleFactor; - final String stackSize = String.valueOf( amount ); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_DEPTH_TEST); - GL11.glPushMatrix(); + enable2DRender(); GL11.glScaled(scaleFactor, scaleFactor, scaleFactor); final int X = (int) ( ( (float) offsetX + 16.0f - fontRenderer.getStringWidth( stackSize ) * scaleFactor ) * inverseScaleFactor ); final int Y = (int) ( ( (float) offsetY + 16.0f - 7.0f * scaleFactor ) * inverseScaleFactor ); fontRenderer.drawStringWithShadow(stackSize, X, Y, 16777215); + + GL11.glScaled(inverseScaleFactor, inverseScaleFactor, inverseScaleFactor); + enable3DRender(); - GL11.glPopMatrix(); - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_DEPTH_TEST); } public static void enableMatrixStackLogging() { diff --git a/src/main/java/codechicken/nei/recipe/BookmarkRecipeId.java b/src/main/java/codechicken/nei/recipe/BookmarkRecipeId.java index e8882f77..f0049012 100644 --- a/src/main/java/codechicken/nei/recipe/BookmarkRecipeId.java +++ b/src/main/java/codechicken/nei/recipe/BookmarkRecipeId.java @@ -5,7 +5,6 @@ import com.google.gson.JsonElement; import com.google.gson.JsonArray; import com.google.gson.JsonPrimitive; import codechicken.nei.util.NBTJson; -import codechicken.nei.NEIClientConfig; import codechicken.nei.PositionedStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.item.ItemStack; @@ -25,15 +24,24 @@ public class BookmarkRecipeId public List ingredients = new ArrayList<>(); - public BookmarkRecipeId(String handlerName, List stacks) + public BookmarkRecipeId(String handlerName, List stacks) { this.handlerName = handlerName; - for (PositionedStack pos : stacks) { - final NBTTagCompound nbt = StackInfo.itemStackToNBT(getItemStackWithMinimumDamage(pos.items)); - if (nbt != null) { - ingredients.add(nbt); + for (Object pos : stacks) { + + if (pos instanceof PositionedStack) { + pos = getItemStackWithMinimumDamage(((PositionedStack) pos).items); } + + if (pos instanceof ItemStack) { + pos = StackInfo.itemStackToNBT((ItemStack) pos); + } + + if (pos instanceof NBTTagCompound) { + ingredients.add((NBTTagCompound) pos); + } + } } @@ -57,6 +65,11 @@ public class BookmarkRecipeId } + public BookmarkRecipeId() + { + + } + public boolean equalsIngredients(List stacks) { @@ -70,7 +83,7 @@ public class BookmarkRecipeId final NBTTagCompound tagCompoundA = StackInfo.itemStackToNBT(getItemStackWithMinimumDamage(pStack.items)); final NBTTagCompound tagCompoundB = ingredients.get(idx); - if (tagCompoundB == null || !tagCompoundA.equals(tagCompoundB)) { + if (tagCompoundB == null || !tagCompoundB.equals(tagCompoundA)) { return false; } @@ -166,4 +179,9 @@ public class BookmarkRecipeId return false; } + public BookmarkRecipeId copy() + { + return new BookmarkRecipeId(handlerName, ingredients); + } + } diff --git a/src/main/java/codechicken/nei/recipe/CheatItemHandler.java b/src/main/java/codechicken/nei/recipe/CheatItemHandler.java new file mode 100644 index 00000000..cdd254ca --- /dev/null +++ b/src/main/java/codechicken/nei/recipe/CheatItemHandler.java @@ -0,0 +1,50 @@ +package codechicken.nei.recipe; + +import codechicken.nei.NEICPH; +import codechicken.nei.NEIClientConfig; +import codechicken.nei.NEIClientUtils; +import codechicken.nei.NEIServerUtils; +import codechicken.nei.api.INEIGuiAdapter; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + + +public class CheatItemHandler extends INEIGuiAdapter +{ + + @Override + public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) + { + final Slot overSlot = gui.getSlotAtPosition(mouseX, mouseY); + + if (overSlot != null && overSlot.isItemValid(draggedStack)) { + + if (NEIClientConfig.canCheatItem(draggedStack)) { + int contents = overSlot.getHasStack() ? overSlot.getStack().stackSize : 0; + final int add = button == 0 ? draggedStack.stackSize : 1; + + if (overSlot.getHasStack() && !NEIServerUtils.areStacksSameType(draggedStack, overSlot.getStack())) { + contents = 0; + } + + final int total = Math.min(contents + add, Math.min(overSlot.getSlotStackLimit(), draggedStack.getMaxStackSize())); + + if (total > contents) { + NEIClientUtils.setSlotContents(overSlot.slotNumber, NEIServerUtils.copyStack(draggedStack, total), true); + NEICPH.sendGiveItem(NEIServerUtils.copyStack(draggedStack, total), false, false); + draggedStack.stackSize -= total - contents; + } + + } else { + draggedStack.stackSize = 0; + } + + return true; + } + + return false; + } + +} + \ No newline at end of file diff --git a/src/main/java/codechicken/nei/recipe/FillFluidContainerHandler.java b/src/main/java/codechicken/nei/recipe/FillFluidContainerHandler.java new file mode 100644 index 00000000..32821faa --- /dev/null +++ b/src/main/java/codechicken/nei/recipe/FillFluidContainerHandler.java @@ -0,0 +1,94 @@ +package codechicken.nei.recipe; + +import codechicken.nei.ItemPanel.ItemPanelSlot; +import codechicken.nei.ItemPanels; +import codechicken.nei.api.INEIGuiAdapter; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidContainerItem; + +public class FillFluidContainerHandler extends INEIGuiAdapter +{ + + @Override + public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) + { + + if (button == 2) { + return false; + } + + if (draggedStack.getItem() instanceof IFluidContainerItem || FluidContainerRegistry.isContainer(draggedStack)) { + ItemPanelSlot mouseOverSlot = ItemPanels.itemPanel.getSlotMouseOver(mouseX, mouseY); + + if (mouseOverSlot == null) { + mouseOverSlot = ItemPanels.bookmarkPanel.getSlotMouseOver(mouseX, mouseY); + } + + if (mouseOverSlot != null) { + FluidStack fluidStack = StackInfo.getFluid(mouseOverSlot.item); + + if (fluidStack != null) { + ItemStack container = fillContainer(draggedStack, fluidStack); + + if (container != null) { + container.stackSize = draggedStack.stackSize; + + if (ItemPanels.itemPanel.draggedStack != null) { + ItemPanels.itemPanel.draggedStack = container; + } else { + ItemPanels.bookmarkPanel.draggedStack = container; + } + + } + + if (button == 1 && StackInfo.getFluid(container != null? container: draggedStack) != null) { + ItemPanels.bookmarkPanel.addOrRemoveItem((container != null? container: draggedStack).copy()); + } + + } + + return true; + } + + } + + return false; + } + + protected ItemStack fillContainer(ItemStack draggedStack, FluidStack fluidStack) + { + fluidStack = fluidStack.copy(); + draggedStack = draggedStack.copy(); + draggedStack.stackSize = 1; + + if (fluidStack.amount == 0) { + fluidStack.amount = 1000; + } + + if (FluidContainerRegistry.isContainer(draggedStack)) { + + if (FluidContainerRegistry.getContainerCapacity(draggedStack) > 0) { + draggedStack = FluidContainerRegistry.drainFluidContainer(draggedStack); + } + + return FluidContainerRegistry.fillFluidContainer(fluidStack, draggedStack); + } else if (draggedStack.getItem() instanceof IFluidContainerItem) { + IFluidContainerItem item = (IFluidContainerItem) draggedStack.getItem(); + + if (item.getCapacity(draggedStack) > 0) { + item.drain(draggedStack, item.getCapacity(draggedStack), true); + } + + if (item.fill(draggedStack, fluidStack, true) > 0) { + return draggedStack; + } + + } + + return null; + } + +} diff --git a/src/main/java/codechicken/nei/recipe/GuiCraftingRecipe.java b/src/main/java/codechicken/nei/recipe/GuiCraftingRecipe.java index 362f9853..7cfb39a3 100644 --- a/src/main/java/codechicken/nei/recipe/GuiCraftingRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiCraftingRecipe.java @@ -4,6 +4,7 @@ import codechicken.core.TaskProfiler; import codechicken.nei.ItemList; import codechicken.nei.NEIClientConfig; import codechicken.nei.NEIClientUtils; +import codechicken.nei.PositionedStack; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; @@ -14,6 +15,7 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; import java.util.ArrayList; +import java.util.List; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; @@ -57,18 +59,42 @@ public class GuiCraftingRecipe extends GuiRecipe handlers.sort(NEIClientConfig.HANDLER_COMPARATOR); - mc.displayGuiScreen(new GuiCraftingRecipe(prevscreen, handlers)); + BookmarkRecipeId recipeId = null; + + if ("item".equals(outputId)) { + recipeId = getRecipeId(prevscreen, (ItemStack)results[0]); + } + + GuiCraftingRecipe gui = new GuiCraftingRecipe(prevscreen, handlers, recipeId); - if (NEIClientConfig.saveCurrentRecipeInBookmarksEnabled() && !NEIClientUtils.shiftKey() && outputId.equals("item") && mc.currentScreen instanceof GuiRecipe) { - GuiCraftingRecipe.openTargetRecipe((GuiRecipe)mc.currentScreen, (ItemStack)results[0]); + mc.displayGuiScreen(gui); + + if (NEIClientConfig.saveCurrentRecipeInBookmarksEnabled() && !NEIClientUtils.shiftKey()) { + gui.openTargetRecipe(gui.recipeId); } return true; } - protected static void openTargetRecipe(GuiRecipe currentScreen, ItemStack stackover) + protected static BookmarkRecipeId getRecipeId(GuiScreen gui, ItemStack stackover) { - currentScreen.openTargetRecipe(ItemPanels.bookmarkPanel.getBookmarkRecipeId(stackover)); + + if (gui instanceof GuiRecipe) { + final List ingredients = ((GuiRecipe) gui).getFocusedRecipeIngredients(); + final String handlerName = ((GuiRecipe) gui).getHandlerName(); + + if (ingredients != null && !ingredients.isEmpty()) { + return new BookmarkRecipeId(handlerName, ingredients); + } + } + + return ItemPanels.bookmarkPanel.getBookmarkRecipeId(stackover); + } + + private GuiCraftingRecipe(GuiScreen prevgui, ArrayList handlers, BookmarkRecipeId recipeId) + { + this(prevgui, handlers); + this.recipeId = recipeId; } private GuiCraftingRecipe(GuiScreen prevgui, ArrayList handlers) { diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index 1dbefa45..00887047 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -63,6 +63,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve public int page; public int recipetype; + public BookmarkRecipeId recipeId; public ContainerRecipe slotcontainer; public GuiContainer firstGui; public GuiScreen firstGuiGeneral; diff --git a/src/main/java/codechicken/nei/recipe/GuiUsageRecipe.java b/src/main/java/codechicken/nei/recipe/GuiUsageRecipe.java index ed4e18bf..80c4405b 100644 --- a/src/main/java/codechicken/nei/recipe/GuiUsageRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiUsageRecipe.java @@ -55,10 +55,29 @@ public class GuiUsageRecipe extends GuiRecipe handlers.sort(NEIClientConfig.HANDLER_COMPARATOR); - mc.displayGuiScreen(new GuiUsageRecipe(prevscreen, handlers)); + BookmarkRecipeId recipeId = null; + + if (prevscreen instanceof GuiRecipe && ((GuiRecipe) prevscreen).recipeId != null) { + recipeId = (((GuiRecipe) prevscreen).recipeId).copy(); + } + + GuiUsageRecipe gui = new GuiUsageRecipe(prevscreen, handlers, recipeId); + + mc.displayGuiScreen(gui); + + if (!NEIClientUtils.shiftKey()) { + gui.openTargetRecipe(recipeId); + } + return true; } + private GuiUsageRecipe(GuiContainer prevgui, ArrayList handlers, BookmarkRecipeId recipeId) + { + this(prevgui, handlers); + this.recipeId = recipeId; + } + private GuiUsageRecipe(GuiContainer prevgui, ArrayList handlers) { super(prevgui); currenthandlers = handlers; diff --git a/src/main/java/codechicken/nei/recipe/SearchInputDropHandler.java b/src/main/java/codechicken/nei/recipe/SearchInputDropHandler.java new file mode 100644 index 00000000..2ff47a8d --- /dev/null +++ b/src/main/java/codechicken/nei/recipe/SearchInputDropHandler.java @@ -0,0 +1,41 @@ +package codechicken.nei.recipe; + +import codechicken.nei.api.INEIGuiAdapter; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import net.minecraft.util.EnumChatFormatting; + +import java.util.regex.Pattern; +import static codechicken.nei.LayoutManager.searchField; + +public class SearchInputDropHandler extends INEIGuiAdapter +{ + + protected static final Pattern SPECIAL_REGEX_CHARS = Pattern.compile("[{}()\\[\\].+*?^$\\\\|]"); + + @Override + public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) + { + + if (searchField.contains(mouseX, mouseY)) { + final FluidStack fluidStack = StackInfo.getFluid(draggedStack); + + if (fluidStack != null) { + searchField.setText(formattingText(fluidStack.getLocalizedName())); + } else { + searchField.setText(formattingText(draggedStack.getDisplayName())); + } + + return true; + } + + return false; + } + + protected String formattingText(String displayName) + { + return SPECIAL_REGEX_CHARS.matcher(EnumChatFormatting.getTextWithoutFormattingCodes(displayName)).replaceAll("\\\\$0"); + } + +} diff --git a/src/main/resources/assets/nei/lang/en_US.lang b/src/main/resources/assets/nei/lang/en_US.lang index 87aad105..55df00da 100644 --- a/src/main/resources/assets/nei/lang/en_US.lang +++ b/src/main/resources/assets/nei/lang/en_US.lang @@ -133,6 +133,9 @@ nei.options.inventory.saveCurrentRecipeInBookmarksEnabled.false=Disabled nei.options.inventory.useNBTInBookmarks=Use NBT in Bookmarks nei.options.inventory.useNBTInBookmarks.true=Yes nei.options.inventory.useNBTInBookmarks.false=No +nei.options.inventory.showRecipeMarker=Show Recipe Marker +nei.options.inventory.showRecipeMarker.true=Yes +nei.options.inventory.showRecipeMarker.false=No nei.options.inventory.creative_tab_style=Creative or JEI tab style nei.options.inventory.creative_tab_style.true=Creative nei.options.inventory.creative_tab_style.false=JEI @@ -193,6 +196,8 @@ nei.options.world.highlight_tips.hide=Hidden nei.options.world.highlight_tips.show=Shown nei.options.world.highlight_tips.sample=Sample +nei.options.world.panels=Panels Settings + nei.options.tools=Tools nei.options.tools.handler_load_from_config=Load handlers from Config nei.options.tools.handler_load_from_config.true=Config