aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2023-07-09 10:01:51 +0800
committerKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2023-07-09 10:21:36 +0800
commit85e5615bac19cf70d00653355f1e01e7d1849f37 (patch)
tree2918faf03d556addfeffd6e6291fa90c24e279f0 /src
parentf2fb1c3d1152efc3cc4741f02fd42dce836bcbb1 (diff)
downloadSkyblocker-85e5615bac19cf70d00653355f1e01e7d1849f37.tar.gz
Skyblocker-85e5615bac19cf70d00653355f1e01e7d1849f37.tar.bz2
Skyblocker-85e5615bac19cf70d00653355f1e01e7d1849f37.zip
Refactor Title
Diffstat (limited to 'src')
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/utils/title/Title.java33
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/utils/title/TitleContainerConfigScreen.java13
2 files changed, 30 insertions, 16 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/title/Title.java b/src/main/java/me/xmrvizzy/skyblocker/utils/title/Title.java
index ac06eb36..7dfef3d9 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/utils/title/Title.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/utils/title/Title.java
@@ -4,11 +4,36 @@ import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
+/**
+ * Represents a title used for {@link TitleContainer}.
+ *
+ * @see TitleContainer
+ */
public class Title {
private MutableText text;
protected float lastX = 0;
protected float lastY = 0;
+ /**
+ * Constructs a new title with the given translation key and formatting to be applied.
+ *
+ * @param textKey the translation key
+ * @param formatting the formatting to be applied to the text
+ */
+ public Title(String textKey, Formatting formatting) {
+ this(Text.translatable(textKey).formatted(formatting));
+ }
+
+ /**
+ * Constructs a new title with the given {@link MutableText}.
+ * Use {@link Text#literal(String)} or {@link Text#translatable(String)} to create a {@link MutableText}
+ *
+ * @param text the mutable text
+ */
+ public Title(MutableText text) {
+ this.text = text;
+ }
+
public MutableText getText() {
return text;
}
@@ -20,12 +45,4 @@ public class Title {
public void setFormatting(Formatting formatting) {
this.text.formatted(formatting);
}
-
- public Title(String textKey, Formatting formatting) {
- this(Text.translatable(textKey).formatted(formatting));
- }
-
- public Title(MutableText text) {
- this.text = text;
- }
}
diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/title/TitleContainerConfigScreen.java b/src/main/java/me/xmrvizzy/skyblocker/utils/title/TitleContainerConfigScreen.java
index 23df1f6c..e729ea15 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/utils/title/TitleContainerConfigScreen.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/utils/title/TitleContainerConfigScreen.java
@@ -3,19 +3,16 @@ package me.xmrvizzy.skyblocker.utils.title;
import me.shedaniel.autoconfig.AutoConfig;
import me.xmrvizzy.skyblocker.config.SkyblockerConfig;
import me.xmrvizzy.skyblocker.utils.RenderUtils;
-import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.math.Vector2f;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Pair;
-import org.joml.Vector2i;
import org.lwjgl.glfw.GLFW;
import java.awt.*;
import java.util.Set;
-import java.util.stream.Collectors;
public class TitleContainerConfigScreen extends Screen {
private final Title example1 = new Title(Text.literal("Test1").formatted(Formatting.RED));
@@ -52,7 +49,7 @@ public class TitleContainerConfigScreen extends Screen {
context.drawVerticalLine(x2, y1, y2, Color.RED.getRGB());
}
- public Pair<Vector2f, Vector2f> getSelectionBoundingBox() {
+ private Pair<Vector2f, Vector2f> getSelectionBoundingBox() {
SkyblockerConfig.Alignment alignment = SkyblockerConfig.get().general.titleContainer.alignment;
float midWidth = getSelectionWidth() / 2F;
@@ -77,14 +74,14 @@ public class TitleContainerConfigScreen extends Screen {
return new Pair<>(new Vector2f(x1, y1), new Vector2f(x2, y2));
}
- public float getSelectionHeight() {
+ private float getSelectionHeight() {
float scale = (3F * (SkyblockerConfig.get().general.titleContainer.titleContainerScale / 100F));
return SkyblockerConfig.get().general.titleContainer.direction == SkyblockerConfig.Direction.HORIZONTAL ?
(textRenderer.fontHeight * scale) :
(textRenderer.fontHeight + 10F) * 3F * scale;
}
- public float getSelectionWidth() {
+ private float getSelectionWidth() {
float scale = (3F * (SkyblockerConfig.get().general.titleContainer.titleContainerScale / 100F));
return SkyblockerConfig.get().general.titleContainer.direction == SkyblockerConfig.Direction.HORIZONTAL ?
(textRenderer.getWidth("Test1") + 10 + textRenderer.getWidth("Test23") + 10 + textRenderer.getWidth("Testing1234")) * scale :
@@ -105,7 +102,7 @@ public class TitleContainerConfigScreen extends Screen {
if (RenderUtils.pointExistsInArea((int) mouseX, (int) mouseY, (int) x1, (int) y1, (int) x2, (int) y2) && button == 0) {
hudX = switch (alignment) {
- case LEFT ->(int) mouseX - midWidth;
+ case LEFT -> (int) mouseX - midWidth;
case MIDDLE -> (int) mouseX;
case RIGHT -> (int) mouseX + midWidth;
};
@@ -117,7 +114,7 @@ public class TitleContainerConfigScreen extends Screen {
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (button == 1) {
- hudX = this.width / 2;
+ hudX = (float) this.width / 2;
hudY = this.height * 0.6F;
}
return super.mouseClicked(mouseX, mouseY, button);