Actual page rendering, woo.

This commit is contained in:
Vasco Lavos committed 2014-01-16 17:36:55 +00:00
1 parent 44f27ff044
commit 1a5e1778ab
7 files changed
+150 -7

No files matched your search

@@ -30,4 +30,23 @@ public interface IGuiLexiconEntry {
*/
public int getPageOn();
/**
* Gets the leftmost part of the GUI.
*/
public int getLeft();
/**
* Gets the topmost part of the GUI.
*/
public int getTop();
/**
* Gets the GUI's width.
*/
public int getWidth();
/**
* Gets the GUI's height
*/
public int getHeight();
}
@@ -24,10 +24,10 @@ public abstract class LexiconPage {
/**
* Does the rendering for this page.
* @param gui The active GuiScreen
* @param x The leftmost part of the gui.
* @param y The top part of the gui.
* @param mx The mouse's relative X position.
* @param my The mouse's relative Y position.
*/
public abstract void renderScreen(IGuiLexiconEntry gui, int x, int y);
public abstract void renderScreen(IGuiLexiconEntry gui, int mx, int my);
public String getUnlocalizedName() {
return unlocalizedName;
@@ -0,0 +1,43 @@
/**
* 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 a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Jan 16, 2014, 5:30:52 PM (GMT)]
*/
package vazkii.botania.client.core.helper;
public class FontHelper {
public static boolean isFormatColor(char par0) {
return par0 >= 48 && par0 <= 57 || par0 >= 97 && par0 <= 102 || par0 >= 65 && par0 <= 70;
}
public static boolean isFormatSpecial(char par0) {
return par0 >= 107 && par0 <= 111 || par0 >= 75 && par0 <= 79 || par0 == 114 || par0 == 82;
}
public static String getFormatFromString(String par0Str) {
String s1 = "";
int i = -1;
int j = par0Str.length();
while ((i = par0Str.indexOf(167, i + 1)) != -1) {
if (i < j - 1) {
char c0 = par0Str.charAt(i + 1);
if (isFormatColor(c0))
s1 = "\u00a7" + c0;
else if (isFormatSpecial(c0))
s1 = s1 + "\u00a7" + c0;
}
}
return s1;
}
}
@@ -15,6 +15,7 @@ import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.StatCollector;
import vazkii.botania.api.LexiconEntry;
import vazkii.botania.api.internal.IGuiLexiconEntry;
import vazkii.botania.api.page.LexiconPage;
import vazkii.botania.client.gui.button.GuiButtonBack;
import vazkii.botania.client.gui.button.GuiButtonPage;
@@ -94,6 +95,29 @@ public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry {
@Override
public void drawScreen(int par1, int par2, float par3) {
super.drawScreen(par1, par2, par3);
LexiconPage page = entry.pages.get(this.page);
page.renderScreen(this, par1, par2);
}
@Override
public int getLeft() {
return left;
}
@Override
public int getTop() {
return top;
}
@Override
public int getWidth() {
return guiWidth;
}
@Override
public int getHeight() {
return guiHeight;
}
}
@@ -26,7 +26,7 @@ public class BLexiconEntry extends LexiconEntry {
@Override
public void setLexiconPages(LexiconPage... pages) {
for(LexiconPage page : pages)
page.unlocalizedName = "botania.page." + getUnlocalizedName() + page.unlocalizedName;
page.unlocalizedName = "botania.page." + getLazyUnlocalizedName() + page.unlocalizedName;
super.setLexiconPages(pages);
}
@@ -35,5 +35,9 @@ public class BLexiconEntry extends LexiconEntry {
public String getUnlocalizedName() {
return "botania.entry." + super.getUnlocalizedName();
}
public String getLazyUnlocalizedName() {
return super.getUnlocalizedName();
}
}
@@ -11,8 +11,17 @@
*/
package vazkii.botania.common.lexicon.page;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper;
import net.minecraft.util.StatCollector;
import vazkii.botania.api.internal.IGuiLexiconEntry;
import vazkii.botania.api.page.LexiconPage;
import vazkii.botania.client.core.helper.FontHelper;
public class PageText extends LexiconPage {
@@ -21,8 +30,51 @@ public class PageText extends LexiconPage {
}
@Override
public void renderScreen(IGuiLexiconEntry gui, int x, int y) {
// TODO
public void renderScreen(IGuiLexiconEntry gui, int mx, int my) {
FontRenderer renderer = Minecraft.getMinecraft().fontRenderer;
boolean unicode = renderer.getUnicodeFlag();
renderer.setUnicodeFlag(true);
String text = StatCollector.translateToLocal(getUnlocalizedName()).replaceAll("&", "\u00a7");
String[] textEntries = text.split("<br>");
int width = gui.getWidth() - 30;
int x = gui.getLeft() + 16;
int y = gui.getTop();
String lastFormat = "";
for(String s : textEntries) {
List<String> wrappedLines = new ArrayList();
String workingOn = "";
int i = 0;
String[] tokens = s.split(" ");
for(String s1 : tokens) {
String format = FontHelper.getFormatFromString(s1);
if(MathHelper.stringNullOrLengthZero(format))
format = lastFormat;
if(renderer.getStringWidth(workingOn + " " + s1) >= width) {
wrappedLines.add(workingOn);
workingOn = "";
}
workingOn = workingOn + format + " " + s1;
if(i == tokens.length - 1)
wrappedLines.add(workingOn);
++i;
lastFormat = format;
}
for(String s1 : wrappedLines) {
y += 10;
renderer.drawString(s1, x, y, 0);
}
y += 10;
}
renderer.setUnicodeFlag(unicode);
}
}
+1
View File
@@ -19,5 +19,6 @@ botania.category.misc=Miscellaneous
# LEXICON ENTRIES
botania.entry.world=The World
botania.page.world0=The world is fun.<br>This line of text is very long so I can test if line wrap works fine, woo.<br>And this one is kinda long too. &eTesting colors. &cMore colors.
botania.entry.basicConcepts=Basic Concepts
botania.entry.gettingStarted=Getting Started