2020-09-09 16:49:01 +02:00
|
|
|
package de.ellpeck.actuallyadditions.booklet.button;
|
2015-12-04 18:14:03 +01:00
|
|
|
|
2016-12-07 15:25:04 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
|
2020-09-09 16:48:43 +02:00
|
|
|
import de.ellpeck.actuallyadditions.common.util.AssetUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.common.util.StackUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.common.util.StringUtil;
|
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.item.ItemStack;
|
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 EntryButton extends GuiButton {
|
2015-12-04 18:14:03 +01:00
|
|
|
|
2016-12-07 15:25:04 +01:00
|
|
|
private final GuiBookletBase gui;
|
|
|
|
private final ItemStack stackToRender;
|
2015-12-04 18:14:03 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public EntryButton(GuiBookletBase gui, int id, int x, int y, int width, int height, String text, ItemStack stackToRender) {
|
2015-12-04 18:14:03 +01:00
|
|
|
super(id, x, y, width, height, text);
|
2016-12-07 15:25:04 +01:00
|
|
|
this.gui = gui;
|
2017-11-02 22:49:53 +01:00
|
|
|
StackUtil.isValid(stackToRender);
|
2016-11-10 19:50:01 +01:00
|
|
|
this.stackToRender = stackToRender;
|
2015-12-04 18:14:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void drawButton(Minecraft minecraft, int mouseX, int mouseY, float f) {
|
|
|
|
if (this.visible) {
|
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 = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
|
2016-01-08 15:21:05 +01:00
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
|
|
|
GlStateManager.blendFunc(770, 771);
|
2015-12-04 18:14:03 +01:00
|
|
|
this.mouseDragged(minecraft, mouseX, mouseY);
|
|
|
|
|
|
|
|
int textOffsetX = 0;
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(this.stackToRender)) {
|
2016-11-10 19:50:01 +01:00
|
|
|
GlStateManager.pushMatrix();
|
2019-05-02 09:10:29 +02:00
|
|
|
AssetUtil.renderStackToGui(this.stackToRender, this.x - 4, this.y, 0.725F);
|
2016-11-10 19:50:01 +01:00
|
|
|
GlStateManager.popMatrix();
|
|
|
|
textOffsetX = 10;
|
2015-12-04 18:14:03 +01:00
|
|
|
}
|
|
|
|
|
2016-12-07 15:25:04 +01:00
|
|
|
float scale = this.gui.getMediumFontSize();
|
2016-11-10 19:50:01 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.hovered) {
|
2016-01-08 15:21:05 +01:00
|
|
|
GlStateManager.pushMatrix();
|
2019-05-02 09:10:29 +02:00
|
|
|
AssetUtil.drawHorizontalGradientRect(this.x + textOffsetX - 1, this.y + this.height - 1, this.x + (int) (minecraft.fontRenderer.getStringWidth(this.displayString) * scale) + textOffsetX + 1, this.y + this.height, 0x80 << 24 | 22271, 22271, this.zLevel);
|
2016-01-08 15:21:05 +01:00
|
|
|
GlStateManager.popMatrix();
|
2015-12-04 18:14:03 +01:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
StringUtil.renderScaledAsciiString(minecraft.fontRenderer, this.displayString, this.x + textOffsetX, this.y + 2 + (this.height - 8) / 2, 0, false, scale);
|
2015-12-04 18:14:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|