46 lines
2.0 KiB
Java
46 lines
2.0 KiB
Java
package pm.j4.petroleum.gui;
|
|
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
|
import net.minecraft.client.MinecraftClient;
|
|
import net.minecraft.client.font.TextRenderer;
|
|
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
|
import net.minecraft.client.util.math.MatrixStack;
|
|
import net.minecraft.text.Text;
|
|
import net.minecraft.util.math.MathHelper;
|
|
import pm.j4.petroleum.modules.base.ModuleBase;
|
|
|
|
public class PMovableButton extends AbstractButtonWidget {
|
|
public PMovableButton(int x, int y, ModuleBase module) {
|
|
super(x, y, 0, 0, module.getReadableName());
|
|
int w = MinecraftClient.getInstance().textRenderer.getWidth(module.getReadableName()) + 8;
|
|
int h = MinecraftClient.getInstance().textRenderer.fontHeight + 8;
|
|
this.width = w;
|
|
this.height = h;
|
|
}
|
|
|
|
@Override
|
|
protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY) {
|
|
this.x += (int)deltaX;
|
|
this.y += (int)deltaY;
|
|
}
|
|
|
|
@Override
|
|
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
|
// CURRENT BUTTON RENDERING
|
|
//TODO just do some shit with Tessellator and BufferBuilder to draw the lines around the button
|
|
MinecraftClient minecraftClient = MinecraftClient.getInstance();
|
|
TextRenderer textRenderer = minecraftClient.textRenderer;
|
|
minecraftClient.getTextureManager().bindTexture(WIDGETS_LOCATION);
|
|
RenderSystem.color4f(1.0F, 1.0F, 1.0F, this.alpha);
|
|
int i = this.getYImage(this.isHovered());
|
|
RenderSystem.enableBlend();
|
|
RenderSystem.defaultBlendFunc();
|
|
RenderSystem.enableDepthTest();
|
|
this.drawTexture(matrices, this.x, this.y, 0, 46 + i * 20, this.width / 2, this.height);
|
|
this.drawTexture(matrices, this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height);
|
|
this.renderBg(matrices, minecraftClient, mouseX, mouseY);
|
|
int j = this.active ? 16777215 : 10526880;
|
|
drawCenteredText(matrices, textRenderer, this.getMessage(), this.x + this.width / 2, this.y + (this.height - 8) / 2, j | MathHelper.ceil(this.alpha * 255.0F) << 24);
|
|
}
|
|
}
|