diff options
8 files changed, 33 insertions, 26 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/Widget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/Widget.java index 9e3c87cf..01f47933 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/Widget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/Widget.java @@ -40,9 +40,11 @@ public abstract class Widget { public final void pack() { for (Component c : components) { - h += c.getHeight() + 4; - w = Math.max(w, c.getWidth()); + h += c.getHeight() + Component.PAD_L; + w = Math.max(w, c.getWidth() + Component.PAD_S); } + + h -= Component.PAD_L / 2; // less padding after lowest/last component h += BORDER_SZE_N + BORDER_SZE_S - 2; w += BORDER_SZE_E + BORDER_SZE_W; @@ -114,7 +116,7 @@ public abstract class Widget { for (Component c : components) { c.render(ms, x + BORDER_SZE_W, yOffs); - yOffs += c.getHeight() + 4; + yOffs += c.getHeight() + Component.PAD_L; } // pop manipulations above ms.pop(); diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/Component.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/Component.java index 92b7ed1b..d9d84bc4 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/Component.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/Component.java @@ -8,12 +8,13 @@ import net.minecraft.client.util.math.MatrixStack; public abstract class Component { static final int ICO_DIM = 16; - static final int PAD_S = 2; - static final int PAD_L = 4; + public static final int PAD_S = 2; + public static final int PAD_L = 4; static TextRenderer txtRend = MinecraftClient.getInstance().textRenderer; static ItemRenderer itmRend = MinecraftClient.getInstance().getItemRenderer(); + // these should always be the content dimensions without any padding. int width, height; public abstract void render(MatrixStack ms, int x, int y); diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoFatTextComponent.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoFatTextComponent.java index 9aec581b..6a780159 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoFatTextComponent.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoFatTextComponent.java @@ -18,8 +18,8 @@ public class IcoFatTextComponent extends Component { this.l1 = l1; this.l2 = l2; - this.width = ICO_DIM + PAD_L + Math.max(txtRend.getWidth(l1), txtRend.getWidth(l2)) + PAD_S; - this.height = txtRend.fontHeight * 2 + PAD_S; + this.width = ICO_DIM + PAD_L + Math.max(txtRend.getWidth(l1), txtRend.getWidth(l2)); + this.height = txtRend.fontHeight + PAD_S + txtRend.fontHeight; } @Override diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoTextComponent.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoTextComponent.java index defbb2e6..b54affbc 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoTextComponent.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoTextComponent.java @@ -15,7 +15,7 @@ public class IcoTextComponent extends Component { this.ico = ico; this.text = text; - this.width = ICO_DIM + PAD_L + txtRend.getWidth(text) + PAD_S; + this.width = ICO_DIM + PAD_L + txtRend.getWidth(text); this.height = ICO_DIM; } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlainTextComponent.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlainTextComponent.java index 8976e6a2..a2ffced9 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlainTextComponent.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlainTextComponent.java @@ -12,13 +12,13 @@ public class PlainTextComponent extends Component { public PlainTextComponent(Text text) { this.text = text; - this.width = PAD_S + txtRend.getWidth(text) + PAD_S; + this.width = PAD_S + txtRend.getWidth(text); // looks off without padding this.height = txtRend.fontHeight; } @Override public void render(MatrixStack ms, int x, int y) { - txtRend.draw(ms, text, x + PAD_S, y, 0xffffffff); + txtRend.draw(ms, text, x, y, 0xffffffff); } } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java index 56e2b3c3..ff296f28 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java @@ -21,7 +21,7 @@ public class PlayerComponent extends Component { name = ple.getProfile().getName(); tex = ple.getSkinTexture(); - this.width = txtRend.getWidth(name) + PAD_S + SKIN_ICO_DIM; + this.width = SKIN_ICO_DIM + PAD_S + txtRend.getWidth(name) ; this.height = txtRend.fontHeight; } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/ProgressComponent.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/ProgressComponent.java index 1803e327..753c9b21 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/ProgressComponent.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/ProgressComponent.java @@ -30,8 +30,8 @@ public class ProgressComponent extends Component { this.pcnt = pcnt; this.barW = BAR_WIDTH; + this.width = ICO_DIM + PAD_L + Math.max(this.barW, txtRend.getWidth(desc)); this.height = txtRend.fontHeight + PAD_S + 2 + txtRend.fontHeight + 2; - this.width = ICO_DIM + PAD_L + Math.max(this.barW, txtRend.getWidth(desc)) + PAD_S; } public ProgressComponent(ItemStack ico, Text text, float pcnt, int color) { diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/TableComponent.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/TableComponent.java index eeb8ce3b..5d27380e 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/TableComponent.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/TableComponent.java @@ -12,43 +12,47 @@ public class TableComponent extends Component { private Component[][] comps; private int color; - private int tw, th; + private int cols, rows; private int cellW, cellH; public TableComponent(int w, int h, int col) { comps = new Component[w][h]; color = 0xff000000 | col; - tw = w; - th = h; + cols = w; + rows = h; } public void addToCell(int x, int y, Component c) { this.comps[x][y] = c; - // are tables still too wide? - this.cellW = Math.max(this.cellW, c.width + PAD_S); + // pad extra to add a vertical line later + this.cellW = Math.max(this.cellW, c.width + PAD_S + PAD_L); // assume all rows are equally high so overwriting doesn't matter // if this wasn't the case, drawing would need more math // not doing any of that if it's not needed - this.cellH = c.height; + this.cellH = c.height + PAD_S; - this.width = this.cellW * this.tw; - this.height = (this.cellH + PAD_S) * this.th - PAD_S; + this.width = this.cellW * this.cols; + this.height = (this.cellH * this.rows) - PAD_S / 2; } @Override public void render(MatrixStack ms, int xpos, int ypos) { - for (int x = 0; x < tw; x++) { - for (int y = 0; y < th; y++) { + for (int x = 0; x < cols; x++) { + for (int y = 0; y < rows; y++) { if (comps[x][y] != null) { - comps[x][y].render(ms, xpos + x * cellW + x * PAD_L, ypos + y * cellH + y * PAD_S); + comps[x][y].render(ms, xpos + (x * cellW), ypos + y * cellH); } } - if (x != tw - 1) { - DrawableHelper.fill(ms, xpos + ((x + 1) * (cellW + PAD_S)) - 1, ypos + 1, - xpos + ((x + 1) * (cellW + PAD_S)), ypos + this.height - 1, this.color); + // add a line before the col if we're not drawing the first one + if (x != 0) { + int lineX1 = xpos + (x * cellW) - PAD_S - 1; + int lineX2 = xpos + (x * cellW) - PAD_S; + int lineY1 = ypos + 1; + int lineY2 = ypos + this.height - PAD_S - 1; // not sure why but it looks correct + DrawableHelper.fill(ms, lineX1, lineY1, lineX2, lineY2, this.color); } } } |