diff --git a/CHANGELOG.md b/CHANGELOG.md index ef0c904d..09ee1e5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,3 +69,10 @@ - Updated to Minecraft 1.20.6 ([#51](https://github.com/LambdAurora/SpruceUI/pull/51)). - Added `MenuBackground` and `MenuBorder` to adapt to Minecraft's new GUI design. + +## 6.0.0 + +- Updated to Minecraft 1.21.2. +- Added `TexturedBorder` for textured borders. +- Updated widget textures to match the new sprite system. +- Removed `ScissorManager` in favor of `GuiGraphics` scissor handling. diff --git a/build.gradle.kts b/build.gradle.kts index 7bb15859..7729e8f8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -28,7 +28,7 @@ group = project.property("maven_group") as String base.archivesName.set(project.property("archives_base_name") as String) val mcVersion = project.property("minecraft_version") as String -version = "${project.property("mod_version")}+${mcVersion}" +version = project.property("mod_version") as String val targetJavaVersion = 21 @@ -171,7 +171,6 @@ dependencies { modLocalRuntime("com.terraformersmc:modmenu:${project.property("modmenu_version")}") { isTransitive = false } - modLocalRuntime(fabricApi.module("fabric-key-binding-api-v1", project.property("fabric_api_version") as String)) "testmodImplementation"(sourceSets.main.get().output) } diff --git a/gradle.properties b/gradle.properties index b602345e..12e582db 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,16 +1,16 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx2G -minecraft_version=1.21.1 -yalmm_mappings=2 -loader_version=0.15.11 +minecraft_version=1.21.2-rc1 +yalmm_mappings=4 +loader_version=0.16.7 # Mod Properties -mod_version=5.1.0 +mod_version=6.0.0+1.21.2 maven_group=dev.lambdaurora archives_base_name=spruceui # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api -fabric_api_version=0.100.4+1.21 -modmenu_version=11.0.1 +fabric_api_version=0.106.0+1.21.2 +modmenu_version=12.0.0-beta.1 diff --git a/src/main/java/dev/lambdaurora/spruceui/SpruceTextures.java b/src/main/java/dev/lambdaurora/spruceui/SpruceTextures.java index 47f48261..28b96fdb 100644 --- a/src/main/java/dev/lambdaurora/spruceui/SpruceTextures.java +++ b/src/main/java/dev/lambdaurora/spruceui/SpruceTextures.java @@ -16,7 +16,7 @@ * Contains the identifiers of various useful textures. * * @author LambdAurora - * @version 5.1.0 + * @version 6.0.0 * @since 5.1.0 */ public final class SpruceTextures { @@ -32,18 +32,21 @@ private SpruceTextures() { /** * The dirt background texture used in pre-1.20.5 versions. */ - public static final Identifier LEGACY_OPTIONS_BACKGROUND = Identifier.of("spruceui", "textures/gui/legacy_options_background.png"); + public static final Identifier LEGACY_OPTIONS_BACKGROUND = SpruceUI.id("textures/gui/legacy_options_background.png"); /* Border */ + public static final Identifier SIMPLE_BORDER_SPRITE = SpruceUI.id("border/simple"); + public static final Identifier SIMPLE_HIGHLIGHTED_BORDER_SPRITE = SpruceUI.id("border/simple_highlighted"); + public static final Identifier MENU_TOP_BORDER = Screen.HEADER_SEPARATOR; public static final Identifier INWORLD_MENU_TOP_BORDER = Screen.INWORLD_HEADER_SEPARATOR; - public static final Identifier MENU_TOP_RIGHT_BORDER = Identifier.of("spruceui", "textures/gui/top_right_border_separator.png"); - public static final Identifier INWORLD_MENU_TOP_RIGHT_BORDER = Identifier.of("spruceui", "textures/gui/inworld_top_right_border_separator.png"); - public static final Identifier MENU_RIGHT_BORDER = Identifier.of("spruceui", "textures/gui/right_border_separator.png"); - public static final Identifier INWORLD_MENU_RIGHT_BORDER = Identifier.of("spruceui", "textures/gui/inworld_right_border_separator.png"); - public static final Identifier MENU_BOTTOM_RIGHT_BORDER = Identifier.of("spruceui", "textures/gui/bottom_right_border_separator.png"); - public static final Identifier INWORLD_MENU_BOTTOM_RIGHT_BORDER = Identifier.of("spruceui", "textures/gui/inworld_bottom_right_border_separator.png"); + public static final Identifier MENU_TOP_RIGHT_BORDER = SpruceUI.id("textures/gui/top_right_border_separator.png"); + public static final Identifier INWORLD_MENU_TOP_RIGHT_BORDER = SpruceUI.id("textures/gui/inworld_top_right_border_separator.png"); + public static final Identifier MENU_RIGHT_BORDER = SpruceUI.id("textures/gui/right_border_separator.png"); + public static final Identifier INWORLD_MENU_RIGHT_BORDER = SpruceUI.id("textures/gui/inworld_right_border_separator.png"); + public static final Identifier MENU_BOTTOM_RIGHT_BORDER = SpruceUI.id("textures/gui/bottom_right_border_separator.png"); + public static final Identifier INWORLD_MENU_BOTTOM_RIGHT_BORDER = SpruceUI.id("textures/gui/inworld_bottom_right_border_separator.png"); public static final Identifier MENU_BOTTOM_BORDER = Screen.FOOTER_SEPARATOR; public static final Identifier INWORLD_MENU_BOTTOM_BORDER = Screen.INWORLD_FOOTER_SEPARATOR; } diff --git a/src/main/java/dev/lambdaurora/spruceui/SpruceUI.java b/src/main/java/dev/lambdaurora/spruceui/SpruceUI.java new file mode 100644 index 00000000..d4512c56 --- /dev/null +++ b/src/main/java/dev/lambdaurora/spruceui/SpruceUI.java @@ -0,0 +1,39 @@ +/* + * Copyright © 2024 LambdAurora + * + * This file is part of SpruceUI. + * + * Licensed under the MIT license. For more information, + * see the LICENSE file. + */ + +package dev.lambdaurora.spruceui; + +import net.minecraft.resources.Identifier; + +/** + * Contains common constants from SpruceUI. + * + * @author LambdAurora + * @version 6.0.0 + * @since 6.0.0 + */ +public final class SpruceUI { + /** + * The namespace of SpruceUI, whose value is {@value}. + */ + public static final String NAMESPACE = "spruceui"; + + /** + * {@return a SpruceUI identifier from the given path} + * + * @param path the path + */ + public static Identifier id(String path) { + return Identifier.of(NAMESPACE, path); + } + + private SpruceUI() { + throw new UnsupportedOperationException("SpruceUi only contains static definitions."); + } +} diff --git a/src/main/java/dev/lambdaurora/spruceui/background/MenuBackground.java b/src/main/java/dev/lambdaurora/spruceui/background/MenuBackground.java index ee0fe1a5..c914b970 100644 --- a/src/main/java/dev/lambdaurora/spruceui/background/MenuBackground.java +++ b/src/main/java/dev/lambdaurora/spruceui/background/MenuBackground.java @@ -9,12 +9,12 @@ package dev.lambdaurora.spruceui.background; -import com.mojang.blaze3d.systems.RenderSystem; import dev.lambdaurora.spruceui.SpruceTextures; import dev.lambdaurora.spruceui.widget.SpruceWidget; import dev.lambdaurora.spruceui.widget.WithBorder; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.RenderType; import net.minecraft.resources.Identifier; /** @@ -23,7 +23,7 @@ * @param texture the texture used for the background * @param inWorldTexture the textured used for the background when playing in a world * @author LambdAurora - * @version 5.1.0 + * @version 6.0.0 * @since 5.1.0 */ public record MenuBackground(Identifier texture, Identifier inWorldTexture) implements Background { @@ -38,8 +38,6 @@ public record MenuBackground(Identifier texture, Identifier inWorldTexture) impl public void render(GuiGraphics graphics, SpruceWidget widget, int vOffset, int mouseX, int mouseY, float delta) { int x = widget.getX(); int y = widget.getY(); - int endX = widget.getEndX(); - int endY = widget.getEndY(); int width = widget.getWidth(); int height = widget.getHeight(); @@ -48,22 +46,18 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int vOffset, int m x += border.getLeft(); y += border.getTop(); - endX -= border.getRight(); - endY -= border.getBottom(); width -= border.getLeft() + border.getRight(); height -= border.getTop() + border.getBottom(); } - RenderSystem.enableBlend(); Identifier identifier = CLIENT.level == null ? this.inWorldTexture : this.texture; graphics.drawTexture( - identifier, + RenderType::guiTextured, identifier, x, y, - endX, endY, + 0, 0, width, height, - 32, 32 + 16, 16 ); - RenderSystem.disableBlend(); } } diff --git a/src/main/java/dev/lambdaurora/spruceui/border/MenuBorder.java b/src/main/java/dev/lambdaurora/spruceui/border/MenuBorder.java index 189482f4..483de69a 100644 --- a/src/main/java/dev/lambdaurora/spruceui/border/MenuBorder.java +++ b/src/main/java/dev/lambdaurora/spruceui/border/MenuBorder.java @@ -14,6 +14,7 @@ import dev.lambdaurora.spruceui.widget.SpruceWidget; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.RenderType; import net.minecraft.resources.Identifier; /** @@ -47,15 +48,25 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mo width -= THICKNESS; } - graphics.drawTexture(topTexture, - widget.getX(), widget.getY(), 0, 0, width, THICKNESS, 32, THICKNESS + graphics.drawTexture( + RenderType::guiTextured, + topTexture, + widget.getX(), widget.getY(), + 0, 0, + width, THICKNESS, + 32, THICKNESS ); } if (this.top && this.right) { Identifier cornerTexture = CLIENT.level == null ? SpruceTextures.MENU_TOP_RIGHT_BORDER : SpruceTextures.INWORLD_MENU_TOP_RIGHT_BORDER; - graphics.drawTexture(cornerTexture, - widget.getEndX() - THICKNESS, widget.getY(), 0, 0, THICKNESS, THICKNESS, THICKNESS, THICKNESS + graphics.drawTexture( + RenderType::guiTextured, + cornerTexture, + widget.getEndX() - THICKNESS, widget.getY(), + 0, 0, + THICKNESS, THICKNESS, + THICKNESS, THICKNESS ); } @@ -74,16 +85,25 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mo height -= THICKNESS; } - graphics.drawTexture(rightTexture, - widget.getEndX() - THICKNESS, y, 0, 0, THICKNESS, height, THICKNESS, 32 + graphics.drawTexture( + RenderType::guiTextured, rightTexture, + widget.getEndX() - THICKNESS, y, + 0, 0, + THICKNESS, height, + THICKNESS, 32 ); } if (this.bottom && this.right) { Identifier cornerTexture = CLIENT.level == null ? SpruceTextures.MENU_BOTTOM_RIGHT_BORDER : SpruceTextures.INWORLD_MENU_BOTTOM_RIGHT_BORDER; - graphics.drawTexture(cornerTexture, - widget.getEndX() - THICKNESS, widget.getEndY() - THICKNESS, 0, 0, THICKNESS, THICKNESS, THICKNESS, THICKNESS + graphics.drawTexture( + RenderType::guiTextured, + cornerTexture, + widget.getEndX() - THICKNESS, widget.getEndY() - THICKNESS, + 0, 0, + THICKNESS, THICKNESS, + THICKNESS, THICKNESS ); } @@ -96,8 +116,13 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mo width -= THICKNESS; } - graphics.drawTexture(bottomTexture, - widget.getX(), widget.getEndY() - THICKNESS, 0, 0, width, THICKNESS, 32, THICKNESS + graphics.drawTexture( + RenderType::guiTextured, + bottomTexture, + widget.getX(), widget.getEndY() - THICKNESS, + 0, 0, + width, THICKNESS, + 32, THICKNESS ); } diff --git a/src/main/java/dev/lambdaurora/spruceui/border/SimpleBorder.java b/src/main/java/dev/lambdaurora/spruceui/border/SimpleBorder.java index 321e5fcf..f0d39320 100644 --- a/src/main/java/dev/lambdaurora/spruceui/border/SimpleBorder.java +++ b/src/main/java/dev/lambdaurora/spruceui/border/SimpleBorder.java @@ -9,28 +9,23 @@ package dev.lambdaurora.spruceui.border; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.*; import dev.lambdaurora.spruceui.util.ColorUtil; import dev.lambdaurora.spruceui.widget.SpruceWidget; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.renderer.GameRenderer; - -import java.util.Arrays; /** * Represents a simple solid border to draw around a widget. * * @author LambdAurora - * @version 5.0.0 - * @since 2.0.0 + * @version 6.0.0 + * @since 6.0.0 */ public final class SimpleBorder implements Border { public static final SimpleBorder SIMPLE_BORDER = new SimpleBorder(1, 192, 192, 192, 255); private final int thickness; - private final int[] color; - private final int[] focusedColor; + private final int color; + private final int focusedColor; public SimpleBorder(int thickness, int color) { this(thickness, color, color); @@ -38,8 +33,8 @@ public SimpleBorder(int thickness, int color) { public SimpleBorder(int thickness, int color, int focusedColor) { this.thickness = thickness; - this.color = ColorUtil.unpackARGBColor(color); - this.focusedColor = ColorUtil.unpackARGBColor(focusedColor); + this.color = color; + this.focusedColor = color; } public SimpleBorder(int thickness, int red, int green, int blue, int alpha) { @@ -48,50 +43,25 @@ public SimpleBorder(int thickness, int red, int green, int blue, int alpha) { public SimpleBorder(int thickness, int red, int green, int blue, int alpha, int focusedRed, int focusedGreen, int focusedBlue, int focusedAlpha) { this.thickness = thickness; - this.color = new int[]{red, green, blue, alpha}; - this.focusedColor = new int[]{focusedRed, focusedGreen, focusedBlue, focusedAlpha}; + this.color = ColorUtil.packARGBColor(red, green, blue, alpha); + this.focusedColor = ColorUtil.packARGBColor(focusedRed, focusedGreen, focusedBlue, focusedAlpha); } @Override public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mouseY, float delta) { - var tessellator = Tessellator.getInstance(); - var buffer = tessellator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - RenderSystem.setShader(GameRenderer::getPositionColorShader); int x = widget.getX(); int y = widget.getY(); int right = x + widget.getWidth(); int bottom = y + widget.getHeight(); - boolean focused = widget.isFocused(); + int color = widget.isFocused() ? this.focusedColor : this.color; // Top border - this.vertex(buffer, x, y + this.thickness, focused); - this.vertex(buffer, right, y + this.thickness, focused); - this.vertex(buffer, right, y, focused); - this.vertex(buffer, x, y, focused); + graphics.fill(x, y, right, y + this.thickness, color); // Right border - this.vertex(buffer, right - this.thickness, bottom, focused); - this.vertex(buffer, right, bottom, focused); - this.vertex(buffer, right, y, focused); - this.vertex(buffer, right - this.thickness, y, focused); + graphics.fill(right - this.thickness, y, right, bottom, color); // Bottom - this.vertex(buffer, x, bottom, focused); - this.vertex(buffer, right, bottom, focused); - this.vertex(buffer, right, bottom - this.thickness, focused); - this.vertex(buffer, x, bottom - this.thickness, focused); + graphics.fill(x, bottom, right, bottom - this.thickness, color); // Left border - this.vertex(buffer, x, bottom, focused); - this.vertex(buffer, x + this.thickness, bottom, focused); - this.vertex(buffer, x + this.thickness, y, focused); - this.vertex(buffer, x, y, focused); - MeshData builtBuffer = buffer.build(); - if (builtBuffer != null) { - BufferUploader.drawWithShader(builtBuffer); - } - tessellator.clear(); - } - - private void vertex(BufferBuilder buffer, int x, int y, boolean focused) { - int[] color = focused ? this.focusedColor : this.color; - buffer.addVertex(x, y, 0).color(color[0], color[1], color[2], color[3]); + graphics.fill(x, y, x + this.thickness, bottom, color); } @Override @@ -103,8 +73,8 @@ public int getThickness() { public String toString() { return "SimpleBorder{" + "thickness=" + this.thickness + - ", color=" + Arrays.toString(this.color) + - ", focusedColor=" + Arrays.toString(this.focusedColor) + + ", color=" + Integer.toHexString(this.color) + + ", focusedColor=" + Integer.toHexString(this.focusedColor) + '}'; } } diff --git a/src/main/java/dev/lambdaurora/spruceui/border/TexturedBorder.java b/src/main/java/dev/lambdaurora/spruceui/border/TexturedBorder.java new file mode 100644 index 00000000..08c2c4a2 --- /dev/null +++ b/src/main/java/dev/lambdaurora/spruceui/border/TexturedBorder.java @@ -0,0 +1,44 @@ +/* + * Copyright © 2024 LambdAurora + * + * This file is part of SpruceUI. + * + * Licensed under the MIT license. For more information, + * see the LICENSE file. + */ + +package dev.lambdaurora.spruceui.border; + +import dev.lambdaurora.spruceui.SpruceTextures; +import dev.lambdaurora.spruceui.widget.SpruceWidget; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.WidgetSprites; +import net.minecraft.client.renderer.RenderType; + +/** + * Represents a textured border to draw around a widget. + * + * @author LambdAurora + * @version 6.0.0 + * @since 6.0.0 + */ +public record TexturedBorder(WidgetSprites sprites) implements Border { + public static final TexturedBorder SIMPLE = new TexturedBorder(new WidgetSprites( + SpruceTextures.SIMPLE_BORDER_SPRITE, + SpruceTextures.SIMPLE_HIGHLIGHTED_BORDER_SPRITE + )); + + @Override + public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mouseY, float delta) { + graphics.drawSprite( + RenderType::guiTextured, this.sprites.get(widget.isActive(), widget.isFocusedOrHovered()), + widget.getX(), widget.getY(), + widget.getWidth(), widget.getHeight() + ); + } + + @Override + public int getThickness() { + return 1; + } +} diff --git a/src/main/java/dev/lambdaurora/spruceui/screen/SpruceHandledScreen.java b/src/main/java/dev/lambdaurora/spruceui/screen/SpruceHandledScreen.java index 41e98d4c..13151cfc 100644 --- a/src/main/java/dev/lambdaurora/spruceui/screen/SpruceHandledScreen.java +++ b/src/main/java/dev/lambdaurora/spruceui/screen/SpruceHandledScreen.java @@ -12,7 +12,6 @@ import dev.lambdaurora.spruceui.SprucePositioned; import dev.lambdaurora.spruceui.Tooltip; import dev.lambdaurora.spruceui.navigation.NavigationDirection; -import dev.lambdaurora.spruceui.util.ScissorManager; import dev.lambdaurora.spruceui.widget.SpruceElement; import dev.lambdaurora.spruceui.widget.SpruceWidget; import net.minecraft.client.gui.GuiGraphics; @@ -37,8 +36,6 @@ * @since 3.3.0 */ public abstract class SpruceHandledScreen extends AbstractContainerScreen implements SprucePositioned, SpruceElement { - protected double scaleFactor; - public SpruceHandledScreen(T handler, Inventory inventory, Text title) { super(handler, inventory, title); } @@ -54,11 +51,6 @@ public void setFocused(GuiEventListener focused) { ((SpruceWidget) focused).setFocused(true); } - @Override - protected void init() { - this.scaleFactor = this.client.getWindow().getGuiScale(); - } - /* Input */ @Override @@ -115,12 +107,10 @@ private boolean tryNavigating(GuiEventListener element, NavigationDirection dire @Override public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - ScissorManager.pushScaleFactor(this.scaleFactor); super.render(graphics, mouseX, mouseY, delta); this.renderWidgets(graphics, mouseX, mouseY, delta); this.renderTitle(graphics, mouseX, mouseY, delta); Tooltip.renderAll(graphics); - ScissorManager.popScaleFactor(); } public void renderTitle(GuiGraphics graphics, int mouseX, int mouseY, float delta) { diff --git a/src/main/java/dev/lambdaurora/spruceui/screen/SpruceScreen.java b/src/main/java/dev/lambdaurora/spruceui/screen/SpruceScreen.java index d97ddd9f..312834bf 100644 --- a/src/main/java/dev/lambdaurora/spruceui/screen/SpruceScreen.java +++ b/src/main/java/dev/lambdaurora/spruceui/screen/SpruceScreen.java @@ -12,7 +12,6 @@ import dev.lambdaurora.spruceui.SprucePositioned; import dev.lambdaurora.spruceui.Tooltip; import dev.lambdaurora.spruceui.navigation.NavigationDirection; -import dev.lambdaurora.spruceui.util.ScissorManager; import dev.lambdaurora.spruceui.widget.SpruceElement; import dev.lambdaurora.spruceui.widget.SpruceWidget; import net.minecraft.client.gui.GuiGraphics; @@ -33,8 +32,6 @@ * @since 2.0.0 */ public abstract class SpruceScreen extends Screen implements SprucePositioned, SpruceElement { - protected double scaleFactor; - protected SpruceScreen(Text title) { super(title); } @@ -50,11 +47,6 @@ public void setFocused(GuiEventListener focused) { focused.setFocused(true); } - @Override - protected void init() { - this.scaleFactor = this.client.getWindow().getGuiScale(); - } - /* Input */ @Override @@ -110,12 +102,10 @@ private boolean tryNavigating(GuiEventListener element, NavigationDirection dire @Override public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - ScissorManager.pushScaleFactor(this.scaleFactor); this.renderBackground(graphics, mouseX, mouseY, delta); this.renderWidgets(graphics, mouseX, mouseY, delta); this.renderTitle(graphics, mouseX, mouseY, delta); Tooltip.renderAll(graphics); - ScissorManager.popScaleFactor(); } public void renderTitle(GuiGraphics graphics, int mouseX, int mouseY, float delta) { diff --git a/src/main/java/dev/lambdaurora/spruceui/util/RenderUtil.java b/src/main/java/dev/lambdaurora/spruceui/util/RenderUtil.java index 77489652..a9a54254 100644 --- a/src/main/java/dev/lambdaurora/spruceui/util/RenderUtil.java +++ b/src/main/java/dev/lambdaurora/spruceui/util/RenderUtil.java @@ -12,7 +12,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; import dev.lambdaurora.spruceui.SpruceTextures; -import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.CoreShaders; public final class RenderUtil { private RenderUtil() { @@ -50,7 +50,7 @@ public static void renderBackgroundTexture(int x, int y, int width, int height, int red, int green, int blue, int alpha) { var tessellator = Tessellator.getInstance(); var bufferBuilder = tessellator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - RenderSystem.setShader(GameRenderer::getPositionTexColorShader); + RenderSystem.setShader(CoreShaders.POSITION_TEX_COLOR); RenderSystem.setShaderColor(1.f, 1.f, 1.f, 1.f); RenderSystem.setShaderTexture(0, SpruceTextures.LEGACY_OPTIONS_BACKGROUND); @@ -75,45 +75,4 @@ public static void renderBackgroundTexture(int x, int y, int width, int height, } tessellator.clear(); } - - /** - * Renders a selection box as background. - * - * @param x the X-coordinate of the selection box - * @param y the Y-coordinate of the selection box - * @param width the width of the selection box - * @param height the height of the selection box - * @param red the red-component color value of the outer border - * @param green the green-component color value of the outer border - * @param blue the blue-component color value of the outer border - * @param alpha the alpha-component color value of the outer border - */ - public static void renderSelectionBox(int x, int y, int width, int height, int red, int green, int blue, int alpha) { - var tessellator = Tessellator.getInstance(); - var bufferBuilder = tessellator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION); - - int top = y + height; - int right = x + width; - - RenderSystem.setShader(GameRenderer::getPositionColorShader); - RenderSystem.setShaderColor(red / 255.f, green / 255.f, blue / 255.f, alpha / 255.f); - bufferBuilder.addVertex(x, top, 0); - bufferBuilder.addVertex(right, top, 0); - bufferBuilder.addVertex(right, y, 0); - bufferBuilder.addVertex(x, y, 0); - MeshData builtBuffer = bufferBuilder.build(); - if (builtBuffer != null) { - BufferUploader.drawWithShader(builtBuffer); - } - RenderSystem.setShaderColor(0, 0, 0, 1.f); - bufferBuilder.addVertex(x + 1, top - 1, 0); - bufferBuilder.addVertex(right - 1, top - 1, 0); - bufferBuilder.addVertex(right - 1, y + 1, 0); - bufferBuilder.addVertex(x + 1, y + 1, 0); - builtBuffer = bufferBuilder.build(); - if (builtBuffer != null) { - BufferUploader.drawWithShader(builtBuffer); - } - tessellator.clear(); - } } diff --git a/src/main/java/dev/lambdaurora/spruceui/util/ScissorManager.java b/src/main/java/dev/lambdaurora/spruceui/util/ScissorManager.java deleted file mode 100644 index 9a6c53b1..00000000 --- a/src/main/java/dev/lambdaurora/spruceui/util/ScissorManager.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright © 2020 LambdAurora - * - * This file is part of SpruceUI. - * - * Licensed under the MIT license. For more information, - * see the LICENSE file. - */ - -package dev.lambdaurora.spruceui.util; - -import com.mojang.blaze3d.systems.RenderSystem; -import it.unimi.dsi.fastutil.doubles.DoubleArrayList; -import it.unimi.dsi.fastutil.doubles.DoubleList; -import net.minecraft.client.Minecraft; - -import java.util.ArrayDeque; -import java.util.Deque; - -/** - * Represents a manager for {@link RenderSystem#enableScissor(int, int, int, int)}. - * - * @author LambdAurora - * @version 3.2.1 - * @since 2.0.0 - */ -public final class ScissorManager { - private static final Deque SCISSOR_STACK = new ArrayDeque<>(); - private static final DoubleList SCALE_FACTOR_STACK = new DoubleArrayList(); - - private ScissorManager() { - throw new UnsupportedOperationException("ScissorManager only contains static definitions."); - } - - public static void pushScaleFactor(double scaleFactor) { - SCALE_FACTOR_STACK.add(scaleFactor); - } - - public static void pushScaleFactorMultiplier(double scaleFactor) { - pushScaleFactor(scaleFactor * getCurrentScaleFactor()); - } - - public static void popScaleFactor() { - if (SCALE_FACTOR_STACK.size() == 0) - return; - SCALE_FACTOR_STACK.removeDouble(SCALE_FACTOR_STACK.size() - 1); - } - - public static double getCurrentScaleFactor() { - if (SCALE_FACTOR_STACK.size() == 0) - return 1.f; - return SCALE_FACTOR_STACK.getDouble(SCALE_FACTOR_STACK.size() - 1); - } - - public static void push(int x, int y, int width, int height, double scaleFactor) { - pushScaleFactor(scaleFactor); - push(x, y, width, height); - } - - /** - * Pushes a new scissor state. - * - * @param x the X coordinate of the drawable area - * @param y the Y coordinate of the drawable area - * @param width the width of the drawable area - * @param height the height of the drawable area - */ - public static void push(int x, int y, int width, int height) { - double scaleFactor = getCurrentScaleFactor(); - var handle = new ScissorHandle((int) (scaleFactor * x), adaptY(y, height, scaleFactor), - (int) (scaleFactor * width), (int) (scaleFactor * height)); - handle.apply(); - SCISSOR_STACK.push(handle); - } - - /** - * Pops the last pushed scissor state. - */ - public static void pop() { - SCISSOR_STACK.pop(); - if (SCISSOR_STACK.isEmpty()) { - RenderSystem.disableScissor(); - } else { - SCISSOR_STACK.getFirst().apply(); - } - } - - private static int adaptY(int y, int height, double scaleFactor) { - var window = Minecraft.getInstance().getWindow(); - int tmpHeight = (int) (window.getHeight() / scaleFactor); - int scaledHeight = window.getHeight() / scaleFactor > (double) tmpHeight ? tmpHeight + 1 : tmpHeight; - return (int) (scaleFactor * (scaledHeight - height - y)); - } - - record ScissorHandle(int x, int y, int width, int height) { - void apply() { - RenderSystem.enableScissor(this.x(), this.y(), this.width(), this.height()); - } - } -} diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceButtonWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceButtonWidget.java index b1c73373..332d4a64 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceButtonWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/AbstractSpruceButtonWidget.java @@ -9,7 +9,6 @@ package dev.lambdaurora.spruceui.widget; -import com.mojang.blaze3d.systems.RenderSystem; import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.Tooltip; import dev.lambdaurora.spruceui.Tooltipable; @@ -18,6 +17,7 @@ import net.minecraft.client.gui.components.WidgetSprites; import net.minecraft.client.gui.narration.NarratedElementType; import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.Text; import net.minecraft.resources.Identifier; import net.minecraft.util.math.MathHelper; @@ -30,7 +30,7 @@ * Represents a button-like widget. * * @author LambdAurora - * @version 5.0.0 + * @version 6.0.0 * @since 2.0.0 */ public abstract class AbstractSpruceButtonWidget extends AbstractSpruceWidget implements Tooltipable { @@ -44,7 +44,9 @@ public abstract class AbstractSpruceButtonWidget extends AbstractSpruceWidget im * @see net.minecraft.client.gui.components.AbstractButton#SPRITES */ protected static final WidgetSprites BUTTON_TEXTURES = new WidgetSprites( - Identifier.ofDefault("widget/button"), Identifier.ofDefault("widget/button_disabled"), Identifier.ofDefault("widget/button_highlighted") + Identifier.ofDefault("widget/button"), + Identifier.ofDefault("widget/button_disabled"), + Identifier.ofDefault("widget/button_highlighted") ); public AbstractSpruceButtonWidget(Position position, int width, int height, Text message) { @@ -159,11 +161,7 @@ protected void renderButton(GuiGraphics graphics, int mouseX, int mouseY, float @Override protected void renderBackground(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - RenderSystem.setShaderColor(1.f, 1.f, 1.f, this.getAlpha()); - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - RenderSystem.enableDepthTest(); - graphics.drawGuiTexture(this.getTexture(), this.getX(), this.getY(), this.getWidth(), this.getHeight()); + graphics.drawSprite(RenderType::guiTextured, this.getTexture(), this.getX(), this.getY(), this.getWidth(), this.getHeight()); } /* Narration */ diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceCheckboxWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceCheckboxWidget.java index 907ce2a6..d6028f74 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceCheckboxWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceCheckboxWidget.java @@ -9,10 +9,11 @@ package dev.lambdaurora.spruceui.widget; -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; import dev.lambdaurora.spruceui.Position; +import dev.lambdaurora.spruceui.SpruceUI; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.WidgetSprites; +import net.minecraft.client.renderer.RenderType; import net.minecraft.locale.Language; import net.minecraft.network.chat.Text; import net.minecraft.resources.Identifier; @@ -22,11 +23,16 @@ * Represents a checkbox widget. * * @author LambdAurora - * @version 5.0.0 + * @version 6.0.0 * @since 1.0.0 */ public class SpruceCheckboxWidget extends AbstractSpruceBooleanButtonWidget { - private static final Identifier TEXTURE = Identifier.of("spruceui", "textures/gui/checkbox.png"); + public static final WidgetSprites BACKGROUND_TEXTURE = new WidgetSprites( + Identifier.ofDefault("widget/checkbox"), + Identifier.ofDefault("widget/checkbox_highlighted") + ); + public static final Identifier CHECKED_TEXTURE = SpruceUI.id("widget/checkbox/checked"); + public static final Identifier CROSSED_TEXTURE = SpruceUI.id("widget/checkbox/crossed"); private boolean showCross = false; private boolean colored = false; @@ -86,25 +92,20 @@ public void setColored(boolean colored) { @Override protected void renderButton(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - RenderSystem.enableDepthTest(); - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); - float[] oldColor = RenderSystem.getShaderColor(); - float oldRed = oldColor[0], oldGreen = oldColor[1], oldBlue = oldColor[2], oldAlpha = oldColor[3]; - if (this.getValue()) { - if (this.colored) - RenderSystem.setShaderColor(0.f, 1.f, 0.f, this.alpha); - graphics.drawTexture(TEXTURE, this.getX(), this.getY(), 0.f, 40.f, this.getHeight(), this.getHeight(), 64, 64); + graphics.drawSprite( + RenderType::guiTextured, CHECKED_TEXTURE, + this.getX(), this.getY(), + this.getHeight(), this.getHeight(), + this.colored ? 0xff00ff00 : -1 + ); } else if (this.showCross) { - if (this.colored) - RenderSystem.setShaderColor(1.f, 0.f, 0.f, this.alpha); - graphics.drawTexture(TEXTURE, this.getX(), this.getY(), 0.f, 20.f, this.getHeight(), this.getHeight(), 64, 64); - } - - if (this.colored) { - RenderSystem.setShaderColor(oldRed, oldGreen, oldBlue, oldAlpha); + graphics.drawSprite( + RenderType::guiTextured, CROSSED_TEXTURE, + this.getX(), this.getY(), + this.getHeight(), this.getHeight(), + this.colored ? 0xffff0000 : -1 + ); } if (this.showMessage) { @@ -116,13 +117,11 @@ protected void renderButton(GuiGraphics graphics, int mouseX, int mouseY, float @Override protected void renderBackground(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - RenderSystem.enableDepthTest(); - RenderSystem.setShaderColor(1.f, 1.f, 1.f, this.alpha); - RenderSystem.setShaderTexture(0, TEXTURE); - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); - graphics.drawTexture(TEXTURE, this.getX(), this.getY(), this.isFocusedOrHovered() ? 20.f : 0.f, 0.f, this.getHeight(), this.getHeight(), 64, 64); + graphics.drawSprite( + RenderType::guiTextured, BACKGROUND_TEXTURE.get(this.isActive(), this.isFocusedOrHovered()), + this.getX(), this.getY(), + this.getHeight(), this.getHeight() + ); } /* Narration */ diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceSliderWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceSliderWidget.java index a900e90c..af3d3b2b 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceSliderWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceSliderWidget.java @@ -9,11 +9,11 @@ package dev.lambdaurora.spruceui.widget; -import com.mojang.blaze3d.systems.RenderSystem; import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.Tooltipable; import dev.lambdaurora.spruceui.navigation.NavigationDirection; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.Text; import net.minecraft.resources.Identifier; import net.minecraft.util.math.MathHelper; @@ -170,10 +170,13 @@ protected Identifier getTexture() { @Override protected void renderButton(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - RenderSystem.setShaderColor(1.f, 1.f, 1.f, 1.f); - final Identifier texture = this.isFocusedOrHovered() ? SLIDER_HANDLE_HIGHLIGHTED : SLIDER_HANDLE; - graphics.drawGuiTexture(texture, this.getX() + (int) (this.value * (double) (this.getWidth() - 8)), this.getY(), 8, 20); + graphics.drawSprite( + RenderType::guiTextured, + texture, + this.getX() + (int) (this.value * (double) (this.getWidth() - 8)), this.getY(), + 8, 20 + ); if (!this.isMouseHovered() && this.inUse) { this.inUse = false; diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceTexturedButtonWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceTexturedButtonWidget.java index f23b0c14..843df2b7 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceTexturedButtonWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceTexturedButtonWidget.java @@ -9,9 +9,9 @@ package dev.lambdaurora.spruceui.widget; -import com.mojang.blaze3d.systems.RenderSystem; import dev.lambdaurora.spruceui.Position; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.Text; import net.minecraft.resources.Identifier; @@ -73,10 +73,8 @@ protected void renderBackground(GuiGraphics graphics, int mouseX, int mouseY, fl v += this.hoveredVOffset; } - RenderSystem.setShaderColor(1.f, 1.f, 1.f, this.getAlpha()); - RenderSystem.setShaderTexture(0, this.texture); - RenderSystem.enableDepthTest(); - graphics.drawTexture(this.texture, + graphics.drawTexture( + RenderType::guiTextured, this.texture, this.getX(), this.getY(), this.u, v, this.getWidth(), this.getHeight(), diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceToggleSwitch.java b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceToggleSwitch.java index 70c951ae..bbd4025b 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/SpruceToggleSwitch.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/SpruceToggleSwitch.java @@ -9,14 +9,14 @@ package dev.lambdaurora.spruceui.widget; -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.SpruceTexts; +import dev.lambdaurora.spruceui.SpruceUI; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.WidgetSprites; +import net.minecraft.client.renderer.RenderType; import net.minecraft.locale.Language; import net.minecraft.network.chat.Text; -import net.minecraft.resources.Identifier; import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; @@ -24,11 +24,22 @@ * Represents a checkbox widget. * * @author LambdAurora - * @version 5.0.0 + * @version 6.0.0 * @since 1.0.0 */ public class SpruceToggleSwitch extends AbstractSpruceBooleanButtonWidget { - private static final Identifier TEXTURE = Identifier.of("spruceui", "textures/gui/toggle_switch.png"); + public static final WidgetSprites BACKGROUND_TEXTURE = new WidgetSprites( + SpruceUI.id("widget/toggle_switch/background"), + SpruceUI.id("widget/toggle_switch/background_highlighted") + ); + public static final WidgetSprites ON_TEXTURE = new WidgetSprites( + SpruceUI.id("widget/toggle_switch/on"), + SpruceUI.id("widget/toggle_switch/on_highlighted") + ); + public static final WidgetSprites OFF_TEXTURE = new WidgetSprites( + SpruceUI.id("widget/toggle_switch/off"), + SpruceUI.id("widget/toggle_switch/off_highlighted") + ); public SpruceToggleSwitch(Position position, int width, int height, Text message, boolean value) { super(position, width, height, message, value); @@ -53,13 +64,11 @@ public SpruceToggleSwitch(Position position, int width, int height, Text message @Override protected void renderButton(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - RenderSystem.enableDepthTest(); - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); - graphics.drawTexture(TEXTURE, this.getX() + (this.getValue() ? 14 : 0), this.getY() + (this.getHeight() / 2 - 9), - this.getValue() ? 50.f : 32.f, this.isFocusedOrHovered() ? 18.f : 0.f, - 18, 18, 68, 36); + graphics.drawSprite( + RenderType::guiTextured, (this.getValue() ? ON_TEXTURE : OFF_TEXTURE).get(this.isActive(), this.isFocusedOrHovered()), + this.getX() + (this.getValue() ? 14 : 0), this.getY() + (this.getHeight() / 2 - 9), + 18, 18 + ); if (this.showMessage) { var message = Language.getInstance().getVisualOrder( @@ -72,14 +81,11 @@ protected void renderButton(GuiGraphics graphics, int mouseX, int mouseY, float @Override protected void renderBackground(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - RenderSystem.enableDepthTest(); - RenderSystem.setShaderColor(1.f, 1.f, 1.f, this.alpha); - RenderSystem.setShaderTexture(0, TEXTURE); - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); - graphics.drawTexture(TEXTURE, this.getX(), this.getY() + (this.getHeight() / 2 - 9), - 0.f, this.isFocusedOrHovered() ? 18.f : 0.f, 32, 18, 68, 36); + graphics.drawSprite( + RenderType::guiTextured, BACKGROUND_TEXTURE.get(this.isActive(), this.isFocusedOrHovered()), + this.getX(), this.getY() + (this.getHeight() / 2 - 9), + 32, 18 + ); } /* Narration */ diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/container/SpruceEntryListWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/container/SpruceEntryListWidget.java index b70ceb45..dab6a1fa 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/container/SpruceEntryListWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/container/SpruceEntryListWidget.java @@ -19,7 +19,6 @@ import dev.lambdaurora.spruceui.border.Border; import dev.lambdaurora.spruceui.border.MenuBorder; import dev.lambdaurora.spruceui.navigation.NavigationDirection; -import dev.lambdaurora.spruceui.util.ScissorManager; import dev.lambdaurora.spruceui.widget.AbstractSpruceWidget; import dev.lambdaurora.spruceui.widget.SpruceWidgetWithBorder; import dev.lambdaurora.spruceui.widget.WithBackground; @@ -28,7 +27,7 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.narration.NarratedElementType; import net.minecraft.client.gui.narration.NarrationElementOutput; -import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.CoreShaders; import net.minecraft.network.chat.Text; import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; @@ -43,7 +42,7 @@ * * @param the type of entry * @author LambdAurora - * @version 5.1.0 + * @version 6.0.0 * @since 2.0.0 */ public abstract class SpruceEntryListWidget extends AbstractSpruceParentWidget @@ -333,12 +332,11 @@ protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float int right = this.getEndInnerBorderedX(); int top = this.getInnerBorderedY(); int bottom = this.getEndInnerBorderedY(); - int width = this.getInnerBorderedWidth(); int height = this.getInnerBorderedHeight(); - ScissorManager.push(left, top, width, height); + graphics.enableScissor(left, top, right, bottom); this.entries.forEach(e -> e.render(graphics, mouseX, mouseY, delta)); - ScissorManager.pop(); + graphics.disableScissor(); RenderSystem.enableBlend(); var tessellator = Tessellator.getInstance(); @@ -349,7 +347,7 @@ protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE ); - RenderSystem.setShader(GameRenderer::getPositionColorShader); + RenderSystem.setShader(CoreShaders.POSITION_COLOR); // TOP buffer.addVertex(left, top + 4, 0).color(0, 0, 0, 0); buffer.addVertex(right, top + 4, 0).color(0, 0, 0, 0); @@ -403,7 +401,7 @@ protected void renderScrollbar( int y = this.getInnerBorderedY(); int endY = this.getEndInnerBorderedY(); - RenderSystem.setShader(GameRenderer::getPositionColorShader); + RenderSystem.setShader(CoreShaders.POSITION_COLOR); buffer.addVertex(scrollbarX, endY, 0.0f).color(0, 0, 0, 255); buffer.addVertex(scrollbarEndX, endY, 0.0f).color(0, 0, 0, 255); buffer.addVertex(scrollbarEndX, y, 0.0f).color(0, 0, 0, 255); diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/text/AbstractSpruceTextInputWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/text/AbstractSpruceTextInputWidget.java index 42602483..aa3dc8aa 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/text/AbstractSpruceTextInputWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/text/AbstractSpruceTextInputWidget.java @@ -13,7 +13,7 @@ import dev.lambdaurora.spruceui.background.Background; import dev.lambdaurora.spruceui.background.SimpleColorBackground; import dev.lambdaurora.spruceui.border.Border; -import dev.lambdaurora.spruceui.border.SimpleBorder; +import dev.lambdaurora.spruceui.border.TexturedBorder; import dev.lambdaurora.spruceui.util.ColorUtil; import dev.lambdaurora.spruceui.widget.AbstractSpruceWidget; import dev.lambdaurora.spruceui.widget.WithBackground; @@ -25,13 +25,13 @@ * Represents a text input widget. * * @author LambdAurora - * @version 5.0.0 + * @version 6.0.0 * @since 2.1.0 */ public abstract class AbstractSpruceTextInputWidget extends AbstractSpruceWidget implements WithBackground, WithBorder { private final Text title; private Background background = new SimpleColorBackground(ColorUtil.BLACK); - private Border border = new SimpleBorder(1, -6250336, ColorUtil.WHITE); + private Border border = TexturedBorder.SIMPLE; private int editableColor = ColorUtil.TEXT_COLOR; private int uneditableColor = ColorUtil.UNEDITABLE_COLOR; diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextAreaWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextAreaWidget.java index 042ec65f..9986a524 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextAreaWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextAreaWidget.java @@ -9,9 +9,6 @@ package dev.lambdaurora.spruceui.widget.text; -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.*; import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.border.Border; import dev.lambdaurora.spruceui.navigation.NavigationDirection; @@ -20,7 +17,7 @@ import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.Text; import net.minecraft.util.StringUtil; import net.minecraft.util.math.MathHelper; @@ -34,7 +31,7 @@ * Represents a text area widget. * * @author LambdAurora - * @version 5.0.0 + * @version 6.0.0 * @since 1.6.3 */ public class SpruceTextAreaWidget extends AbstractSpruceTextInputWidget { @@ -502,23 +499,7 @@ protected void drawSelection(GuiGraphics graphics, String line, int lineY, int r int x2 = x + this.font.width(selected); int y2 = lineY + this.font.lineHeight; - var tessellator = Tessellator.getInstance(); - var buffer = tessellator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION); - RenderSystem.enableColorLogicOp(); - RenderSystem.logicOp(GlStateManager.LogicOp.OR_REVERSE); - RenderSystem.setShader(GameRenderer::getPositionShader); - RenderSystem.setShaderColor(0.0f, 0.0f, 1.0f, 1.0f); - buffer.addVertex(x, y2, 0.f); - buffer.addVertex(x2, y2, 0.f); - buffer.addVertex(x2, lineY, 0.f); - buffer.addVertex(x, lineY, 0.f); - MeshData builtBuffer = buffer.build(); - if (builtBuffer != null) { - BufferUploader.drawWithShader(builtBuffer); - } - tessellator.clear(); - RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); - RenderSystem.disableColorLogicOp(); + graphics.fill(RenderType.guiTextHighlight(), x, lineY, x2, y2, 0xff0000ff); } /** diff --git a/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextFieldWidget.java b/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextFieldWidget.java index 34926647..308448bb 100644 --- a/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextFieldWidget.java +++ b/src/main/java/dev/lambdaurora/spruceui/widget/text/SpruceTextFieldWidget.java @@ -9,9 +9,6 @@ package dev.lambdaurora.spruceui.widget.text; -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.*; import dev.lambdaurora.spruceui.Position; import dev.lambdaurora.spruceui.Tooltip; import dev.lambdaurora.spruceui.Tooltipable; @@ -22,7 +19,7 @@ import net.minecraft.client.gui.narration.NarratedElementType; import net.minecraft.client.gui.narration.NarrationElementOutput; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.Style; import net.minecraft.network.chat.Text; import net.minecraft.util.FormattedCharSequence; @@ -41,7 +38,7 @@ * Represents a text field widget. * * @author LambdAurora - * @version 5.0.0 + * @version 6.0.0 * @since 2.1.0 */ public class SpruceTextFieldWidget extends AbstractSpruceTextInputWidget implements Tooltipable { @@ -439,16 +436,17 @@ protected void drawText(GuiGraphics graphics) { graphics.drawShadowedText(this.client.font, this.renderTextProvider.apply(displayedText, this.firstCharacterIndex), x, y, textColor); - this.drawSelection(displayedText, y); + this.drawSelection(graphics, displayedText, y); } /** * Draws the selection over the text. * + * @param graphics the GUI graphics instance to render with * @param line the current line * @param lineY the line Y-coordinates */ - protected void drawSelection(String line, int lineY) { + protected void drawSelection(GuiGraphics graphics, String line, int lineY) { if (!this.isFocused() || !this.selection.active) return; @@ -464,22 +462,7 @@ protected void drawSelection(String line, int lineY) { int x2 = x + this.client.font.width(selected); int y2 = lineY + this.client.font.lineHeight; - var tessellator = Tessellator.getInstance(); - var buffer = tessellator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION); - RenderSystem.enableColorLogicOp(); - RenderSystem.logicOp(GlStateManager.LogicOp.OR_REVERSE); - RenderSystem.setShader(GameRenderer::getPositionShader); - RenderSystem.setShaderColor(0.f, 0.f, 255.f, 255.f); - buffer.addVertex(x, y2, 0.f); - buffer.addVertex(x2, y2, 0.f); - buffer.addVertex(x2, lineY, 0.f); - buffer.addVertex(x, lineY, 0.f); - MeshData builtBuffer = buffer.build(); - if (builtBuffer != null) { - BufferUploader.drawWithShader(builtBuffer); - } - tessellator.clear(); - RenderSystem.disableColorLogicOp(); + graphics.fill(RenderType.guiTextHighlight(), x, lineY, x2, y2, 0xff0000ff); } /** diff --git a/src/main/resources/assets/spruceui/textures/gui/checkbox.png b/src/main/resources/assets/spruceui/textures/gui/checkbox.png deleted file mode 100644 index 2e46259e..00000000 Binary files a/src/main/resources/assets/spruceui/textures/gui/checkbox.png and /dev/null differ diff --git a/src/main/resources/assets/spruceui/textures/gui/sprites/border/simple.png b/src/main/resources/assets/spruceui/textures/gui/sprites/border/simple.png new file mode 100644 index 00000000..8db605e2 Binary files /dev/null and b/src/main/resources/assets/spruceui/textures/gui/sprites/border/simple.png differ diff --git a/src/main/resources/assets/spruceui/textures/gui/sprites/border/simple.png.mcmeta b/src/main/resources/assets/spruceui/textures/gui/sprites/border/simple.png.mcmeta new file mode 100644 index 00000000..6e42b433 --- /dev/null +++ b/src/main/resources/assets/spruceui/textures/gui/sprites/border/simple.png.mcmeta @@ -0,0 +1,10 @@ +{ + "gui": { + "scaling": { + "type": "nine_slice", + "width": 200, + "height": 20, + "border": 1 + } + } +} diff --git a/src/main/resources/assets/spruceui/textures/gui/sprites/border/simple_highlighted.png b/src/main/resources/assets/spruceui/textures/gui/sprites/border/simple_highlighted.png new file mode 100644 index 00000000..9a617a71 Binary files /dev/null and b/src/main/resources/assets/spruceui/textures/gui/sprites/border/simple_highlighted.png differ diff --git a/src/main/resources/assets/spruceui/textures/gui/sprites/border/simple_highlighted.png.mcmeta b/src/main/resources/assets/spruceui/textures/gui/sprites/border/simple_highlighted.png.mcmeta new file mode 100644 index 00000000..6e42b433 --- /dev/null +++ b/src/main/resources/assets/spruceui/textures/gui/sprites/border/simple_highlighted.png.mcmeta @@ -0,0 +1,10 @@ +{ + "gui": { + "scaling": { + "type": "nine_slice", + "width": 200, + "height": 20, + "border": 1 + } + } +} diff --git a/src/main/resources/assets/spruceui/textures/gui/sprites/widget/checkbox/checked.png b/src/main/resources/assets/spruceui/textures/gui/sprites/widget/checkbox/checked.png new file mode 100644 index 00000000..f26344b4 Binary files /dev/null and b/src/main/resources/assets/spruceui/textures/gui/sprites/widget/checkbox/checked.png differ diff --git a/src/main/resources/assets/spruceui/textures/gui/sprites/widget/checkbox/crossed.png b/src/main/resources/assets/spruceui/textures/gui/sprites/widget/checkbox/crossed.png new file mode 100644 index 00000000..8ade8714 Binary files /dev/null and b/src/main/resources/assets/spruceui/textures/gui/sprites/widget/checkbox/crossed.png differ diff --git a/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/background.png b/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/background.png new file mode 100644 index 00000000..0613a54b Binary files /dev/null and b/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/background.png differ diff --git a/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/background_highlighted.png b/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/background_highlighted.png new file mode 100644 index 00000000..8e3249c6 Binary files /dev/null and b/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/background_highlighted.png differ diff --git a/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/off.png b/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/off.png new file mode 100644 index 00000000..9653a471 Binary files /dev/null and b/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/off.png differ diff --git a/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/off_highlighted.png b/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/off_highlighted.png new file mode 100644 index 00000000..237b89e9 Binary files /dev/null and b/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/off_highlighted.png differ diff --git a/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/on.png b/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/on.png new file mode 100644 index 00000000..d539ed96 Binary files /dev/null and b/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/on.png differ diff --git a/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/on_highlighted.png b/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/on_highlighted.png new file mode 100644 index 00000000..1bb86e13 Binary files /dev/null and b/src/main/resources/assets/spruceui/textures/gui/sprites/widget/toggle_switch/on_highlighted.png differ diff --git a/src/main/resources/assets/spruceui/textures/gui/toggle_switch.png b/src/main/resources/assets/spruceui/textures/gui/toggle_switch.png deleted file mode 100644 index 500332b3..00000000 Binary files a/src/main/resources/assets/spruceui/textures/gui/toggle_switch.png and /dev/null differ diff --git a/src/main/resources/high_contrast/assets/spruceui/textures/gui/checkbox.png b/src/main/resources/high_contrast/assets/spruceui/textures/gui/checkbox.png deleted file mode 100644 index 663d82ee..00000000 Binary files a/src/main/resources/high_contrast/assets/spruceui/textures/gui/checkbox.png and /dev/null differ diff --git a/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/background.png b/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/background.png new file mode 100644 index 00000000..dfa151a6 Binary files /dev/null and b/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/background.png differ diff --git a/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/background_highlighted.png b/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/background_highlighted.png new file mode 100644 index 00000000..dfa151a6 Binary files /dev/null and b/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/background_highlighted.png differ diff --git a/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/off.png b/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/off.png new file mode 100644 index 00000000..c19dae79 Binary files /dev/null and b/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/off.png differ diff --git a/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/off_highlighted.png b/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/off_highlighted.png new file mode 100644 index 00000000..ea701ed8 Binary files /dev/null and b/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/off_highlighted.png differ diff --git a/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/on.png b/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/on.png new file mode 100644 index 00000000..f1f36a14 Binary files /dev/null and b/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/on.png differ diff --git a/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/on_highlighted.png b/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/on_highlighted.png new file mode 100644 index 00000000..f59da114 Binary files /dev/null and b/src/main/resources/high_contrast/assets/spruceui/textures/gui/sprites/widget/toggle_switch/on_highlighted.png differ diff --git a/src/main/resources/high_contrast/assets/spruceui/textures/gui/toggle_switch.png b/src/main/resources/high_contrast/assets/spruceui/textures/gui/toggle_switch.png deleted file mode 100644 index bba17083..00000000 Binary files a/src/main/resources/high_contrast/assets/spruceui/textures/gui/toggle_switch.png and /dev/null differ diff --git a/src/testmod/java/dev/lambdaurora/spruceui/test/SpruceUITest.java b/src/testmod/java/dev/lambdaurora/spruceui/test/SpruceUITest.java index ad558666..d077e683 100644 --- a/src/testmod/java/dev/lambdaurora/spruceui/test/SpruceUITest.java +++ b/src/testmod/java/dev/lambdaurora/spruceui/test/SpruceUITest.java @@ -110,7 +110,7 @@ public SpruceUITest() { Minecraft client = Minecraft.getInstance(); SystemToast toast = SystemToast.multiline(client, SystemToast.SystemToastId.PERIODIC_NOTIFICATION, Text.literal("Action button pressed!"), Text.literal("I'm a result of the action")); - client.getToasts().addToast(toast); + client.getToastManager().addToast(toast); }, Text.literal("Represents an option with a simple action.\n" + "It's used like a normal button and a press callback."));