Skip to content

Commit

Permalink
fix(bio-forge): fix inability to (un-)focus the search box via mouse …
Browse files Browse the repository at this point in the history
…click
  • Loading branch information
Elenterius committed Jan 21, 2024
1 parent 1f7fa9a commit b32a997
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ protected void init() {
searchInput.setTextColor(ColorStyles.TEXT_ACCENT_FORGE);

recipeBook = new BioForgeScreenController(minecraft, menu);

//minecraft.keyboardHandler.setSendRepeatsToGui(true);
}

@Override
public void removed() {
//minecraft.keyboardHandler.setSendRepeatsToGui(false);
}

public void onRecipeBookUpdated() {
Expand All @@ -86,7 +79,13 @@ protected void slotClicked(Slot slot, int slotId, int mouseButton, ClickType typ

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (searchInput.mouseClicked(mouseX, mouseY, button)) return true;
if (searchInput.mouseClicked(mouseX, mouseY, button)) {
searchInput.setFocused(true);
return true;
}
else {
searchInput.setFocused(false);
}

if (recipeBook.hasRecipesOnPage()) {
int recipes = recipeBook.getMaxRecipesOnGrid();
Expand Down Expand Up @@ -134,7 +133,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return true;
}

if (Objects.requireNonNull(minecraft).options.keyChat.matches(keyCode, scanCode) && !searchInput.isFocused()) {
if (minecraft.options.keyChat.matches(keyCode, scanCode) && !searchInput.isFocused()) {
ignoreTextInput = true;
searchInput.setFocused(true);
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.github.elenterius.biomancy.client.gui.component;

import com.github.elenterius.biomancy.util.ComponentUtil;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.FormattedText;

/**
* disables the drawing of the background but keeps the paddings/margins intact
*/
public class CustomEditBox extends EditBox {

private FormattedText hint = FormattedText.EMPTY;
private Component hint = ComponentUtil.empty();
private final Font font;
private boolean isBackgroundDisabled = false;

Expand All @@ -34,7 +34,7 @@ public void setBordered(boolean enableBackgroundDrawing) {
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
if (visible) {
if (!isFocused() && getValue().isEmpty()) {
guiGraphics.drawString(font, hint.getString(), getX() + 4, getY() + (height - 8) / 2, -1);
guiGraphics.drawString(font, hint, getX() + 4, getY() + (height - 8) / 2, 0xff_ffffff);
}
else super.render(guiGraphics, mouseX, mouseY, partialTick);
}
Expand Down

0 comments on commit b32a997

Please sign in to comment.