package ihl.guidebook; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; import org.lwjgl.opengl.GL11; import org.xml.sax.SAXException; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.texture.ITextureObject; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import ihl.IHLMod; import ihl.datanet.GuiInvisibleButton; import ihl.utils.IHLRenderUtils; public class IHLGuidebookGui extends GuiContainer { public IHLGuidebookContainer container; private static final ResourceLocation background = new ResourceLocation("ihl", "textures/gui/GUIGuidebook.png"); public Map linksCoordinatesMap = new HashMap(); private GuiInvisibleButton prevPageAreaButton; private GuiInvisibleButton nextPageAreaButton; private String title; private String[] localisedContent=new String[2];;// By text block and row private ResourceLocation[] resourceLocationCache = new ResourceLocation[16];//By section number private int currentSection=0; private int textBlockNumberOnPageTurn=0; private int stringNumberOnPageTurn=0; private final int titleX=25; private final int titleY=7; private final int textBlockWidth=104; private final int textBlockX1=20; private final int textBlockY1=38; private final int textBlockX2=130; private final int textBlockY2=5; private final int textBlockMaxY=200; private int stringHeight=10; private int textRowInRightPage=0; private int textBlockInRightPage=0; private int textRowInNextPage=0; private int textBlockInNextPage=0; private int[] textRowStart=new int[2]; private int textBlockStart=0; private int pictureWidth; private int pictureHeight; private int maxSection=0; public IHLGuidebookGui(IHLGuidebookContainer container1) { super(container1); this.container = container1; this.xSize=this.container.xSize; this.ySize=this.container.ySize; } @Override public void initGui() { super.initGui(); int x = (width - xSize) / 2; int y = (height - ySize) / 2; prevPageAreaButton = new GuiInvisibleButton(0, x, y, xSize/2, 162, linksCoordinatesMap, buttonList); nextPageAreaButton = new GuiInvisibleButton(1, x+xSize/2, y, xSize/2, 162, linksCoordinatesMap, buttonList); this.clear(); try { IHLMod.xmlparser.setupGuidebookGUI(this, 0); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } @Override public void actionPerformed(GuiButton button) { super.actionPerformed(button); switch(button.id) { case 0: currentSection--; if(currentSection<0) { currentSection=this.maxSection; } this.textBlockStart=0; this.textRowStart[0]=0; this.textRowStart[1]=0; break; case 1: if(textRowInNextPage==0 && textBlockInNextPage==0) { currentSection++; this.textBlockStart=0; this.textRowStart[0]=0; this.textRowStart[1]=0; } else { this.textBlockStart=textBlockInNextPage; this.textRowStart[textBlockStart]=textRowInNextPage; textRowInNextPage=0; textBlockInNextPage=0; } break; } this.clear(); try { IHLMod.xmlparser.setupGuidebookGUI(this, currentSection); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void clear() { for(int i=0;i splittedText = IHLRenderUtils.instance.splitStringByWidth(this.localisedContent[0], Math.round(textBlockWidth)); for(int i1=this.textRowStart[0]; i1 < splittedText.size(); i1++) { yPos+=stringHeight; if(yPos splittedText = IHLRenderUtils.instance.splitStringByWidth(this.localisedContent[1], Math.round(textBlockWidth)); for(int i1=this.textRowStart[1]; i1 < splittedText.size(); i1++) { yPos+=stringHeight; if(yPos