Move features from GuiTexturedButton to GuiAdvancedButton
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +1,23 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
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.util.ResourceLocation;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class GuiTexturedButton extends GuiButton implements GuiElement {
|
||||
public class GuiTexturedButton extends GuiAdvancedButton implements GuiElement {
|
||||
private final ResourceLocation texture;
|
||||
private final int u, v;
|
||||
private final int textureWidth, textureHeight;
|
||||
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, Runnable action, String hoverText) {
|
||||
super(buttonId, x, y, width, height, "");
|
||||
super(buttonId, x, y, width, height, "", action, hoverText);
|
||||
this.texture = texture;
|
||||
this.u = u;
|
||||
this.v = v;
|
||||
this.textureWidth = textureWidth;
|
||||
this.textureHeight = textureHeight;
|
||||
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
|
||||
@@ -49,48 +32,4 @@ public class GuiTexturedButton extends GuiButton implements GuiElement {
|
||||
Gui.drawModalRectWithCustomSizedTexture(xPosition, yPosition, u, v, width, height, textureWidth, textureHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@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, Color.WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonPressed(Minecraft mc, int mouseX, int mouseY, char key, int keyCode) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(Minecraft mc) {
|
||||
|
||||
}
|
||||
|
||||
public void performAction() {
|
||||
action.run();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user