From f56f78487baef7b0b8045b7fcca3eee21a274fd6 Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Mon, 20 Jan 2014 15:46:19 +0000 Subject: [PATCH] Added pages to the Lexicon Index. Also alphabetical sorting. --- MODSRC/vazkii/botania/api/LexiconEntry.java | 8 --- .../botania/client/gui/GuiLexiconIndex.java | 56 ++++++++++++++++--- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/MODSRC/vazkii/botania/api/LexiconEntry.java b/MODSRC/vazkii/botania/api/LexiconEntry.java index 94a01d1bb..9803c3d67 100644 --- a/MODSRC/vazkii/botania/api/LexiconEntry.java +++ b/MODSRC/vazkii/botania/api/LexiconEntry.java @@ -48,12 +48,4 @@ public class LexiconEntry { public void addPage(LexiconPage page) { pages.add(page); } - - /** - * Should this entry be displayed in the list of entries? - */ - public boolean shouldBeDisplayed(GuiScreen screen, EntityPlayer player) { - return true; - } - } diff --git a/MODSRC/vazkii/botania/client/gui/GuiLexiconIndex.java b/MODSRC/vazkii/botania/client/gui/GuiLexiconIndex.java index 5ab8b3f78..ae5c81f38 100644 --- a/MODSRC/vazkii/botania/client/gui/GuiLexiconIndex.java +++ b/MODSRC/vazkii/botania/client/gui/GuiLexiconIndex.java @@ -11,6 +11,9 @@ */ package vazkii.botania.client.gui; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import net.minecraft.client.gui.GuiButton; @@ -19,6 +22,7 @@ import vazkii.botania.api.LexiconCategory; import vazkii.botania.api.LexiconEntry; import vazkii.botania.client.gui.button.GuiButtonBack; import vazkii.botania.client.gui.button.GuiButtonInvisible; +import vazkii.botania.client.gui.button.GuiButtonPage; public class GuiLexiconIndex extends GuiLexicon { @@ -26,6 +30,10 @@ public class GuiLexiconIndex extends GuiLexicon { String title; int page = 0; + GuiButton leftButton, rightButton; + + List entriesToDisplay = new ArrayList(); + public GuiLexiconIndex(LexiconCategory category) { this.category = category; title = StatCollector.translateToLocal(category.getUnlocalizedName()); @@ -45,14 +53,29 @@ public class GuiLexiconIndex extends GuiLexicon { public void initGui() { super.initGui(); buttonList.add(new GuiButtonBack(12, left + guiWidth / 2 - 8, top + guiHeight + 2)); + buttonList.add(leftButton = new GuiButtonPage(13, left, top + guiHeight - 10, false)); + buttonList.add(rightButton = new GuiButtonPage(14, left + guiWidth - 18, top + guiHeight - 10, true)); + + entriesToDisplay.clear(); + entriesToDisplay.addAll(category.entries); + Collections.sort(entriesToDisplay, new Comparator() { + + @Override + public int compare(LexiconEntry arg0, LexiconEntry arg1) { + return StatCollector.translateToLocal(arg0.getUnlocalizedName()).compareTo(StatCollector.translateToLocal(arg1.getUnlocalizedName())); + } + + }); + + updatePageButtons(); + populateIndex(); } @Override void populateIndex() { - List entryList = category.entries; - for(int i = 0; i < 12; i++) { - GuiButtonInvisible button = (GuiButtonInvisible) buttonList.get(i); - LexiconEntry entry = i >= entryList.size() ? null : entryList.get(i); + for(int i = page * 12; i < (page + 1) * 12; i++) { + GuiButtonInvisible button = (GuiButtonInvisible) buttonList.get(i - page * 12); + LexiconEntry entry = i >= entriesToDisplay.size() ? null : entriesToDisplay.get(i); if(entry != null) button.displayString = StatCollector.translateToLocal(entry.getUnlocalizedName()); else button.displayString = ""; @@ -61,15 +84,32 @@ public class GuiLexiconIndex extends GuiLexicon { @Override protected void actionPerformed(GuiButton par1GuiButton) { - if(par1GuiButton.id == 12) + switch(par1GuiButton.id) { + case 12 : mc.displayGuiScreen(new GuiLexicon()); - else { + break; + case 13 : + page--; + updatePageButtons(); + populateIndex(); + break; + case 14 : + page++; + updatePageButtons(); + populateIndex(); + break; + default : int index = par1GuiButton.id + page * 12; - if(index >= category.entries.size()) + if(index >= entriesToDisplay.size()) return; - LexiconEntry entry = category.entries.get(index); + LexiconEntry entry = entriesToDisplay.get(index); mc.displayGuiScreen(new GuiLexiconEntry(entry, this)); } } + + public void updatePageButtons() { + leftButton.enabled = page != 0; + rightButton.enabled = page < (entriesToDisplay.size() - 1) / 12; + } }