diff options
author | Trương Hoàng Long <longtruong2411@gmail.com> | 2022-05-30 17:12:52 +0200 |
---|---|---|
committer | Trương Hoàng Long <longtruong2411@gmail.com> | 2022-05-30 17:12:52 +0200 |
commit | 5779413f8f8f5da6faf142e7eb86ab12315a93ec (patch) | |
tree | d65eaf696d55a29ae6c2ef964da6c2115034c8c5 /src/main/java/me/xmrvizzy/skyblocker | |
parent | 3a1a1427b838fbfb992c0eab48d4282aa42ea1e3 (diff) | |
parent | b0f1e1ccf07cc67c26938e952345a0cfb69146c9 (diff) | |
download | Skyblocker-5779413f8f8f5da6faf142e7eb86ab12315a93ec.tar.gz Skyblocker-5779413f8f8f5da6faf142e7eb86ab12315a93ec.tar.bz2 Skyblocker-5779413f8f8f5da6faf142e7eb86ab12315a93ec.zip |
Merge branch 'master' of https://github.com/SkyblockerMod/Skyblocker
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker')
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java | 41 | ||||
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java | 120 |
2 files changed, 144 insertions, 17 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java index 5357fade..0a7260f8 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java @@ -62,6 +62,47 @@ public class SkyblockerConfig implements ConfigData { public static class Bars { public boolean enableBars = true; + + @ConfigEntry.Category("barpositions") + @ConfigEntry.Gui.CollapsibleObject(startExpanded = false) + public BarPositions barpositions = new BarPositions(); + } + + public static class BarPositions { + @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + public BarPosition healthBarPosition = BarPosition.LAYER1; + @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + public BarPosition manaBarPosition = BarPosition.LAYER1; + @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + public BarPosition defenceBarPosition = BarPosition.LAYER1; + @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + public BarPosition experienceBarPosition = BarPosition.LAYER1; + + } + + public enum BarPosition { + LAYER1, + LAYER2, + RIGHT, + NONE; + + public String toString() { + return switch (this) { + case LAYER1 -> "Layer 1"; + case LAYER2 -> "Layer 2"; + case RIGHT -> "Right"; + case NONE -> "Disabled"; + }; + } + + public int toInt() { + return switch (this) { + case LAYER1 -> 0; + case LAYER2 -> 1; + case RIGHT -> 2; + case NONE -> -1; + }; + } } public static class Hitbox { diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java index c463ecb5..dd7ef478 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java @@ -16,25 +16,39 @@ public class FancyStatusBars extends DrawableHelper { private final StatusBarTracker statusBarTracker = SkyblockerMod.getInstance().statusBarTracker; private final StatusBar[] bars = new StatusBar[]{ - new StatusBar(0, 16733525, 2), - new StatusBar(1, 5636095, 2), - new StatusBar(2, 12106180, 1), - new StatusBar(3, 8453920, 1), + 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 }; - private int left; - private int top; + // 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 (32 * value - 1) / max; + return (100 * value) / max; } public boolean render(MatrixStack matrices, int scaledWidth, int scaledHeight) { var player = client.player; if (!SkyblockerConfig.get().general.bars.enableBars || player == null) return false; - left = scaledWidth / 2 - 91; - top = scaledHeight - 35; + 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()); @@ -44,6 +58,20 @@ public class FancyStatusBars extends DrawableHelper { bars[3].fill[0] = (int) (32 * 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 -> SkyblockerConfig.get().general.bars.barpositions.healthBarPosition.toInt(); + case 1 -> SkyblockerConfig.get().general.bars.barpositions.manaBarPosition.toInt(); + case 2 -> SkyblockerConfig.get().general.bars.barpositions.defenceBarPosition.toInt(); + case 3 -> SkyblockerConfig.get().general.bars.barpositions.experienceBarPosition.toInt(); + default -> 0; + }; + + if (bars[i].anchorNum != configAnchorNum) + moveBar(i, configAnchorNum); + } + RenderSystem.setShaderTexture(0, BARS); for (var bar : bars) bar.draw(matrices); @@ -52,19 +80,58 @@ public class FancyStatusBars extends DrawableHelper { 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, rightCount = 0; + for (int i = 0; i < 4; i++) { + switch (bars[i].anchorNum) { + case 0 -> layer1Count++; + case 1 -> layer2Count++; + case 2 -> rightCount++; + } + } + + // 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; - private final int offsetX; + 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.offsetX = i * 46; this.v = i * 9; this.text_color = textColor; this.fill = new int[fillNum]; - this.fill[0] = 33; + this.fill[0] = 100; + this.anchorNum = 0; this.text = ""; } @@ -77,16 +144,35 @@ public class FancyStatusBars extends DrawableHelper { } public void draw(MatrixStack matrices) { - drawTexture(matrices, left + offsetX, top, 0, v, 43, 9); - for (int i = 0; i < fill.length; i++) - drawTexture(matrices, left + offsetX + 11, top, 43 + i * 31, v, fill[i], 9); + // Dont draw if anchorNum is outside of range + if (anchorNum < 0 || anchorNum > 2) return; + + // Draw the icon for the bar + drawTexture(matrices, anchorsX[anchorNum] + offsetX, anchorsY[anchorNum], 0, v, 9, 9); + + // Draw the background for the bar + drawTexture(matrices, anchorsX[anchorNum] + offsetX + 10, anchorsY[anchorNum], 10, v, 2, 9); + for (int i = 2; i < bar_width - 2; i++) + drawTexture(matrices, anchorsX[anchorNum] + offsetX + 10 + i, anchorsY[anchorNum], 12, v, 1, 9); + drawTexture(matrices, anchorsX[anchorNum] + offsetX + 10 + bar_width - 2, anchorsY[anchorNum], 41, v, 2, 9); + + // Draw the filled part of the bar + for (int i = 0; i < fill.length; i++) { + for (int j = (bar_width - 3); j >= 0; j--) { + if ( Math.max((j * 100)/(bar_width - 3), 1) > fill[i]) continue; + drawTexture(matrices, anchorsX[anchorNum] + offsetX + 11 + j, anchorsY[anchorNum], ((j == 0 || j == bar_width - 3) ? 43 : 44) + i * 31, v, 1, 9); + } + } } public void drawText(MatrixStack matrices) { + // 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 = left + this.offsetX + 11 + (33 - textRenderer.getWidth(text)) / 2; - int y = top - 3; + 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) { |