diff options
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/config')
3 files changed, 151 insertions, 4 deletions
diff --git a/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java b/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java new file mode 100644 index 00000000..c33e2f54 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java @@ -0,0 +1,83 @@ +package de.hysky.skyblocker.config; + +import de.hysky.skyblocker.skyblock.tabhud.widget.Widget; +import de.hysky.skyblocker.utils.render.RenderHelper; +import it.unimi.dsi.fastutil.ints.IntIntImmutablePair; +import it.unimi.dsi.fastutil.ints.IntIntPair; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.Text; + +import java.awt.*; + +public abstract class HudConfigScreen extends Screen { + private final Widget widget; + private final Screen parent; + + private int hudX = 0; + private int hudY = 0; + public HudConfigScreen(Text title, Widget widget, Screen parent) { + super(title); + this.widget = widget; + this.parent = parent; + + int[] posFromConfig = getPosFromConfig(SkyblockerConfigManager.get()); + hudX = posFromConfig[0]; + hudY = posFromConfig[1]; + } + + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + super.render(context, mouseX, mouseY, delta); + renderBackground(context, mouseX, mouseY, delta); + renderWidget(context, hudX, hudY); + context.drawCenteredTextWithShadow(textRenderer, "Right Click To Reset Position", width / 2, height / 2, Color.GRAY.getRGB()); + } + + @Override + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { + IntIntPair dims = getDimensions(); + if (RenderHelper.pointIsInArea(mouseX, mouseY, hudX, hudY, hudX + dims.leftInt(), hudY + dims.rightInt()) && button == 0) { + hudX = (int) Math.max(Math.min(mouseX - (double) dims.leftInt() / 2, this.width - dims.leftInt()), 0); + hudY = (int) Math.max(Math.min(mouseY - (double) dims.rightInt() / 2, this.height - dims.rightInt()), 0); + } + return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (button == 1) { + IntIntPair dims = getDimensions(); + hudX = this.width / 2 - dims.leftInt(); + hudY = this.height / 2 - dims.rightInt(); + } + return super.mouseClicked(mouseX, mouseY, button); + } + + abstract protected int[] getPosFromConfig(SkyblockerConfig config); + + protected IntIntPair getDimensions() { + return new IntIntImmutablePair(widget.getHeight(), widget.getWidth()); + } + + @Override + public void close() { + SkyblockerConfig skyblockerConfig = SkyblockerConfigManager.get(); + savePos(skyblockerConfig, hudX, hudY); + SkyblockerConfigManager.save(); + + client.setScreen(parent); + } + + /** + * This method should save the passed position to the config + * <p> + * NOTE: The parent class will call {@link SkyblockerConfigManager#save()} right after this method + * @param configManager the config so you don't have to get it + * @param x x + * @param y y + */ + abstract protected void savePos(SkyblockerConfig configManager, int x, int y); + + abstract protected void renderWidget(DrawContext context, int x, int y); +} diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java index 175c3bdf..826495fb 100644 --- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java @@ -652,6 +652,9 @@ public class SkyblockerConfig { public Rift rift = new Rift(); @SerialEntry + public TheEnd end = new TheEnd(); + + @SerialEntry public SpidersDen spidersDen = new SpidersDen(); @SerialEntry @@ -1042,6 +1045,24 @@ public class SkyblockerConfig { public int mcGrubberStacks = 0; } + public static class TheEnd { + + @SerialEntry + public boolean hudEnabled = true; + + @SerialEntry + public boolean enableBackground = true; + + @SerialEntry + public boolean waypoint = true; + + @SerialEntry + public int x = 10; + + @SerialEntry + public int y = 10; + } + public static class SpidersDen { @SerialEntry public Relics relics = new Relics(); diff --git a/src/main/java/de/hysky/skyblocker/config/categories/LocationsCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/LocationsCategory.java index 9bdcf2e9..75c83a9b 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/LocationsCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/LocationsCategory.java @@ -2,11 +2,11 @@ package de.hysky.skyblocker.config.categories; import de.hysky.skyblocker.config.ConfigUtils; import de.hysky.skyblocker.config.SkyblockerConfig; -import dev.isxander.yacl3.api.ConfigCategory; -import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; -import dev.isxander.yacl3.api.OptionGroup; +import de.hysky.skyblocker.skyblock.end.EndHudConfigScreen; +import de.hysky.skyblocker.skyblock.end.TheEnd; +import dev.isxander.yacl3.api.*; import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder; +import net.minecraft.client.MinecraftClient; import net.minecraft.text.Text; public class LocationsCategory { @@ -79,6 +79,49 @@ public class LocationsCategory { .build()) .build()) + // The end + .group(OptionGroup.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.end")) + .collapsed(false) + .option(Option.<Boolean>createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.end.hudEnabled")) + .binding(defaults.locations.end.hudEnabled, + () -> config.locations.end.hudEnabled, + newValue -> config.locations.end.hudEnabled = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) + .option(Option.<Boolean>createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enableBackground")) // Reusing that string cuz sure + .binding(defaults.locations.end.enableBackground, + () -> config.locations.end.enableBackground, + newValue -> config.locations.end.enableBackground = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) + .option(Option.<Boolean>createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.end.waypoint")) + .binding(defaults.locations.end.waypoint, + () -> config.locations.end.waypoint, + newValue -> config.locations.end.waypoint = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) + .option(ButtonOption.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.end.screen")) + .text(Text.translatable("text.skyblocker.open")) // Reusing again lol + .action((screen, opt) -> MinecraftClient.getInstance().setScreen(new EndHudConfigScreen(screen))) + .build()) + .option(ButtonOption.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.end.resetName")) + .text(Text.translatable("text.autoconfig.skyblocker.option.locations.end.resetText")) + .action((screen, opt) -> { + TheEnd.zealotsKilled = 0; + TheEnd.zealotsSinceLastEye = 0; + TheEnd.eyes = 0; + }) + .build()) + .build() + + ) + //Spider's Den .group(OptionGroup.createBuilder() .name(Text.translatable("text.autoconfig.skyblocker.option.locations.spidersDen")) |
