aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock/fancybars
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/fancybars')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/fancybars/BarGrid.java93
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBar.java136
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBarsConfigScreen.java44
3 files changed, 273 insertions, 0 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/BarGrid.java b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/BarGrid.java
new file mode 100644
index 00000000..b85f85e1
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/BarGrid.java
@@ -0,0 +1,93 @@
+package de.hysky.skyblocker.skyblock.fancybars;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class BarGrid {
+ private final LinkedList<LinkedList<StatusBar>> top = new LinkedList<>();
+ private final LinkedList<LinkedList<StatusBar>> bottomLeft = new LinkedList<>();
+ private final LinkedList<LinkedList<StatusBar>> bottomRight = new LinkedList<>();
+
+ public BarGrid() {}
+
+ public void add(int row, StatusBar bar, boolean right) {
+ if (row > 0)
+ top.get(row).add(bar);
+ else if (row < 0) {
+ if (right) {
+ bottomRight.get(Math.abs(row)).add(bar);
+ } else {
+ bottomLeft.get(Math.abs(row)).add(bar);
+ }
+ }
+ }
+
+ public void add(int x, int y, StatusBar bar) {
+ if (y > 0) {
+ if (x < 1) throw new IllegalArgumentException("x can't be negative, x: " + x);
+ LinkedList<StatusBar> statusBars = top.get(y-1);
+ statusBars.add(Math.min(x-1, statusBars.size()), bar);
+ bar.gridY = y;
+ bar.gridX = statusBars.indexOf(bar)+1;
+ } else if (y < 0) {
+ LinkedList<StatusBar> statusBars = (x < 0? bottomLeft: bottomRight).get(Math.abs(y)-1);
+ statusBars.add(Math.min(Math.abs(x)-1, statusBars.size()), bar);
+ bar.gridY = y;
+ bar.gridX = -(statusBars.indexOf(bar)+1);
+ }
+ }
+
+ public List<StatusBar> getRow(int row, boolean right) {
+ if (row > 0) {
+ return top.get(row-1);
+ } else {
+ return (right ? bottomRight: bottomLeft).get(Math.abs(row)-1);
+ }
+ }
+
+ public void addRow(int row, boolean right) {
+ if (row>0) {
+ top.add(row-1, new LinkedList<>());
+ } else if (row<0) {
+ (right ? bottomRight: bottomLeft).add(Math.abs(row)-1, new LinkedList<>());
+ }
+ }
+
+ public void remove(int x, int y) {
+ if (y > 0) {
+ if (x < 1) throw new IllegalArgumentException("x can't be negative, x: " + x);
+ LinkedList<StatusBar> statusBars = top.get(y-1);
+ StatusBar remove = statusBars.remove(x-1);
+ for (int i = x-1; i < statusBars.size(); i++) {
+ statusBars.get(i).gridX--;
+ }
+ remove.gridX = 0;
+ remove.gridY = 0;
+ if (statusBars.isEmpty()) {
+ top.remove(y - 1);
+ for (int i = y-1; i < top.size(); i++) {
+ for (StatusBar bar : top.get(i)) {
+ bar.gridY--;
+ }
+ }
+ }
+ } else if (y < 0) {
+ LinkedList<LinkedList<StatusBar>> bottom = x < 0 ? bottomLeft : bottomRight;
+ LinkedList<StatusBar> statusBars = bottom.get(Math.abs(y)-1);
+ StatusBar remove = statusBars.remove(Math.abs(x) - 1);
+ for (int i = Math.abs(x)-1; i < statusBars.size(); i++) {
+ statusBars.get(i).gridX--;
+ }
+ remove.gridX = 0;
+ remove.gridY = 0;
+ if (statusBars.isEmpty()) {
+ bottom.remove(Math.abs(y) - 1);
+ for (int i = Math.abs(y)-1; i < bottom.size(); i++) {
+ for (StatusBar bar : bottom.get(i)) {
+ bar.gridY--;
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBar.java b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBar.java
new file mode 100644
index 00000000..9c688051
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBar.java
@@ -0,0 +1,136 @@
+package de.hysky.skyblocker.skyblock.fancybars;
+
+import de.hysky.skyblocker.SkyblockerMod;
+import de.hysky.skyblocker.utils.render.RenderHelper;
+import net.minecraft.client.gui.*;
+import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
+import net.minecraft.client.gui.widget.ClickableWidget;
+import net.minecraft.client.gui.widget.Widget;
+import net.minecraft.util.Identifier;
+import org.jetbrains.annotations.Nullable;
+
+import java.awt.*;
+import java.util.function.Consumer;
+
+public class StatusBar implements Widget, Drawable, Element, Selectable {
+
+ private static final Identifier BAR_FILL = new Identifier(SkyblockerMod.NAMESPACE, "bars/bar_fill");
+ private static final Identifier BAR_BACK = new Identifier(SkyblockerMod.NAMESPACE, "bars/bar_back");
+
+ private final Identifier icon;
+ private final Color[] colors;
+ private final boolean hasOverflow;
+ private final @Nullable Color textColor;
+
+ private @Nullable Consumer<StatusBar> onClick = null;
+ public int gridX = 0;
+ public int gridY = 0;
+
+ public float size = 1;
+ private int width = 0;
+
+ public float fill = 0;
+ public float overflowFill = 0;
+
+ private int x = 0;
+ private int y = 0;
+
+ public StatusBar(Identifier icon, Color[] colors, boolean hasOverflow, @Nullable Color textColor) {
+ this.icon = icon;
+ this.colors = colors;
+ this.hasOverflow = hasOverflow;
+ this.textColor = textColor;
+ }
+
+ @Override
+ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
+ context.drawGuiTexture(icon, x, y, 9, 9);
+ context.drawGuiTexture(BAR_BACK, x + 10, y + 1, width - 10, 7);
+ RenderHelper.renderNineSliceColored(context, BAR_FILL, x + 11, y + 2, (int) ((width - 12) * fill), 5, colors[0]);
+ if (hasOverflow) {
+ RenderHelper.renderNineSliceColored(context, BAR_FILL, x + 11, y + 2, (int) ((width - 12) * overflowFill), 5, colors[1]);
+ }
+ }
+
+ // GUI shenanigans
+
+ @Override
+ public void setX(int x) {
+ this.x = x;
+ }
+
+ @Override
+ public void setY(int y) {
+ this.y = y;
+ }
+
+ @Override
+ public int getX() {
+ return x;
+ }
+
+ @Override
+ public int getY() {
+ return y;
+ }
+
+ @Override
+ public int getWidth() {
+ return width;
+ }
+
+ public void setWidth(int width) {
+ this.width = width;
+ }
+
+ @Override
+ public int getHeight() {
+ return 9;
+ }
+
+ @Override
+ public ScreenRect getNavigationFocus() {
+ return Widget.super.getNavigationFocus();
+ }
+
+ @Override
+ public boolean isMouseOver(double mouseX, double mouseY) {
+ return mouseX >= x && mouseX <= x + getWidth() && mouseY >= y && mouseY <= y + getHeight();
+ }
+
+ @Override
+ public void forEachChild(Consumer<ClickableWidget> consumer) {}
+
+ @Override
+ public void setFocused(boolean focused) {
+
+ }
+
+ @Override
+ public boolean isFocused() {
+ return false;
+ }
+
+ @Override
+ public SelectionType getType() {
+ return SelectionType.NONE;
+ }
+
+ @Override
+ public boolean mouseClicked(double mouseX, double mouseY, int button) {
+ if (!isMouseOver(mouseX, mouseY)) return false;
+ if (onClick != null) {
+ onClick.accept(this);
+ }
+ return true;
+ }
+
+ public void setOnClick(@Nullable Consumer<StatusBar> onClick) {
+ this.onClick = onClick;
+ }
+
+ @Override
+ public void appendNarrations(NarrationMessageBuilder builder) {
+
+ }
+}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBarsConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBarsConfigScreen.java
new file mode 100644
index 00000000..1f0b7ffe
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/fancybars/StatusBarsConfigScreen.java
@@ -0,0 +1,44 @@
+package de.hysky.skyblocker.skyblock.fancybars;
+
+import de.hysky.skyblocker.skyblock.FancyStatusBars;
+import net.minecraft.client.gui.DrawContext;
+import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.text.Text;
+import net.minecraft.util.Identifier;
+import org.jetbrains.annotations.Nullable;
+
+public class StatusBarsConfigScreen extends Screen {
+
+ private static final Identifier HOTBAR_TEXTURE = new Identifier("hud/hotbar");
+
+ private @Nullable StatusBar cursorBar = null;
+ protected StatusBarsConfigScreen(Text title) {
+ super(title);
+ }
+
+ @Override
+ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
+ super.render(context, mouseX, mouseY, delta);
+ context.drawGuiTexture(HOTBAR_TEXTURE, width/2 - 91, height-22, 182, 22);
+ if (cursorBar != null) {
+ cursorBar.setX(mouseX);
+ cursorBar.setY(mouseY);
+ cursorBar.render(context, mouseX, mouseY, delta);
+ }
+ }
+
+ @Override
+ protected void init() {
+ super.init();
+ FancyStatusBars.statusBars.values().forEach(this::setup);
+ }
+
+ private void setup(StatusBar statusBar) {
+ this.addDrawableChild(statusBar);
+ statusBar.setOnClick(this::onClick);
+ }
+
+ private void onClick(StatusBar statusBar) {
+
+ }
+}