diff options
Diffstat (limited to 'src')
10 files changed, 105 insertions, 69 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 96546fa..2229424 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 @@ -4,6 +4,7 @@ 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.Style; import net.minecraft.text.Text; import io.github.cottonmc.cotton.gui.GuiDescription; @@ -221,8 +222,8 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree //} @Override - public void renderTextHover(MatrixStack matrices, Text text, int x, int y) { - renderTextHoverEffect(matrices, text, x, y); + public void renderTextHover(MatrixStack matrices, Style textStyle, int x, int y) { + renderTextHoverEffect(matrices, textStyle, x, y); } @Override 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 fb73dd2..a8327c2 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 @@ -6,7 +6,7 @@ import net.minecraft.client.render.DiffuseLighting; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; +import net.minecraft.text.Style; import org.lwjgl.glfw.GLFW; import io.github.cottonmc.cotton.gui.CottonInventoryController; @@ -199,10 +199,6 @@ public class CottonInventoryScreen<T extends CottonInventoryController> extends root.paint(matrices, x, y, mouseX-x, mouseY-y); } } - - if (getTitle() != null) { - textRenderer.draw(matrices, getTitle(), x, y, description.getTitleColor()); - } } @SuppressWarnings("deprecation") @@ -223,7 +219,16 @@ public class CottonInventoryScreen<T extends CottonInventoryController> extends drawMouseoverTooltip(matrices, mouseX, mouseY); //Draws the itemstack tooltips } - + + @Override + protected void drawForeground(MatrixStack matrices, int mouseX, int mouseY) { + if (description != null) { + this.textRenderer.draw(matrices, this.title, (float) this.field_25267, (float) this.field_25268, description.getTitleColor()); + } + + // Don't draw the player inventory label as it's drawn by the widget itself + } + @Override public void tick() { super.tick(); @@ -236,8 +241,8 @@ public class CottonInventoryScreen<T extends CottonInventoryController> extends } @Override - public void renderTextHover(MatrixStack matrices, Text text, int x, int y) { - renderTextHoverEffect(matrices, text, x, y); + public void renderTextHover(MatrixStack matrices, Style textStyle, int x, int y) { + renderTextHoverEffect(matrices, textStyle, x, y); } @Override 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 4868f92..e7baf15 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 @@ -2,12 +2,12 @@ package io.github.cottonmc.cotton.gui.client; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.class_5348; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; import net.minecraft.util.Identifier; import org.lwjgl.opengl.GL11; @@ -324,7 +324,7 @@ public class ScreenDrawing { * @param color the text color * @since 1.9.0 */ - public static void drawString(MatrixStack matrices, Text text, Alignment align, int x, int y, int width, int color) { + public static void drawString(MatrixStack matrices, class_5348 text, Alignment align, int x, int y, int width, int color) { switch(align) { case LEFT: { MinecraftClient.getInstance().textRenderer.draw(matrices, text, x, y, color); @@ -388,7 +388,7 @@ public class ScreenDrawing { * @param width the width of the string, used for aligning * @param color the text color */ - public static void drawStringWithShadow(MatrixStack matrices, Text text, Alignment align, int x, int y, int width, int color) { + public static void drawStringWithShadow(MatrixStack matrices, class_5348 text, Alignment align, int x, int y, int width, int color) { switch(align) { case LEFT: { MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, text, x, y, color); @@ -431,7 +431,7 @@ public class ScreenDrawing { * @param y the Y position * @param color the text color */ - public static void drawString(MatrixStack matrices, Text text, int x, int y, int color) { + public static void drawString(MatrixStack matrices, class_5348 text, int x, int y, int color) { MinecraftClient.getInstance().textRenderer.draw(matrices, text, x, y, color); } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/TextHoverRendererScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/TextHoverRendererScreen.java index 7c46450..d6b4ca1 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/TextHoverRendererScreen.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/TextHoverRendererScreen.java @@ -1,11 +1,11 @@ package io.github.cottonmc.cotton.gui.client; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; +import net.minecraft.text.Style; /** * Implemented by LibGui screens to access {@code Screen.renderTextHoverEffect()}. */ public interface TextHoverRendererScreen { - void renderTextHover(MatrixStack matrices, Text text, int x, int y); + void renderTextHover(MatrixStack matrices, Style textStyle, int x, int y); } 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 7946259..7087e00 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 @@ -2,19 +2,18 @@ package io.github.cottonmc.cotton.gui.widget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.class_5348; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.widget.AbstractButtonWidget; import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.sound.SoundEvents; -import net.minecraft.text.Text; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.widget.data.Alignment; -import org.lwjgl.glfw.GLFW; public class WButton extends WWidget { - private Text label; + private class_5348 label; protected int color = WLabel.DEFAULT_TEXT_COLOR; protected int darkmodeColor = WLabel.DEFAULT_TEXT_COLOR; private boolean enabled = true; @@ -26,7 +25,7 @@ public class WButton extends WWidget { } - public WButton(Text text) { + public WButton(class_5348 text) { this.label = text; } @@ -111,11 +110,11 @@ public class WButton extends WWidget { return this; } - public Text getLabel() { + public class_5348 getLabel() { return label; } - public WButton setLabel(Text label) { + public WButton setLabel(class_5348 label) { this.label = label; return this; } 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 09f24e7..edbc36b 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 @@ -2,11 +2,12 @@ package io.github.cottonmc.cotton.gui.widget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.class_5348; 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; +import net.minecraft.text.Style; import io.github.cottonmc.cotton.gui.client.LibGuiClient; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; @@ -19,7 +20,7 @@ import javax.annotation.Nullable; * A single-line label widget. */ public class WLabel extends WWidget { - protected Text text; + protected class_5348 text; protected Alignment alignment = Alignment.LEFT; protected int color; protected int darkmodeColor; @@ -50,7 +51,7 @@ public class WLabel extends WWidget { * @param text the text of the label * @param color the color of the label */ - public WLabel(Text text, int color) { + public WLabel(class_5348 text, int color) { this.text = text; this.color = color; this.darkmodeColor = (color==DEFAULT_TEXT_COLOR) ? DEFAULT_DARKMODE_TEXT_COLOR : color; @@ -71,7 +72,7 @@ public class WLabel extends WWidget { * @param text the text of the label * @since 1.8.0 */ - public WLabel(Text text) { + public WLabel(class_5348 text) { this(text, DEFAULT_TEXT_COLOR); } @@ -79,11 +80,11 @@ public class WLabel extends WWidget { public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { ScreenDrawing.drawString(matrices, text, alignment, x, y, this.getWidth(), LibGuiClient.config.darkMode ? darkmodeColor : color); - Text hoveredText = getTextAt(mouseX, mouseY); - if (hoveredText != null) { + Style hoveredTextStyle = getTextStyleAt(mouseX, mouseY); + if (hoveredTextStyle != null) { Screen screen = MinecraftClient.getInstance().currentScreen; if (screen instanceof TextHoverRendererScreen) { - ((TextHoverRendererScreen) screen).renderTextHover(matrices, hoveredText, x + mouseX, y + mouseY); + ((TextHoverRendererScreen) screen).renderTextHover(matrices, hoveredTextStyle, x + mouseX, y + mouseY); } } } @@ -91,20 +92,20 @@ public class WLabel extends WWidget { @Environment(EnvType.CLIENT) @Override public void onClick(int x, int y, int button) { - Text hoveredText = getTextAt(x, y); - if (hoveredText != null) { + Style hoveredTextStyle = getTextStyleAt(x, y); + if (hoveredTextStyle != null) { Screen screen = MinecraftClient.getInstance().currentScreen; if (screen != null) { - screen.handleTextClick(hoveredText); + screen.handleTextClick(hoveredTextStyle); } } } @Environment(EnvType.CLIENT) @Nullable - public Text getTextAt(int x, int y) { + public Style getTextStyleAt(int x, int y) { if (isWithinBounds(x, y)) { - return MinecraftClient.getInstance().textRenderer.trimToWidth(text, x); + return MinecraftClient.getInstance().textRenderer.getTextHandler().trimToWidth(text, x); } return null; } @@ -118,7 +119,11 @@ public class WLabel extends WWidget { public void setSize(int x, int y) { super.setSize(x, Math.max(8, y)); } - + + public int getDarkmodeColor() { + return darkmodeColor; + } + public WLabel setDarkmodeColor(int color) { darkmodeColor = color; return this; @@ -128,18 +133,35 @@ public class WLabel extends WWidget { this.darkmodeColor = this.color; return this; } - + + public int getColor() { + return color; + } + + public WLabel setColor(int color) { + this.color = color; + return this; + } + public WLabel setColor(int color, int darkmodeColor) { this.color = color; this.darkmodeColor = darkmodeColor; return this; } - - public WLabel setText(Text text) { + + public class_5348 getText() { + return text; + } + + public WLabel setText(class_5348 text) { this.text = text; return this; } - + + public Alignment getAlignment() { + return alignment; + } + public WLabel setAlignment(Alignment align) { this.alignment = align; return this; 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 d853bd7..7f122da 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 @@ -2,10 +2,10 @@ package io.github.cottonmc.cotton.gui.widget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.class_5348; import net.minecraft.client.gui.widget.AbstractButtonWidget; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.Vector3f; -import net.minecraft.text.Text; import net.minecraft.util.math.Quaternion; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; @@ -26,7 +26,7 @@ import javax.annotation.Nullable; public class WLabeledSlider extends WAbstractSlider { private static final Quaternion ROTATION_Z_270 = Vector3f.POSITIVE_X.getDegreesQuaternion(270); - @Nullable private Text label = null; + @Nullable private class_5348 label = null; @Nullable private LabelUpdater labelUpdater = null; private Alignment labelAlignment = Alignment.CENTER; @@ -59,7 +59,7 @@ public class WLabeledSlider extends WAbstractSlider { * @param axis the slider axis * @param label the slider label (can be null) */ - public WLabeledSlider(int min, int max, Axis axis, @Nullable Text label) { + public WLabeledSlider(int min, int max, Axis axis, @Nullable class_5348 label) { this(min, max, axis); this.label = label; } @@ -71,7 +71,7 @@ public class WLabeledSlider extends WAbstractSlider { * @param max the maximum value * @param label the slider label (can be null) */ - public WLabeledSlider(int min, int max, @Nullable Text label) { + public WLabeledSlider(int min, int max, @Nullable class_5348 label) { this(min, max); this.label = label; } @@ -91,7 +91,7 @@ public class WLabeledSlider extends WAbstractSlider { * @return the label */ @Nullable - public Text getLabel() { + public class_5348 getLabel() { return label; } @@ -100,7 +100,7 @@ public class WLabeledSlider extends WAbstractSlider { * * @param label the new label */ - public void setLabel(@Nullable Text label) { + public void setLabel(@Nullable class_5348 label) { this.label = label; } @@ -228,6 +228,6 @@ public class WLabeledSlider extends WAbstractSlider { * @param value the slider value * @return the label */ - Text updateLabel(int value); + class_5348 updateLabel(int value); } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java index 3002fc2..d657a01 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java @@ -2,6 +2,9 @@ package io.github.cottonmc.cotton.gui.widget; import java.util.ArrayList; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; import io.github.cottonmc.cotton.gui.GuiDescription; import io.github.cottonmc.cotton.gui.client.BackgroundPainter; @@ -265,4 +268,9 @@ public abstract class WPanel extends WWidget { return null; } + + @Override + public String toString() { + return "WPanel{ children: [\n" + children.stream().map(Objects::toString).flatMap(x -> Stream.of(x.split("\n")).map(y -> "\t" + y)).collect(Collectors.joining(",\n")) + "] }"; + } } 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 ea7f721..4051a89 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 @@ -2,11 +2,12 @@ package io.github.cottonmc.cotton.gui.widget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.class_5348; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; +import net.minecraft.text.Style; import io.github.cottonmc.cotton.gui.client.LibGuiClient; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; @@ -23,18 +24,18 @@ import java.util.Objects; * @since 1.8.0 */ public class WText extends WWidget { - protected Text text; + protected class_5348 text; protected int color; protected int darkmodeColor; protected Alignment alignment = Alignment.LEFT; - private List<Text> wrappedLines; + private List<class_5348> wrappedLines; private boolean wrappingScheduled = false; - public WText(Text text) { + public WText(class_5348 text) { this(text, WLabel.DEFAULT_TEXT_COLOR); } - public WText(Text text, int color) { + public WText(class_5348 text, int color) { this.text = Objects.requireNonNull(text, "text must not be null"); this.color = color; this.darkmodeColor = (color == WLabel.DEFAULT_TEXT_COLOR) ? WLabel.DEFAULT_DARKMODE_TEXT_COLOR : color; @@ -59,13 +60,13 @@ public class WText extends WWidget { @Environment(EnvType.CLIENT) @Nullable - public Text getTextAt(int x, int y) { + public Style getTextStyleAt(int x, int y) { TextRenderer font = MinecraftClient.getInstance().textRenderer; int lineIndex = y / font.fontHeight; if (lineIndex >= 0 && lineIndex < wrappedLines.size()) { - Text line = wrappedLines.get(lineIndex); - return font.trimToWidth(line, x); + class_5348 line = wrappedLines.get(lineIndex); + return font.getTextHandler().trimToWidth(line, x); } return null; @@ -81,17 +82,17 @@ public class WText extends WWidget { TextRenderer font = MinecraftClient.getInstance().textRenderer; for (int i = 0; i < wrappedLines.size(); i++) { - Text line = wrappedLines.get(i); + class_5348 line = wrappedLines.get(i); int c = LibGuiClient.config.darkMode ? darkmodeColor : color; ScreenDrawing.drawString(matrices, line, alignment, x, y + i * font.fontHeight, width, c); } - Text hoveredText = getTextAt(mouseX, mouseY); - if (hoveredText != null) { + Style hoveredTextStyle = getTextStyleAt(mouseX, mouseY); + if (hoveredTextStyle != null) { Screen screen = MinecraftClient.getInstance().currentScreen; if (screen instanceof TextHoverRendererScreen) { - ((TextHoverRendererScreen) screen).renderTextHover(matrices, hoveredText, x + mouseX, y + mouseY); + ((TextHoverRendererScreen) screen).renderTextHover(matrices, hoveredTextStyle, x + mouseX, y + mouseY); } } } @@ -101,17 +102,17 @@ public class WText extends WWidget { public void onClick(int x, int y, int button) { if (button != 0) return; // only left clicks - Text hoveredText = getTextAt(x, y); - if (hoveredText != null) { - MinecraftClient.getInstance().currentScreen.handleTextClick(hoveredText); + Style hoveredTextStyle = getTextStyleAt(x, y); + if (hoveredTextStyle != null) { + MinecraftClient.getInstance().currentScreen.handleTextClick(hoveredTextStyle); } } - public Text getText() { + public class_5348 getText() { return text; } - public WText setText(Text text) { + public WText setText(class_5348 text) { Objects.requireNonNull(text, "text is null"); this.text = text; wrappingScheduled = true; 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 ac1f42d..9d1306f 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,11 +2,11 @@ package io.github.cottonmc.cotton.gui.widget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.class_5348; import net.minecraft.client.MinecraftClient; import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.sound.SoundEvents; -import net.minecraft.text.Text; import net.minecraft.util.Identifier; import io.github.cottonmc.cotton.gui.client.LibGuiClient; @@ -25,7 +25,7 @@ public class WToggleButton extends WWidget { protected Identifier offImage; protected Identifier focusImage = DEFAULT_FOCUS_IMAGE; - @Nullable protected Text label = null; + @Nullable protected class_5348 label = null; protected boolean isOn = false; @Nullable protected Consumer<Boolean> onToggle = null; @@ -39,7 +39,7 @@ public class WToggleButton extends WWidget { } /** Defaults with text */ - public WToggleButton(Text text) { + public WToggleButton(class_5348 text) { this(DEFAULT_ON_IMAGE, DEFAULT_OFF_IMAGE); this.label = text; } @@ -51,7 +51,7 @@ public class WToggleButton extends WWidget { } /** Custom images, with default sizes and a label */ - public WToggleButton(Identifier onImage, Identifier offImage, Text label) { + public WToggleButton(Identifier onImage, Identifier offImage, class_5348 label) { this.onImage = onImage; this.offImage = offImage; this.label = label; @@ -118,11 +118,11 @@ public class WToggleButton extends WWidget { } @Nullable - public Text getLabel() { + public class_5348 getLabel() { return label; } - public WToggleButton setLabel(@Nullable Text label) { + public WToggleButton setLabel(@Nullable class_5348 label) { this.label = label; return this; } |