Files
NotEnoughItems/src/main/java/codechicken/nei/Button.java
T

67 lines
1.5 KiB
Java
Raw Normal View History

2014-04-29 10:54:20 +10:00
package codechicken.nei;
import static codechicken.lib.gui.GuiDraw.getStringWidth;
import java.util.List;
public abstract class Button extends Widget {
public Button(String s) {
2014-04-29 10:54:20 +10:00
label = s;
}
public Button() {
2014-04-29 10:54:20 +10:00
label = "";
}
public int contentWidth() {
2014-04-29 10:54:20 +10:00
return getRenderIcon() == null ? getStringWidth(label) : getRenderIcon().width;
}
@Override
public void draw(int mousex, int mousey) {
2014-04-29 10:54:20 +10:00
LayoutManager.getLayoutStyle().drawButton(this, mousex, mousey);
}
@Override
public boolean handleClick(int mx, int my, int button) {
if (button == 1 || button == 0) if (onButtonPress(button == 1)) NEIClientUtils.playClickSound();
2014-04-29 10:54:20 +10:00
return true;
}
2014-04-29 10:54:20 +10:00
public abstract boolean onButtonPress(boolean rightclick);
public Image getRenderIcon() {
2014-04-29 10:54:20 +10:00
return icon;
}
2014-04-29 10:54:20 +10:00
@Override
public List<String> handleTooltip(int mx, int my, List<String> tooltip) {
if (!contains(mx, my)) return tooltip;
2021-03-15 22:31:36 -07:00
final String tip = getButtonTip();
if (tip != null) tooltip.add(tip);
2021-03-15 22:31:36 -07:00
addTooltips(tooltip);
2014-04-29 10:54:20 +10:00
return tooltip;
}
public String getButtonTip() {
2014-04-29 10:54:20 +10:00
return null;
}
public void addTooltips(List<String> tooltip) {}
public String getRenderLabel() {
2014-04-29 10:54:20 +10:00
return label;
}
2019-12-30 20:19:16 -08:00
public final String label;
2014-04-29 10:54:20 +10:00
public Image icon;
2014-04-29 10:54:20 +10:00
/**
* 0x4 = state flag, as opposed to 1 click 0 = normal 1 = on 2 = disabled
2014-04-29 10:54:20 +10:00
*/
public int state;
}