Skip to content

Commit

Permalink
DnD big ItemStack; Show green slot highlighting overlay (GTNewHorizon…
Browse files Browse the repository at this point in the history
…s#463)

* DnD big ItemStack; Show green slot highlighting overlay

* change config

* spotless

* remove system.log

* remove system.log

* show formatted stacksize

* fix draw handler foreground

---------

Co-authored-by: slprime <[email protected]>
  • Loading branch information
slprime and slprime authored Feb 21, 2024
1 parent f7ba34c commit 94676e0
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 38 deletions.
3 changes: 1 addition & 2 deletions src/main/java/codechicken/nei/LayoutManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -828,11 +828,10 @@ public static void drawButtonBackground(int x, int y, int w, int h, boolean edge
public static void drawItemPresenceOverlay(int slotX, int slotY, boolean isPresent, boolean slotHighlight) {

if (slotHighlight) {
if (isPresent) return;
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glTranslatef(0, 0, -150);
drawRect(slotX, slotY, 16, 16, 0x80AA0000);
drawRect(slotX, slotY, 16, 16, isPresent ? 0x8000AA00 : 0x80AA0000);
GL11.glTranslatef(0, 0, 150);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
Expand Down
25 changes: 11 additions & 14 deletions src/main/java/codechicken/nei/NEIClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,11 @@ public boolean onClick(int button) {
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.jei_style_item_presence_overlay")
.setComment("Enable/disable JEI Style item presence overlay on ?-hover").getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.jei_style_item_presence_overlay", true));
tag.getTag("inventory.itemPresenceOverlay").setComment("Item presence overlay on ?-hover").getIntValue(1);
API.addOption(new OptionCycled("inventory.itemPresenceOverlay", 3, true));

tag.getTag("inventory.slotHighlightPresent").setComment("Highlight Present Item").getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.slotHighlightPresent", true));

tag.getTag("inventory.jei_style_recipe_catalyst").setComment("Enable/disable JEI Style Recipe Catalysts")
.getBooleanValue(true);
Expand All @@ -303,11 +305,6 @@ public boolean onClick(int button) {
.setComment("Require holding shift to move items when overlaying recipe").getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.shift_overlay_recipe", true));

tag.getTag("inventory.slotHighlight")
.setComment("Highlight the entire slot instead of just showing an icon for the recipe overlay")
.getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.slotHighlight", true));

tag.getTag("tools.handler_load_from_config").setComment("ADVANCED: Load handlers from config")
.getBooleanValue(false);
API.addOption(new OptionToggleButton("tools.handler_load_from_config", true) {
Expand Down Expand Up @@ -622,8 +619,12 @@ public static boolean areJEIStyleTabsVisible() {
return getBooleanSetting("inventory.jei_style_tabs");
}

public static boolean isJEIStyleItemPresenceOverlayVisible() {
return getBooleanSetting("inventory.jei_style_item_presence_overlay");
public static int itemPresenceOverlay() {
return getIntSetting("inventory.itemPresenceOverlay");
}

public static boolean isSlotHighlightPresent() {
return getBooleanSetting("inventory.slotHighlightPresent");
}

public static boolean areJEIStyleRecipeCatalystsVisible() {
Expand All @@ -650,10 +651,6 @@ public static boolean requireShiftForOverlayRecipe() {
return getBooleanSetting("inventory.shift_overlay_recipe");
}

public static boolean isSlotHighlightEnabled() {
return getBooleanSetting("inventory.slotHighlight");
}

public static boolean isEnabled() {
return enabledOverride && getBooleanSetting("inventory.widgetsenabled");
}
Expand Down
34 changes: 25 additions & 9 deletions src/main/java/codechicken/nei/guihook/GuiContainerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.recipe.StackInfo;
import codechicken.nei.util.ReadableNumberConverter;

public class GuiContainerManager {

Expand Down Expand Up @@ -269,17 +270,33 @@ public static void drawItem(int i, int j, ItemStack itemstack, FontRenderer font
boolean glRescale = GL11.glGetBoolean(GL12.GL_RESCALE_NORMAL);

float zLevel = drawItems.zLevel += 100F;
float scale = smallAmount ? 0.5f : 1f;

try {
drawItems.renderItemAndEffectIntoGUI(fontRenderer, renderEngine, itemstack, i, j);

if (stackSize == null) {
stackSize = itemstack.stackSize > 1 ? String.valueOf(itemstack.stackSize) : "";
if (itemstack.stackSize > 1) {
stackSize = ReadableNumberConverter.INSTANCE.toWideReadableForm(itemstack.stackSize);

if (stackSize.length() == 3) {
scale = 0.8f;
} else if (stackSize.length() == 4) {
scale = 0.6f;
} else if (stackSize.length() > 4) {
scale = 0.5f;
}

} else {
stackSize = "";
}

}

if (smallAmount) {
if (scale != 1f) {

if (!stackSize.isEmpty()) {
drawBigStackSize(i, j, stackSize);
drawBigStackSize(i, j, stackSize, scale);
}

// stackSize = "". it needed for correct draw item with alpha and blend
Expand Down Expand Up @@ -311,16 +328,15 @@ public static void drawItem(int i, int j, ItemStack itemstack, FontRenderer font
}

// copy from appeng.client.render.AppEngRenderItem
protected static void drawBigStackSize(int offsetX, int offsetY, String stackSize) {
final float scaleFactor = fontRenderer.getUnicodeFlag() ? 0.85f : 0.5f;
final float inverseScaleFactor = 1.0f / scaleFactor;
protected static void drawBigStackSize(int offsetX, int offsetY, String stackSize, float scale) {
final float inverseScaleFactor = 1.0f / scale;

enable2DRender();
GL11.glScaled(scaleFactor, scaleFactor, scaleFactor);
GL11.glScaled(scale, scale, scale);

final int X = (int) (((float) offsetX + 16.0f - fontRenderer.getStringWidth(stackSize) * scaleFactor)
final int X = (int) (((float) offsetX + 16.0f - fontRenderer.getStringWidth(stackSize) * scale)
* inverseScaleFactor);
final int Y = (int) (((float) offsetY + 16.0f - 7.0f * scaleFactor) * inverseScaleFactor);
final int Y = (int) (((float) offsetY + 16.0f - 7.0f * scale) * inverseScaleFactor);
fontRenderer.drawStringWithShadow(stackSize, X, Y, 16777215);

GL11.glScaled(inverseScaleFactor, inverseScaleFactor, inverseScaleFactor);
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/codechicken/nei/recipe/GuiRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,8 @@ public void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {

}

final boolean drawItemPresence = NEIClientConfig.isJEIStyleItemPresenceOverlayVisible();
final boolean slotHighlight = NEIClientConfig.isSlotHighlightEnabled();
final int presenceOverlay = NEIClientConfig.itemPresenceOverlay();
final boolean highlightPresentItem = NEIClientConfig.isSlotHighlightPresent();

GL11.glPushMatrix();
GL11.glTranslatef(5, 32 - ySkip + yShift, 0);
Expand All @@ -1023,7 +1023,7 @@ public void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {

handler.original.drawForeground(recipeIndex);

if (drawItemPresence && firstGui != null
if (presenceOverlay > 0 && firstGui != null
&& firstGui.inventorySlots != null
&& (isMouseOverOverlayButton(refIndex) || limitToOneRecipe)) {

Expand All @@ -1037,7 +1037,11 @@ public void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
for (int j = 0; j < ingredients.size(); j++) {
PositionedStack stack = ingredients.get(j);
boolean isPresent = itemPresenceCacheSlots.get(j);
LayoutManager.drawItemPresenceOverlay(stack.relx, stack.rely, isPresent, slotHighlight);

if (highlightPresentItem || !isPresent) {
LayoutManager
.drawItemPresenceOverlay(stack.relx, stack.rely, isPresent, presenceOverlay == 2);
}
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/main/resources/assets/nei/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ 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.jei_style_item_presence_overlay=JEI Style Item Overlay on ?-Hover
nei.options.inventory.jei_style_item_presence_overlay.true=Yes
nei.options.inventory.jei_style_item_presence_overlay.false=No
nei.options.inventory.itemPresenceOverlay=Item Overlay on ?-Hover
nei.options.inventory.itemPresenceOverlay.0=None
nei.options.inventory.itemPresenceOverlay.1=Icon
nei.options.inventory.itemPresenceOverlay.2=Background
nei.options.inventory.slotHighlightPresent=Highlight Present Item
nei.options.inventory.slotHighlightPresent.true=Yes
nei.options.inventory.slotHighlightPresent.false=No
nei.options.inventory.jei_style_recipe_catalyst=JEI Style Recipe Catalysts
nei.options.inventory.jei_style_recipe_catalyst.true=Yes
nei.options.inventory.jei_style_recipe_catalyst.false=No
Expand Down Expand Up @@ -190,9 +194,6 @@ nei.options.inventory.jei_style_cycled_ingredients.false=No
nei.options.inventory.shift_overlay_recipe=Require holding shift to move items when overlaying recipe
nei.options.inventory.shift_overlay_recipe.true=Yes
nei.options.inventory.shift_overlay_recipe.false=No
nei.options.inventory.slotHighlight=Highlight the entire slot instead of just showing an icon for the recipe overlay
nei.options.inventory.slotHighlight.true=Yes
nei.options.inventory.slotHighlight.false=No
nei.options.inventory.widgetsenabled.true=NEI Enabled
nei.options.inventory.widgetsenabled.false=NEI Disabled
nei.options.inventory.cheatmode.0=Recipe Mode
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/assets/nei/lang/zh_CN.lang
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ nei.options.inventory.bookmarksEnabled.false=隐藏
nei.options.inventory.jei_style_tabs=JEI标签页
nei.options.inventory.jei_style_tabs.true=是
nei.options.inventory.jei_style_tabs.false=否 [不会吧]
nei.options.inventory.jei_style_item_presence_overlay=JEI风格物品覆盖?-悬停
nei.options.inventory.jei_style_item_presence_overlay.true=是
nei.options.inventory.jei_style_item_presence_overlay.false=否
nei.options.inventory.jei_style_recipe_catalyst=JEI风格可执行合成表机器显示[测试中]
nei.options.inventory.jei_style_recipe_catalyst.true=是
nei.options.inventory.jei_style_recipe_catalyst.false=否
Expand Down

0 comments on commit 94676e0

Please sign in to comment.