From 07ec5f67c5df3e655c4e0ca5d79ff288a5d74f54 Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Sun, 21 Mar 2021 21:43:37 -0700 Subject: [PATCH] DrawableResource from JEI. Swap out tab & tab icon drawing. --- .../nei/textures/nei_tabbed_sprites.png | Bin 0 -> 3334 bytes src/codechicken/nei/LayoutManager.java | 2 +- .../nei/drawable/DrawableBuilder.java | 52 +++++++++++++++ .../nei/drawable/DrawableResource.java | 63 ++++++++++++++++++ src/codechicken/nei/recipe/GuiRecipeTab.java | 50 +++++++------- 5 files changed, 140 insertions(+), 27 deletions(-) create mode 100644 resources/assets/nei/textures/nei_tabbed_sprites.png create mode 100644 src/codechicken/nei/drawable/DrawableBuilder.java create mode 100644 src/codechicken/nei/drawable/DrawableResource.java diff --git a/resources/assets/nei/textures/nei_tabbed_sprites.png b/resources/assets/nei/textures/nei_tabbed_sprites.png new file mode 100644 index 0000000000000000000000000000000000000000..803f876e4253dd38532540b6ba11d7e7a1c5c3fe GIT binary patch literal 3334 zcmeHJ`8O178=gsHG})sFk;vx~?oa;W%bIx_H>%Q(Eo_{PYOn4w?Apih?2LU&<1^|HU z76{nuwltr|=zuJ4lVc7cj2Y z*LWK`u6^m_=br$r+VnAW!m^ns_#bdq?-qABa}?_!YOXde3w*8Tady_y^x$jx0c7TJ zk7u~Z!%-iWV)rzd#h1TEp2Ss0v}@9Xn1Hus6;z(UKrZexa*>~xrX;G`S&_xxX84?m z!MVm=JYnp7IPaR77_yOF3>Ybf4JQKO4j}-*NrAry7~_skWnY4E2y-LwBFE|D9O8s> z8aryp4#H6X_Wg0;RBL5@T8 zt=>*bvH9ydcLT6WmA2iUSqMtv03?cbXU3apx z(@Ilpbs?#H&-}3T5NnP%ww2_b(5fi+!^rJNkm@(_aT1h~k*^@P0}$b&7$m_Dk8d?M zUp`D3ftJlT)_H=HQ0HjatVAC z+r=eenu}AGEhfClaeX;_nwL|emrr&_N(dsKQOkJ_&h~_>(j8(J7t7G9Sy*35xA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q&hwCtfKgDR=ttW{q2sMwKFF&$UW-# z)>Z!iyLU1|DJ|+(O?2+<{$k4dyTfOLgAsnmn3YswkSHZn?1@6wBh#zOmoV4Ivnsr= z6l~P1+5E74L!Z$sr)~}jC$c8!o5+il%(S5KK&?U`4sgnftU^gTOF=~B{xGzL#ya;% zTQS5CYz=l}(^n;3bRzbSzbO4s(UT%U-&m?j7<2wBFNg zD&KLTkcGNxMXht`+YUL)rpw60cfLM5IO(*JFBh!Z>Cv~RQXdH-?5=M3cBdl)_xX-@ z8q(e|d3v`iAxodEKbq&+ybJNj&J73lr)pzx`5M(MS(l#0{<9xL-{Q5D$C4fDokSo~ z0GXB-dHY$dz8lV;U*3dWN(!*jo>R!$%D~+WO}MbS`s?<^vo9(OqgxAu|vf}DyVDmt2Mk*!^3r0%-|etSPT z6>x0UI1G&5`zmG&4zN zG%s?4_yI2nN-Av+EW7`ZqHaa=1I{?CqQU^ZXS^zpT+ya-LZ(qNGtN{nA=Nb-6~iA` uc_jWlZTiS@GLQlO`@{Qx{SOl$oLG-RdEb%0%TucNmj+>EVOVY8_V7QS)5$CV literal 0 HcmV?d00001 diff --git a/src/codechicken/nei/LayoutManager.java b/src/codechicken/nei/LayoutManager.java index 4603fd42..6c41a2b0 100644 --- a/src/codechicken/nei/LayoutManager.java +++ b/src/codechicken/nei/LayoutManager.java @@ -258,7 +258,7 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH GL11.glEnable(GL11.GL_DEPTH_TEST); } } - + @Override public void postRenderObjects(GuiContainer gui, int mousex, int mousey) { if (!isHidden() && isEnabled()) { diff --git a/src/codechicken/nei/drawable/DrawableBuilder.java b/src/codechicken/nei/drawable/DrawableBuilder.java new file mode 100644 index 00000000..bfd0dc10 --- /dev/null +++ b/src/codechicken/nei/drawable/DrawableBuilder.java @@ -0,0 +1,52 @@ +package codechicken.nei.drawable; + +import net.minecraft.util.ResourceLocation; + +public class DrawableBuilder { + private final ResourceLocation resourceLocation; + private int u; + private int v; + private int width; + private int height; + private int textureWidth = 256; + private int textureHeight = 256; + private int paddingTop = 0; + private int paddingBottom = 0; + private int paddingLeft = 0; + private int paddingRight = 0; + + public DrawableBuilder(String resourceLocation, int u, int v, int width, int height) { + this.u = u; + this.v = v; + this.width = width; + this.height = height; + this.resourceLocation = new ResourceLocation(resourceLocation); + } + + public DrawableBuilder setTextureSize(int width, int height) { + this.textureWidth = width; + this.textureHeight = height; + return this; + } + + public DrawableBuilder addPadding(int paddingTop, int paddingBottom, int paddingLeft, int paddingRight) { + this.paddingTop = paddingTop; + this.paddingBottom = paddingBottom; + this.paddingLeft = paddingLeft; + this.paddingRight = paddingRight; + return this; + } + + public DrawableBuilder trim(int trimTop, int trimBottom, int trimLeft, int trimRight) { + this.u += trimLeft; + this.v += trimTop; + this.width -= trimLeft + trimRight; + this.height -= trimTop + trimBottom; + return this; + } + + public DrawableResource build() { + return new DrawableResource(resourceLocation, u, v, width, height, paddingTop, paddingBottom, paddingLeft, paddingRight, textureWidth, textureHeight); + } + +} diff --git a/src/codechicken/nei/drawable/DrawableResource.java b/src/codechicken/nei/drawable/DrawableResource.java new file mode 100644 index 00000000..bca9db71 --- /dev/null +++ b/src/codechicken/nei/drawable/DrawableResource.java @@ -0,0 +1,63 @@ +package codechicken.nei.drawable; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.util.ResourceLocation; + +public class DrawableResource { + + private final ResourceLocation resourceLocation; + private final int textureWidth; + private final int textureHeight; + + private final int u; + private final int v; + private final int width; + private final int height; + private final int paddingTop; + private final int paddingBottom; + private final int paddingLeft; + private final int paddingRight; + + public DrawableResource(ResourceLocation resourceLocation, int u, int v, int width, int height, int paddingTop, int paddingBottom, int paddingLeft, int paddingRight, int textureWidth, int textureHeight) { + this.resourceLocation = resourceLocation; + this.textureWidth = textureWidth; + this.textureHeight = textureHeight; + + this.u = u; + this.v = v; + this.width = width; + this.height = height; + + this.paddingTop = paddingTop; + this.paddingBottom = paddingBottom; + this.paddingLeft = paddingLeft; + this.paddingRight = paddingRight; + } + + public int getWidth() { + return width + paddingLeft + paddingRight; + } + + public int getHeight() { + return height + paddingTop + paddingBottom; + } + + public void draw(int xOffset, int yOffset) { + draw(xOffset, yOffset, 0, 0, 0, 0); + } + + 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.u + maskLeft; + int v = this.v + maskTop; + int width = this.width - maskRight - maskLeft; + int height = this.height - maskBottom - maskTop; + // drawModalRectWithCustomSizedTexture + Gui.func_146110_a(x, y, u, v, width, height, textureWidth, textureHeight); + } +} + diff --git a/src/codechicken/nei/recipe/GuiRecipeTab.java b/src/codechicken/nei/recipe/GuiRecipeTab.java index 94bdef58..ba5b33f3 100644 --- a/src/codechicken/nei/recipe/GuiRecipeTab.java +++ b/src/codechicken/nei/recipe/GuiRecipeTab.java @@ -2,9 +2,9 @@ package codechicken.nei.recipe; import codechicken.lib.gui.GuiDraw; -import codechicken.nei.Button; -import codechicken.nei.Image; -import codechicken.nei.LayoutManager; +import codechicken.nei.Widget; +import codechicken.nei.drawable.DrawableBuilder; +import codechicken.nei.drawable.DrawableResource; import codechicken.nei.guihook.GuiContainerManager; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.registry.GameRegistry; @@ -18,14 +18,14 @@ import org.lwjgl.opengl.GL11; import java.util.HashMap; import java.util.List; -public class GuiRecipeTab extends Button { - public static HashMap> iconMap = new HashMap<>(); +public class GuiRecipeTab extends Widget { + public static HashMap> imageMap = new HashMap<>(); public static HashMap> stackMap = new HashMap<>(); public static final int TAB_WIDTH = 24; public static final int TAB_HEIGHT = 24; - private static final Image selectedIcon = new Image(0, 52, 24, 24); - private static final Image unselectedIcon = new Image(24, 52, 24, 24); + private static final DrawableResource selectedIcon = new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 0, 16, 24, 24).build(); + private static final DrawableResource unselectedIcon = new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 24, 16, 24, 24).build(); private final GuiRecipe guiRecipe; private final IRecipeHandler handler; @@ -61,14 +61,13 @@ public class GuiRecipeTab extends Button { public void drawBackground(int mouseX, int mouseY) { GL11.glDisable(GL11.GL_LIGHTING); GL11.glColor4f(1, 1, 1, 1); + final DrawableResource image; + if (selected) image = selectedIcon; + else image = unselectedIcon; - if (selected) icon = selectedIcon; - else icon = unselectedIcon; - - final int iconX = x + (w - icon.width) / 2; - final int iconY = y + (h - icon.height) / 2; - LayoutManager.drawIcon(iconX, iconY, icon); - + final int iconX = x + (w - image.getWidth()) / 2; + final int iconY = y + (h - image.getHeight()) / 2; + image.draw(iconX, iconY); } public void drawForeground(int mouseX, int mouseY) { @@ -76,13 +75,13 @@ public class GuiRecipeTab extends Button { final int iconY = y + 4; final FontRenderer fontRenderer = GuiDraw.fontRenderer; - final Image icon = getIcon(handlerName); + final DrawableResource icon = getImage(handlerName); final ItemStack itemStack = getItemStack(handlerName, handlerID); - + if (icon != null) { - LayoutManager.drawIcon(iconX + 1, iconY + 1, icon); + icon.draw(iconX + 1, iconY + 1); } else if (itemStack != null) { GuiContainerManager.drawItems.zLevel += 100; GuiContainerManager.drawItem(iconX, iconY, itemStack); @@ -98,7 +97,6 @@ public class GuiRecipeTab extends Button { } } - @Override public void addTooltips(List tooltip) { tooltip.add(handler.getRecipeName().trim()); @@ -113,7 +111,6 @@ public class GuiRecipeTab extends Button { } - @Override public boolean onButtonPress(boolean rightclick) { int newIdx = guiRecipe.currenthandlers.indexOf(handler); if (newIdx == -1) @@ -140,7 +137,7 @@ public class GuiRecipeTab extends Button { if (stackRes != null) return stackRes.getLeft(); - Pair iconRes = iconMap.get(name); + Pair iconRes = imageMap.get(name); if (iconRes != null) return iconRes.getLeft(); @@ -154,8 +151,8 @@ public class GuiRecipeTab extends Button { return null; } - public static Image getIcon(String id) { - Pair res = iconMap.get(id); + public static DrawableResource getImage(String id) { + Pair res = imageMap.get(id); if (res != null) return res.getRight(); return null; @@ -169,8 +166,9 @@ public class GuiRecipeTab extends Button { addToStackMap("codechicken.nei.recipe.FurnaceRecipeHandler", "minecraft", "minecraft:furnace"); addToStackMap("codechicken.nei.recipe.ShapedRecipeHandler", "minecraft", "minecraft:crafting_table"); addToStackMap("codechicken.nei.recipe.ShapelessRecipeHandler", "minecraft", "minecraft:crafting_table"); - addToIconMap("codechicken.nei.recipe.FuelRecipeHandler", "minecraft", new Image(80, 36, 14, 14)); - + addToIconMap("codechicken.nei.recipe.FuelRecipeHandler", "minecraft", + new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 80, 0, 14, 14).build()); + // IC2 if (Loader.isModLoaded("IC2")) { addToStackMap("ic2.neiIntegration.core.recipehandler.AdvRecipeHandler", "IC2", "IC2:blockreactorvessel"); @@ -561,7 +559,7 @@ public class GuiRecipeTab extends Button { else System.out.println("Couldn't find " + modname + " - " + item_id); } - private static void addToIconMap(String handler, String modid, Image image) { - iconMap.put(handler, new ImmutablePair<>(modid, image)); + private static void addToIconMap(String handler, String modname, DrawableResource image) { + imageMap.put(handler, new ImmutablePair<>(modname, image)); } }