Added feature creep to the Lexica Botania in the form of a "View Online" button as well as a Lookup History (similar to your browser's history).

This commit is contained in:
Lizbeth Rika committed 2015-03-02 19:00:46 +00:00
1 parent 21ebe8f971
commit 1fda5aa3cd
8 files changed
+185 -14

No files matched your search

@@ -37,6 +37,7 @@ import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.client.core.proxy.ClientProxy;
import vazkii.botania.client.gui.lexicon.button.GuiButtonBookmark;
import vazkii.botania.client.gui.lexicon.button.GuiButtonCategory;
import vazkii.botania.client.gui.lexicon.button.GuiButtonHistory;
import vazkii.botania.client.gui.lexicon.button.GuiButtonInvisible;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.core.handler.SheddingHandler;
@@ -49,7 +50,9 @@ public class GuiLexicon extends GuiScreen {
public static ItemStack stackUsed;
private static final int[] KONAMI_CODE = { 200, 200, 208, 208, 203, 205, 203, 205, 48, 30 };
public static final int BOOKMARK_START = 1337;
public static final int MAX_BOOKMARK_COUNT = 8;
public static List<GuiLexicon> bookmarks = new ArrayList();
boolean bookmarksNeedPopulation = false;
@@ -142,7 +145,8 @@ public class GuiLexicon extends GuiScreen {
GL11.glScalef(2F, 2F, 1F);
}
drawHeader();
if(isMainPage())
drawHeader();
if(bookmarksNeedPopulation) {
populateBookmarks();
@@ -218,12 +222,19 @@ public class GuiLexicon extends GuiScreen {
fontRendererObj.drawSplitString(String.format(StatCollector.translateToLocal("botania.gui.lexicon.header"), ItemLexicon.getEdition()), left + 18, top + 12, 110, 0);
fontRendererObj.setUnicodeFlag(unicode);
}
boolean isMainPage() {
return true;
}
@Override
protected void actionPerformed(GuiButton par1GuiButton) {
if(par1GuiButton.id >= BOOKMARK_START)
handleBookmark(par1GuiButton);
else if(par1GuiButton instanceof GuiButtonCategory) {
if(par1GuiButton.id >= BOOKMARK_START) {
if(par1GuiButton.id >= BOOKMARK_START + MAX_BOOKMARK_COUNT) {
mc.displayGuiScreen(new GuiLexiconHistory());
ClientTickHandler.notifyPageChange();
} else handleBookmark(par1GuiButton);
} else if(par1GuiButton instanceof GuiButtonCategory) {
LexiconCategory category = ((GuiButtonCategory) par1GuiButton).getCategory();
mc.displayGuiScreen(new GuiLexiconIndex(category));
@@ -316,12 +327,15 @@ public class GuiLexicon extends GuiScreen {
if(lex.getTitle().equals(getTitle()))
thisExists = true;
boolean addEnabled = len < 8 && this instanceof IParented && !thisExists;
boolean addEnabled = len < MAX_BOOKMARK_COUNT && this instanceof IParented && !thisExists;
for(int i = 0; i < len + (addEnabled ? 1 : 0); i++) {
boolean isAdd = i == bookmarks.size();
GuiLexicon gui = isAdd ? null : bookmarks.get(i);
buttonList.add(new GuiButtonBookmark(BOOKMARK_START + i, left + 138, top + 18 + 14 * i, gui == null ? this : gui, gui == null ? "+" : gui.getTitle()));
}
if(isMainPage())
buttonList.add(new GuiButtonHistory(BOOKMARK_START + MAX_BOOKMARK_COUNT, left + 138, top + guiHeight - 24, StatCollector.translateToLocal("botaniamisc.history"), this));
}
public static void startTutorial() {
@@ -385,7 +399,6 @@ public class GuiLexicon extends GuiScreen {
mc.setIngameFocus();
}
System.out.println(par2);
if(par2 == KONAMI_CODE[konamiIndex]) {
konamiIndex++;
if(konamiIndex >= KONAMI_CODE.length) {
@@ -402,13 +415,15 @@ public class GuiLexicon extends GuiScreen {
return true;
if(gui.isIndex()) {
GuiLexiconIndex indexGui=(GuiLexiconIndex)gui;
if(indexGui.category==null)
if(indexGui.category == null)
return true;
return BotaniaAPI.getAllCategories().contains(indexGui.category);
}
GuiLexiconEntry entryGui=(GuiLexiconEntry)gui;
GuiLexiconEntry entryGui = (GuiLexiconEntry) gui;
if(!BotaniaAPI.getAllEntries().contains(entryGui.entry))
return false;
return entryGui.page < entryGui.entry.pages.size();
}
}
@@ -10,6 +10,10 @@
*/
package vazkii.botania.client.gui.lexicon;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import net.minecraft.client.Minecraft;
@@ -30,6 +34,7 @@ import vazkii.botania.client.core.handler.ClientTickHandler;
import vazkii.botania.client.gui.lexicon.button.GuiButtonBackWithShift;
import vazkii.botania.client.gui.lexicon.button.GuiButtonPage;
import vazkii.botania.client.gui.lexicon.button.GuiButtonShare;
import vazkii.botania.client.gui.lexicon.button.GuiButtonViewOnline;
public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry, IParented {
@@ -39,7 +44,7 @@ public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry, IPa
String title;
String subtitle;
GuiButton leftButton, rightButton, backButton, shareButton;
GuiButton leftButton, rightButton, backButton;
public GuiLexiconEntry(LexiconEntry entry, GuiScreen parent) {
this.entry = entry;
@@ -58,7 +63,8 @@ public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry, IPa
buttonList.add(backButton = new GuiButtonBackWithShift(0, left + guiWidth / 2 - 8, top + guiHeight + 2));
buttonList.add(leftButton = new GuiButtonPage(1, left, top + guiHeight - 10, false));
buttonList.add(rightButton = new GuiButtonPage(2, left + guiWidth - 18, top + guiHeight - 10, true));
buttonList.add(shareButton = new GuiButtonShare(3, left + guiWidth - 6, top - 2));
buttonList.add(new GuiButtonShare(3, left + guiWidth - 6, top - 2));
buttonList.add(new GuiButtonViewOnline(4, left - 8, top + 8));
if(!GuiLexicon.isValidLexiconGui(this)) {
currentOpenLexicon = new GuiLexicon();
@@ -71,6 +77,7 @@ public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry, IPa
page.onOpened(this);
updatePageButtons();
GuiLexiconHistory.visit(entry);
}
@Override
@@ -84,8 +91,8 @@ public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry, IPa
}
@Override
void drawHeader() {
// NO-OP
boolean isMainPage() {
return false;
}
@Override
@@ -140,6 +147,13 @@ public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry, IPa
mc.ingameGUI.getChatGUI().addToSentMessages(cmd);
mc.thePlayer.sendChatMessage(cmd);
break;
case 4 :
try {
if(Desktop.isDesktopSupported())
Desktop.getDesktop().browse(new URI("http://botaniamod.net/lexicon.php#" + entry.unlocalizedName));
} catch(Exception e) {
e.printStackTrace();
}
}
updatePageButtons();
@@ -0,0 +1,46 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Mar 2, 2015, 6:27:58 PM (GMT)]
*/
package vazkii.botania.client.gui.lexicon;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.util.StatCollector;
import vazkii.botania.api.lexicon.ILexicon;
import vazkii.botania.api.lexicon.LexiconEntry;
public class GuiLexiconHistory extends GuiLexiconIndex {
public static List<LexiconEntry> history = new ArrayList();
public GuiLexiconHistory() {
super(null);
title = StatCollector.translateToLocal("botaniamisc.historyLong");
}
@Override
void buildEntries() {
entriesToDisplay.clear();
ILexicon lex = (ILexicon) stackUsed.getItem();
for(int i = history.size() - 1; i >= 0; i--) {
LexiconEntry entry = history.get(i);
if(lex.isKnowledgeUnlocked(stackUsed, entry.getKnowledgeType()) && StatCollector.translateToLocal(entry.getUnlocalizedName()).toLowerCase().contains(searchField.getText().toLowerCase().trim()))
entriesToDisplay.add(entry);
}
}
public static void visit(LexiconEntry entry) {
if(history.contains(entry))
history.remove(entry);
history.add(entry);
}
}
@@ -52,8 +52,8 @@ public class GuiLexiconIndex extends GuiLexicon implements IParented {
}
@Override
void drawHeader() {
// NO-OP
boolean isMainPage() {
return false;
}
@Override
@@ -0,0 +1,46 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Mar 2, 2015, 6:01:26 PM (GMT)]
*/
package vazkii.botania.client.gui.lexicon.button;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.client.gui.lexicon.GuiLexicon;
public class GuiButtonHistory extends GuiButtonLexicon {
GuiLexicon gui;
public GuiButtonHistory(int par1, int par2, int par3, String str, GuiLexicon gui) {
super(par1, par2, par3, gui.bookmarkWidth(str) + 5, 11, str);
this.gui = gui;
}
@Override
public void drawButton(Minecraft mc, int par2, int par3) {
gui.drawBookmark(xPosition, yPosition, displayString, false);
field_146123_n = par2 >= xPosition && par3 >= yPosition && par2 < xPosition + width && par3 < yPosition + height;
int k = getHoverState(field_146123_n);
List<String> tooltip = new ArrayList();
tooltip.add(StatCollector.translateToLocal("botaniamisc.historyLong"));
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("botaniamisc.historyDesc"));
int tooltipY = (tooltip.size() + 1) * 5;
if(k == 2)
RenderHelper.renderTooltip(par2, par3 + tooltipY, tooltip);
}
}
@@ -0,0 +1,46 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Mar 2, 2015, 5:34:05 PM (GMT)]
*/
package vazkii.botania.client.gui.lexicon.button;
import java.util.Arrays;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.client.gui.lexicon.GuiLexicon;
public class GuiButtonViewOnline extends GuiButtonLexicon {
public GuiButtonViewOnline(int id, int x, int y) {
super(id, x, y, 11, 11, "");
}
@Override
public void drawButton(Minecraft par1Minecraft, int par2, int par3) {
field_146123_n = par2 >= xPosition && par3 >= yPosition && par2 < xPosition + width && par3 < yPosition + height;
int k = getHoverState(field_146123_n);
par1Minecraft.renderEngine.bindTexture(GuiLexicon.texture);
GL11.glColor4f(1F, 1F, 1F, 1F);
drawTexturedModalRect(xPosition, yPosition, k == 2 ? 41 : 30, 200, 11, 11);
List<String> tooltip = Arrays.asList(EnumChatFormatting.AQUA + StatCollector.translateToLocal("botaniamisc.viewOnline"));
int tooltipY = (tooltip.size() - 1) * 10;
if(k == 2)
RenderHelper.renderTooltip(par2, par3 + tooltipY, tooltip);
}
}
@@ -86,6 +86,10 @@ botaniamisc.tutorialEnded=Your tutorial is over, you should now have a basic ide
botaniamisc.cosmeticBauble=&oCosmetic
botaniamisc.hasCosmetic=&oHas Cosmetic Override: &r%s
botaniamisc.typeToSearch=(type to search)
botaniamisc.viewOnline=View Online
botaniamisc.history=History
botaniamisc.historyLong=Lookup History
botaniamisc.historyDesc=See the last entries visited
# NEI INTEGRATION
botania.nei.brewery=Botanical Brewery
Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB