v2.0.1
This commit is contained in:
1 parent
347ec658bb
commit
48899f85f9
36 files changed
+728
-824
No files matched your search
+1
-3
@@ -43,6 +43,4 @@ replay_*.log
|
||||
|
||||
todo.txt
|
||||
cambios.md
|
||||
remappedSrc/
|
||||
src/main/java/me/retucio/camtweaks/ui/widgets/Frame.java
|
||||
src/main/java/me/retucio/camtweaks/ui/widgets/Button.java
|
||||
remappedSrc/
|
||||
+1
-1
@@ -6,7 +6,7 @@ yarn_mappings=1.21.10+build.2
|
||||
loader_version=0.17.3
|
||||
loom_version=1.11-SNAPSHOT
|
||||
|
||||
mod_version=2.0
|
||||
mod_version=2.1
|
||||
maven_group=me.retucio
|
||||
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.hud.HudEditorScreen;
|
||||
import me.retucio.camtweaks.ui.hud.HudRenderer;
|
||||
import me.retucio.camtweaks.ui.buttons.BindButton;
|
||||
import me.retucio.camtweaks.ui.buttons.SettingButton;
|
||||
import me.retucio.camtweaks.ui.buttons.TextButton;
|
||||
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame;
|
||||
import me.retucio.camtweaks.ui.frames.SettingsFrame;
|
||||
import me.retucio.camtweaks.ui.widgets.buttons.settings.BindButton;
|
||||
import me.retucio.camtweaks.ui.widgets.buttons.SettingButton;
|
||||
import me.retucio.camtweaks.ui.widgets.buttons.settings.TextButton;
|
||||
import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
|
||||
import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
|
||||
|
||||
import me.retucio.camtweaks.ui.widgets.Button;
|
||||
import me.retucio.camtweaks.util.*;
|
||||
|
||||
|
||||
@@ -84,7 +85,7 @@ public class CameraTweaks implements ClientModInitializer {
|
||||
|
||||
EVENT_BUS.register(this);
|
||||
|
||||
EVENT_BUS.register(new HudRenderer());
|
||||
EVENT_BUS.register(HudRenderer.class);
|
||||
|
||||
EVENT_BUS.register(ChatUtil.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
|
||||
private boolean isAnySettingButtonFocused() {
|
||||
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()))
|
||||
return true;
|
||||
return false;
|
||||
@@ -173,8 +174,8 @@ public class CameraTweaks implements ClientModInitializer {
|
||||
private void handleSettingButtonsKey(int key, int action) {
|
||||
for (SettingsFrame sf : ClickGUI.INSTANCE.getSettingsFrames()) {
|
||||
for (SettingButton sb : sf.getButtons()) {
|
||||
if (sb instanceof BindButton b) b.onKey(key, action);
|
||||
else if (sb instanceof TextButton t) t.onKey(key, action);
|
||||
if (sb instanceof BindButton bb) bb.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.builder.LiteralArgumentBuilder;
|
||||
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 net.minecraft.command.CommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
@@ -80,39 +80,39 @@ public class ClientConfig {
|
||||
|
||||
@SubscribeEvent
|
||||
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();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onExtendModuleFrame(ModuleFrameEvent.Extend event) {
|
||||
extendableFrames.put("M", new FrameData(
|
||||
ClickGUI.INSTANCE.getModulesFrame().x,
|
||||
ClickGUI.INSTANCE.getModulesFrame().y,
|
||||
ClickGUI.INSTANCE.getModulesFrame().getX(),
|
||||
ClickGUI.INSTANCE.getModulesFrame().getY(),
|
||||
ClickGUI.INSTANCE.getModulesFrame().extended));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onMoveModuleFrame(ModuleFrameEvent.Move event) {
|
||||
extendableFrames.replace("M", new FrameData(
|
||||
ClickGUI.INSTANCE.getModulesFrame().x,
|
||||
ClickGUI.INSTANCE.getModulesFrame().y,
|
||||
ClickGUI.INSTANCE.getModulesFrame().getX(),
|
||||
ClickGUI.INSTANCE.getModulesFrame().getY(),
|
||||
ClickGUI.INSTANCE.getModulesFrame().extended));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onExtendGUISettingsFrame(GUISettingsFrameEvent.Extend event) {
|
||||
extendableFrames.put("S", new FrameData(
|
||||
ClickGUI.INSTANCE.getGuiSettingsFrame().x,
|
||||
ClickGUI.INSTANCE.getGuiSettingsFrame().y,
|
||||
ClickGUI.INSTANCE.getGuiSettingsFrame().getX(),
|
||||
ClickGUI.INSTANCE.getGuiSettingsFrame().getY(),
|
||||
ClickGUI.INSTANCE.getGuiSettingsFrame().extended));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onMoveGUISettingsFrame(GUISettingsFrameEvent.Move event) {
|
||||
extendableFrames.replace("S", new FrameData(
|
||||
ClickGUI.INSTANCE.getGuiSettingsFrame().x,
|
||||
ClickGUI.INSTANCE.getGuiSettingsFrame().y,
|
||||
ClickGUI.INSTANCE.getGuiSettingsFrame().getX(),
|
||||
ClickGUI.INSTANCE.getGuiSettingsFrame().getY(),
|
||||
ClickGUI.INSTANCE.getGuiSettingsFrame().extended));
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ import me.retucio.camtweaks.CameraTweaks;
|
||||
import me.retucio.camtweaks.module.Module;
|
||||
import me.retucio.camtweaks.module.ModuleManager;
|
||||
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.frames.ClientSettingsFrame;
|
||||
import me.retucio.camtweaks.ui.frames.SettingsFrame;
|
||||
import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
|
||||
import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@@ -100,7 +100,7 @@ public class ConfigManager {
|
||||
|
||||
public static void setFramePosition(SettingsFrame frame) {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -203,8 +203,8 @@ public class ConfigManager {
|
||||
private static void applyExtendableFrame(ModuleFrame frame) {
|
||||
ClientConfig.FrameData frameData = config.extendableFrames.get("M");
|
||||
if (frameData != null) {
|
||||
frame.x = frameData.x();
|
||||
frame.y = frameData.y();
|
||||
frame.setX(frameData.x());
|
||||
frame.setY(frameData.y());
|
||||
frame.extended = frameData.extended();
|
||||
}
|
||||
}
|
||||
@@ -212,8 +212,8 @@ public class ConfigManager {
|
||||
private static void applyExtendableFrame(ClientSettingsFrame frame) {
|
||||
ClientConfig.FrameData frameData = config.extendableFrames.get("S");
|
||||
if (frameData != null) {
|
||||
frame.x = frameData.x();
|
||||
frame.y = frameData.y();
|
||||
frame.setX(frameData.x());
|
||||
frame.setY(frameData.y());
|
||||
frame.extended = frameData.extended();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.retucio.camtweaks.event.events.camtweaks;
|
||||
|
||||
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
|
||||
public class SettingsFrameEvent {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package me.retucio.camtweaks.mixin;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import me.retucio.camtweaks.CameraTweaks;
|
||||
import me.retucio.camtweaks.command.CommandManager;
|
||||
import me.retucio.camtweaks.config.ConfigManager;
|
||||
import me.retucio.camtweaks.event.events.ClientClickEvent;
|
||||
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame;
|
||||
import net.minecraft.SharedConstants;
|
||||
import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
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.callback.CallbackInfo;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import static me.retucio.camtweaks.CameraTweaks.getVersionName;
|
||||
import static me.retucio.camtweaks.CameraTweaks.mc;
|
||||
|
||||
@Mixin(Screen.class)
|
||||
|
||||
@@ -2,7 +2,7 @@ package me.retucio.camtweaks.module.settings;
|
||||
|
||||
import me.retucio.camtweaks.module.Module;
|
||||
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.KeyUtil;
|
||||
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;
|
||||
|
||||
import me.retucio.camtweaks.config.ConfigManager;
|
||||
import me.retucio.camtweaks.module.ModuleManager;
|
||||
import me.retucio.camtweaks.module.modules.HUD;
|
||||
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame;
|
||||
import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
|
||||
import me.retucio.camtweaks.util.Colors;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
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.settings.Setting;
|
||||
import me.retucio.camtweaks.module.settings.ColorSetting;
|
||||
import me.retucio.camtweaks.ui.buttons.ListButton;
|
||||
import me.retucio.camtweaks.ui.buttons.ModuleButton;
|
||||
import me.retucio.camtweaks.ui.buttons.SettingButton;
|
||||
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame;
|
||||
import me.retucio.camtweaks.ui.frames.ColorPickerFrame;
|
||||
import me.retucio.camtweaks.ui.frames.ModuleFrame;
|
||||
import me.retucio.camtweaks.ui.frames.SettingsFrame;
|
||||
import me.retucio.camtweaks.ui.widgets.ScrollBarWidget;
|
||||
import me.retucio.camtweaks.ui.widgets.SearchBarWidget;
|
||||
import me.retucio.camtweaks.ui.widgets.buttons.settings.ListButton;
|
||||
import me.retucio.camtweaks.ui.widgets.buttons.ModuleButton;
|
||||
import me.retucio.camtweaks.ui.widgets.buttons.SettingButton;
|
||||
import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
|
||||
import me.retucio.camtweaks.ui.widgets.frames.settings.ColorPickerFrame;
|
||||
import me.retucio.camtweaks.ui.widgets.frames.ModuleFrame;
|
||||
import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
|
||||
import me.retucio.camtweaks.ui.widgets.Button;
|
||||
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 net.minecraft.client.MinecraftClient;
|
||||
@@ -29,16 +32,19 @@ import net.minecraft.text.Text;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
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
|
||||
public class ClickGUI extends Screen {
|
||||
|
||||
private final MinecraftClient mc = MinecraftClient.getInstance();
|
||||
public static ClickGUI INSTANCE;
|
||||
|
||||
private boolean anyFocused;
|
||||
private Object selected = null;
|
||||
private Widget selected = null;
|
||||
|
||||
private final ModuleFrame modulesFrame = new ModuleFrame(20, 30, 100, 20);
|
||||
private final List<SettingsFrame> settingsFrames = new ArrayList<>();
|
||||
@@ -46,8 +52,7 @@ public class ClickGUI extends Screen {
|
||||
|
||||
private final ScrollBarWidget scrollBar = new ScrollBarWidget();
|
||||
private final SearchBarWidget searchBar = new SearchBarWidget(340, 16, 300, 20);
|
||||
|
||||
private final MinecraftClient mc = MinecraftClient.getInstance();
|
||||
private final List<Widget> miscWidgets = Arrays.asList(scrollBar, searchBar);
|
||||
|
||||
public ClickGUI() {
|
||||
super(Text.of("interfaz"));
|
||||
@@ -59,7 +64,7 @@ public class ClickGUI extends Screen {
|
||||
public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
|
||||
scrollBar.setWindowHeight(mc.getWindow().getScaledHeight());
|
||||
scrollBar.setContentHeight(calculateContentHeight());
|
||||
scrollBar.render(ctx, mouseX, mouseY);
|
||||
scrollBar.render(ctx, mouseX, mouseY, delta);
|
||||
|
||||
int scrollOffset = scrollBar.getScrollOffset();
|
||||
|
||||
@@ -111,43 +116,52 @@ public class ClickGUI extends Screen {
|
||||
}
|
||||
|
||||
private int calculateContentHeight() {
|
||||
int bottom = modulesFrame.y + modulesFrame.h + modulesFrame.totalHeight;
|
||||
int bottom = modulesFrame.getY() + modulesFrame.getH() + modulesFrame.getTotalHeight();
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
public boolean mouseClicked(Click click, boolean doubled) {
|
||||
scrollBar.mouseClicked(click.x(), click.y(), click.button());
|
||||
searchBar.mouseClicked(click.x(), click.y(), click.button());
|
||||
miscWidgets.forEach(w -> w.mouseClicked(
|
||||
(int) click.x(),
|
||||
(int) click.y(),
|
||||
click.button()));
|
||||
|
||||
// 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))
|
||||
sf.mouseClicked(click.x(), click.y(), click.button());
|
||||
sf.mouseClicked((int) click.x(), (int) click.y(), click.button());
|
||||
|
||||
return super.mouseClicked(click, doubled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(Click click) {
|
||||
scrollBar.mouseReleased(click.x(), click.y(), click.button());
|
||||
searchBar.mouseReleased(click.x(), click.y(), click.button());
|
||||
miscWidgets.forEach(w -> w.mouseReleased(
|
||||
(int) click.x(),
|
||||
(int) click.y(),
|
||||
click.button()));
|
||||
|
||||
// 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))
|
||||
sf.mouseReleased(click.x(), click.y(), click.button());
|
||||
sf.mouseReleased((int) click.x(), (int) click.y(), click.button());
|
||||
|
||||
return super.mouseReleased(click);
|
||||
}
|
||||
|
||||
@Override
|
||||
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))
|
||||
sf.mouseDragged(click.x(), click.y());
|
||||
sf.mouseDragged((int) click.x(), (int) click.y());
|
||||
|
||||
return super.mouseDragged(click, deltaX, deltaY);
|
||||
}
|
||||
|
||||
@@ -158,8 +172,8 @@ public class ClickGUI extends Screen {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onMouseScroll(MouseScrollEvent event) {
|
||||
// subir y bajar la pantalla con la rueda del ratón
|
||||
scrollBar.onMouseScroll(event.getVertical() * guiSettings.scrollSens.getValue());
|
||||
miscWidgets.forEach(w -> w.mouseScrolled(
|
||||
event.getVertical() * guiSettings.scrollSens.getValue()));
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
int h = CameraTweaks.mc.getWindow().getScaledHeight();
|
||||
int minY = Math.min(modulesFrame.y, settingsFrames.stream().mapToInt(sf -> sf.y).min().orElse(modulesFrame.y));
|
||||
int maxY = Math.max(modulesFrame.y + modulesFrame.h, settingsFrames.stream().mapToInt(sf -> sf.y + sf.h).max().orElse(modulesFrame.y + modulesFrame.h));
|
||||
int minY = Math.min(modulesFrame.getY(), settingsFrames.stream().mapToInt(Frame::getY).min().orElse(modulesFrame.getY()));
|
||||
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);
|
||||
|
||||
if (correction != 0) {
|
||||
modulesFrame.y += correction;
|
||||
settingsFrames.forEach(sf -> sf.y += correction);
|
||||
modulesFrame.setY(modulesFrame.getY() + correction);
|
||||
settingsFrames.forEach(sf -> sf.setY(sf.getY() + correction));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +197,8 @@ public class ClickGUI extends Screen {
|
||||
String searchInput = searchBar.getSearchInput().trim();
|
||||
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();
|
||||
|
||||
if (searchInput.isEmpty()) {
|
||||
@@ -203,7 +218,8 @@ public class ClickGUI extends Screen {
|
||||
}
|
||||
|
||||
for (SettingsFrame sf : settingsFrames) {
|
||||
for (SettingButton sb : sf.getButtons()) {
|
||||
for (Button b : sf.getButtons()) {
|
||||
if (!(b instanceof SettingButton<?> sb)) return;
|
||||
Setting setting = sb.getSetting();
|
||||
|
||||
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) {
|
||||
// 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
|
||||
SettingsFrame frame = new SettingsFrame(module, x, y, 120, 20);
|
||||
settingsFrames.add(frame);
|
||||
CameraTweaks.EVENT_BUS.post(new SettingsFrameEvent.Open(frame));
|
||||
}
|
||||
|
||||
public void openListSettingsFrame(Module module, int x, int y) {
|
||||
if (isSettingsFrameOpen(module)) return;
|
||||
SettingsFrame frame = new SettingsFrame(module, x, y, 120, 18);
|
||||
// abrir un marco de ajustes específicamente para ajustes de selección múltiple
|
||||
public void openListSettingsFrame(Module dummy, int x, int y) {
|
||||
if (isSettingsFrameOpen(dummy)) return;
|
||||
SettingsFrame frame = new SettingsFrame(dummy, x, y, 120, 18);
|
||||
settingsFrames.add(frame);
|
||||
}
|
||||
|
||||
@@ -244,12 +261,13 @@ public class ClickGUI extends Screen {
|
||||
List<SettingsFrame> toRemove = new ArrayList<>();
|
||||
for (SettingsFrame sf : settingsFrames) {
|
||||
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
|
||||
CameraTweaks.EVENT_BUS.post(new SettingsFrameEvent.Close(sf));
|
||||
|| (!(sf instanceof ColorPickerFrame) && sf.module == module)) { // lógica muy mierdas, lo sé, pero paso de hacerlo bien
|
||||
toRemove.add(sf);
|
||||
CameraTweaks.EVENT_BUS.post(new SettingsFrameEvent.Close(sf));
|
||||
unselect(sf);
|
||||
}
|
||||
}
|
||||
|
||||
settingsFrames.removeAll(toRemove);
|
||||
}
|
||||
|
||||
@@ -259,13 +277,6 @@ public class ClickGUI extends Screen {
|
||||
.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) {
|
||||
for (SettingsFrame sf : getSettingsFrames()) {
|
||||
if (sf instanceof ColorPickerFrame cpf)
|
||||
@@ -279,7 +290,7 @@ public class ClickGUI extends Screen {
|
||||
if (isColorPickerFrameOpen(frame.getColorSetting())) {
|
||||
closeColorPickerFrame(frame.getColorSetting());
|
||||
return;
|
||||
};
|
||||
}
|
||||
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
|
||||
|
||||
@Override
|
||||
@@ -332,6 +351,8 @@ public class ClickGUI extends Screen {
|
||||
return guiSettingsFrame;
|
||||
}
|
||||
|
||||
public List<Widget> getMiscWidgets() { return miscWidgets; }
|
||||
|
||||
public List<SettingsFrame> getSettingsFrames() {
|
||||
return settingsFrames;
|
||||
}
|
||||
@@ -347,27 +368,27 @@ public class ClickGUI extends Screen {
|
||||
|
||||
// selección de widgets
|
||||
|
||||
public Object getSelected() {
|
||||
public Widget getSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
public void setSelected(Object object) {
|
||||
this.selected = object;
|
||||
public void setSelected(Widget widget) {
|
||||
this.selected = widget;
|
||||
}
|
||||
|
||||
public boolean canSelect(Object object) {
|
||||
return getSelected() == null || getSelected() == object;
|
||||
public boolean canSelect(Widget widget) {
|
||||
return getSelected() == null || getSelected() == widget;
|
||||
}
|
||||
|
||||
public boolean trySelect(Object object) {
|
||||
if (canSelect(object)) {
|
||||
setSelected(object);
|
||||
public boolean trySelect(Widget widget) {
|
||||
if (canSelect(widget)) {
|
||||
setSelected(widget);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void unselect(Object object) {
|
||||
if (selected == object) setSelected(null);
|
||||
public void unselect(Widget widget) {
|
||||
if (selected == widget) setSelected(null);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package me.retucio.camtweaks.ui.screen;
|
||||
|
||||
import me.retucio.camtweaks.CameraTweaks;
|
||||
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 net.minecraft.client.gl.RenderPipelines;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
|
||||
@@ -1,36 +1,27 @@
|
||||
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 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 x, y, w, h;
|
||||
|
||||
public Button(Frame parent, int offset) {
|
||||
public Button(Frame<?> parent, int offset) {
|
||||
super(parent.getX(), parent.getRenderY(), parent.getW(), parent.getH());
|
||||
this.parent = parent;
|
||||
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 mouseDragged(int mouseX, int mouseY);
|
||||
public void mouseReleased(int mouseX, int mouseY, int button) {
|
||||
ClickGUI.INSTANCE.unselect(this);
|
||||
public abstract void drawTooltip(DrawContext ctx, int mouseX, int mouseY);
|
||||
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public abstract void drawTooltip(DrawContext ctx, double mouseX, double 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 void setOffset(int offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
}
|
||||
@@ -1,63 +1,51 @@
|
||||
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 java.util.ArrayList;
|
||||
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;
|
||||
private final List<Button> buttons = new ArrayList<>();
|
||||
private List<Button> visibleButtons = new ArrayList<>();
|
||||
protected final List<B> buttons = new ArrayList<>();
|
||||
protected List<B> visibleButtons = new ArrayList<>();
|
||||
|
||||
private int x, y, w, h;
|
||||
private int renderY;
|
||||
private int dragX, dragY;
|
||||
private boolean dragging;
|
||||
public int totalHeight = 0;
|
||||
protected int renderY;
|
||||
protected int totalHeight = 0;
|
||||
|
||||
protected int dragX, dragY;
|
||||
protected boolean dragging;
|
||||
|
||||
public Frame(String title, int x, int y, int w, int h) {
|
||||
super(x, y, w, h);
|
||||
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) {
|
||||
for (Button button : visibleButtons) button.drawTooltip(ctx, mouseX, mouseY);
|
||||
}
|
||||
|
||||
public abstract void mouseClicked(int mouseX, int mouseY, int button);
|
||||
public abstract void mouseDragged(int mouseX, int mouseY);
|
||||
public void mouseReleased(int mouseX, int mouseY, int button) {
|
||||
ClickGUI.INSTANCE.unselect(this);
|
||||
}
|
||||
protected abstract void updateWidth();
|
||||
|
||||
public abstract void updateWidth();
|
||||
|
||||
public List<Button> getButtons() {
|
||||
return buttons;
|
||||
}
|
||||
|
||||
public List<Button> getVisibleButtons() {
|
||||
return visibleButtons;
|
||||
}
|
||||
|
||||
public boolean isHovered(double mouseX, double mouseY) {
|
||||
return mouseX > x && mouseX < x + w && mouseY > renderY && mouseY < renderY + h;
|
||||
@Override
|
||||
// verificar si el puntero del ratón se encuentra encima
|
||||
public boolean isHovered(int mouseX, int mouseY) {
|
||||
return mouseX > x && mouseX < x + w
|
||||
&& mouseY > renderY && mouseY < renderY + h;
|
||||
}
|
||||
|
||||
public void updateRenderY(int 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; }
|
||||
}
|
||||
+37
-25
@@ -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.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 net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
// clase para el botón para cada módulo
|
||||
public class ModuleButton {
|
||||
public class ModuleButton extends Button {
|
||||
|
||||
private final Module module;
|
||||
public ModuleFrame parent;
|
||||
public int offset;
|
||||
public final int height = 18;
|
||||
|
||||
public ModuleButton(Module module, ModuleFrame parent, int offset) {
|
||||
super(parent, offset);
|
||||
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
|
||||
parent.x + 2, parent.renderY + offset + 3,
|
||||
parent.x + parent.w - 2 , parent.renderY + height + offset,
|
||||
parent.getX() + 2, parent.getRenderY() + offset + 3,
|
||||
parent.getX() + parent.getW() - 2 , parent.getRenderY() + height + offset,
|
||||
determineColor(mouseX, mouseY));
|
||||
|
||||
ctx.drawText( // dibujar el nombre del módulo
|
||||
parent.mc.textRenderer, module.getName(),
|
||||
parent.x + 5, parent.renderY + offset + (height / 2) - (parent.mc.textRenderer.fontHeight / 2) + 2,
|
||||
mc.textRenderer, module.getName(),
|
||||
parent.getX() + 5, parent.getRenderY() + offset + (height / 2) - (mc.textRenderer.fontHeight / 2) + 2,
|
||||
-1, true);
|
||||
|
||||
// dibujar "tooltips" (cajas de texto) al pasar el puntero encima del botón, para mostrar su descripción
|
||||
if (isHovered((int) mouseX, (int) mouseY))
|
||||
ctx.drawTooltip(Text.of(module.getDescription()), (int) mouseX, (int) mouseY + 20);
|
||||
if (isHovered(mouseX, mouseY))
|
||||
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 (button == 0) { // clic izquierdo para activar / desactivar el módulo
|
||||
module.toggle();
|
||||
@@ -46,29 +51,36 @@ public class ModuleButton {
|
||||
ClickGUI.INSTANCE.closeSettingsFrame(module);
|
||||
else
|
||||
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) {
|
||||
ClickGUI.INSTANCE.unselect(this);
|
||||
}
|
||||
@Override
|
||||
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
|
||||
@Override
|
||||
public boolean isHovered(int mouseX, int mouseY) {
|
||||
return ClickGUI.INSTANCE.canSelect(this)
|
||||
&& mouseX > parent.x
|
||||
&& mouseX < parent.x + parent.w
|
||||
&& mouseY > parent.renderY + offset
|
||||
&& mouseY < parent.renderY + height + offset;
|
||||
&& mouseX > parent.getX()
|
||||
&& mouseX < parent.getX() + parent.getW()
|
||||
&& mouseY > parent.getRenderY() + offset
|
||||
&& mouseY < parent.getRenderY() + height + offset;
|
||||
}
|
||||
|
||||
public int determineColor(double mouseX, double mouseY) {
|
||||
// determina el color del botón, dependiendo de si está el puntero encima y si está activado
|
||||
if (module.isEnabled())
|
||||
return isHovered((int) mouseX, (int) mouseY) ? Colors.mainColor.brighter().getRGB() : Colors.mainColor.getRGB();
|
||||
return isHovered((int) mouseX, (int) mouseY) ? Colors.buttonColor.brighter().getRGB() : Colors.buttonColor.getRGB();
|
||||
return isHovered((int) mouseX, (int) mouseY)
|
||||
? Colors.mainColor.brighter().getRGB()
|
||||
: Colors.mainColor.getRGB();
|
||||
return isHovered((int) mouseX, (int) mouseY)
|
||||
? Colors.buttonColor.brighter().getRGB()
|
||||
: Colors.buttonColor.getRGB();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
+21
-28
@@ -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.ui.widgets.buttons.SettingButton;
|
||||
import me.retucio.camtweaks.ui.screen.ClickGUI;
|
||||
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame;
|
||||
import me.retucio.camtweaks.ui.frames.SettingsFrame;
|
||||
import me.retucio.camtweaks.ui.widgets.frames.settings.ClientSettingsFrame;
|
||||
import me.retucio.camtweaks.ui.widgets.frames.SettingsFrame;
|
||||
import me.retucio.camtweaks.util.ChatUtil;
|
||||
import me.retucio.camtweaks.util.Colors;
|
||||
import me.retucio.camtweaks.util.KeyUtil;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.input.KeyInput;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
@@ -13,12 +15,10 @@ import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.util.Formatting;
|
||||
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
|
||||
public class BindButton extends SettingButton {
|
||||
// botón para configurar la tecla asignada a un módulo. comienza a escuchar al hacerle clic.
|
||||
public class BindButton extends SettingButton<KeySetting> {
|
||||
|
||||
private final KeySetting setting;
|
||||
private boolean listening = false;
|
||||
|
||||
public BindButton(KeySetting setting, SettingsFrame parent, int offset) {
|
||||
@@ -27,22 +27,27 @@ public class BindButton extends SettingButton {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext ctx, double mouseX, double mouseY, float delta) {
|
||||
int bgColor = isHovered((int) mouseX, (int) mouseY)
|
||||
public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
|
||||
// fondo
|
||||
int bgColor = isHovered(mouseX, mouseY)
|
||||
? Colors.buttonColor.brighter().getRGB()
|
||||
: Colors.buttonColor.getRGB();
|
||||
|
||||
ctx.fill(x, y, x + w, y + h, bgColor);
|
||||
|
||||
// texto
|
||||
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
|
||||
public void mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (isHovered((int) mouseX, (int) mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
|
||||
if (button == 0) listening = !listening;
|
||||
else if (button == 1 && mc.isShiftPressed())
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
|
||||
if (button == 0) {
|
||||
listening = !listening;
|
||||
}
|
||||
else if (button == 1 && KeyUtil.isShiftDown()) {
|
||||
setting.reset();
|
||||
}
|
||||
} else {
|
||||
listening = false;
|
||||
}
|
||||
@@ -55,6 +60,7 @@ public class BindButton extends SettingButton {
|
||||
setting.setKey(GLFW.GLFW_KEY_UNKNOWN);
|
||||
} else {
|
||||
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 allowMultiple = ClientSettingsFrame.guiSettings.multipleKeybinds.isEnabled();
|
||||
|
||||
@@ -71,20 +77,7 @@ public class BindButton extends SettingButton {
|
||||
listening = false;
|
||||
}
|
||||
|
||||
|
||||
public boolean isFocused() {
|
||||
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) {}
|
||||
}
|
||||
+16
-35
@@ -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.settings.BooleanSetting;
|
||||
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.util.Colors;
|
||||
import me.retucio.camtweaks.util.KeyUtil;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
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 Map<T, BooleanSetting> optionButtons = new HashMap<>();
|
||||
private T lastSelectedValue;
|
||||
|
||||
public ChooseButton(OptionSetting<T> setting, SettingsFrame parent, int offset) {
|
||||
super(setting, parent, offset);
|
||||
this.setting = setting;
|
||||
this.lastSelectedValue = setting.getValue();
|
||||
|
||||
// crear un módulo "dummy" (falso)
|
||||
dummy = new Module(setting.getName(), setting.getDescription()) {
|
||||
@@ -33,32 +31,27 @@ public class ChooseButton<T> extends SettingButton {
|
||||
};
|
||||
|
||||
// ocultar cosas innecesarias
|
||||
dummy.getBind().setVisible(false);
|
||||
dummy.getSettings().stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase("modo de tecla"))
|
||||
.findFirst()
|
||||
.ifPresent(s -> s.setVisible(false));
|
||||
dummy.getSettings().stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase("notificar"))
|
||||
.findFirst()
|
||||
.ifPresent(s -> s.setVisible(false));
|
||||
dummy.getSettings().get(0).setVisible(false);
|
||||
dummy.getSettings().get(1).setVisible(false);
|
||||
dummy.getSettings().get(2).setVisible(false);
|
||||
dummy.shouldSaveSettings(false);
|
||||
}
|
||||
|
||||
@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)
|
||||
? Colors.buttonColor.brighter().getRGB()
|
||||
: Colors.buttonColor.getRGB();
|
||||
|
||||
ctx.fill(x, y, x + w, y + h, bgColor);
|
||||
|
||||
// texto
|
||||
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
|
||||
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)) {
|
||||
// click izquierdo / derecho: abrir marco
|
||||
if (button <= 1 && !mc.isShiftPressed()) {
|
||||
@@ -68,9 +61,9 @@ public class ChooseButton<T> extends SettingButton {
|
||||
}
|
||||
|
||||
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
|
||||
} else if (button == 1 && mc.isShiftPressed()) {
|
||||
} else if (button == 1 && KeyUtil.isShiftDown()) {
|
||||
setting.reset();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+35
-43
@@ -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.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.KeyUtil;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static me.retucio.camtweaks.CameraTweaks.mc;
|
||||
|
||||
// botón para los ajustes tipo EnumSetting (de modo)
|
||||
public class CycleButton<E extends Enum<E>> extends SettingButton {
|
||||
|
||||
private final EnumSetting<E> setting;
|
||||
public class CycleButton<E extends Enum<E>> extends SettingButton<EnumSetting<E>> {
|
||||
|
||||
public CycleButton(EnumSetting<E> setting, SettingsFrame parent, int offset) {
|
||||
super(setting, parent, offset);
|
||||
@@ -27,64 +24,59 @@ public class CycleButton<E extends Enum<E>> extends SettingButton {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext ctx, double mouseX, double mouseY, float delta) {
|
||||
int bgColor = isHovered((int) mouseX, (int) mouseY)
|
||||
public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
|
||||
// fondo
|
||||
int bgColor = isHovered(mouseX, mouseY)
|
||||
? Colors.buttonColor.brighter().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
|
||||
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
|
||||
public void drawTooltip(DrawContext ctx, double mouseX, double mouseY) {
|
||||
if (isHovered((int) mouseX, (int) mouseY)) {
|
||||
Screen currentScreen = parent.mc.currentScreen;
|
||||
public void drawTooltip(DrawContext ctx, int mouseX, int mouseY) {
|
||||
if (isHovered(mouseX, mouseY)) {
|
||||
Screen currentScreen = mc.currentScreen;
|
||||
|
||||
if (currentScreen != null) {
|
||||
if (mc.isShiftPressed()) {
|
||||
// lista de opciones disponibles
|
||||
List<Text> lines = new ArrayList<>();
|
||||
lines.add(Text.literal("modos disponibles:"));
|
||||
|
||||
for (Enum<?> val : setting.getValues()) {
|
||||
if (val == setting.getValue())
|
||||
lines.add(Text.literal("> " + val.toString() + " <").formatted(Formatting.GREEN));
|
||||
else
|
||||
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 {
|
||||
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) {}
|
||||
}
|
||||
+24
-36
@@ -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.settings.BooleanSetting;
|
||||
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.frames.SettingsFrame;
|
||||
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 net.minecraft.text.Text;
|
||||
|
||||
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 Map<T, BooleanSetting> optionButtons = new HashMap<>();
|
||||
@@ -31,50 +32,49 @@ public class ListButton<T> extends SettingButton {
|
||||
};
|
||||
|
||||
// ocultar cosas innecesarias
|
||||
dummy.getBind().setVisible(false);
|
||||
dummy.getSettings().stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase("modo de tecla"))
|
||||
.findFirst()
|
||||
.ifPresent(s -> s.setVisible(false));
|
||||
dummy.getSettings().stream()
|
||||
.filter(s -> s.getName().equalsIgnoreCase("notificar"))
|
||||
.findFirst()
|
||||
.ifPresent(s -> s.setVisible(false));
|
||||
dummy.getSettings().get(0).setVisible(false);
|
||||
dummy.getSettings().get(1).setVisible(false);
|
||||
dummy.getSettings().get(2).setVisible(false);
|
||||
dummy.shouldSaveSettings(false);
|
||||
}
|
||||
|
||||
@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)
|
||||
? Colors.buttonColor.brighter().getRGB()
|
||||
: Colors.buttonColor.getRGB();
|
||||
|
||||
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() + ")";
|
||||
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 drawTooltip(DrawContext ctx, double mouseX, double mouseY) {
|
||||
public void drawTooltip(DrawContext ctx, int mouseX, int 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
|
||||
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)) {
|
||||
// click izquierdo / derecho: abrir marco
|
||||
if (button <= 1 && !mc.isShiftPressed()) {
|
||||
// clic izquierdo / derecho: abrir marco
|
||||
if (button <= 1 && !KeyUtil.isShiftDown()) {
|
||||
if (ClickGUI.INSTANCE.isSettingsFrameOpen(dummy)) {
|
||||
ClickGUI.INSTANCE.closeSettingsFrame(dummy);
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
} else if (button == 1 && mc.isShiftPressed()) {
|
||||
} else if (button == 1 && KeyUtil.isShiftDown()) {
|
||||
setting.reset();
|
||||
refreshDummy();
|
||||
}
|
||||
@@ -107,16 +107,4 @@ public class ListButton<T> extends SettingButton {
|
||||
private int countEnabled() {
|
||||
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) {}
|
||||
}
|
||||
+25
-31
@@ -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.ui.screen.ClickGUI;
|
||||
import me.retucio.camtweaks.ui.frames.ClientSettingsFrame;
|
||||
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.widgets.frames.settings.ClientSettingsFrame;
|
||||
import me.retucio.camtweaks.util.Colors;
|
||||
import me.retucio.camtweaks.util.KeyUtil;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.awt.*;
|
||||
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
|
||||
public class SliderButton extends SettingButton {
|
||||
public class SliderButton extends SettingButton<NumberSetting> {
|
||||
|
||||
private final NumberSetting setting;
|
||||
private boolean dragging = false;
|
||||
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);
|
||||
this.setting = setting;
|
||||
this.df = new DecimalFormat("#.##"); // solo mostrar dos décimales
|
||||
EVENT_BUS.subscribe(this); // para poder escuchar teclas
|
||||
}
|
||||
|
||||
@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 fillingColor = Colors.mainColor;
|
||||
|
||||
@@ -48,9 +45,9 @@ public class SliderButton extends SettingButton {
|
||||
ctx.fill(x, y, x + filled, y + h, fillingColor.getRGB());
|
||||
|
||||
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) {
|
||||
double newVal = setting.getMin() + ((mouseX - x) / (double) w) * (setting.getMax() - setting.getMin());
|
||||
newVal = Math.max(setting.getMin(), Math.min(setting.getMax(), newVal));
|
||||
@@ -60,30 +57,27 @@ public class SliderButton extends SettingButton {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (isHovered((int) mouseX, (int) mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
|
||||
public void onKey(int key, int action) {
|
||||
// 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
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(double mouseX, double mouseY, int button) {
|
||||
ClickGUI.INSTANCE.unselect(this);
|
||||
public void mouseReleased(int mouseX, int mouseY, int button) {
|
||||
super.mouseReleased(mouseX, mouseY, button);
|
||||
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;
|
||||
}
|
||||
}
|
||||
+17
-23
@@ -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.ui.widgets.buttons.SettingButton;
|
||||
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.KeyUtil;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import static me.retucio.camtweaks.CameraTweaks.mc;
|
||||
|
||||
// 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 final StringSetting setting;
|
||||
@@ -23,20 +24,21 @@ public class TextButton extends SettingButton {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext ctx, double mouseX, double mouseY, float delta) {
|
||||
int bgColor = isHovered((int) mouseX, (int) mouseY)
|
||||
public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
|
||||
// fondo
|
||||
int bgColor = isHovered(mouseX, mouseY)
|
||||
? Colors.buttonColor.brighter().getRGB()
|
||||
: Colors.buttonColor.getRGB();
|
||||
|
||||
ctx.fill(x, y, x + w, y + h, bgColor);
|
||||
|
||||
// texto
|
||||
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
|
||||
public void mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (isHovered((int) mouseX, (int) mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
|
||||
if (button == 0) {
|
||||
typing = true;
|
||||
buffer.setLength(0);
|
||||
@@ -51,13 +53,6 @@ public class TextButton extends SettingButton {
|
||||
}
|
||||
|
||||
@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) {
|
||||
if (!typing || action == GLFW.GLFW_RELEASE) return;
|
||||
|
||||
@@ -69,10 +64,12 @@ public class TextButton extends SettingButton {
|
||||
onBackspace();
|
||||
} case GLFW.GLFW_KEY_ESCAPE -> {
|
||||
typing = false;
|
||||
} case GLFW.GLFW_KEY_SPACE -> {
|
||||
charTyped(' ');
|
||||
} default -> {
|
||||
String c = KeyUtil.getKeyName(key);
|
||||
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));
|
||||
else
|
||||
charTyped(c.toLowerCase().charAt(0));
|
||||
@@ -91,11 +88,8 @@ public class TextButton extends SettingButton {
|
||||
return typing;
|
||||
}
|
||||
|
||||
public StringSetting getSetting() {
|
||||
return setting;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
-40
@@ -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.event.events.camtweaks.ModuleFrameEvent;
|
||||
import me.retucio.camtweaks.module.Module;
|
||||
import me.retucio.camtweaks.module.ModuleManager;
|
||||
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 net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
// marco para los módulos
|
||||
public class ModuleFrame {
|
||||
public class ModuleFrame extends Frame<ModuleButton> {
|
||||
|
||||
public int x, y, w, h;
|
||||
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 boolean extended;
|
||||
|
||||
public MinecraftClient mc = MinecraftClient.getInstance();
|
||||
|
||||
public ModuleFrame(int x, int y, int w, int h) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
super("módulos", x, y, w, h);
|
||||
dragging = false;
|
||||
extended = true;
|
||||
|
||||
// determinar el saliente para cada botón de módulo
|
||||
int offset = h;
|
||||
for (Module module : ModuleManager.INSTANCE.getModules()) {
|
||||
moduleButtons.add(new ModuleButton(module, this, offset));
|
||||
buttons.add(new ModuleButton(module, this, offset));
|
||||
updateWidth();
|
||||
offset += h;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateRenderY(int scrollOffset) {
|
||||
renderY = y - scrollOffset;
|
||||
}
|
||||
|
||||
void updateWidth() {
|
||||
@Override
|
||||
protected void updateWidth() {
|
||||
// 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;
|
||||
|
||||
int maxWidth = mc.textRenderer.getWidth(title);
|
||||
for (ModuleButton button : moduleButtons) {
|
||||
for (ModuleButton button : buttons) {
|
||||
String text = button.getModule().getName();
|
||||
int textWidth = mc.textRenderer.getWidth(text);
|
||||
maxWidth = Math.max(maxWidth, textWidth);
|
||||
@@ -63,6 +52,7 @@ public class ModuleFrame {
|
||||
this.w = maxWidth + 22;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
|
||||
updateWidth();
|
||||
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),
|
||||
-1, true);
|
||||
|
||||
List<ModuleButton> visibleButtons = moduleButtons.stream()
|
||||
List<ModuleButton> visibleButtons = buttons.stream()
|
||||
.filter(mb -> mb.getModule().isSearchMatch())
|
||||
.toList();
|
||||
|
||||
@@ -93,7 +83,7 @@ public class ModuleFrame {
|
||||
// dibujar los botones para cada módulo
|
||||
int buttonY = renderY + h + 1;
|
||||
for (ModuleButton moduleButton : visibleButtons) {
|
||||
moduleButton.offset = buttonY - renderY;
|
||||
moduleButton.setOffset(buttonY - renderY);
|
||||
moduleButton.render(ctx, mouseX, mouseY, delta);
|
||||
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
|
||||
if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
|
||||
if (button == 0) { // clic izquierdo para arrastrarlo
|
||||
dragging = true;
|
||||
dragX = (int) (mouseX - x);
|
||||
dragY = (int) (mouseY - y);
|
||||
dragX = mouseX - x;
|
||||
dragY = mouseY - y;
|
||||
} else if (button == 1) { // clic derecho para extenderlo
|
||||
extended = !extended;
|
||||
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
|
||||
|
||||
List<ModuleButton> visibleModuleButtons = moduleButtons.stream()
|
||||
List<ModuleButton> visibleModuleButtons = buttons.stream()
|
||||
.filter(mb -> mb.getModule().isSearchMatch())
|
||||
.toList();
|
||||
|
||||
@@ -126,17 +117,18 @@ public class ModuleFrame {
|
||||
}
|
||||
|
||||
// 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);
|
||||
if (button == 0 && dragging)
|
||||
dragging = false;
|
||||
|
||||
List<ModuleButton> visibleModuleButtons = moduleButtons.stream()
|
||||
List<ModuleButton> visibleModuleButtons = buttons.stream()
|
||||
.filter(mb -> mb.getModule().isSearchMatch())
|
||||
.toList();
|
||||
|
||||
for (ModuleButton moduleButton : visibleModuleButtons) {
|
||||
if (moduleButton.isHovered((int) mouseX, (int) mouseY))
|
||||
if (moduleButton.isHovered(mouseX, mouseY))
|
||||
moduleButton.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@@ -144,10 +136,11 @@ public class ModuleFrame {
|
||||
CameraTweaks.EVENT_BUS.post(new ModuleFrameEvent.Move());
|
||||
}
|
||||
|
||||
// verificar si el puntero del ratón se encuentra encima
|
||||
public boolean isHovered(double mouseX, double mouseY) {
|
||||
return mouseX > x && mouseX < x + w && mouseY > renderY && mouseY < renderY + h;
|
||||
}
|
||||
@Override
|
||||
public void mouseDragged(int mouseX, int mouseY) {}
|
||||
|
||||
@Override
|
||||
public void onKey(int key, int action) {}
|
||||
|
||||
// actualizar la posición al arrastrar el marco
|
||||
public void updatePosition(double mouseX, double mouseY) {
|
||||
@@ -156,8 +149,4 @@ public class ModuleFrame {
|
||||
y = (int) (mouseY - dragY);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ModuleButton> getButtons() {
|
||||
return moduleButtons;
|
||||
}
|
||||
}
|
||||
+95
-105
@@ -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.event.events.camtweaks.SettingsFrameEvent;
|
||||
import me.retucio.camtweaks.module.Module;
|
||||
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.buttons.*;
|
||||
import me.retucio.camtweaks.ui.buttons.SliderButton;
|
||||
import me.retucio.camtweaks.ui.buttons.TextButton;
|
||||
import me.retucio.camtweaks.ui.buttons.ToggleButton;
|
||||
import me.retucio.camtweaks.ui.widgets.buttons.*;
|
||||
import me.retucio.camtweaks.ui.widgets.Frame;
|
||||
import me.retucio.camtweaks.util.Colors;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
// 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;
|
||||
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) {
|
||||
super("ajustes de " + module.getName(), x, y, w, h);
|
||||
this.module = module;
|
||||
|
||||
// asegurarse de que no se sale de la pantalla
|
||||
if (mc.getWindow() != null && x + w > mc.getWindow().getScaledWidth())
|
||||
this.x = mc.getWindow().getScaledWidth() - w;
|
||||
else
|
||||
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 -> {}
|
||||
}
|
||||
if (mc.getWindow() != null) {
|
||||
this.x = Math.clamp(this.x, 0, mc.getWindow().getScaledWidth() - w);
|
||||
this.y = Math.clamp(this.y, 0, mc.getWindow().getScaledHeight() - totalHeight - h);
|
||||
}
|
||||
title = "ajustes de " + module.getName();
|
||||
|
||||
visibleButtons = settingButtons.stream()
|
||||
addButtons();
|
||||
|
||||
visibleButtons = buttons.stream()
|
||||
.filter(sb -> sb.getSetting().isVisible())
|
||||
.toList();
|
||||
}
|
||||
|
||||
public void addButton(SettingButton button) {
|
||||
settingButtons.add(button);
|
||||
updateWidth(); // actualizar anchura del frame tras cada iteración
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
|
||||
updateWidth();
|
||||
|
||||
@@ -117,7 +65,7 @@ public class SettingsFrame {
|
||||
ctx.drawText(mc.textRenderer, title, titleX, titleY, -1, 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())
|
||||
.toList();
|
||||
|
||||
@@ -143,7 +91,7 @@ public class SettingsFrame {
|
||||
}
|
||||
|
||||
int startButtonY = firstLineY - descBoxTop + descBoxBottom;
|
||||
for (SettingButton sb : visibleButtons) {
|
||||
for (SettingButton<?> sb : visibleButtons) {
|
||||
sb.setX(x + 4);
|
||||
sb.setY(startButtonY);
|
||||
sb.setW(w - 8);
|
||||
@@ -153,75 +101,64 @@ public class SettingsFrame {
|
||||
}
|
||||
}
|
||||
|
||||
public void drawTooltips(DrawContext ctx, double mouseX, double mouseY) {
|
||||
for (SettingButton sb : visibleButtons)
|
||||
@Override
|
||||
public void drawTooltips(DrawContext ctx, int mouseX, int mouseY) {
|
||||
for (SettingButton<?> sb : visibleButtons)
|
||||
sb.drawTooltip(ctx, mouseX, mouseY);
|
||||
}
|
||||
|
||||
|
||||
public void mouseClicked(double mouseX, double mouseY, int button) {
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if (isHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
|
||||
if (isCloseButtonHovered(mouseX, mouseY)) {
|
||||
ClickGUI.INSTANCE.closeSettingsFrame(this.module);
|
||||
return;
|
||||
} if (button == 0) {
|
||||
dragging = true;
|
||||
dragX = (int) (mouseX - x);
|
||||
dragY = (int) (mouseY - y);
|
||||
dragX = mouseX - x;
|
||||
dragY = mouseY - y;
|
||||
} else if (button == 1) {
|
||||
ClickGUI.INSTANCE.closeSettingsFrame(module);
|
||||
}
|
||||
}
|
||||
|
||||
for (SettingButton sb : visibleButtons)
|
||||
for (SettingButton<?> sb : visibleButtons)
|
||||
sb.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
public void mouseReleased(double mouseX, double mouseY, int button) {
|
||||
ClickGUI.INSTANCE.unselect(this);
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY, int button) {
|
||||
super.mouseReleased(mouseX, mouseY, button);
|
||||
if (button == 0) {
|
||||
dragging = false;
|
||||
CameraTweaks.EVENT_BUS.post(new SettingsFrameEvent.Move(this));
|
||||
}
|
||||
|
||||
for (SettingButton sb : visibleButtons)
|
||||
for (SettingButton<?> sb : visibleButtons)
|
||||
sb.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
public void mouseDragged(double mouseX, double mouseY) {
|
||||
for (SettingButton sb : visibleButtons)
|
||||
@Override
|
||||
public void mouseDragged(int mouseX, int mouseY) {
|
||||
for (SettingButton<?> sb : visibleButtons)
|
||||
sb.mouseDragged(mouseX, mouseY);
|
||||
}
|
||||
|
||||
public void updatePosition(double mouseX, double mouseY) {
|
||||
if (dragging) {
|
||||
x = (int) (mouseX - dragX);
|
||||
y = (int) (mouseY - dragY);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onKey(int key, int action) {}
|
||||
|
||||
public boolean isHovered(double mouseX, double mouseY) {
|
||||
return mouseX > x && mouseX < x + w &&
|
||||
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() {
|
||||
@Override
|
||||
public void updateWidth() {
|
||||
// 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;
|
||||
|
||||
int maxWidth = mc.textRenderer.getWidth(title);
|
||||
for (SettingButton button : settingButtons) {
|
||||
for (SettingButton<?> button : buttons) {
|
||||
String text = button.getSetting().getName();
|
||||
|
||||
switch (button) {
|
||||
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 TextButton textButton -> text += ": " + textButton.getSetting().getValue();
|
||||
default -> {}
|
||||
@@ -233,6 +170,14 @@ public class SettingsFrame {
|
||||
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) {
|
||||
List<String> lines = new ArrayList<>();
|
||||
if (mc.textRenderer == null) return lines;
|
||||
@@ -253,11 +198,56 @@ public class SettingsFrame {
|
||||
return lines;
|
||||
}
|
||||
|
||||
public List<SettingButton> getButtons() {
|
||||
return settingButtons;
|
||||
private void addButtons() {
|
||||
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) {
|
||||
renderY = y - scrollOffset;
|
||||
public void addButton(SettingButton<?> button) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
+12
-11
@@ -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.event.events.camtweaks.GUISettingsFrameEvent;
|
||||
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.buttons.SettingButton;
|
||||
import me.retucio.camtweaks.ui.widgets.buttons.SettingButton;
|
||||
import me.retucio.camtweaks.util.Colors;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
|
||||
@@ -14,10 +15,10 @@ public class ClientSettingsFrame extends SettingsFrame {
|
||||
|
||||
public static final GUI guiSettings = new GUI();
|
||||
public boolean extended = false;
|
||||
private final String title = "ajustes del mod";
|
||||
|
||||
public ClientSettingsFrame(int x, int y, int w, int h) {
|
||||
super(guiSettings, x, y, w, h);
|
||||
title = "ajustes del mod";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,7 +36,7 @@ public class ClientSettingsFrame extends SettingsFrame {
|
||||
renderY + (h / 2) - (mc.textRenderer.fontHeight / 2),
|
||||
-1, true);
|
||||
|
||||
List<SettingButton> visibleButtons = settingButtons.stream()
|
||||
List<SettingButton<?>> visibleButtons = buttons.stream()
|
||||
.filter(sb -> sb.getSetting().isVisible() && sb.getSetting().isSearchMatch())
|
||||
.toList();
|
||||
|
||||
@@ -44,7 +45,7 @@ public class ClientSettingsFrame extends SettingsFrame {
|
||||
totalHeight = visibleButtons.size() * h;
|
||||
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.setY(currentY);
|
||||
sb.setW(w - 8);
|
||||
@@ -57,12 +58,12 @@ public class ClientSettingsFrame extends SettingsFrame {
|
||||
}
|
||||
|
||||
@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 (button == 0) {
|
||||
dragging = true;
|
||||
dragX = (int) (mouseX - x);
|
||||
dragY = (int) (mouseY - y);
|
||||
dragX = mouseX - x;
|
||||
dragY = mouseY - y;
|
||||
} else if (button == 1) {
|
||||
extended = !extended;
|
||||
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
|
||||
for (SettingButton settingButton : settingButtons)
|
||||
for (SettingButton<?> settingButton : buttons)
|
||||
settingButton.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(double mouseX, double mouseY, int button) {
|
||||
public void mouseReleased(int mouseX, int mouseY, int button) {
|
||||
ClickGUI.INSTANCE.unselect(this);
|
||||
if (button == 0 && dragging)
|
||||
CameraTweaks.EVENT_BUS.post(new GUISettingsFrameEvent.Move());
|
||||
@@ -84,7 +85,7 @@ public class ClientSettingsFrame extends SettingsFrame {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTooltips(DrawContext ctx, double mouseX, double mouseY) {
|
||||
public void drawTooltips(DrawContext ctx, int mouseX, int mouseY) {
|
||||
if (!extended) return;
|
||||
super.drawTooltips(ctx, mouseX, mouseY);
|
||||
}
|
||||
+15
-12
@@ -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.settings.Setting;
|
||||
import me.retucio.camtweaks.module.settings.BooleanSetting;
|
||||
import me.retucio.camtweaks.module.settings.ColorSetting;
|
||||
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.util.Colors;
|
||||
import me.retucio.camtweaks.util.render.DrawUtil;
|
||||
@@ -86,7 +89,7 @@ public class ColorPickerFrame extends SettingsFrame {
|
||||
});
|
||||
}
|
||||
|
||||
settingButtons.clear();
|
||||
buttons.clear();
|
||||
|
||||
Module originalModule = this.module;
|
||||
this.module = dummyModule;
|
||||
@@ -238,11 +241,11 @@ public class ColorPickerFrame extends SettingsFrame {
|
||||
|
||||
// botones de ajustes
|
||||
int startButtonY = alphaPickerY + alphaPickerHeight + padding;
|
||||
visibleButtons = settingButtons.stream()
|
||||
visibleButtons = buttons.stream()
|
||||
.filter(sb -> sb.getSetting().isVisible() && sb.getSetting().isSearchMatch())
|
||||
.toList();
|
||||
|
||||
for (SettingButton sb : visibleButtons) {
|
||||
for (SettingButton<?> sb : visibleButtons) {
|
||||
sb.setX(x + 4);
|
||||
sb.setY(startButtonY);
|
||||
sb.setW(w - 8);
|
||||
@@ -310,7 +313,7 @@ public class ColorPickerFrame extends SettingsFrame {
|
||||
// DETECCIÓN DE INPUTS
|
||||
|
||||
@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 (isCloseButtonHovered(mouseX, mouseY)) {
|
||||
ClickGUI.INSTANCE.closeSettingsFrame(this.dummyModule);
|
||||
@@ -344,13 +347,13 @@ public class ColorPickerFrame extends SettingsFrame {
|
||||
updateColorFromPicker((int) mouseX, (int) mouseY);
|
||||
}
|
||||
|
||||
for (SettingButton sb : visibleButtons)
|
||||
for (SettingButton<?> sb : visibleButtons)
|
||||
sb.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(double mouseX, double mouseY, int button) {
|
||||
ClickGUI.INSTANCE.unselect(this);
|
||||
public void mouseReleased(int mouseX, int mouseY, int button) {
|
||||
super.mouseReleased(mouseX, mouseY, button);
|
||||
if (button == 0) { // soltar todo
|
||||
dragging = false;
|
||||
pickingHue = false;
|
||||
@@ -358,16 +361,16 @@ public class ColorPickerFrame extends SettingsFrame {
|
||||
pickingAlpha = false;
|
||||
}
|
||||
|
||||
for (SettingButton sb : visibleButtons)
|
||||
for (SettingButton<?> sb : visibleButtons)
|
||||
sb.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(double mouseX, double mouseY) {
|
||||
public void mouseDragged(int mouseX, int mouseY) {
|
||||
if (pickingHue || pickingSaturationBrightness || pickingAlpha)
|
||||
updateColorFromPicker((int) mouseX, (int) mouseY);
|
||||
|
||||
for (SettingButton sb : visibleButtons)
|
||||
for (SettingButton<?> sb : visibleButtons)
|
||||
sb.mouseDragged(mouseX, mouseY);
|
||||
}
|
||||
|
||||
+20
-14
@@ -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.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 net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ScrollBarWidget {
|
||||
public class ScrollBarWidget extends Widget {
|
||||
|
||||
private boolean dragging;
|
||||
private int dragY, scrollStart;
|
||||
@@ -16,11 +16,13 @@ public class ScrollBarWidget {
|
||||
|
||||
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() {}
|
||||
|
||||
public void render(DrawContext ctx, double mouseX, double mouseY) {
|
||||
@Override
|
||||
public void render(DrawContext ctx, int mouseX, int mouseY, float delta) {
|
||||
if (contentHeight <= windowHeight || !ClientSettingsFrame.guiSettings.scrollBar.isEnabled()) return;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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 (isThumbHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
|
||||
dragging = true;
|
||||
dragY = (int) mouseY;
|
||||
dragY = mouseY;
|
||||
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);
|
||||
dragging = false;
|
||||
}
|
||||
|
||||
public void mouseDragged(double mouseY) {
|
||||
@Override
|
||||
public void mouseDragged(int mouseX, int mouseY) {
|
||||
if (!dragging || !ClientSettingsFrame.guiSettings.scrollBar.isEnabled()) return;
|
||||
|
||||
int thumbHeight = getThumbHeight();
|
||||
int trackHeight = windowHeight - thumbHeight;
|
||||
|
||||
float ratio = (float) (contentHeight - windowHeight) / trackHeight;
|
||||
int deltaY = (int) mouseY - dragY;
|
||||
int deltaY = mouseY - dragY;
|
||||
scrollOffset = scrollStart + (int) (deltaY * ratio);
|
||||
clampOffset();
|
||||
}
|
||||
|
||||
public void onMouseScroll(double amount) {
|
||||
@Override
|
||||
public void mouseScrolled(double amount) {
|
||||
if (contentHeight <= windowHeight) return;
|
||||
scrollOffset -= (int) amount * 20;
|
||||
clampOffset();
|
||||
+17
-31
@@ -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.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.KeyUtil;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
@@ -13,28 +13,22 @@ import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
public class SearchBarWidget {
|
||||
public class SearchBarWidget extends Widget {
|
||||
|
||||
private boolean dragging;
|
||||
private int dragX, dragY;
|
||||
|
||||
private int x, y;
|
||||
private final int w, h;
|
||||
private int renderY;
|
||||
|
||||
private boolean focused;
|
||||
private final StringBuilder buffer = new StringBuilder();
|
||||
|
||||
private final MinecraftClient mc = MinecraftClient.getInstance();
|
||||
|
||||
public SearchBarWidget(int x, int y, int w, int h) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
super(x, y, w, 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;
|
||||
|
||||
Color textFieldColor = isTextFieldHovered(mouseX, mouseY)
|
||||
@@ -66,7 +60,8 @@ public class SearchBarWidget {
|
||||
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 (isHandleHovered(mouseX, mouseY) && ClickGUI.INSTANCE.trySelect(this)) {
|
||||
dragging = true;
|
||||
@@ -78,7 +73,8 @@ public class SearchBarWidget {
|
||||
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;
|
||||
ClickGUI.INSTANCE.unselect(this);
|
||||
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) {
|
||||
if (!ClientSettingsFrame.guiSettings.searchBar.isEnabled()) return;
|
||||
if (!focused || action == GLFW.GLFW_RELEASE) return;
|
||||
@@ -162,20 +164,4 @@ public class SearchBarWidget {
|
||||
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.event.SubscribeEvent;
|
||||
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.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
@@ -4,7 +4,7 @@ import net.minecraft.util.Formatting;
|
||||
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user