Add option to switch between JEI tab style and Creative tab style

This commit is contained in:
Jason Mitchell authored and Jason Mitchell committed 2021-04-12 20:20:36 -07:00
1 parent a14d70ee8f
commit 4fb83ddea6
6 files changed
+152 -26

No files matched your search

+3
View File
@@ -114,6 +114,9 @@ nei.options.inventory.bookmarksEnabled.false=Hidden
nei.options.inventory.jei_style_tabs=JEI Style Tabs
nei.options.inventory.jei_style_tabs.true=Yes
nei.options.inventory.jei_style_tabs.false=No [Weirdo]
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
nei.options.inventory.widgetsenabled.true=NEI Enabled
nei.options.inventory.widgetsenabled.false=NEI Disabled
nei.options.inventory.cheatmode.0=Recipe Mode
+7 -1
View File
@@ -78,7 +78,7 @@ public class NEIClientConfig
tag.getTag("inventory.widgetsenabled").getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.widgetsenabled"));
tag.getTag("inventory.hidden").getBooleanValue(false);
tag.getTag("inventory.cheatmode").getIntValue(2);
tag.getTag("inventory.lockmode").setComment("For those who can't help themselves.\nSet this to a mode and you will be unable to change it ingame").getIntValue(-1);
@@ -130,6 +130,9 @@ public class NEIClientConfig
tag.getTag("inventory.jei_style_tabs").setComment("Enable/disable JEI Style Tabs").getBooleanValue(true);
API.addOption(new OptionToggleButtonBoubs("inventory.jei_style_tabs", true));
tag.getTag("inventory.creative_tab_style").setComment("Creative or JEI style tabs").getBooleanValue(false);
API.addOption(new OptionToggleButton("inventory.creative_tab_style", true));
setDefaultKeyBindings();
}
@@ -294,6 +297,9 @@ public class NEIClientConfig
public static boolean areJEIStyleTabsVisible() {
return getBooleanSetting("inventory.jei_style_tabs");
}
public static boolean useCreativeTabStyle() {
return getBooleanSetting("inventory.creative_tab_style");
}
public static boolean isEnabled() {
return enabledOverride && getBooleanSetting("inventory.widgetsenabled");
}
+20 -15
View File
@@ -18,14 +18,9 @@ import org.lwjgl.opengl.GL11;
import java.util.HashMap;
import java.util.List;
public class GuiRecipeTab extends Widget {
public abstract 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 = 28;
public static final int TAB_HEIGHT = 31;
private static final DrawableResource selectedIcon = new DrawableBuilder("minecraft:textures/gui/container/creative_inventory/tabs.png", 28, 32, 28, 32).build();
private static final DrawableResource unselectedIcon = new DrawableBuilder("minecraft:textures/gui/container/creative_inventory/tabs.png", 28, 0, 28, 30).build();
private final GuiRecipe guiRecipe;
private final IRecipeHandler handler;
@@ -33,13 +28,23 @@ public class GuiRecipeTab extends Widget {
private final String handlerID;
private boolean selected;
public abstract int getWidth();
public abstract int getHeight();
public abstract DrawableResource getSelectedTabImage();
public abstract DrawableResource getUnselectedTabImage();
protected abstract int getForegroundIconX();
protected abstract int getForegroundIconY();
public GuiRecipeTab(GuiRecipe guiRecipe, IRecipeHandler handler, int x, int y) {
super();
this.x = x;
this.y = y;
this.w = TAB_WIDTH;
this.h = TAB_HEIGHT;
this.w = getWidth();
this.h = getHeight();
this.handler = handler;
this.handlerName = handler.toString().split("@")[0];
this.guiRecipe = guiRecipe;
@@ -62,17 +67,17 @@ public class GuiRecipeTab extends Widget {
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glColor4f(1, 1, 1, 1);
final DrawableResource image;
if (selected) image = selectedIcon;
else image = unselectedIcon;
if (selected) image = getSelectedTabImage();
else image = getUnselectedTabImage();
final int iconX = x + (w - image.getWidth()) / 2;
final int iconY = y;
final int iconY = y + (h - image.getHeight()) / 2;
image.draw(iconX, iconY);
}
public void drawForeground(int mouseX, int mouseY) {
final int iconX = x + (w - 16) / 2;
final int iconY = y + h - 22;
final int iconX = getForegroundIconX();
final int iconY = getForegroundIconY();
final FontRenderer fontRenderer = GuiDraw.fontRenderer;
final DrawableResource icon = getImage(handlerName);
@@ -89,8 +94,8 @@ public class GuiRecipeTab extends Widget {
} else {
// Text fallback
String text = handler.getRecipeName().substring(0, 2);
int textCenterX = x + (int) (TAB_WIDTH / 2f);
int textCenterY = y + (int) (TAB_HEIGHT / 2f) - 3;
int textCenterX = x + (int) (getWidth() / 2f);
int textCenterY = y + (int) (getHeight() / 2f) - 3;
int color = selected ? 0xffffa0 : 0xe0e0e0;
fontRenderer.drawStringWithShadow(text, textCenterX - (int) (fontRenderer.getStringWidth(text) / 2f), textCenterY, color);
GL11.glColor4f(1, 1, 1, 1);
@@ -0,0 +1,47 @@
package codechicken.nei.recipe;
import codechicken.nei.drawable.DrawableBuilder;
import codechicken.nei.drawable.DrawableResource;
public class GuiRecipeTabCreative extends GuiRecipeTab {
public static final int TAB_WIDTH = 28;
public static final int TAB_HEIGHT = 31;
private static final DrawableResource selectedTabImage = new DrawableBuilder("minecraft:textures/gui/container/creative_inventory/tabs.png", 28, 32, 28, 32).build();
private static final DrawableResource unselectedTabImage = new DrawableBuilder("minecraft:textures/gui/container/creative_inventory/tabs.png", 28, 0, 28, 30).build();
public GuiRecipeTabCreative(GuiRecipe guiRecipe, IRecipeHandler handler, int x, int y) {
super(guiRecipe, handler, x, y);
}
@Override
public int getWidth() {
return TAB_WIDTH;
}
@Override
public int getHeight() {
return TAB_HEIGHT;
}
@Override
protected int getForegroundIconX() {
return x + (w - 16) / 2;
}
@Override
protected int getForegroundIconY() {
return y + h - 22;
}
@Override
public DrawableResource getSelectedTabImage() {
return selectedTabImage;
}
@Override
public DrawableResource getUnselectedTabImage() {
return unselectedTabImage;
}
}
@@ -0,0 +1,47 @@
package codechicken.nei.recipe;
import codechicken.nei.drawable.DrawableBuilder;
import codechicken.nei.drawable.DrawableResource;
public class GuiRecipeTabJEI extends GuiRecipeTab {
public static final int TAB_WIDTH = 24;
public static final int TAB_HEIGHT = 24;
private static final DrawableResource selectedTabImage = new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 0, 16, 24, 24).build();
private static final DrawableResource unselectedTabImage = new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 24, 16, 24, 24).build();
public GuiRecipeTabJEI(GuiRecipe guiRecipe, IRecipeHandler handler, int x, int y) {
super(guiRecipe, handler, x, y);
}
@Override
public int getWidth() {
return TAB_WIDTH;
}
@Override
public int getHeight() {
return TAB_HEIGHT;
}
@Override
protected int getForegroundIconX() {
return x + 4;
}
@Override
protected int getForegroundIconY() {
return y + 4;
}
@Override
public DrawableResource getSelectedTabImage() {
return selectedTabImage;
}
@Override
public DrawableResource getUnselectedTabImage() {
return unselectedTabImage;
}
}
+28 -10
View File
@@ -14,23 +14,37 @@ public class GuiRecipeTabs {
private final List<Button> buttons = new ArrayList<>();
private final Rectangle area = new Rectangle();
private boolean creative_tab_style;
private int pageCount = 1;
private int pageNumber = 0;
private int categoriesPerPage = 1;
private int numHandlers = 1;
private int tabWidth;
private int tabHeight;
public GuiRecipeTabs(GuiRecipe guiRecipe) {
this.guiRecipe = guiRecipe;
}
public void initLayout() {
creative_tab_style = NEIClientConfig.useCreativeTabStyle();
if(creative_tab_style) {
tabWidth = GuiRecipeTabCreative.TAB_WIDTH;
tabHeight = GuiRecipeTabCreative.TAB_HEIGHT;
} else {
tabWidth = GuiRecipeTabJEI.TAB_WIDTH;
tabHeight = GuiRecipeTabJEI.TAB_HEIGHT;
}
int totalWidth = 0;
categoriesPerPage = 0;
numHandlers = guiRecipe.currenthandlers.size();
for (IRecipeHandler handler : guiRecipe.currenthandlers) {
if (totalWidth + GuiRecipeTab.TAB_WIDTH < (guiRecipe.xSize - 4)) {
totalWidth += GuiRecipeTab.TAB_WIDTH;
if (totalWidth + tabWidth < (guiRecipe.xSize - 4)) {
totalWidth += tabWidth;
categoriesPerPage++;
} else {
break;
@@ -38,9 +52,9 @@ public class GuiRecipeTabs {
}
area.width = totalWidth;
area.height = GuiRecipeTab.TAB_HEIGHT;
area.height = tabHeight;
area.x = guiRecipe.guiLeft + 4;
area.y = guiRecipe.guiTop - GuiRecipeTab.TAB_HEIGHT + 3;
area.y = guiRecipe.guiTop - tabHeight + 3;
pageCount = (int) Math.ceil((float) numHandlers / categoriesPerPage);
calcPageNumber();
@@ -62,20 +76,24 @@ public class GuiRecipeTabs {
final int index = i + startIndex;
if (index >= numHandlers) break;
IRecipeHandler handler = guiRecipe.currenthandlers.get(index);
int tabX = area.x + (i * GuiRecipeTab.TAB_WIDTH);
tabs.add(new GuiRecipeTab(guiRecipe, handler, tabX, area.y));
int tabX = area.x + (i * tabWidth);
if(NEIClientConfig.useCreativeTabStyle())
tabs.add(new GuiRecipeTabCreative(guiRecipe, handler, tabX, area.y));
else
tabs.add(new GuiRecipeTabJEI(guiRecipe, handler, tabX, area.y));
}
// Maybe add buttons
if (numHandlers > categoriesPerPage) {
Button prevTab = new Button("prevTab") {
@Override
public boolean onButtonPress(boolean rightClick) {
if (!rightClick) {
NEIClientUtils.playClickSound();
return previousPage();
} else return false;
} else
return false;
}
@Override
public String getRenderLabel() {
@@ -83,9 +101,9 @@ public class GuiRecipeTabs {
}
};
prevTab.w = 8;
prevTab.h = GuiRecipeTab.TAB_HEIGHT - 4;
prevTab.h = tabHeight - 4;
prevTab.x = area.x - prevTab.w;
prevTab.y = area.y + 4;
prevTab.y = area.y + 2;
buttons.add(prevTab);
Button nextTab = new Button("nextTab") {