Move features from GuiTexturedButton to GuiAdvancedButton

This commit is contained in:
johni0702
2015-07-07 16:30:53 +02:00
parent ddeb27be6f
commit 37c1796dca
2 changed files with 36 additions and 65 deletions

View File

@@ -1,12 +1,33 @@
package eu.crushedpixel.replaymod.gui.elements;
import eu.crushedpixel.replaymod.ReplayMod;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import java.awt.*;
public class GuiAdvancedButton extends GuiButton implements GuiElement {
private final Runnable action;
private final String hoverText;
public GuiAdvancedButton(int id, int x, int y, String buttonText) {
this(id, x, y, buttonText, null, null);
}
public GuiAdvancedButton(int x, int y, int width, int height, String buttonText, Runnable action, String hoverText) {
this(0, x, y, width, height, buttonText, action, hoverText);
}
public GuiAdvancedButton(int id, int x, int y, String buttonText, Runnable action, String hoverText) {
super(id, x, y, buttonText);
this.action = action;
this.hoverText = hoverText;
}
public GuiAdvancedButton(int id, int x, int y, int width, int height, String buttonText, Runnable action, String hoverText) {
super(id, x, y, width, height, buttonText);
this.action = action;
this.hoverText = hoverText;
}
@Override
@@ -16,7 +37,10 @@ public class GuiAdvancedButton extends GuiButton implements GuiElement {
@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, Color.WHITE);
}
}
@Override
@@ -29,7 +53,9 @@ public class GuiAdvancedButton extends GuiButton implements GuiElement {
@Override
public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
mousePressed(mc, mouseX, mouseY);
if (isHovering(mouseX, mouseY)) {
performAction();
}
}
@Override
@@ -51,4 +77,10 @@ public class GuiAdvancedButton extends GuiButton implements GuiElement {
public void tick(Minecraft mc) {
}
public void performAction() {
if (action != null) {
action.run();
}
}
}