[BugFix] Keybinding not working

This commit is contained in:
xiaozhou233 committed 2026-01-19 14:56:24 +08:00
1 parent 634f6fd34f
commit f689847f1e
4 files changed
+34 -2

No files matched your search

@@ -1,5 +1,7 @@
package cn.xiaozhou233.orangex.ui.clickgui.component;
import cn.xiaozhou233.orangex.ui.clickgui.component.impl.ModuleButton;
import cn.xiaozhou233.orangex.ui.clickgui.panel.Panel;
import lombok.Getter;
import lombok.Setter;
@@ -56,4 +58,11 @@ public abstract class Component {
return parent == null ? y : parent.getAbsoluteY() + y;
}
protected void setParent(Panel panel) {
this.parent = parent;
}
public void setParent(Component parent) {
this.parent = parent;
}
}
@@ -5,6 +5,7 @@ import cn.xiaozhou233.orangex.ui.clickgui.component.Component;
import cn.xiaozhou233.orangex.ui.clickgui.component.ValueComponent;
import cn.xiaozhou233.orangex.ui.clickgui.render.GuiRenderUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.GameSettings;
public class KeybindComponent extends ValueComponent {
@@ -29,7 +30,7 @@ public class KeybindComponent extends ValueComponent {
GuiRenderUtils.enableBlend();
GuiRenderUtils.drawRect(ax, ay, width, height, bgColor);
String keyName = listening ? "Press a key..." : Minecraft.getMinecraft().gameSettings.getKeyDisplayString(value.getValue());
String keyName = listening ? "Press a key..." : GameSettings.getKeyDisplayString(value.getValue());
GuiRenderUtils.drawString(value.getName() + ": " + keyName, ax + 6, ay + 4, 0xFFFFFFFF);
GuiRenderUtils.disableBlend();
}
@@ -47,6 +48,8 @@ public class KeybindComponent extends ValueComponent {
public void keyTyped(char typedChar, int keyCode) {
if (!listening) return;
System.out.println("KeyTyped triggered: " + keyCode); // 用来测试
if (keyCode == 1) {
listening = false;
return;
@@ -57,6 +60,7 @@ public class KeybindComponent extends ValueComponent {
applyValue();
}
@Override
public void applyValue() {
// no-op
@@ -69,7 +69,6 @@ public class ModuleButton extends Component {
@Override
public void mouseClicked(int mouseX, int mouseY, int button) {
if (expanded) {
for (Component component : components) {
if (component.isHovered(mouseX, mouseY)) {
@@ -95,7 +94,17 @@ public class ModuleButton extends Component {
}
}
@Override
public void keyTyped(char typedChar, int keyCode) {
if (!expanded) return;
for (Component component : components) {
component.keyTyped(typedChar, keyCode);
}
}
public void addComponent(Component component) {
component.setParent(this);
components.add(component);
}
}
@@ -124,7 +124,17 @@ public class Panel extends Component {
}
public void addComponent(Component component) {
component.setParent(this);
components.add(component);
}
@Override
public void keyTyped(char typedChar, int keyCode) {
super.keyTyped(typedChar, keyCode);
for (Component c : components) {
c.keyTyped(typedChar, keyCode);
}
}
}