2015-12-04 18:14:03 +01:00
|
|
|
/*
|
|
|
|
* This file ("BookmarkButton.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
|
|
|
* © 2015 Ellpeck
|
|
|
|
*/
|
|
|
|
|
|
|
|
package ellpeck.actuallyadditions.booklet.button;
|
|
|
|
|
|
|
|
import ellpeck.actuallyadditions.booklet.BookletUtils;
|
2015-12-04 18:55:50 +01:00
|
|
|
import ellpeck.actuallyadditions.booklet.EntrySet;
|
2015-12-04 18:14:03 +01:00
|
|
|
import ellpeck.actuallyadditions.booklet.GuiBooklet;
|
|
|
|
import ellpeck.actuallyadditions.booklet.page.BookletPage;
|
|
|
|
import ellpeck.actuallyadditions.items.InitItems;
|
|
|
|
import ellpeck.actuallyadditions.util.KeyUtil;
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
import net.minecraft.client.renderer.OpenGlHelper;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.EnumChatFormatting;
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
public class BookmarkButton extends GuiButton{
|
|
|
|
|
2015-12-04 18:55:50 +01:00
|
|
|
public EntrySet assignedEntry = new EntrySet(null);
|
2015-12-04 18:14:03 +01:00
|
|
|
|
|
|
|
private GuiBooklet booklet;
|
|
|
|
|
|
|
|
public BookmarkButton(int id, int x, int y, GuiBooklet booklet){
|
|
|
|
super(id, x, y, 16, 16, "");
|
|
|
|
this.booklet = booklet;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onPressed(){
|
2015-12-04 18:55:50 +01:00
|
|
|
if(this.assignedEntry.entry != null){
|
2015-12-04 18:14:03 +01:00
|
|
|
if(KeyUtil.isShiftPressed()){
|
2015-12-04 18:55:50 +01:00
|
|
|
this.assignedEntry.removeEntry();
|
2015-12-04 18:14:03 +01:00
|
|
|
}
|
|
|
|
else{
|
2015-12-04 18:55:50 +01:00
|
|
|
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{
|
2015-12-04 18:55:50 +01:00
|
|
|
if(this.booklet.currentEntrySet.entry != null){
|
|
|
|
this.assignedEntry.setEntry(this.booklet.currentEntrySet.page, this.booklet.currentEntrySet.chapter, this.booklet.currentEntrySet.entry, this.booklet.currentEntrySet.pageInIndex);
|
2015-12-04 18:14:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawButton(Minecraft minecraft, int x, int y){
|
|
|
|
if(this.visible){
|
|
|
|
minecraft.getTextureManager().bindTexture(GuiBooklet.resLoc);
|
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
this.field_146123_n = x >= this.xPosition && y >= this.yPosition && x < this.xPosition+this.width && y < this.yPosition+this.height;
|
|
|
|
int k = this.getHoverState(this.field_146123_n);
|
|
|
|
if(k == 0){
|
|
|
|
k = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
GL11.glEnable(GL11.GL_BLEND);
|
|
|
|
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
|
|
|
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
int renderHeight = 25;
|
2015-12-04 18:55:50 +01:00
|
|
|
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);
|
|
|
|
|
2015-12-04 18:55:50 +01:00
|
|
|
if(this.assignedEntry.entry != null){
|
2015-12-04 18:14:03 +01:00
|
|
|
GL11.glPushMatrix();
|
2015-12-04 18:55:50 +01:00
|
|
|
BookletPage.renderItem(booklet, this.assignedEntry.chapter != null && this.assignedEntry.chapter.displayStack != null ? this.assignedEntry.chapter.displayStack : new ItemStack(InitItems.itemBooklet), this.xPosition+2, this.yPosition+1, 0.725F);
|
2015-12-04 18:14:03 +01:00
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public void drawHover(int mouseX, int mouseY){
|
|
|
|
ArrayList list = new ArrayList();
|
2015-12-04 18:55:50 +01:00
|
|
|
if(this.assignedEntry.entry != null){
|
|
|
|
if(this.assignedEntry.chapter != null){
|
|
|
|
list.add(EnumChatFormatting.GOLD+this.assignedEntry.chapter.getLocalizedName()+", Page "+this.assignedEntry.page.getID());
|
2015-12-04 18:14:03 +01:00
|
|
|
}
|
|
|
|
else{
|
2015-12-04 18:55:50 +01:00
|
|
|
list.add(EnumChatFormatting.GOLD+this.assignedEntry.entry.getLocalizedName()+", Page "+this.assignedEntry.pageInIndex);
|
2015-12-04 18:14:03 +01:00
|
|
|
}
|
|
|
|
list.add("Click to open");
|
|
|
|
list.add(EnumChatFormatting.ITALIC+"Shift-Click to remove");
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
list.add(EnumChatFormatting.GOLD+"None");
|
|
|
|
list.add("Click to save current page");
|
|
|
|
}
|
|
|
|
this.booklet.drawHoveringText(list, mouseX, mouseY);
|
|
|
|
}
|
|
|
|
}
|