config for keybidnings

This commit is contained in:
2025-06-17 11:42:19 -05:00
parent 5b77ea7363
commit d178f1504b
4 changed files with 63 additions and 0 deletions
@@ -1,5 +1,6 @@
package org.saturnclient.modules.mods;
import org.lwjgl.glfw.GLFW;
import org.saturnclient.modules.HudMod;
import org.saturnclient.modules.ModDimensions;
import org.saturnclient.modules.Module;
@@ -14,6 +15,7 @@ import net.minecraft.item.Items;
public class ArmorDisplay extends Module implements HudMod {
private static Property<Boolean> enabled = Property.bool(true);
private static Property<Integer> test = Property.keybinding(GLFW.GLFW_KEY_Y);
private static ModDimensions dimensions = new ModDimensions(40, 60);
public ArmorDisplay() {
@@ -22,9 +24,17 @@ public class ArmorDisplay extends Module implements HudMod {
.version("v0.1.0")
.tags("Utility"),
enabled.named("Enabled"),
test.named("Test key"),
dimensions.prop());
}
@Override
public void tick() {
if (test.isKeyPressed()) {
}
}
public void renderArmor(RenderScope scope, ItemStack helmet, ItemStack chestplate, ItemStack leggings, ItemStack boots) {
int row = 0;
@@ -2,6 +2,9 @@ package org.saturnclient.saturnclient.config;
import java.util.Map;
import org.lwjgl.glfw.GLFW;
import org.saturnclient.saturnclient.SaturnClient;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
@@ -15,6 +18,7 @@ public class Property<T> {
HEX,
NAMESPACE,
SELECT,
KEYBINDING,
}
public T value;
@@ -79,6 +83,10 @@ public class Property<T> {
return new Property<>(value, PropertyType.HEX);
}
public static Property<Integer> keybinding(int value) {
return new Property<>(value, PropertyType.KEYBINDING);
}
public void next() {
if ((Integer) value < availableValues.length-1) setValue((Integer)value+1);
else setValue(0);
@@ -186,4 +194,8 @@ public class Property<T> {
public NamedProperty<T> named(String name) {
return new NamedProperty<>(name, this);
}
public boolean isKeyPressed() {
return GLFW.glfwGetKey(SaturnClient.client.getWindow().getHandle(), (Integer) (Object) value) == GLFW.GLFW_PRESS;
}
}
@@ -0,0 +1,36 @@
package org.saturnclient.ui2.components.inputs;
import org.lwjgl.glfw.GLFW;
import org.saturnclient.saturnclient.config.Property;
import org.saturnclient.saturnclient.config.ThemeManager;
import org.saturnclient.ui2.Element;
import org.saturnclient.ui2.ElementContext;
import org.saturnclient.ui2.RenderScope;
import org.saturnclient.ui2.resources.Fonts;
public class KeybindingSelector extends Element {
private static ThemeManager theme = new ThemeManager("Input");
private static Property<Integer> font = theme.property("font", Property.font(1));
Property<Integer> prop;
public KeybindingSelector(Property<Integer> prop) {
this.prop = prop;
this.width = 120;
this.height = Fonts.getHeight();
}
@Override
public void render(RenderScope renderScope, ElementContext ctx) {
int textColor = focused ? 0xFFFFFF : 0xAAAAAA;
int scanCode = GLFW.glfwGetKeyScancode(prop.value);
renderScope.drawRoundedRectangle(0, 0, width, height, 10, 0xFF000000);
renderScope.drawText(0.6f, GLFW.glfwGetKeyName(prop.value, scanCode).toUpperCase(), 4, 4, font.value, textColor);
}
@Override
public void keyPressed(int keyCode, int scanCode, int modifiers) {
prop.value = keyCode;
focused = false;
}
}
@@ -9,6 +9,7 @@ import org.saturnclient.ui2.components.Sidebar;
import org.saturnclient.ui2.components.inputs.FloatInput;
import org.saturnclient.ui2.components.inputs.HexInput;
import org.saturnclient.ui2.components.inputs.IntInput;
import org.saturnclient.ui2.components.inputs.KeybindingSelector;
import org.saturnclient.ui2.components.inputs.Select;
import org.saturnclient.ui2.components.inputs.Toggle;
import org.saturnclient.ui2.elements.Scroll;
@@ -97,6 +98,10 @@ public class ConfigEditor extends SaturnScreen {
configScroll.draw(new Select((Property<Integer>) prop).position(w / 2, modY));
break;
case KEYBINDING:
configScroll.draw(new KeybindingSelector((Property<Integer>) prop).position(w / 2, modY));
break;
case STRING:
}