| 24 | import net.minecraft.sound.SoundEvents; |
| 25 | |
| 26 | public class Button { |
| 27 | |
| 28 | private String text; |
| 29 | private float x, y, width, height; |
| 30 | public boolean animation; |
| 31 | public boolean enabled; |
| 32 | private Runnable onClickAction; |
| 33 | |
| 34 | public Button(String text, float x, float y, float width, float height, boolean animation, Runnable onClickAction) { |
| 35 | this.text = text; |
| 36 | this.x = x; |
| 37 | this.y = y; |
| 38 | this.width = width; |
| 39 | this.height = height; |
| 40 | this.animation = animation; |
| 41 | this.onClickAction = onClickAction; |
| 42 | this.enabled = true; |
| 43 | } |
| 44 | |
| 45 | float hoverTicks = 80; |
| 46 | public void render(MatrixStack matrices, double mouseX, double mouseY, float delta) { |
| 47 | if (isHovered(mouseX, mouseY) && hoverTicks > 20) { |
| 48 | hoverTicks-=5; |
| 49 | } else if (!isHovered(mouseX, mouseY) && hoverTicks < 80) { |
| 50 | hoverTicks+=5; |
| 51 | } |
| 52 | RenderUtils.drawBorderRect(matrices, x, y - 1, x + width, y + height + 1, ColorUtils.defaultClientColor, 1); |
| 53 | RenderUtils.fill(matrices, x, y, x + width, y + height, ColorUtils.transparent((int)hoverTicks)); |
| 54 | HypnoticScreen.font.drawCenteredString(matrices, text, x + width / 2, y + 2, -1, true); |
| 55 | } |
| 56 | |
| 57 | public boolean isHovered(double mouseX, double mouseY) { |
| 58 | return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height && enabled; |
| 59 | } |
| 60 | |
| 61 | public String getText() { |
| 62 | return text; |
| 63 | } |
| 64 | |
| 65 | public void setText(String text) { |
| 66 | this.text = text; |
| 67 | } |
| 68 | |
| 69 | public double getX() { |
| 70 | return x; |
| 71 | } |
| 72 | |
| 73 | public double getY() { |
| 74 | return y; |
| 75 | } |
| 76 | |
| 77 | public void setX(float x) { |
| 78 | this.x = x; |
| 79 | } |
| 80 | |
| 81 | public void setY(float y) { |
| 82 | this.y = y; |
| 83 | } |
nothing calls this directly
no outgoing calls
no test coverage detected