From 8fe2abe0aec53a40d9e68b8390652a5e4e530e83 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Fri, 21 Jun 2019 20:31:28 +0100 Subject: [PATCH] Forward tab key directly to the terminal Fixes #256 --- .../computercraft/client/gui/GuiComputer.java | 13 +++++++++++++ .../dan200/computercraft/client/gui/GuiTurtle.java | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java index 159aba7c0..13a01b0ce 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java @@ -20,6 +20,7 @@ import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.ITextComponent; +import org.lwjgl.glfw.GLFW; public final class GuiComputer extends ContainerScreen { @@ -109,6 +110,18 @@ public void tick() terminal.update(); } + @Override + public boolean keyPressed( int key, int scancode, int modifiers ) + { + // Forward the tab key to the terminal, rather than moving between controls. + if( key == GLFW.GLFW_KEY_TAB && getFocused() != null && getFocused() == terminalWrapper ) + { + return getFocused().keyPressed( key, scancode, modifiers ); + } + + return super.keyPressed( key, scancode, modifiers ); + } + @Override public void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY ) { diff --git a/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java b/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java index 98ec8b647..7e80b05aa 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java @@ -17,6 +17,7 @@ import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.ITextComponent; +import org.lwjgl.glfw.GLFW; public class GuiTurtle extends ContainerScreen { @@ -80,6 +81,18 @@ public void tick() terminal.update(); } + @Override + public boolean keyPressed( int key, int scancode, int modifiers ) + { + // Forward the tab key to the terminal, rather than moving between controls. + if( key == GLFW.GLFW_KEY_TAB && getFocused() != null && getFocused() == terminalWrapper ) + { + return getFocused().keyPressed( key, scancode, modifiers ); + } + + return super.keyPressed( key, scancode, modifiers ); + } + private void drawSelectionSlot( boolean advanced ) { // Draw selection slot