aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/FancyStatusBars.java191
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/auction/EditBidPopup.java13
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/fancybars/BarPositioner.java308
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/fancybars/EditBarColorPopup.java117
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/fancybars/EditBarWidget.java274
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/fancybars/FancyStatusBars.java288
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBar.java353
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBarsConfigScreen.java365
8 files changed, 1706 insertions, 203 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/FancyStatusBars.java b/src/main/java/de/hysky/skyblocker/skyblock/FancyStatusBars.java
deleted file mode 100644
index 3456d1ad..00000000
--- a/src/main/java/de/hysky/skyblocker/skyblock/FancyStatusBars.java
+++ /dev/null
@@ -1,191 +0,0 @@
-package de.hysky.skyblocker.skyblock;
-
-import de.hysky.skyblocker.SkyblockerMod;
-import de.hysky.skyblocker.config.SkyblockerConfigManager;
-import de.hysky.skyblocker.utils.Utils;
-import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.font.TextRenderer;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.util.Identifier;
-
-public class FancyStatusBars {
- private static final Identifier BARS = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/bars.png");
-
- private final MinecraftClient client = MinecraftClient.getInstance();
- private final StatusBarTracker statusBarTracker = SkyblockerMod.getInstance().statusBarTracker;
-
- private final StatusBar[] bars = new StatusBar[]{
- new StatusBar(0, 16733525, 2), // Health Bar
- new StatusBar(1, 5636095, 2), // Intelligence Bar
- new StatusBar(2, 12106180, 1), // Defence Bar
- new StatusBar(3, 8453920, 1), // Experience Bar
- };
-
- // Positions to show the bars
- // 0: Hotbar Layer 1, 1: Hotbar Layer 2, 2: Right of hotbar
- // Anything outside the set values hides the bar
- private final int[] anchorsX = new int[3];
- private final int[] anchorsY = new int[3];
-
- public FancyStatusBars() {
- moveBar(0, 0);
- moveBar(1, 0);
- moveBar(2, 0);
- moveBar(3, 0);
- }
-
- private int fill(int value, int max) {
- return (100 * value) / max;
- }
-
- public boolean render(DrawContext context, int scaledWidth, int scaledHeight) {
- var player = client.player;
- if (!SkyblockerConfigManager.get().general.bars.enableBars || player == null || Utils.isInTheRift())
- return false;
- anchorsX[0] = scaledWidth / 2 - 91;
- anchorsY[0] = scaledHeight - 33;
- anchorsX[1] = anchorsX[0];
- anchorsY[1] = anchorsY[0] - 10;
- anchorsX[2] = (scaledWidth / 2 + 91) + 2;
- anchorsY[2] = scaledHeight - 16;
-
- bars[0].update(statusBarTracker.getHealth());
- bars[1].update(statusBarTracker.getMana());
- int def = statusBarTracker.getDefense();
- bars[2].fill[0] = fill(def, def + 100);
- bars[2].text = def;
- bars[3].fill[0] = (int) (100 * player.experienceProgress);
- bars[3].text = player.experienceLevel;
-
- // Update positions of bars from config
- for (int i = 0; i < 4; i++) {
- int configAnchorNum = switch (i) {
- case 0 -> SkyblockerConfigManager.get().general.bars.barPositions.healthBarPosition.toInt();
- case 1 -> SkyblockerConfigManager.get().general.bars.barPositions.manaBarPosition.toInt();
- case 2 -> SkyblockerConfigManager.get().general.bars.barPositions.defenceBarPosition.toInt();
- case 3 -> SkyblockerConfigManager.get().general.bars.barPositions.experienceBarPosition.toInt();
- default -> 0;
- };
-
- if (bars[i].anchorNum != configAnchorNum)
- moveBar(i, configAnchorNum);
- }
-
- for (var bar : bars) {
- bar.draw(context);
- }
- for (var bar : bars) {
- bar.drawText(context);
- }
- return true;
- }
-
- public void moveBar(int bar, int location) {
- // Set the bar to the new anchor
- bars[bar].anchorNum = location;
-
- // Count how many bars are in each location
- int layer1Count = 0, layer2Count = 0;
- for (int i = 0; i < 4; i++) {
- switch (bars[i].anchorNum) {
- case 0 -> layer1Count++;
- case 1 -> layer2Count++;
- }
- }
-
- // Set the bars width and offsetX according to their anchor and how many bars are on that layer
- int adjustedLayer1Count = 0, adjustedLayer2Count = 0, adjustedRightCount = 0;
- for (int i = 0; i < 4; i++) {
- switch (bars[i].anchorNum) {
- case 0 -> {
- bars[i].bar_width = (172 - ((layer1Count - 1) * 11)) / layer1Count;
- bars[i].offsetX = adjustedLayer1Count * (bars[i].bar_width + 11 + (layer1Count == 3 ? 0 : 1));
- adjustedLayer1Count++;
- }
- case 1 -> {
- bars[i].bar_width = (172 - ((layer2Count - 1) * 11)) / layer2Count;
- bars[i].offsetX = adjustedLayer2Count * (bars[i].bar_width + 11 + (layer2Count == 3 ? 0 : 1));
- adjustedLayer2Count++;
- }
- case 2 -> {
- bars[i].bar_width = 50;
- bars[i].offsetX = adjustedRightCount * (50 + 11);
- adjustedRightCount++;
- }
- }
- }
- }
-
- private class StatusBar {
- public final int[] fill;
- public int offsetX;
- private final int v;
- private final int text_color;
- public int anchorNum;
- public int bar_width;
- public Object text;
-
- private StatusBar(int i, int textColor, int fillNum) {
- this.v = i * 9;
- this.text_color = textColor;
- this.fill = new int[fillNum];
- this.fill[0] = 100;
- this.anchorNum = 0;
- this.text = "";
- }
-
- public void update(StatusBarTracker.Resource resource) {
- int max = resource.max();
- int val = resource.value();
- this.fill[0] = fill(val, max);
- this.fill[1] = fill(resource.overflow(), max);
- this.text = val;
- }
-
- public void draw(DrawContext context) {
- // Dont draw if anchorNum is outside of range
- if (anchorNum < 0 || anchorNum > 2) return;
-
- // Draw the icon for the bar
- context.drawTexture(BARS, anchorsX[anchorNum] + offsetX, anchorsY[anchorNum], 0, v, 9, 9);
-
- // Draw the background for the bar
- context.drawTexture(BARS, anchorsX[anchorNum] + offsetX + 10, anchorsY[anchorNum], 10, v, 2, 9);
- for (int i = 2; i < bar_width - 2; i += 58) {
- context.drawTexture(BARS, anchorsX[anchorNum] + offsetX + 10 + i, anchorsY[anchorNum], 12, v, Math.min(58, bar_width - 2 - i), 9);
- }
- context.drawTexture(BARS, anchorsX[anchorNum] + offsetX + 10 + bar_width - 2, anchorsY[anchorNum], 70, v, 2, 9);
-
- // Draw the filled part of the bar
- for (int i = 0; i < fill.length; i++) {
- int fill_width = this.fill[i] * (bar_width - 2) / 100;
- if (fill_width >= 1) {
- context.drawTexture(BARS, anchorsX[anchorNum] + offsetX + 11, anchorsY[anchorNum], 72 + i * 60, v, 1, 9);
- }
- for (int j = 1; j < fill_width - 1; j += 58) {
- context.drawTexture(BARS, anchorsX[anchorNum] + offsetX + 11 + j, anchorsY[anchorNum], 73 + i * 60, v, Math.min(58, fill_width - 1 - j), 9);
- }
- if (fill_width == bar_width - 2) {
- context.drawTexture(BARS, anchorsX[anchorNum] + offsetX + 11 + fill_width - 1, anchorsY[anchorNum], 131 + i * 60, v, 1, 9);
- }
- }
- }
-
- public void drawText(DrawContext context) {
- // Dont draw if anchorNum is outside of range
- if (anchorNum < 0 || anchorNum > 2) return;
-
- TextRenderer textRenderer = client.textRenderer;
- String text = this.text.toString();
- int x = anchorsX[anchorNum] + this.offsetX + 11 + (bar_width - textRenderer.getWidth(text)) / 2;
- int y = anchorsY[anchorNum] - 3;
-
- final int[] offsets = new int[]{-1, 1};
- for (int i : offsets) {
- context.drawText(textRenderer, text, x + i, y, 0, false);
- context.drawText(textRenderer, text, x, y + i, 0, false);
- }
- context.drawText(textRenderer, text, x, y, text_color, false);
- }
- }
-}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/auction/EditBidPopup.java b/src/main/java/de/hysky/skyblocker/skyblock/auction/EditBidPopup.java
index 6b90b86c..9d460803 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/auction/EditBidPopup.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/auction/EditBidPopup.java
@@ -34,18 +34,7 @@ public class EditBidPopup extends AbstractPopupScreen {
super.init();
layout = DirectionalLayoutWidget.vertical();
layout.spacing(8).getMainPositioner().alignHorizontalCenter();
- textFieldWidget = new TextFieldWidget(textRenderer, 120, 15, Text.empty()) {
- @Override
- public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
- if (!super.keyPressed(keyCode, scanCode, modifiers)) {
- if (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_KP_ENTER) {
- done(null);
- return true;
- }
- } else return true;
- return false;
- }
- };
+ textFieldWidget = new EnterConfirmTextFieldWidget(textRenderer, 120, 15, Text.empty(), () -> done(null));
textFieldWidget.setTextPredicate(this::isStringGood);
layout.add(new TextWidget(Text.literal("- Set Bid -").fillStyle(Style.EMPTY.withBold(true)), textRenderer));
layout.add(textFieldWidget);
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/BarPositioner.java b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/BarPositioner.java
new file mode 100644
index 00000000..a72b955b
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/BarPositioner.java
@@ -0,0 +1,308 @@
+package de.hysky.skyblocker.skyblock.fancybars;
+
+import net.minecraft.client.gui.ScreenPos;
+import net.minecraft.client.gui.ScreenRect;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.*;
+
+public class BarPositioner {
+
+ private final Map<BarAnchor, LinkedList<LinkedList<StatusBar>>> map = new HashMap<>(BarAnchor.values().length);
+
+ public BarPositioner() {
+ for (BarAnchor value : BarAnchor.values()) {
+ map.put(value, new LinkedList<>());
+ }
+ }
+
+
+ public int getRowCount(@NotNull BarAnchor barAnchor) {
+ return map.get(barAnchor).size();
+ }
+
+ /**
+ * Adds a row to the end of an anchor
+ *
+ * @param barAnchor the anchor
+ */
+ public void addRow(@NotNull BarAnchor barAnchor) {
+ map.get(barAnchor).add(new LinkedList<>());
+ }
+
+ /**
+ * Adds a row at the specified index
+ *
+ * @param barAnchor the anchor
+ * @param row row index
+ */
+ public void addRow(@NotNull BarAnchor barAnchor, int row) {
+ map.get(barAnchor).add(row, new LinkedList<>());
+ }
+
+ /**
+ * adds a bar to the end of a row
+ *
+ * @param barAnchor the anchor
+ * @param row the row
+ * @param bar the bar to add
+ */
+ public void addBar(@NotNull BarAnchor barAnchor, int row, StatusBar bar) {
+ LinkedList<StatusBar> statusBars = map.get(barAnchor).get(row);
+ statusBars.add(bar);
+ bar.gridY = row;
+ bar.gridX = statusBars.lastIndexOf(bar); // optimization baby, start with the end!
+ bar.anchor = barAnchor;
+ }
+
+ /**
+ * adds a bar to the specified x in a row
+ *
+ * @param barAnchor the anchor
+ * @param row the row
+ * @param x the index in the row
+ * @param bar the bar to add
+ */
+ public void addBar(@NotNull BarAnchor barAnchor, int row, int x, StatusBar bar) {
+ LinkedList<StatusBar> statusBars = map.get(barAnchor).get(row);
+ statusBars.add(x, bar);
+ bar.gridY = row;
+ bar.gridX = statusBars.indexOf(bar);
+ bar.anchor = barAnchor;
+ }
+
+ /**
+ * removes the specified bar at x on the row. If it's row is empty after being removed, the row will be auto removed
+ *
+ * @param barAnchor the anchor
+ * @param row dah row
+ * @param x dah x
+ */
+ public void removeBar(@NotNull BarAnchor barAnchor, int row, int x) {
+ LinkedList<StatusBar> statusBars = map.get(barAnchor).get(row);
+ StatusBar remove = statusBars.remove(x);
+ remove.anchor = null;
+ for (int i = x; i < statusBars.size(); i++) {
+ statusBars.get(i).gridX--;
+ }
+ if (statusBars.isEmpty()) removeRow(barAnchor, row);
+ }
+
+ /**
+ * removes the specified bar on the row. If it's row is empty after being removed, the row will be auto removed
+ *
+ * @param barAnchor the anchor
+ * @param row dah row
+ * @param bar dah bar
+ */
+ public void removeBar(@NotNull BarAnchor barAnchor, int row, StatusBar bar) {
+ LinkedList<StatusBar> barRow = map.get(barAnchor).get(row);
+ int x = barRow.indexOf(bar);
+ if (x < 0) return; // probably a bad idea
+
+ barRow.remove(bar);
+ bar.anchor = null;
+ for (int i = x; i < barRow.size(); i++) {
+ barRow.get(i).gridX--;
+ }
+ if (barRow.isEmpty()) removeRow(barAnchor, row);
+ }
+
+ /**
+ * row must be empty
+ *
+ * @param barAnchor the anchor
+ * @param row the row to remove
+ */
+ public void removeRow(@NotNull BarAnchor barAnchor, int row) {
+ LinkedList<StatusBar> barRow = map.get(barAnchor).get(row);
+ if (!barRow.isEmpty())
+ throw new IllegalStateException("Can't remove a non-empty row (" + barAnchor + "," + row + ")");
+ map.get(barAnchor).remove(row);
+ for (int i = row; i < map.get(barAnchor).size(); i++) {
+ for (StatusBar statusBar : map.get(barAnchor).get(i)) {
+ statusBar.gridY--;
+ }
+ }
+ }
+
+
+ public LinkedList<StatusBar> getRow(@NotNull BarAnchor barAnchor, int row) {
+ return map.get(barAnchor).get(row);
+ }
+
+ public StatusBar getBar(@NotNull BarAnchor barAnchor, int row, int x) {
+ return map.get(barAnchor).get(row).get(x);
+ }
+
+ public boolean hasNeighbor(@NotNull BarAnchor barAnchor, int row, int x, boolean right) {
+ LinkedList<StatusBar> statusBars = map.get(barAnchor).get(row);
+ if (barAnchor.isRight()) {
+ return (right && x < statusBars.size() - 1) || (!right && x > 0);
+ } else {
+ return (right && x > 0) || (!right && x < statusBars.size() - 1);
+ }
+ }
+
+
+ public enum BarAnchor {
+ HOTBAR_LEFT(true, false,
+ (scaledWidth, scaledHeight) -> new ScreenPos(scaledWidth / 2 - 91 - 2, scaledHeight - 5),
+ SizeRule.freeSize(25, 2, 6)),
+
+ HOTBAR_RIGHT(true, true,
+ (scaledWidth, scaledHeight) -> new ScreenPos(scaledWidth / 2 + 91 + 2, scaledHeight - 5),
+ SizeRule.freeSize(25, 2, 6)),
+
+ HOTBAR_TOP(true, true,
+ (scaledWidth, scaledHeight) -> new ScreenPos(scaledWidth / 2 - 91, scaledHeight - 23),
+ SizeRule.targetSize(12, 182, 2),
+ anchorPosition -> new ScreenRect(anchorPosition.x(), anchorPosition.y() - 20, 182, 20)),
+
+ SCREEN_TOP_LEFT(false, true,
+ ((scaledWidth, scaledHeight) -> new ScreenPos(5, 5)),
+ SizeRule.freeSize(25, 2, 6)
+ ),
+ SCREEN_TOP_RIGHT(false, false,
+ ((scaledWidth, scaledHeight) -> new ScreenPos(scaledWidth - 5, 5)),
+ SizeRule.freeSize(25, 2, 6)
+ ),
+ SCREEN_BOTTOM_LEFT(true, true,
+ ((scaledWidth, scaledHeight) -> new ScreenPos(5, scaledHeight - 5)),
+ SizeRule.freeSize(25, 2, 6)
+ ),
+ SCREEN_BOTTOM_RIGHT(true, false,
+ ((scaledWidth, scaledHeight) -> new ScreenPos(scaledWidth - 5, scaledHeight - 5)),
+ SizeRule.freeSize(25, 2, 6)
+ );
+
+ private final AnchorPositionProvider positionProvider;
+ private final AnchorHitboxProvider hitboxProvider;
+ private final boolean up;
+ private final boolean right;
+ private final SizeRule sizeRule;
+
+ /**
+ * @param up whether the rows stack towards the top of the screen from the anchor (false is bottom)
+ * @param right whether the bars are line up towards the right of the screen from the anchor (false is left)
+ * @param positionProvider provides the position of the anchor for a give screen size
+ * @param sizeRule the rule the bars should follow. See {@link SizeRule}
+ * @param hitboxProvider provides the hitbox for when the anchor has no bars for the config screen
+ */
+ BarAnchor(boolean up, boolean right, AnchorPositionProvider positionProvider, SizeRule sizeRule, AnchorHitboxProvider hitboxProvider) {
+ this.positionProvider = positionProvider;
+ this.up = up;
+ this.right = right;
+ this.hitboxProvider = hitboxProvider;
+ this.sizeRule = sizeRule;
+ }
+
+ BarAnchor(boolean up, boolean right, AnchorPositionProvider positionProvider, SizeRule sizeRule) {
+ this(up, right, positionProvider, sizeRule,
+ anchorPosition -> new ScreenRect(anchorPosition.x() - (right ? 0 : 20), anchorPosition.y() - (up ? 20 : 0), 20, 20));
+ }
+
+ public ScreenPos getAnchorPosition(int scaledWidth, int scaledHeight) {
+ return positionProvider.getPosition(scaledWidth, scaledHeight);
+ }
+
+ public ScreenRect getAnchorHitbox(ScreenPos anchorPosition) {
+ return hitboxProvider.getHitbox(anchorPosition);
+ }
+
+ /**
+ * whether the rows stack towards the top of the screen from the anchor (false is bottom)
+ *
+ * @return true if towards the top, false otherwise
+ */
+ public boolean isUp() {
+ return up;
+ }
+
+ /**
+ * whether the bars are line up towards the right of the screen from the anchor (false is left)
+ *
+ * @return true if towards the right, false otherwise
+ */
+ public boolean isRight() {
+ return right;
+ }
+
+ public SizeRule getSizeRule() {
+ return sizeRule;
+ }
+
+ private static final List<BarAnchor> cached = List.of(values());
+
+ /**
+ * cached version of {@link BarAnchor#values()}
+ *
+ * @return the list of anchors
+ */
+ public static List<BarAnchor> allAnchors() {
+ return cached;
+ }
+ }
+
+ /**
+ * The rules the bars on an anchor should follow
+ *
+ * @param isTargetSize whether the bars went to fit to a target width
+ * @param targetSize the size of all the bars on a row should add up to this (target size)
+ * @param totalWidth the total width taken by all the bars on the row (target size)
+ * @param widthPerSize the width of each size "unit" (free size)
+ * @param minSize the minimum (free and target size)
+ * @param maxSize the maximum (free and target size, THIS SHOULD BE THE SAME AS {@code targetSize} FOR {@code isTargetSize = true})
+ */
+ public record SizeRule(boolean isTargetSize, int targetSize, int totalWidth, int widthPerSize, int minSize, int maxSize) {
+ public static SizeRule freeSize(int widthPerSize, int minSize, int maxSize) {
+ return new SizeRule(false, -1, -1, widthPerSize, minSize, maxSize);
+ }
+
+ public static SizeRule targetSize(int targetSize, int totalWidth, int minSize) {
+ return new SizeRule(true, targetSize, totalWidth, -1, minSize, targetSize);
+ }
+ }
+
+ /**
+ * A record representing a snapshot of a bar's position
+ *
+ * @param barAnchor
+ * @param x
+ * @param y the row
+ */
+ public record BarLocation(@Nullable BarAnchor barAnchor, int x, int y) {
+
+ public static final BarLocation NULL = new BarLocation(null, -1, -1);
+
+ public static BarLocation of(StatusBar bar) {
+ return new BarLocation(bar.anchor, bar.gridX, bar.gridY);
+ }
+
+ public boolean equals(BarAnchor barAnchor, int x, int y) {
+ return x == this.x && y == this.y && barAnchor == this.barAnchor;
+ }
+ }
+
+ /**
+ * provides the position of the anchor for a give screen size
+ */
+ @FunctionalInterface
+ interface AnchorPositionProvider {
+
+ ScreenPos getPosition(int scaledWidth, int scaledHeight);
+ }
+
+ @FunctionalInterface
+ interface AnchorHitboxProvider {
+
+ /**
+ * The hitbox, as in how large the area of "snapping" is if there are no bars on this anchor
+ *
+ * @param anchorPosition the position of the anchor
+ * @return the rectangle that represents the hitbox
+ */
+ ScreenRect getHitbox(ScreenPos anchorPosition);
+ }
+}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/EditBarColorPopup.java b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/EditBarColorPopup.java
new file mode 100644
index 00000000..64e79bab
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/EditBarColorPopup.java
@@ -0,0 +1,117 @@
+package de.hysky.skyblocker.skyblock.fancybars;
+
+import de.hysky.skyblocker.utils.render.gui.AbstractPopupScreen;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.gui.DrawContext;
+import net.minecraft.client.gui.Element;
+import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
+import net.minecraft.client.gui.widget.*;
+import net.minecraft.text.Style;
+import net.minecraft.text.Text;
+
+import java.awt.*;
+import java.util.List;
+import java.util.function.Consumer;
+
+public class EditBarColorPopup extends AbstractPopupScreen {
+
+ private final Consumer<Color> setColor;
+
+ private DirectionalLayoutWidget layout = DirectionalLayoutWidget.vertical();
+ private BasicColorSelector colorSelector;
+
+ protected EditBarColorPopup(Text title, Screen backgroundScreen, Consumer<Color> setColor) {
+ super(title, backgroundScreen);
+ this.setColor = setColor;
+ }
+
+ @Override
+ protected void init() {
+ super.init();
+ layout = DirectionalLayoutWidget.vertical();
+ layout.spacing(8).getMainPositioner().alignHorizontalCenter();
+ layout.add(new TextWidget(title.copy().fillStyle(Style.EMPTY.withBold(true)), MinecraftClient.getInstance().textRenderer));
+ colorSelector = new BasicColorSelector(0, 0, 150, () -> done(null));
+ layout.add(colorSelector);
+
+ DirectionalLayoutWidget horizontal = DirectionalLayoutWidget.horizontal();
+ ButtonWidget buttonWidget = ButtonWidget.builder(Text.literal("Cancel"), button -> close()).width(80).build();
+ horizontal.add(buttonWidget);
+ horizontal.add(ButtonWidget.builder(Text.literal("Done"), this::done).width(80).build());
+
+ layout.add(horizontal);
+ layout.forEachChild(this::addDrawableChild);
+ this.layout.refreshPositions();
+ SimplePositioningWidget.setPos(layout, this.getNavigationFocus());
+ }
+
+ private void done(Object object) {
+ if (colorSelector.validColor) setColor.accept(new Color(colorSelector.getColor()));
+ close();
+ }
+
+ @Override
+ public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) {
+ super.renderBackground(context, mouseX, mouseY, delta);
+ drawPopupBackground(context, layout.getX(), layout.getY(), layout.getWidth(), layout.getHeight());
+ }
+
+ private static class BasicColorSelector extends ContainerWidget {
+
+ private final EnterConfirmTextFieldWidget textFieldWidget;
+
+ public BasicColorSelector(int x, int y, int width, Runnable onEnter) {
+ super(x, y, width, 15, Text.literal("edit color"));
+ textFieldWidget = new EnterConfirmTextFieldWidget(MinecraftClient.getInstance().textRenderer, getX() + 16, getY(), width - 16, 15, Text.empty(), onEnter);
+ textFieldWidget.setChangedListener(this::onTextChange);
+ textFieldWidget.setTextPredicate(s -> s.length() <= 6);
+ }
+
+ @Override
+ public List<? extends Element> children() {
+ return List.of(textFieldWidget);
+ }
+
+ public int getColor() {
+ return color;
+ }
+
+ private int color = 0xFF000000;
+ private boolean validColor = false;
+
+ private void onTextChange(String text) {
+ try {
+ color = Integer.parseInt(text, 16) | 0xFF000000;
+ validColor = true;
+ } catch (NumberFormatException e) {
+ color = 0;
+ validColor = false;
+ }
+ }
+
+ @Override
+ protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
+ context.drawBorder(getX(), getY(), 15, 15, validColor ? -1 : 0xFFDD0000);
+ context.fill(getX() + 1, getY() + 1, getX() + 14, getY() + 14, color);
+ textFieldWidget.renderWidget(context, mouseX, mouseY, delta);
+ }
+
+ @Override
+ protected void appendClickableNarrations(NarrationMessageBuilder builder) {
+
+ }
+
+ @Override
+ public void setX(int x) {
+ super.setX(x);
+ textFieldWidget.setX(getX() + 16);
+ }
+
+ @Override
+ public void setY(int y) {
+ super.setY(y);
+ textFieldWidget.setY(getY());
+ }
+ }
+}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/EditBarWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/EditBarWidget.java
new file mode 100644
index 00000000..54af7a03
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/EditBarWidget.java
@@ -0,0 +1,274 @@
+package de.hysky.skyblocker.skyblock.fancybars;
+
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.font.TextRenderer;
+import net.minecraft.client.gui.DrawContext;
+import net.minecraft.client.gui.Element;
+import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
+import net.minecraft.client.gui.tooltip.TooltipBackgroundRenderer;
+import net.minecraft.client.gui.widget.ClickableWidget;
+import net.minecraft.client.gui.widget.ContainerWidget;
+import net.minecraft.client.gui.widget.TextWidget;
+import net.minecraft.client.util.math.MatrixStack;
+import net.minecraft.text.MutableText;
+import net.minecraft.text.Text;
+import net.minecraft.util.Colors;
+import net.minecraft.util.Formatting;
+
+import java.awt.*;
+import java.util.List;
+import java.util.function.Consumer;
+
+public class EditBarWidget extends ContainerWidget {
+
+ private final EnumCyclingOption<StatusBar.IconPosition> iconOption;
+ private final BooleanOption booleanOption;
+
+ private final ColorOption color1;
+ private final ColorOption color2;
+ private final ColorOption textColor;
+ private final TextWidget nameWidget;
+
+ private int contentsWidth = 0;
+
+ public EditBarWidget(int x, int y, Screen parent) {
+ super(x, y, 100, 66, Text.literal("Edit bar"));
+
+ TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
+
+ nameWidget = new TextWidget(Text.empty(), textRenderer);
+
+ MutableText translatable = Text.translatable("skyblocker.bars.config.icon");
+ contentsWidth = Math.max(contentsWidth, textRenderer.getWidth(translatable) + textRenderer.getWidth("RIGHT") + 10);
+ iconOption = new EnumCyclingOption<>(0, 11, getWidth(), translatable, StatusBar.IconPosition.class);
+
+ translatable = Text.translatable("skyblocker.bars.config.showValue");
+ contentsWidth = Math.max(contentsWidth, textRenderer.getWidth(translatable) + 9 + 10);
+ booleanOption = new BooleanOption(0, 22, getWidth(), translatable);
+
+ // COLO(u)RS
+ translatable = Text.translatable("skyblocker.bars.config.mainColor");
+ contentsWidth = Math.max(contentsWidth, textRenderer.getWidth(translatable) + 9 + 10);
+ color1 = new ColorOption(0, 33, getWidth(), translatable, parent);
+
+ translatable = Text.translatable("skyblocker.bars.config.overflowColor");
+ contentsWidth = Math.max(contentsWidth, textRenderer.getWidth(translatable) + 9 + 10);
+ color2 = new ColorOption(0, 44, getWidth(), translatable, parent);
+
+ translatable = Text.translatable("skyblocker.bars.config.textColor");
+ contentsWidth = Math.max(contentsWidth, textRenderer.getWidth(translatable) + 9 + 10);
+ textColor = new ColorOption(0, 55, getWidth(), translatable, parent);
+
+ setWidth(contentsWidth);
+ }
+
+ @Override
+ public List<? extends Element> children() {
+ return List.of(iconOption, booleanOption, color1, color2, textColor);
+ }
+
+ public int insideMouseX = 0;
+ public int insideMouseY = 0;
+
+ @Override
+ protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
+ if (isHovered()) {
+ insideMouseX = mouseX;
+ insideMouseY = mouseY;
+ } else {
+ int i = mouseX - insideMouseX;
+ int j = mouseY - insideMouseY;
+ if (i * i + j * j > 30 * 30) visible = false;
+ }
+ TooltipBackgroundRenderer.render(context, getX(), getY(), getWidth(), getHeight(), 0);
+ MatrixStack matrices = context.getMatrices();
+ matrices.push();
+ matrices.translate(getX(), getY(), 0);
+ nameWidget.render(context, mouseX, mouseY, delta);
+ iconOption.renderWidget(context, mouseX - getX(), mouseY - getY(), delta);
+ booleanOption.renderWidget(context, mouseX - getX(), mouseY - getY(), delta);
+ color1.renderWidget(context, mouseX - getX(), mouseY - getY(), delta);
+ color2.renderWidget(context, mouseX - getX(), mouseY - getY(), delta);
+ textColor.renderWidget(context, mouseX - getX(), mouseY - getY(), delta);
+ matrices.pop();
+ }
+
+ @Override
+ protected void appendClickableNarrations(NarrationMessageBuilder builder) {
+ }
+
+ @Override
+ public boolean mouseClicked(double mouseX, double mouseY, int button) {
+ if (!visible) return false;
+ if (!isHovered()) visible = false;
+ return super.mouseClicked(mouseX - getX(), mouseY - getY(), button);
+ }
+
+ public void setStatusBar(StatusBar statusBar) {
+ iconOption.setCurrent(statusBar.getIconPosition());
+ iconOption.setOnChange(statusBar::setIconPosition);
+ booleanOption.setCurrent(statusBar.showText());
+ booleanOption.setOnChange(statusBar::setShowText);
+
+ color1.setCurrent(statusBar.getColors()[0].getRGB());
+ color1.setOnChange(color -> statusBar.getColors()[0] = color);
+
+ color2.active = statusBar.hasOverflow();
+ if (color2.active) {
+ color2.setCurrent(statusBar.getColors()[1].getRGB());
+ color2.setOnChange(color -> statusBar.getColors()[1] = color);
+ }
+
+ if (statusBar.getTextColor() != null) {
+ textColor.setCurrent(statusBar.getTextColor().getRGB());
+ }
+ textColor.setOnChange(statusBar::setTextColor);
+
+ MutableText formatted = statusBar.getName().copy().formatted(Formatting.BOLD);
+ nameWidget.setMessage(formatted);
+ setWidth(Math.max(MinecraftClient.getInstance().textRenderer.getWidth(formatted), contentsWidth));
+ }
+
+ @Override
+ public void setWidth(int width) {
+ super.setWidth(width);
+ iconOption.setWidth(width);
+ booleanOption.setWidth(width);
+ color1.setWidth(width);
+ color2.setWidth(width);
+ textColor.setWidth(width);
+ nameWidget.setWidth(width);
+
+ }
+
+ public static class EnumCyclingOption<T extends Enum<T>> extends ClickableWidget {
+
+ private T current;
+ private final T[] values;
+ private Consumer<T> onChange = null;
+
+ public EnumCyclingOption(int x, int y, int width, Text message, Class<T> enumClass) {
+ super(x, y, width, 11, message);
+ values = enumClass.getEnumConstants();
+ current = values[0];
+ }
+
+ @Override
+ protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
+ if (isMouseOver(mouseX, mouseY)) {
+ context.fill(getX(), getY(), getRight(), getBottom(), 0x20FFFFFF);
+ }
+ TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
+ context.drawText(textRenderer, getMessage(), getX() + 1, getY() + 1, -1, true);
+ String string = current.toString();
+ context.drawText(textRenderer, string, getRight() - textRenderer.getWidth(string) - 1, getY() + 1, -1, true);
+ }
+
+ public void setCurrent(T current) {
+ this.current = current;
+ }
+
+ @Override
+ public void onClick(double mouseX, double mouseY) {
+ current = values[(current.ordinal() + 1) % values.length];
+ if (onChange != null) onChange.accept(current);
+ super.onClick(mouseX, mouseY);
+ }
+
+ @Override
+ protected void appendClickableNarrations(NarrationMessageBuilder builder) {
+ }
+
+ public void setOnChange(Consumer<T> onChange) {
+ this.onChange = onChange;
+ }
+ }
+
+ public static class BooleanOption extends ClickableWidget {
+
+ private boolean current = false;
+ private Consumer<Boolean> onChange = null;
+
+ public BooleanOption(int x, int y, int width, Text message) {
+ super(x, y, width, 11, message);
+ }
+
+ @Override
+ protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
+ if (isMouseOver(mouseX, mouseY)) {
+ context.fill(getX(), getY(), getRight(), getBottom(), 0x20FFFFFF);
+ }
+ TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
+ context.drawText(textRenderer, getMessage(), getX() + 1, getY() + 1, -1, true);
+ context.drawBorder(getRight() - 10, getY() + 1, 9, 9, -1);
+ if (current) context.fill(getRight() - 8, getY() + 3, getRight() - 3, getY() + 8, -1);
+ }
+
+ @Override
+ public void onClick(double mouseX, double mouseY) {
+ current = !current;
+ if (onChange != null) onChange.accept(current);
+ super.onClick(mouseX, mouseY);
+ }
+</