Skip to content

Commit

Permalink
Add Search Recipe Icon
Browse files Browse the repository at this point in the history
  • Loading branch information
slprime committed Jan 21, 2024
1 parent 06cdea3 commit b03ae51
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/main/java/codechicken/nei/BookmarkPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,7 @@ public void mouseUp(int mousex, int mousey, int button) {

this.mouseDownSlot = -1;
this.groupingItem = null;
grid.onItemsChanged(); /* make sure grid redraws the new item */
saveBookmarks();
} else {
super.mouseUp(mousex, mousey, button);
Expand Down
72 changes: 49 additions & 23 deletions src/main/java/codechicken/nei/recipe/GuiRecipe.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package codechicken.nei.recipe;

import static codechicken.lib.gui.GuiDraw.fontRenderer;
import static codechicken.nei.NEIClientUtils.translate;

import java.awt.Point;
import java.awt.Rectangle;
Expand Down Expand Up @@ -31,6 +30,7 @@
import org.lwjgl.opengl.GL11;

import codechicken.lib.gui.GuiDraw;
import codechicken.nei.Button;
import codechicken.nei.GuiNEIButton;
import codechicken.nei.LayoutManager;
import codechicken.nei.NEICPH;
Expand Down Expand Up @@ -248,6 +248,28 @@ public void onTextChange(String oldText) {

};

protected static Button toggleSearch = new Button() {

@Override
public boolean onButtonPress(boolean rightclick) {
if (rightclick) return false;

if (searchField.isVisible()) {
searchField.setText("");
searchField.setFocus(false);
searchField.setVisible(false);
state = 0;
} else {
searchField.setVisible(true);
searchField.setFocus(true);
state = 2;
}

return true;
}

};

/**
* This will only be true iff height hacking has been configured for the current recipe handler AND we are currently
* within the scope of an active {@link CompatibilityHacks} instance.
Expand Down Expand Up @@ -395,6 +417,9 @@ public void initGui() {
nextpage = new GuiNEIButton(2, leftButtonX, guiTop + 17, buttonWidth, buttonHeight, "<");
prevpage = new GuiNEIButton(3, rightButtonX, guiTop + 17, buttonWidth, buttonHeight, ">");

toggleSearch.icon = new DrawableBuilder("nei:textures/nei_sprites.png", 0, 38, 8, 8).setTextureSize(128, 128)
.build();

buttonList.addAll(Arrays.asList(nexttype, prevtype, nextpage, prevpage));

if (currenthandlers.size() == 1) {
Expand Down Expand Up @@ -484,6 +509,7 @@ public void setRecipePage(int idx, int recipe) {
if (!limitToOneRecipe) {
searchField.setText("");
searchField.setVisible(false);
toggleSearch.state = 0;
}

page = Math.min(Math.max(0, recipe), handler.numRecipes() - 1) / getRecipesPerPage();
Expand Down Expand Up @@ -648,19 +674,14 @@ public void keyTyped(char c, int i) {
protected void mouseClicked(int mousex, int mousey, int button) {

if (!limitToOneRecipe && handler != null && IRecipeFilterProvider.filteringAvailable(handler)) {
if (new Rectangle(borderPadding + buttonWidth - 2, 15, xSize - (borderPadding + buttonWidth) * 2 + 2, 16)
.contains(mousex - guiLeft, mousey - guiTop)) {
searchField.setVisible(true);
if (toggleSearch.contains(mousex - guiLeft, mousey - guiTop)) {
toggleSearch.handleClick(mousex - guiLeft, mousey - guiTop, button);
} else if (searchField.contains(mousex - guiLeft, mousey - guiTop)) {
searchField.handleClick(mousex - guiLeft, mousey - guiTop, button);
if (!searchField.focused()) {
searchField.setFocus(true);
}
} else {
searchField.onGuiClick(mousex - guiLeft, mousey - guiTop);
if (searchField.text().isEmpty() && !searchField.focused()) {
searchField.setVisible(false);
}
}

}

try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) {
Expand Down Expand Up @@ -753,14 +774,15 @@ public List<String> handleTooltip(GuiContainer gui, int mousex, int mousey, List
}
recipeTabs.handleTooltip(mousex, mousey, currenttip);

if (currenttip.isEmpty()
&& new Rectangle(borderPadding + buttonWidth - 2, 15, xSize - (borderPadding + buttonWidth) * 2 + 2, 16)
if (currenttip.isEmpty() && searchField.isVisible()
&& new Rectangle(searchField.x + searchField.w, 15, 44, 16)
.contains(mousex - guiLeft, mousey - guiTop)) {

if (!searchField.isVisible() && IRecipeFilterProvider.filteringAvailable(handler)) {
currenttip.add(translate("recipe.search.show"));
}
final String s = String.format("%d/%d", page + 1, (handler.numRecipes() - 1) / getRecipesPerPage() + 1);

if (fontRendererObj.getStringWidth(s) >= 45) {
currenttip.add(s);
}
}

return currenttip;
Expand Down Expand Up @@ -845,9 +867,13 @@ public void refreshPage() {
checkYShift();

if (!limitToOneRecipe) {
toggleSearch.w = toggleSearch.h = 12;
toggleSearch.x = borderPadding + buttonWidth;
toggleSearch.y = 17;

searchField.y = 16;
searchField.x = borderPadding + buttonWidth - 2;
searchField.w = xSize - (borderPadding + buttonWidth) * 2 + 1 - 45;
searchField.x = borderPadding + buttonWidth + toggleSearch.w - 1;
searchField.w = xSize - (borderPadding + buttonWidth) * 2 + 1 - toggleSearch.w - 45;
searchField.h = 14;
}

Expand Down Expand Up @@ -940,7 +966,11 @@ public void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
String s = handler.getRecipeName().trim();
fontRendererObj.drawStringWithShadow(s, (xSize - fontRendererObj.getStringWidth(s)) / 2, 5, 0xffffff);

if (!limitToOneRecipe && searchField.isVisible()) {
if (IRecipeFilterProvider.filteringAvailable(handler)) {
toggleSearch.draw(mouseX - guiLeft, mouseY - guiTop);
}

if (searchField.isVisible()) {
searchField.draw(mouseX - guiLeft, mouseY - guiTop);
s = NEIClientUtils.cropText(
fontRendererObj,
Expand Down Expand Up @@ -1143,10 +1173,7 @@ public List<TaggedInventoryArea> getInventoryAreas(GuiContainer gui) {
@Override
public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button) {

if (!limitToOneRecipe && handler != null
&& new Rectangle(borderPadding + buttonWidth - 2, 15, xSize - (borderPadding + buttonWidth) * 2 + 2, 16)
.contains(mousex - guiLeft, mousey - guiTop)
&& IRecipeFilterProvider.filteringAvailable(handler)) {
if (searchField.isVisible() && searchField.contains(mousex - guiLeft, mousey - guiTop)) {
final FluidStack fluidStack = StackInfo.getFluid(draggedStack);

if (fluidStack != null) {
Expand All @@ -1155,7 +1182,6 @@ && new Rectangle(borderPadding + buttonWidth - 2, 15, xSize - (borderPadding + b
searchField.setText(formattingText(draggedStack.getDisplayName()));
}

searchField.setVisible(true);
return true;
}

Expand Down
1 change: 0 additions & 1 deletion src/main/resources/assets/nei/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ nei.options.tools.dump.handlers.mode.1=Json

nei.recipe.page=Page %s/%s
nei.recipe.tooltip=Recipes
nei.recipe.search.show=Click to Search
nei.recipe.shaped=Shaped Crafting
nei.recipe.shapeless=Shapeless Crafting
nei.recipe.furnace=Smelting
Expand Down
Binary file modified src/main/resources/assets/nei/textures/nei_sprites.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b03ae51

Please sign in to comment.