From 54cab8890fae9b3f7803b368fb97208d570447b1 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Thu, 9 Apr 2020 18:20:31 +0300 Subject: Fix #43, fix null inventories not being converted to EmptyInventory There's no Nullable on InventoryProvider.getInventory, but some mods return null there. --- .../cotton/gui/CottonCraftingController.java | 32 +++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java b/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java index ec0cdc9..000d63d 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java @@ -110,15 +110,15 @@ public class CottonCraftingController extends AbstractRecipeScreenHandler inventorySlots = new ArrayList<>(); for(Slot slot : slots) { @@ -186,13 +186,13 @@ public class CottonCraftingController extends AbstractRecipeScreenHandler=0; i--) { Slot curSlot = inventorySlots.get(i); - if (insertIntoExisting(toInsert, curSlot)) inserted = true; + if (insertIntoExisting(toInsert, curSlot, player)) inserted = true; if (toInsert.isEmpty()) break; } } else { for(int i=0; i storageSlots = new ArrayList<>(); ArrayList hotbarSlots = new ArrayList<>(); @@ -243,7 +243,7 @@ public class CottonCraftingController extends AbstractRecipeScreenHandler Date: Thu, 9 Apr 2020 18:31:44 +0300 Subject: Update to 20w15a, bump version to 1.8.1 --- gradle.properties | 10 +++++----- .../cottonmc/cotton/gui/CottonCraftingController.java | 2 +- .../java/io/github/cottonmc/cotton/gui/EmptyInventory.java | 14 +++++++------- .../java/io/github/cottonmc/cotton/gui/ValidatedSlot.java | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/main/java') diff --git a/gradle.properties b/gradle.properties index 9d3b564..eac0999 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=20w12a - yarn_mappings=20w12a+build.14 - loader_version=0.7.8+build.186 + minecraft_version=20w15a + yarn_mappings=20w15a+build.3 + loader_version=0.8.2+build.194 # Mod Properties - mod_version = 1.8.0 + mod_version = 1.8.1 maven_group = io.github.cottonmc archives_base_name = LibGui # Dependencies - fabric_version=0.5.5+build.311-1.16 + fabric_version=0.5.9+build.319-1.16 jankson_version=2.0.1+j1.2.0 diff --git a/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java b/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java index 000d63d..6bc7dcd 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java @@ -421,7 +421,7 @@ public class CottonCraftingController extends AbstractRecipeScreenHandler Date: Sat, 25 Apr 2020 23:15:06 +0300 Subject: Update to 20w17a I hate this snapshot. --- build.gradle | 2 +- gradle.properties | 8 +- .../cotton/gui/client/CottonClientScreen.java | 12 ++- .../cottonmc/cotton/gui/client/CottonHud.java | 4 +- .../cotton/gui/client/CottonInventoryScreen.java | 18 ++-- .../cottonmc/cotton/gui/client/ScreenDrawing.java | 109 +++++++++++++++++++-- .../io/github/cottonmc/cotton/gui/widget/WBar.java | 13 +-- .../github/cottonmc/cotton/gui/widget/WButton.java | 2 +- .../github/cottonmc/cotton/gui/widget/WLabel.java | 12 +-- .../cottonmc/cotton/gui/widget/WLabeledSlider.java | 2 +- .../github/cottonmc/cotton/gui/widget/WText.java | 11 +-- .../cottonmc/cotton/gui/widget/WTextField.java | 10 +- .../cottonmc/cotton/gui/widget/WToggleButton.java | 3 +- .../github/cottonmc/cotton/gui/widget/WWidget.java | 30 ++++-- 14 files changed, 170 insertions(+), 66 deletions(-) (limited to 'src/main/java') diff --git a/build.gradle b/build.gradle index dc89864..3d0e1db 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ buildscript { System.out.println(rootProject.name); if (rootProject.name.equalsIgnoreCase("LibGUI")) { System.out.println("Added libgui to classpath"); - classpath 'fabric-loom:fabric-loom.gradle.plugin:0.2.6-SNAPSHOT' + classpath 'fabric-loom:fabric-loom.gradle.plugin:0.2.7-SNAPSHOT' } } } diff --git a/gradle.properties b/gradle.properties index eac0999..b1db372 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=20w15a - yarn_mappings=20w15a+build.3 + minecraft_version=20w17a + yarn_mappings=20w17a+build.4 loader_version=0.8.2+build.194 # Mod Properties - mod_version = 1.8.1 + mod_version = 1.9.0 maven_group = io.github.cottonmc archives_base_name = LibGui # Dependencies - fabric_version=0.5.9+build.319-1.16 + fabric_version=0.6.2+build.327-1.16 jankson_version=2.0.1+j1.2.0 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 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 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 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 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,8 +19,22 @@ 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. * @@ -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 information) { + public void addTooltip(List 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 info = new ArrayList<>(); - addInformation(info); + List info = new ArrayList<>(); + addTooltip(info); + + List 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 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 tooltip) { + } /** * Find the most specific child node at this location. For non-panel widgets, returns this widget. -- cgit From 0706a4f52d768fbb485c5c0000ffc8d187703bbe Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Sat, 25 Apr 2020 23:25:50 +0300 Subject: Use better text wrapping --- src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main/java') 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 2522644..e9c34e7 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 @@ -10,6 +10,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.util.Texts; +import net.minecraft.text.Style; import net.minecraft.text.Text; import javax.annotation.Nullable; @@ -48,7 +49,7 @@ public class WText extends WWidget { @Environment(EnvType.CLIENT) private void wrapLines() { TextRenderer font = MinecraftClient.getInstance().textRenderer; - wrappedLines = Texts.wrapLines(text, width, font); + wrappedLines = font.method_27527().method_27491(text, width, Style.field_24360, false); } @Environment(EnvType.CLIENT) -- cgit From 095e92e3508f8a32d1910c0619afb31df0657598 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Sun, 26 Apr 2020 00:19:03 +0300 Subject: Add missing alignment accessors to WText --- .../github/cottonmc/cotton/gui/widget/WText.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/main/java') 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 e9c34e7..4a4e63c 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 @@ -136,4 +136,26 @@ public class WText extends WWidget { this.darkmodeColor = this.color; return this; } + + /** + * Gets the alignment of this text widget. + * + * @return the alignment + * @since 1.9.0 + */ + public Alignment getAlignment() { + return alignment; + } + + /** + * Sets the alignment of this text widget. + * + * @param alignment the new alignment + * @return this widget + * @since 1.9.0 + */ + public WText setAlignment(Alignment alignment) { + this.alignment = alignment; + return this; + } } -- cgit From 73487371949a9dcc3c67aed69e689ab9390b6230 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Mon, 13 Apr 2020 21:14:29 +0300 Subject: Fix #45 --- src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main/java') 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 4a4e63c..b94a626 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 @@ -69,7 +69,7 @@ public class WText extends WWidget { @Environment(EnvType.CLIENT) @Override public void paintBackground(int x, int y, int mouseX, int mouseY) { - if (wrappingScheduled) { + if (wrappedLines == null || wrappingScheduled) { wrapLines(); wrappingScheduled = false; } @@ -106,6 +106,7 @@ public class WText extends WWidget { } public WText setText(Text text) { + Objects.requireNonNull(text, "text is null"); this.text = text; wrappingScheduled = true; -- cgit From c4f5735047943775c8f4fddc80f87227d0127753 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Mon, 13 Apr 2020 21:27:50 +0300 Subject: Improve WWidget documentation and add Nullable annotations --- .../github/cottonmc/cotton/gui/widget/WWidget.java | 94 +++++++++++++++++++--- 1 file changed, 84 insertions(+), 10 deletions(-) (limited to 'src/main/java') 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 4914e98..83003cc 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 @@ -12,32 +12,78 @@ import net.minecraft.client.gui.screen.Screen; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; +import javax.annotation.Nullable; + +/** + * The base class for all widgets. + */ public class WWidget { + /** + * The containing panel of this widget. + * Can be null if this widget is the root panel or a HUD widget. + */ + @Nullable protected WPanel parent; protected int x = 0; protected int y = 0; protected int width = 18; protected int height = 18; + + /** + * The containing {@link GuiDescription} of this widget. + * Can be null if this widget is a {@linkplain io.github.cottonmc.cotton.gui.client.CottonHud HUD} widget. + */ + @Nullable protected GuiDescription host; - + + /** + * Sets the location of this widget relative to its parent. + * + * @param x the new X coordinate + * @param y the new Y coordinate + */ public void setLocation(int x, int y) { this.x = x; this.y = y; } - + + /** + * Sets the size of this widget. + * + *

Overriding methods may restrict one of the dimensions to be + * a constant value, for example {@code super.setSize(x, 20)}. + * + * @param x the new width + * @param y the new height + */ public void setSize(int x, int y) { this.width = x; this.height = y; } - + + /** + * Gets the X coordinate of this widget relative to its parent. + * + * @return the X coordinate + */ public int getX() { return x; } - + + /** + * Gets the Y coordinate of this widget relative to its parent. + * + * @return the Y coordinate + */ public int getY() { return y; } - + + /** + * Gets the absolute X coordinate of this widget. + * + * @return the absolute X coordinate + */ public int getAbsoluteX() { if (parent==null) { return getX(); @@ -45,7 +91,12 @@ public class WWidget { return getX() + parent.getAbsoluteX(); } } - + + /** + * Gets the absolute Y coordinate of this widget. + * + * @return the absolute Y coordinate + */ public int getAbsoluteY() { if (parent==null) { return getY(); @@ -61,11 +112,21 @@ public class WWidget { public int getHeight() { return height; } - + + /** + * Checks whether this widget can be resized using {@link #setSize}. + * + * @return true if this widget can be resized, false otherwise + */ public boolean canResize() { return false; } - + + /** + * Sets the parent panel of this widget. + * + * @param parent the new parent + */ public void setParent(WPanel parent) { this.parent = parent; } @@ -219,7 +280,16 @@ public class WWidget { // renderTooltip(mouseX, mouseY); //} } - + + /** + * Checks whether a location is within this widget's bounds. + * + *

The default implementation checks that X and Y are at least 0 and below the width and height of this widget. + * + * @param x the X coordinate + * @param y the Y coordinate + * @return true if the location is within this widget, false otherwise + */ public boolean isWithinBounds(int x, int y) { return x>=0 && y>=0 && x Date: Mon, 13 Apr 2020 21:28:20 +0300 Subject: Add Environment annotations to WWidget.tick overrides --- .../java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java | 3 +++ src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java | 1 + src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java | 6 +++++- 3 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src/main/java') diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java index a086b3a..7d19288 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java @@ -1,5 +1,7 @@ package io.github.cottonmc.cotton.gui.widget; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.util.math.MathHelper; import org.lwjgl.glfw.GLFW; @@ -152,6 +154,7 @@ public abstract class WAbstractSlider extends WWidget { } } + @Environment(EnvType.CLIENT) @Override public void tick() { if (draggingFinishedFromScrollingTimer > 0) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java index be516c7..6302125 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java @@ -41,6 +41,7 @@ public class WItem extends WWidget { return true; } + @Environment(EnvType.CLIENT) @Override public void tick() { if (ticks++ >= duration) { 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 1233d7d..706a71b 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 @@ -169,7 +169,11 @@ public abstract class WPanel extends WWidget { child.paintForeground(x + child.getX(), y + child.getY(), mouseX, mouseY); } } - + + /** + * Ticks all children of this panel. + */ + @Environment(EnvType.CLIENT) @Override public void tick() { for(WWidget child : children) child.tick(); -- cgit From 993de8f9a6392fc69c92e33216d1da4fb8983c30 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Mon, 13 Apr 2020 21:32:54 +0300 Subject: Improve panel and list docs --- .../cottonmc/cotton/gui/widget/WListPanel.java | 36 ++++++++++++++++++++-- .../github/cottonmc/cotton/gui/widget/WPanel.java | 30 ++++++++++++++++-- 2 files changed, 60 insertions(+), 6 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java index 7c92191..ff2b897 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java @@ -16,25 +16,49 @@ import io.github.cottonmc.cotton.gui.widget.data.Axis; *

W is the WWidget class that will represent a single D of data. */ public class WListPanel extends WClippedPanel { + /** + * The list of data that this list represents. + */ protected List data; + + /** + * The supplier of new empty widgets. + */ protected Supplier supplier; + + /** + * The widget configurator that configures the passed widget + * to display the passed data. + */ protected BiConsumer configurator; protected HashMap configured = new HashMap<>(); protected List unconfigured = new ArrayList<>(); + + /** + * The height of each child cell. + */ protected int cellHeight = 20; + + /** + * Whether this list has a fixed height for items. + */ protected boolean fixedHeight = false; protected int margin = 4; - + + /** + * The scroll bar of this list. + */ protected WScrollBar scrollBar = new WScrollBar(Axis.VERTICAL); - int lastScroll = -1; + private int lastScroll = -1; public WListPanel(List data, Supplier supplier, BiConsumer configurator) { this.data = data; this.supplier = supplier; this.configurator = configurator; scrollBar.setMaxValue(data.size()); + scrollBar.setParent(this); } /** @@ -157,7 +181,13 @@ public class WListPanel extends WClippedPanel { //System.out.println("Children: "+children.size()); } - + + /** + * Sets the height of this list's items to a constant value. + * + * @param height the item height + * @return this list + */ public WListPanel setListItemHeight(int height) { cellHeight = height; fixedHeight = true; 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 706a71b..373479b 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 @@ -9,7 +9,15 @@ import io.github.cottonmc.cotton.gui.client.BackgroundPainter; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +/** + * Panels are widgets tthat contain other widgets. + */ public abstract class WPanel extends WWidget { + /** + * The widgets contained within this panel. + * + *

The list is mutable. + */ protected final List children = Lists.newArrayList(); @Environment(EnvType.CLIENT) private BackgroundPainter backgroundPainter = null; @@ -21,7 +29,12 @@ public abstract class WPanel extends WWidget { child.createPeers(c); } } - + + /** + * Removes the widget from this panel. + * + * @param w the removed widget + */ public void remove(WWidget w) { children.remove(w); } @@ -30,13 +43,24 @@ public abstract class WPanel extends WWidget { public boolean canResize() { return true; } - + + /** + * Sets the {@link BackgroundPainter} of this panel. + * + * @param painter the new painter + * @return this panel + */ @Environment(EnvType.CLIENT) public WPanel setBackgroundPainter(BackgroundPainter painter) { this.backgroundPainter = painter; return this; } - + + /** + * Gets the current {@link BackgroundPainter} of this panel. + * + * @return the painter + */ @Environment(EnvType.CLIENT) public BackgroundPainter getBackgroundPainter() { return this.backgroundPainter; -- cgit From 67e660cfb277f184cb55b7234740cba1b2f462d0 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Wed, 15 Apr 2020 15:47:04 +0300 Subject: Improve labeled slider docs --- .../cottonmc/cotton/gui/widget/WLabeledSlider.java | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'src/main/java') 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 5b7e812..d9ab1b0 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 @@ -25,19 +25,47 @@ public class WLabeledSlider extends WAbstractSlider { @Nullable private LabelUpdater labelUpdater = null; private Alignment labelAlignment = Alignment.CENTER; + /** + * Constructs a horizontal slider with no default label. + * + * @param min the minimum value + * @param max the maximum value + */ public WLabeledSlider(int min, int max) { this(min, max, Axis.HORIZONTAL); } + /** + * Constructs a slider with no default label. + * + * @param min the minimum value + * @param max the maximum value + * @param axis the slider axis + */ public WLabeledSlider(int min, int max, Axis axis) { super(min, max, axis); } + /** + * Constructs a slider. + * + * @param min the minimum value + * @param max the maximum value + * @param axis the slider axis + * @param label the slider label (can be null) + */ public WLabeledSlider(int min, int max, Axis axis, @Nullable Text label) { this(min, max, axis); this.label = label; } + /** + * Constructs a horizontal slider. + * + * @param min the minimum value + * @param max the maximum value + * @param label the slider label (can be null) + */ public WLabeledSlider(int min, int max, @Nullable Text label) { this(min, max); this.label = label; @@ -52,11 +80,21 @@ public class WLabeledSlider extends WAbstractSlider { } } + /** + * Gets the current label of this slider. + * + * @return the label + */ @Nullable public Text getLabel() { return label; } + /** + * Sets the label of this slider. + * + * @param label the new label + */ public void setLabel(@Nullable Text label) { this.label = label; } @@ -69,19 +107,39 @@ public class WLabeledSlider extends WAbstractSlider { } } + /** + * Gets the text alignment of this slider's label. + * + * @return the alignment + */ public Alignment getLabelAlignment() { return labelAlignment; } + /** + * Sets the text alignment of this slider's label. + * + * @param labelAlignment the new alignment + */ public void setLabelAlignment(Alignment labelAlignment) { this.labelAlignment = labelAlignment; } + /** + * Gets the {@link LabelUpdater} of this slider. + * + * @return the label updater + */ @Nullable public LabelUpdater getLabelUpdater() { return labelUpdater; } + /** + * Sets the {@link LabelUpdater} of this slider. + * + * @param labelUpdater the new label updater + */ public void setLabelUpdater(@Nullable LabelUpdater labelUpdater) { this.labelUpdater = labelUpdater; } @@ -150,8 +208,19 @@ public class WLabeledSlider extends WAbstractSlider { ScreenDrawing.texturedRect(x + halfWidth, y, halfWidth, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonEndLeft, buttonTop, 200 * px, buttonTop + buttonHeight, 0xFFFFFFFF); } + /** + * A label updater updates the label of a slider based on the current value. + * + *

Useful for situations when you want to have display values on the slider. + */ @FunctionalInterface public interface LabelUpdater { + /** + * Gets the updated label for the new slider value. + * + * @param value the slider value + * @return the label + */ Text updateLabel(int value); } } -- cgit From 308915315a358ce14c8951bc97bac76abb0da8bf Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Wed, 15 Apr 2020 15:58:44 +0300 Subject: Add some label docs --- src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/main/java') 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 6db09b9..e815723 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 @@ -23,7 +23,14 @@ public class WLabel extends WWidget { protected int color; protected int darkmodeColor; + /** + * The default text color for light mode labels. + */ public static final int DEFAULT_TEXT_COLOR = 0x404040; + + /** + * The default text color for {@linkplain io.github.cottonmc.cotton.gui.client.LibGuiConfig#darkMode dark mode} labels. + */ public static final int DEFAULT_DARKMODE_TEXT_COLOR = 0xbcbcbc; /** -- cgit From cf26e57d6846474702c0a86b0d199667a233ffc0 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Wed, 15 Apr 2020 16:06:32 +0300 Subject: Add Environment annotations to interaction methods Should fix #41. --- .../io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java | 7 +++++++ .../java/io/github/cottonmc/cotton/gui/widget/WButton.java | 5 ++++- src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java | 1 + src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java | 9 ++++++--- .../java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java | 8 ++++++-- src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java | 1 + .../java/io/github/cottonmc/cotton/gui/widget/WTextField.java | 9 ++++++--- .../java/io/github/cottonmc/cotton/gui/widget/WWidget.java | 10 ++++++++++ 8 files changed, 41 insertions(+), 9 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java index 7d19288..b5e1344 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WAbstractSlider.java @@ -105,6 +105,7 @@ public abstract class WAbstractSlider extends WWidget { return true; } + @Environment(EnvType.CLIENT) @Override public WWidget onMouseDown(int x, int y, int button) { // Check if cursor is inside or <=2px away from track @@ -114,6 +115,7 @@ public abstract class WAbstractSlider extends WWidget { return super.onMouseDown(x, y, button); } + @Environment(EnvType.CLIENT) @Override public void onMouseDrag(int x, int y, int button) { if (isFocused()) { @@ -122,6 +124,7 @@ public abstract class WAbstractSlider extends WWidget { } } + @Environment(EnvType.CLIENT) @Override public void onClick(int x, int y, int button) { moveSlider(x, y); @@ -136,6 +139,7 @@ public abstract class WAbstractSlider extends WWidget { if (value != previousValue) onValueChanged(value); } + @Environment(EnvType.CLIENT) @Override public WWidget onMouseUp(int x, int y, int button) { dragging = false; @@ -143,6 +147,7 @@ public abstract class WAbstractSlider extends WWidget { return super.onMouseUp(x, y, button); } + @Environment(EnvType.CLIENT) @Override public void onMouseScroll(int x, int y, double amount) { int previous = value; @@ -245,6 +250,7 @@ public abstract class WAbstractSlider extends WWidget { if (valueChangeListener != null) valueChangeListener.accept(value); } + @Environment(EnvType.CLIENT) @Override public void onKeyPressed(int ch, int key, int modifiers) { boolean valueChanged = false; @@ -272,6 +278,7 @@ public abstract class WAbstractSlider extends WWidget { } } + @Environment(EnvType.CLIENT) @Override public void onKeyReleased(int ch, int key, int modifiers) { if (pendingDraggingFinishedFromKeyboard && (isDecreasingKey(ch) || isIncreasingKey(ch))) { 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 aa025f0..b3fc425 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,6 +2,8 @@ package io.github.cottonmc.cotton.gui.widget; 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; import net.minecraft.client.gui.widget.AbstractButtonWidget; import net.minecraft.client.sound.PositionedSoundInstance; @@ -66,7 +68,8 @@ public class WButton extends WWidget { public void setSize(int x, int y) { super.setSize(x, 20); } - + + @Environment(EnvType.CLIENT) @Override public void onClick(int x, int y, int button) { super.onClick(x, y, button); 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 e815723..1ab42b1 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 @@ -87,6 +87,7 @@ public class WLabel extends WWidget { } } + @Environment(EnvType.CLIENT) @Override public void onClick(int x, int y, int button) { Text hoveredText = getTextAt(x, y); 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 373479b..e7bdeab 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 @@ -86,7 +86,8 @@ public abstract class WPanel extends WWidget { int pushDown = w.getY()+w.getHeight(); this.setSize(Math.max(this.getWidth(), pushRight), Math.max(this.getHeight(), pushDown)); } - + + @Environment(EnvType.CLIENT) @Override public WWidget onMouseUp(int x, int y, int button) { if (children.isEmpty()) return super.onMouseUp(x, y, button); @@ -101,7 +102,8 @@ public abstract class WPanel extends WWidget { } return super.onMouseUp(x, y, button); } - + + @Environment(EnvType.CLIENT) @Override public WWidget onMouseDown(int x, int y, int button) { if (children.isEmpty()) return super.onMouseDown(x, y, button); @@ -116,7 +118,8 @@ public abstract class WPanel extends WWidget { } return super.onMouseDown(x, y, button); } - + + @Environment(EnvType.CLIENT) @Override public void onMouseDrag(int x, int y, int button) { if (children.isEmpty()) return; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java index aa64567..7f2dac3 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java @@ -3,6 +3,8 @@ 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.Axis; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; public class WScrollBar extends WWidget { protected Axis axis = Axis.HORIZONTAL; @@ -150,12 +152,14 @@ public class WScrollBar extends WWidget { sliding = true; return this; } - + + @Environment(EnvType.CLIENT) @Override public void onMouseDrag(int x, int y, int button) { adjustSlider(x, y); } - + + @Environment(EnvType.CLIENT) @Override public WWidget onMouseUp(int x, int y, int button) { //TODO: Clicking before or after the handle should jump instead of scrolling 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 b94a626..f71f53b 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 @@ -91,6 +91,7 @@ public class WText extends WWidget { } } + @Environment(EnvType.CLIENT) @Override public void onClick(int x, int y, int button) { if (button != 0) return; // only left clicks 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 7896f6e..75e7628 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 @@ -529,13 +529,15 @@ public class WTextField extends WWidget { renderButton(x, y); } - + + @Environment(EnvType.CLIENT) @Override public void onClick(int x, int y, int button) { requestFocus(); cursor = getCaretPos(this.text, x-OFFSET_X_TEXT); } - + + @Environment(EnvType.CLIENT) @Override public void onCharTyped(char ch) { if (this.text.length() Date: Sun, 26 Apr 2020 00:47:40 +0300 Subject: Fix WTexts being fixed-size --- src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/main/java') 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 f71f53b..2052379 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 @@ -46,6 +46,11 @@ public class WText extends WWidget { wrappingScheduled = true; } + @Override + public boolean canResize() { + return true; + } + @Environment(EnvType.CLIENT) private void wrapLines() { TextRenderer font = MinecraftClient.getInstance().textRenderer; -- cgit From 9743d57ec08b0488e2c7152615d54dd813a1bd3f Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Sun, 26 Apr 2020 01:02:18 +0300 Subject: Remove broken scaling from WItem --- src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java | 1 - 1 file changed, 1 deletion(-) (limited to 'src/main/java') diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java index 6302125..d3d91b0 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java @@ -56,7 +56,6 @@ public class WItem extends WWidget { RenderSystem.pushMatrix(); RenderSystem.enableDepthTest(); RenderSystem.translatef(x, y, 0); - RenderSystem.scalef(1.2f, 1.2f, 1.0f); MinecraftClient mc = MinecraftClient.getInstance(); ItemRenderer renderer = mc.getItemRenderer(); -- cgit