2016-11-10 19:50:01 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.inventory.gui;
|
2015-12-04 18:14:03 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-12-04 18:14:03 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.GuiButton;
|
2016-01-08 15:21:05 +01:00
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
2016-11-10 19:50:01 +01:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2016-11-12 15:09:30 +01:00
|
|
|
import net.minecraftforge.fml.client.config.GuiUtils;
|
2016-06-01 15:22:30 +02:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-12-04 18:14:03 +01:00
|
|
|
|
2016-06-01 15:22:30 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public class TexturedButton extends GuiButton {
|
2015-12-04 18:14:03 +01:00
|
|
|
|
2019-02-27 19:53:05 +01:00
|
|
|
public final List<String> textList = new ArrayList<>();
|
2016-11-16 20:31:16 +01:00
|
|
|
private final ResourceLocation resLoc;
|
2015-12-04 18:14:03 +01:00
|
|
|
public int texturePosX;
|
|
|
|
public int texturePosY;
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public TexturedButton(ResourceLocation resLoc, int id, int x, int y, int texturePosX, int texturePosY, int width, int height) {
|
2017-07-28 03:17:50 +02:00
|
|
|
this(resLoc, id, x, y, texturePosX, texturePosY, width, height, new ArrayList<String>());
|
2015-12-19 10:30:39 +01:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public TexturedButton(ResourceLocation resLoc, int id, int x, int y, int texturePosX, int texturePosY, int width, int height, List<String> hoverTextList) {
|
2015-12-04 18:14:03 +01:00
|
|
|
super(id, x, y, width, height, "");
|
|
|
|
this.texturePosX = texturePosX;
|
|
|
|
this.texturePosY = texturePosY;
|
2016-11-10 19:50:01 +01:00
|
|
|
this.resLoc = resLoc;
|
2015-12-04 18:14:03 +01:00
|
|
|
this.textList.addAll(hoverTextList);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void drawButton(Minecraft minecraft, int x, int y, float f) {
|
|
|
|
if (this.visible) {
|
2016-11-10 19:50:01 +01:00
|
|
|
minecraft.getTextureManager().bindTexture(this.resLoc);
|
2016-01-08 15:21:05 +01:00
|
|
|
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
2019-05-02 09:10:29 +02:00
|
|
|
this.hovered = x >= this.x && y >= this.y && x < this.x + this.width && y < this.y + this.height;
|
2016-01-07 23:42:42 +01:00
|
|
|
int k = this.getHoverState(this.hovered);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (k == 0) {
|
2015-12-04 18:14:03 +01:00
|
|
|
k = 1;
|
|
|
|
}
|
|
|
|
|
2016-01-08 15:21:05 +01:00
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
|
|
|
GlStateManager.blendFunc(770, 771);
|
2019-05-02 09:10:29 +02:00
|
|
|
this.drawTexturedModalRect(this.x, this.y, this.texturePosX, this.texturePosY - this.height + k * this.height, this.width, this.height);
|
2015-12-04 18:14:03 +01:00
|
|
|
this.mouseDragged(minecraft, x, y);
|
|
|
|
}
|
|
|
|
}
|
2016-11-12 15:09:30 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public void drawHover(int x, int y) {
|
|
|
|
if (this.isMouseOver()) {
|
2016-11-12 15:09:30 +01:00
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
2017-06-29 18:30:02 +02:00
|
|
|
GuiUtils.drawHoveringText(this.textList, x, y, mc.displayWidth, mc.displayHeight, -1, mc.fontRenderer);
|
2016-11-12 15:09:30 +01:00
|
|
|
}
|
|
|
|
}
|
2015-12-04 18:14:03 +01:00
|
|
|
}
|