This commit is contained in:
retuci0 committed 2026-01-01 18:29:46 +01:00
1 parent 347ec658bb
commit 48899f85f9
36 files changed
+728 -824

No files matched your search

+1 -3
View File
@@ -43,6 +43,4 @@ replay_*.log
todo.txt todo.txt
cambios.md cambios.md
remappedSrc/ remappedSrc/
src/main/java/me/retucio/camtweaks/ui/widgets/Frame.java
src/main/java/me/retucio/camtweaks/ui/widgets/Button.java
+1 -1
View File
@@ -6,7 +6,7 @@ yarn_mappings=1.21.10+build.2
loader_version=0.17.3 loader_version=0.17.3
loom_version=1.11-SNAPSHOT loom_version=1.11-SNAPSHOT
mod_version=2.0 mod_version=2.1
maven_group=me.retucio maven_group=me.retucio
archives_base_name=camtweaks archives_base_name=camtweaks
@@ -20,12 +20,13 @@ import me.retucio.camtweaks.module.modules.HUD;
import me.retucio.camtweaks.ui.screen.ClickGUI; import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.hud.HudEditorScreen; import me.retucio.camtweaks.ui.hud.HudEditorScreen;
import me.retucio.camtweaks.ui.hud.HudRenderer; import me.retucio.camtweaks.ui.hud.HudRenderer;
import me.retucio.camtweaks.ui.buttons.BindButton; import me.retucio.camtweaks.ui.widgets.buttons.settings.BindButton;
import me.retucio.camtweaks.ui.buttons.SettingButton; import me.retucio.camtweaks.ui.widgets.buttons.SettingButton;
import me.retucio.camtweaks.ui.buttons.TextButton; import me.retucio.camtweaks.ui.widgets.buttons.settings.TextButton;
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
import me.retucio.camtweaks.ui.frames.SettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
import me.retucio.camtweaks.ui.widgets.Button;
import me.retucio.camtweaks.util.*; import me.retucio.camtweaks.util.*;
@@ -84,7 +85,7 @@ public class CameraTweaks implements ClientModInitializer {
EVENT_BUS.register(this); EVENT_BUS.register(this);
EVENT_BUS.register(new HudRenderer()); EVENT_BUS.register(HudRenderer.class);
EVENT_BUS.register(ChatUtil.class); EVENT_BUS.register(ChatUtil.class);
EVENT_BUS.register(DrawUtil.class); EVENT_BUS.register(DrawUtil.class);
@@ -149,7 +150,7 @@ public class CameraTweaks implements ClientModInitializer {
// verifica si algún botón de ajustes está escuchando // verifica si algún botón de ajustes está escuchando
private boolean isAnySettingButtonFocused() { private boolean isAnySettingButtonFocused() {
for (SettingsFrame sf : ClickGUI.INSTANCE.getSettingsFrames()) for (SettingsFrame sf : ClickGUI.INSTANCE.getSettingsFrames())
for (SettingButton sb : sf.getButtons()) for (Button sb : sf.getButtons())
if ((sb instanceof BindButton b && b.isFocused()) || (sb instanceof TextButton t && t.isFocused())) if ((sb instanceof BindButton b && b.isFocused()) || (sb instanceof TextButton t && t.isFocused()))
return true; return true;
return false; return false;
@@ -173,8 +174,8 @@ public class CameraTweaks implements ClientModInitializer {
private void handleSettingButtonsKey(int key, int action) { private void handleSettingButtonsKey(int key, int action) {
for (SettingsFrame sf : ClickGUI.INSTANCE.getSettingsFrames()) { for (SettingsFrame sf : ClickGUI.INSTANCE.getSettingsFrames()) {
for (SettingButton sb : sf.getButtons()) { for (SettingButton sb : sf.getButtons()) {
if (sb instanceof BindButton b) b.onKey(key, action); if (sb instanceof BindButton bb) bb.onKey(key, action);
else if (sb instanceof TextButton t) t.onKey(key, action); if (sb instanceof TextButton tb) tb.onKey(key, action);
} }
} }
} }
@@ -3,7 +3,7 @@ package me.retucio.camtweaks.command.commands;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import me.retucio.camtweaks.command.Command; import me.retucio.camtweaks.command.Command;
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
import me.retucio.camtweaks.util.ChatUtil; import me.retucio.camtweaks.util.ChatUtil;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.text.Text; import net.minecraft.text.Text;
@@ -80,39 +80,39 @@ public class ClientConfig {
@SubscribeEvent @SubscribeEvent
public void onMoveSettingsFrame(SettingsFrameEvent.Move event) { public void onMoveSettingsFrame(SettingsFrameEvent.Move event) {
settingsFrames.replace(event.getFrame().module.getName(), new int[]{event.getFrame().x, event.getFrame().y}); settingsFrames.replace(event.getFrame().module.getName(), new int[]{event.getFrame().getX(), event.getFrame().getY()});
ConfigManager.save(); ConfigManager.save();
} }
@SubscribeEvent @SubscribeEvent
public void onExtendModuleFrame(ModuleFrameEvent.Extend event) { public void onExtendModuleFrame(ModuleFrameEvent.Extend event) {
extendableFrames.put("M", new FrameData( extendableFrames.put("M", new FrameData(
ClickGUI.INSTANCE.getModulesFrame().x, ClickGUI.INSTANCE.getModulesFrame().getX(),
ClickGUI.INSTANCE.getModulesFrame().y, ClickGUI.INSTANCE.getModulesFrame().getY(),
ClickGUI.INSTANCE.getModulesFrame().extended)); ClickGUI.INSTANCE.getModulesFrame().extended));
} }
@SubscribeEvent @SubscribeEvent
public void onMoveModuleFrame(ModuleFrameEvent.Move event) { public void onMoveModuleFrame(ModuleFrameEvent.Move event) {
extendableFrames.replace("M", new FrameData( extendableFrames.replace("M", new FrameData(
ClickGUI.INSTANCE.getModulesFrame().x, ClickGUI.INSTANCE.getModulesFrame().getX(),
ClickGUI.INSTANCE.getModulesFrame().y, ClickGUI.INSTANCE.getModulesFrame().getY(),
ClickGUI.INSTANCE.getModulesFrame().extended)); ClickGUI.INSTANCE.getModulesFrame().extended));
} }
@SubscribeEvent @SubscribeEvent
public void onExtendGUISettingsFrame(GUISettingsFrameEvent.Extend event) { public void onExtendGUISettingsFrame(GUISettingsFrameEvent.Extend event) {
extendableFrames.put("S", new FrameData( extendableFrames.put("S", new FrameData(
ClickGUI.INSTANCE.getGuiSettingsFrame().x, ClickGUI.INSTANCE.getGuiSettingsFrame().getX(),
ClickGUI.INSTANCE.getGuiSettingsFrame().y, ClickGUI.INSTANCE.getGuiSettingsFrame().getY(),
ClickGUI.INSTANCE.getGuiSettingsFrame().extended)); ClickGUI.INSTANCE.getGuiSettingsFrame().extended));
} }
@SubscribeEvent @SubscribeEvent
public void onMoveGUISettingsFrame(GUISettingsFrameEvent.Move event) { public void onMoveGUISettingsFrame(GUISettingsFrameEvent.Move event) {
extendableFrames.replace("S", new FrameData( extendableFrames.replace("S", new FrameData(
ClickGUI.INSTANCE.getGuiSettingsFrame().x, ClickGUI.INSTANCE.getGuiSettingsFrame().getX(),
ClickGUI.INSTANCE.getGuiSettingsFrame().y, ClickGUI.INSTANCE.getGuiSettingsFrame().getY(),
ClickGUI.INSTANCE.getGuiSettingsFrame().extended)); ClickGUI.INSTANCE.getGuiSettingsFrame().extended));
} }
@@ -6,10 +6,10 @@ import me.retucio.camtweaks.CameraTweaks;
import me.retucio.camtweaks.module.Module; import me.retucio.camtweaks.module.Module;
import me.retucio.camtweaks.module.ModuleManager; import me.retucio.camtweaks.module.ModuleManager;
import me.retucio.camtweaks.module.settings.*; import me.retucio.camtweaks.module.settings.*;
import me.retucio.camtweaks.ui.frames.ModuleFrame; import me.retucio.camtweaks.ui.widgets.frames.ModuleFrame;
import me.retucio.camtweaks.ui.screen.ClickGUI; import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
import me.retucio.camtweaks.ui.frames.SettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
@@ -100,7 +100,7 @@ public class ConfigManager {
public static void setFramePosition(SettingsFrame frame) { public static void setFramePosition(SettingsFrame frame) {
ensureConfig(); ensureConfig();
config.settingsFrames.put(frame.module.getName(), new int[] {frame.x, frame.y}); config.settingsFrames.put(frame.module.getName(), new int[] {frame.getX(), frame.getY()});
save(); save();
} }
@@ -203,8 +203,8 @@ public class ConfigManager {
private static void applyExtendableFrame(ModuleFrame frame) { private static void applyExtendableFrame(ModuleFrame frame) {
ClientConfig.FrameData frameData = config.extendableFrames.get("M"); ClientConfig.FrameData frameData = config.extendableFrames.get("M");
if (frameData != null) { if (frameData != null) {
frame.x = frameData.x(); frame.setX(frameData.x());
frame.y = frameData.y(); frame.setY(frameData.y());
frame.extended = frameData.extended(); frame.extended = frameData.extended();
} }
} }
@@ -212,8 +212,8 @@ public class ConfigManager {
private static void applyExtendableFrame(ClientSettingsFrame frame) { private static void applyExtendableFrame(ClientSettingsFrame frame) {
ClientConfig.FrameData frameData = config.extendableFrames.get("S"); ClientConfig.FrameData frameData = config.extendableFrames.get("S");
if (frameData != null) { if (frameData != null) {
frame.x = frameData.x(); frame.setX(frameData.x());
frame.y = frameData.y(); frame.setY(frameData.y());
frame.extended = frameData.extended(); frame.extended = frameData.extended();
} }
} }
@@ -1,7 +1,7 @@
package me.retucio.camtweaks.event.events.camtweaks; package me.retucio.camtweaks.event.events.camtweaks;
import me.retucio.camtweaks.event.Event; import me.retucio.camtweaks.event.Event;
import me.retucio.camtweaks.ui.frames.SettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
// se genera cada que se interactúa con un marco de ajustes de un módulo // se genera cada que se interactúa con un marco de ajustes de un módulo
public class SettingsFrameEvent { public class SettingsFrameEvent {
@@ -1,12 +1,10 @@
package me.retucio.camtweaks.mixin; package me.retucio.camtweaks.mixin;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import me.retucio.camtweaks.CameraTweaks;
import me.retucio.camtweaks.command.CommandManager; import me.retucio.camtweaks.command.CommandManager;
import me.retucio.camtweaks.config.ConfigManager; import me.retucio.camtweaks.config.ConfigManager;
import me.retucio.camtweaks.event.events.ClientClickEvent; import me.retucio.camtweaks.event.events.ClientClickEvent;
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
import net.minecraft.SharedConstants;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
@@ -16,9 +14,6 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.awt.*;
import static me.retucio.camtweaks.CameraTweaks.getVersionName;
import static me.retucio.camtweaks.CameraTweaks.mc; import static me.retucio.camtweaks.CameraTweaks.mc;
@Mixin(Screen.class) @Mixin(Screen.class)
@@ -2,7 +2,7 @@ package me.retucio.camtweaks.module.settings;
import me.retucio.camtweaks.module.Module; import me.retucio.camtweaks.module.Module;
import me.retucio.camtweaks.module.ModuleManager; import me.retucio.camtweaks.module.ModuleManager;
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
import me.retucio.camtweaks.util.ChatUtil; import me.retucio.camtweaks.util.ChatUtil;
import me.retucio.camtweaks.util.KeyUtil; import me.retucio.camtweaks.util.KeyUtil;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
@@ -1,96 +0,0 @@
package me.retucio.camtweaks.ui.buttons;
import me.retucio.camtweaks.module.Module;
import me.retucio.camtweaks.module.settings.ColorSetting;
import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.frames.SettingsFrame;
import me.retucio.camtweaks.util.ChatUtil;
import me.retucio.camtweaks.util.Colors;
import me.retucio.camtweaks.util.render.DrawUtil;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import static me.retucio.camtweaks.CameraTweaks.mc;
public class ColorButton extends SettingButton {
private final ColorSetting setting;
public ColorButton(ColorSetting setting, SettingsFrame parent, int offset) {
super(setting, parent, offset);
this.setting = setting;
}
@Override
public void render(DrawContext ctx, double mouseX, double mouseY, float delta) {
// fondo
Color bgColor = isHovered((int) mouseX, (int) mouseY)
? Colors.buttonColor.brighter()
: Colors.buttonColor;
ctx.fill(x, y, x + w, y + h, bgColor.getRGB());
// prev. del color
int previewSize = h - 6;
int previewX = x + 5;
int previewY = y + 3;
DrawUtil.drawBorder(ctx, previewX - 1, previewY - 1, previewSize + 2, previewSize + 2, setting.isRainbow() ? Colors.mainColor.getRGB() : -1);
ctx.fill(previewX, previewY, previewX + previewSize, previewY + previewSize, setting.getColor().getRGB());
// texto
String label = setting.getName();
int textX = previewX + previewSize + 5;
ctx.drawText(parent.mc.textRenderer, label, textX, y + 3, -1, true);
// valor actual
String valueText = setting.isRainbow() ? "gay." : Colors.ARGBtoHex(setting.getA(), setting.getR(), setting.getG(), setting.getB());
int valueWidth = parent.mc.textRenderer.getWidth(valueText);
ctx.drawText(parent.mc.textRenderer, valueText, x + w - valueWidth - 5, y + 3, -1, true);
}
@Override
public void drawTooltip(DrawContext ctx, double mouseX, double mouseY) {
if (isHovered((int) mouseX, (int) mouseY)) {
List<Text> tooltip = new ArrayList<>();
tooltip.add(Text.of(setting.getDescription()));
tooltip.add(setting.getTooltipText());
ctx.drawTooltip(mc.textRenderer, tooltip, (int) mouseX, (int) mouseY + 20);
}
}
@Override
public void mouseClicked(double mouseX, double mouseY, int button) {
if (isHovered((int) mouseX, (int) mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
if (button == 0) {
// click izq.: abrir selector de colores
ClickGUI.INSTANCE.openColorPickerFrame(setting.getModule(), setting, parent.x + parent.w + 120, parent.renderY + offset);
} else if (button == 1 && mc.isShiftPressed()) {
// shift + clic dcho.: restablecer color
setting.reset();
}
}
}
@Override
public void mouseReleased(double mouseX, double mouseY, int button) {
ClickGUI.INSTANCE.unselect(this);
}
@Override
public void mouseDragged(double mouseX, double mouseY) {}
public ColorSetting getSetting() {
return setting;
}
public void refreshDummy() {
// This is called when the color picker frame needs to be refreshed
// We'll update any linked dummy module in the color picker frame
}
}
@@ -1,80 +0,0 @@
package me.retucio.camtweaks.ui.buttons;
import me.retucio.camtweaks.module.settings.Setting;
import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.frames.SettingsFrame;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
// clase base para los botones de los ajustes
public abstract class SettingButton {
protected final Setting setting;
protected final SettingsFrame parent;
protected int offset;
protected int x, y, w, h;
public SettingButton(Setting setting, SettingsFrame parent, int offset) {
this.setting = setting;
this.parent = parent;
this.offset = offset;
}
public abstract void render(DrawContext ctx, double mouseX, double mouseY, float delta);
public abstract void mouseClicked(double mouseX, double mouseY, int button);
public abstract void mouseReleased(double mouseX, double mouseY, int button);
public abstract void mouseDragged(double mouseX, double mouseY);
// dibujar "tooltips" (cajitas de texto bajo el puntero del ratón) con la descripción para asistir al usuario en el caso de que tenga down
public void drawTooltip(DrawContext ctx, double mouseX, double mouseY) {
if (isHovered((int) mouseX, (int) mouseY))
ctx.drawTooltip(Text.of(setting.getDescription()), (int) mouseX, (int) mouseY + 20);
}
protected boolean isHovered(double mouseX, double mouseY) {
return isHovered((int) mouseX, (int) mouseY);
}
protected boolean isHovered(int mouseX, int mouseY) {
if (!ClickGUI.INSTANCE.canSelect(this)) return false;
return mouseX > x && mouseX < x + w &&
mouseY > y && mouseY < y + h;
}
public Setting getSetting() {
return setting;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getW() {
return w;
}
public void setW(int w) {
this.w = w;
}
public int getH() {
return h;
}
public void setH(int h) {
this.h = h;
}
}
@@ -1,56 +0,0 @@
package me.retucio.camtweaks.ui.buttons;
import me.retucio.camtweaks.module.settings.BooleanSetting;
import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.frames.SettingsFrame;
import me.retucio.camtweaks.util.Colors;
import net.minecraft.client.gui.DrawContext;
import java.awt.*;
import static me.retucio.camtweaks.CameraTweaks.mc;
// botón para los ajustes booleanos (funciona como un interruptor)
public class ToggleButton extends SettingButton {
private final BooleanSetting setting;
public ToggleButton(BooleanSetting setting, SettingsFrame parent, int offset) {
super(setting, parent, offset);
this.setting = setting;
}
@Override
public void render(DrawContext ctx, double mouseX, double mouseY, float delta) {
Color color = setting.isEnabled()
? Colors.enabledToggleButtonColor
: Colors.disabledToggleButtonColor;
if (isHovered((int) mouseX, (int) mouseY))
color = color.brighter();
ctx.fill(x, y, x + w, y + h, color.getRGB());
ctx.drawText(parent.mc.textRenderer, setting.getName(), x + 5, y + 3, -1, true);
}
@Override
public void mouseClicked(double mouseX, double mouseY, int button) {
if (isHovered((int) mouseX, (int) mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
if (button == 0) setting.toggle(); // clic izquierdo para alternar
else if (button == 1 && mc.isShiftPressed()) // shift izquierdo + clic derecho para restablecer al valor por defecto
setting.reset();
}
}
@Override
public void mouseReleased(double mouseX, double mouseY, int button) {
ClickGUI.INSTANCE.unselect(this);
}
@Override
public void mouseDragged(double mouseX, double mouseY) {}
public BooleanSetting getSetting() {
return setting;
}
}
@@ -1,9 +1,7 @@
package me.retucio.camtweaks.ui.hud; package me.retucio.camtweaks.ui.hud;
import me.retucio.camtweaks.config.ConfigManager; import me.retucio.camtweaks.config.ConfigManager;
import me.retucio.camtweaks.module.ModuleManager; import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
import me.retucio.camtweaks.module.modules.HUD;
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame;
import me.retucio.camtweaks.util.Colors; import me.retucio.camtweaks.util.Colors;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Click; import net.minecraft.client.gui.Click;
@@ -9,15 +9,18 @@ import me.retucio.camtweaks.event.events.camtweaks.SettingsFrameEvent;
import me.retucio.camtweaks.module.Module; import me.retucio.camtweaks.module.Module;
import me.retucio.camtweaks.module.settings.Setting; import me.retucio.camtweaks.module.settings.Setting;
import me.retucio.camtweaks.module.settings.ColorSetting; import me.retucio.camtweaks.module.settings.ColorSetting;
import me.retucio.camtweaks.ui.buttons.ListButton; import me.retucio.camtweaks.ui.widgets.buttons.settings.ListButton;
import me.retucio.camtweaks.ui.buttons.ModuleButton; import me.retucio.camtweaks.ui.widgets.buttons.ModuleButton;
import me.retucio.camtweaks.ui.buttons.SettingButton; import me.retucio.camtweaks.ui.widgets.buttons.SettingButton;
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
import me.retucio.camtweaks.ui.frames.ColorPickerFrame; import me.retucio.camtweaks.ui.widgets.frames.settings.ColorPickerFrame;
import me.retucio.camtweaks.ui.frames.ModuleFrame; import me.retucio.camtweaks.ui.widgets.frames.ModuleFrame;
import me.retucio.camtweaks.ui.frames.SettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
import me.retucio.camtweaks.ui.widgets.ScrollBarWidget; import me.retucio.camtweaks.ui.widgets.Button;
import me.retucio.camtweaks.ui.widgets.SearchBarWidget; import me.retucio.camtweaks.ui.widgets.Frame;
import me.retucio.camtweaks.ui.widgets.Widget;
import me.retucio.camtweaks.ui.widgets.misc.ScrollBarWidget;
import me.retucio.camtweaks.ui.widgets.misc.SearchBarWidget;
import me.retucio.camtweaks.util.KeyUtil; import me.retucio.camtweaks.util.KeyUtil;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
@@ -29,16 +32,19 @@ import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import static me.retucio.camtweaks.ui.frames.ClientSettingsFrame.guiSettings; import static me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame.guiSettings;
// interfaz gráfica, se abre con el shift derecho por defecto. aquí se encuentran los módulos y sus ajustes // interfaz gráfica, se abre con el shift derecho por defecto. aquí se encuentran los módulos y sus ajustes
public class ClickGUI extends Screen { public class ClickGUI extends Screen {
private final MinecraftClient mc = MinecraftClient.getInstance();
public static ClickGUI INSTANCE; public static ClickGUI INSTANCE;
private boolean anyFocused; private boolean anyFocused;
private Object selected = null; private Widget selected = null;
private final ModuleFrame modulesFrame = new ModuleFrame(20, 30, 100, 20); private final ModuleFrame modulesFrame = new ModuleFrame(20, 30, 100, 20);
private final List<SettingsFrame> settingsFrames = new ArrayList<>(); private final List<SettingsFrame> settingsFrames = new ArrayList<>();
@@ -46,8 +52,7 @@ public class ClickGUI extends Screen {
private final ScrollBarWidget scrollBar = new ScrollBarWidget(); private final ScrollBarWidget scrollBar = new ScrollBarWidget();
private final SearchBarWidget searchBar = new SearchBarWidget(340, 16, 300, 20); private final SearchBarWidget searchBar = new SearchBarWidget(340, 16, 300, 20);
private final List<Widget> miscWidgets = Arrays.asList(scrollBar, searchBar);
private final MinecraftClient mc = MinecraftClient.getInstance();
public ClickGUI() { public ClickGUI() {
super(Text.of("interfaz")); super(Text.of("interfaz"));
@@ -59,7 +64,7 @@ public class ClickGUI extends Screen {
public void render(DrawContext ctx, int mouseX, int mouseY, float delta) { public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
scrollBar.setWindowHeight(mc.getWindow().getScaledHeight()); scrollBar.setWindowHeight(mc.getWindow().getScaledHeight());
scrollBar.setContentHeight(calculateContentHeight()); scrollBar.setContentHeight(calculateContentHeight());
scrollBar.render(ctx, mouseX, mouseY); scrollBar.render(ctx, mouseX, mouseY, delta);
int scrollOffset = scrollBar.getScrollOffset(); int scrollOffset = scrollBar.getScrollOffset();
@@ -111,43 +116,52 @@ public class ClickGUI extends Screen {
} }
private int calculateContentHeight() { private int calculateContentHeight() {
int bottom = modulesFrame.y + modulesFrame.h + modulesFrame.totalHeight; int bottom = modulesFrame.getY() + modulesFrame.getH() + modulesFrame.getTotalHeight();
for (SettingsFrame frame : settingsFrames) for (SettingsFrame frame : settingsFrames)
bottom = Math.max(bottom, frame.y + frame.h + frame.totalHeight); bottom = Math.max(bottom, frame.getY() + frame.getH() + frame.getTotalHeight());
return bottom + 20; // padding return bottom + 20; // padding
} }
public boolean mouseClicked(Click click, boolean doubled) { public boolean mouseClicked(Click click, boolean doubled) {
scrollBar.mouseClicked(click.x(), click.y(), click.button()); miscWidgets.forEach(w -> w.mouseClicked(
searchBar.mouseClicked(click.x(), click.y(), click.button()); (int) click.x(),
(int) click.y(),
click.button()));
// detectar clics sobre los marcos // detectar clics sobre los marcos
modulesFrame.mouseClicked(click.x(), click.y(), click.button()); modulesFrame.mouseClicked((int) click.x(), (int) click.y(), click.button());
for (SettingsFrame sf : new ArrayList<>(settingsFrames)) for (SettingsFrame sf : new ArrayList<>(settingsFrames))
sf.mouseClicked(click.x(), click.y(), click.button()); sf.mouseClicked((int) click.x(), (int) click.y(), click.button());
return super.mouseClicked(click, doubled); return super.mouseClicked(click, doubled);
} }
@Override @Override
public boolean mouseReleased(Click click) { public boolean mouseReleased(Click click) {
scrollBar.mouseReleased(click.x(), click.y(), click.button()); miscWidgets.forEach(w -> w.mouseReleased(
searchBar.mouseReleased(click.x(), click.y(), click.button()); (int) click.x(),
(int) click.y(),
click.button()));
// registrar cuándo se suelta el clic, en cada marco respectivamente // registrar cuándo se suelta el clic, en cada marco respectivamente
modulesFrame.mouseReleased(click.x(), click.y(), click.button()); modulesFrame.mouseReleased((int) click.x(), (int) click.y(), click.button());
for (SettingsFrame sf : new ArrayList<>(settingsFrames)) for (SettingsFrame sf : new ArrayList<>(settingsFrames))
sf.mouseReleased(click.x(), click.y(), click.button()); sf.mouseReleased((int) click.x(), (int) click.y(), click.button());
return super.mouseReleased(click); return super.mouseReleased(click);
} }
@Override @Override
public boolean mouseDragged(Click click, double deltaX, double deltaY) { public boolean mouseDragged(Click click, double deltaX, double deltaY) {
scrollBar.mouseDragged(click.y()); miscWidgets.forEach(w -> w.mouseDragged(
(int) click.x(),
(int) click.y()));
for (SettingsFrame sf : new ArrayList<>(settingsFrames)) for (SettingsFrame sf : new ArrayList<>(settingsFrames))
sf.mouseDragged(click.x(), click.y()); sf.mouseDragged((int) click.x(), (int) click.y());
return super.mouseDragged(click, deltaX, deltaY); return super.mouseDragged(click, deltaX, deltaY);
} }
@@ -158,8 +172,8 @@ public class ClickGUI extends Screen {
@SubscribeEvent @SubscribeEvent
public void onMouseScroll(MouseScrollEvent event) { public void onMouseScroll(MouseScrollEvent event) {
// subir y bajar la pantalla con la rueda del ratón miscWidgets.forEach(w -> w.mouseScrolled(
scrollBar.onMouseScroll(event.getVertical() * guiSettings.scrollSens.getValue()); event.getVertical() * guiSettings.scrollSens.getValue()));
} }
@SubscribeEvent @SubscribeEvent
@@ -168,13 +182,13 @@ public class ClickGUI extends Screen {
if (CameraTweaks.mc.currentScreen != this || event.getButton() != 2 || !KeyUtil.isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT)) return; if (CameraTweaks.mc.currentScreen != this || event.getButton() != 2 || !KeyUtil.isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT)) return;
int h = CameraTweaks.mc.getWindow().getScaledHeight(); int h = CameraTweaks.mc.getWindow().getScaledHeight();
int minY = Math.min(modulesFrame.y, settingsFrames.stream().mapToInt(sf -> sf.y).min().orElse(modulesFrame.y)); int minY = Math.min(modulesFrame.getY(), settingsFrames.stream().mapToInt(Frame::getY).min().orElse(modulesFrame.getY()));
int maxY = Math.max(modulesFrame.y + modulesFrame.h, settingsFrames.stream().mapToInt(sf -> sf.y + sf.h).max().orElse(modulesFrame.y + modulesFrame.h)); int maxY = Math.max(modulesFrame.getY() + modulesFrame.getH(), settingsFrames.stream().mapToInt(sf -> sf.getY() + sf.getH()).max().orElse(modulesFrame.getY() + modulesFrame.getH()));
int correction = minY < 0 ? -minY + 4 : (maxY > h ? h - maxY - 4 : 0); int correction = minY < 0 ? -minY + 4 : (maxY > h ? h - maxY - 4 : 0);
if (correction != 0) { if (correction != 0) {
modulesFrame.y += correction; modulesFrame.setY(modulesFrame.getY() + correction);
settingsFrames.forEach(sf -> sf.y += correction); settingsFrames.forEach(sf -> sf.setY(sf.getY() + correction));
} }
} }
@@ -183,7 +197,8 @@ public class ClickGUI extends Screen {
String searchInput = searchBar.getSearchInput().trim(); String searchInput = searchBar.getSearchInput().trim();
if (!guiSettings.matchCase.isEnabled()) searchInput = searchInput.toLowerCase(); if (!guiSettings.matchCase.isEnabled()) searchInput = searchInput.toLowerCase();
for (ModuleButton mb : modulesFrame.getButtons()) { for (Button b : modulesFrame.getButtons()) {
if (!(b instanceof ModuleButton mb)) return;
Module module = mb.getModule(); Module module = mb.getModule();
if (searchInput.isEmpty()) { if (searchInput.isEmpty()) {
@@ -203,7 +218,8 @@ public class ClickGUI extends Screen {
} }
for (SettingsFrame sf : settingsFrames) { for (SettingsFrame sf : settingsFrames) {
for (SettingButton sb : sf.getButtons()) { for (Button b : sf.getButtons()) {
if (!(b instanceof SettingButton<?> sb)) return;
Setting setting = sb.getSetting(); Setting setting = sb.getSetting();
if (searchInput.isEmpty()) { if (searchInput.isEmpty()) {
@@ -224,17 +240,18 @@ public class ClickGUI extends Screen {
} }
} }
// abrir un marco donde se encuentran los ajustes del módulo deseado
public void openSettingsFrame(Module module, int x, int y) { public void openSettingsFrame(Module module, int x, int y) {
// abrir un marco donde se encuentran los ajustes del módulo deseado
if (isSettingsFrameOpen(module)) return; // permitir un solo marco de ajustes por módulo if (isSettingsFrameOpen(module)) return; // permitir un solo marco de ajustes por módulo
SettingsFrame frame = new SettingsFrame(module, x, y, 120, 20); SettingsFrame frame = new SettingsFrame(module, x, y, 120, 20);
settingsFrames.add(frame); settingsFrames.add(frame);
CameraTweaks.EVENT_BUS.post(new SettingsFrameEvent.Open(frame)); CameraTweaks.EVENT_BUS.post(new SettingsFrameEvent.Open(frame));
} }
public void openListSettingsFrame(Module module, int x, int y) { // abrir un marco de ajustes específicamente para ajustes de selección múltiple
if (isSettingsFrameOpen(module)) return; public void openListSettingsFrame(Module dummy, int x, int y) {
SettingsFrame frame = new SettingsFrame(module, x, y, 120, 18); if (isSettingsFrameOpen(dummy)) return;
SettingsFrame frame = new SettingsFrame(dummy, x, y, 120, 18);
settingsFrames.add(frame); settingsFrames.add(frame);
} }
@@ -244,12 +261,13 @@ public class ClickGUI extends Screen {
List<SettingsFrame> toRemove = new ArrayList<>(); List<SettingsFrame> toRemove = new ArrayList<>();
for (SettingsFrame sf : settingsFrames) { for (SettingsFrame sf : settingsFrames) {
if ((sf instanceof ColorPickerFrame cpf && cpf.dummyModule == module) // para los selectores de colores if ((sf instanceof ColorPickerFrame cpf && cpf.dummyModule == module) // para los selectores de colores
|| (!(sf instanceof ColorPickerFrame) && sf.module == module)) { // lógica muy mierdas, lo sé, pero paso de hacerlo bien || (!(sf instanceof ColorPickerFrame) && sf.module == module)) { // lógica muy mierdas, lo sé, pero paso de hacerlo bien
CameraTweaks.EVENT_BUS.post(new SettingsFrameEvent.Close(sf));
toRemove.add(sf); toRemove.add(sf);
CameraTweaks.EVENT_BUS.post(new SettingsFrameEvent.Close(sf));
unselect(sf); unselect(sf);
} }
} }
settingsFrames.removeAll(toRemove); settingsFrames.removeAll(toRemove);
} }
@@ -259,13 +277,6 @@ public class ClickGUI extends Screen {
.anyMatch(sf -> sf.module.getName().equals(module.getName())); .anyMatch(sf -> sf.module.getName().equals(module.getName()));
} }
public void refreshListButtons() {
for (SettingsFrame frame : settingsFrames)
for (SettingButton button : frame.getButtons())
if (button instanceof ListButton<?> lb)
lb.refreshDummy();
}
public boolean isColorPickerFrameOpen(ColorSetting setting) { public boolean isColorPickerFrameOpen(ColorSetting setting) {
for (SettingsFrame sf : getSettingsFrames()) { for (SettingsFrame sf : getSettingsFrames()) {
if (sf instanceof ColorPickerFrame cpf) if (sf instanceof ColorPickerFrame cpf)
@@ -279,7 +290,7 @@ public class ClickGUI extends Screen {
if (isColorPickerFrameOpen(frame.getColorSetting())) { if (isColorPickerFrameOpen(frame.getColorSetting())) {
closeColorPickerFrame(frame.getColorSetting()); closeColorPickerFrame(frame.getColorSetting());
return; return;
}; }
settingsFrames.add(frame); settingsFrames.add(frame);
} }
@@ -292,6 +303,14 @@ public class ClickGUI extends Screen {
} }
} }
public void refreshListButtons() {
for (SettingsFrame frame : settingsFrames)
for (Button button : frame.getButtons())
if (button instanceof ListButton<?> lb)
lb.refreshDummy();
}
// métodos del súper // métodos del súper
@Override @Override
@@ -332,6 +351,8 @@ public class ClickGUI extends Screen {
return guiSettingsFrame; return guiSettingsFrame;
} }
public List<Widget> getMiscWidgets() { return miscWidgets; }
public List<SettingsFrame> getSettingsFrames() { public List<SettingsFrame> getSettingsFrames() {
return settingsFrames; return settingsFrames;
} }
@@ -347,27 +368,27 @@ public class ClickGUI extends Screen {
// selección de widgets // selección de widgets
public Object getSelected() { public Widget getSelected() {
return selected; return selected;
} }
public void setSelected(Object object) { public void setSelected(Widget widget) {
this.selected = object; this.selected = widget;
} }
public boolean canSelect(Object object) { public boolean canSelect(Widget widget) {
return getSelected() == null || getSelected() == object; return getSelected() == null || getSelected() == widget;
} }
public boolean trySelect(Object object) { public boolean trySelect(Widget widget) {
if (canSelect(object)) { if (canSelect(widget)) {
setSelected(object); setSelected(widget);
return true; return true;
} }
return false; return false;
} }
public void unselect(Object object) { public void unselect(Widget widget) {
if (selected == object) setSelected(null); if (selected == widget) setSelected(null);
} }
} }
@@ -2,7 +2,7 @@ package me.retucio.camtweaks.ui.screen;
import me.retucio.camtweaks.CameraTweaks; import me.retucio.camtweaks.CameraTweaks;
import me.retucio.camtweaks.module.modules.ShulkerPeek; import me.retucio.camtweaks.module.modules.ShulkerPeek;
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
import me.retucio.camtweaks.util.Colors; import me.retucio.camtweaks.util.Colors;
import net.minecraft.client.gl.RenderPipelines; import net.minecraft.client.gl.RenderPipelines;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
@@ -1,36 +1,27 @@
package me.retucio.camtweaks.ui.widgets; package me.retucio.camtweaks.ui.widgets;
import me.retucio.camtweaks.module.settings.Setting;
import me.retucio.camtweaks.ui.frames.SettingsFrame;
import me.retucio.camtweaks.ui.screen.ClickGUI; import me.retucio.camtweaks.ui.screen.ClickGUI;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
public abstract class Button { public abstract class Button extends Widget {
protected Frame parent; protected Frame<?> parent;
protected int offset; protected int offset;
protected int x, y, w, h; public Button(Frame<?> parent, int offset) {
super(parent.getX(), parent.getRenderY(), parent.getW(), parent.getH());
public Button(Frame parent, int offset) {
this.parent = parent; this.parent = parent;
this.offset = offset; this.offset = offset;
} }
public abstract void render(DrawContext ctx, int mouseX, int mouseY, float delta);
public abstract void mouseClicked(int mouseX, int mouseY, int button); public abstract void drawTooltip(DrawContext ctx, int mouseX, int mouseY);
public abstract void mouseDragged(int mouseX, int mouseY);
public void mouseReleased(int mouseX, int mouseY, int button) { public int getOffset() {
ClickGUI.INSTANCE.unselect(this); return offset;
} }
public abstract void drawTooltip(DrawContext ctx, double mouseX, double mouseY); public void setOffset(int offset) {
this.offset = offset;
protected boolean isHovered(int mouseX, int mouseY) {
if (!ClickGUI.INSTANCE.canSelect(this)) return false;
return mouseX > x && mouseX < x + w &&
mouseY > y && mouseY < y + h;
} }
} }
@@ -1,63 +1,51 @@
package me.retucio.camtweaks.ui.widgets; package me.retucio.camtweaks.ui.widgets;
import me.retucio.camtweaks.ui.screen.ClickGUI;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public abstract class Frame { public abstract class Frame<B extends Button> extends Widget {
private final MinecraftClient mc = MinecraftClient.getInstance(); protected String title;
public final String title; protected final List<B> buttons = new ArrayList<>();
private final List<Button> buttons = new ArrayList<>(); protected List<B> visibleButtons = new ArrayList<>();
private List<Button> visibleButtons = new ArrayList<>();
private int x, y, w, h; protected int renderY;
private int renderY; protected int totalHeight = 0;
private int dragX, dragY;
private boolean dragging; protected int dragX, dragY;
public int totalHeight = 0; protected boolean dragging;
public Frame(String title, int x, int y, int w, int h) { public Frame(String title, int x, int y, int w, int h) {
super(x, y, w, h);
this.title = title; this.title = title;
this.x = x;
this.y = y;
this.w = w;
this.h = h;
} }
public abstract void render(DrawContext ctx, int mouseX, int mouseY, float delta);
public void drawTooltips(DrawContext ctx, int mouseX, int mouseY) { public void drawTooltips(DrawContext ctx, int mouseX, int mouseY) {
for (Button button : visibleButtons) button.drawTooltip(ctx, mouseX, mouseY); for (Button button : visibleButtons) button.drawTooltip(ctx, mouseX, mouseY);
} }
public abstract void mouseClicked(int mouseX, int mouseY, int button); protected abstract void updateWidth();
public abstract void mouseDragged(int mouseX, int mouseY);
public void mouseReleased(int mouseX, int mouseY, int button) {
ClickGUI.INSTANCE.unselect(this);
}
public abstract void updateWidth(); @Override
// verificar si el puntero del ratón se encuentra encima
public List<Button> getButtons() { public boolean isHovered(int mouseX, int mouseY) {
return buttons; return mouseX > x && mouseX < x + w
} && mouseY > renderY && mouseY < renderY + h;
public List<Button> getVisibleButtons() {
return visibleButtons;
}
public boolean isHovered(double mouseX, double mouseY) {
return mouseX > x && mouseX < x + w && mouseY > renderY && mouseY < renderY + h;
} }
public void updateRenderY(int scrollOffset) { public void updateRenderY(int scrollOffset) {
renderY = y - scrollOffset; renderY = y - scrollOffset;
} }
public List<B> getButtons() { return buttons; }
public List<B> getVisibleButtons() { return visibleButtons; }
public int getRenderY() { return renderY; }
public void setRenderY(int renderY) { this.renderY = renderY; }
public int getTotalHeight() { return totalHeight; }
public void setTotalHeight(int totalHeight) { this.totalHeight = totalHeight; }
} }
@@ -0,0 +1,58 @@
package me.retucio.camtweaks.ui.widgets;
import me.retucio.camtweaks.ui.screen.ClickGUI;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
public abstract class Widget {
protected final MinecraftClient mc = MinecraftClient.getInstance();
protected int x, y, w, h;
public Widget(int x, int y, int w, int h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
public abstract void render(DrawContext ctx, int mouseX, int mouseY, float delta);
// input
public void onKey(int key, int action) {}
public void mouseClicked(int mouseX, int mouseY, int button) {}
public void mouseReleased(int mouseX, int mouseY, int button) {
ClickGUI.INSTANCE.unselect(this);
}
public void mouseDragged(int mouseX, int mouseY) {}
public void mouseScrolled(double amount) {}
public boolean isHovered(int mouseX, int mouseY) {
if (!ClickGUI.INSTANCE.canSelect(this)) return false;
return mouseX > x && mouseX < x + w &&
mouseY > y && mouseY < y + h;
}
// getters y setters
public int getX() { return x; }
public void setX(int x) { this.x = x; }
public int getY() { return y; }
public void setY( int y) {this.y = y; }
public int getW() { return w; }
public void setW(int w) { this.w = w; }
public int getH() { return h; }
public void setH(int h) { this.h = h; }
}
@@ -1,43 +1,48 @@
package me.retucio.camtweaks.ui.buttons; package me.retucio.camtweaks.ui.widgets.buttons;
import me.retucio.camtweaks.module.Module; import me.retucio.camtweaks.module.Module;
import me.retucio.camtweaks.ui.screen.ClickGUI; import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.frames.ModuleFrame; import me.retucio.camtweaks.ui.widgets.frames.ModuleFrame;
import me.retucio.camtweaks.ui.widgets.Button;
import me.retucio.camtweaks.util.Colors; import me.retucio.camtweaks.util.Colors;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text; import net.minecraft.text.Text;
// clase para el botón para cada módulo // clase para el botón para cada módulo
public class ModuleButton { public class ModuleButton extends Button {
private final Module module; private final Module module;
public ModuleFrame parent;
public int offset;
public final int height = 18; public final int height = 18;
public ModuleButton(Module module, ModuleFrame parent, int offset) { public ModuleButton(Module module, ModuleFrame parent, int offset) {
super(parent, offset);
this.module = module; this.module = module;
this.parent = parent;
this.offset = offset;
} }
public void render(DrawContext ctx, double mouseX, double mouseY, float delta) { @Override
public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
ctx.fill( // dibujar el contorno del botón ctx.fill( // dibujar el contorno del botón
parent.x + 2, parent.renderY + offset + 3, parent.getX() + 2, parent.getRenderY() + offset + 3,
parent.x + parent.w - 2 , parent.renderY + height + offset, parent.getX() + parent.getW() - 2 , parent.getRenderY() + height + offset,
determineColor(mouseX, mouseY)); determineColor(mouseX, mouseY));
ctx.drawText( // dibujar el nombre del módulo ctx.drawText( // dibujar el nombre del módulo
parent.mc.textRenderer, module.getName(), mc.textRenderer, module.getName(),
parent.x + 5, parent.renderY + offset + (height / 2) - (parent.mc.textRenderer.fontHeight / 2) + 2, parent.getX() + 5, parent.getRenderY() + offset + (height / 2) - (mc.textRenderer.fontHeight / 2) + 2,
-1, true); -1, true);
// dibujar "tooltips" (cajas de texto) al pasar el puntero encima del botón, para mostrar su descripción // dibujar "tooltips" (cajas de texto) al pasar el puntero encima del botón, para mostrar su descripción
if (isHovered((int) mouseX, (int) mouseY)) if (isHovered(mouseX, mouseY))
ctx.drawTooltip(Text.of(module.getDescription()), (int) mouseX, (int) mouseY + 20); drawTooltip(ctx, mouseX, mouseY);
} }
public void mouseClicked(double mouseX, double mouseY, int button) { @Override
public void drawTooltip(DrawContext ctx, int mouseX, int mouseY) {
ctx.drawTooltip(Text.of(module.getDescription()), mouseX, mouseY + 20);
}
@Override
public void mouseClicked(int mouseX, int mouseY, int button) {
if (isHovered((int) mouseX, (int) mouseY) && ClickGUI.INSTANCE.trySelect(this)) { if (isHovered((int) mouseX, (int) mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
if (button == 0) { // clic izquierdo para activar / desactivar el módulo if (button == 0) { // clic izquierdo para activar / desactivar el módulo
module.toggle(); module.toggle();
@@ -46,29 +51,36 @@ public class ModuleButton {
ClickGUI.INSTANCE.closeSettingsFrame(module); ClickGUI.INSTANCE.closeSettingsFrame(module);
else else
ClickGUI.INSTANCE.openSettingsFrame(module, ClickGUI.INSTANCE.openSettingsFrame(module,
parent.x + parent.w + 120, parent.renderY + offset); parent.getX() + parent.getW() + 120, parent.getRenderY() + offset);
} }
} }
} }
public void mouseReleased(double mouseX, double mouseY, int button) { @Override
ClickGUI.INSTANCE.unselect(this); public void mouseDragged(int mouseX, int mouseY) {}
}
@Override
public void onKey(int key, int action) {}
// verifica si el puntero del ratón se encuentra sobre el botón del módulo // verifica si el puntero del ratón se encuentra sobre el botón del módulo
@Override
public boolean isHovered(int mouseX, int mouseY) { public boolean isHovered(int mouseX, int mouseY) {
return ClickGUI.INSTANCE.canSelect(this) return ClickGUI.INSTANCE.canSelect(this)
&& mouseX > parent.x && mouseX > parent.getX()
&& mouseX < parent.x + parent.w && mouseX < parent.getX() + parent.getW()
&& mouseY > parent.renderY + offset && mouseY > parent.getRenderY() + offset
&& mouseY < parent.renderY + height + offset; && mouseY < parent.getRenderY() + height + offset;
} }
public int determineColor(double mouseX, double mouseY) { public int determineColor(double mouseX, double mouseY) {
// determina el color del botón, dependiendo de si está el puntero encima y si está activado // determina el color del botón, dependiendo de si está el puntero encima y si está activado
if (module.isEnabled()) if (module.isEnabled())
return isHovered((int) mouseX, (int) mouseY) ? Colors.mainColor.brighter().getRGB() : Colors.mainColor.getRGB(); return isHovered((int) mouseX, (int) mouseY)
return isHovered((int) mouseX, (int) mouseY) ? Colors.buttonColor.brighter().getRGB() : Colors.buttonColor.getRGB(); ? Colors.mainColor.brighter().getRGB()
: Colors.mainColor.getRGB();
return isHovered((int) mouseX, (int) mouseY)
? Colors.buttonColor.brighter().getRGB()
: Colors.buttonColor.getRGB();
} }
public Module getModule() { public Module getModule() {
@@ -0,0 +1,30 @@
package me.retucio.camtweaks.ui.widgets.buttons;
import me.retucio.camtweaks.module.settings.Setting;
import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
import me.retucio.camtweaks.ui.widgets.Button;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
// clase base para los botones de los ajustes
public abstract class SettingButton<S extends Setting> extends Button {
protected S setting;
public SettingButton(S setting, SettingsFrame parent, int offset) {
super(parent, offset);
this.setting = setting;
}
// dibujar "tooltips" (cajitas de texto bajo el puntero del ratón)
// con la descripción para asistir al usuario en el caso de que tenga down
@Override
public void drawTooltip(DrawContext ctx, int mouseX, int mouseY) {
if (isHovered(mouseX, mouseY))
ctx.drawTooltip(Text.of(setting.getDescription()), mouseX, mouseY + 20);
}
public S getSetting() {
return setting;
}
}
@@ -1,11 +1,13 @@
package me.retucio.camtweaks.ui.buttons; package me.retucio.camtweaks.ui.widgets.buttons.settings;
import me.retucio.camtweaks.module.settings.KeySetting; import me.retucio.camtweaks.module.settings.KeySetting;
import me.retucio.camtweaks.ui.widgets.buttons.SettingButton;
import me.retucio.camtweaks.ui.screen.ClickGUI; import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
import me.retucio.camtweaks.ui.frames.SettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
import me.retucio.camtweaks.util.ChatUtil; import me.retucio.camtweaks.util.ChatUtil;
import me.retucio.camtweaks.util.Colors; import me.retucio.camtweaks.util.Colors;
import me.retucio.camtweaks.util.KeyUtil;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.input.KeyInput; import net.minecraft.client.input.KeyInput;
import net.minecraft.client.option.KeyBinding; import net.minecraft.client.option.KeyBinding;
@@ -13,12 +15,10 @@ import net.minecraft.client.resource.language.I18n;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import static me.retucio.camtweaks.CameraTweaks.mc;
// botón para configurar la tecla asignada a un módulo. comienza a escuchar al hacerle clic // botón para configurar la tecla asignada a un módulo. comienza a escuchar al hacerle clic.
public class BindButton extends SettingButton { public class BindButton extends SettingButton<KeySetting> {
private final KeySetting setting;
private boolean listening = false; private boolean listening = false;
public BindButton(KeySetting setting, SettingsFrame parent, int offset) { public BindButton(KeySetting setting, SettingsFrame parent, int offset) {
@@ -27,22 +27,27 @@ public class BindButton extends SettingButton {
} }
@Override @Override
public void render(DrawContext ctx, double mouseX, double mouseY, float delta) { public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
int bgColor = isHovered((int) mouseX, (int) mouseY) // fondo
int bgColor = isHovered(mouseX, mouseY)
? Colors.buttonColor.brighter().getRGB() ? Colors.buttonColor.brighter().getRGB()
: Colors.buttonColor.getRGB(); : Colors.buttonColor.getRGB();
ctx.fill(x, y, x + w, y + h, bgColor); ctx.fill(x, y, x + w, y + h, bgColor);
// texto
String label = setting.getName() + ": " + (listening ? "..." : setting.getKeyName()); String label = setting.getName() + ": " + (listening ? "..." : setting.getKeyName());
ctx.drawText(parent.mc.textRenderer, label, x + 5, y + 3, -1, true); ctx.drawText(mc.textRenderer, label, x + 5, y + 3, -1, true);
} }
@Override @Override
public void mouseClicked(double mouseX, double mouseY, int button) { public void mouseClicked(int mouseX, int mouseY, int button) {
if (isHovered((int) mouseX, (int) mouseY) && ClickGUI.INSTANCE.trySelect(this)) { if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
if (button == 0) listening = !listening; if (button == 0) {
else if (button == 1 && mc.isShiftPressed()) listening = !listening;
}
else if (button == 1 && KeyUtil.isShiftDown()) {
setting.reset(); setting.reset();
}
} else { } else {
listening = false; listening = false;
} }
@@ -55,6 +60,7 @@ public class BindButton extends SettingButton {
setting.setKey(GLFW.GLFW_KEY_UNKNOWN); setting.setKey(GLFW.GLFW_KEY_UNKNOWN);
} else { } else {
for (KeyBinding bind : mc.options.allKeys) { for (KeyBinding bind : mc.options.allKeys) {
// no permitir usar la misma tecla para varias acciones, si el ajuste para esto está activado
boolean keyAlreadyBound = bind.matchesKey(new KeyInput(key, 0, 0)); boolean keyAlreadyBound = bind.matchesKey(new KeyInput(key, 0, 0));
boolean allowMultiple = ClientSettingsFrame.guiSettings.multipleKeybinds.isEnabled(); boolean allowMultiple = ClientSettingsFrame.guiSettings.multipleKeybinds.isEnabled();
@@ -71,20 +77,7 @@ public class BindButton extends SettingButton {
listening = false; listening = false;
} }
public boolean isFocused() { public boolean isFocused() {
return listening; return listening;
} }
public KeySetting getSetting() {
return setting;
}
@Override
public void mouseReleased(double mouseX, double mouseY, int button) {
ClickGUI.INSTANCE.unselect(this);
}
@Override
public void mouseDragged(double mouseX, double mouseY) {}
} }
@@ -1,30 +1,28 @@
package me.retucio.camtweaks.ui.buttons; package me.retucio.camtweaks.ui.widgets.buttons.settings;
import me.retucio.camtweaks.module.Module; import me.retucio.camtweaks.module.Module;
import me.retucio.camtweaks.module.settings.BooleanSetting; import me.retucio.camtweaks.module.settings.BooleanSetting;
import me.retucio.camtweaks.module.settings.OptionSetting; import me.retucio.camtweaks.module.settings.OptionSetting;
import me.retucio.camtweaks.ui.frames.SettingsFrame; import me.retucio.camtweaks.ui.widgets.buttons.SettingButton;
import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
import me.retucio.camtweaks.ui.screen.ClickGUI; import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.util.Colors; import me.retucio.camtweaks.util.Colors;
import me.retucio.camtweaks.util.KeyUtil;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static me.retucio.camtweaks.CameraTweaks.mc; // botón para los ajustes de selección única
public class ChooseButton<T> extends SettingButton<OptionSetting<T>> {
public class ChooseButton<T> extends SettingButton {
private final OptionSetting<T> setting;
private final Module dummy; private final Module dummy;
private final Map<T, BooleanSetting> optionButtons = new HashMap<>(); private final Map<T, BooleanSetting> optionButtons = new HashMap<>();
private T lastSelectedValue;
public ChooseButton(OptionSetting<T> setting, SettingsFrame parent, int offset) { public ChooseButton(OptionSetting<T> setting, SettingsFrame parent, int offset) {
super(setting, parent, offset); super(setting, parent, offset);
this.setting = setting; this.setting = setting;
this.lastSelectedValue = setting.getValue();
// crear un módulo "dummy" (falso) // crear un módulo "dummy" (falso)
dummy = new Module(setting.getName(), setting.getDescription()) { dummy = new Module(setting.getName(), setting.getDescription()) {
@@ -33,32 +31,27 @@ public class ChooseButton<T> extends SettingButton {
}; };
// ocultar cosas innecesarias // ocultar cosas innecesarias
dummy.getBind().setVisible(false); dummy.getSettings().get(0).setVisible(false);
dummy.getSettings().stream() dummy.getSettings().get(1).setVisible(false);
.filter(s -> s.getName().equalsIgnoreCase("modo de tecla")) dummy.getSettings().get(2).setVisible(false);
.findFirst()
.ifPresent(s -> s.setVisible(false));
dummy.getSettings().stream()
.filter(s -> s.getName().equalsIgnoreCase("notificar"))
.findFirst()
.ifPresent(s -> s.setVisible(false));
dummy.shouldSaveSettings(false); dummy.shouldSaveSettings(false);
} }
@Override @Override
public void render(DrawContext ctx, double mouseX, double mouseY, float delta) { public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
// fondo
int bgColor = isHovered(mouseX, mouseY) int bgColor = isHovered(mouseX, mouseY)
? Colors.buttonColor.brighter().getRGB() ? Colors.buttonColor.brighter().getRGB()
: Colors.buttonColor.getRGB(); : Colors.buttonColor.getRGB();
ctx.fill(x, y, x + w, y + h, bgColor); ctx.fill(x, y, x + w, y + h, bgColor);
// texto
String label = setting.getName() + ": " + setting.getDisplayName(setting.getValue()); String label = setting.getName() + ": " + setting.getDisplayName(setting.getValue());
ctx.drawText(parent.mc.textRenderer, label, x + 5, y + 3, -1, true); ctx.drawText(mc.textRenderer, label, x + 5, y + 3, -1, true);
} }
@Override @Override
public void mouseClicked(double mouseX, double mouseY, int button) { public void mouseClicked(int mouseX, int mouseY, int button) {
if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) { if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
// click izquierdo / derecho: abrir marco // click izquierdo / derecho: abrir marco
if (button <= 1 && !mc.isShiftPressed()) { if (button <= 1 && !mc.isShiftPressed()) {
@@ -68,9 +61,9 @@ public class ChooseButton<T> extends SettingButton {
} }
rebuildDummy(); rebuildDummy();
ClickGUI.INSTANCE.openListSettingsFrame(dummy, parent.x + 40, parent.y + 40); ClickGUI.INSTANCE.openListSettingsFrame(dummy, parent.getX() + 40, parent.getY() + 40);
// shift + clic derecho: restablecer valores // shift + clic derecho: restablecer valores
} else if (button == 1 && mc.isShiftPressed()) { } else if (button == 1 && KeyUtil.isShiftDown()) {
setting.reset(); setting.reset();
refreshDummy(); refreshDummy();
} }
@@ -119,16 +112,4 @@ public class ChooseButton<T> extends SettingButton {
} }
} }
} }
public OptionSetting<T> getSetting() {
return setting;
}
@Override
public void mouseReleased(double mouseX, double mouseY, int button) {
ClickGUI.INSTANCE.unselect(this);
}
@Override
public void mouseDragged(double mouseX, double mouseY) {}
} }
@@ -0,0 +1,78 @@
package me.retucio.camtweaks.ui.widgets.buttons.settings;
import me.retucio.camtweaks.module.settings.ColorSetting;
import me.retucio.camtweaks.ui.widgets.buttons.SettingButton;
import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
import me.retucio.camtweaks.util.Colors;
import me.retucio.camtweaks.util.KeyUtil;
import me.retucio.camtweaks.util.render.DrawUtil;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public class ColorButton extends SettingButton<ColorSetting> {
public ColorButton(ColorSetting setting, SettingsFrame parent, int offset) {
super(setting, parent, offset);
this.setting = setting;
}
@Override
public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
// fondo
Color bgColor = isHovered(mouseX, mouseY)
? Colors.buttonColor.brighter()
: Colors.buttonColor;
ctx.fill(x, y, x + w, y + h, bgColor.getRGB());
// prev. del color
int previewSize = h - 6;
int previewX = x + 5;
int previewY = y + 3;
DrawUtil.drawBorder(ctx, previewX - 1, previewY - 1, previewSize + 2, previewSize + 2, setting.isRainbow() ? Colors.mainColor.getRGB() : -1);
ctx.fill(previewX, previewY, previewX + previewSize, previewY + previewSize, setting.getColor().getRGB());
// texto
String label = setting.getName();
int textX = previewX + previewSize + 5;
ctx.drawText(mc.textRenderer, label, textX, y + 3, -1, true);
// valor actual
String valueText = setting.isRainbow() ? "gay." : Colors.ARGBtoHex(setting.getA(), setting.getR(), setting.getG(), setting.getB());
int valueWidth = mc.textRenderer.getWidth(valueText);
ctx.drawText(mc.textRenderer, valueText, x + w - valueWidth - 5, y + 3, -1, true);
}
@Override
public void mouseClicked(int mouseX, int mouseY, int button) {
if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
if (button == 0) {
// clic izq.: abrir selector de colores
ClickGUI.INSTANCE.openColorPickerFrame(
setting.getModule(), setting,
parent.getX() + parent.getW() + 120,
parent.getRenderY() + offset);
} else if (button == 1 && KeyUtil.isShiftDown()) {
// shift + clic dcho.: restablecer color
setting.reset();
}
}
}
@Override
public void drawTooltip(DrawContext ctx, int mouseX, int mouseY) {
if (isHovered(mouseX, mouseY)) {
List<Text> tooltip = new ArrayList<>();
tooltip.add(Text.of(setting.getDescription()));
tooltip.add(setting.getTooltipText());
ctx.drawTooltip(mc.textRenderer, tooltip, mouseX, mouseY + 20);
}
}
}
@@ -1,25 +1,22 @@
package me.retucio.camtweaks.ui.buttons; package me.retucio.camtweaks.ui.widgets.buttons.settings;
import me.retucio.camtweaks.module.settings.EnumSetting; import me.retucio.camtweaks.module.settings.EnumSetting;
import me.retucio.camtweaks.ui.screen.ClickGUI; import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.frames.SettingsFrame; import me.retucio.camtweaks.ui.widgets.buttons.SettingButton;
import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
import me.retucio.camtweaks.util.Colors; import me.retucio.camtweaks.util.Colors;
import me.retucio.camtweaks.util.KeyUtil; import me.retucio.camtweaks.util.KeyUtil;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import org.lwjgl.glfw.GLFW;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static me.retucio.camtweaks.CameraTweaks.mc;
// botón para los ajustes tipo EnumSetting (de modo) // botón para los ajustes tipo EnumSetting (de modo)
public class CycleButton<E extends Enum<E>> extends SettingButton { public class CycleButton<E extends Enum<E>> extends SettingButton<EnumSetting<E>> {
private final EnumSetting<E> setting;
public CycleButton(EnumSetting<E> setting, SettingsFrame parent, int offset) { public CycleButton(EnumSetting<E> setting, SettingsFrame parent, int offset) {
super(setting, parent, offset); super(setting, parent, offset);
@@ -27,64 +24,59 @@ public class CycleButton<E extends Enum<E>> extends SettingButton {
} }
@Override @Override
public void render(DrawContext ctx, double mouseX, double mouseY, float delta) { public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
int bgColor = isHovered((int) mouseX, (int) mouseY) // fondo
int bgColor = isHovered(mouseX, mouseY)
? Colors.buttonColor.brighter().getRGB() ? Colors.buttonColor.brighter().getRGB()
: Colors.buttonColor.getRGB(); : Colors.buttonColor.getRGB();
ctx.fill(x, y, x + w, y + h, bgColor); // fondo del botón ctx.fill(x, y, x + w, y + h, bgColor);
// texto del botón: nombre + valor de texto del enum // texto del botón: nombre + valor de texto del enum
String label = setting.getName() + ": " + setting.getValue().toString(); String label = setting.getName() + ": " + setting.getValue().toString();
ctx.drawText(parent.mc.textRenderer, label, x + 5, y + 3, -1, true); ctx.drawText(mc.textRenderer, label, x + 5, y + 3, -1, true);
}
@Override
public void mouseClicked(int mouseX, int mouseY, int button) {
if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
if (button == 0) {
setting.cycle(); // clic izquierdo -> ciclar
} else if (button == 1) {
// shift + clic derecho -> restablecer
if (KeyUtil.isShiftDown())
setting.reset();
else // solamente clic derecho -> ciclar valores pero hacia atrás
setting.cycleBackwards();
}
}
} }
@Override @Override
public void drawTooltip(DrawContext ctx, double mouseX, double mouseY) { public void drawTooltip(DrawContext ctx, int mouseX, int mouseY) {
if (isHovered((int) mouseX, (int) mouseY)) { if (isHovered(mouseX, mouseY)) {
Screen currentScreen = parent.mc.currentScreen; Screen currentScreen = mc.currentScreen;
if (currentScreen != null) { if (currentScreen != null) {
if (mc.isShiftPressed()) { if (mc.isShiftPressed()) {
// lista de opciones disponibles
List<Text> lines = new ArrayList<>(); List<Text> lines = new ArrayList<>();
lines.add(Text.literal("modos disponibles:")); lines.add(Text.literal("modos disponibles:"));
for (Enum<?> val : setting.getValues()) { for (Enum<?> val : setting.getValues()) {
if (val == setting.getValue()) if (val == setting.getValue())
lines.add(Text.literal("> " + val.toString() + " <").formatted(Formatting.GREEN)); lines.add(Text.literal("> " + val.toString() + " <").formatted(Formatting.GREEN));
else else
lines.add(Text.literal(val.toString())); lines.add(Text.literal(val.toString()));
} }
ctx.drawTooltip(parent.mc.textRenderer, lines, (int) mouseX, (int) mouseY + 20);
ctx.drawTooltip(mc.textRenderer, lines, mouseX, mouseY + 20);
} else { } else {
ctx.drawTooltip(Text.of(setting.getDescription()), (int) mouseX, (int) mouseY + 20); // descripción normal del ajuste
ctx.drawTooltip(Text.of(setting.getDescription()), mouseX, mouseY + 20);
} }
} }
} }
} }
@Override
public void mouseClicked(double mouseX, double mouseY, int button) {
if (isHovered((int) mouseX, (int) mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
if (button == 0) {
setting.cycle(); // clic izquierdo -> ciclar
} else if (button == 1) {
// shift + clic derecho -> restablecer
if (KeyUtil.isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT))
setting.reset();
else
setting.cycleBackwards(); // solamente clic derecho -> ciclar valores pero hacia atrás
}
}
}
public EnumSetting<E> getSetting() {
return setting;
}
@Override
public void mouseReleased(double mouseX, double mouseY, int button) {
ClickGUI.INSTANCE.unselect(this);
}
@Override
public void mouseDragged(double mouseX, double mouseY) {}
} }
@@ -1,21 +1,22 @@
package me.retucio.camtweaks.ui.buttons; package me.retucio.camtweaks.ui.widgets.buttons.settings;
import me.retucio.camtweaks.module.Module; import me.retucio.camtweaks.module.Module;
import me.retucio.camtweaks.module.settings.BooleanSetting; import me.retucio.camtweaks.module.settings.BooleanSetting;
import me.retucio.camtweaks.module.settings.ListSetting; import me.retucio.camtweaks.module.settings.ListSetting;
import me.retucio.camtweaks.ui.widgets.buttons.SettingButton;
import me.retucio.camtweaks.ui.screen.ClickGUI; import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.frames.SettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
import me.retucio.camtweaks.util.Colors; import me.retucio.camtweaks.util.Colors;
import me.retucio.camtweaks.util.KeyUtil;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import java.util.*; import java.util.*;
import static me.retucio.camtweaks.CameraTweaks.mc;
public class ListButton<T> extends SettingButton { // botón para los ajustes de selección múltiple
public class ListButton<T> extends SettingButton<ListSetting<T>> {
private final ListSetting<T> setting;
private final Module dummy; private final Module dummy;
private final Map<T, BooleanSetting> optionButtons = new HashMap<>(); private final Map<T, BooleanSetting> optionButtons = new HashMap<>();
@@ -31,50 +32,49 @@ public class ListButton<T> extends SettingButton {
}; };
// ocultar cosas innecesarias // ocultar cosas innecesarias
dummy.getBind().setVisible(false); dummy.getSettings().get(0).setVisible(false);
dummy.getSettings().stream() dummy.getSettings().get(1).setVisible(false);
.filter(s -> s.getName().equalsIgnoreCase("modo de tecla")) dummy.getSettings().get(2).setVisible(false);
.findFirst()
.ifPresent(s -> s.setVisible(false));
dummy.getSettings().stream()
.filter(s -> s.getName().equalsIgnoreCase("notificar"))
.findFirst()
.ifPresent(s -> s.setVisible(false));
dummy.shouldSaveSettings(false); dummy.shouldSaveSettings(false);
} }
@Override @Override
public void render(DrawContext ctx, double mouseX, double mouseY, float delta) { public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
// fondo
int bgColor = isHovered(mouseX, mouseY) int bgColor = isHovered(mouseX, mouseY)
? Colors.buttonColor.brighter().getRGB() ? Colors.buttonColor.brighter().getRGB()
: Colors.buttonColor.getRGB(); : Colors.buttonColor.getRGB();
ctx.fill(x, y, x + w, y + h, bgColor); ctx.fill(x, y, x + w, y + h, bgColor);
// texto: nombre + número de opciones seleccionadas / total de opciones
String label = setting.getName() + " (" + countEnabled() + "/" + setting.getOptions().size() + ")"; String label = setting.getName() + " (" + countEnabled() + "/" + setting.getOptions().size() + ")";
ctx.drawText(parent.mc.textRenderer, label, x + 5, y + 3, -1, true); ctx.drawText(mc.textRenderer, label, x + 5, y + 3, -1, true);
} }
@Override @Override
public void drawTooltip(DrawContext ctx, double mouseX, double mouseY) { public void drawTooltip(DrawContext ctx, int mouseX, int mouseY) {
if (isHovered(mouseX, mouseY)) if (isHovered(mouseX, mouseY))
ctx.drawTooltip(Text.of(setting.getDescription() + " (" + countEnabled() + " de " + setting.getOptions().size() + ")"), (int) mouseX, (int) mouseY); ctx.drawTooltip(Text.of(
setting.getDescription()
+ " (" + countEnabled() + " de "
+ setting.getOptions().size() + ")"),
mouseX, mouseY);
} }
@Override @Override
public void mouseClicked(double mouseX, double mouseY, int button) { public void mouseClicked(int mouseX, int mouseY, int button) {
if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) { if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
// click izquierdo / derecho: abrir marco // clic izquierdo / derecho: abrir marco
if (button <= 1 && !mc.isShiftPressed()) { if (button <= 1 && !KeyUtil.isShiftDown()) {
if (ClickGUI.INSTANCE.isSettingsFrameOpen(dummy)) { if (ClickGUI.INSTANCE.isSettingsFrameOpen(dummy)) {
ClickGUI.INSTANCE.closeSettingsFrame(dummy); ClickGUI.INSTANCE.closeSettingsFrame(dummy);
return; return;
} }
rebuildDummy(); rebuildDummy();
ClickGUI.INSTANCE.openListSettingsFrame(dummy, parent.x + 40, parent.y + 40); ClickGUI.INSTANCE.openListSettingsFrame(dummy, parent.getX() + 40, parent.getY() + 40);
// shift + clic derecho: restablecer valores // shift + clic derecho: restablecer valores
} else if (button == 1 && mc.isShiftPressed()) { } else if (button == 1 && KeyUtil.isShiftDown()) {
setting.reset(); setting.reset();
refreshDummy(); refreshDummy();
} }
@@ -107,16 +107,4 @@ public class ListButton<T> extends SettingButton {
private int countEnabled() { private int countEnabled() {
return (int) setting.getOptions().stream().filter(setting::isEnabled).count(); return (int) setting.getOptions().stream().filter(setting::isEnabled).count();
} }
public ListSetting<T> getSetting() {
return setting;
}
@Override
public void mouseReleased(double mouseX, double mouseY, int button) {
ClickGUI.INSTANCE.unselect(this);
}
@Override
public void mouseDragged(double mouseX, double mouseY) {}
} }
@@ -1,25 +1,22 @@
package me.retucio.camtweaks.ui.buttons; package me.retucio.camtweaks.ui.widgets.buttons.settings;
import me.retucio.camtweaks.event.SubscribeEvent;
import me.retucio.camtweaks.event.events.KeyEvent;
import me.retucio.camtweaks.module.settings.NumberSetting; import me.retucio.camtweaks.module.settings.NumberSetting;
import me.retucio.camtweaks.ui.screen.ClickGUI; import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame; import me.retucio.camtweaks.ui.widgets.buttons.SettingButton;
import me.retucio.camtweaks.ui.frames.SettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
import me.retucio.camtweaks.util.Colors; import me.retucio.camtweaks.util.Colors;
import me.retucio.camtweaks.util.KeyUtil;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import java.awt.*; import java.awt.*;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import static me.retucio.camtweaks.CameraTweaks.EVENT_BUS;
import static me.retucio.camtweaks.CameraTweaks.mc;
// slider (barrita) para los ajustes numéricos // slider (barrita) para los ajustes numéricos
public class SliderButton extends SettingButton { public class SliderButton extends SettingButton<NumberSetting> {
private final NumberSetting setting;
private boolean dragging = false; private boolean dragging = false;
public final DecimalFormat df; // usar formato decimal para el valor del ajuste public final DecimalFormat df; // usar formato decimal para el valor del ajuste
@@ -27,11 +24,11 @@ public class SliderButton extends SettingButton {
super(setting, parent, offset); super(setting, parent, offset);
this.setting = setting; this.setting = setting;
this.df = new DecimalFormat("#.##"); // solo mostrar dos décimales this.df = new DecimalFormat("#.##"); // solo mostrar dos décimales
EVENT_BUS.subscribe(this); // para poder escuchar teclas
} }
@Override @Override
public void render(DrawContext ctx, double mouseX, double mouseY, float delta) { public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
// fondo
Color bgColor = Colors.buttonColor; Color bgColor = Colors.buttonColor;
Color fillingColor = Colors.mainColor; Color fillingColor = Colors.mainColor;
@@ -48,9 +45,9 @@ public class SliderButton extends SettingButton {
ctx.fill(x, y, x + filled, y + h, fillingColor.getRGB()); ctx.fill(x, y, x + filled, y + h, fillingColor.getRGB());
String label = setting.getName() + ": " + df.format(setting.getValue()); String label = setting.getName() + ": " + df.format(setting.getValue());
ctx.drawText(parent.mc.textRenderer, label, x + 5, y + 3, -1, true); ctx.drawText(mc.textRenderer, label, x + 5, y + 3, -1, true);
// lógica para el arrastre (arrastramiento?) del valor // lógica para arrastrar el valor
if (dragging) { if (dragging) {
double newVal = setting.getMin() + ((mouseX - x) / (double) w) * (setting.getMax() - setting.getMin()); double newVal = setting.getMin() + ((mouseX - x) / (double) w) * (setting.getMax() - setting.getMin());
newVal = Math.max(setting.getMin(), Math.min(setting.getMax(), newVal)); newVal = Math.max(setting.getMin(), Math.min(setting.getMax(), newVal));
@@ -60,30 +57,27 @@ public class SliderButton extends SettingButton {
} }
@Override @Override
public void mouseClicked(double mouseX, double mouseY, int button) { public void onKey(int key, int action) {
if (isHovered((int) mouseX, (int) mouseY) && ClickGUI.INSTANCE.trySelect(this)) { // de no ser de esto, si se cierra la interfaz sin haber soltado el ratón mientras se arrastraba el valor,
// al reabrir la interfaz se seguía arrastrando, aun habiendo soltado ya el clic
if (key == GLFW.GLFW_KEY_ESCAPE
|| key == ClientSettingsFrame.guiSettings.getKey())
dragging = false;
}
@Override
public void mouseClicked(int mouseX, int mouseY, int button) {
if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
if (button == 0) dragging = true; // arrastrar con el clic izquierdo if (button == 0) dragging = true; // arrastrar con el clic izquierdo
else if (button == 1 && mc.isShiftPressed()) // restablecer al valor por defecto con shift izquerdo + clic derecho else if (button == 1 && KeyUtil.isShiftDown())
// restablecer al valor por defecto con shift + clic derecho
setting.reset(); setting.reset();
} }
} }
@Override @Override
public void mouseReleased(double mouseX, double mouseY, int button) { public void mouseReleased(int mouseX, int mouseY, int button) {
ClickGUI.INSTANCE.unselect(this); super.mouseReleased(mouseX, mouseY, button);
if (button == 0) dragging = false; if (button == 0) dragging = false;
} }
@Override
public void mouseDragged(double mouseX, double mouseY) {}
@SubscribeEvent
public void onKey(KeyEvent event) {
// de no ser de esto, si se cierra la interfaz sin haber soltado el ratón mientras se arrastraba el valor, al reabrir la interfaz se seguía arrastrando, aún habiendo soltado ya el clic
if (event.getKey() == GLFW.GLFW_KEY_ESCAPE || event.getKey() == ClientSettingsFrame.guiSettings.getKey()) dragging = false;
}
public NumberSetting getSetting() {
return setting;
}
} }
@@ -1,17 +1,18 @@
package me.retucio.camtweaks.ui.buttons; package me.retucio.camtweaks.ui.widgets.buttons.settings;
import me.retucio.camtweaks.module.settings.StringSetting; import me.retucio.camtweaks.module.settings.StringSetting;
import me.retucio.camtweaks.ui.widgets.buttons.SettingButton;
import me.retucio.camtweaks.ui.screen.ClickGUI; import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.frames.SettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
import me.retucio.camtweaks.util.Colors; import me.retucio.camtweaks.util.Colors;
import me.retucio.camtweaks.util.KeyUtil; import me.retucio.camtweaks.util.KeyUtil;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import static me.retucio.camtweaks.CameraTweaks.mc;
// botón para los ajustes que requieran introducir texto // botón para los ajustes que requieran introducir texto
public class TextButton extends SettingButton { @SuppressWarnings("RedundantLabeledSwitchRuleCodeBlock")
public class TextButton extends SettingButton<StringSetting> {
private boolean typing; private boolean typing;
private final StringSetting setting; private final StringSetting setting;
@@ -23,20 +24,21 @@ public class TextButton extends SettingButton {
} }
@Override @Override
public void render(DrawContext ctx, double mouseX, double mouseY, float delta) { public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
int bgColor = isHovered((int) mouseX, (int) mouseY) // fondo
int bgColor = isHovered(mouseX, mouseY)
? Colors.buttonColor.brighter().getRGB() ? Colors.buttonColor.brighter().getRGB()
: Colors.buttonColor.getRGB(); : Colors.buttonColor.getRGB();
ctx.fill(x, y, x + w, y + h, bgColor); ctx.fill(x, y, x + w, y + h, bgColor);
// texto
String label = setting.getName() + ": " + (typing ? buffer + "_" : setting.getValue()); String label = setting.getName() + ": " + (typing ? buffer + "_" : setting.getValue());
ctx.drawText(parent.mc.textRenderer, label, x + 5, y + 3, -1, true); ctx.drawText(mc.textRenderer, label, x + 5, y + 3, -1, true);
} }
@Override @Override
public void mouseClicked(double mouseX, double mouseY, int button) { public void mouseClicked(int mouseX, int mouseY, int button) {
if (isHovered((int) mouseX, (int) mouseY) && ClickGUI.INSTANCE.trySelect(this)) { if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
if (button == 0) { if (button == 0) {
typing = true; typing = true;
buffer.setLength(0); buffer.setLength(0);
@@ -51,13 +53,6 @@ public class TextButton extends SettingButton {
} }
@Override @Override
public void mouseReleased(double mouseX, double mouseY, int button) {
ClickGUI.INSTANCE.unselect(this);
}
@Override
public void mouseDragged(double mouseX, double mouseY) {}
public void onKey(int key, int action) { public void onKey(int key, int action) {
if (!typing || action == GLFW.GLFW_RELEASE) return; if (!typing || action == GLFW.GLFW_RELEASE) return;
@@ -69,10 +64,12 @@ public class TextButton extends SettingButton {
onBackspace(); onBackspace();
} case GLFW.GLFW_KEY_ESCAPE -> { } case GLFW.GLFW_KEY_ESCAPE -> {
typing = false; typing = false;
} case GLFW.GLFW_KEY_SPACE -> {
charTyped(' ');
} default -> { } default -> {
String c = KeyUtil.getKeyName(key); String c = KeyUtil.getKeyName(key);
if (c.length() == 1) { if (c.length() == 1) {
if (KeyUtil.isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT) || KeyUtil.isKeyDown(GLFW.GLFW_KEY_RIGHT_SHIFT)) if (KeyUtil.isShiftDown())
charTyped(KeyUtil.shiftKey(c).charAt(0)); charTyped(KeyUtil.shiftKey(c).charAt(0));
else else
charTyped(c.toLowerCase().charAt(0)); charTyped(c.toLowerCase().charAt(0));
@@ -91,11 +88,8 @@ public class TextButton extends SettingButton {
return typing; return typing;
} }
public StringSetting getSetting() {
return setting;
}
private void onBackspace() { private void onBackspace() {
if (!buffer.isEmpty()) buffer.deleteCharAt(buffer.length() - 1); if (!buffer.isEmpty())
buffer.deleteCharAt(buffer.length() - 1);
} }
} }
@@ -0,0 +1,49 @@
package me.retucio.camtweaks.ui.widgets.buttons.settings;
import me.retucio.camtweaks.module.settings.BooleanSetting;
import me.retucio.camtweaks.ui.widgets.buttons.SettingButton;
import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
import me.retucio.camtweaks.util.Colors;
import me.retucio.camtweaks.util.KeyUtil;
import net.minecraft.client.gui.DrawContext;
import java.awt.*;
// botón para los ajustes booleanos (funciona como un interruptor)
public class ToggleButton extends SettingButton<BooleanSetting> {
private final BooleanSetting setting;
public ToggleButton(BooleanSetting setting, SettingsFrame parent, int offset) {
super(setting, parent, offset);
this.setting = setting;
}
@Override
public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
// fondo
Color color = setting.isEnabled()
? Colors.enabledToggleButtonColor
: Colors.disabledToggleButtonColor;
if (isHovered(mouseX, mouseY))
color = color.brighter();
ctx.fill(x, y, x + w, y + h, color.getRGB());
// texto
ctx.drawText(mc.textRenderer, setting.getName(), x + 5, y + 3, -1, true);
}
@Override
public void mouseClicked(int mouseX, int mouseY, int button) {
if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
if (button == 0) setting.toggle(); // clic izquierdo para alternar
else if (button == 1 && KeyUtil.isShiftDown())
// shift + clic derecho para restablecer al valor por defecto
setting.reset();
}
}
}
@@ -1,61 +1,50 @@
package me.retucio.camtweaks.ui.frames; package me.retucio.camtweaks.ui.widgets.frames;
import me.retucio.camtweaks.CameraTweaks; import me.retucio.camtweaks.CameraTweaks;
import me.retucio.camtweaks.event.events.camtweaks.ModuleFrameEvent; import me.retucio.camtweaks.event.events.camtweaks.ModuleFrameEvent;
import me.retucio.camtweaks.module.Module; import me.retucio.camtweaks.module.Module;
import me.retucio.camtweaks.module.ModuleManager; import me.retucio.camtweaks.module.ModuleManager;
import me.retucio.camtweaks.ui.screen.ClickGUI; import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.buttons.ModuleButton; import me.retucio.camtweaks.ui.widgets.buttons.ModuleButton;
import me.retucio.camtweaks.ui.widgets.Frame;
import me.retucio.camtweaks.util.Colors; import me.retucio.camtweaks.util.Colors;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import java.util.ArrayList;
import java.util.List; import java.util.List;
// marco para los módulos // marco para los módulos
public class ModuleFrame { public class ModuleFrame extends Frame<ModuleButton> {
public int x, y, w, h; public boolean extended;
public int renderY;
public int dragX, dragY;
public int totalHeight = 0;
public boolean dragging, extended;
public final String title = "módulos";
private final List<ModuleButton> moduleButtons = new ArrayList<>();
public MinecraftClient mc = MinecraftClient.getInstance(); public MinecraftClient mc = MinecraftClient.getInstance();
public ModuleFrame(int x, int y, int w, int h) { public ModuleFrame(int x, int y, int w, int h) {
this.x = x; super("módulos", x, y, w, h);
this.y = y;
this.w = w;
this.h = h;
dragging = false; dragging = false;
extended = true; extended = true;
// determinar el saliente para cada botón de módulo // determinar el saliente para cada botón de módulo
int offset = h; int offset = h;
for (Module module : ModuleManager.INSTANCE.getModules()) { for (Module module : ModuleManager.INSTANCE.getModules()) {
moduleButtons.add(new ModuleButton(module, this, offset)); buttons.add(new ModuleButton(module, this, offset));
updateWidth(); updateWidth();
offset += h; offset += h;
} }
} }
public void updateRenderY(int scrollOffset) { @Override
renderY = y - scrollOffset; protected void updateWidth() {
}
void updateWidth() {
// asegurarse de que todos los botones caben en el marco, haciendo que la anchura se ajuste al texto más largo // asegurarse de que todos los botones caben en el marco, haciendo que la anchura se ajuste al texto más largo
if (mc.textRenderer == null) return; if (mc.textRenderer == null) return;
int maxWidth = mc.textRenderer.getWidth(title); int maxWidth = mc.textRenderer.getWidth(title);
for (ModuleButton button : moduleButtons) { for (ModuleButton button : buttons) {
String text = button.getModule().getName(); String text = button.getModule().getName();
int textWidth = mc.textRenderer.getWidth(text); int textWidth = mc.textRenderer.getWidth(text);
maxWidth = Math.max(maxWidth, textWidth); maxWidth = Math.max(maxWidth, textWidth);
@@ -63,6 +52,7 @@ public class ModuleFrame {
this.w = maxWidth + 22; this.w = maxWidth + 22;
} }
@Override
public void render(DrawContext ctx, int mouseX, int mouseY, float delta) { public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
updateWidth(); updateWidth();
ctx.fill(x, renderY, x + w, renderY + h, Colors.mainColor.getRGB()); // cabeza del marco ctx.fill(x, renderY, x + w, renderY + h, Colors.mainColor.getRGB()); // cabeza del marco
@@ -78,7 +68,7 @@ public class ModuleFrame {
renderY + (h / 2) - (mc.textRenderer.fontHeight / 2), renderY + (h / 2) - (mc.textRenderer.fontHeight / 2),
-1, true); -1, true);
List<ModuleButton> visibleButtons = moduleButtons.stream() List<ModuleButton> visibleButtons = buttons.stream()
.filter(mb -> mb.getModule().isSearchMatch()) .filter(mb -> mb.getModule().isSearchMatch())
.toList(); .toList();
@@ -93,7 +83,7 @@ public class ModuleFrame {
// dibujar los botones para cada módulo // dibujar los botones para cada módulo
int buttonY = renderY + h + 1; int buttonY = renderY + h + 1;
for (ModuleButton moduleButton : visibleButtons) { for (ModuleButton moduleButton : visibleButtons) {
moduleButton.offset = buttonY - renderY; moduleButton.setOffset(buttonY - renderY);
moduleButton.render(ctx, mouseX, mouseY, delta); moduleButton.render(ctx, mouseX, mouseY, delta);
buttonY += h; buttonY += h;
} }
@@ -102,13 +92,14 @@ public class ModuleFrame {
} }
} }
public void mouseClicked(double mouseX, double mouseY, int button) { @Override
public void mouseClicked(int mouseX, int mouseY, int button) {
// registrar clics // registrar clics
if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) { if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
if (button == 0) { // clic izquierdo para arrastrarlo if (button == 0) { // clic izquierdo para arrastrarlo
dragging = true; dragging = true;
dragX = (int) (mouseX - x); dragX = mouseX - x;
dragY = (int) (mouseY - y); dragY = mouseY - y;
} else if (button == 1) { // clic derecho para extenderlo } else if (button == 1) { // clic derecho para extenderlo
extended = !extended; extended = !extended;
CameraTweaks.EVENT_BUS.post(new ModuleFrameEvent.Extend()); CameraTweaks.EVENT_BUS.post(new ModuleFrameEvent.Extend());
@@ -117,7 +108,7 @@ public class ModuleFrame {
if (!extended) return; // solo dejar clicar en los módulos si el marco está extendido if (!extended) return; // solo dejar clicar en los módulos si el marco está extendido
List<ModuleButton> visibleModuleButtons = moduleButtons.stream() List<ModuleButton> visibleModuleButtons = buttons.stream()
.filter(mb -> mb.getModule().isSearchMatch()) .filter(mb -> mb.getModule().isSearchMatch())
.toList(); .toList();
@@ -126,17 +117,18 @@ public class ModuleFrame {
} }
// detectar cuándo se suelta el clic // detectar cuándo se suelta el clic
public void mouseReleased(double mouseX, double mouseY, int button) { @Override
public void mouseReleased(int mouseX, int mouseY, int button) {
ClickGUI.INSTANCE.unselect(this); ClickGUI.INSTANCE.unselect(this);
if (button == 0 && dragging) if (button == 0 && dragging)
dragging = false; dragging = false;
List<ModuleButton> visibleModuleButtons = moduleButtons.stream() List<ModuleButton> visibleModuleButtons = buttons.stream()
.filter(mb -> mb.getModule().isSearchMatch()) .filter(mb -> mb.getModule().isSearchMatch())
.toList(); .toList();
for (ModuleButton moduleButton : visibleModuleButtons) { for (ModuleButton moduleButton : visibleModuleButtons) {
if (moduleButton.isHovered((int) mouseX, (int) mouseY)) if (moduleButton.isHovered(mouseX, mouseY))
moduleButton.mouseReleased(mouseX, mouseY, button); moduleButton.mouseReleased(mouseX, mouseY, button);
} }
@@ -144,10 +136,11 @@ public class ModuleFrame {
CameraTweaks.EVENT_BUS.post(new ModuleFrameEvent.Move()); CameraTweaks.EVENT_BUS.post(new ModuleFrameEvent.Move());
} }
// verificar si el puntero del ratón se encuentra encima @Override
public boolean isHovered(double mouseX, double mouseY) { public void mouseDragged(int mouseX, int mouseY) {}
return mouseX > x && mouseX < x + w && mouseY > renderY && mouseY < renderY + h;
} @Override
public void onKey(int key, int action) {}
// actualizar la posición al arrastrar el marco // actualizar la posición al arrastrar el marco
public void updatePosition(double mouseX, double mouseY) { public void updatePosition(double mouseX, double mouseY) {
@@ -156,8 +149,4 @@ public class ModuleFrame {
y = (int) (mouseY - dragY); y = (int) (mouseY - dragY);
} }
} }
public List<ModuleButton> getButtons() {
return moduleButtons;
}
} }
@@ -1,97 +1,45 @@
package me.retucio.camtweaks.ui.frames; package me.retucio.camtweaks.ui.widgets.frames;
import me.retucio.camtweaks.CameraTweaks; import me.retucio.camtweaks.CameraTweaks;
import me.retucio.camtweaks.event.events.camtweaks.SettingsFrameEvent; import me.retucio.camtweaks.event.events.camtweaks.SettingsFrameEvent;
import me.retucio.camtweaks.module.Module; import me.retucio.camtweaks.module.Module;
import me.retucio.camtweaks.module.settings.*; import me.retucio.camtweaks.module.settings.*;
import me.retucio.camtweaks.ui.widgets.buttons.settings.*;
import me.retucio.camtweaks.ui.screen.ClickGUI; import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.buttons.*; import me.retucio.camtweaks.ui.widgets.buttons.*;
import me.retucio.camtweaks.ui.buttons.SliderButton; import me.retucio.camtweaks.ui.widgets.Frame;
import me.retucio.camtweaks.ui.buttons.TextButton;
import me.retucio.camtweaks.ui.buttons.ToggleButton;
import me.retucio.camtweaks.util.Colors; import me.retucio.camtweaks.util.Colors;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
// marco para los botones de los ajustes de cada módulo // marco para los botones de los ajustes de cada módulo
public class SettingsFrame { public class SettingsFrame extends Frame<SettingButton<? extends Setting>> {
final String title;
public Module module; public Module module;
final List<SettingButton> settingButtons = new ArrayList<>();
public List<SettingButton> visibleButtons = new ArrayList<>();
public int x, y, w, h;
public int renderY;
int dragX, dragY;
boolean dragging;
public int totalHeight = 0;
public final MinecraftClient mc = MinecraftClient.getInstance();
@SuppressWarnings({"rawtypes", "unchecked"})
public SettingsFrame(Module module, int x, int y, int w, int h) { public SettingsFrame(Module module, int x, int y, int w, int h) {
super("ajustes de " + module.getName(), x, y, w, h);
this.module = module; this.module = module;
// asegurarse de que no se sale de la pantalla // asegurarse de que no se sale de la pantalla
if (mc.getWindow() != null && x + w > mc.getWindow().getScaledWidth()) if (mc.getWindow() != null) {
this.x = mc.getWindow().getScaledWidth() - w; this.x = Math.clamp(this.x, 0, mc.getWindow().getScaledWidth() - w);
else this.y = Math.clamp(this.y, 0, mc.getWindow().getScaledHeight() - totalHeight - h);
this.x = x;
this.y = y;
this.w = w;
this.h = h;
// añadir el respectivo tipo de botón de cada ajuste a la lista de botones
int offset = h;
for (Setting setting : module.getSettings()) {
switch (setting) {
case BooleanSetting b -> {
addButton(new ToggleButton(b, this, offset));
offset += 18;
} case NumberSetting n -> {
addButton(new SliderButton(n, this, offset));
offset += 18;
} case EnumSetting e -> {
addButton(new CycleButton<>(e, this, offset));
offset += 18;
} case KeySetting k -> {
addButton(new BindButton(k, this, offset));
offset += 18;
} case StringSetting s -> {
addButton(new TextButton(s, this, offset));
offset += 18;
} case ListSetting l -> {
addButton(new ListButton<>(l, this, offset));
offset += 18;
} case ColorSetting c -> {
addButton(new ColorButton(c, this, offset));
offset += 18;
} case OptionSetting o -> {
addButton(new ChooseButton<>(o, this, offset));
offset += 18;
}
default -> {}
}
} }
title = "ajustes de " + module.getName();
visibleButtons = settingButtons.stream() addButtons();
visibleButtons = buttons.stream()
.filter(sb -> sb.getSetting().isVisible()) .filter(sb -> sb.getSetting().isVisible())
.toList(); .toList();
} }
public void addButton(SettingButton button) { @Override
settingButtons.add(button);
updateWidth(); // actualizar anchura del frame tras cada iteración
}
public void render(DrawContext ctx, int mouseX, int mouseY, float delta) { public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
updateWidth(); updateWidth();
@@ -117,7 +65,7 @@ public class SettingsFrame {
ctx.drawText(mc.textRenderer, title, titleX, titleY, -1, true); ctx.drawText(mc.textRenderer, title, titleX, titleY, -1, true);
ctx.drawText(mc.textRenderer, "×", x + w - mc.textRenderer.getWidth("×") - 8, titleY, closeButtonColor, true); ctx.drawText(mc.textRenderer, "×", x + w - mc.textRenderer.getWidth("×") - 8, titleY, closeButtonColor, true);
visibleButtons = settingButtons.stream() visibleButtons = buttons.stream()
.filter(sb -> sb.getSetting().isVisible() && sb.getSetting().isSearchMatch()) .filter(sb -> sb.getSetting().isVisible() && sb.getSetting().isSearchMatch())
.toList(); .toList();
@@ -143,7 +91,7 @@ public class SettingsFrame {
} }
int startButtonY = firstLineY - descBoxTop + descBoxBottom; int startButtonY = firstLineY - descBoxTop + descBoxBottom;
for (SettingButton sb : visibleButtons) { for (SettingButton<?> sb : visibleButtons) {
sb.setX(x + 4); sb.setX(x + 4);
sb.setY(startButtonY); sb.setY(startButtonY);
sb.setW(w - 8); sb.setW(w - 8);
@@ -153,75 +101,64 @@ public class SettingsFrame {
} }
} }
public void drawTooltips(DrawContext ctx, double mouseX, double mouseY) { @Override
for (SettingButton sb : visibleButtons) public void drawTooltips(DrawContext ctx, int mouseX, int mouseY) {
for (SettingButton<?> sb : visibleButtons)
sb.drawTooltip(ctx, mouseX, mouseY); sb.drawTooltip(ctx, mouseX, mouseY);
} }
@Override
public void mouseClicked(double mouseX, double mouseY, int button) { public void mouseClicked(int mouseX, int mouseY, int button) {
if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) { if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
if (isCloseButtonHovered(mouseX, mouseY)) { if (isCloseButtonHovered(mouseX, mouseY)) {
ClickGUI.INSTANCE.closeSettingsFrame(this.module); ClickGUI.INSTANCE.closeSettingsFrame(this.module);
return; return;
} if (button == 0) { } if (button == 0) {
dragging = true; dragging = true;
dragX = (int) (mouseX - x); dragX = mouseX - x;
dragY = (int) (mouseY - y); dragY = mouseY - y;
} else if (button == 1) { } else if (button == 1) {
ClickGUI.INSTANCE.closeSettingsFrame(module); ClickGUI.INSTANCE.closeSettingsFrame(module);
} }
} }
for (SettingButton sb : visibleButtons) for (SettingButton<?> sb : visibleButtons)
sb.mouseClicked(mouseX, mouseY, button); sb.mouseClicked(mouseX, mouseY, button);
} }
public void mouseReleased(double mouseX, double mouseY, int button) { @Override
ClickGUI.INSTANCE.unselect(this); public void mouseReleased(int mouseX, int mouseY, int button) {
super.mouseReleased(mouseX, mouseY, button);
if (button == 0) { if (button == 0) {
dragging = false; dragging = false;
CameraTweaks.EVENT_BUS.post(new SettingsFrameEvent.Move(this)); CameraTweaks.EVENT_BUS.post(new SettingsFrameEvent.Move(this));
} }
for (SettingButton sb : visibleButtons) for (SettingButton<?> sb : visibleButtons)
sb.mouseReleased(mouseX, mouseY, button); sb.mouseReleased(mouseX, mouseY, button);
} }
public void mouseDragged(double mouseX, double mouseY) { @Override
for (SettingButton sb : visibleButtons) public void mouseDragged(int mouseX, int mouseY) {
for (SettingButton<?> sb : visibleButtons)
sb.mouseDragged(mouseX, mouseY); sb.mouseDragged(mouseX, mouseY);
} }
public void updatePosition(double mouseX, double mouseY) { @Override
if (dragging) { public void onKey(int key, int action) {}
x = (int) (mouseX - dragX);
y = (int) (mouseY - dragY);
}
}
public boolean isHovered(double mouseX, double mouseY) { @Override
return mouseX > x && mouseX < x + w && public void updateWidth() {
mouseY > renderY && mouseY < renderY + h;
}
public boolean isCloseButtonHovered(double mouseX, double mouseY) {
return mouseX > x + w - mc.textRenderer.getWidth("×") - 12 && mouseX < x + w - 4
&& mouseY > renderY + 4 && mouseY < renderY + h - 4;
}
@SuppressWarnings("rawtypes")
void updateWidth() {
// asegurarse de que todos los botones caben en el marco, haciendo que la anchura se ajuste al texto más largo // asegurarse de que todos los botones caben en el marco, haciendo que la anchura se ajuste al texto más largo
if (mc.textRenderer == null) return; if (mc.textRenderer == null) return;
int maxWidth = mc.textRenderer.getWidth(title); int maxWidth = mc.textRenderer.getWidth(title);
for (SettingButton button : settingButtons) { for (SettingButton<?> button : buttons) {
String text = button.getSetting().getName(); String text = button.getSetting().getName();
switch (button) { switch (button) {
case SliderButton sliderButton -> text += ": " + sliderButton.df.format((sliderButton.getSetting()).getValue()); case SliderButton sliderButton -> text += ": " + sliderButton.df.format((sliderButton.getSetting()).getValue());
case CycleButton cycleButton -> text += ": " + cycleButton.getSetting().getValue(); case CycleButton<?> cycleButton -> text += ": " + cycleButton.getSetting().getValue();
case BindButton bindButton -> text += ": " + bindButton.getSetting().getKeyName(); case BindButton bindButton -> text += ": " + bindButton.getSetting().getKeyName();
case TextButton textButton -> text += ": " + textButton.getSetting().getValue(); case TextButton textButton -> text += ": " + textButton.getSetting().getValue();
default -> {} default -> {}
@@ -233,6 +170,14 @@ public class SettingsFrame {
this.w = maxWidth + 30; this.w = maxWidth + 30;
} }
public void updatePosition(double mouseX, double mouseY) {
if (dragging) {
x = (int) (mouseX - dragX);
y = (int) (mouseY - dragY);
}
}
private List<String> wrapDescription(String text, int maxWidth) { private List<String> wrapDescription(String text, int maxWidth) {
List<String> lines = new ArrayList<>(); List<String> lines = new ArrayList<>();
if (mc.textRenderer == null) return lines; if (mc.textRenderer == null) return lines;
@@ -253,11 +198,56 @@ public class SettingsFrame {
return lines; return lines;
} }
public List<SettingButton> getButtons() { private void addButtons() {
return settingButtons; int offset = h;
for (Setting setting : module.getSettings()) {
switch (setting) {
case BooleanSetting b -> {
addButton(new ToggleButton(b, this, offset));
offset += 18;
}
case NumberSetting n -> {
addButton(new SliderButton(n, this, offset));
offset += 18;
}
case EnumSetting<?> e -> {
addButton(new CycleButton<>(e, this, offset));
offset += 18;
}
case KeySetting k -> {
addButton(new BindButton(k, this, offset));
offset += 18;
}
case StringSetting s -> {
addButton(new TextButton(s, this, offset));
offset += 18;
}
case ListSetting<?> l -> {
addButton(new ListButton<>(l, this, offset));
offset += 18;
}
case ColorSetting c -> {
addButton(new ColorButton(c, this, offset));
offset += 18;
}
case OptionSetting<?> o -> {
addButton(new ChooseButton<>(o, this, offset));
offset += 18;
}
default -> {
}
}
}
} }
public void updateRenderY(int scrollOffset) { public void addButton(SettingButton<?> button) {
renderY = y - scrollOffset; buttons.add(button);
updateWidth(); // actualizar anchura del frame tras cada iteración
}
protected boolean isCloseButtonHovered(double mouseX, double mouseY) {
return mouseX > x + w - mc.textRenderer.getWidth("×") - 12 && mouseX < x + w - 4
&& mouseY > renderY + 4 && mouseY < renderY + h - 4;
} }
} }
@@ -1,10 +1,11 @@
package me.retucio.camtweaks.ui.frames; package me.retucio.camtweaks.ui.widgets.frames.settings;
import me.retucio.camtweaks.CameraTweaks; import me.retucio.camtweaks.CameraTweaks;
import me.retucio.camtweaks.event.events.camtweaks.GUISettingsFrameEvent; import me.retucio.camtweaks.event.events.camtweaks.GUISettingsFrameEvent;
import me.retucio.camtweaks.module.modules.GUI; import me.retucio.camtweaks.module.modules.GUI;
import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
import me.retucio.camtweaks.ui.screen.ClickGUI; import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.buttons.SettingButton; import me.retucio.camtweaks.ui.widgets.buttons.SettingButton;
import me.retucio.camtweaks.util.Colors; import me.retucio.camtweaks.util.Colors;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
@@ -14,10 +15,10 @@ public class ClientSettingsFrame extends SettingsFrame {
public static final GUI guiSettings = new GUI(); public static final GUI guiSettings = new GUI();
public boolean extended = false; public boolean extended = false;
private final String title = "ajustes del mod";
public ClientSettingsFrame(int x, int y, int w, int h) { public ClientSettingsFrame(int x, int y, int w, int h) {
super(guiSettings, x, y, w, h); super(guiSettings, x, y, w, h);
title = "ajustes del mod";
} }
@Override @Override
@@ -35,7 +36,7 @@ public class ClientSettingsFrame extends SettingsFrame {
renderY + (h / 2) - (mc.textRenderer.fontHeight / 2), renderY + (h / 2) - (mc.textRenderer.fontHeight / 2),
-1, true); -1, true);
List<SettingButton> visibleButtons = settingButtons.stream() List<SettingButton<?>> visibleButtons = buttons.stream()
.filter(sb -> sb.getSetting().isVisible() && sb.getSetting().isSearchMatch()) .filter(sb -> sb.getSetting().isVisible() && sb.getSetting().isSearchMatch())
.toList(); .toList();
@@ -44,7 +45,7 @@ public class ClientSettingsFrame extends SettingsFrame {
totalHeight = visibleButtons.size() * h; totalHeight = visibleButtons.size() * h;
ctx.fill(x, currentY - 2, x + w, currentY + totalHeight, Colors.frameBGColor.getRGB()); ctx.fill(x, currentY - 2, x + w, currentY + totalHeight, Colors.frameBGColor.getRGB());
for (SettingButton sb : visibleButtons) { for (SettingButton<?> sb : visibleButtons) {
sb.setX(x + 4); sb.setX(x + 4);
sb.setY(currentY); sb.setY(currentY);
sb.setW(w - 8); sb.setW(w - 8);
@@ -57,12 +58,12 @@ public class ClientSettingsFrame extends SettingsFrame {
} }
@Override @Override
public void mouseClicked(double mouseX, double mouseY, int button) { public void mouseClicked(int mouseX, int mouseY, int button) {
if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) { if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
if (button == 0) { if (button == 0) {
dragging = true; dragging = true;
dragX = (int) (mouseX - x); dragX = mouseX - x;
dragY = (int) (mouseY - y); dragY = mouseY - y;
} else if (button == 1) { } else if (button == 1) {
extended = !extended; extended = !extended;
CameraTweaks.EVENT_BUS.post(new GUISettingsFrameEvent.Extend()); CameraTweaks.EVENT_BUS.post(new GUISettingsFrameEvent.Extend());
@@ -70,12 +71,12 @@ public class ClientSettingsFrame extends SettingsFrame {
} }
if (!extended) return; // solo dejar clicar en los módulos si el marco está extendido if (!extended) return; // solo dejar clicar en los módulos si el marco está extendido
for (SettingButton settingButton : settingButtons) for (SettingButton<?> settingButton : buttons)
settingButton.mouseClicked(mouseX, mouseY, button); settingButton.mouseClicked(mouseX, mouseY, button);
} }
@Override @Override
public void mouseReleased(double mouseX, double mouseY, int button) { public void mouseReleased(int mouseX, int mouseY, int button) {
ClickGUI.INSTANCE.unselect(this); ClickGUI.INSTANCE.unselect(this);
if (button == 0 && dragging) if (button == 0 && dragging)
CameraTweaks.EVENT_BUS.post(new GUISettingsFrameEvent.Move()); CameraTweaks.EVENT_BUS.post(new GUISettingsFrameEvent.Move());
@@ -84,7 +85,7 @@ public class ClientSettingsFrame extends SettingsFrame {
} }
@Override @Override
public void drawTooltips(DrawContext ctx, double mouseX, double mouseY) { public void drawTooltips(DrawContext ctx, int mouseX, int mouseY) {
if (!extended) return; if (!extended) return;
super.drawTooltips(ctx, mouseX, mouseY); super.drawTooltips(ctx, mouseX, mouseY);
} }
@@ -1,11 +1,14 @@
package me.retucio.camtweaks.ui.frames; package me.retucio.camtweaks.ui.widgets.frames.settings;
import me.retucio.camtweaks.module.Module; import me.retucio.camtweaks.module.Module;
import me.retucio.camtweaks.module.settings.Setting; import me.retucio.camtweaks.module.settings.Setting;
import me.retucio.camtweaks.module.settings.BooleanSetting; import me.retucio.camtweaks.module.settings.BooleanSetting;
import me.retucio.camtweaks.module.settings.ColorSetting; import me.retucio.camtweaks.module.settings.ColorSetting;
import me.retucio.camtweaks.module.settings.NumberSetting; import me.retucio.camtweaks.module.settings.NumberSetting;
import me.retucio.camtweaks.ui.buttons.*; import me.retucio.camtweaks.ui.widgets.buttons.*;
import me.retucio.camtweaks.ui.widgets.buttons.settings.SliderButton;
import me.retucio.camtweaks.ui.widgets.buttons.settings.ToggleButton;
import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
import me.retucio.camtweaks.ui.screen.ClickGUI; import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.util.Colors; import me.retucio.camtweaks.util.Colors;
import me.retucio.camtweaks.util.render.DrawUtil; import me.retucio.camtweaks.util.render.DrawUtil;
@@ -86,7 +89,7 @@ public class ColorPickerFrame extends SettingsFrame {
}); });
} }
settingButtons.clear(); buttons.clear();
Module originalModule = this.module; Module originalModule = this.module;
this.module = dummyModule; this.module = dummyModule;
@@ -238,11 +241,11 @@ public class ColorPickerFrame extends SettingsFrame {
// botones de ajustes // botones de ajustes
int startButtonY = alphaPickerY + alphaPickerHeight + padding; int startButtonY = alphaPickerY + alphaPickerHeight + padding;
visibleButtons = settingButtons.stream() visibleButtons = buttons.stream()
.filter(sb -> sb.getSetting().isVisible() && sb.getSetting().isSearchMatch()) .filter(sb -> sb.getSetting().isVisible() && sb.getSetting().isSearchMatch())
.toList(); .toList();
for (SettingButton sb : visibleButtons) { for (SettingButton<?> sb : visibleButtons) {
sb.setX(x + 4); sb.setX(x + 4);
sb.setY(startButtonY); sb.setY(startButtonY);
sb.setW(w - 8); sb.setW(w - 8);
@@ -310,7 +313,7 @@ public class ColorPickerFrame extends SettingsFrame {
// DETECCIÓN DE INPUTS // DETECCIÓN DE INPUTS
@Override @Override
public void mouseClicked(double mouseX, double mouseY, int button) { public void mouseClicked(int mouseX, int mouseY, int button) {
if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) { if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
if (isCloseButtonHovered(mouseX, mouseY)) { if (isCloseButtonHovered(mouseX, mouseY)) {
ClickGUI.INSTANCE.closeSettingsFrame(this.dummyModule); ClickGUI.INSTANCE.closeSettingsFrame(this.dummyModule);
@@ -344,13 +347,13 @@ public class ColorPickerFrame extends SettingsFrame {
updateColorFromPicker((int) mouseX, (int) mouseY); updateColorFromPicker((int) mouseX, (int) mouseY);
} }
for (SettingButton sb : visibleButtons) for (SettingButton<?> sb : visibleButtons)
sb.mouseClicked(mouseX, mouseY, button); sb.mouseClicked(mouseX, mouseY, button);
} }
@Override @Override
public void mouseReleased(double mouseX, double mouseY, int button) { public void mouseReleased(int mouseX, int mouseY, int button) {
ClickGUI.INSTANCE.unselect(this); super.mouseReleased(mouseX, mouseY, button);
if (button == 0) { // soltar todo if (button == 0) { // soltar todo
dragging = false; dragging = false;
pickingHue = false; pickingHue = false;
@@ -358,16 +361,16 @@ public class ColorPickerFrame extends SettingsFrame {
pickingAlpha = false; pickingAlpha = false;
} }
for (SettingButton sb : visibleButtons) for (SettingButton<?> sb : visibleButtons)
sb.mouseReleased(mouseX, mouseY, button); sb.mouseReleased(mouseX, mouseY, button);
} }
@Override @Override
public void mouseDragged(double mouseX, double mouseY) { public void mouseDragged(int mouseX, int mouseY) {
if (pickingHue || pickingSaturationBrightness || pickingAlpha) if (pickingHue || pickingSaturationBrightness || pickingAlpha)
updateColorFromPicker((int) mouseX, (int) mouseY); updateColorFromPicker((int) mouseX, (int) mouseY);
for (SettingButton sb : visibleButtons) for (SettingButton<?> sb : visibleButtons)
sb.mouseDragged(mouseX, mouseY); sb.mouseDragged(mouseX, mouseY);
} }
@@ -1,14 +1,14 @@
package me.retucio.camtweaks.ui.widgets; package me.retucio.camtweaks.ui.widgets.misc;
import me.retucio.camtweaks.ui.screen.ClickGUI; import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
import me.retucio.camtweaks.ui.widgets.Widget;
import me.retucio.camtweaks.util.Colors; import me.retucio.camtweaks.util.Colors;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import java.awt.*; import java.awt.*;
public class ScrollBarWidget { public class ScrollBarWidget extends Widget {
private boolean dragging; private boolean dragging;
private int dragY, scrollStart; private int dragY, scrollStart;
@@ -16,11 +16,13 @@ public class ScrollBarWidget {
private int contentHeight, windowHeight; private int contentHeight, windowHeight;
private final MinecraftClient mc = MinecraftClient.getInstance(); public ScrollBarWidget() {
// las coordenadas no importan porque está estático
super(0, 0, 0, 0);
}
public ScrollBarWidget() {} @Override
public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
public void render(DrawContext ctx, double mouseX, double mouseY) {
if (contentHeight <= windowHeight || !ClientSettingsFrame.guiSettings.scrollBar.isEnabled()) return; if (contentHeight <= windowHeight || !ClientSettingsFrame.guiSettings.scrollBar.isEnabled()) return;
int trackX1 = mc.getWindow().getScaledWidth() - 10; int trackX1 = mc.getWindow().getScaledWidth() - 10;
@@ -40,33 +42,37 @@ public class ScrollBarWidget {
ctx.fill(trackX1 + 1, thumbY + 1, trackX2 - 1, thumbY + thumbHeight - 1, thumbColor.getRGB()); ctx.fill(trackX1 + 1, thumbY + 1, trackX2 - 1, thumbY + thumbHeight - 1, thumbColor.getRGB());
} }
public void mouseClicked(double mouseX, double mouseY, int button) { @Override
public void mouseClicked(int mouseX, int mouseY, int button) {
if (button != 0 || !ClientSettingsFrame.guiSettings.scrollBar.isEnabled()) return; if (button != 0 || !ClientSettingsFrame.guiSettings.scrollBar.isEnabled()) return;
if (isThumbHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) { if (isThumbHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
dragging = true; dragging = true;
dragY = (int) mouseY; dragY = mouseY;
scrollStart = scrollOffset; scrollStart = scrollOffset;
} }
} }
public void mouseReleased(double mouseX, double mouseY, int button) { @Override
public void mouseReleased(int mouseX, int mouseY, int button) {
ClickGUI.INSTANCE.unselect(this); ClickGUI.INSTANCE.unselect(this);
dragging = false; dragging = false;
} }
public void mouseDragged(double mouseY) { @Override
public void mouseDragged(int mouseX, int mouseY) {
if (!dragging || !ClientSettingsFrame.guiSettings.scrollBar.isEnabled()) return; if (!dragging || !ClientSettingsFrame.guiSettings.scrollBar.isEnabled()) return;
int thumbHeight = getThumbHeight(); int thumbHeight = getThumbHeight();
int trackHeight = windowHeight - thumbHeight; int trackHeight = windowHeight - thumbHeight;
float ratio = (float) (contentHeight - windowHeight) / trackHeight; float ratio = (float) (contentHeight - windowHeight) / trackHeight;
int deltaY = (int) mouseY - dragY; int deltaY = mouseY - dragY;
scrollOffset = scrollStart + (int) (deltaY * ratio); scrollOffset = scrollStart + (int) (deltaY * ratio);
clampOffset(); clampOffset();
} }
public void onMouseScroll(double amount) { @Override
public void mouseScrolled(double amount) {
if (contentHeight <= windowHeight) return; if (contentHeight <= windowHeight) return;
scrollOffset -= (int) amount * 20; scrollOffset -= (int) amount * 20;
clampOffset(); clampOffset();
@@ -1,11 +1,11 @@
package me.retucio.camtweaks.ui.widgets; package me.retucio.camtweaks.ui.widgets.misc;
import me.retucio.camtweaks.config.ConfigManager; import me.retucio.camtweaks.config.ConfigManager;
import me.retucio.camtweaks.ui.screen.ClickGUI; import me.retucio.camtweaks.ui.screen.ClickGUI;
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
import me.retucio.camtweaks.ui.widgets.Widget;
import me.retucio.camtweaks.util.Colors; import me.retucio.camtweaks.util.Colors;
import me.retucio.camtweaks.util.KeyUtil; import me.retucio.camtweaks.util.KeyUtil;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
@@ -13,28 +13,22 @@ import org.lwjgl.glfw.GLFW;
import java.awt.Color; import java.awt.Color;
public class SearchBarWidget { public class SearchBarWidget extends Widget {
private boolean dragging; private boolean dragging;
private int dragX, dragY; private int dragX, dragY;
private int x, y;
private final int w, h;
private int renderY; private int renderY;
private boolean focused; private boolean focused;
private final StringBuilder buffer = new StringBuilder(); private final StringBuilder buffer = new StringBuilder();
private final MinecraftClient mc = MinecraftClient.getInstance();
public SearchBarWidget(int x, int y, int w, int h) { public SearchBarWidget(int x, int y, int w, int h) {
this.x = x; super(x, y, w, h);
this.y = y;
this.w = w;
this.h = h;
} }
public void render(DrawContext ctx, double mouseX, double mouseY, float delta) { @Override
public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
if (!ClientSettingsFrame.guiSettings.searchBar.isEnabled()) return; if (!ClientSettingsFrame.guiSettings.searchBar.isEnabled()) return;
Color textFieldColor = isTextFieldHovered(mouseX, mouseY) Color textFieldColor = isTextFieldHovered(mouseX, mouseY)
@@ -66,7 +60,8 @@ public class SearchBarWidget {
isClearButtonHovered(mouseX, mouseY) ? Color.RED.getRGB() : -1, true); isClearButtonHovered(mouseX, mouseY) ? Color.RED.getRGB() : -1, true);
} }
public void mouseClicked(double mouseX, double mouseY, int button) { @Override
public void mouseClicked(int mouseX, int mouseY, int button) {
if (button != 0 || !ClientSettingsFrame.guiSettings.searchBar.isEnabled()) return; if (button != 0 || !ClientSettingsFrame.guiSettings.searchBar.isEnabled()) return;
if (isHandleHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) { if (isHandleHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
dragging = true; dragging = true;
@@ -78,7 +73,8 @@ public class SearchBarWidget {
focused = isTextFieldHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this); focused = isTextFieldHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this);
} }
public void mouseReleased(double mouseX, double mouseY, int button) { @Override
public void mouseReleased(int mouseX, int mouseY, int button) {
if (!ClientSettingsFrame.guiSettings.searchBar.isEnabled()) return; if (!ClientSettingsFrame.guiSettings.searchBar.isEnabled()) return;
ClickGUI.INSTANCE.unselect(this); ClickGUI.INSTANCE.unselect(this);
if (button == 0 && dragging) { if (button == 0 && dragging) {
@@ -87,6 +83,12 @@ public class SearchBarWidget {
} }
} }
@Override
public void mouseDragged(int mouseX, int mouseY) {
}
@Override
public void onKey(int key, int action) { public void onKey(int key, int action) {
if (!ClientSettingsFrame.guiSettings.searchBar.isEnabled()) return; if (!ClientSettingsFrame.guiSettings.searchBar.isEnabled()) return;
if (!focused || action == GLFW.GLFW_RELEASE) return; if (!focused || action == GLFW.GLFW_RELEASE) return;
@@ -162,20 +164,4 @@ public class SearchBarWidget {
ConfigManager.setSearchBarPosition(x, y); ConfigManager.setSearchBarPosition(x, y);
} }
} }
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
} }
@@ -3,7 +3,7 @@ package me.retucio.camtweaks.util;
import me.retucio.camtweaks.CameraTweaks; import me.retucio.camtweaks.CameraTweaks;
import me.retucio.camtweaks.event.SubscribeEvent; import me.retucio.camtweaks.event.SubscribeEvent;
import me.retucio.camtweaks.event.events.camtweaks.LoadModuleManagerEvent; import me.retucio.camtweaks.event.events.camtweaks.LoadModuleManagerEvent;
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame; import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
@@ -4,7 +4,7 @@ import net.minecraft.util.Formatting;
import java.awt.Color; import java.awt.Color;
import static me.retucio.camtweaks.ui.frames.ClientSettingsFrame.guiSettings; import static me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame.guiSettings;
// clase para los colores // clase para los colores