Skip to content

Commit

Permalink
Added separate overlay draw call to IRecipeLayoutDrawable
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Jul 30, 2017
1 parent 70c1b04 commit 3452328
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 78 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -5,4 +5,4 @@ curse_project_id=238222

version_major=4
version_minor=7
version_patch=3
version_patch=4
20 changes: 18 additions & 2 deletions src/api/java/mezz/jei/api/gui/IRecipeLayoutDrawable.java
Expand Up @@ -21,9 +21,16 @@ public interface IRecipeLayoutDrawable extends IRecipeLayout {
void setPosition(int posX, int posY);

/**
* Draw the recipe layout.
* Draw the recipe without overlays such as item tool tips.
* @since JEI 4.7.4
*/
void draw(Minecraft minecraft, int mouseX, int mouseY);
void drawRecipe(Minecraft minecraft, int mouseX, int mouseY);

/**
* Draw the recipe overlays such as item tool tips.
* @since JEI 4.7.4
*/
void drawOverlays(Minecraft minecraft, int mouseX, int mouseY);

/**
* Returns true if the mouse is hovering over the recipe.
Expand All @@ -37,4 +44,13 @@ public interface IRecipeLayoutDrawable extends IRecipeLayout {
*/
@Nullable
Object getIngredientUnderMouse(int mouseX, int mouseY);

// DEPRECATED BELOW

/**
* Draw the recipe layout.
* @deprecated since JEI 4.7.4, use {@link #drawRecipe(Minecraft, int, int)} and {@link #drawOverlays(Minecraft, int, int)}
*/
@Deprecated
void draw(Minecraft minecraft, int mouseX, int mouseY);
}
32 changes: 15 additions & 17 deletions src/main/java/mezz/jei/gui/ingredients/GuiIngredient.java
@@ -1,13 +1,5 @@
package mezz.jei.gui.ingredients;

import javax.annotation.Nullable;
import java.awt.Color;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import mezz.jei.Internal;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IGuiIngredient;
Expand All @@ -28,6 +20,14 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;

import javax.annotation.Nullable;
import java.awt.Color;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class GuiIngredient<T> extends Gui implements IGuiIngredient<T> {
private static final String oreDictionaryIngredient = Translator.translateToLocal("jei.tooltip.recipe.ore.dict");

Expand Down Expand Up @@ -138,15 +138,6 @@ public void draw(Minecraft minecraft, int xOffset, int yOffset) {
ingredientRenderer.render(minecraft, xOffset + rect.x + xPadding, yOffset + rect.y + yPadding, value);
}

public void drawHovered(Minecraft minecraft, int xOffset, int yOffset, int mouseX, int mouseY) {
draw(minecraft, xOffset, yOffset);

T value = getDisplayedIngredient();
if (value != null) {
drawTooltip(minecraft, xOffset, yOffset, mouseX, mouseY, value);
}
}

@Override
public void drawHighlight(Minecraft minecraft, Color color, int xOffset, int yOffset) {
int x = rect.x + xOffset + xPadding;
Expand All @@ -157,6 +148,13 @@ public void drawHighlight(Minecraft minecraft, Color color, int xOffset, int yOf
GlStateManager.color(1f, 1f, 1f, 1f);
}

public void drawOverlays(Minecraft minecraft, int xOffset, int yOffset, int mouseX, int mouseY) {
T value = getDisplayedIngredient();
if (value != null) {
drawTooltip(minecraft, xOffset, yOffset, mouseX, mouseY, value);
}
}

private void drawTooltip(Minecraft minecraft, int xOffset, int yOffset, int mouseX, int mouseY, T value) {
try {
GlStateManager.disableDepth();
Expand Down
43 changes: 25 additions & 18 deletions src/main/java/mezz/jei/gui/ingredients/GuiIngredientGroup.java
@@ -1,15 +1,5 @@
package mezz.jei.gui.ingredients;

import javax.annotation.Nullable;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import mezz.jei.Internal;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IGuiIngredientGroup;
Expand All @@ -24,6 +14,17 @@
import mezz.jei.util.Log;
import net.minecraft.client.Minecraft;

import javax.annotation.Nullable;
import java.awt.Color;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class GuiIngredientGroup<T> implements IGuiIngredientGroup<T> {
private final Map<Integer, GuiIngredient<T>> guiIngredients = new HashMap<>();
private final Set<Integer> inputSlots = new HashSet<>();
Expand Down Expand Up @@ -160,17 +161,23 @@ public T getIngredientUnderMouse(int xOffset, int yOffset, int mouseX, int mouse
}

@Nullable
public GuiIngredient<T> draw(Minecraft minecraft, int xOffset, int yOffset, int mouseX, int mouseY) {
GuiIngredient<T> hovered = null;
public GuiIngredient<T> getHoveredIngredient(int xOffset, int yOffset, int mouseX, int mouseY) {
for (GuiIngredient<T> ingredient : guiIngredients.values()) {
if (hovered == null && ingredient.isMouseOver(xOffset, yOffset, mouseX, mouseY)) {
hovered = ingredient;
hovered.setTooltipCallback(tooltipCallback);
} else {
ingredient.draw(minecraft, xOffset, yOffset);
if (ingredient.isMouseOver(xOffset, yOffset, mouseX, mouseY)) {
return ingredient;
}
}
return null;
}

public void draw(Minecraft minecraft, int xOffset, int yOffset, Color highlightColor, int mouseX, int mouseY) {
for (GuiIngredient<T> ingredient : guiIngredients.values()) {
ingredient.draw(minecraft, xOffset, yOffset);
if (ingredient.isMouseOver(xOffset, yOffset, mouseX, mouseY)) {
ingredient.setTooltipCallback(tooltipCallback);
ingredient.drawHighlight(minecraft, highlightColor, xOffset, yOffset);
}
}
return hovered;
}

@Override
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/mezz/jei/gui/recipes/RecipeCatalysts.java
@@ -1,11 +1,5 @@
package mezz.jei.gui.recipes;

import javax.annotation.Nullable;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import mezz.jei.Internal;
import mezz.jei.api.IGuiHelper;
import mezz.jei.api.gui.IDrawable;
Expand All @@ -22,6 +16,12 @@
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;

import javax.annotation.Nullable;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* The area drawn on left side of the {@link RecipesGui} that shows which items can craft the current recipe category.
*/
Expand Down Expand Up @@ -116,9 +116,8 @@ public GuiIngredient draw(Minecraft minecraft, int mouseX, int mouseY) {
for (GuiIngredient guiIngredient : this.ingredients) {
if (guiIngredient.isMouseOver(0, 0, mouseX, mouseY)) {
hovered = guiIngredient;
} else {
guiIngredient.draw(minecraft, 0, 0);
}
guiIngredient.draw(minecraft, 0, 0);
}
return hovered;
}
Expand Down
56 changes: 42 additions & 14 deletions src/main/java/mezz/jei/gui/recipes/RecipeLayout.java
@@ -1,12 +1,5 @@
package mezz.jei.gui.recipes;

import javax.annotation.Nullable;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;

import mezz.jei.Internal;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IGuiFluidStackGroup;
Expand All @@ -31,6 +24,14 @@
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;

import javax.annotation.Nullable;
import java.awt.Color;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;

public class RecipeLayout implements IRecipeLayoutDrawable {
private static final int RECIPE_BUTTON_SIZE = 13;
public static final int recipeTransferButtonIndex = 100;
Expand All @@ -45,6 +46,7 @@ public class RecipeLayout implements IRecipeLayoutDrawable {
private final IRecipeWrapper recipeWrapper;
@Nullable
private final IFocus<?> focus;
private final Color highlightColor = new Color(0x7FFFFFFF, true);
@Nullable
private ShapelessIcon shapelessIcon;

Expand Down Expand Up @@ -120,6 +122,12 @@ public void setPosition(int posX, int posY) {

@Override
public void draw(Minecraft minecraft, final int mouseX, final int mouseY) {
drawRecipe(minecraft, mouseX, mouseY);
drawOverlays(minecraft, mouseX, mouseY);
}

@Override
public void drawRecipe(Minecraft minecraft, int mouseX, int mouseY) {
IDrawable background = recipeCategory.getBackground();

GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
Expand All @@ -143,24 +151,44 @@ public void draw(Minecraft minecraft, final int mouseX, final int mouseY) {
}
GlStateManager.popMatrix();

GuiIngredient hoveredIngredient = null;
for (GuiIngredientGroup guiIngredientGroup : guiIngredientGroups.values()) {
GuiIngredient hovered = guiIngredientGroup.draw(minecraft, posX, posY, mouseX, mouseY);
if (hovered != null) {
hoveredIngredient = hovered;
}
guiIngredientGroup.draw(minecraft, posX, posY, highlightColor, mouseX, mouseY);
}
if (recipeTransferButton != null) {
float partialTicks = minecraft.getRenderPartialTicks();
recipeTransferButton.drawButton(minecraft, mouseX, mouseY, partialTicks);
}
GlStateManager.disableBlend();
GlStateManager.disableLighting();
GlStateManager.disableAlpha();
}

@Override
public void drawOverlays(Minecraft minecraft, int mouseX, int mouseY) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableLighting();
GlStateManager.enableAlpha();

final int recipeMouseX = mouseX - posX;
final int recipeMouseY = mouseY - posY;

GuiIngredient hoveredIngredient = null;
for (GuiIngredientGroup guiIngredientGroup : guiIngredientGroups.values()) {
hoveredIngredient = guiIngredientGroup.getHoveredIngredient(posX, posY, mouseX, mouseY);
if (hoveredIngredient != null) {
break;
}
}
if (recipeTransferButton != null) {
recipeTransferButton.drawToolTip(minecraft, mouseX, mouseY);
}
GlStateManager.disableBlend();
GlStateManager.disableLighting();

if (hoveredIngredient != null) {
hoveredIngredient.drawHovered(minecraft, posX, posY, recipeMouseX, recipeMouseY);
hoveredIngredient.drawOverlays(minecraft, posX, posY, recipeMouseX, recipeMouseY);
} else if (isMouseOver(mouseX, mouseY)) {
List<String> tooltipStrings = new ArrayList<>();
List<String> tooltipStrings = new ArrayList<String>();
List<String> categoryTooltipStrings = LegacyUtil.getTooltipStrings(recipeCategory, recipeMouseX, recipeMouseY);
tooltipStrings.addAll(categoryTooltipStrings);
List<String> wrapperTooltips = recipeWrapper.getTooltipStrings(recipeMouseX, recipeMouseY);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/mezz/jei/gui/recipes/RecipeTransferButton.java
Expand Up @@ -40,9 +40,7 @@ public void init(@Nullable Container container, EntityPlayer player) {
}
}

@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
super.drawButton(mc, mouseX, mouseY, partialTicks);
public void drawToolTip(Minecraft mc, int mouseX, int mouseY) {
if (hovered && visible) {
if (recipeTransferError != null) {
recipeTransferError.showError(mc, mouseX, mouseY, recipeLayout, recipeLayout.getPosX(), recipeLayout.getPosY());
Expand Down
29 changes: 14 additions & 15 deletions src/main/java/mezz/jei/gui/recipes/RecipesGui.java
@@ -1,11 +1,5 @@
package mezz.jei.gui.recipes;

import javax.annotation.Nullable;
import java.awt.Color;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import mezz.jei.Internal;
import mezz.jei.api.IRecipeRegistry;
import mezz.jei.api.IRecipesGui;
Expand Down Expand Up @@ -41,6 +35,12 @@
import net.minecraftforge.fml.client.config.HoverChecker;
import org.lwjgl.input.Mouse;

import javax.annotation.Nullable;
import java.awt.Color;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class RecipesGui extends GuiScreen implements IRecipesGui, IShowsRecipeFocuses, IRecipeLogicStateListener {
private static final int borderPadding = 6;
private static final int innerPadding = 5;
Expand Down Expand Up @@ -200,24 +200,23 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
nextPage.drawButton(mc, mouseX, mouseY, partialTicks);
previousPage.drawButton(mc, mouseX, mouseY, partialTicks);

RecipeLayout hovered = null;
RecipeLayout hoveredLayout = null;
for (RecipeLayout recipeLayout : recipeLayouts) {
if (recipeLayout.isMouseOver(mouseX, mouseY)) {
hovered = recipeLayout;
} else {
recipeLayout.draw(mc, mouseX, mouseY);
hoveredLayout = recipeLayout;
}
recipeLayout.drawRecipe(mc, mouseX, mouseY);
}

GuiIngredient hoveredItemStack = recipeCatalysts.draw(mc, mouseX, mouseY);
GuiIngredient hoveredRecipeCatalyst = recipeCatalysts.draw(mc, mouseX, mouseY);

recipeGuiTabs.draw(mc, mouseX, mouseY);

if (hovered != null) {
hovered.draw(mc, mouseX, mouseY);
if (hoveredLayout != null) {
hoveredLayout.drawOverlays(mc, mouseX, mouseY);
}
if (hoveredItemStack != null) {
hoveredItemStack.drawHovered(mc, 0, 0, mouseX, mouseY);
if (hoveredRecipeCatalyst != null) {
hoveredRecipeCatalyst.drawOverlays(mc, 0, 0, mouseX, mouseY);
}

if (titleHoverChecker.checkHover(mouseX, mouseY) && !logic.hasAllCategories()) {
Expand Down

0 comments on commit 3452328

Please sign in to comment.