aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin <92656833+kevinthegreat1@users.noreply.github.com>2024-03-18 00:41:11 -0400
committerGitHub <noreply@github.com>2024-03-18 00:41:11 -0400
commit02a7ecc471c3a24a0ef4c9a58b70ebf2510ed55f (patch)
treedb7ec1bc6e5142cd1853c49e3f08148544d16b8e
parent40fc0550c7441ed6966d8a0222b60485180f93e0 (diff)
parent5cf396aa564ba3b93762f914cc2334d48596ab2e (diff)
downloadSkyblocker-02a7ecc471c3a24a0ef4c9a58b70ebf2510ed55f.tar.gz
Skyblocker-02a7ecc471c3a24a0ef4c9a58b70ebf2510ed55f.tar.bz2
Skyblocker-02a7ecc471c3a24a0ef4c9a58b70ebf2510ed55f.zip
Merge pull request #589 from kevinthegreat1/farming-hud
Farming HUD & HUD Refactor
-rw-r--r--src/main/java/de/hysky/skyblocker/SkyblockerMod.java6
-rw-r--r--src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java129
-rw-r--r--src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java24
-rw-r--r--src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java7
-rw-r--r--src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java8
-rw-r--r--src/main/java/de/hysky/skyblocker/config/categories/LocationsCategory.java22
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java17
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java65
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java71
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java75
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/end/EndHudConfigScreen.java29
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/end/TheEnd.java2
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java123
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudConfigScreen.java30
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java67
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java3
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/Ico.java11
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/CameraPositionWidget.java17
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/EmptyWidget.java12
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/Widget.java27
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/ItemUtils.java14
-rw-r--r--src/main/resources/assets/skyblocker/lang/en_us.json7
22 files changed, 504 insertions, 262 deletions
diff --git a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java
index 2987f493..ebb85b36 100644
--- a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java
+++ b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java
@@ -8,8 +8,8 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.debug.Debug;
import de.hysky.skyblocker.skyblock.*;
import de.hysky.skyblocker.skyblock.chat.ChatRuleAnnouncementScreen;
-import de.hysky.skyblocker.skyblock.crimson.kuudra.Kuudra;
import de.hysky.skyblocker.skyblock.chat.ChatRulesHandler;
+import de.hysky.skyblocker.skyblock.crimson.kuudra.Kuudra;
import de.hysky.skyblocker.skyblock.dungeon.*;
import de.hysky.skyblocker.skyblock.dungeon.partyfinder.PartyFinderScreen;
import de.hysky.skyblocker.skyblock.dungeon.puzzle.*;
@@ -22,6 +22,7 @@ import de.hysky.skyblocker.skyblock.dwarven.CrystalsLocationsManager;
import de.hysky.skyblocker.skyblock.dwarven.DwarvenHud;
import de.hysky.skyblocker.skyblock.end.BeaconHighlighter;
import de.hysky.skyblocker.skyblock.end.TheEnd;
+import de.hysky.skyblocker.skyblock.garden.FarmingHud;
import de.hysky.skyblocker.skyblock.garden.VisitorHelper;
import de.hysky.skyblocker.skyblock.item.*;
import de.hysky.skyblocker.skyblock.item.tooltip.BackpackPreview;
@@ -108,8 +109,10 @@ public class SkyblockerMod implements ClientModInitializer {
BackpackPreview.init();
QuickNav.init();
ItemCooldowns.init();
+ TabHud.init();
DwarvenHud.init();
CrystalsHud.init();
+ FarmingHud.init();
CrystalsLocationsManager.init();
ChatMessageListener.init();
Shortcuts.init();
@@ -118,7 +121,6 @@ public class SkyblockerMod implements ClientModInitializer {
DiscordRPCManager.init();
LividColor.init();
FishingHelper.init();
- TabHud.init();
DungeonMap.init();
DungeonManager.init();
DungeonBlaze.init();
diff --git a/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java b/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java
index c33e2f54..07109b46 100644
--- a/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java
+++ b/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java
@@ -2,82 +2,141 @@ 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 it.unimi.dsi.fastutil.ints.IntIntMutablePair;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
+import net.minecraft.util.math.MathHelper;
import java.awt.*;
+import java.util.List;
+/**
+ * A screen for configuring the positions of HUD widgets.
+ * <p>
+ * This class takes care of rendering the widgets, dragging them, and resetting their positions.
+ * Create one subclass for each collection of HUD widgets that are displayed at the same time.
+ * (i.e. one for dwarven mines, one for the end, etc.) See an implementation for an example.
+ */
public abstract class HudConfigScreen extends Screen {
- private final Widget widget;
private final Screen parent;
+ private final List<Widget> widgets;
- private int hudX = 0;
- private int hudY = 0;
- public HudConfigScreen(Text title, Widget widget, Screen parent) {
+ private Widget draggingWidget;
+ private double mouseClickRelativeX;
+ private double mouseClickRelativeY;
+
+ /**
+ * Creates a new HudConfigScreen with the passed title, parent, and widget
+ * @param title the title of the screen
+ * @param parent the parent screen
+ * @param widget the widget to configure
+ */
+ public HudConfigScreen(Text title, Screen parent, Widget widget) {
+ this(title, parent, List.of(widget));
+ }
+
+ /**
+ * Creates a new HudConfigScreen with the passed title, parent, and widgets
+ * @param title the title of the screen
+ * @param parent the parent screen
+ * @param widgets the widgets to configure
+ */
+ public HudConfigScreen(Text title, Screen parent, List<Widget> widgets) {
super(title);
- this.widget = widget;
this.parent = parent;
-
- int[] posFromConfig = getPosFromConfig(SkyblockerConfigManager.get());
- hudX = posFromConfig[0];
- hudY = posFromConfig[1];
+ this.widgets = widgets;
+ resetPos();
}
@Override
- public void render(DrawContext context, int mouseX, int mouseY, float delta) {
+ public final 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);
+ renderWidget(context, widgets);
context.drawCenteredTextWithShadow(textRenderer, "Right Click To Reset Position", width / 2, height / 2, Color.GRAY.getRGB());
}
+ /**
+ * Renders the widgets using the default {@link Widget#render(DrawContext, boolean)} method. Override to change the behavior.
+ * @param context the context to render in
+ * @param widgets the widgets to render
+ */
+ protected void renderWidget(DrawContext context, List<Widget> widgets) {
+ for (Widget widget : widgets) {
+ widget.render(context, SkyblockerConfigManager.get().general.tabHud.enableHudBackground);
+ }
+ }
+
@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);
+ public final boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
+ if (button == 0 && draggingWidget != null) {
+ draggingWidget.setX((int) MathHelper.clamp(mouseX - mouseClickRelativeX, 0, this.width - draggingWidget.getWidth()));
+ draggingWidget.setY((int) MathHelper.clamp(mouseY - mouseClickRelativeY, 0, this.height - draggingWidget.getHeight()));
}
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();
+ public final boolean mouseClicked(double mouseX, double mouseY, int button) {
+ if (button == 0) {
+ for (Widget widget : widgets) {
+ if (RenderHelper.pointIsInArea(mouseX, mouseY, widget.getX(), widget.getY(), widget.getX() + widget.getWidth(), widget.getY() + widget.getHeight())) {
+ draggingWidget = widget;
+ mouseClickRelativeX = mouseX - widget.getX();
+ mouseClickRelativeY = mouseY - widget.getY();
+ break;
+ }
+ }
+ } else if (button == 1) {
+ resetPos();
}
return super.mouseClicked(mouseX, mouseY, button);
}
- abstract protected int[] getPosFromConfig(SkyblockerConfig config);
+ @Override
+ public final boolean mouseReleased(double mouseX, double mouseY, int button) {
+ draggingWidget = null;
+ return super.mouseReleased(mouseX, mouseY, button);
+ }
- protected IntIntPair getDimensions() {
- return new IntIntImmutablePair(widget.getHeight(), widget.getWidth());
+ /**
+ * Resets the positions of the widgets to the positions in the config. Override to change the behavior.
+ */
+ protected void resetPos() {
+ List<IntIntMutablePair> configPositions = getConfigPos(SkyblockerConfigManager.get());
+ if (configPositions.size() != widgets.size()) {
+ throw new IllegalStateException("The number of positions (" + configPositions.size() + ") does not match the number of widgets (" + widgets.size() + ")");
+ }
+ for (int i = 0; i < widgets.size(); i++) {
+ Widget widget = widgets.get(i);
+ IntIntMutablePair configPos = configPositions.get(i);
+ widget.setX(configPos.leftInt());
+ widget.setY(configPos.rightInt());
+ }
}
+ /**
+ * Returns the positions of the widgets in the config
+ * @param config the config to get the positions from
+ * @return the positions of the widgets
+ */
+ protected abstract List<IntIntMutablePair> getConfigPos(SkyblockerConfig config);
+
@Override
- public void close() {
+ public final void close() {
SkyblockerConfig skyblockerConfig = SkyblockerConfigManager.get();
- savePos(skyblockerConfig, hudX, hudY);
+ savePos(skyblockerConfig, widgets);
SkyblockerConfigManager.save();
client.setScreen(parent);
}
/**
- * This method should save the passed position to the config
+ * Saves the passed positions 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
+ * @param widgets the widgets to save
*/
- abstract protected void savePos(SkyblockerConfig configManager, int x, int y);
-
- abstract protected void renderWidget(DrawContext context, int x, int y);
+ protected abstract void savePos(SkyblockerConfig configManager, List<Widget> widgets);
}
diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java
index a86b0111..e006886c 100644
--- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java
+++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java
@@ -267,6 +267,9 @@ public class SkyblockerConfig {
public int tabHudScale = 100;
@SerialEntry
+ public boolean enableHudBackground = true;
+
+ @SerialEntry
public boolean plainPlayerNames = false;
@SerialEntry
@@ -945,9 +948,6 @@ public class SkyblockerConfig {
public DwarvenHudStyle style = DwarvenHudStyle.SIMPLE;
@SerialEntry
- public boolean enableBackground = true;
-
- @SerialEntry
public int x = 10;
@SerialEntry
@@ -1063,9 +1063,6 @@ public class SkyblockerConfig {
public boolean hudEnabled = true;
@SerialEntry
- public boolean enableBackground = true;
-
- @SerialEntry
public boolean waypoint = true;
@SerialEntry
@@ -1090,12 +1087,26 @@ public class SkyblockerConfig {
public static class Garden {
@SerialEntry
+ public FarmingHud farmingHud = new FarmingHud();
+
+ @SerialEntry
public boolean dicerTitlePrevent = true;
@SerialEntry
public boolean visitorHelper = true;
}
+ public static class FarmingHud {
+ @SerialEntry
+ public boolean enableHud = true;
+
+ @SerialEntry
+ public int x;
+
+ @SerialEntry
+ public int y;
+ }
+
public static class Slayer {
@SerialEntry
public EndermanSlayer endermanSlayer = new EndermanSlayer();
@@ -1199,6 +1210,7 @@ public class SkyblockerConfig {
@SerialEntry
public ChatRuleConfig chatRuleConfig = new ChatRuleConfig();
}
+
public static class ChatRuleConfig {
@SerialEntry
public int announcementLength = 60;
diff --git a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java
index 97b48bc4..4ae0fc35 100644
--- a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java
+++ b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java
@@ -76,13 +76,6 @@ public class DwarvenMinesCategory {
.text(Text.translatable("text.skyblocker.open"))
.action((screen, opt) -> MinecraftClient.getInstance().setScreen(new DwarvenHudConfigScreen(screen)))
.build())
- .option(Option.<Boolean>createBuilder()
- .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enableBackground"))
- .binding(defaults.locations.dwarvenMines.dwarvenHud.enableBackground,
- () -> config.locations.dwarvenMines.dwarvenHud.enableBackground,
- newValue -> config.locations.dwarvenMines.dwarvenHud.enableBackground = newValue)
- .controller(ConfigUtils::createBooleanController)
- .build())
.build())
//crystal HUD
.group(OptionGroup.createBuilder()
diff --git a/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java
index afd688d8..23ce7bb6 100644
--- a/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java
+++ b/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java
@@ -107,6 +107,14 @@ public class GeneralCategory {
.controller(opt -> IntegerSliderControllerBuilder.create(opt).range(10, 200).step(1))
.build())
.option(Option.<Boolean>createBuilder()
+ .name(Text.translatable("text.autoconfig.skyblocker.option.general.tabHud.enableHudBackground"))
+ .description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.general.tabHud.enableHudBackground.@Tooltip")))
+ .binding(defaults.general.tabHud.enableHudBackground,
+ () -> config.general.tabHud.enableHudBackground,
+ newValue -> config.general.tabHud.enableHudBackground = newValue)
+ .controller(ConfigUtils::createBooleanController)
+ .build())
+ .option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.general.tabHud.plainPlayerNames"))
.description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.general.tabHud.plainPlayerNames.@Tooltip")))
.binding(defaults.general.tabHud.plainPlayerNames,
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 d97513f8..86ed3f6c 100644
--- a/src/main/java/de/hysky/skyblocker/config/categories/LocationsCategory.java
+++ b/src/main/java/de/hysky/skyblocker/config/categories/LocationsCategory.java
@@ -4,6 +4,7 @@ import de.hysky.skyblocker.config.ConfigUtils;
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.skyblock.end.EndHudConfigScreen;
import de.hysky.skyblocker.skyblock.end.TheEnd;
+import de.hysky.skyblocker.skyblock.garden.FarmingHudConfigScreen;
import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder;
import net.minecraft.client.MinecraftClient;
@@ -91,13 +92,6 @@ public class LocationsCategory {
.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,
@@ -147,6 +141,18 @@ public class LocationsCategory {
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.garden"))
.collapsed(false)
.option(Option.<Boolean>createBuilder()
+ .name(Text.translatable("text.autoconfig.skyblocker.option.locations.garden.farmingHud.enableHud"))
+ .binding(defaults.locations.garden.farmingHud.enableHud,
+ () -> config.locations.garden.farmingHud.enableHud,
+ newValue -> config.locations.garden.farmingHud.enableHud = newValue)
+ .controller(ConfigUtils::createBooleanController)
+ .build())
+ .option(ButtonOption.createBuilder()
+ .name(Text.translatable("text.autoconfig.skyblocker.option.locations.garden.farmingHud.config"))
+ .text(Text.translatable("text.skyblocker.open"))
+ .action((screen, opt) -> MinecraftClient.getInstance().setScreen(new FarmingHudConfigScreen(screen)))
+ .build())
+ .option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.garden.dicerTitlePrevent"))
.binding(defaults.locations.garden.dicerTitlePrevent,
() -> config.locations.garden.dicerTitlePrevent,
@@ -154,7 +160,7 @@ public class LocationsCategory {
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
- .name(Text.translatable("text.autoconfig.skyblocker.option.general.visitorHelper"))
+ .name(Text.translatable("text.autoconfig.skyblocker.option.locations.garden.visitorHelper"))
.binding(defaults.locations.garden.visitorHelper,
() -> config.locations.garden.visitorHelper,
newValue -> config.locations.garden.visitorHelper = newValue)
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java
index 7b15c61e..f113561f 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java
@@ -4,7 +4,6 @@ import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
-import it.unimi.dsi.fastutil.ints.IntIntPair;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
@@ -14,14 +13,13 @@ import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RotationAxis;
+import org.joml.Vector2i;
+import org.joml.Vector2ic;
import java.awt.*;
import java.util.Arrays;
import java.util.Map;
-import org.joml.Vector2i;
-import org.joml.Vector2ic;
-
public class CrystalsHud {
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();
protected static final Identifier MAP_TEXTURE = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/crystals_map.png");
@@ -47,9 +45,8 @@ public class CrystalsHud {
});
}
- protected static IntIntPair getDimensionsForConfig() {
- int size = (int) (62 * SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.mapScaling);
- return IntIntPair.of(size, size);
+ protected static int getDimensionsForConfig() {
+ return (int) (62 * SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.mapScaling);
}
@@ -119,7 +116,7 @@ public class CrystalsHud {
}
/**
- * Converts an X and Z coordinate in the crystal hollow to a X and Y coordinate on the map.
+ * Converts an X and Z coordinate in the crystal hollow to an X and Y coordinate on the map.
*
* @param x the world X coordinate
* @param z the world Z coordinate
@@ -142,8 +139,8 @@ public class CrystalsHud {
* Based off code from {@link net.minecraft.client.render.MapRenderer}
*/
private static float yaw2Cardinal(float yaw) {
- yaw += + 180; //flip direction
- byte clipped = (byte) ((yaw += yaw < 0.0 ? -8.0 : 8.0) * 16.0 / 360.0);
+ yaw += 180; //flip direction
+ byte clipped = (byte) ((yaw + (yaw < 0.0 ? -8.0 : 8.0)) * 16.0 / 360.0);
return (clipped * 360f) / 16f;
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java
index b4e423e9..15e605b9 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java
@@ -1,69 +1,44 @@
package de.hysky.skyblocker.skyblock.dwarven;
-import de.hysky.skyblocker.config.SkyblockerConfigManager;
-import de.hysky.skyblocker.utils.render.RenderHelper;
-import it.unimi.dsi.fastutil.ints.IntIntPair;
+import de.hysky.skyblocker.config.HudConfigScreen;
+import de.hysky.skyblocker.config.SkyblockerConfig;
+import de.hysky.skyblocker.skyblock.tabhud.widget.EmptyWidget;
+import de.hysky.skyblocker.skyblock.tabhud.widget.Widget;
+import it.unimi.dsi.fastutil.ints.IntIntMutablePair;
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;
-public class CrystalsHudConfigScreen extends Screen {
-
- private int hudX = SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.x;
- private int hudY = SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.y;
- private final Screen parent;
+public class CrystalsHudConfigScreen extends HudConfigScreen {
+ private static final EmptyWidget WIDGET = new EmptyWidget();
protected CrystalsHudConfigScreen() {
this(null);
}
public CrystalsHudConfigScreen(Screen parent) {
- super(Text.of("Crystals HUD Config"));
- this.parent = parent;
- }
-
- @Override
- public void render(DrawContext context, int mouseX, int mouseY, float delta) {
- super.render(context, mouseX, mouseY, delta);
- renderBackground(context, mouseX, mouseY, delta);
- renderHUDMap(context, hudX, hudY);
- context.drawCenteredTextWithShadow(textRenderer, "Right Click To Reset Position", width / 2, height / 2, Color.GRAY.getRGB());
+ super(Text.of("Crystals HUD Config"), parent, WIDGET);
+ WIDGET.setDimensions(CrystalsHud.getDimensionsForConfig());
}
+ @SuppressWarnings("SuspiciousNameCombination")
@Override
- public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
- IntIntPair dims = CrystalsHud.getDimensionsForConfig();
- 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);
+ protected List<IntIntMutablePair> getConfigPos(SkyblockerConfig config) {
+ return List.of(IntIntMutablePair.of(config.locations.dwarvenMines.crystalsHud.x, config.locations.dwarvenMines.crystalsHud.y));
}
@Override
- public boolean mouseClicked(double mouseX, double mouseY, int button) {
- if (button == 1) {
- IntIntPair dims = CrystalsHud.getDimensionsForConfig();
- hudX = this.width / 2 - dims.leftInt();
- hudY = this.height / 2 - dims.rightInt();
- }
- return super.mouseClicked(mouseX, mouseY, button);
+ protected void renderWidget(DrawContext context, List<Widget> widgets) {
+ int size = CrystalsHud.getDimensionsForConfig();
+ WIDGET.setDimensions(size);
+ context.drawTexture(CrystalsHud.MAP_TEXTURE, WIDGET.getX(), WIDGET.getY(), 0, 0, size, size, size, size);
}
- private void renderHUDMap(DrawContext context, int x, int y) {
- float scaling = SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.mapScaling;
- int size = (int) (62 * scaling);
- context.drawTexture(CrystalsHud.MAP_TEXTURE, x, y, 0, 0, size, size, size, size);
- }
-
@Override
- public void close() {
- SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.x = hudX;
- SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.y = hudY;
- SkyblockerConfigManager.save();
-
- client.setScreen(parent);
+ protected void savePos(SkyblockerConfig configManager, List<Widget> widgets) {
+ configManager.locations.dwarvenMines.crystalsHud.x = widgets.get(0).getX();
+ configManager.locations.dwarvenMines.crystalsHud.y = widgets.get(0).getY();
}
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java
index 608873c0..8eb15935 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java
@@ -6,8 +6,6 @@ import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudCommsWidget;
import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudPowderWidget;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
-import it.unimi.dsi.fastutil.Pair;
-import it.unimi.dsi.fastutil.ints.IntIntPair;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
@@ -56,7 +54,7 @@ public class DwarvenHud {
.executes(Scheduler.queueOpenScreenCommand(DwarvenHudConfigScreen::new))))));
HudRenderCallback.EVENT.register((context, tickDelta) -> {
- if ((!SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions && !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder)
+ if ((!SkyblockerConfigManager.get().general.tabHud.enableHudBackground && !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder)
|| client.options.playerListKey.isPressed()
|| client.player == null
|| (!Utils.isInDwarvenMines() && !Utils.isInCrystalHollows())) {
@@ -72,52 +70,11 @@ public class DwarvenHud {
});
}
- /**
- * Gets the dimensions (width, height) for the commissions hud and the powder hud
- * @param commissions what commissions to get the dimensions for
- * @return a {@link Pair} of {@link IntIntPair} with the first pair being for the commissions hud and the second pair being for the powder hud
- */
- public static Pair<IntIntPair,IntIntPair> getDimForConfig(List<Commission> commissions) {
- return switch (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.style) {
- case SIMPLE -> {
- HudCommsWidget.INSTANCE_CFG.updateData(commissions, false);
- yield Pair.of(
- IntIntPair.of(
- HudCommsWidget.INSTANCE_CFG.getWidth(),
- HudCommsWidget.INSTANCE_CFG.getHeight()),
- IntIntPair.of(
- HudPowderWidget.INSTANCE_CFG.getWidth(),
- HudPowderWidget.INSTANCE_CFG.getHeight())
- );
- }
- case FANCY -> {
- HudCommsWidget.INSTANCE_CFG.updateData(commissions, true);
- yield Pair.of(
- IntIntPair.of(
- HudCommsWidget.INSTANCE_CFG.getWidth(),
- HudCommsWidget.INSTANCE_CFG.getHeight()),
- IntIntPair.of(
- HudPowderWidget.INSTANCE_CFG.getWidth(),
- HudPowderWidget.INSTANCE_CFG.getHeight())
- );
- }
- default -> Pair.of(
- IntIntPair.of(
- 200,
- 20 * commissions.size()),
- IntIntPair.of(
- 200,
- 40)
- );
- };
- }
-
public static void render(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List<Commission> commissions) {
-
switch (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.style) {
- case SIMPLE -> renderSimple(hcw,hpw, context, comHudX, comHudY,powderHudX,powderHudY, commissions);
- case FANCY -> renderFancy(hcw,hpw, context, comHudX, comHudY,powderHudX,powderHudY, commissions);
- case CLASSIC -> renderClassic(context, comHudX, comHudY,powderHudX,powderHudY, commissions);
+ case SIMPLE -> renderSimple(hcw, hpw, context, comHudX, comHudY, powderHudX, powderHudY, commissions);
+ case FANCY -> renderFancy(hcw, hpw, context, comHudX, comHudY, powderHudX, powderHudY, commissions);
+ case CLASSIC -> renderClassic(context, comHudX, comHudY, powderHudX, powderHudY, commissions);
}
}
@@ -131,11 +88,11 @@ public class DwarvenHud {
* @param commissions the commissions to render to the commissions hud
*/
public static void renderClassic(DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List<Commission> commissions) {
- if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground) {
+ if (SkyblockerConfigManager.get().general.tabHud.enableHudBackground) {
context.fill(comHudX, comHudY, comHudX + 200, comHudY + (20 * commissions.size()), 0x64000000);
context.fill(powderHudX, powderHudY, powderHudX + 200, powderHudY + 40, 0x64000000);
}
- if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) {
+ if (SkyblockerConfigManager.get().general.tabHud.enableHudBackground) {
int y = 0;
for (Commission commission : commissions) {
float percentage;
@@ -167,43 +124,41 @@ public class DwarvenHud {
}
public static void renderSimple(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List<Commission> commissions) {
- if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) {
+ if (SkyblockerConfigManager.get().general.tabHud.enabl