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

104 lines
4.4 KiB
Java
Raw Normal View History

2015-12-04 18:14:03 +01:00
/*
2016-05-16 22:52:27 +02:00
* This file ("BookmarkButton.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 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils;
import de.ellpeck.actuallyadditions.mod.booklet.GuiBooklet;
2016-06-01 00:39:35 +02:00
import de.ellpeck.actuallyadditions.mod.booklet.entry.EntrySet;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.items.InitItems;
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;
2016-03-18 15:42:06 +01:00
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.GlStateManager;
2015-12-04 18:14:03 +01:00
import net.minecraft.item.ItemStack;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-12-04 18:14:03 +01:00
import java.util.ArrayList;
@SideOnly(Side.CLIENT)
2015-12-04 18:14:03 +01:00
public class BookmarkButton extends GuiButton{
2016-05-19 20:05:12 +02:00
private final GuiBooklet booklet;
2016-06-01 00:39:35 +02:00
public EntrySet assignedEntry = new EntrySet(null);
2015-12-04 18:14:03 +01:00
public BookmarkButton(int id, int x, int y, GuiBooklet booklet){
super(id, x, y, 16, 16, "");
this.booklet = booklet;
}
public void onPressed(){
if(this.assignedEntry.entry != null){
2016-03-18 15:42:06 +01:00
if(GuiScreen.isShiftKeyDown()){
this.assignedEntry.removeEntry();
this.booklet.shouldSaveDataNextClose = true;
2015-12-04 18:14:03 +01:00
}
else{
BookletUtils.openIndexEntry(this.booklet, this.assignedEntry.entry, this.assignedEntry.pageInIndex, true);
BookletUtils.openChapter(this.booklet, this.assignedEntry.chapter, this.assignedEntry.page);
2015-12-04 18:14:03 +01:00
}
}
else{
2016-05-14 13:51:18 +02:00
if(this.booklet.currentEntrySet.getCurrentEntry() != null){
this.assignedEntry.setEntry(this.booklet.currentEntrySet.getCurrentPage(), this.booklet.currentEntrySet.getCurrentChapter(), this.booklet.currentEntrySet.getCurrentEntry(), this.booklet.currentEntrySet.getPageInIndex());
this.booklet.shouldSaveDataNextClose = true;
2015-12-04 18:14:03 +01:00
}
}
}
@Override
public void drawButton(Minecraft minecraft, int x, int y){
2015-12-04 18:14:03 +01:00
if(this.visible){
2016-06-17 23:50:38 +02:00
minecraft.getTextureManager().bindTexture(GuiBooklet.RES_LOC);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.hovered = x >= this.xPosition && y >= this.yPosition && x < this.xPosition+this.width && y < this.yPosition+this.height;
int k = this.getHoverState(this.hovered);
2015-12-04 18:14:03 +01:00
if(k == 0){
k = 1;
}
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.blendFunc(770, 771);
2015-12-04 18:14:03 +01:00
int renderHeight = 25;
this.drawTexturedModalRect(this.xPosition, this.yPosition, 146+(this.assignedEntry.entry == null ? 0 : 16), 194-renderHeight+k*renderHeight, this.width, renderHeight);
2015-12-04 18:14:03 +01:00
this.mouseDragged(minecraft, x, y);
if(this.assignedEntry.entry != null){
GlStateManager.pushMatrix();
2016-01-05 14:57:50 +01:00
AssetUtil.renderStackToGui(this.assignedEntry.chapter != null && this.assignedEntry.chapter.getDisplayItemStack() != null ? this.assignedEntry.chapter.getDisplayItemStack() : new ItemStack(InitItems.itemBooklet), this.xPosition+2, this.yPosition+1, 0.725F);
GlStateManager.popMatrix();
2015-12-04 18:14:03 +01:00
}
}
}
public void drawHover(int mouseX, int mouseY){
ArrayList list = new ArrayList();
if(this.assignedEntry.entry != null){
if(this.assignedEntry.chapter != null){
2016-03-18 23:47:22 +01:00
list.add(TextFormatting.GOLD+this.assignedEntry.chapter.getLocalizedName()+", Page "+this.assignedEntry.page.getID());
2015-12-04 18:14:03 +01:00
}
else{
2016-03-18 23:47:22 +01:00
list.add(TextFormatting.GOLD+this.assignedEntry.entry.getLocalizedName()+", Page "+this.assignedEntry.pageInIndex);
2015-12-04 18:14:03 +01:00
}
list.add("Click to open");
2016-03-18 23:47:22 +01:00
list.add(TextFormatting.ITALIC+"Shift-Click to remove");
2015-12-04 18:14:03 +01:00
}
else{
2016-03-18 23:47:22 +01:00
list.add(TextFormatting.GOLD+"None");
2015-12-04 18:14:03 +01:00
list.add("Click to save current page");
}
this.booklet.drawHoveringText(list, mouseX, mouseY);
}
}