aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorvicisacat <victor.branchu@gmail.com>2024-04-17 23:07:49 +0200
committervicisacat <victor.branchu@gmail.com>2024-04-20 16:09:49 +0200
commitf0ff0b555621f2d7f240bc72ccc1c7667badab6f (patch)
tree76feeb4c44483a364cce571eecc4809022c13411 /src/main/java
parentb791e38cbd36360935164e337fa992bf514cbb36 (diff)
downloadSkyblocker-f0ff0b555621f2d7f240bc72ccc1c7667badab6f.tar.gz
Skyblocker-f0ff0b555621f2d7f240bc72ccc1c7667badab6f.tar.bz2
Skyblocker-f0ff0b555621f2d7f240bc72ccc1c7667badab6f.zip
things happened yea
rewrote the entire thing to use semi data-driven BarAnchors help button in the config screen
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java6
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/FancyStatusBars.java233
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/auction/AuctionBrowserScreen.java2
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java2
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java4
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/fancybars/BarPositioner.java319
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBar.java27
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBarsConfigScreen.java299
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/searchoverlay/SearchOverManager.java2
9 files changed, 608 insertions, 286 deletions
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 0c6a3d75..37faaf25 100644
--- a/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java
+++ b/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java
@@ -2,6 +2,7 @@ package de.hysky.skyblocker.config.categories;
import de.hysky.skyblocker.config.ConfigUtils;
import de.hysky.skyblocker.config.SkyblockerConfig;
+import de.hysky.skyblocker.skyblock.fancybars.StatusBarsConfigScreen;
import de.hysky.skyblocker.skyblock.shortcut.ShortcutsConfigScreen;
import de.hysky.skyblocker.utils.render.title.TitleContainerConfigScreen;
import de.hysky.skyblocker.utils.waypoint.Waypoint;
@@ -156,6 +157,11 @@ public class GeneralCategory {
//Fancy Bars
.group(OptionGroup.createBuilder()
+ .option(ButtonOption.createBuilder()
+ .name(Text.translatable("skyblocker.bars.config.openScreen"))
+ .text(Text.translatable("text.skyblocker.open"))
+ .action((screen, opt) -> MinecraftClient.getInstance().setScreen(new StatusBarsConfigScreen()))
+ .build())
.name(Text.translatable("text.autoconfig.skyblocker.option.general.bars"))
.collapsed(true)
.option(Option.<Boolean>createBuilder()
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/FancyStatusBars.java b/src/main/java/de/hysky/skyblocker/skyblock/FancyStatusBars.java
index 6bf012ff..306c2456 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/FancyStatusBars.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/FancyStatusBars.java
@@ -4,6 +4,7 @@ import com.google.gson.JsonObject;
import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.fancybars.BarGrid;
+import de.hysky.skyblocker.skyblock.fancybars.BarPositioner;
import de.hysky.skyblocker.skyblock.fancybars.StatusBar;
import de.hysky.skyblocker.skyblock.fancybars.StatusBarsConfigScreen;
import de.hysky.skyblocker.utils.Utils;
@@ -15,6 +16,7 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
+import net.minecraft.client.gui.ScreenPos;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
@@ -57,6 +59,8 @@ public class FancyStatusBars {
private final int[] anchorsX = new int[3];
private final int[] anchorsY = new int[3];
+ public static BarPositioner barPositioner = new BarPositioner();
+ @Deprecated(forRemoval = true)
public static BarGrid barGrid = new BarGrid();
public static Map<String, StatusBar> statusBars = new HashMap<>();
@@ -76,17 +80,21 @@ public class FancyStatusBars {
// Default positions
StatusBar health = statusBars.get("health");
- health.gridX = 1;
- health.gridY = 1;
+ health.anchor = BarPositioner.BarAnchor.HOTBAR_TOP;
+ health.gridX = 0;
+ health.gridY = 0;
StatusBar intelligence = statusBars.get("intelligence");
- intelligence.gridX = 2;
- intelligence.gridY = 1;
+ intelligence.anchor = BarPositioner.BarAnchor.HOTBAR_TOP;
+ intelligence.gridX = 1;
+ intelligence.gridY = 0;
StatusBar defense = statusBars.get("defense");
- defense.gridX = 1;
- defense.gridY = -1;
+ defense.anchor = BarPositioner.BarAnchor.HOTBAR_RIGHT;
+ defense.gridX = 0;
+ defense.gridY = 0;
StatusBar experience = statusBars.get("experience");
- experience.gridX = 1;
- experience.gridY = 2;
+ experience.anchor = BarPositioner.BarAnchor.HOTBAR_TOP;
+ experience.gridX = 0;
+ experience.gridY = 1;
CompletableFuture.supplyAsync(FancyStatusBars::loadBarConfig).thenAccept(object -> {
if (object != null) {
@@ -102,8 +110,11 @@ public class FancyStatusBars {
}
}
}
- placeBarsInGrid();
+ placeBarsInPositioner();
configLoaded = true;
+ }).exceptionally(throwable -> {
+ LOGGER.error("[Skyblocker] Failed reading status bars config", throwable);
+ return null;
});
ClientLifecycleEvents.CLIENT_STOPPING.register((client) -> {
saveBarConfig();
@@ -119,53 +130,30 @@ public class FancyStatusBars {
//placeBarsInGrid();
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(
- ClientCommandManager.literal("skyblocker")
- .then(ClientCommandManager.literal("bar_test").executes(Scheduler.queueOpenScreenCommand(StatusBarsConfigScreen::new)))));
+ ClientCommandManager.literal(SkyblockerMod.NAMESPACE)
+ .then(ClientCommandManager.literal("bars").executes(Scheduler.queueOpenScreenCommand(StatusBarsConfigScreen::new)))));
}
private static boolean configLoaded = false;
- private static void placeBarsInGrid() {
+ private static void placeBarsInPositioner() {
List<StatusBar> original = statusBars.values().stream().toList();
- // TOP
- List<StatusBar> barList = new ArrayList<>(original.stream().filter(statusBar -> statusBar.gridY > 0).toList());
- barList.sort((a, b) -> a.gridY == b.gridY ? Integer.compare(a.gridX, b.gridX) : Integer.compare(a.gridY, b.gridY));
-
- int y = 0;
- int rowNum = 0;
- for (StatusBar statusBar : barList) {
- if (statusBar.gridY > y) {
- barGrid.addRowToEnd(true, false);
- rowNum++;
- y = statusBar.gridY;
- }
- barGrid.addToEndOfRow(rowNum, false, statusBar);
- }
-
- // BOTTOM LEFT
- barList.clear();
- barList.addAll(original.stream().filter(statusBar -> statusBar.gridY < 0 && statusBar.gridX < 0).toList());
- barList.sort((a, b) -> a.gridY == b.gridY ? -Integer.compare(a.gridX, b.gridX) : -Integer.compare(a.gridY, b.gridY));
- doBottom(false, barList);
-
- // BOTTOM RIGHT
- barList.clear();
- barList.addAll(original.stream().filter(statusBar -> statusBar.gridY < 0 && statusBar.gridX > 0).toList());
- barList.sort((a, b) -> a.gridY == b.gridY ? Integer.compare(a.gridX, b.gridX) : -Integer.compare(a.gridY, b.gridY));
- doBottom(true, barList);
- }
-
- private static void doBottom(boolean right, List<StatusBar> barList) {
- int y = 0;
- int rowNum = 0;
- for (StatusBar statusBar : barList) {
- if (statusBar.gridY < y) {
- barGrid.addRowToEnd(false, right);
- rowNum--;
- y = statusBar.gridY;
+ for (BarPositioner.BarAnchor barAnchor : BarPositioner.BarAnchor.allAnchors()) {
+ List<StatusBar> barList = new ArrayList<>(original.stream().filter(bar -> bar.anchor == barAnchor).toList());
+ if (barList.isEmpty()) continue;
+ barList.sort((a, b) -> a.gridY == b.gridY ? Integer.compare(a.gridX, b.gridX) : Integer.compare(a.gridY, b.gridY));
+
+ int y = -1;
+ int rowNum = -1;
+ for (StatusBar statusBar : barList) {
+ if (statusBar.gridY > y) {
+ barPositioner.addRow(barAnchor);
+ rowNum++;
+ y = statusBar.gridY;
+ }
+ barPositioner.addBar(barAnchor, rowNum, statusBar);
}
- barGrid.addToEndOfRow(rowNum, right, statusBar);
}
}
@@ -193,97 +181,82 @@ public class FancyStatusBars {
public static void updatePositions() {
if (!configLoaded) return;
- final float hotbarSize = 182;
final int width = MinecraftClient.getInstance().getWindow().getScaledWidth();
final int height = MinecraftClient.getInstance().getWindow().getScaledHeight();
- for (StatusBar value : statusBars.values()) {
- if (value.gridX == 0 || value.gridY == 0) {
- value.setX(-1);
- value.setY(-1);
- value.setWidth(0);
- }
- }
-
- // THE TOP
- for (int i = 0; i < barGrid.getTopSize(); i++) {
- List<StatusBar> row = barGrid.getRow(i + 1, false);
- System.out.println(row);
- if (row.isEmpty()) continue;
- int totalSize = 0;
- for (StatusBar bar : row) {
- totalSize += bar.size;
- }
-
- // Fix sizing
- whileLoop:
- while (totalSize != 12) {
- if (totalSize > 12) {
- for (StatusBar bar : row) {
- if (bar.size > bar.getMinimumSize()) { // TODO: this can cause infinite looping if we add more than 6 bars
- bar.size--;
- totalSize--;
- }
- if (totalSize == 12) break whileLoop;
- }
- } else {
- for (StatusBar bar : row) {
- if (bar.size < bar.getMaximumSize()) {
- bar.size++;
- totalSize++;
+ for (BarPositioner.BarAnchor barAnchor : BarPositioner.BarAnchor.allAnchors()) {
+ ScreenPos anchorPosition = barAnchor.getAnchorPosition(width, height);
+ BarPositioner.SizeRule sizeRule = barAnchor.getSizeRule();
+
+ if (sizeRule.isTargetSize()) {
+ for (int row = 0; row < barPositioner.getRowCount(barAnchor); row++) {
+ LinkedList<StatusBar> barRow = barPositioner.getRow(barAnchor, row);
+ if (barRow.isEmpty()) continue;
+
+ // FIX SIZES
+ int totalSize = 0;
+ for (StatusBar statusBar : barRow)
+ totalSize += (statusBar.size = MathHelper.clamp(statusBar.size, sizeRule.minSize(), sizeRule.maxSize()));
+
+ whileLoop:
+ while (totalSize != sizeRule.targetSize()) {
+ if (totalSize > sizeRule.targetSize()) {
+ for (StatusBar statusBar : barRow) {
+ if (statusBar.size > sizeRule.minSize()) {
+ statusBar.size--;
+ totalSize--;
+ if (totalSize == sizeRule.targetSize()) break whileLoop;
+ }
+ }
+ } else {
+ for (StatusBar statusBar : barRow) {
+ if (statusBar.size < sizeRule.maxSize()) {
+ statusBar.size++;
+ totalSize++;
+ if (totalSize == sizeRule.targetSize()) break whileLoop;
+ }
+ }
}
- if (totalSize == 12) break whileLoop;
}
+
}
}
- int x = width / 2 - 91;
- int y = height - 33 - 10 * i;
- int size = 0;
- for (int j = 0; j < row.size(); j++) {
- StatusBar bar = row.get(j);
- bar.setX(x + (int) ((size / 12.d) * hotbarSize));
- bar.setY(y);
- bar.setWidth((int) ((bar.size / 12.d) * hotbarSize));
- size += bar.size;
- bar.gridY = i + 1;
- bar.gridX = j + 1;
- }
- }
+ for (int row = 0; row < barPositioner.getRowCount(barAnchor); row++) {
+ List<StatusBar> barRow = barPositioner.getRow(barAnchor, row);
+ if (barRow.isEmpty()) continue;
- // BOTTOM LEFT
- for (int i = 0; i < barGrid.getBottomLeftSize(); i++) {
- List<StatusBar> row = barGrid.getRow(-(i + 1), false);
- if (row.isEmpty()) continue;
- int x = width / 2 - 91 - 2;
- int y = height - 15 - 10 * (barGrid.getBottomLeftSize() - i - 1);
- for (int j = 0; j < row.size(); j++) {
- StatusBar bar = row.get(j);
- bar.size = MathHelper.clamp(bar.size, bar.getMinimumSize(), bar.getMaximumSize());
- bar.setY(y);
- bar.setWidth(bar.size * 25);
- x -= bar.getWidth();
- bar.setX(x);
- bar.gridX = -j - 1;
- bar.gridY = -i - 1;
- }
- }
- // BOTTOM RIGHT
- for (int i = 0; i < barGrid.getBottomRightSize(); i++) {
- List<StatusBar> row = barGrid.getRow(-(i + 1), true);
- if (row.isEmpty()) continue;
- int x = width / 2 + 91 + 2;
- int y = height - 15 - 10 * (barGrid.getBottomRightSize() - i - 1);
- for (int j = 0; j < row.size(); j++) {
- StatusBar bar = row.get(j);
- bar.size = MathHelper.clamp(bar.size, bar.getMinimumSize(), bar.getMaximumSize());
- bar.setX(x);
- bar.setY(y);
- bar.setWidth(bar.size * 25);
- x += bar.getWidth();
- bar.gridX = j + 1;
- bar.gridY = -i - 1;
+
+ // Update the positions
+ float widthPerSize;
+ if (sizeRule.isTargetSize())
+ widthPerSize = (float) sizeRule.totalWidth() / sizeRule.targetSize();
+ else
+ widthPerSize = sizeRule.widthPerSize();
+
+ int currSize = 0;
+ for (int i = 0; i < barRow.size(); i++) {
+ StatusBar statusBar = barRow.get(i);
+ statusBar.size = MathHelper.clamp(statusBar.size, sizeRule.minSize(), sizeRule.maxSize());
+
+ float x = barAnchor.isRight() ?
+ anchorPosition.x() + currSize * widthPerSize :
+ anchorPosition.x() - currSize * widthPerSize - statusBar.size * widthPerSize;
+ statusBar.setX((int) x);
+
+ int y = barAnchor.isUp() ?
+ anchorPosition.y() - (row + 1) * (statusBar.getHeight() + 1) :
+ anchorPosition.y() + row * (statusBar.getHeight() + 1);
+ statusBar.setY(y);
+
+ statusBar.setWidth((int) (statusBar.size * widthPerSize));
+ currSize += statusBar.size;
+ statusBar.gridX = i;
+ statusBar.gridY = row;
+
+ }
}
+
}
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/auction/AuctionBrowserScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/auction/AuctionBrowserScreen.java
index c8bc1f13..d6111f1b 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/auction/AuctionBrowserScreen.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/auction/AuctionBrowserScreen.java
@@ -352,7 +352,7 @@ public class AuctionBrowserScreen extends AbstractCustomHypixelGUI<AuctionHouseS
List<Text> tooltip = ItemUtils.getNbtTooltips(stack);
String str = tooltip.get(0).getString().trim();
str = str.substring(1, str.length() - 1); // remove parentheses
- String[] parts = str.split("/"); // split the string
+ String[] parts = str.split("/"); // targetSize the string
currentPage = Integer.parseInt(parts[0].replace(",", "")); // parse current page
totalPages = Integer.parseInt(parts[1].replace(",", "")); // parse total
} catch (Exception e) {
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java
index 34cc6352..65cbde5b 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRule.java
@@ -235,7 +235,7 @@ public class ChatRule {
String rawLocation = Utils.getLocationRaw();
Boolean isLocationValid = null;
- for (String validLocation : validLocations.replace(" ", "").toLowerCase().split(",")) {//the locations are raw locations split by "," and start with ! if not locations
+ for (String validLocation : validLocations.replace(" ", "").toLowerCase().split(",")) {//the locations are raw locations targetSize by "," and start with ! if not locations
String rawValidLocation = ChatRulesHandler.locations.get(validLocation.replace("!",""));
if (rawValidLocation == null) continue;
if (validLocation.startsWith("!")) {//not location
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java
index 8e0073f7..3d373025 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java
@@ -117,7 +117,7 @@ public class DungeonMapUtils {
* @param mapEntrancePos the map position of the top left corner of the entrance
* @param mapRoomSize the size of a room on the map
* @return the map position of the top left corner of the room the player is in
- * @implNote {@code mapPos} is shifted by 2 so room borders are evenly split.
+ * @implNote {@code mapPos} is shifted by 2 so room borders are evenly targetSize.
* {@code mapPos} is then shifted by {@code offset} to align the top left most room at (0, 0)
* so subtracting the modulo will give the top left corner of the room shifted by {@code offset}.
* Finally, {@code mapPos} is shifted back by {@code offset} to its intended position.
@@ -168,7 +168,7 @@ public class DungeonMapUtils {
* @param x the x position of the coordinate to calculate
* @param z the z position of the coordinate to calculate
* @return the physical position of the northwest corner of the room the player is in
- * @implNote {@code physicalPos} is shifted by 0.5 so room borders are evenly split.
+ * @implNote {@code physicalPos} is shifted by 0.5 so room borders are evenly targetSize.
* {@code physicalPos} is further shifted by 8 because Hypixel offset dungeons by 8 blocks in Skyblock 0.12.3.
* Subtracting the modulo gives the northwest corner of the room shifted by 8. Finally, {@code physicalPos} is shifted back by 8 to its intended position.
*/
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..7fde9117
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/BarPositioner.java
@@ -0,0 +1,319 @@
+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);
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (this == object) return true;
+ if (object == null || getClass() != object.getClass()) return false;
+
+ BarLocation that = (BarLocation) object;
+ return x == that.x && y == that.y && barAnchor == that.barAnchor;
+ }
+
+ 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/StatusBar.java b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBar.java
index ea4a0388..5ece1934 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBar.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBar.java
@@ -86,12 +86,14 @@ public class StatusBar implements Widget, Drawable, Element, Selectable {
private @Nullable OnClick onClick = null;
public int gridX = 0;
public int gridY = 0;
+ public @Nullable BarPositioner.BarAnchor anchor = null;
public int size = 1;
private int width = 0;
public float fill = 0;
public float overflowFill = 0;
+ public boolean ghost = false;
private Object value = "";
@@ -116,6 +118,8 @@ public class StatusBar implements Widget, Drawable, Element, Selectable {
@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
if (width <= 0) return;
+ // half works lol. only puts transparency on the filler of the bar
+ if (ghost) context.setShaderColor(1f,1f,1f,0.25f);
switch (iconPosition) {
case LEFT -> context.drawGuiTexture(icon, x, y, 9, 9);
case RIGHT -> context.drawGuiTexture(icon, x + width - 9, y, 9, 9);
@@ -130,6 +134,7 @@ public class StatusBar implements Widget, Drawable, Element, Selectable {
if (hasOverflow && overflowFill > 0) {
RenderHelper.renderNineSliceColored(context, BAR_FILL, barX + 1, y + 2, (int) ((barWith - 2) * overflowFill), 5, colors[1]);
}
+ if (ghost) context.setShaderColor(1f,1f,1f,1f);
//context.drawText(MinecraftClient.getInstance().textRenderer, gridX + " " + gridY + " s:" + size , x, y-9, Colors.WHITE, true);
}
@@ -159,13 +164,19 @@ public class StatusBar implements Widget, Drawable, Element, Selectable {
int temp_x = x;
int temp_y = y;
int temp_width = width;
+ boolean temp_ghost = ghost;
+
x = mouseX;
y = mouseY;
width = 100;
+ ghost = false;
+
render(context, mouseX, mouseY, delta);
+
x = temp_x;
y = temp_y;
width = temp_width;
+ ghost = temp_ghost;
}
// GUI shenanigans
@@ -204,14 +215,6 @@ public class StatusBar implements Widget, Drawable, Element, Selectable {
return 9;
}
- public int getMinimumSize() {
- return 2;
- }
-
- public int getMaximumSize() {
- return gridY < 0 ? 6 : 12;
- }
-
@Override
public ScreenRect getNavigationFocus() {
return Widget.super.getNavigationFocus();
@@ -267,6 +270,7 @@ public class StatusBar implements Widget, Drawable, Element, Selectable {
.append("x", x)
.append("y", y)
.append("width", width)
+ .append("anchor", anchor)
.toString();
}
@@ -315,11 +319,13 @@ public class StatusBar implements Widget, Drawable, Element, Selectable {
if (object.has("text_color")) this.textColor = new Color(Integer.parseInt(object.get("text_color").getAsString(), 16));
+ String maybeAnchor = object.get("anchor").getAsString().trim();
+ this.anchor = maybeAnchor.equals("null") ? null : BarPositioner.BarAnchor.valueOf(maybeAnchor);
this.size = object.get("size").getAsInt();
this.gridX = object.get("x").getAsInt();
this.gridY = object.get("y").getAsInt();
// these are optional too, why not
- if (object.has("icon_position")) this.iconPosition = IconPosition.valueOf(object.get("icon_position").getAsString());
+ if (object.has("icon_position")) this.iconPosition = IconPosition.valueOf(object.get("icon_position").getAsString().trim());
if (object.has("show_text")) this.showText = object.get("show_text").getAsBoolean();
}
@@ -335,6 +341,9 @@ public class StatusBar implements Widget, Drawable, Element, Selectable {
object.addProperty("text_color", Integer.toHexString(textColor.getRGB()).substring(2));
}
object.addProperty("size", size);
+ if (anchor != null) {
+ object.addProperty("anchor", anchor.toString());
+ } else object.addProperty("anchor", "null");
object.addProperty("x", gridX);
object.addProperty("y", gridY);
object.addProperty("icon_position", iconPosition.toString());
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBarsConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBarsConfigScreen.java
index 3bcc2011..7c1aa71b 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBarsConfigScreen.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBarsConfigScreen.java
@@ -10,12 +10,14 @@ import net.minecraft.client.gui.ScreenPos;
import net.minecraft.client.gui.ScreenRect;
import net.minecraft.client.gui.navigation.NavigationAxis;
import net.minecraft.client.gui.navigation.NavigationDirection;
+import net.minecraft.client.gui.screen.PopupScreen;
import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.text.Text;
-import net.minecraft.util.Colors;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
+import de.hysky.skyblocker.skyblock.fancybars.BarPositioner.BarLocation;
import java.util.Collection;
import java.util.HashMap;
@@ -27,7 +29,7 @@ public class StatusBarsConfigScreen extends Screen {
public static final long RESIZE_CURSOR = GLFW.glfwCreateStandardCursor(GLFW.GLFW_HRESIZE_CURSOR);
- private final Map<ScreenRect, int[]> meaningFullName = new HashMap<>();
+ private final Map<ScreenRect, BarLocation> meaningFullName = new HashMap<>();
private static final int HOTBAR_WIDTH = 182;
private @Nullable StatusBar cursorBar = null;
@@ -37,21 +39,24 @@ public class StatusBarsConfigScreen extends Screen {
FancyStatusBars.updatePositions();
}
- private final int[] currentCursorCoords = new int[]{0, 0};
+ private BarLocation currentInsertLocation = new BarLocation(null, 0, 0);
- private final Pair<int[], Boolean> resizeHover = new ObjectBooleanMutablePair<>(new int[]{0, 0}, false);
+ private final Pair<BarLocation, Boolean> resizeHover = new ObjectBooleanMutablePair<>(BarLocation.NULL, false);
- private final Pair<int[], int[]> resizedBars = ObjectObjectMutablePair.of(new int[]{0, 0}, new int[]{0, 0});
+ private final Pair<BarLocation, BarLocation> resizedBars = ObjectObjectMutablePair.of(BarLocation.NULL, BarLocation.NULL);
private boolean resizing = false;
private EditBarWidget editBarWidget;
+ // prioritize left and right cuz they are much smaller space than up and down
+ private static final NavigationDirection[] DIRECTION_CHECK_ORDER = new NavigationDirection[]{NavigationDirection.LEFT, NavigationDirection.RIGHT, NavigationDirection.UP, NavigationDirection.DOWN};
+
@SuppressWarnings("UnreachableCode") // IntelliJ big stupid
@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
- for (ScreenRect screenRect : meaningFullName.keySet()) {
+ /*for (ScreenRect screenRect : meaningFullName.keySet()) {
context.fillGradient(screenRect.position().x(), screenRect.position().y(), screenRect.position().x() + screenRect.width(), screenRect.position().y() + screenRect.height(), 0xFFFF0000, 0xFF0000FF);
- }
+ }*/
super.render(context, mouseX, mouseY, delta);
context.drawGuiTexture(HOTBAR_TEXTURE, width / 2 - HOTBAR_WIDTH / 2, height - 22, HOTBAR_WIDTH, 22);
editBarWidget.render(context, mouseX, mouseY, delta);
@@ -60,109 +65,99 @@ public class StatusBarsConfigScreen extends Screen {
assert client != null;
WindowAccessor window = (WindowAccessor) (Object) client.getWindow();
assert window != null;
+
if (cursorBar != null) {
cursorBar.renderCursor(context, mouseX, mouseY, delta);
- context.drawText(textRenderer, currentCursorCoords[0] + " " + currentCursorCoords[1], 100, 5, Colors.WHITE, true);
-
-
- if (FancyStatusBars.barGrid.getTopSize() == 0 && topBarZone.overlaps(mouseRect) && currentCursorCoords[1] != 1) {
- FancyStatusBars.barGrid.remove(cursorBar.gridX, cursorBar.gridY);
- FancyStatusBars.barGrid.addRow(1, true);
- FancyStatusBars.barGrid.add(1, 1, cursorBar);
- currentCursorCoords[1] = 1;
- FancyStatusBars.updatePositions();
- } else if (FancyStatusBars.barGrid.getBottomLeftSize() == 0 && bottomLeftBarZone.overlaps(mouseRect) && (currentCursorCoords[0] != -1 || currentCursorCoords[1] != -1)) {
- FancyStatusBars.barGrid.remove(cursorBar.gridX, cursorBar.gridY);
- FancyStatusBars.barGrid.addRow(-1, false);
- FancyStatusBars.barGrid.add(-1, -1, cursorBar);
- currentCursorCoords[0] = -1;
- currentCursorCoords[1] = -1;
- FancyStatusBars.updatePositions();
- } else if (FancyStatusBars.barGrid.getBottomRightSize() == 0 && bottomRightBarZone.overlaps(mouseRect) && (currentCursorCoords[0] != 1 || currentCursorCoords[1] != -1)) {
- FancyStatusBars.barGrid.remove(cursorBar.gridX, cursorBar.gridY);
- FancyStatusBars.barGrid.addRow(-1, true);
- FancyStatusBars.barGrid.add(1, -1, cursorBar);
- currentCursorCoords[0] = 1;
- currentCursorCoords[1] = -1;
- FancyStatusBars.updatePositions();
- } else rectLoop:for (ScreenRect screenRect : meaningFullName.keySet()) {
- for (NavigationDirection direction : NavigationDirection.values()) {
+ boolean inserted = false;
+ rectLoop:
+ for (ScreenRect screenRect : meaningFullName.keySet()) {
+ for (NavigationDirection direction : DIRECTION_CHECK_ORDER) {
boolean overlaps = screenRect.getBorder(direction).add(direction).overlaps(mouseRect);
if (overlaps) {
- int[] ints = meaningFullName.get(screenRect);
- final boolean vertical = direction.getAxis().equals(NavigationAxis.VERTICAL);
- int offsetX = 0;
- int offsetY = 0;
- if (vertical) {
- if (!direction.isPositive()) {
- offsetY = ints[1] > 0 ? 1 : 0;
- } else {
- offsetY = ints[1] > 0 ? 0 : -1;
+ BarLocation barSnap = meaningFullName.get(screenRect);
+ if (direction.getAxis().equals(NavigationAxis.VERTICAL)) {
+ int neighborInsertY = getNeighborInsertY(barSnap, !direction.isPositive());
+ if (!currentInsertLocation.equals(barSnap.barAnchor(), barSnap.x(), neighborInsertY)) {
+ if (cursorBar.anchor != null)
+ FancyStatusBars.barPositioner.removeBar(cursorBar.anchor, cursorBar.gridY, cursorBar);
+ FancyStatusBars.barPositioner.addRow(barSnap.barAnchor(), neighborInsertY);
+ FancyStatusBars.barPositioner.addBar(barSnap.barAnchor(), neighborInsertY, cursorBar);
+ currentInsertLocation = BarLocation.of(cursorBar);
+ inserted = true;
}
} else {
- if (direction.isPositive()) {
- offsetX = ints[0] > 0 ? 1 : 0;
- } else {
- offsetX = ints[0] > 0 ? 0 : -1;
- }
- }
- context.drawText(textRenderer, ints[0] + offsetX + " " + ints[1] + offsetY, 100, 15, Colors.WHITE, true);
- if (ints[0] + offsetX != currentCursorCoords[0] || ints[1] + offsetY != currentCursorCoords[1]) {
- currentCursorCoords[0] = ints[0] + offsetX;
- currentCursorCoords[1] = ints[1] + offsetY;
- FancyStatusBars.barGrid.remove(cursorBar.gridX, cursorBar.gridY);
-
-
- if (vertical) {
-
- FancyStatusBars.barGrid.addRow(ints[1] + offsetY, ints[0] > 0);
- FancyStatusBars.barGrid.add(ints[0] < 0 ? -1 : 1, ints[1] + offsetY, cursorBar);
- } else {
-
- FancyStatusBars.barGrid.add(ints[0] + offsetX, ints[1], cursorBar);
+ int neighborInsertX = getNeighborInsertX(barSnap, direction.isPositive());
+ if (!currentInsertLocation.equals(barSnap.barAnchor(), neighborInsertX, barSnap.y())) {
+ if (cursorBar.anchor != null)
+ FancyStatusBars.barPositioner.removeBar(cursorBar.anchor, cursorBar.gridY, cursorBar);
+ FancyStatusBars.barPositioner.addBar(barSnap.barAnchor(), barSnap.y(), neighborInsertX, cursorBar);
+ currentInsertLocation = BarLocation.of(cursorBar);
+ inserted = true;
}
- FancyStatusBars.updatePositions();
}
break rectLoop;
}
}
}
+ if (inserted) {
+ FancyStatusBars.updatePositions();
+ return;
+ }
+ // check for hovering empty anchors
+ for (BarPositioner.BarAnchor barAnchor : BarPositioner.BarAnchor.allAnchors()) {
+ if (FancyStatusBars.barPositioner.getRowCount(barAnchor) != 0) continue;
+ ScreenRect anchorHitbox = barAnchor.getAnchorHitbox(barAnchor.getAnchorPosition(width, height));
+ context.fill(anchorHitbox.getLeft(), anchorHitbox.getTop(), anchorHitbox.getRight(), anchorHitbox.getBottom(), 0x99FFFFFF);
+ if (anchorHitbox.overlaps(mouseRect) && currentInsertLocation.barAnchor() != barAnchor) {
+ if (cursorBar.anchor != null)
+ FancyStatusBars.barPositioner.removeBar(cursorBar.anchor, cursorBar.gridY, cursorBar);
+ FancyStatusBars.barPositioner.addRow(barAnchor);
+ FancyStatusBars.barPositioner.addBar(barAnchor, 0, cursorBar);
+ currentInsertLocation = BarLocation.of(cursorBar);
+ FancyStatusBars.updatePositions();
+ }
+ }
} else {
- // RESIZING STATE
- if (resizing) {
+ if (resizing) { // actively resizing one or 2 bars
int middleX;
- boolean bottom;
- int[] left = resizedBars.left();
- int[] right = resizedBars.right();
- boolean hasRight = right[0] != 0;
- boolean hasLeft = left[0] != 0;
+ BarLocation left = resizedBars.left();
+ BarLocation right = resizedBars.right();
+ boolean hasRight = !right.equals(BarLocation.NULL);
+ boolean hasLeft = !left.equals(BarLocation.NULL);
+ BarPositioner.BarAnchor barAnchor;
if (!hasRight) {
- StatusBar bar = FancyStatusBars.barGrid.getBar(left[0], left[1]);
+ barAnchor = left.barAnchor();
+ StatusBar bar = FancyStatusBars.barPositioner.getBar(barAnchor, left.y(), left.x());
middleX = bar.getX() + bar.getWidth();
- bottom = bar.gridY < 0;
} else {
- middleX = FancyStatusBars.barGrid.getBar(right[0], right[1]).getX();
- bottom = right[1] < 0;
+ barAnchor = right.barAnchor();
+ middleX = FancyStatusBars.barPositioner.getBar(barAnchor, right.y(), right.x()).getX();
}
- int i = bottom ? 20 : 10;
+
boolean doResize = true;
StatusBar rightBar = null;
StatusBar leftBar = null;
- context.drawText(textRenderer, Integer.toString(mouseX - middleX), 100, 25, -1, true);
+ BarPositioner.SizeRule sizeRule = barAnchor.getSizeRule();
- if (mouseX < middleX) {
- if (middleX - mouseX > i) {
+ float widthPerSize;
+ if (sizeRule.isTargetSize())
+ widthPerSize = (float) sizeRule.totalWidth() / sizeRule.targetSize();
+ else
+ widthPerSize = sizeRule.widthPerSize();
+ // resize towards the left
+ if (mouseX < middleX) {
+ if (middleX - mouseX > widthPerSize / .75f) {
if (hasRight) {
- rightBar = FancyStatusBars.barGrid.getBar(right[0], right[1]);
- if (rightBar.size + 1 > rightBar.getMaximumSize()) doResize = false;
+ rightBar = FancyStatusBars.barPositioner.getBar(barAnchor, right.y(), right.x());
+ if (rightBar.size + 1 > sizeRule.maxSize()) doResize = false;
}
if (hasLeft) {
- leftBar = FancyStatusBars.barGrid.getBar(left[0], left[1]);
- if (leftBar.size - 1 < leftBar.getMinimumSize()) doResize = false;
+ leftBar = FancyStatusBars.barPositioner.getBar(barAnchor, left.y(), left.x());
+ if (leftBar.size - 1 < sizeRule.minSize()) doResize = false;
}
if (doResize) {
@@ -171,18 +166,16 @@ public class StatusBarsConfigScreen extends Screen {
FancyStatusBars.updatePositions();
}
}
- } else {
- if (mouseX - middleX > i) {
-
+ } else { // towards the right
+ if (mouseX - middleX > widthPerSize / .75f) {
if (hasRight) {
- rightBar = FancyStatusBars.barGrid.getBar(right[0], right[1]);
- if (rightBar.size - 1 < rightBar.getMinimumSize()) doResize = false;
+ rightBar = FancyStatusBars.barPositioner.getBar(barAnchor, right.y(), right.x());
+ if (rightBar.size - 1 < sizeRule.minSize()) doResize = false;
}
if (hasLeft) {
- leftBar = FancyStatusBars.barGrid.getBar(left[0], left[1]);
- if (leftBar.size + 1 > leftBar.getMaximumSize()) doResize = false;
+ leftBar = FancyStatusBars.barPositioner.getBar(barAnchor, left.y(), left.x());
+ if (leftBar.size + 1 > sizeRule.maxSize()) doResize = false;
}
- context.drawText(textRenderer, leftBar.size + " " + leftBar.getMaximumSize(), 100, 35, -1, true);
if (doResize) {
if (hasRight) rightBar.size--;
@@ -191,29 +184,26 @@ public class StatusBarsConfigScreen extends Screen {
}
}
}
- GLFW.glfwSetCursor(window.getHandle(), RESIZE_CURSOR);
- }
- // NOT RESIZING STATE
- else {
+
+ } else { // hovering bars
rectLoop:
for (ScreenRect screenRect : meaningFullName.keySet()) {
for (NavigationDirection direction : new NavigationDirection[]{NavigationDirection.LEFT, NavigationDirection.RIGHT}) {
boolean overlaps = screenRect.getBorder(direction).add(direction).overlaps(mouseRect);
if (overlaps && !editBarWidget.isMouseOver(mouseX, mouseY)) {
- int[] ints = meaningFullName.get(screenRect);
- boolean left = direction.equals(NavigationDirection.LEFT);
- if ((ints[0] == 1 && left) || (ints[0] == -1 && !left) || (!left && ints[1] > 0 && ints[0] == FancyStatusBars.barGrid.getRow(ints[1], true).size())) {
+ BarLocation barLocation = meaningFullName.get(screenRect);
+ boolean right = direction.equals(NavigationDirection.RIGHT);
+ // can't resize on the edge of a target size row!
+ if (barLocation.barAnchor().getSizeRule().isTargetSize() && !FancyStatusBars.barPositioner.hasNeighbor(barLocation.barAnchor(), barLocation.y(), barLocation.x(), right)) {
break;
}
- resizeHover.first()[0] = ints[0];
- resizeHover.first()[1] = ints[1];
- resizeHover.right(!left);
+ resizeHover.first(barLocation);
+ resizeHover.right(right);
GLFW.glfwSetCursor(window.getHandle(), RESIZE_CURSOR);
break rectLoop;
} else {
- resizeHover.first()[0] = 0;
- resizeHover.first()[1] = 0;
+ resizeHover.first(BarLocation.NULL);
GLFW.glfwSetCursor(window.getHandle(), 0);
}
}
@@ -222,9 +212,27 @@ public class StatusBarsConfigScreen extends Screen {
}
}
- private ScreenRect topBarZone = new ScreenRect(0, 0, 0, 0);
- private ScreenRect bottomLeftBarZone = new ScreenRect(0, 0, 0, 0);
- private ScreenRect bottomRightBarZone = new ScreenRect(0, 0, 0, 0);
+ private static int getNeighborInsertX(BarLocation barLocation, boolean right) {
+ BarPositioner.BarAnchor barAnchor = barLocation.barAnchor();
+ int gridX = barLocation.x();
+ if (barAnchor == null) return 0;
+ if (right) {
+ return barAnchor.isRight() ? gridX + 1 : gridX;
+ } else {
+ return barAnchor.isRight() ? gridX : gridX + 1;
+ }
+ }
+
+ private static int getNeighborInsertY(BarLocation barLocation, boolean up) {
+ BarPositioner.BarAnchor barAnchor = barLocation.barAnchor();
+ int gridY = barLocation.y();
+ if (barAnchor == null) return 0;
+ if (up) {
+ return barAnchor.isUp() ? gridY + 1 : gridY;
+ } else {
+ return barAnchor.isUp() ? gridY : gridY + 1;
+ }
+ }
@Override
protected void init() {
@@ -234,24 +242,31 @@ public class StatusBarsConfigScreen extends Screen {
addSelectableChild(editBarWidget); // rendering separately to have it above hotbar
Collection<StatusBar> values = FancyStatusBars.statusBars.values();
values.forEach(this::setup);
- checkZeroCoordinates(values);
+ checkNullAnchor(values);
updateScreenRects();
- topBarZone = new ScreenRect(width / 2 - HOTBAR_WIDTH / 2, height - 22 - 15, HOTBAR_WIDTH, 15);
- bottomLeftBarZone = new ScreenRect(width / 2 - HOTBAR_WIDTH / 2 - 20, height - 22, 20, 22);
- bottomRightBarZone = new ScreenRect(width / 2 + HOTBAR_WIDTH / 2, height - 22, 20, 22);
+ this.addDrawableChild(ButtonWidget.builder(Text.literal("?"),
+ button -> {
+ assert client != null;
+ client.setScreen(new PopupScreen.Builder(this, Text.translatable("skyblocker.bars.config.explanationTitle"))
+ .button(Text.translatable("gui.ok"), PopupScreen::close)
+ .message(Text.translatable("skyblocker.bars.config.explanation"))
+ .build());
+ })
+ .dimensions(width - 20, (height - 15) / 2, 15, 15)
+ .build());
}
private void setup(StatusBar statusBar) {
this.addDrawableChild(statusBar);
- statusBar.setOnClick(this::onClick);
+ statusBar.setOnClick(this::onBarClick);
}
- private static void checkZeroCoordinates(Iterable<StatusBar> bars) {
+ private static void checkNullAnchor(Iterable<StatusBar> bars) {
int offset = 0;
for (StatusBar statusBar : bars) {
- if (statusBar.gridX == 0 || statusBar.gridY == 0) {
+ if (statusBar.anchor == null) {
statusBar.setX(5);
- statusBar.setY(5 + offset);
+ statusBar.setY(50 + offset);
statusBar.setWidth(30);
offset += statusBar.getHeight();
}
@@ -263,6 +278,7 @@ public class StatusBarsConfigScreen extends Screen {
public void removed() {
super.removed();
FancyStatusBars.statusBars.values().forEach(statusBar -> statusBar.setOnClick(null));
+ if (cursorBar != null) cursorBar.ghost = false;
FancyStatusBars.updatePositions();
assert client != null;
GLFW.glfwSetCursor(((WindowAccessor) (Object) client.getWindow()).getHandle(), 0);
@@ -274,11 +290,14 @@ public class StatusBarsConfigScreen extends Screen {
return false;
}
- private void onClick(StatusBar statusBar, int button, int mouseX, int mouseY) {
+ private void onBarClick(StatusBar statusBar, int button, int mouseX, int mouseY) {
if (button == 0) {
cursorBar = statusBar;
- FancyStatusBars.barGrid.remove(statusBar.gridX, statusBar.gridY);
+ cursorBar.ghost = true;
+ if (statusBar.anchor != null)
+ FancyStatusBars.barPositioner.removeBar(statusBar.anchor, statusBar.gridY, statusBar);
FancyStatusBars.updatePositions();
+ cursorBar.setX(width + 5); // send it to limbo lol
updateScreenRects();
} else if (button == 1) {
int x = Math.min(mouseX - 1, width - editBarWidget.getWidth());
@@ -292,25 +311,27 @@ public class StatusBarsConfigScreen extends Screen {
private void updateScreenRects() {
meaningFullName.clear();
- FancyStatusBars.statusBars.values().forEach(statusBar1 -> meaningFullName.put(
- new ScreenRect(new ScreenPos(statusBar1.getX(), statusBar1.getY()), statusBar1.getWidth(), statusBar1.getHeight()),
- new int[]{statusBar1.gridX, statusBar1.gridY}));
+ FancyStatusBars.statusBars.values().forEach(statusBar1 -> {
+ if (statusBar1.anchor == null) return;
+ meaningFullName.put(
+ new ScreenRect(new ScreenPos(statusBar1.getX(), statusBar1.getY()), statusBar1.getWidth(), statusBar1.getHeight()),
+ BarLocation.of(statusBar1));
+ });
}
@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
if (cursorBar != null) {
+ cursorBar.ghost = false;
cursorBar = null;
FancyStatusBars.updatePositions();
- checkZeroCoordinates(FancyStatusBars.statusBars.values());
+ checkNullAnchor(FancyStatusBars.statusBars.values());
updateScreenRects();
return true;
} else if (resizing) {
resizing = false;
- resizedBars.left()[0] = 0;
- resizedBars.left()[1] = 0;
- resizedBars.right()[0] = 0;
- resizedBars.right()[1] = 0;
+ resizedBars.left(BarLocation.NULL);
+ resizedBars.right(BarLocation.NULL);
updateScreenRects();
return true;
}
@@ -319,29 +340,23 @@ public class StatusBarsConfigScreen extends Screen {
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
- int[] first = resizeHover.first();
+ BarLocation first = resizeHover.first();
// want the right click thing to have priority
- if (!editBarWidget.isMouseOver(mouseX, mouseY) && button == 0 && first[0] != 0 && first[1] != 0) {
+ if (!editBarWidget.isMouseOver(mouseX, mouseY) && button == 0 && !first.equals(BarLocation.NULL)) {
+ BarPositioner.BarAnchor barAnchor = first.barAnchor();
+ assert barAnchor != null;
if (resizeHover.right()) {
- resizedBars.left()[0] = first[0];
- resizedBars.left()[1] = first[1];
- if (FancyStatusBars.barGrid.coordinatesExist(first[0] + 1, first[1])) {
- resizedBars.right()[0] = first[0] + 1;
- resizedBars.right()[1] = first[1];
- } else {
- resizedBars.right()[0] = 0;
- resizedBars.right()[1] = 0;
- }
+ resizedBars.left(first);
+
+ if (FancyStatusBars.barPositioner.hasNeighbor(barAnchor, first.y(), first.x(), true)) {
+ resizedBars.right(new BarLocation(barAnchor, first.x() + (barAnchor.isRight() ? 1 : -1), first.y()));
+ } else resizedBars.right(BarLocation.NULL);
} else {
- resizedBars.right()[0] = first[0];
- resizedBars.right()[1] = first[1];
- if (FancyStatusBars.barGrid.coordinatesExist(first[0] - 1, first[1])) {
- resizedBars.left()[0] = first[0] - 1;
- resizedBars.left()[1] = first[1];
- } else {
- resizedBars.left()[0] = 0;
- resizedBars.left()[1] = 0;
- }
+ resizedBars.right(first);
+
+ if (FancyStatusBars.barPositioner.hasNeighbor(barAnchor, first.y(), first.x(), false)) {
+ resizedBars.left(new BarLocation(barAnchor, first.x() + (barAnchor.isRight() ? -1 : 1), first.y()));
+ } else resizedBars.left(BarLocation.NULL);
}
resizing = true;
return true;
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/searchoverlay/SearchOverManager.java b/src/main/java/de/hysky/skyblocker/skyblock/searchoverlay/SearchOverManager.java
index 1d740601..c5811dd2 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/searchoverlay/SearchOverManager.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/searchoverlay/SearchOverManager.java
@@ -318,7 +318,7 @@ public class SearchOverManager {
}
/**
- * pushes the ({@link SearchOverManager#search}) to the sign. It needs to split it over two lines without splitting a word
+ * pushes the ({@link SearchOverManager#search}) to the sign. It needs to targetSize it over two lines without splitting a word
*/
private static void pushSign() {
//splits text into 2 lines max = 30 chars