From f51f6032ca074fb0450d112b4dceb0676d76496d Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Thu, 5 Nov 2020 15:41:40 +0100 Subject: [PATCH] Use empty hotkey button when key is unbound across all versions This happened to already be the case in 1.16.3 (because of another bug), this commit makes it intentional and consistent across all versions. Using the empty label over NONE or another label because it doesn't change the width of the button and therefore fits nicer with all the other buttons. --- src/main/java/com/replaymod/core/KeyBindingRegistry.java | 8 ++++++++ src/main/java/com/replaymod/extras/HotkeyButtons.java | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/replaymod/core/KeyBindingRegistry.java b/src/main/java/com/replaymod/core/KeyBindingRegistry.java index f89e4eec..7ddbc78f 100644 --- a/src/main/java/com/replaymod/core/KeyBindingRegistry.java +++ b/src/main/java/com/replaymod/core/KeyBindingRegistry.java @@ -185,6 +185,14 @@ public class KeyBindingRegistry extends EventRegistrations { return MCVer.getBoundKey(keyBinding); } + public boolean isBound() { + //#if MC>=11400 + return !keyBinding.isUnbound(); + //#else + //$$ return keyBinding.getKeyCode() != 0; + //#endif + } + public void trigger() { KeyBindingAccessor acc = (KeyBindingAccessor) keyBinding; acc.setPressTime(acc.getPressTime() + 1); diff --git a/src/main/java/com/replaymod/extras/HotkeyButtons.java b/src/main/java/com/replaymod/extras/HotkeyButtons.java index 49324f50..6ca9aeec 100644 --- a/src/main/java/com/replaymod/extras/HotkeyButtons.java +++ b/src/main/java/com/replaymod/extras/HotkeyButtons.java @@ -73,7 +73,7 @@ public class HotkeyButtons extends EventRegistrations implements Extra { @Override public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { // There doesn't seem to be an KeyBindingUpdate event, so we'll just update it every time - setLabel(keyBinding.getBoundKey()); + setLabel(keyBinding.isBound() ? keyBinding.getBoundKey() : ""); super.draw(renderer, size, renderInfo); } }.onClick(keyBinding::trigger);