From 2463d8c02436775ce137ce037a872650aed1f46f Mon Sep 17 00:00:00 2001 From: coolGi Date: Tue, 3 Oct 2023 14:38:52 +1030 Subject: [PATCH] Added option to allow button background to not appear --- .../wrappers/gui/TexturedButtonWidget.java | 104 +++++++++++------- .../wrappers/gui/updater/UpdateModScreen.java | 4 +- 2 files changed, 66 insertions(+), 42 deletions(-) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/TexturedButtonWidget.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/TexturedButtonWidget.java index 1e5658acf..d3f0b8db4 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/TexturedButtonWidget.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/TexturedButtonWidget.java @@ -33,10 +33,14 @@ import net.minecraft.client.gui.components.WidgetSprites; #endif /** - * Creates a button with a texture on it + * Creates a button with a texture on it (and a background) that works with all mc versions + * + * @author coolGi + * @version 2023-10-03 */ public class TexturedButtonWidget extends ImageButton { + public final boolean renderBackground; #if POST_MC_1_20_2 public static WidgetSprites locationToSprite(ResourceLocation resourceLocation, int u, int v) { @@ -64,58 +68,73 @@ public class TexturedButtonWidget extends ImageButton #if POST_MC_1_17_1 - public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, ResourceLocation texture, OnPress pressAction) + public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, ResourceLocation texture, OnPress pressAction) { + this(x, y, width, height, u, v, texture, pressAction, true); + } + public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, ResourceLocation texture, OnPress pressAction, boolean renderBackground) { #if PRE_MC_1_20_2 super(x, y, width, height, u, v, texture, pressAction); #else super(x, y, width, height, locationToSprite(texture, u, v), pressAction); #endif + this.renderBackground = renderBackground; } #endif - public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, ResourceLocation texture, int textureWidth, int textureHeight, OnPress pressAction) + public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, ResourceLocation texture, int textureWidth, int textureHeight, OnPress pressAction) { + this(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction, true); + } + public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, ResourceLocation texture, int textureWidth, int textureHeight, OnPress pressAction, boolean renderBackground) { #if PRE_MC_1_20_2 super(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction); #else super(x, y, width, height, locationToSprite(texture, u, v, textureWidth, textureHeight, hoveredVOffset), pressAction); #endif + this.renderBackground = renderBackground; } - public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, ResourceLocation texture, int textureWidth, int textureHeight, OnPress pressAction, Component text) + public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, ResourceLocation texture, int textureWidth, int textureHeight, OnPress pressAction, Component text) { + this(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction, text, true); + } + public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, ResourceLocation texture, int textureWidth, int textureHeight, OnPress pressAction, Component text, boolean renderBackground) { #if PRE_MC_1_20_2 super(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction, text); #else super(x, y, locationToSprite(texture, u, v, textureWidth, textureHeight, hoveredVOffset), pressAction, text); #endif + this.renderBackground = renderBackground; } #if PRE_MC_1_19_4 @Override public void renderButton(PoseStack matrices, int mouseX, int mouseY, float delta) { - #if PRE_MC_1_17_1 - Minecraft.getInstance().getTextureManager().bind(WIDGETS_LOCATION); - RenderSystem.color4f(1.0F, 1.0F, 1.0F, this.alpha); - #else - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderTexture(0, WIDGETS_LOCATION); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha); - #endif + if (this.renderBackground) // Renders the background of the button + { + #if PRE_MC_1_17_1 + Minecraft.getInstance().getTextureManager().bind(WIDGETS_LOCATION); + RenderSystem.color4f(1.0F, 1.0F, 1.0F, this.alpha); + #else + RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.setShaderTexture(0, WIDGETS_LOCATION); + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha); + #endif - int i = this.getYImage(this.isHovered); - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - RenderSystem.enableDepthTest(); - #if PRE_MC_1_19_4 - this.blit(matrices, this.x, this.y, 0, 46 + i * 20, this.width / 2, this.height); - this.blit(matrices, this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height); - #else - this.blit(matrices, this.getX(), this.getY(), 0, 46 + i * 20, this.getWidth() / 2, this.getHeight()); - this.blit(matrices, this.getX() + this.getWidth() / 2, this.getY(), 200 - this.width / 2, 46 + i * 20, this.getWidth() / 2, this.getHeight()); - #endif + int i = this.getYImage(this.isHovered); + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); + RenderSystem.enableDepthTest(); + #if PRE_MC_1_19_4 + this.blit(matrices, this.x, this.y, 0, 46 + i * 20, this.width / 2, this.height); + this.blit(matrices, this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height); + #else + this.blit(matrices, this.getX(), this.getY(), 0, 46 + i * 20, this.getWidth() / 2, this.getHeight()); + this.blit(matrices, this.getX() + this.getWidth() / 2, this.getY(), 200 - this.width / 2, 46 + i * 20, this.getWidth() / 2, this.getHeight()); + #endif + } super.renderButton(matrices, mouseX, mouseY, delta); } @@ -131,25 +150,28 @@ public class TexturedButtonWidget extends ImageButton public void renderWidget(GuiGraphics matrices, int mouseX, int mouseY, float delta) { #endif - int i = 1; - if (!this.active) i = 0; - else if (this.isHovered) i = 2; + if (this.renderBackground) // Renders the background of the button + { + int i = 1; + if (!this.active) i = 0; + else if (this.isHovered) i = 2; - #if PRE_MC_1_20_1 - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - RenderSystem.enableDepthTest(); - - this.blit(matrices, this.getX(), this.getY(), 0, 46 + i * 20, this.getWidth() / 2, this.getHeight()); - this.blit(matrices, this.getX() + this.getWidth() / 2, this.getY(), 200 - this.width / 2, 46 + i * 20, this.getWidth() / 2, this.getHeight()); - #elif MC_1_20_1 - matrices.blit(WIDGETS_LOCATION, this.getX(), this.getY(), 0, 46 + i * 20, this.getWidth() / 2, this.getHeight()); - matrices.blit(WIDGETS_LOCATION, this.getX() + this.getWidth() / 2, this.getY(), 200 - this.width / 2, 46 + i * 20, this.getWidth() / 2, this.getHeight()); - #else - // FIXME[1.20.2]: Later changed `.enabled()` to a proper thing taking the hovered and active into account - matrices.blit(sprites.enabled(), this.getX(), this.getY(), 0, 46 + i * 20, this.getWidth() / 2, this.getHeight()); - matrices.blit(sprites.enabled(), this.getX() + this.getWidth() / 2, this.getY(), 200 - this.width / 2, 46 + i * 20, this.getWidth() / 2, this.getHeight()); - #endif + #if PRE_MC_1_20_1 + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); + RenderSystem.enableDepthTest(); + + this.blit(matrices, this.getX(), this.getY(), 0, 46 + i * 20, this.getWidth() / 2, this.getHeight()); + this.blit(matrices, this.getX() + this.getWidth() / 2, this.getY(), 200 - this.width / 2, 46 + i * 20, this.getWidth() / 2, this.getHeight()); + #elif MC_1_20_1 + matrices.blit(WIDGETS_LOCATION, this.getX(), this.getY(), 0, 46 + i * 20, this.getWidth() / 2, this.getHeight()); + matrices.blit(WIDGETS_LOCATION, this.getX() + this.getWidth() / 2, this.getY(), 200 - this.width / 2, 46 + i * 20, this.getWidth() / 2, this.getHeight()); + #else + // FIXME[1.20.2]: Later changed `.enabled()` to a proper thing taking the hovered and active into account + matrices.blit(sprites.enabled(), this.getX(), this.getY(), 0, 46 + i * 20, this.getWidth() / 2, this.getHeight()); + matrices.blit(sprites.enabled(), this.getX() + this.getWidth() / 2, this.getY(), 200 - this.width / 2, 46 + i * 20, this.getWidth() / 2, this.getHeight()); + #endif + } super.renderWidget(matrices, mouseX, mouseY, delta); } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/updater/UpdateModScreen.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/updater/UpdateModScreen.java index 0484da1aa..608592901 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/updater/UpdateModScreen.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/updater/UpdateModScreen.java @@ -90,7 +90,9 @@ public class UpdateModScreen extends DhScreen // For now it goes to the client option by default (buttonWidget) -> System.out.println("Nice, you found an easter egg :)"), // TODO: Add a proper easter egg to pressing the logo (maybe with confetti) // Add a title to the button - Translatable(ModInfo.ID + ".updater.title") + Translatable(ModInfo.ID + ".updater.title"), + // Dont render the background of the button + false )); } catch (Exception e)