From 19ee548771ae4cc6d0b4e0b02447c1388b80aa80 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 29 Aug 2015 10:59:03 +0200 Subject: [PATCH] Added Pages to Indexes to have more space for chapters available --- .../inventory/gui/booklet/BookletChapter.java | 2 +- .../inventory/gui/booklet/GuiBooklet.java | 83 +++++++++++++------ 2 files changed, 60 insertions(+), 25 deletions(-) diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/gui/booklet/BookletChapter.java b/src/main/java/ellpeck/actuallyadditions/inventory/gui/booklet/BookletChapter.java index 2135bc9ec..96b3ee71a 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/gui/booklet/BookletChapter.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/gui/booklet/BookletChapter.java @@ -8,10 +8,10 @@ public class BookletChapter{ public final IBookletPage[] pages; private final String unlocalizedName; public final BookletIndexEntry entry; - public int openPage; public BookletChapter(String unlocalizedName, BookletIndexEntry entry, IBookletPage... pages){ this.pages = pages.clone(); + this.unlocalizedName = unlocalizedName; entry.addChapter(this); this.entry = entry; diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/gui/booklet/GuiBooklet.java b/src/main/java/ellpeck/actuallyadditions/inventory/gui/booklet/GuiBooklet.java index 5a178a032..5ebff24ce 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/gui/booklet/GuiBooklet.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/gui/booklet/GuiBooklet.java @@ -31,6 +31,8 @@ public class GuiBooklet extends GuiScreen{ public IBookletPage currentPage; public BookletChapter currentChapter; public BookletIndexEntry currentIndexEntry; + public int pageOpenInIndex; + public int indexPageAmount; private static final int BUTTON_ACHIEVEMENTS_ID = -2; private static final int BUTTON_CONFIG_ID = -1; @@ -66,7 +68,7 @@ public class GuiBooklet extends GuiScreen{ this.currentPage = null; this.currentChapter = null; this.currentIndexEntry = null; - this.openIndexEntry(null); + this.openIndexEntry(null, 1); } private GuiButton getButton(int id){ @@ -88,15 +90,22 @@ public class GuiBooklet extends GuiScreen{ if(this.currentChapter == null){ this.drawCenteredString(this.fontRendererObj, this.currentIndexEntry.getLocalizedName(), this.guiLeft+this.xSize/2, this.guiTop-8, StringUtil.DECIMAL_COLOR_WHITE); } - else + else{ this.drawCenteredString(this.fontRendererObj, this.currentChapter.getLocalizedName(), this.guiLeft+this.xSize/2, this.guiTop-8, StringUtil.DECIMAL_COLOR_WHITE); + } } - else + else{ this.drawCenteredString(this.fontRendererObj, StringUtil.localize("itemGroup."+ModUtil.MOD_ID_LOWER), this.guiLeft+this.xSize/2, this.guiTop-8, StringUtil.DECIMAL_COLOR_WHITE); + } - if(this.currentIndexEntry != null && this.currentChapter != null && this.currentPage != null){ - this.drawCenteredString(this.unicodeRenderer, this.currentPage.getID()+"/"+this.currentChapter.pages.length, this.guiLeft+this.xSize/2, this.guiTop+172, StringUtil.DECIMAL_COLOR_WHITE); - this.currentPage.renderPre(this, x, y); + if(this.currentIndexEntry != null){ + if(this.currentChapter != null && this.currentPage != null){ + this.drawCenteredString(this.unicodeRenderer, this.currentPage.getID()+"/"+this.currentChapter.pages.length, this.guiLeft+this.xSize/2, this.guiTop+172, StringUtil.DECIMAL_COLOR_WHITE); + this.currentPage.renderPre(this, x, y); + } + else{ + this.drawCenteredString(this.unicodeRenderer, this.pageOpenInIndex+"/"+this.indexPageAmount, this.guiLeft+this.xSize/2, this.guiTop+172, StringUtil.DECIMAL_COLOR_WHITE); + } } super.drawScreen(x, y, f); @@ -146,60 +155,86 @@ public class GuiBooklet extends GuiScreen{ mc.displayGuiScreen(new GuiAAAchievements(this, mc.thePlayer.getStatFileWriter())); } else if(button.id == BUTTON_FORWARD_ID){ - IBookletPage page = this.getNextPage(this.currentChapter, this.currentPage); - if(page != null) this.currentPage = page; + if(this.currentIndexEntry != null){ + if(this.currentPage != null){ + IBookletPage page = this.getNextPage(this.currentChapter, this.currentPage); + if(page != null) this.currentPage = page; + } + else{ + this.openIndexEntry(this.currentIndexEntry, this.pageOpenInIndex+1); + } + } } else if(button.id == BUTTON_BACK_ID){ - IBookletPage page = this.getPrevPage(this.currentChapter, this.currentPage); - if(page != null) this.currentPage = page; + if(this.currentIndexEntry != null){ + if(this.currentPage != null){ + IBookletPage page = this.getPrevPage(this.currentChapter, this.currentPage); + if(page != null) this.currentPage = page; + } + else{ + this.openIndexEntry(this.currentIndexEntry, this.pageOpenInIndex-1); + } + } } else if(button.id == BUTTON_RETURN_ID){ if(this.currentChapter != null){ - this.openIndexEntry(this.currentChapter.entry); - this.currentChapter = null; + this.openIndexEntry(this.currentChapter.entry, this.pageOpenInIndex); + } + else{ + this.openIndexEntry(null, 1); } - else this.openIndexEntry(null); } else if(button.id >= CHAPTER_BUTTONS_START){ int actualButton = button.id-CHAPTER_BUTTONS_START; if(this.currentIndexEntry != null){ if(this.currentChapter == null){ if(actualButton < this.currentIndexEntry.chapters.size()){ - this.openChapter(currentIndexEntry.chapters.get(actualButton)); + this.openChapter(currentIndexEntry.chapters.get(actualButton+(12*this.pageOpenInIndex-12))); } } } else{ if(actualButton < InitBooklet.entries.size()){ - this.openIndexEntry(InitBooklet.entries.get(actualButton)); + this.openIndexEntry(InitBooklet.entries.get(actualButton), 1); } } } if(button.id == BUTTON_FORWARD_ID || button.id == BUTTON_BACK_ID){ - this.getButton(BUTTON_FORWARD_ID).visible = this.getNextPage(this.currentChapter, this.currentPage) != null; - this.getButton(BUTTON_BACK_ID).visible = this.getPrevPage(this.currentChapter, this.currentPage) != null; + if(this.currentChapter != null && this.currentIndexEntry != null){ + if(this.currentPage != null){ + this.getButton(BUTTON_FORWARD_ID).visible = this.getNextPage(this.currentChapter, this.currentPage) != null; + this.getButton(BUTTON_BACK_ID).visible = this.getPrevPage(this.currentChapter, this.currentPage) != null; + } + } } } - private void openIndexEntry(BookletIndexEntry entry){ + private void openIndexEntry(BookletIndexEntry entry, int page){ + this.currentPage = null; + this.currentChapter = null; + this.currentIndexEntry = entry; + this.indexPageAmount = entry == null ? 1 : entry.chapters.size()/12+1; + this.pageOpenInIndex = entry == null ? 1 : (this.indexPageAmount <= page ? this.indexPageAmount : page); this.getButton(BUTTON_RETURN_ID).visible = entry != null; - this.getButton(BUTTON_FORWARD_ID).visible = false; - this.getButton(BUTTON_BACK_ID).visible = false; + this.getButton(BUTTON_FORWARD_ID).visible = this.pageOpenInIndex < this.indexPageAmount; + this.getButton(BUTTON_BACK_ID).visible = this.pageOpenInIndex > 1; for(int i = 0; i < 12; i++){ GuiButton button = this.getButton(CHAPTER_BUTTONS_START+i); if(entry == null){ - boolean entryExists = InitBooklet.entries.size() > i; + boolean entryExists = InitBooklet.entries.size() > i+(12*this.pageOpenInIndex-12); button.visible = entryExists; - if(entryExists) button.displayString = InitBooklet.entries.get(i).getLocalizedName(); + if(entryExists){ + button.displayString = InitBooklet.entries.get(i+(12*this.pageOpenInIndex-12)).getLocalizedName(); + } } else{ - boolean entryExists = entry.chapters.size() > i; + boolean entryExists = entry.chapters.size() > i+(12*this.pageOpenInIndex-12); button.visible = entryExists; - if(entryExists) button.displayString = entry.chapters.get(i).getLocalizedName(); + if(entryExists) button.displayString = entry.chapters.get(i+(12*this.pageOpenInIndex-12)).getLocalizedName(); } } }