From 7e74f5c56fbe48ca990eeb873585947b95294c25 Mon Sep 17 00:00:00 2001 From: dooji2 Date: Sat, 15 Mar 2025 16:07:44 +0200 Subject: [PATCH 1/2] Add CENTER_LEFT and CENTER_RIGHT --- .../glowcase/block/entity/TextBlockEntity.java | 2 +- .../client/gui/screen/ingame/PopupBlockEditScreen.java | 8 ++++---- .../client/gui/screen/ingame/TextBlockEditScreen.java | 10 ++++++---- .../render/block/entity/TextBlockEntityRenderer.java | 2 ++ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/dev/hephaestus/glowcase/block/entity/TextBlockEntity.java b/src/main/java/dev/hephaestus/glowcase/block/entity/TextBlockEntity.java index ad439761..c3fe54b2 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/entity/TextBlockEntity.java +++ b/src/main/java/dev/hephaestus/glowcase/block/entity/TextBlockEntity.java @@ -109,7 +109,7 @@ public void setRawLine(int i, String string) { } public enum TextAlignment { - LEFT, CENTER, RIGHT + LEFT, CENTER, CENTER_LEFT, CENTER_RIGHT, RIGHT } public enum ZOffset { diff --git a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/PopupBlockEditScreen.java b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/PopupBlockEditScreen.java index 2db579a5..343f876e 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/PopupBlockEditScreen.java +++ b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/PopupBlockEditScreen.java @@ -69,7 +69,7 @@ public void init() { this.changeAlignment = ButtonWidget.builder(Text.stringifiedTranslatable("gui.glowcase.alignment", this.popupBlockEntity.textAlignment), action -> { switch (popupBlockEntity.textAlignment) { case LEFT -> popupBlockEntity.textAlignment = TextBlockEntity.TextAlignment.CENTER; - case CENTER -> popupBlockEntity.textAlignment = TextBlockEntity.TextAlignment.RIGHT; + case CENTER, CENTER_LEFT, CENTER_RIGHT -> popupBlockEntity.textAlignment = TextBlockEntity.TextAlignment.RIGHT; case RIGHT -> popupBlockEntity.textAlignment = TextBlockEntity.TextAlignment.LEFT; } this.popupBlockEntity.renderDirty = true; @@ -115,7 +115,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { int lineWidth = this.textRenderer.getWidth(text); switch (this.popupBlockEntity.textAlignment) { case LEFT -> context.drawTextWithShadow(client.textRenderer, text, this.width / 10, i * 12, this.popupBlockEntity.color); - case CENTER -> context.drawTextWithShadow(client.textRenderer, text, this.width / 2 - lineWidth / 2, i * 12, this.popupBlockEntity.color); + case CENTER, CENTER_LEFT, CENTER_RIGHT -> context.drawTextWithShadow(client.textRenderer, text, this.width / 2 - lineWidth / 2, i * 12, this.popupBlockEntity.color); case RIGHT -> context.drawTextWithShadow(client.textRenderer, text, this.width - this.width / 10 - lineWidth, i * 12, this.popupBlockEntity.color); } } @@ -133,7 +133,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { float push = switch (this.popupBlockEntity.textAlignment) { case LEFT -> this.width / 10F; - case CENTER -> this.width / 2F - this.textRenderer.getWidth(line) / 2F; + case CENTER, CENTER_LEFT, CENTER_RIGHT -> this.width / 2F - this.textRenderer.getWidth(line) / 2F; case RIGHT -> this.width - this.width / 10F - this.textRenderer.getWidth(line); }; @@ -290,7 +290,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { contentsStart = this.width / 10; contentsEnd = contentsStart + baseContentsWidth; } - case CENTER -> { + case CENTER, CENTER_LEFT, CENTER_RIGHT -> { int midpoint = this.width / 2; int textMidpoint = baseContentsWidth / 2; contentsStart = midpoint - textMidpoint; diff --git a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/TextBlockEditScreen.java b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/TextBlockEditScreen.java index 5c5873f9..aa3a390e 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/TextBlockEditScreen.java +++ b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/TextBlockEditScreen.java @@ -76,7 +76,9 @@ public void init() { this.changeAlignment = ButtonWidget.builder(Text.stringifiedTranslatable("gui.glowcase.alignment", this.textBlockEntity.textAlignment), action -> { switch (textBlockEntity.textAlignment) { case LEFT -> textBlockEntity.textAlignment = TextBlockEntity.TextAlignment.CENTER; - case CENTER -> textBlockEntity.textAlignment = TextBlockEntity.TextAlignment.RIGHT; + case CENTER -> textBlockEntity.textAlignment = TextBlockEntity.TextAlignment.CENTER_LEFT; + case CENTER_LEFT -> textBlockEntity.textAlignment = TextBlockEntity.TextAlignment.CENTER_RIGHT; + case CENTER_RIGHT -> textBlockEntity.textAlignment = TextBlockEntity.TextAlignment.RIGHT; case RIGHT -> textBlockEntity.textAlignment = TextBlockEntity.TextAlignment.LEFT; } this.textBlockEntity.renderDirty = true; @@ -158,7 +160,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { int lineWidth = this.textRenderer.getWidth(text); switch (this.textBlockEntity.textAlignment) { case LEFT -> context.drawTextWithShadow(client.textRenderer, text, this.width / 10, i * 12, this.textBlockEntity.color); - case CENTER -> context.drawTextWithShadow(client.textRenderer, text, this.width / 2 - lineWidth / 2, i * 12, this.textBlockEntity.color); + case CENTER, CENTER_LEFT, CENTER_RIGHT -> context.drawTextWithShadow(client.textRenderer, text, this.width / 2 - lineWidth / 2, i * 12, this.textBlockEntity.color); case RIGHT -> context.drawTextWithShadow(client.textRenderer, text, this.width - this.width / 10 - lineWidth, i * 12, this.textBlockEntity.color); } } @@ -176,7 +178,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { float push = switch (this.textBlockEntity.textAlignment) { case LEFT -> this.width / 10F; - case CENTER -> this.width / 2F - this.textRenderer.getWidth(line) / 2F; + case CENTER, CENTER_LEFT, CENTER_RIGHT -> this.width / 2F - this.textRenderer.getWidth(line) / 2F; case RIGHT -> this.width - this.width / 10F - this.textRenderer.getWidth(line); }; @@ -386,7 +388,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { contentsStart = this.width / 10; contentsEnd = contentsStart + baseContentsWidth; } - case CENTER -> { + case CENTER, CENTER_LEFT, CENTER_RIGHT -> { int midpoint = this.width / 2; int textMidpoint = baseContentsWidth / 2; contentsStart = midpoint - textMidpoint; diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/TextBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/TextBlockEntityRenderer.java index feb0dbde..7073667d 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/TextBlockEntityRenderer.java +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/TextBlockEntityRenderer.java @@ -68,6 +68,8 @@ public void renderBaked(TextBlockEntity entity, MatrixStack matrices, VertexCons double dX = switch (entity.textAlignment) { case LEFT -> -maxLength / 2D; case CENTER -> (maxLength - width) / 2D - maxLength / 2D; + case CENTER_LEFT -> (-maxLength / 2D) - (width / 2D); + case CENTER_RIGHT -> (maxLength / 2D) - (width / 2D); case RIGHT -> maxLength - width - maxLength / 2D; }; From bad562c545e3a32fcded989e3c2c62b06f3b9d21 Mon Sep 17 00:00:00 2001 From: dooji2 Date: Sat, 15 Mar 2025 17:35:48 +0200 Subject: [PATCH 2/2] Fix the math --- .../client/render/block/entity/TextBlockEntityRenderer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/TextBlockEntityRenderer.java b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/TextBlockEntityRenderer.java index 7073667d..ce6e4f93 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/TextBlockEntityRenderer.java +++ b/src/main/java/dev/hephaestus/glowcase/client/render/block/entity/TextBlockEntityRenderer.java @@ -68,8 +68,8 @@ public void renderBaked(TextBlockEntity entity, MatrixStack matrices, VertexCons double dX = switch (entity.textAlignment) { case LEFT -> -maxLength / 2D; case CENTER -> (maxLength - width) / 2D - maxLength / 2D; - case CENTER_LEFT -> (-maxLength / 2D) - (width / 2D); - case CENTER_RIGHT -> (maxLength / 2D) - (width / 2D); + case CENTER_LEFT -> -50D - (width / 2D); + case CENTER_RIGHT -> 50D - (width / 2D); case RIGHT -> maxLength - width - maxLength / 2D; };