ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/TexturedButton.java

72 lines
2.8 KiB
Java
Raw Normal View History

2015-12-04 18:14:03 +01:00
/*
2016-05-16 22:52:27 +02:00
* This file ("TexturedButton.java") is part of the Actually Additions mod for Minecraft.
2015-12-04 18:14:03 +01:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-12-04 18:14:03 +01:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2015-12-04 18:14:03 +01:00
*/
package de.ellpeck.actuallyadditions.mod.inventory.gui;
2015-12-04 18:14:03 +01:00
2021-02-27 22:59:18 +01:00
import com.mojang.blaze3d.platform.GlStateManager;
2021-03-01 20:55:50 +01:00
import com.mojang.blaze3d.systems.RenderSystem;
2015-12-04 18:14:03 +01:00
import net.minecraft.client.Minecraft;
2021-02-27 22:59:18 +01:00
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.ResourceLocation;
2021-03-01 20:55:50 +01:00
import net.minecraft.util.text.StringTextComponent;
2021-02-27 22:59:18 +01:00
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.client.gui.GuiUtils;
2021-02-26 22:15:48 +01:00
import java.util.ArrayList;
import java.util.List;
2015-12-04 18:14:03 +01:00
2021-02-26 22:15:48 +01:00
@OnlyIn(Dist.CLIENT)
2021-02-27 22:59:18 +01:00
public class TexturedButton extends Button {
2015-12-04 18:14:03 +01:00
2019-02-27 19:53:05 +01:00
public final List<String> textList = new ArrayList<>();
private final ResourceLocation resLoc;
2015-12-04 18:14:03 +01:00
public int texturePosX;
public int texturePosY;
2021-03-01 20:55:50 +01:00
public TexturedButton(ResourceLocation resLoc, int x, int y, int texturePosX, int texturePosY, int width, int height, IPressable pressable) {
this(resLoc, x, y, texturePosX, texturePosY, width, height, new ArrayList<>());
2015-12-19 10:30:39 +01:00
}
2021-03-01 20:55:50 +01:00
public TexturedButton(ResourceLocation resLoc, int x, int y, int texturePosX, int texturePosY, int width, int height, List<String> hoverTextList, IPressable pressable) {
super(x, y, width, height, StringTextComponent.EMPTY, pressable);
2015-12-04 18:14:03 +01:00
this.texturePosX = texturePosX;
this.texturePosY = texturePosY;
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) {
minecraft.getTextureManager().bindTexture(this.resLoc);
2021-03-01 20:55:50 +01:00
RenderSystem.color4f(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;
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;
}
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.blendFunc(770, 771);
this.blit(matrices, 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()) {
2021-02-26 22:15:48 +01:00
Minecraft mc = Minecraft.getInstance();
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
}