aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java12
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java4
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java18
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java109
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java13
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java2
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java12
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java2
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java11
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java10
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java3
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java30
12 files changed, 165 insertions, 61 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
index 1a8c326..05f3b68 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
@@ -5,6 +5,7 @@ import io.github.cottonmc.cotton.gui.widget.WPanel;
import io.github.cottonmc.cotton.gui.widget.WWidget;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
@@ -55,7 +56,7 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree
}
public void paint(int mouseX, int mouseY) {
- super.renderBackground();
+ super.renderBackground(ScreenDrawing.matrices);
if (description!=null) {
WPanel root = description.getRootPanel();
@@ -65,16 +66,17 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree
}
if (getTitle() != null) {
- textRenderer.draw(getTitle().asFormattedString(), left, top, description.getTitleColor());
+ textRenderer.method_27528(ScreenDrawing.matrices, getTitle(), left, top, description.getTitleColor());
}
}
@SuppressWarnings("deprecation")
@Override
- public void render(int mouseX, int mouseY, float partialTicks) {
+ public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) {
+ ScreenDrawing.matrices = matrices;
paint(mouseX, mouseY);
- super.render(mouseX, mouseY, partialTicks);
+ super.render(matrices, mouseX, mouseY, partialTicks);
if (description!=null) {
WPanel root = description.getRootPanel();
@@ -222,6 +224,6 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree
@Override
public void renderTextHover(Text text, int x, int y) {
- renderTextHoverEffect(text, x, y);
+ renderTextHoverEffect(ScreenDrawing.matrices, text, x, y);
}
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java
index 6294ac6..0e6fa4f 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java
@@ -6,6 +6,7 @@ import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.Window;
+import net.minecraft.client.util.math.MatrixStack;
import java.util.*;
@@ -104,7 +105,8 @@ public enum CottonHud implements HudRenderCallback {
}
@Override
- public void onHudRender(float tickDelta) {
+ public void onHudRender(MatrixStack matrices, float tickDelta) {
+ ScreenDrawing.matrices = matrices;
Window window = MinecraftClient.getInstance().getWindow();
int hudWidth = window.getScaledWidth();
int hudHeight = window.getScaledHeight();
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
index 83c1837..5dca5f1 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
@@ -2,6 +2,7 @@ package io.github.cottonmc.cotton.gui.client;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.render.DiffuseLighting;
+import net.minecraft.client.util.math.MatrixStack;
import org.lwjgl.glfw.GLFW;
import io.github.cottonmc.cotton.gui.CottonCraftingController;
@@ -182,12 +183,12 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends H
WWidget child = root.hit(containerX, containerY);
child.onMouseMove(containerX - child.getAbsoluteX(), containerY - child.getAbsoluteY());
}
-
+
@Override
- protected void drawBackground(float partialTicks, int mouseX, int mouseY) {} //This is just an AbstractContainerScreen thing; most Screens don't work this way.
+ protected void drawBackground(MatrixStack matrices, float partialTicks, int mouseX, int mouseY) {} //This is just an AbstractContainerScreen thing; most Screens don't work this way.
public void paint(int mouseX, int mouseY) {
- super.renderBackground();
+ super.renderBackground(ScreenDrawing.matrices);
if (description!=null) {
WPanel root = description.getRootPanel();
@@ -197,16 +198,17 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends H
}
if (getTitle() != null) {
- textRenderer.draw(getTitle().asFormattedString(), x, y, description.getTitleColor());
+ textRenderer.method_27528(ScreenDrawing.matrices, getTitle(), x, y, description.getTitleColor());
}
}
@SuppressWarnings("deprecation")
@Override
- public void render(int mouseX, int mouseY, float partialTicks) {
+ public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) {
+ ScreenDrawing.matrices = matrices;
paint(mouseX, mouseY);
- super.render(mouseX, mouseY, partialTicks);
+ super.render(matrices, mouseX, mouseY, partialTicks);
DiffuseLighting.disable(); //Needed because super.render leaves dirty state
if (description!=null) {
@@ -219,7 +221,7 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends H
}
}
- drawMouseoverTooltip(mouseX, mouseY); //Draws the itemstack tooltips
+ drawMouseoverTooltip(matrices, mouseX, mouseY); //Draws the itemstack tooltips
}
@Override
@@ -235,6 +237,6 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends H
@Override
public void renderTextHover(Text text, int x, int y) {
- renderTextHoverEffect(text, x, y);
+ renderTextHoverEffect(ScreenDrawing.matrices, text, x, y);
}
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
index 0cfac29..199909f 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java
@@ -1,5 +1,7 @@
package io.github.cottonmc.cotton.gui.client;
+import net.minecraft.client.util.math.MatrixStack;
+import net.minecraft.text.Text;
import org.lwjgl.opengl.GL11;
import com.mojang.blaze3d.platform.GlStateManager;
@@ -17,9 +19,23 @@ import net.minecraft.util.Identifier;
* {@code ScreenDrawing} contains utility methods for drawing contents on a screen.
*/
public class ScreenDrawing {
+ // Internal MatrixStack for rendering strings.
+ // TODO (2.0): Remove
+ static MatrixStack matrices;
+
private ScreenDrawing() {}
/**
+ * Gets the currently bound matrix stack.
+ *
+ * @return the matrix stack
+ * @since 1.9.0
+ */
+ public static MatrixStack getMatrices() {
+ return matrices;
+ }
+
+ /**
* Draws a textured rectangle.
*
* @param x the x coordinate of the box on-screen
@@ -295,19 +311,51 @@ public class ScreenDrawing {
public static void drawString(String s, Alignment align, int x, int y, int width, int color) {
switch(align) {
case LEFT: {
- MinecraftClient.getInstance().textRenderer.draw(s, x, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, s, x, y, color);
}
break;
case CENTER: {
int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s);
int l = (width/2) - (wid/2);
- MinecraftClient.getInstance().textRenderer.draw(s, x+l, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, s, x+l, y, color);
}
break;
case RIGHT: {
int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s);
int l = width - wid;
- MinecraftClient.getInstance().textRenderer.draw(s, x+l, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, s, x+l, y, color);
+ }
+ break;
+ }
+ }
+
+ /**
+ * Draws a text component with a custom alignment.
+ *
+ * @param text the text
+ * @param align the alignment of the string
+ * @param x the X position
+ * @param y the Y position
+ * @param width the width of the string, used for aligning
+ * @param color the text color
+ * @since 1.9.0
+ */
+ public static void drawString(Text text, Alignment align, int x, int y, int width, int color) {
+ switch(align) {
+ case LEFT: {
+ MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x, y, color);
+ }
+ break;
+ case CENTER: {
+ int wid = MinecraftClient.getInstance().textRenderer.method_27525(text);
+ int l = (width/2) - (wid/2);
+ MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x+l, y, color);
+ }
+ break;
+ case RIGHT: {
+ int wid = MinecraftClient.getInstance().textRenderer.method_27525(text);
+ int l = width - wid;
+ MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x+l, y, color);
}
break;
}
@@ -326,19 +374,50 @@ public class ScreenDrawing {
public static void drawStringWithShadow(String s, Alignment align, int x, int y, int width, int color) {
switch(align) {
case LEFT: {
- MinecraftClient.getInstance().textRenderer.drawWithShadow(s, x, y, color);
+ MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x, y, color);
}
break;
case CENTER: {
int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s);
int l = (width/2) - (wid/2);
- MinecraftClient.getInstance().textRenderer.drawWithShadow(s, x+l, y, color);
+ MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x+l, y, color);
}
break;
case RIGHT: {
int wid = MinecraftClient.getInstance().textRenderer.getStringWidth(s);
int l = width - wid;
- MinecraftClient.getInstance().textRenderer.drawWithShadow(s, x+l, y, color);
+ MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x+l, y, color);
+ }
+ break;
+ }
+ }
+
+ /**
+ * Draws a shadowed text component.
+ *
+ * @param text the text component
+ * @param align the alignment of the string
+ * @param x the X position
+ * @param y the Y position
+ * @param width the width of the string, used for aligning
+ * @param color the text color
+ */
+ public static void drawStringWithShadow(Text text, Alignment align, int x, int y, int width, int color) {
+ switch(align) {
+ case LEFT: {
+ MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x, y, color);
+ }
+ break;
+ case CENTER: {
+ int wid = MinecraftClient.getInstance().textRenderer.method_27525(text);
+ int l = (width/2) - (wid/2);
+ MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x+l, y, color);
+ }
+ break;
+ case RIGHT: {
+ int wid = MinecraftClient.getInstance().textRenderer.method_27525(text);
+ int l = width - wid;
+ MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x+l, y, color);
}
break;
}
@@ -353,7 +432,19 @@ public class ScreenDrawing {
* @param color the text color
*/
public static void drawString(String s, int x, int y, int color) {
- MinecraftClient.getInstance().textRenderer.draw(s, x, y, color);
+ MinecraftClient.getInstance().textRenderer.draw(matrices, s, x, y, color);
+ }
+
+ /**
+ * Draws a left-aligned text component.
+ *
+ * @param text the text component
+ * @param x the X position
+ * @param y the Y position
+ * @param color the text color
+ */
+ public static void drawString(Text text, int x, int y, int color) {
+ MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x, y, color);
}
/**
@@ -361,8 +452,8 @@ public class ScreenDrawing {
*/
@Deprecated
public static void drawCenteredWithShadow(String s, int x, int y, int color) {
- TextRenderer render = MinecraftClient.getInstance().getFontManager().getTextRenderer(MinecraftClient.DEFAULT_TEXT_RENDERER_ID);
- render.drawWithShadow(s, (float)(x - render.getStringWidth(s) / 2), (float)y, color);
+ TextRenderer render = MinecraftClient.getInstance().textRenderer;
+ render.drawWithShadow(matrices, s, (float)(x - render.getStringWidth(s) / 2), (float)y, color);
}
public static int colorAtOpacity(int opaque, float opacity) {
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java
index 519d1a3..168e540 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java
@@ -7,6 +7,7 @@ import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.screen.PropertyDelegate;
+import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
@@ -160,23 +161,23 @@ public class WBar extends WWidget {
}
@Override
- public void addInformation(List<String> information) {
+ public void addTooltip(List<Text> information) {
if (tooltipLabel!=null) {
int value = (field>=0) ? properties.get(field) : 0;
int valMax = (max>=0) ? properties.get(max) : maxValue;
- String formatted = tooltipLabel;
+ Text formatted;
try {
- formatted = new TranslatableText(tooltipLabel, Integer.valueOf(value), Integer.valueOf(valMax)).asFormattedString();
+ formatted = new TranslatableText(tooltipLabel, Integer.valueOf(value), Integer.valueOf(valMax));
} catch (Throwable t) {
- formatted = t.getLocalizedMessage();
+ formatted = new LiteralText(t.getLocalizedMessage());
} //Fallback to raw tooltipLabel
information.add(formatted);
}
if (tooltipTextComponent!=null) {
try {
- information.add(tooltipTextComponent.asFormattedString());
+ information.add(tooltipTextComponent);
} catch (Throwable t) {
- information.add(t.getLocalizedMessage());
+ information.add(new LiteralText(t.getLocalizedMessage()));
}
}
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
index fbf664d..aa025f0 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java
@@ -58,7 +58,7 @@ public class WButton extends WWidget {
color = 0xFFFFA0;
}*/
- ScreenDrawing.drawStringWithShadow(label.asFormattedString(), alignment, x, y + ((20 - 8) / 2), width, color); //LibGuiClient.config.darkMode ? darkmodeColor : color);
+ ScreenDrawing.drawStringWithShadow(label, alignment, x, y + ((20 - 8) / 2), width, color); //LibGuiClient.config.darkMode ? darkmodeColor : color);
}
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
index d925c17..6db09b9 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
@@ -69,8 +69,7 @@ public class WLabel extends WWidget {
@Override
public void paintBackground(int x, int y, int mouseX, int mouseY) {
- String translated = text.asFormattedString();
- ScreenDrawing.drawString(translated, alignment, x, y, this.getWidth(), LibGuiClient.config.darkMode ? darkmodeColor : color);
+ ScreenDrawing.drawString(text, alignment, x, y, this.getWidth(), LibGuiClient.config.darkMode ? darkmodeColor : color);
Text hoveredText = getTextAt(mouseX, mouseY);
if (hoveredText != null) {
@@ -96,14 +95,7 @@ public class WLabel extends WWidget {
@Nullable
private Text getTextAt(int x, int y) {
if (isWithinBounds(x, y)) {
- int i = 0;
- for (Text component : text) {
- TextRenderer renderer = MinecraftClient.getInstance().textRenderer;
- i += renderer.getStringWidth(component.asFormattedString());
- if (i > x) {
- return component;
- }
- }
+ return MinecraftClient.getInstance().textRenderer.method_27527().method_27489(text, x);
}
return null;
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java
index 4541427..5b7e812 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java
@@ -129,7 +129,7 @@ public class WLabeledSlider extends WAbstractSlider {
if (label != null) {
int color = isMouseInsideBounds(mouseX, mouseY) ? 0xFFFFA0 : 0xE0E0E0;
- ScreenDrawing.drawStringWithShadow(label.asFormattedString(), labelAlignment, 2, aHeight / 2 - 4, aWidth - 4, color);
+ ScreenDrawing.drawStringWithShadow(label, labelAlignment, 2, aHeight / 2 - 4, aWidth - 4, color);
}
RenderSystem.popMatrix();
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java
index 7982b2d..2522644 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java
@@ -48,7 +48,7 @@ public class WText extends WWidget {
@Environment(EnvType.CLIENT)
private void wrapLines() {
TextRenderer font = MinecraftClient.getInstance().textRenderer;
- wrappedLines = Texts.wrapLines(text, width, font, true, true);
+ wrappedLines = Texts.wrapLines(text, width, font);
}
@Environment(EnvType.CLIENT)
@@ -59,11 +59,7 @@ public class WText extends WWidget {
if (lineIndex >= 0 && lineIndex < wrappedLines.size()) {
Text line = wrappedLines.get(lineIndex);
- int xi = 0;
- for (Text part : line) {
- xi += font.getStringWidth(part.asFormattedString());
- if (xi > x) return part;
- }
+ return font.method_27527().method_27489(line, x);
}
return null;
@@ -81,9 +77,8 @@ public class WText extends WWidget {
for (int i = 0; i < wrappedLines.size(); i++) {
Text line = wrappedLines.get(i);
int c = LibGuiClient.config.darkMode ? darkmodeColor : color;
- String str = line.asFormattedString();
- ScreenDrawing.drawString(str, alignment, x, y + i * font.fontHeight, width, c);
+ ScreenDrawing.drawString(line, alignment, x, y + i * font.fontHeight, width, c);
}
Text hoveredText = getTextAt(mouseX, mouseY);
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java
index 97023aa..7896f6e 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java
@@ -321,7 +321,7 @@ public class WTextField extends WWidget {
int textColor = this.editable ? this.enabledColor : this.uneditableColor;
//TODO: Scroll offset
- String trimText = font.trimToWidth(this.text, this.width-OFFSET_X_TEXT);
+ String trimText = font.method_27523(this.text, this.width-OFFSET_X_TEXT);
boolean selection = (select!=-1);
boolean focused = this.isFocused(); //this.isFocused() && this.focusedTicks / 6 % 2 == 0 && boolean_1; //Blinks the cursor
@@ -347,16 +347,16 @@ public class WTextField extends WWidget {
int preCursorAdvance = textX;
if (!trimText.isEmpty()) {
String string_2 = trimText.substring(0,adjustedCursor);
- preCursorAdvance = font.drawWithShadow(string_2, textX, textY, textColor);
+ preCursorAdvance = font.drawWithShadow(ScreenDrawing.getMatrices(), string_2, textX, textY, textColor);
}
if (adjustedCursor<trimText.length()) {
- font.drawWithShadow(trimText.substring(adjustedCursor), preCursorAdvance-1, (float)textY, textColor);
+ font.drawWithShadow(ScreenDrawing.getMatrices(), trimText.substring(adjustedCursor), preCursorAdvance-1, (float)textY, textColor);
}
if (text.length()==0 && this.suggestion != null) {
- font.drawWithShadow(this.suggestion, textX, textY, -8355712);
+ font.drawWithShadow(ScreenDrawing.getMatrices(), this.suggestion, textX, textY, -8355712);
}
//int var10002;
@@ -378,7 +378,7 @@ public class WTextField extends WWidget {
// DrawableHelper.fill(int_9, var10001, var10002, var10003 + 9, -3092272);
} else {
- font.drawWithShadow("_", preCursorAdvance, textY, textColor);
+ font.drawWithShadow(ScreenDrawing.getMatrices(), "_", preCursorAdvance, textY, textColor);
}
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java
index 0e069f0..d6aee69 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java
@@ -2,6 +2,7 @@ package io.github.cottonmc.cotton.gui.widget;
import io.github.cottonmc.cotton.gui.client.LibGuiClient;
import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
+import io.github.cottonmc.cotton.gui.widget.data.Alignment;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
@@ -75,7 +76,7 @@ public class WToggleButton extends WWidget {
ScreenDrawing.texturedRect(x, y, 18, 18, isOn ? onImage : offImage, 0xFFFFFFFF);
if (label!=null) {
- ScreenDrawing.drawString(label.asFormattedString(), x + 22, y+6, LibGuiClient.config.darkMode ? darkmodeColor : color);
+ ScreenDrawing.drawString(label, x + 22, y+6, LibGuiClient.config.darkMode ? darkmodeColor : color);
}
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java
index a1957af..4914e98 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java
@@ -4,10 +4,13 @@ import java.util.ArrayList;
import java.util.List;
import io.github.cottonmc.cotton.gui.GuiDescription;
+import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.text.LiteralText;
+import net.minecraft.text.Text;
public class WWidget {
protected WPanel parent;
@@ -222,19 +225,25 @@ public class WWidget {
}
/**
- * Internal method to render tooltip data. This requires an overriden {@link #addInformation(List)
- * addInformation} method to insert data into the tooltip - without this, the method returns early, because no work
+ * Internal method to render tooltip data. This requires an overriden {@link #addTooltip(List)
+ * addTooltip} method to insert data into the tooltip - without this, the method returns early, because no work
*/
@Environment(EnvType.CLIENT)
public void renderTooltip(int x, int y, int tX, int tY) {
- List<String> info = new ArrayList<>();
- addInformation(info);
+ List<Text> info = new ArrayList<>();
+ addTooltip(info);
+
+ List<String> stringInfo = new ArrayList<>();
+ addInformation(stringInfo);
+ for (String line : stringInfo) {
+ info.add(new LiteralText(line));
+ }
if (info.size() == 0)
return;
-
+
Screen screen = MinecraftClient.getInstance().currentScreen;
- screen.renderTooltip(info, tX+x, tY+y);
+ screen.renderTooltip(ScreenDrawing.getMatrices(), info, tX+x, tY+y);
}
/**
@@ -248,9 +257,18 @@ public class WWidget {
/**
* Adds information to this widget's tooltip. If information remains empty after this call, no tooltip will be drawn.
* @param information List containing all previous tooltip data.
+ * @deprecated Replaced with {@link #addTooltip(List)}
*/
+ @Deprecated
public void addInformation(List<String> information) {
}
+
+ /**
+ * Adds lines to this widget's tooltip. If the lines remain empty after this call, no tooltip will be drawn.
+ * @param tooltip List containing all previous tooltip data.
+ */
+ public void addTooltip(List<Text> tooltip) {
+ }
/**
* Find the most specific child node at this location. For non-panel widgets, returns this widget.