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

63 lines
2.6 KiB
Java
Raw Normal View History

2015-12-04 18:14:03 +01:00
/*
2016-05-16 22:52:27 +02:00
* This file ("IndexButton.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
*
2016-05-16 22:54:42 +02:00
* © 2015-2016 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
2016-01-05 14:57:50 +01:00
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.booklet.GuiBooklet;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
2015-12-04 18:14:03 +01:00
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-12-04 18:14:03 +01:00
@SideOnly(Side.CLIENT)
2015-12-04 18:14:03 +01:00
public class IndexButton extends GuiButton{
2016-05-19 20:05:12 +02:00
private final GuiBooklet gui;
2016-06-01 00:39:35 +02:00
public IBookletChapter chap;
2015-12-04 18:14:03 +01:00
public IndexButton(int id, int x, int y, int width, int height, String text, GuiBooklet gui){
super(id, x, y, width, height, text);
this.gui = gui;
}
@Override
public void drawButton(Minecraft minecraft, int mouseX, int mouseY){
2015-12-04 18:14:03 +01:00
if(this.visible){
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition+this.width && mouseY < this.yPosition+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;
if(this.chap != null){
2016-01-05 14:57:50 +01:00
if(this.chap.getDisplayItemStack() != null){
GlStateManager.pushMatrix();
2016-01-05 14:57:50 +01:00
AssetUtil.renderStackToGui(this.chap.getDisplayItemStack(), this.xPosition-4, this.yPosition, 0.725F);
GlStateManager.popMatrix();
2015-12-04 18:14:03 +01:00
textOffsetX = 10;
}
}
if(this.hovered){
GlStateManager.pushMatrix();
AssetUtil.drawHorizontalGradientRect(this.xPosition+textOffsetX-1, this.yPosition+this.height-1, this.xPosition+this.gui.getFontRenderer().getStringWidth(this.displayString)+textOffsetX+1, this.yPosition+this.height, 0x80 << 24 | 22271, 22271, this.zLevel);
GlStateManager.popMatrix();
2015-12-04 18:14:03 +01:00
}
this.gui.getFontRenderer().drawString(this.displayString, this.xPosition+textOffsetX, this.yPosition+(this.height-8)/2, 0);
}
}
}