diff --git a/build.properties b/build.properties index f34b24ca..48e7f3c8 100644 --- a/build.properties +++ b/build.properties @@ -2,4 +2,4 @@ mc_version=1.7.10 forge_version=10.13.4.1614-1.7.10 ccl_version=1.1.3.138 ccc_version=1.0.7.+ -mod_version=2.1.0-GTNH-beta4 +mod_version=2.1.0-GTNH-beta5 diff --git a/src/codechicken/nei/LayoutStyleMinecraft.java b/src/codechicken/nei/LayoutStyleMinecraft.java index 9d9c0a18..177d5fa3 100644 --- a/src/codechicken/nei/LayoutStyleMinecraft.java +++ b/src/codechicken/nei/LayoutStyleMinecraft.java @@ -136,7 +136,7 @@ public class LayoutStyleMinecraft extends LayoutStyle searchField.y = gui.height - searchField.h - 2; - dropDown.x = itemPanel.x - 150; + dropDown.x = gui.guiLeft; dropDown.h = 20; dropDown.w = Math.min(itemPanel.prev.x - dropDown.x - 3, 100); searchField.h = 20; diff --git a/src/codechicken/nei/drawable/DrawableResource.java b/src/codechicken/nei/drawable/DrawableResource.java index 5ede219a..849e5130 100644 --- a/src/codechicken/nei/drawable/DrawableResource.java +++ b/src/codechicken/nei/drawable/DrawableResource.java @@ -43,14 +43,14 @@ public class DrawableResource extends Image { public void draw(int xOffset, int yOffset, int maskTop, int maskBottom, int maskLeft, int maskRight) { Minecraft.getMinecraft().getTextureManager().bindTexture(this.resourceLocation); - int x = xOffset + this.paddingLeft + maskLeft; - int y = yOffset + this.paddingTop + maskTop; - int u = this.x + maskLeft; - int v = this.y + maskTop; - int width = this.width - maskRight - maskLeft; - int height = this.height - maskBottom - maskTop; + final int x = xOffset + this.paddingLeft + maskLeft; + final int y = yOffset + this.paddingTop + maskTop; + final int textureX = this.x + maskLeft; + final int textureY = this.y + maskTop; + final int width = this.width - maskRight - maskLeft; + final int height = this.height - maskBottom - maskTop; // drawModalRectWithCustomSizedTexture - Gui.func_146110_a(x, y, u, v, width, height, textureWidth, textureHeight); + Gui.func_146110_a(x, y, textureX, textureY, width, height, textureWidth, textureHeight); } } diff --git a/src/codechicken/nei/recipe/GuiRecipe.java b/src/codechicken/nei/recipe/GuiRecipe.java index 0343325d..dcebdd7d 100644 --- a/src/codechicken/nei/recipe/GuiRecipe.java +++ b/src/codechicken/nei/recipe/GuiRecipe.java @@ -13,6 +13,8 @@ import codechicken.nei.api.INEIGuiHandler; import codechicken.nei.api.IOverlayHandler; import codechicken.nei.api.IRecipeOverlayRenderer; import codechicken.nei.api.TaggedInventoryArea; +import codechicken.nei.drawable.DrawableBuilder; +import codechicken.nei.drawable.DrawableResource; import codechicken.nei.guihook.GuiContainerManager; import codechicken.nei.guihook.IContainerTooltipHandler; import codechicken.nei.guihook.IGuiClientSide; @@ -34,11 +36,25 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOverlay, IGuiClientSide, IGuiHandleMouseWheel, IContainerTooltipHandler, INEIGuiHandler -{ +public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOverlay, IGuiClientSide, IGuiHandleMouseWheel, IContainerTooltipHandler, INEIGuiHandler { + // Background image calculations + private static final int BG_TOP_HEIGHT = 6; + private static final int BG_MIDDLE_HEIGHT = 154; + private static final int BG_BOTTOM_HEIGHT = 6; + + private static final int BG_TOP_Y = 0; + private static final int BG_MIDDLE_Y = BG_TOP_Y + BG_TOP_HEIGHT; + private static final int BG_BOTTOM_Y = BG_MIDDLE_Y + BG_MIDDLE_HEIGHT; + + // Button sizes private static final int borderPadding = 6; private static final int buttonWidth = 13; private static final int buttonHeight = 12; + + // Background image + final DrawableResource bgTop = new DrawableBuilder("nei:textures/gui/recipebg.png", 0, BG_TOP_Y, 176, BG_TOP_HEIGHT).build(); + final DrawableResource bgMiddle = new DrawableBuilder("nei:textures/gui/recipebg.png", 0, BG_MIDDLE_Y, 176, BG_MIDDLE_HEIGHT).build(); + final DrawableResource bgBottom = new DrawableBuilder("nei:textures/gui/recipebg.png", 0, BG_BOTTOM_Y, 176, BG_BOTTOM_HEIGHT).build(); public ArrayList currenthandlers = new ArrayList<>(); private static Class gregtechHandler; @@ -51,6 +67,11 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve } } + // DEPRECATED +// public GuiButton overlay1; +// public GuiButton overlay2; + // END DEPRECATED + public int page; public int recipetype; public ContainerRecipe slotcontainer; @@ -58,8 +79,6 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve public GuiScreen prevGui; public GuiButton nextpage; public GuiButton prevpage; - public GuiButton overlay1; - public GuiButton overlay2; private GuiButton nexttype; private GuiButton prevtype; private final Rectangle area = new Rectangle(); @@ -84,22 +103,25 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve @Override public void initGui() { + this.xSize = 176; + this.ySize = Math.min(Math.max(this.height - 68, 166), 370); super.initGui(); - + this.guiTop = (this.height - this.ySize) / 2 + 10; + currenthandlers = getCurrentRecipeHandlers(); // Probably don't comment me out final int rightButtonX = guiLeft + xSize - borderPadding - buttonWidth; final int leftButtonX = guiLeft + borderPadding; - nexttype = new GuiNEIButton(0, leftButtonX, (height - ySize) / 2 + 3, buttonWidth, buttonHeight, "<"); - prevtype = new GuiNEIButton(1, rightButtonX, (height - ySize) / 2 + 3, buttonWidth, buttonHeight, ">"); + nexttype = new GuiNEIButton(0, leftButtonX, guiTop + 3, buttonWidth, buttonHeight, "<"); + prevtype = new GuiNEIButton(1, rightButtonX, guiTop + 3, buttonWidth, buttonHeight, ">"); - nextpage = new GuiNEIButton(2, leftButtonX, (height - ySize) / 2 + 17, buttonWidth, buttonHeight, "<"); - prevpage = new GuiNEIButton(3, rightButtonX, (height - ySize) / 2 + 17, buttonWidth, buttonHeight, ">"); + nextpage = new GuiNEIButton(2, leftButtonX, guiTop + 17, buttonWidth, buttonHeight, "<"); + prevpage = new GuiNEIButton(3, rightButtonX, guiTop + 17, buttonWidth, buttonHeight, ">"); - overlay1 = new GuiNEIButton(4, width / 2 + 65, (height - ySize) / 2 + 63, buttonWidth, buttonHeight, "?"); - overlay2 = new GuiNEIButton(5, width / 2 + 65, (height - ySize) / 2 + 128, buttonWidth, buttonHeight, "?"); +// overlay1 = new GuiNEIButton(4, width / 2 + 65, guiTop + 63, buttonWidth, buttonHeight, "?"); +// overlay2 = new GuiNEIButton(5, width / 2 + 65, guiTop + 128, buttonWidth, buttonHeight, "?"); - buttonList.addAll(Arrays.asList(nexttype, prevtype, nextpage, prevpage, overlay1, overlay2)); + buttonList.addAll(Arrays.asList(nexttype, prevtype, nextpage, prevpage)); if (currenthandlers.size() == 1) { nexttype.visible = false; @@ -130,7 +152,8 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve return; IRecipeHandler recipehandler = currenthandlers.get(recipetype); - for (int recipe = page * recipehandler.recipiesPerPage(); recipe < recipehandler.numRecipes() && recipe < (page + 1) * recipehandler.recipiesPerPage(); recipe++) + final int recipesPerPage = getRecipesPerPage(); + for (int recipe = page * recipesPerPage; recipe < recipehandler.numRecipes() && recipe < (page + 1) * recipesPerPage; recipe++) if (recipehandler.keyTyped(this, c, i, recipe)) return; @@ -152,7 +175,8 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve @Override protected void mouseClicked(int x, int y, int button) { IRecipeHandler recipehandler = currenthandlers.get(recipetype); - for (int recipe = page * recipehandler.recipiesPerPage(); recipe < recipehandler.numRecipes() && recipe < (page + 1) * recipehandler.recipiesPerPage(); recipe++) + final int recipesPerPage = getRecipesPerPage(); + for (int recipe = page * recipesPerPage; recipe < recipehandler.numRecipes() && recipe < (page + 1) * recipesPerPage; recipe++) if (recipehandler.mouseClicked(this, button, recipe)) return; if (recipeTabs.mouseClicked(x, y, button)) @@ -163,6 +187,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve @Override protected void actionPerformed(GuiButton guibutton) { super.actionPerformed(guibutton); + final int recipesPerPage = getRecipesPerPage(); switch (guibutton.id) { case 0: prevType(); @@ -176,12 +201,12 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve case 3: nextPage(); break; - case 4: - overlayRecipe(page * currenthandlers.get(recipetype).recipiesPerPage()); - break; - case 5: - overlayRecipe(page * currenthandlers.get(recipetype).recipiesPerPage() + 1); - break; +// case 4: +// overlayRecipe(page * recipesPerPage); +// break; +// case 5: +// overlayRecipe(page * recipesPerPage + 1); +// break; } } @@ -194,8 +219,9 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve @Override public List handleTooltip(GuiContainer gui, int mousex, int mousey, List currenttip) { + final int recipesPerPage = getRecipesPerPage(); IRecipeHandler recipehandler = currenthandlers.get(recipetype); - for (int i = page * recipehandler.recipiesPerPage(); i < recipehandler.numRecipes() && i < (page + 1) * recipehandler.recipiesPerPage(); i++) + for (int i = page * recipesPerPage; i < recipehandler.numRecipes() && i < (page + 1) * recipesPerPage; i++) currenttip = recipehandler.handleTooltip(this, currenttip, i); recipeTabs.handleTooltip(mousex, mousey, currenttip); return currenttip; @@ -203,8 +229,9 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve @Override public List handleItemTooltip(GuiContainer gui, ItemStack stack, int mousex, int mousey, List currenttip) { + final int recipesPerPage = getRecipesPerPage(); IRecipeHandler recipehandler = currenthandlers.get(recipetype); - for (int i = page * recipehandler.recipiesPerPage(); i < recipehandler.numRecipes() && i < (page + 1) * recipehandler.recipiesPerPage(); i++) + for (int i = page * recipesPerPage; i < recipehandler.numRecipes() && i < (page + 1) * recipesPerPage; i++) currenttip = recipehandler.handleItemTooltip(this, stack, currenttip, i); return currenttip; @@ -217,14 +244,12 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve private void nextPage() { page++; - if (page > (currenthandlers.get(recipetype).numRecipes() - 1) / currenthandlers.get(recipetype).recipiesPerPage()) - page = 0; + if (page > (currenthandlers.get(recipetype).numRecipes() - 1) / getRecipesPerPage()) page = 0; } private void prevPage() { page--; - if (page < 0) - page = (currenthandlers.get(recipetype).numRecipes() - 1) / currenthandlers.get(recipetype).recipiesPerPage(); + if (page < 0) page = (currenthandlers.get(recipetype).numRecipes() - 1) / getRecipesPerPage(); } private void nextType() { @@ -237,28 +262,26 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve public void setRecipePage(int idx) { recipetype = idx; - if (recipetype < 0) - recipetype = currenthandlers.size() - 1; - else if (recipetype >= currenthandlers.size()) - recipetype = 0; + if (recipetype < 0) recipetype = currenthandlers.size() - 1; + else if (recipetype >= currenthandlers.size()) recipetype = 0; page = 0; recipeTabs.calcPageNumber(); checkGregTech(); } - private void overlayRecipe(int recipe) { - IRecipeOverlayRenderer renderer = currenthandlers.get(recipetype).getOverlayRenderer(firstGui, recipe); - IOverlayHandler handler = currenthandlers.get(recipetype).getOverlayHandler(firstGui, recipe); - boolean shift = NEIClientUtils.shiftKey(); - - if (handler != null && (renderer == null || shift)) { - mc.displayGuiScreen(firstGui); - handler.overlayRecipe(firstGui, currenthandlers.get(recipetype), recipe, shift); - } else if (renderer != null) { - mc.displayGuiScreen(firstGui); - LayoutManager.overlayRenderer = renderer; - } - } +// private void overlayRecipe(int recipe) { +// IRecipeOverlayRenderer renderer = currenthandlers.get(recipetype).getOverlayRenderer(firstGui, recipe); +// IOverlayHandler handler = currenthandlers.get(recipetype).getOverlayHandler(firstGui, recipe); +// boolean shift = NEIClientUtils.shiftKey(); +// +// if (handler != null && (renderer == null || shift)) { +// mc.displayGuiScreen(firstGui); +// handler.overlayRecipe(firstGui, currenthandlers.get(recipetype), recipe, shift); +// } else if (renderer != null) { +// mc.displayGuiScreen(firstGui); +// LayoutManager.overlayRenderer = renderer; +// } +// } public void refreshPage() { refreshSlots(); @@ -271,24 +294,25 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve calcArea(handler); checkGregTech(); - boolean multiplepages = handler.numRecipes() > handler.recipiesPerPage(); + final int recipesPerPage = getRecipesPerPage(); + boolean multiplepages = handler.numRecipes() > recipesPerPage; nextpage.enabled = prevpage.enabled = multiplepages; - if(firstGui != null) { - overlay1.yPosition = (height - ySize) / 2 + 17 + (handler.recipiesPerPage() == 2 ? 63 : 128); - overlay1.visible = handler.hasOverlay(firstGui, firstGui.inventorySlots, page * handler.recipiesPerPage()); - overlay2.visible = handler.recipiesPerPage() == 2 && page * handler.recipiesPerPage() + 1 < handler.numRecipes() && - handler.hasOverlay(firstGui, firstGui.inventorySlots, page * handler.recipiesPerPage() + 1); - } else { - overlay1.visible = overlay2.visible = false; - } +// // TODO: Display overlay buttons here again +// if(firstGui != null) { +// overlay1.yPosition = guiTop + 17 + (recipesPerPage == 2 ? 63 : 128); +// overlay1.visible = handler.hasOverlay(firstGui, firstGui.inventorySlots, page * recipesPerPage); +// overlay2.visible = recipesPerPage == 2 && page * recipesPerPage + 1 < handler.numRecipes() && handler.hasOverlay(firstGui, firstGui.inventorySlots, page * recipesPerPage + 1); +// } else { +// overlay1.visible = overlay2.visible = false; +// } recipeTabs.refreshPage(); } private void calcArea(IRecipeHandler handler) { if ( handler.getClass().toString().contains("fox.spiteful.avaritia.compat.nei.")) { - // Handle avarita's oversized handler area + // Handle Avarita's oversized handler area area.width = 256; area.height = 208; } @@ -296,8 +320,9 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve private void refreshSlots() { slotcontainer.inventorySlots.clear(); + final int recipesPerPage = getRecipesPerPage(); IRecipeHandler recipehandler = currenthandlers.get(recipetype); - for (int i = page * recipehandler.recipiesPerPage(); i < recipehandler.numRecipes() && i < (page + 1) * recipehandler.recipiesPerPage(); i++) { + for (int i = page * recipesPerPage; i < recipehandler.numRecipes() && i < (page + 1) * recipesPerPage; i++) { Point p = getRecipePosition(i); List stacks = recipehandler.getIngredientStacks(i); @@ -317,16 +342,16 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { GuiContainerManager.enable2DRender(); - + final int recipesPerPage = getRecipesPerPage(); IRecipeHandler recipehandler = currenthandlers.get(recipetype); String s = recipehandler.getRecipeName(); fontRendererObj.drawStringWithShadow(s, (xSize - fontRendererObj.getStringWidth(s)) / 2, 5, 0xffffff); - s = NEIClientUtils.translate("recipe.page", page + 1, (currenthandlers.get(recipetype).numRecipes() - 1) / recipehandler.recipiesPerPage() + 1); + s = NEIClientUtils.translate("recipe.page", page + 1, (currenthandlers.get(recipetype).numRecipes() - 1) / recipesPerPage + 1); fontRendererObj.drawStringWithShadow(s, (xSize - fontRendererObj.getStringWidth(s)) / 2, 19, 0xffffff); GL11.glPushMatrix(); GL11.glTranslatef(5, 32 + yShift, 0); - for (int i = page * recipehandler.recipiesPerPage(); i < recipehandler.numRecipes() && i < (page + 1) * recipehandler.recipiesPerPage(); i++) { + for (int i = page * recipesPerPage; i < recipehandler.numRecipes() && i < (page + 1) * recipesPerPage; i++) { recipehandler.drawForeground(i); GL11.glTranslatef(0, 65, 0); } @@ -335,11 +360,12 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve @Override protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) { + final int recipesPerPage = getRecipesPerPage(); GL11.glColor4f(1, 1, 1, 1); - CCRenderState.changeTexture("nei:textures/gui/recipebg.png"); - int j = (width - xSize) / 2; - int k = (height - ySize) / 2; - drawTexturedModalRect(j, k, 0, 0, xSize, ySize); + final int j = (width - xSize) / 2; + final int k = guiTop; + + drawBackgroundTiled(j, k); drawRect(guiLeft + borderPadding + buttonWidth - 1, nexttype.yPosition, @@ -350,9 +376,7 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve nextpage.yPosition, guiLeft + xSize - borderPadding - buttonWidth, nextpage.yPosition + buttonHeight, - 0x30000000); - - + 0x30000000); if (NEIClientConfig.areJEIStyleTabsVisible()) { RenderHelper.enableGUIStandardItemLighting(); @@ -364,13 +388,38 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve GL11.glPushMatrix(); GL11.glTranslatef(j + 5, k + 32 + yShift, 0); IRecipeHandler recipehandler = currenthandlers.get(recipetype); - for (int i = page * recipehandler.recipiesPerPage(); i < recipehandler.numRecipes() && i < (page + 1) * recipehandler.recipiesPerPage(); i++) { + for (int i = page * recipesPerPage; i < recipehandler.numRecipes() && i < (page + 1) * recipesPerPage; i++) { recipehandler.drawBackground(i); GL11.glTranslatef(0, 65, 0); } GL11.glPopMatrix(); } + private void drawBackgroundTiled(int j, int k) { + // Draw the top + bgTop.draw(j, k + BG_TOP_Y); + + // Maybe Tile the middle + final int tiledHeight = ySize - BG_TOP_HEIGHT - BG_BOTTOM_HEIGHT; + + if (tiledHeight > 0) { + final int yTileCount = tiledHeight / BG_MIDDLE_HEIGHT; + final int yRemainder = tiledHeight - (yTileCount * BG_MIDDLE_HEIGHT); + final int yStart = k + BG_TOP_HEIGHT + tiledHeight; + + for (int yTile = 0; yTile <= yTileCount; yTile++) { + final int tileHeight = (yTile == yTileCount) ? yRemainder : BG_MIDDLE_HEIGHT; + final int y = yStart - ((yTile + 1) * BG_MIDDLE_HEIGHT); + if (tileHeight > 0) { + bgMiddle.draw(j, y, BG_MIDDLE_HEIGHT - tileHeight, 0, 0, 0); + } + } + } + + // Draw the bottom + bgBottom.draw(j, k + ySize - BG_BOTTOM_HEIGHT); + } + @Override public GuiContainer getFirstScreen() { return firstGui; @@ -383,9 +432,24 @@ public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOve return stackSlot == mouseoverSlot; } + + private int getRecipesPerPage() { + // The handlers give no indication of height, and use hard coded values + // The default handlers have a height of 65. Go with the (most likely incorrect) assumption + // that if a handler allows more than one recipe per page the height is 65 so use that to calculate the # per page. + // If it only allows for 1 then it's unknown and we'll stick with 1 recipe per page. + + final IRecipeHandler handler = currenthandlers.get(recipetype); + final int handlerRecipesPerPage = handler.recipiesPerPage(); + if (handler instanceof TemplateRecipeHandler && handlerRecipesPerPage > 1) { + return ((ySize - (prevtype.height*3)) / 65); + } else { + return handlerRecipesPerPage; + } + } public Point getRecipePosition(int recipe) { - return new Point(5, 32 + yShift + (recipe % currenthandlers.get(recipetype).recipiesPerPage()) * 65); + return new Point(5, 32 + yShift + (recipe % getRecipesPerPage()) * 65); } @Override