diff options
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock')
3 files changed, 51 insertions, 24 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHud.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHud.java index 083cdcdf..4dcdf5c1 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHud.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHud.java @@ -10,6 +10,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.text.Text; import net.minecraft.util.Formatting; +import net.minecraft.util.Pair; import java.util.ArrayList; import java.util.List; @@ -51,16 +52,34 @@ public class DwarvenHud { || commissionList.isEmpty()) { return; } - render(context, SkyblockerConfig.get().locations.dwarvenMines.dwarvenHud.x, + render(HudCommsWidget.INSTANCE, context, SkyblockerConfig.get().locations.dwarvenMines.dwarvenHud.x, SkyblockerConfig.get().locations.dwarvenMines.dwarvenHud.y, commissionList); }); } - public static void render(DrawContext context, int hudX, int hudY, List<Commission> commissions) { + public static Pair<Integer, Integer> getDimForConfig(List<Commission> commissions) { + switch (SkyblockerConfig.get().locations.dwarvenMines.dwarvenHud.style) { + case SIMPLE: + HudCommsWidget.INSTANCE_CFG.updateData(commissions, false); + return new Pair<Integer, Integer>( + HudCommsWidget.INSTANCE_CFG.getWidth(), + HudCommsWidget.INSTANCE_CFG.getHeight()); + case FANCY : + HudCommsWidget.INSTANCE_CFG.updateData(commissions, true); + return new Pair<Integer, Integer>( + HudCommsWidget.INSTANCE_CFG.getWidth(), + HudCommsWidget.INSTANCE_CFG.getHeight()); + case CLASSIC: + default: + return new Pair<Integer, Integer>(200, 20 * commissions.size()); + } + } + + public static void render(HudCommsWidget hcw, DrawContext context, int hudX, int hudY, List<Commission> commissions) { switch (SkyblockerConfig.get().locations.dwarvenMines.dwarvenHud.style) { - case SIMPLE -> renderSimple(context, hudX, hudY, commissions); - case FANCY -> renderFancy(context, hudX, hudY, commissions); + case SIMPLE -> renderSimple(hcw, context, hudX, hudY, commissions); + case FANCY -> renderFancy(hcw, context, hudX, hudY, commissions); case CLASSIC -> renderClassic(context, hudX, hudY, commissions); } } @@ -83,21 +102,21 @@ public class DwarvenHud { } } - public static void renderSimple(DrawContext context, int hudX, int hudY, List<Commission> commissions) { - HudCommsWidget.INSTANCE.updateData(commissions, false); - HudCommsWidget.INSTANCE.update(); - HudCommsWidget.INSTANCE.setX(hudX); - HudCommsWidget.INSTANCE.setY(hudY); - HudCommsWidget.INSTANCE.render(context, + public static void renderSimple(HudCommsWidget hcw, DrawContext context, int hudX, int hudY, List<Commission> commissions) { + hcw.updateData(commissions, false); + hcw.update(); + hcw.setX(hudX); + hcw.setY(hudY); + hcw.render(context, SkyblockerConfig.get().locations.dwarvenMines.dwarvenHud.enableBackground); } - public static void renderFancy(DrawContext context, int hudX, int hudY, List<Commission> commissions) { - HudCommsWidget.INSTANCE.updateData(commissions, true); - HudCommsWidget.INSTANCE.update(); - HudCommsWidget.INSTANCE.setX(hudX); - HudCommsWidget.INSTANCE.setY(hudY); - HudCommsWidget.INSTANCE.render(context, + public static void renderFancy(HudCommsWidget hcw, DrawContext context, int hudX, int hudY, List<Commission> commissions) { + hcw.updateData(commissions, true); + hcw.update(); + hcw.setX(hudX); + hcw.setY(hudY); + hcw.render(context, SkyblockerConfig.get().locations.dwarvenMines.dwarvenHud.enableBackground); } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java index 10e62d88..e7db0a66 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java @@ -1,17 +1,22 @@ package me.xmrvizzy.skyblocker.skyblock.dwarven; +import java.awt.Color; +import java.util.List; + import me.shedaniel.autoconfig.AutoConfig; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import me.xmrvizzy.skyblocker.skyblock.dwarven.DwarvenHud.Commission; +import me.xmrvizzy.skyblocker.skyblock.tabhud.widget.hud.HudCommsWidget; import me.xmrvizzy.skyblocker.utils.RenderUtils; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.text.Text; - -import java.awt.*; -import java.util.List; +import net.minecraft.util.Pair; public class DwarvenHudConfigScreen extends Screen { + private static final List<Commission> CFG_COMMS = List.of(new DwarvenHud.Commission("Test Commission 1", "1%"), new DwarvenHud.Commission("Test Commission 2", "2%")); + private int hudX = SkyblockerConfig.get().locations.dwarvenMines.dwarvenHud.x; private int hudY = SkyblockerConfig.get().locations.dwarvenMines.dwarvenHud.y; @@ -23,15 +28,16 @@ public class DwarvenHudConfigScreen extends Screen { public void render(DrawContext context, int mouseX, int mouseY, float delta) { super.render(context, mouseX, mouseY, delta); renderBackground(context); - DwarvenHud.render(context, hudX, hudY, List.of(new DwarvenHud.Commission("Test Commission 1", "1%"), new DwarvenHud.Commission("Test Commission 2", "2%"))); + DwarvenHud.render(HudCommsWidget.INSTANCE_CFG, context, hudX, hudY, List.of(new DwarvenHud.Commission("Test Commission 1", "1%"), new DwarvenHud.Commission("Test Commission 2", "2%"))); 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) { + Pair<Integer, Integer> dims = DwarvenHud.getDimForConfig(CFG_COMMS); if (RenderUtils.pointExistsInArea((int) mouseX, (int) mouseY, hudX, hudY, hudX + 200, hudY + 40) && button == 0) { - hudX = (int) Math.max(Math.min(mouseX - 100, this.width - 200), 0); - hudY = (int) Math.max(Math.min(mouseY - 20, this.height - 40), 0); + hudX = (int) Math.max(Math.min(mouseX - dims.getLeft()/2, this.width - dims.getLeft()), 0); + hudY = (int) Math.max(Math.min(mouseY - dims.getRight()/2, this.height - dims.getRight()), 0); } return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); } @@ -39,8 +45,9 @@ public class DwarvenHudConfigScreen extends Screen { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { if (button == 1) { - hudX = this.width / 2 - 100; - hudY = this.height / 2 - 20; + Pair<Integer, Integer> dims = DwarvenHud.getDimForConfig(CFG_COMMS); + hudX = this.width / 2 - dims.getLeft(); + hudY = this.height / 2 - dims.getRight(); } return super.mouseClicked(mouseX, mouseY, button); } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/hud/HudCommsWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/hud/HudCommsWidget.java index fa7a607a..ab8546cc 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/hud/HudCommsWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/hud/HudCommsWidget.java @@ -30,6 +30,7 @@ public class HudCommsWidget extends Widget { // when called before the client window is created (roughly). // the rebdering god 2 from the fabricord explained that detail, thanks! public static HudCommsWidget INSTANCE = new HudCommsWidget(); + public static HudCommsWidget INSTANCE_CFG = new HudCommsWidget(); // another repulsive hack to make this widget-like hud element work with the new widget class // DON'T USE WITH THE WIDGET SYSTEM, ONLY USE FOR DWARVENHUD! |