aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/gui/widgets/GT_GuiIconCheckButton.java
blob: 5b5007fef3923041a8b6ce5dcd2c4252e1542fd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package gregtech.api.gui.widgets;

import gregtech.api.interfaces.IGuiScreen;

public class GT_GuiIconCheckButton extends GT_GuiIconButton {

    private final GT_GuiIcon checkedIcon;
    private final GT_GuiIcon normalIcon;
    private final String checkedTooltip;
    private final String normalTooltip;
    private boolean checked = false;

    public GT_GuiIconCheckButton(IGuiScreen gui, int id, int x, int y, GT_GuiIcon checkedIcon, GT_GuiIcon normalIcon) {
        this(gui, id, x, y, checkedIcon, normalIcon, null, null);
    }

    public GT_GuiIconCheckButton(IGuiScreen gui, int id, int x, int y, GT_GuiIcon checkedIcon, GT_GuiIcon normalIcon,
        String checkedTooltip, String normalTooltip) {
        super(gui, id, x, y, normalIcon);
        this.checkedIcon = checkedIcon;
        this.normalIcon = normalIcon;
        this.checkedTooltip = checkedTooltip;
        this.normalTooltip = normalTooltip;
    }

    @Override
    public GT_GuiIcon getButtonTexture(boolean mouseOver) {
        if (!enabled) return GT_GuiIcon.BUTTON_DISABLED;
        if (this.equals(super.gui.getSelectedButton()))
            return mouseOver ? GT_GuiIcon.BUTTON_HIGHLIGHT_DOWN : GT_GuiIcon.BUTTON_DOWN;
        return mouseOver ? GT_GuiIcon.BUTTON_HIGHLIGHT : GT_GuiIcon.BUTTON_NORMAL;
    }

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        super.setIcon(checked ? checkedIcon : normalIcon);
        super.setTooltipText(checked ? checkedTooltip : normalTooltip);
        this.checked = checked;
    }
}