Use component like system for gui overlay
Add missing abort path replay button
This commit is contained in:
@@ -5,50 +5,85 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class GuiTexturedButton extends GuiButton {
|
||||
public class GuiTexturedButton extends GuiButton implements GuiElement {
|
||||
private final ResourceLocation texture;
|
||||
private final int u, v;
|
||||
private final int textureWidth, textureHeight;
|
||||
private final String hoverKey;
|
||||
private final Runnable action;
|
||||
private final String hoverText;
|
||||
|
||||
public GuiTexturedButton(int buttonId, int x, int y, int width, int height, ResourceLocation texture,
|
||||
int u, int v, int textureWidth, int textureHeight) {
|
||||
this(buttonId, x, y, width, height, texture, u, v, textureWidth, textureHeight, null);
|
||||
int u, int v, int textureWidth, int textureHeight, Runnable action) {
|
||||
this(buttonId, x, y, width, height, texture, u, v, textureWidth, textureHeight, action, null);
|
||||
}
|
||||
|
||||
public GuiTexturedButton(int buttonId, int x, int y, int width, int height, ResourceLocation texture,
|
||||
int u, int v, int textureWidth, int textureHeight, String hoverKey) {
|
||||
int u, int v, int textureWidth, int textureHeight, Runnable action, String hoverText) {
|
||||
super(buttonId, x, y, width, height, "");
|
||||
this.texture = texture;
|
||||
this.u = u;
|
||||
this.v = v;
|
||||
this.textureWidth = textureWidth;
|
||||
this.textureHeight = textureHeight;
|
||||
this.hoverKey = hoverKey;
|
||||
this.action = action;
|
||||
this.hoverText = hoverText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHovering(int mouseX, int mouseY) {
|
||||
return enabled && visible
|
||||
&& mouseX >= xPosition
|
||||
&& mouseY >= yPosition
|
||||
&& mouseX < xPosition + width
|
||||
&& mouseY < yPosition + height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
if (visible) {
|
||||
hovered = mouseX >= xPosition
|
||||
&& mouseY >= yPosition
|
||||
&& mouseX < xPosition + width
|
||||
&& mouseY < yPosition + height;
|
||||
hovered = isHovering(mouseX, mouseY);
|
||||
|
||||
mc.renderEngine.bindTexture(texture);
|
||||
|
||||
GlStateManager.color(1, 1, 1);
|
||||
int u = this.u + (hovered ? width : 0);
|
||||
Gui.drawModalRectWithCustomSizedTexture(xPosition, yPosition, u, v, width, height, textureWidth, textureHeight);
|
||||
|
||||
if(hovered && hoverKey != null) {
|
||||
ReplayMod.tooltipRenderer.drawTooltip(mouseX, mouseY, I18n.format(hoverKey), null, Color.WHITE.getRGB());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Minecraft mc, int mouseX, int mouseY) {
|
||||
drawButton(mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOverlay(Minecraft mc, int mouseX, int mouseY) {
|
||||
hovered = isHovering(mouseX, mouseY);
|
||||
if(hovered && hoverText != null) {
|
||||
ReplayMod.tooltipRenderer.drawTooltip(mouseX, mouseY, hoverText, null, 0xffffffff);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
|
||||
if (isHovering(mouseX, mouseY)) {
|
||||
performAction();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) {
|
||||
|
||||
}
|
||||
|
||||
public void performAction() {
|
||||
action.run();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user