2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
|
|
|
|
import static codechicken.lib.gui.GuiDraw.getStringWidth;
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public abstract class Button extends Widget {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public Button(String s) {
|
2014-04-29 10:54:20 +10:00
|
|
|
label = s;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public Button() {
|
2014-04-29 10:54:20 +10:00
|
|
|
label = "";
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public int contentWidth() {
|
2014-04-29 10:54:20 +10:00
|
|
|
return getRenderIcon() == null ? getStringWidth(label) : getRenderIcon().width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public void draw(int mousex, int mousey) {
|
2014-04-29 10:54:20 +10:00
|
|
|
LayoutManager.getLayoutStyle().drawButton(this, mousex, mousey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public boolean handleClick(int mx, int my, int button) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (button == 1 || button == 0) if (onButtonPress(button == 1)) NEIClientUtils.playClickSound();
|
2014-04-29 10:54:20 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
public abstract boolean onButtonPress(boolean rightclick);
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public Image getRenderIcon() {
|
2014-04-29 10:54:20 +10:00
|
|
|
return icon;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2014-06-29 20:31:37 +10:00
|
|
|
public List<String> handleTooltip(int mx, int my, List<String> tooltip) {
|
2022-06-24 12:32:13 +01:00
|
|
|
if (!contains(mx, my)) return tooltip;
|
2014-06-29 20:31:37 +10:00
|
|
|
|
2021-03-15 22:31:36 -07:00
|
|
|
final String tip = getButtonTip();
|
2022-06-24 12:32:13 +01:00
|
|
|
if (tip != null) tooltip.add(tip);
|
|
|
|
|
|
2021-03-15 22:31:36 -07:00
|
|
|
addTooltips(tooltip);
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
return tooltip;
|
|
|
|
|
}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
public String getButtonTip() {
|
2014-04-29 10:54:20 +10:00
|
|
|
return null;
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
|
|
|
|
public void addTooltips(List<String> tooltip) {}
|
2014-06-29 20:31:37 +10:00
|
|
|
|
|
|
|
|
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-06-29 20:31:37 +10:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
/**
|
2023-01-28 17:55:51 -08: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;
|
|
|
|
|
}
|