aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/gui/widgets/GT_GuiIcon.java
blob: 01c867167852a0728398f178f72b6c1c8ca00c8e (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package gregtech.api.gui.widgets;

import java.util.Arrays;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.ResourceLocation;

import gregtech.api.interfaces.IGuiIcon;

public enum GT_GuiIcon implements IGuiIcon {

    BUTTON_NORMAL(0, 0, 0),
    BUTTON_DOWN(0, 32, 0),
    BUTTON_HIGHLIGHT(0, 32 * 2, 0),
    BUTTON_HIGHLIGHT_DOWN(0, 32 * 3, 0),
    BUTTON_DISABLED(0, 32 * 4, 0),

    DISABLE(0, 0, 32),
    REDSTONE_OFF(0, 32, 32),
    REDSTONE_ON(0, 32 * 2, 32),
    CHECKMARK(0, 32 * 3, 32),
    CROSS(0, 32 * 4, 32),
    WHITELIST(0, 32 * 5, 32),
    BLACKLIST(0, 32 * 6, 32),
    PROGRESS(0, 32 * 7, 32),

    EXPORT(0, 0, 32 * 2),
    IMPORT(0, 32, 32 * 2),
    ALLOW_INPUT(0, 32 * 2, 32 * 2),
    BLOCK_INPUT(0, 32 * 3, 32 * 2),
    GREEN_ARROW_UP(0, 32 * 4, 32 * 2),
    GREEN_ARROW_DOWN(0, 32 * 5, 32 * 2),
    CYCLIC(0, 32 * 6, 32 * 2),

    AND_GATE(0, 0, 32 * 3),
    NAND_GATE(0, 32, 32 * 3),
    OR_GATE(0, 32 * 2, 32 * 3),
    NOR_GATE(0, 32 * 3, 32 * 3),
    ANALOG_MODE(0, 32 * 4, 32 * 3),

    SLOT_DARKGRAY(1, 176, 0, 18, 18),
    SLOT_GRAY(1, 176, 18, 18, 18),

    TAB_NORMAL(2, 0, 0, 18, 20),
    TAB_HIGHLIGHT(2, 18, 0, 18, 20),
    TAB_DISABLED(2, 18 * 2, 0, 18, 20),
    TAB_NORMAL_BRONZE(2, 0, 20, 18, 20),
    TAB_HIGHLIGHT_BRONZE(2, 18, 20, 18, 20),
    TAB_DISABLED_BRONZE(2, 18 * 2, 20, 18, 20),
    TAB_NORMAL_STEEL(2, 0, 2 * 20, 18, 20),
    TAB_HIGHLIGHT_STEEL(2, 18, 2 * 20, 18, 20),
    TAB_DISABLED_STEEL(2, 18 * 2, 2 * 20, 18, 20),
    TAB_NORMAL_BRICK(2, 0, 3 * 20, 18, 20),
    TAB_HIGHLIGHT_BRICK(2, 18, 3 * 20, 18, 20),
    TAB_DISABLED_BRICK(2, 18 * 2, 3 * 20, 18, 20),
    TAB_INFO_GRAY(2, 220, 0, 18, 20),
    TAB_INFO_BLUE(2, 220 + 18, 0, 18, 20),;

    private static final int T_SIZE = 256;
    private static ResourceLocation[] TEXTURES = { new ResourceLocation("gregtech", "textures/gui/GuiButtons.png"),
            new ResourceLocation("gregtech", "textures/gui/GuiCover.png"),
            new ResourceLocation("gregtech", "textures/gui/GuiTabs.png"), };

    public final int x, y, width, height;
    public final IGuiIcon overlay;
    private final int texID;

    GT_GuiIcon(int texID, int x, int y, int width, int height, IGuiIcon overlay) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        this.overlay = overlay;
        this.texID = texID;
    }

    GT_GuiIcon(int texID, int x, int y) {
        this(texID, x, y, 32, 32, null);
    }

    GT_GuiIcon(int texID, int x, int y, int width, int height) {
        this(texID, x, y, width, height, null);
    }

    public static void render(IGuiIcon icon, double x, double y, double width, double height, double zLevel,
            boolean doDraw) {
        render(icon, x, y, width, height, zLevel, doDraw, false);
    }

    public static void render(IGuiIcon icon, double x, double y, double width, double height, double zLevel,
            boolean doDraw, boolean flipHoritontally) {
        Tessellator tess = Tessellator.instance;
        if (doDraw) {
            Minecraft.getMinecraft().renderEngine.bindTexture(TEXTURES[icon.getTexId()]);
            tess.startDrawingQuads();
        }
        double minU = (double) (icon.getX() + (flipHoritontally ? icon.getWidth() : 0)) / T_SIZE;
        double maxU = (double) (icon.getX() + (flipHoritontally ? 0 : icon.getWidth())) / T_SIZE;
        double minV = (double) icon.getY() / T_SIZE;
        double maxV = (double) (icon.getY() + icon.getHeight()) / T_SIZE;
        tess.addVertexWithUV(x, y + height, zLevel, minU, maxV);
        tess.addVertexWithUV(x + width, y + height, zLevel, maxU, maxV);
        tess.addVertexWithUV(x + width, y + 0, zLevel, maxU, minV);
        tess.addVertexWithUV(x, y + 0, zLevel, minU, minV);

        if (icon.getOverlay() != null) render(icon.getOverlay(), x, y, width, height, zLevel, false);

        if (doDraw) tess.draw();
    }

    /**
     * This is intended to enable addon mods to register additional textures. They can then add to this enum using
     * EnumHelper.addEnum or by creating your their enum that implements IGuiIcon (still requires adding a texture here)
     *
     * @param location
     */
    public static void addTextures(ResourceLocation... location) {
        if (location == null || location.length == 0) return;

        int startIndex = TEXTURES.length;
        TEXTURES = (ResourceLocation[]) Arrays.copyOf(TEXTURES, location.length);
        for (int i = 0; i < location.length; i++) {
            TEXTURES[startIndex + i] = location[i];
        }
    }

    @Override
    public int getX() {
        return this.x;
    }

    @Override
    public int getY() {
        return this.y;
    }

    @Override
    public int getWidth() {
        return this.width;
    }

    @Override
    public int getHeight() {
        return this.height;
    }

    @Override
    public int getTexId() {
        return this.texID;
    }

    @Override
    public IGuiIcon getOverlay() {
        return this.overlay;
    }
}