This commit is contained in:
0x3C50 2022-03-19 18:44:12 +01:00
parent 2defc34e57
commit c547898e13
5 changed files with 124 additions and 56 deletions

View file

@ -30,12 +30,18 @@ public class ConfigDisplay extends Element {
super(x, y, 100, 0);
this.mc = mc;
for (SettingBase<?> setting : mc.getSettings()) {
if (setting instanceof BooleanSetting set) {
BooleanSettingEditor bse = new BooleanSettingEditor(0, 0, width - padding - paddingLeft, set);
bases.add(bse);
} else if (setting instanceof DoubleSetting set) {
DoubleSettingEditor dse = new DoubleSettingEditor(0, 0, width - padding - paddingLeft, set);
bases.add(dse);
if (set.getName().equalsIgnoreCase("keybind")) {
KeybindEditor ke = new KeybindEditor(0,0,width-padding-paddingLeft,set);
bases.add(ke);
} else {
DoubleSettingEditor dse = new DoubleSettingEditor(0, 0, width - padding - paddingLeft, set);
bases.add(dse);
}
} else if (setting instanceof EnumSetting<?> set) {
EnumSettingEditor ese = new EnumSettingEditor(0, 0, width - padding - paddingLeft, set);
bases.add(ese);

View file

@ -0,0 +1,115 @@
/*
* Copyright (c) Shadow client, 0x150, Saturn5VFive 2022. All rights reserved.
*/
package net.shadow.client.feature.gui.clickgui.element.impl.config;
import net.minecraft.client.util.math.MatrixStack;
import net.shadow.client.feature.config.DoubleSetting;
import net.shadow.client.helper.font.FontRenderers;
import net.shadow.client.helper.render.Renderer;
import org.lwjgl.glfw.GLFW;
import java.awt.*;
import java.lang.reflect.Field;
public class KeybindEditor extends ConfigBase<DoubleSetting> {
static double h = FontRenderers.getRenderer().getFontHeight()+2;
boolean selecting = false;
boolean cancelNextCharTyped = false;
public KeybindEditor(double x, double y, double width, DoubleSetting configValue) {
super(x, y, width, h, configValue);
}
@Override
public double getHeight() {
return h;
}
@Override
public boolean clicked(double x, double y, int button) {
if (inBounds(x,y)) {
selecting = !selecting;
return true;
}
return false;
}
@Override
public boolean dragged(double x, double y, double deltaX, double deltaY, int button) {
return false;
}
@Override
public boolean released() {
return false;
}
// long lastUpdate = System.currentTimeMillis();
@Override
public boolean keyPressed(int keycode, int modifiers) {
if (selecting) {
// lastUpdate = System.currentTimeMillis();
cancelNextCharTyped = true;
if (keycode == GLFW.GLFW_KEY_ESCAPE) {
selecting = false;
return true;
}
if (keycode == GLFW.GLFW_KEY_BACKSPACE) keycode = -1;
configValue.setValue(keycode+0d);
selecting = false;
return true;
}
return false;
}
@Override
public void render(MatrixStack matrices, double mouseX, double mouseY, double scrollBeingUsed) {
String keyName;
int keybind = getKeybind();
if (selecting) {
keyName = "...";
}
else if (keybind == -1) {
keyName = "None";
} else {
keyName = GLFW.glfwGetKeyName(keybind, GLFW.glfwGetKeyScancode(keybind));
if (keyName == null) {
try {
for (Field declaredField : GLFW.class.getDeclaredFields()) {
if (declaredField.getName().startsWith("GLFW_KEY_")) {
int a = (int) declaredField.get(null);
if (a == keybind) {
String nb = declaredField.getName().substring("GLFW_KEY_".length());
keyName = nb.substring(0, 1).toUpperCase() + nb.substring(1).toLowerCase();
}
}
}
} catch (Exception ignored) {
keyName = "unknown." + keybind;
}
} else keyName = keyName.toUpperCase();
}
Renderer.R2D.renderRoundedQuad(matrices, new Color(40, 40, 40),x,y,x+width,y+h,5,20);
FontRenderers.getRenderer().drawCenteredString(matrices,keyName,x+width/2d,y+h/2d-FontRenderers.getRenderer().getMarginHeight()/2d,1f,1f,1f,1f);
}
int getKeybind() {
return (int) (configValue.getValue()+0);
}
@Override
public void tickAnim() {
}
@Override
public boolean charTyped(char c, int mods) {
// this gets triggered right after keyPressed so i cant really prevent it unless i do this cursed shit
if (cancelNextCharTyped) {
cancelNextCharTyped = false;
return true;
}
return false;
}
}

View file

@ -32,7 +32,7 @@ public abstract class Module {
this.moduleType = type;
this.config = new ModuleConfig();
this.keybind = this.config.create(new DoubleSetting.Builder(-1).name("Keybind").description("The keybind to toggle the module with").min(-1).max(65535).precision(0).get());
this.keybind.showIf(() -> false);
// this.keybind.showIf(() -> false);
this.debuggerEnabled = this.config.create(new BooleanSetting.Builder(false).name("Debugger").description("Shows a lot of funky visuals describing whats going on").get());
boolean hasAnnotation = false;
for (Annotation declaredAnnotation : this.getClass().getDeclaredAnnotations()) {

View file

@ -1,52 +0,0 @@
/*
* Copyright (c) Shadow client, 0x150, Saturn5VFive 2022. All rights reserved.
*/
package net.shadow.client.mixin;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.shadow.client.feature.gui.clickgui.theme.ThemeManager;
import net.shadow.client.helper.font.FontRenderers;
import net.shadow.client.helper.render.Renderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.awt.*;
@Mixin(ClickableWidget.class)
public abstract class ButtonWidgetMixin {
final Color unselectedColor = ThemeManager.getMainTheme().getInactive();
final Color selectedColor = ThemeManager.getMainTheme().getHeader();
@org.spongepowered.asm.mixin.Shadow
public int x;
@org.spongepowered.asm.mixin.Shadow
public int y;
@org.spongepowered.asm.mixin.Shadow
protected int width;
@org.spongepowered.asm.mixin.Shadow
protected int height;
double animProgress = 0;
@org.spongepowered.asm.mixin.Shadow
public abstract boolean isHovered();
@org.spongepowered.asm.mixin.Shadow
public abstract Text getMessage();
@Inject(method = "renderButton", at = @At("HEAD"), cancellable = true)
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) {
Renderer.R2D.renderRoundedQuad(matrices, this.isHovered() ? selectedColor : unselectedColor, x, y, x + width, y + height, 5, 7);
FontRenderers.getRenderer().drawCenteredString(matrices, this.getMessage().getString(), this.x + this.width / 2f, this.y + (this.height - 9) / 2f, 0xFFFFFF);
ci.cancel();
//if (!UnloadModule.loaded) return
}
double easeInOutQuint(double x) {
return x < 0.5 ? 16 * x * x * x * x * x : 1 - Math.pow(-2 * x + 2, 5) / 2;
}
}

View file

@ -13,7 +13,6 @@
"BlockEntityRenderDispatcherMixin",
"BlockMixin",
"BlockRenderManagerMixin",
"ButtonWidgetMixin",
"CameraMixin",
"ClientConnection1Mixin",
"ClientConnectionMixin",