Skip to content

Fix Bedrock Anvil text field focus #392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.dafuqs.spectrum.inventories;

import com.mojang.blaze3d.systems.*;
import de.dafuqs.spectrum.*;
import de.dafuqs.spectrum.helpers.*;
import de.dafuqs.spectrum.networking.*;
Expand Down Expand Up @@ -50,7 +49,6 @@ protected void setup() {
int j = (this.height - this.backgroundHeight) / 2;

this.nameField = new TextFieldWidget(this.textRenderer, i + 62, j + 24, 98, 12, Text.translatable("container.spectrum.bedrock_anvil"));
this.nameField.setFocusUnlocked(false);
this.nameField.setEditableColor(-1);
this.nameField.setUneditableColor(-1);
this.nameField.setDrawsBackground(false);
Expand All @@ -60,7 +58,6 @@ protected void setup() {
this.addSelectableChild(this.nameField);

this.loreField = new TextFieldWidget(this.textRenderer, i + 45, j + 76, 116, 12, Text.translatable("container.spectrum.bedrock_anvil.lore"));
this.loreField.setFocusUnlocked(false);
this.loreField.setEditableColor(-1);
this.loreField.setUneditableColor(-1);
this.loreField.setDrawsBackground(false);
Expand All @@ -86,23 +83,21 @@ public void resize(MinecraftClient client, int width, int height) {

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == 256) {
this.client.player.closeHandledScreen();
if (keyCode == GLFW.GLFW_KEY_ESCAPE) {
this.close();
return true;
}

if (keyCode == GLFW.GLFW_KEY_TAB) {
Element focusedElement = getFocused();
if (focusedElement == this.nameField) {
this.nameField.setFocused(false);
setFocused(this.loreField);
} else if (focusedElement == this.loreField) {
this.loreField.setFocused(false);
setFocused(this.nameField);
}
Element focusedElement = this.getFocused();
if (focusedElement == this.nameField)
this.setFocused(this.loreField);
else if (focusedElement == this.loreField)
this.setFocused(this.nameField);
return true;
}

return this.nameField.keyPressed(keyCode, scanCode, modifiers) || this.nameField.isActive()
|| this.loreField.keyPressed(keyCode, scanCode, modifiers) || this.loreField.isActive()

return (this.getFocused() != null && this.getFocused().keyPressed(keyCode, scanCode, modifiers))
|| super.keyPressed(keyCode, scanCode, modifiers);
}

Expand Down Expand Up @@ -199,5 +194,5 @@ public void onSlotUpdate(ScreenHandler handler, int slotId, ItemStack stack) {
this.setFocused(this.nameField);
}
}

}
Loading