|
| 1 | +package me.melontini.andromeda.common.client; |
| 2 | + |
| 3 | +import com.mojang.blaze3d.systems.RenderSystem; |
| 4 | +import net.minecraft.client.gui.DrawContext; |
| 5 | +import net.minecraft.client.gui.widget.ButtonWidget; |
| 6 | +import net.minecraft.screen.ScreenTexts; |
| 7 | +import net.minecraft.text.Text; |
| 8 | +import net.minecraft.util.Identifier; |
| 9 | + |
| 10 | +public class UvTexturedButtonWidget extends ButtonWidget { |
| 11 | + protected final Identifier texture; |
| 12 | + protected final int u; |
| 13 | + protected final int v; |
| 14 | + protected final int hoveredVOffset; |
| 15 | + protected final int textureWidth; |
| 16 | + protected final int textureHeight; |
| 17 | + |
| 18 | + public UvTexturedButtonWidget(int x, int y, int width, int height, int u, int v, Identifier texture, ButtonWidget.PressAction pressAction) { |
| 19 | + this(x, y, width, height, u, v, height, texture, 256, 256, pressAction); |
| 20 | + } |
| 21 | + |
| 22 | + public UvTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, ButtonWidget.PressAction pressAction) { |
| 23 | + this(x, y, width, height, u, v, hoveredVOffset, texture, 256, 256, pressAction); |
| 24 | + } |
| 25 | + |
| 26 | + public UvTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction) { |
| 27 | + this(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction, ScreenTexts.EMPTY); |
| 28 | + } |
| 29 | + |
| 30 | + public UvTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction, Text message) { |
| 31 | + super(x, y, width, height, message, pressAction, DEFAULT_NARRATION_SUPPLIER); |
| 32 | + this.textureWidth = textureWidth; |
| 33 | + this.textureHeight = textureHeight; |
| 34 | + this.u = u; |
| 35 | + this.v = v; |
| 36 | + this.hoveredVOffset = hoveredVOffset; |
| 37 | + this.texture = texture; |
| 38 | + } |
| 39 | + |
| 40 | + public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) { |
| 41 | + int i = v; |
| 42 | + if (!this.isNarratable()) { |
| 43 | + i = v + hoveredVOffset * 2; |
| 44 | + } else if (this.isSelected()) { |
| 45 | + i = v + hoveredVOffset; |
| 46 | + } |
| 47 | + |
| 48 | + RenderSystem.enableDepthTest(); |
| 49 | + context.drawTexture(texture, this.getX(), this.getY(), (float)u, (float)i, width, height, textureWidth, textureHeight); |
| 50 | + } |
| 51 | +} |
0 commit comments