mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
Feat: add KeybindComponent for keybind editing, fix StringComponent overflow
- Create KeybindComponent (extends OptionComponent) for editing module keybinds - Click to enter listening mode, press key to bind, DELETE to clear, ESC to cancel - Display 'NONE' when no key is bound - Add KeybindComponent to ModuleButton options list (bottom of expanded settings) - Remove keybind display from ModuleButton main area (moved to options) - Fix StringComponent value text overflowing component bounds - Truncate with '...' when value exceeds 50px available width
This commit is contained in:
1 parent
6c68130a4f
commit
4c8e1ae378
3 files changed
+92
-12
No files matched your search
+3
-11
@@ -5,10 +5,10 @@ import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.option.Option;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.Component;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.option.KeybindComponent;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.option.OptionComponent;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.option.OptionComponentFactory;
|
||||
import lombok.Getter;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -43,6 +43,8 @@ public class ModuleButton extends Component {
|
||||
|
||||
optionY += 18;
|
||||
}
|
||||
|
||||
options.add(new KeybindComponent(parent, module, offsetX, offsetY + optionY));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,16 +60,6 @@ public class ModuleButton extends Component {
|
||||
color
|
||||
);
|
||||
|
||||
if (module.getKey() != Keyboard.KEY_NONE) {
|
||||
String keyName = Keyboard.getKeyName(module.getKey());
|
||||
int keyX = getX() + width - 5 -
|
||||
(int) OrangeX.getInstance()
|
||||
.getStbFontManager()
|
||||
.getProxima(18)
|
||||
.getStringWidth(keyName);
|
||||
drawString(keyName, keyX, getY() + 5, 0xff555555);
|
||||
}
|
||||
|
||||
if (expanded) {
|
||||
for (OptionComponent option : options) {
|
||||
option.drawScreen(mouseX, mouseY, partialTicks);
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class KeybindComponent extends OptionComponent {
|
||||
|
||||
private final Module module;
|
||||
private boolean listening;
|
||||
|
||||
public KeybindComponent(Panel parent, Module module, int offsetX, int offsetY) {
|
||||
super(parent, null, offsetX, offsetY, 120, 16);
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
drawString("Keybind", getX() + 4, getY() + 4, 0xffffffff);
|
||||
|
||||
String keyName;
|
||||
if (listening) {
|
||||
keyName = "...";
|
||||
} else {
|
||||
keyName = module.getKey() != Keyboard.KEY_NONE
|
||||
? Keyboard.getKeyName(module.getKey()) : "NONE";
|
||||
}
|
||||
|
||||
int keyX = getX() + width - 4 -
|
||||
(int) OrangeX.getInstance()
|
||||
.getStbFontManager()
|
||||
.getProxima(18)
|
||||
.getStringWidth(keyName);
|
||||
int keyColor = listening ? 0xff55ffff : 0xffaaaaaa;
|
||||
drawString(keyName, keyX, getY() + 4, keyColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (!isHovered(mouseX, mouseY)) return;
|
||||
if (mouseButton == 0) {
|
||||
listening = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
if (!listening) return;
|
||||
|
||||
if (keyCode == 1) {
|
||||
listening = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (keyCode == Keyboard.KEY_DELETE) {
|
||||
module.setKey(Keyboard.KEY_NONE);
|
||||
listening = false;
|
||||
return;
|
||||
}
|
||||
|
||||
module.setKey(keyCode);
|
||||
listening = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY, int mouseButton) {
|
||||
}
|
||||
}
|
||||
+20
-1
@@ -1,5 +1,6 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component.option;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.module.option.impl.StringOption;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.Panel;
|
||||
|
||||
@@ -38,9 +39,27 @@ public class StringComponent extends OptionComponent {
|
||||
value += "_";
|
||||
|
||||
|
||||
int maxValueWidth = 50;
|
||||
int valueWidth = (int) OrangeX.getInstance()
|
||||
.getStbFontManager()
|
||||
.getProxima(18)
|
||||
.getStringWidth(value);
|
||||
|
||||
if (valueWidth > maxValueWidth) {
|
||||
while ((int) OrangeX.getInstance()
|
||||
.getStbFontManager()
|
||||
.getProxima(18)
|
||||
.getStringWidth(value + "...") > maxValueWidth
|
||||
&& value.length() > 0) {
|
||||
value = value.substring(0, value.length() - 1);
|
||||
}
|
||||
value += "...";
|
||||
}
|
||||
|
||||
|
||||
drawString(
|
||||
value,
|
||||
getX() + width - 50,
|
||||
getX() + width - 5 - maxValueWidth,
|
||||
getY() + 5,
|
||||
typing
|
||||
? 0xff55ffff
|
||||
|
||||
Reference in new issue
Block a user