From 8c72a302747debd42f80f6984de9db62a876589a Mon Sep 17 00:00:00 2001 From: BluSunrize Date: Wed, 1 May 2024 12:10:52 +0200 Subject: [PATCH] Fix buttons in the circuit table not behaving correctly with keyboard inputs, closes #5856 --- changelog.md | 1 + .../client/gui/CircuitTableScreen.java | 1 + .../gui/elements/GuiButtonLogicCircuitRegister.java | 8 +++++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 1d21d2a6b0..e104bf60b4 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,7 @@ - Change recipe for hempcrete to make it cheaper to mass produce (voidsong-dragonfly) - Fix covered conveyors crashing the game (BluSunrize) - Fix multiblocks being broken by flowing water (BluSunrize) +- Fix buttons in the circuit table not behaving correctly with keyboard inputs (BluSunrize) ##### Version 1.20.4-11.1.0-172 - First release for 1.20.4 diff --git a/src/main/java/blusunrize/immersiveengineering/client/gui/CircuitTableScreen.java b/src/main/java/blusunrize/immersiveengineering/client/gui/CircuitTableScreen.java index 8e0118b1f4..7466b98533 100644 --- a/src/main/java/blusunrize/immersiveengineering/client/gui/CircuitTableScreen.java +++ b/src/main/java/blusunrize/immersiveengineering/client/gui/CircuitTableScreen.java @@ -162,6 +162,7 @@ private void updateButtons() { int inputCount = operator.getArgumentCount(); int inputStart = 130-(inputCount*10-1); + this.inputButtons.forEach(this::removeWidget); this.inputButtons.clear(); for(int i = 0; i < inputCount; i++) this.inputButtons.add(this.addRenderableWidget(GuiButtonLogicCircuitRegister.create( diff --git a/src/main/java/blusunrize/immersiveengineering/client/gui/elements/GuiButtonLogicCircuitRegister.java b/src/main/java/blusunrize/immersiveengineering/client/gui/elements/GuiButtonLogicCircuitRegister.java index ec9cb39cde..2eff879858 100644 --- a/src/main/java/blusunrize/immersiveengineering/client/gui/elements/GuiButtonLogicCircuitRegister.java +++ b/src/main/java/blusunrize/immersiveengineering/client/gui/elements/GuiButtonLogicCircuitRegister.java @@ -95,9 +95,9 @@ public boolean charTyped(char codePoint, int modifiers) if(Character.isDigit(codePoint)) { int number = Character.digit(codePoint, 10); - if(number>=0 && number<8) + if(number >= 0&&number < 8) { - this.state.setValue(number+16); // plus 16 colors + this.state.setValue(number+15); // plus 15 colors, the final increment is done by onPress this.onPress.onPress(this); return true; } @@ -108,7 +108,9 @@ else if(Character.isAlphabetic(codePoint)) if(!options.isEmpty()) { int next = (options.indexOf(this.getStateAsInt())+1)%options.size(); - this.state.setValue(options.get(next)); + // subtract one because final increment is done by onPress + int stateIdx = Math.floorMod(options.get(next)-1, states.length); + this.state.setValue(stateIdx); this.onPress.onPress(this); return true; }