package mods.tinker.tconstruct.client.gui; import mods.tinker.tconstruct.client.TProxyClient; import mods.tinker.tconstruct.library.TConstructClientRegistry; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiParticle; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.item.ItemStack; import org.lwjgl.opengl.GL11; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class GuiManual extends GuiScreen { ItemStack itemstackBook; Document manual; private RenderItem renderitem = new RenderItem(); int bookImageWidth = 206; int bookImageHeight = 200; int bookTotalPages = 1; int currentPage; int maxPages; private TurnPageButton buttonNextPage; private TurnPageButton buttonPreviousPage; String pageLeftType; String textLeft; ItemStack[] iconsLeft; String[] multiTextLeft; String pageRightType; String textRight; ItemStack[] iconsRight; String[] multiTextRight; //CustomFont font; //int guiscale; public GuiManual(ItemStack stack, Document doc) { this.mc = Minecraft.getMinecraft(); this.itemstackBook = stack; currentPage = 0; //Stack page manual = doc; //font = new CustomFont(mc, "Times New Roman", 16); } @Override public void setWorldAndResolution (Minecraft minecraft, int w, int h) { this.guiParticles = new GuiParticle(minecraft); this.mc = minecraft; this.fontRenderer = TProxyClient.smallFontRenderer; this.width = w; this.height = h; this.buttonList.clear(); this.initGui(); /*int scale = 0; while (width / (scale + 1) >= 160) { scale++; } guiscale = scale;*/ //font.scale = scale; } public void initGui () { maxPages = manual.getElementsByTagName("page").getLength(); updateText(); int xPos = (this.width) / 2; this.buttonList.add(this.buttonNextPage = new TurnPageButton(1, xPos + bookImageWidth - 50, 180, true)); this.buttonList.add(this.buttonPreviousPage = new TurnPageButton(2, xPos - bookImageWidth + 24, 180, false)); } protected void actionPerformed (GuiButton button) { if (button.enabled) { if (button.id == 1) currentPage += 2; if (button.id == 2) currentPage -= 2; updateText(); } } void updateText () { if (currentPage >= maxPages - 1) currentPage = maxPages - 2; if (currentPage % 2 == 1) currentPage--; if (currentPage < 0) currentPage = 0; NodeList nList = manual.getElementsByTagName("page"); Node node = nList.item(currentPage); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; pageLeftType = element.getAttribute("type"); if (pageLeftType.equals("text") || pageLeftType.equals("intro")) { NodeList nodes = element.getElementsByTagName("text"); if (nodes != null) textLeft = nodes.item(0).getTextContent(); } else if (pageLeftType.equals("contents")) { NodeList nodes = element.getElementsByTagName("link"); multiTextLeft = new String[nodes.getLength()]; iconsLeft = new ItemStack[nodes.getLength()]; for (int i = 0; i < nodes.getLength(); i++) { NodeList children = nodes.item(i).getChildNodes(); multiTextLeft[i] = children.item(0).getTextContent(); iconsLeft[i] = TConstructClientRegistry.getManualIcon(children.item(1).getTextContent()); } } } node = nList.item(currentPage + 1); if (node != null && node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; pageRightType = element.getAttribute("type"); if (pageRightType.equals("text") || pageRightType.equals("intro")) { NodeList nodes = element.getElementsByTagName("text"); if (nodes != null) textRight = nodes.item(0).getTextContent(); } else if (pageRightType.equals("contents")) { //Minecraft.getMinecraft().getLogAgent().logInfo("Contents!"); NodeList nodes = element.getElementsByTagName("link"); multiTextRight = new String[nodes.getLength()]; iconsRight = new ItemStack[nodes.getLength()]; for (int i = 0; i < nodes.getLength(); i++) { NodeList children = nodes.item(i).getChildNodes(); multiTextRight[i] = children.item(1).getTextContent(); iconsRight[i] = TConstructClientRegistry.getManualIcon(children.item(3).getTextContent()); } } } else { pageRightType = "blank"; textRight = null; } } public void drawScreen (int par1, int par2, float par3) { //int texID = this.mc.renderEngine.getTexture(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.renderEngine.bindTexture("/mods/tinker/textures/gui/bookright.png"); int localWidth = (this.width) / 2; byte localHeight = 8; this.drawTexturedModalRect(localWidth, localHeight, 0, 0, this.bookImageWidth, this.bookImageHeight); //texID = this.mc.renderEngine.getTexture("/mods/tinker/textures/gui/bookleft.png"); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); //this.mc.renderEngine.bindTexture(texID); this.mc.renderEngine.bindTexture("/mods/tinker/textures/gui/bookleft.png"); localWidth = localWidth - this.bookImageWidth; this.drawTexturedModalRect(localWidth, localHeight, 256 - this.bookImageWidth, 0, this.bookImageWidth, this.bookImageHeight); super.drawScreen(par1, par2, par3); //if (textLeft != null) //{ if (pageLeftType.equals("text")) { if (textLeft != null) drawTextPage(textLeft, localWidth + 16, localHeight + 12); } else if (pageLeftType.equals("intro")) { if (textLeft != null) drawTitlePage(textLeft, localWidth + 16, localHeight + 12); } else if (pageLeftType.equals("contents")) drawContentTablePage(iconsLeft, localWidth + 16, localHeight + 12); //} //if (textRight != null) //{ if (pageRightType.equals("text")) { if (textRight != null) drawTextPage(textRight, localWidth + 220, localHeight + 12); } else if (pageRightType.equals("intro")) { if (textRight != null) drawTitlePage(textRight, localWidth + 220, localHeight + 12); } else if (pageRightType.equals("contents")) drawContentTablePage(iconsRight, localWidth + 220, localHeight + 12); //} } public void drawTextPage (String text, int localWidth, int localHeight) { this.fontRenderer.drawSplitString(text, localWidth, localHeight, 178, 0); } public void drawTitlePage (String text, int localWidth, int localHeight) { this.fontRenderer.drawSplitString(text, localWidth, localHeight, 178, 0); } public void drawContentTablePage (ItemStack[] icons, int localWidth, int localHeight) { this.fontRenderer.drawString("\u00a7nTable of Contents", localWidth+50, localHeight+4, 0); for (int i = 0; i < icons.length; i++) { renderitem.renderItemIntoGUI(fontRenderer, mc.renderEngine, icons[i], localWidth+16, localHeight + 18*i + 18); this.fontRenderer.drawString(multiTextRight[i], localWidth+38, localHeight + 18*i + 18, 0); } } }