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 00000000..803f876e Binary files /dev/null and b/resources/assets/nei/textures/nei_tabbed_sprites.png differ 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)); } }