mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-10-26 14:24:07 +00:00
DrawableResource from JEI. Swap out tab & tab icon drawing.
This commit is contained in:
1 parent
2a667e1942
commit
6279149b21
5 files changed
+140
-27
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
@@ -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()) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String, ImmutablePair<String, Image>> iconMap = new HashMap<>();
|
||||
public class GuiRecipeTab extends Widget {
|
||||
public static HashMap<String, ImmutablePair<String, DrawableResource>> imageMap = new HashMap<>();
|
||||
public static HashMap<String, ImmutablePair<String, ItemStack>> 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<String> 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<String, Image> iconRes = iconMap.get(name);
|
||||
Pair<String, DrawableResource> 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<String, Image> res = iconMap.get(id);
|
||||
public static DrawableResource getImage(String id) {
|
||||
Pair<String, DrawableResource> 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));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user