ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/button/EntryButton.java

68 lines
2.8 KiB
Java
Raw Normal View History

2015-12-04 18:14:03 +01:00
/*
* This file ("EntryButton.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
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.booklet.button;
2015-12-04 18:14:03 +01:00
2021-02-27 22:59:18 +01:00
import com.mojang.blaze3d.platform.GlStateManager;
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
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.item.ItemStack;
2021-02-27 22:59:18 +01:00
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
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 EntryButton extends Button {
2015-12-04 18:14:03 +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);
this.gui = gui;
2017-11-02 22:49:53 +01:00
StackUtil.isValid(stackToRender);
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) {
GlStateManager.color3arg(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;
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)) {
GlStateManager._pushMatrix();
2019-05-02 09:10:29 +02:00
AssetUtil.renderStackToGui(this.stackToRender, this.x - 4, this.y, 0.725F);
GlStateManager._popMatrix();
textOffsetX = 10;
2015-12-04 18:14:03 +01:00
}
float scale = this.gui.getMediumFontSize();
2019-05-02 09:10:29 +02:00
if (this.hovered) {
GlStateManager._pushMatrix();
AssetUtil.drawHorizontalGradientRect(this.x + textOffsetX - 1, this.y + this.height - 1, this.x + (int) (minecraft.font.width(this.displayString) * scale) + textOffsetX + 1, this.y + this.height, 0x80 << 24 | 22271, 22271, this.zLevel);
GlStateManager._popMatrix();
2015-12-04 18:14:03 +01:00
}
StringUtil.renderScaledAsciiString(minecraft.font, this.displayString, this.x + textOffsetX, this.y + 2 + (this.height - 8) / 2, 0, false, scale);
2015-12-04 18:14:03 +01:00
}
}
}