2017-04-20 20:44:08 +02:00
|
|
|
package malte0811.industrialWires.client.gui.elements;
|
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
|
|
|
import net.minecraft.item.EnumDyeColor;
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
|
|
|
public class GuiChannelPicker extends GuiButton {
|
2017-05-03 18:08:52 +02:00
|
|
|
protected byte selected;
|
|
|
|
protected byte currHovered;
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-04-20 20:44:08 +02:00
|
|
|
public GuiChannelPicker(int id, int x, int y, int size, byte selectedChannel) {
|
|
|
|
super(id, x, y, size, size, "");
|
|
|
|
selected = selectedChannel;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-07-09 18:10:06 +02:00
|
|
|
public void drawButton(@Nonnull Minecraft mc, int mouseX, int mouseY, float patrtialTicks) {
|
2017-04-20 20:44:08 +02:00
|
|
|
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
|
|
|
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
2017-06-25 18:34:10 +02:00
|
|
|
mouseX -= x;
|
|
|
|
mouseY -= y;
|
2017-04-20 20:44:08 +02:00
|
|
|
currHovered = -1;
|
2017-05-11 16:39:20 +02:00
|
|
|
for (byte i = 0; i < 16; i++) {
|
|
|
|
int xMin = width / 4 * (i % 4);
|
|
|
|
int yMin = height / 4 * (i / 4);
|
|
|
|
int xMax = xMin + width / 4;
|
|
|
|
int yMax = yMin + height / 4;
|
2017-04-20 20:44:08 +02:00
|
|
|
EnumDyeColor color = EnumDyeColor.byMetadata(i);
|
2017-07-09 18:10:06 +02:00
|
|
|
int colorVal = color.getColorValue() | 0xff000000;
|
2017-05-11 16:39:20 +02:00
|
|
|
if (mouseX >= xMin && mouseX < xMax && mouseY >= yMin && mouseY < yMax) {
|
2017-04-20 20:44:08 +02:00
|
|
|
currHovered = i;
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
if (selected == i) {
|
2017-06-25 18:34:10 +02:00
|
|
|
drawRect(xMin + x, yMin + y, xMax + x, yMax + y, 0xff000000 | ~colorVal);
|
2017-04-20 20:44:08 +02:00
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
if (currHovered == i) {
|
2017-06-25 18:34:10 +02:00
|
|
|
drawRect(xMin + x, yMin + y, xMax + x, yMax + y, colorVal);
|
2017-04-20 20:44:08 +02:00
|
|
|
} else {
|
2017-05-11 16:39:20 +02:00
|
|
|
final int offset = width / 20;
|
2017-06-25 18:34:10 +02:00
|
|
|
drawRect(xMin + offset + x, yMin + offset + y, xMax - offset + x, yMax - offset + y, colorVal);
|
2017-04-20 20:44:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-25 18:34:10 +02:00
|
|
|
public boolean click(int xMouse, int yMouse) {
|
|
|
|
if (x <= xMouse && x + width >= xMouse && y <= yMouse && y + height >= yMouse) {
|
2017-05-03 18:08:52 +02:00
|
|
|
select();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void select() {
|
2017-05-11 16:39:20 +02:00
|
|
|
if (currHovered >= 0) {
|
2017-04-20 20:44:08 +02:00
|
|
|
selected = currHovered;
|
|
|
|
}
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-04-20 20:44:08 +02:00
|
|
|
public byte getSelected() {
|
|
|
|
return selected;
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-06-25 18:34:10 +02:00
|
|
|
public boolean isHovered(int xMouse, int yMouse) {
|
|
|
|
return x <= xMouse && x + width >= xMouse && y <= yMouse && y + height >= yMouse;
|
2017-04-20 20:44:08 +02:00
|
|
|
}
|
|
|
|
}
|