Added Bookmarks

This commit is contained in:
Ellpeck 2015-11-16 19:57:46 +01:00
parent 4d1dffb714
commit 3ff1c50454
3 changed files with 118 additions and 22 deletions

View file

@ -15,6 +15,7 @@ import ellpeck.actuallyadditions.booklet.chapter.BookletChapter;
import ellpeck.actuallyadditions.booklet.entry.BookletEntry;
import ellpeck.actuallyadditions.booklet.entry.BookletEntryAllSearch;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.items.InitItems;
import ellpeck.actuallyadditions.update.UpdateChecker;
import ellpeck.actuallyadditions.util.*;
import net.minecraft.client.Minecraft;
@ -83,6 +84,7 @@ public class BookletUtils{
ArrayList<String> infoList = null;
for(BookletPage page : booklet.currentChapter.pages){
if(page != null && page.getItemStacksForPage() != null){
for(ItemStack stack : page.getItemStacksForPage()){
for(Achievement achievement : InitAchievements.achievementList){
if(stack != null && achievement.theItemStack != null && achievement.theItemStack.isItemEqual(stack)){
@ -105,6 +107,7 @@ public class BookletUtils{
}
}
}
}
if(infoList != null){
booklet.drawHoveringText(infoList, mouseX, mouseY);
@ -145,11 +148,11 @@ public class BookletUtils{
@SuppressWarnings("unchecked")
public static void doHoverTexts(GuiBooklet booklet, int mouseX, int mouseY){
//Achievements Hover Text
if(mouseX >= booklet.guiLeft+138 && mouseX <= booklet.guiLeft+138+7 && mouseY >= booklet.guiTop && mouseY <= booklet.guiTop+7){
if(booklet.buttonAchievements.func_146115_a()){
booklet.drawHoveringText(Collections.singletonList(EnumChatFormatting.GOLD+"Show Achievements"), mouseX, mouseY);
}
//Config Hover Text
if(mouseX >= booklet.guiLeft+138 && mouseX <= booklet.guiLeft+138+7 && mouseY >= booklet.guiTop+10 && mouseY <= booklet.guiTop+10+7){
else if(booklet.buttonConfig.func_146115_a()){
ArrayList list = new ArrayList();
list.add(EnumChatFormatting.GOLD+"Show Configuration GUI");
list.addAll(booklet.getFontRenderer().listFormattedStringToWidth("It is highly recommended that you restart your game after changing anything as that prevents possible bugs occuring!", GuiBooklet.TOOLTIP_SPLIT_LENGTH));
@ -157,15 +160,15 @@ public class BookletUtils{
}
//Twitter Hover Text
if(mouseX >= booklet.guiLeft && mouseX <= booklet.guiLeft+7 && mouseY >= booklet.guiTop && mouseY <= booklet.guiTop+7){
else if(booklet.buttonTwitter.func_146115_a()){
booklet.drawHoveringText(Collections.singletonList(EnumChatFormatting.GOLD+"Open @ActAddMod on Twitter in Browser"), mouseX, mouseY);
}
//Forum Hover Text
if(mouseX >= booklet.guiLeft && mouseX <= booklet.guiLeft+7 && mouseY >= booklet.guiTop+10 && mouseY <= booklet.guiTop+10+7){
else if(booklet.buttonForum.func_146115_a()){
booklet.drawHoveringText(Collections.singletonList(EnumChatFormatting.GOLD+"Open Minecraft Forum Post in Browser"), mouseX, mouseY);
}
//Update Checker Hover Text
if(mouseX >= booklet.guiLeft-11 && mouseX <= booklet.guiLeft-11+10 && mouseY >= booklet.guiTop-11 && mouseY <= booklet.guiTop-11+10){
else if(booklet.buttonUpdate.func_146115_a()){
ArrayList list = new ArrayList();
if(UpdateChecker.checkFailed){
list.add(IChatComponent.Serializer.func_150699_a(StringUtil.localize("info."+ModUtil.MOD_ID_LOWER+".update.failed")).getFormattedText());
@ -177,6 +180,13 @@ public class BookletUtils{
}
booklet.drawHoveringText(list, mouseX, mouseY);
}
else{
for(GuiButton button : booklet.bookmarkButtons){
if(button instanceof BookmarkButton && button.func_146115_a()){
((BookmarkButton)button).drawHover(mouseX, mouseY);
}
}
}
}
/**
@ -454,4 +464,71 @@ public class BookletUtils{
}
}
}
public static class BookmarkButton extends GuiButton{
public BookletChapter assignedChapter;
public BookletPage assignedPage;
public BookletEntry assignedEntry;
public int assignedPageInIndex;
private GuiBooklet booklet;
public BookmarkButton(int id, int x, int y, GuiBooklet booklet){
super(id, x, y, 16, 16, "");
this.booklet = booklet;
}
@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);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 120, 180-this.height+k*this.height, this.width, this.height);
this.mouseDragged(minecraft, x, y);
if(this.assignedEntry != null){
GL11.glPushMatrix();
BookletPage.renderItem(booklet, this.assignedChapter != null && this.assignedChapter.displayStack != null ? this.assignedChapter.displayStack : new ItemStack(InitItems.itemLexicon), this.xPosition+2, this.yPosition+2, 0.725F);
GL11.glPopMatrix();
}
}
}
public void onPressed(){
if(this.assignedEntry != null){
if(KeyUtil.isShiftPressed()){
this.assignedEntry = null;
this.assignedChapter = null;
this.assignedPage = null;
this.assignedPageInIndex = 1;
}
else{
openIndexEntry(this.booklet, this.assignedEntry, this.assignedPageInIndex, true);
openChapter(this.booklet, this.assignedChapter, this.assignedPage);
}
}
else{
if(this.booklet.currentIndexEntry != null){
this.assignedEntry = this.booklet.currentIndexEntry;
this.assignedChapter = this.booklet.currentChapter;
this.assignedPage = this.booklet.currentPage;
this.assignedPageInIndex = this.booklet.pageOpenInIndex;
}
}
}
public void drawHover(int mouseX, int mouseY){
String strg = this.assignedChapter == null ? (this.assignedEntry == null ? "None" : (this.assignedEntry.getLocalizedName()+", Page "+this.assignedPageInIndex)) : (this.assignedChapter.getLocalizedName()+", Page "+this.assignedPage.getID());
this.booklet.drawHoveringText(Collections.singletonList(strg), mouseX, mouseY);
}
}
}

View file

@ -37,17 +37,22 @@ public class GuiBooklet extends GuiScreen{
public static final ResourceLocation resLocHalloween = AssetUtil.getBookletGuiLocation("guiBookletHalloween");
public static final ResourceLocation resLocChristmas = AssetUtil.getBookletGuiLocation("guiBookletChristmas");
public static final ResourceLocation resLocValentine = AssetUtil.getBookletGuiLocation("guiBookletValentinesDay");
public static final int CHAPTER_BUTTONS_AMOUNT = 13;
public static final int TOOLTIP_SPLIT_LENGTH = 200;
public int xSize;
public int ySize;
public int guiLeft;
public int guiTop;
public BookletPage currentPage;
public BookletChapter currentChapter;
public BookletEntry currentIndexEntry;
public int pageOpenInIndex;
public int indexPageAmount;
public GuiButton buttonForward;
public GuiButton buttonBackward;
public GuiButton buttonPreviousScreen;
@ -58,7 +63,11 @@ public class GuiBooklet extends GuiScreen{
public GuiButton buttonAchievements;
public GuiButton buttonConfig;
public GuiButton[] chapterButtons = new GuiButton[CHAPTER_BUTTONS_AMOUNT];
public GuiButton[] bookmarkButtons = new GuiButton[8];
public GuiTextField searchField;
private int ticksElapsed;
private boolean mousePressed;
@ -194,6 +203,10 @@ public class GuiBooklet extends GuiScreen{
BookletUtils.openIndexEntry(this, null, 1, true);
}
}
//Handles Bookmark button
else if(button instanceof BookletUtils.BookmarkButton){
((BookletUtils.BookmarkButton)button).onPressed();
}
else{
BookletUtils.handleChapterButtonClick(this, button);
}
@ -211,10 +224,10 @@ public class GuiBooklet extends GuiScreen{
this.buttonBackward = new BookletUtils.TexturedButton(1, this.guiLeft-18, this.guiTop+this.ySize+2, 146, 0, 18, 10);
this.buttonList.add(this.buttonBackward);
this.buttonPreviousScreen = new BookletUtils.TexturedButton(2, this.guiLeft+this.xSize/2-7, this.guiTop+this.ySize+2, 182, 0, 15, 10);
this.buttonPreviousScreen = new BookletUtils.TexturedButton(2, this.guiLeft+this.xSize/2-7, this.guiTop+this.ySize+20, 182, 0, 15, 10);
this.buttonList.add(this.buttonPreviousScreen);
this.buttonPreviouslyOpenedGui = new BookletUtils.TexturedButton(3, this.guiLeft+this.xSize/3, this.guiTop+this.ySize+2, 245, 44, 11, 15);
this.buttonPreviouslyOpenedGui = new BookletUtils.TexturedButton(3, this.guiLeft+this.xSize/3, this.guiTop+this.ySize+20, 245, 44, 11, 15);
this.buttonList.add(this.buttonPreviouslyOpenedGui);
this.buttonUpdate = new BookletUtils.TexturedButton(4, this.guiLeft-11, this.guiTop-11, 245, 0, 11, 11);
@ -238,6 +251,12 @@ public class GuiBooklet extends GuiScreen{
this.buttonList.add(this.chapterButtons[i]);
}
for(int i = 0; i < this.bookmarkButtons.length; i++){
int x = this.guiLeft+xSize/2-(this.bookmarkButtons.length/2*16)+(i*16);
this.bookmarkButtons[i] = new BookletUtils.BookmarkButton(this.chapterButtons[this.chapterButtons.length-1].id+1+i, x, this.guiTop+this.ySize, this);
this.buttonList.add(this.bookmarkButtons[i]);
}
this.searchField = new GuiTextField(this.fontRendererObj, guiLeft+148, guiTop+162, 66, 10);
this.searchField.setMaxStringLength(30);
this.searchField.setEnableBackgroundDrawing(false);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB