summaryrefslogtreecommitdiff
path: root/ihl/guidebook
diff options
context:
space:
mode:
authorFoghrye4 <foghrye4@gmail.com>2016-04-11 19:44:54 +0300
committerFoghrye4 <foghrye4@gmail.com>2016-04-11 19:44:54 +0300
commit05c78126859231a68e199dc34613689bd0978e2f (patch)
tree050bea104a18c72905095d29f31bec2935a27a24 /ihl/guidebook
Initial commit
Diffstat (limited to 'ihl/guidebook')
-rw-r--r--ihl/guidebook/IHLGuidebookContainer.java30
-rw-r--r--ihl/guidebook/IHLGuidebookGui.java288
-rw-r--r--ihl/guidebook/IHLGuidebookInventory.java123
-rw-r--r--ihl/guidebook/IHLGuidebookItem.java63
-rw-r--r--ihl/guidebook/IHLGuidebookSlot.java20
5 files changed, 524 insertions, 0 deletions
diff --git a/ihl/guidebook/IHLGuidebookContainer.java b/ihl/guidebook/IHLGuidebookContainer.java
new file mode 100644
index 0000000..4510dcd
--- /dev/null
+++ b/ihl/guidebook/IHLGuidebookContainer.java
@@ -0,0 +1,30 @@
+package ihl.guidebook;
+
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.Slot;
+import ic2.core.ContainerBase;
+
+public class IHLGuidebookContainer extends ContainerBase<IHLGuidebookInventory>
+{
+ public IHLGuidebookInventory box;
+ public int xSize=256;
+ public int ySize=211;
+
+ public IHLGuidebookContainer(EntityPlayer entityPlayer, IHLGuidebookInventory box)
+ {
+ super(box);
+ this.box = box;
+ int col;
+ for (col = 0; col < 4; ++col)
+ {
+ this.addSlotToContainer(new Slot(box, col, 18 + col * 18, 20));
+ }
+ }
+
+ @Override
+ public void onContainerClosed(EntityPlayer entityPlayer)
+ {
+ this.box.onGuiClosed(entityPlayer);
+ super.onContainerClosed(entityPlayer);
+ }
+}
diff --git a/ihl/guidebook/IHLGuidebookGui.java b/ihl/guidebook/IHLGuidebookGui.java
new file mode 100644
index 0000000..343f522
--- /dev/null
+++ b/ihl/guidebook/IHLGuidebookGui.java
@@ -0,0 +1,288 @@
+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<Integer, Integer[]> linksCoordinatesMap = new HashMap<Integer,Integer[]>();
+ 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<this.container.base.content.length;i++)
+ {
+ this.container.base.content[i]=null;
+ }
+ this.title=null;
+ this.localisedContent[0]=null;
+ this.localisedContent[1]=null;
+ }
+
+ public void setTitle(String title1) {
+ this.title=StatCollector.translateToLocal(title1);
+ }
+
+ public void setPicture(String string,int width,int height)
+ {
+ IHLMod.log.debug("setting picture='"+string+"' \n height="+height+" \n width="+width);
+ if(this.resourceLocationCache[this.currentSection]==null)
+ {
+ this.resourceLocationCache[this.currentSection]=new ResourceLocation("ihl",string);
+ }
+ this.pictureWidth=width;
+ this.pictureHeight=height;
+ }
+
+
+ @Override
+ protected void drawGuiContainerForegroundLayer(int par1, int par2) {
+ IHLRenderUtils.instance.updateScreenSize();
+ this.textRowInRightPage=0;
+ this.textBlockInRightPage=0;
+ this.drawPage(this.textBlockX1,this.textBlockY1);
+ }
+
+ private void drawPage(int startX, int startY)
+ {
+ int xOffset = (this.width - xSize) / 2;
+ int yOffset = (this.height - ySize) / 2;
+ GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
+ this.fontRendererObj.drawString(this.title, this.titleX, this.titleY, 0);
+ int xPos=startX;
+ int yPos=startY;
+ if(this.textBlockStart==0)
+ {
+ if(this.localisedContent[0]!=null)
+ {
+ List<String> splittedText = IHLRenderUtils.instance.splitStringByWidth(this.localisedContent[0], Math.round(textBlockWidth));
+ for(int i1=this.textRowStart[0]; i1 < splittedText.size(); i1++)
+ {
+ yPos+=stringHeight;
+ if(yPos<this.textBlockMaxY)
+ {
+ this.fontRendererObj.drawString(splittedText.get(i1), Math.round(xPos), Math.round(yPos), 0);
+ }
+ else if(xPos!=this.textBlockX2)
+ {
+ yPos=this.textBlockY2;
+ xPos=this.textBlockX2;
+ this.fontRendererObj.drawString(splittedText.get(i1), Math.round(xPos), Math.round(yPos), 0);
+ }
+ else
+ {
+ textRowInNextPage=i1;
+ textBlockInNextPage=0;
+ return;
+ }
+ }
+ }
+ if(this.resourceLocationCache[this.currentSection]!=null)
+ {
+ GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
+ if(yPos+this.pictureHeight<this.textBlockMaxY)
+ {
+ yPos+=stringHeight;
+ ITextureObject texture = this.mc.renderEngine.getTexture(this.resourceLocationCache[this.currentSection]);
+ this.mc.renderEngine.bindTexture(this.resourceLocationCache[this.currentSection]);
+ this.drawTexturedModalRect(Math.round(xPos), Math.round(yPos), 0, 0, this.pictureWidth, this.pictureHeight);
+ yPos+=Math.round(this.pictureHeight);
+ }
+ else
+ {
+ yPos=this.textBlockY2;
+ xPos=this.textBlockX2;
+ this.mc.renderEngine.bindTexture(this.resourceLocationCache[this.currentSection]);
+ this.drawTexturedModalRect(Math.round(xPos), Math.round(yPos), 0, 0, this.pictureWidth, this.pictureHeight);
+ yPos+=Math.round(this.pictureHeight);
+ }
+ }
+
+ }
+ if(this.localisedContent[1]!=null)
+ {
+ List<String> splittedText = IHLRenderUtils.instance.splitStringByWidth(this.localisedContent[1], Math.round(textBlockWidth));
+ for(int i1=this.textRowStart[1]; i1 < splittedText.size(); i1++)
+ {
+ yPos+=stringHeight;
+ if(yPos<this.textBlockMaxY)
+ {
+ this.fontRendererObj.drawString(splittedText.get(i1), Math.round(xPos), Math.round(yPos), 0);
+ }
+ else if(xPos!=this.textBlockX2)
+ {
+ yPos=this.textBlockY2;
+ xPos=this.textBlockX2;
+ this.fontRendererObj.drawString(splittedText.get(i1), Math.round(xPos), Math.round(yPos), 0);
+ }
+ else
+ {
+ textRowInNextPage=i1;
+ textBlockInNextPage=1;
+ return;
+ }
+ }
+ }
+ GL11.glScalef(1f, 1f, 1f);
+ }
+
+
+ @Override
+ protected void drawGuiContainerBackgroundLayer(float par1, int par2,
+ int par3) {
+ //draw your Gui here, only thing you need to change is the path
+ GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
+ int x = (width - xSize) / 2;
+ int y = (height - ySize) / 2;
+ this.mc.renderEngine.bindTexture(background);
+ this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
+
+ }
+
+ public void setSectionNumber(int i)
+ {
+ this.currentSection=0;
+ }
+
+ public void setMaxSectionNumber(int i)
+ {
+ this.maxSection=Math.max(i,this.maxSection);
+ }
+
+ public int getMaxSectionNumber()
+ {
+ return this.maxSection;
+ }
+
+ public void addItemStack(ItemStack itemStack)
+ {
+ for(int i=0;i<this.container.base.content.length;i++)
+ {
+ if(this.container.base.content[i]==null)
+ {
+ this.container.base.content[i]=itemStack;
+ break;
+ }
+ }
+ }
+
+ public void addTextBlock(String textContent) {
+ for(int i=0; i < this.localisedContent.length; i++)
+ {
+ if(this.localisedContent[i]==null)
+ {
+ this.localisedContent[i]=StatCollector.translateToLocal(textContent);
+ break;
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/ihl/guidebook/IHLGuidebookInventory.java b/ihl/guidebook/IHLGuidebookInventory.java
new file mode 100644
index 0000000..8535a3c
--- /dev/null
+++ b/ihl/guidebook/IHLGuidebookInventory.java
@@ -0,0 +1,123 @@
+package ihl.guidebook;
+
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import net.minecraft.client.gui.GuiScreen;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.item.ItemStack;
+import ic2.core.ContainerBase;
+import ic2.core.IHasGui;
+
+public class IHLGuidebookInventory implements IHasGui{
+
+ ItemStack thisItemStack;
+ IInventory inventoryContainer;
+ public ItemStack[] content = new ItemStack[4];
+
+ public IHLGuidebookInventory(EntityPlayer player, ItemStack stack) {
+ thisItemStack=stack;
+ inventoryContainer=player.inventory;
+ }
+
+ public IHLGuidebookInventory(IInventory inventoryContainer1, ItemStack stack)
+ {
+ thisItemStack=stack;
+ inventoryContainer=inventoryContainer1;
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public GuiScreen getGui(EntityPlayer player, boolean arg1) {
+ return new IHLGuidebookGui(new IHLGuidebookContainer(player, this));
+ }
+
+ @Override
+ public ContainerBase<?> getGuiContainer(EntityPlayer player) {
+ return new IHLGuidebookContainer(player, this);
+ }
+
+ @Override
+ public String getInventoryName() {
+ return "IHLGuidebook";
+ }
+
+ @Override
+ public boolean hasCustomInventoryName() {
+ return false;
+ }
+
+ @Override
+ public boolean isItemValidForSlot(int arg0, ItemStack stack) {
+ return false;
+ }
+
+ @Override
+ public int getInventoryStackLimit()
+ {
+ return 1;
+ }
+
+ @Override
+ public ItemStack getStackInSlot(int slotNumber) {
+ return content[slotNumber];
+ }
+
+ @Override
+ public void setInventorySlotContents(int arg0, ItemStack arg1)
+ {
+ }
+
+ @Override
+ public void closeInventory() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public ItemStack decrStackSize(int arg0, int arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int getSizeInventory() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public ItemStack getStackInSlotOnClosing(int arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean isUseableByPlayer(EntityPlayer arg0) {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ @Override
+ public void markDirty() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void openInventory() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onGuiClosed(EntityPlayer arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean isThisContainer(ItemStack stack)
+ {
+ return this.thisItemStack.equals(stack);
+ }
+}
diff --git a/ihl/guidebook/IHLGuidebookItem.java b/ihl/guidebook/IHLGuidebookItem.java
new file mode 100644
index 0000000..e616455
--- /dev/null
+++ b/ihl/guidebook/IHLGuidebookItem.java
@@ -0,0 +1,63 @@
+package ihl.guidebook;
+
+import cpw.mods.fml.common.registry.GameRegistry;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+
+import net.minecraft.client.renderer.texture.IIconRegister;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
+import ic2.core.IC2;
+import ic2.core.IHasGui;
+import ic2.core.item.IHandHeldInventory;
+import ihl.IHLCreativeTab;
+import ihl.IHLModInfo;
+
+public class IHLGuidebookItem extends Item implements IHandHeldInventory{
+
+ public IHLGuidebookItem() {
+ super();
+ this.setUnlocalizedName("guidebook");
+ this.setCreativeTab(IHLCreativeTab.tab);
+ this.maxStackSize=1;
+ this.setCreativeTab(IHLCreativeTab.tab);
+ this.setMaxDamage(0);
+ }
+
+ public static void init()
+ {
+ GameRegistry.registerItem(new IHLGuidebookItem(), "guidebook");
+ }
+
+ @Override
+ public IHasGui getInventory(EntityPlayer entityPlayer, ItemStack itemStack)
+ {
+ return new IHLGuidebookInventory(entityPlayer, itemStack);
+ }
+
+ @Override
+ public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer)
+ {
+ if (IC2.platform.isSimulating())
+ {
+ IC2.platform.launchGui(entityPlayer, this.getInventory(entityPlayer, itemStack));
+ }
+ return itemStack;
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public void registerIcons(IIconRegister register)
+ {
+ itemIcon=register.registerIcon(IHLModInfo.MODID + ":guidebook");
+ }
+
+ @Override
+ public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset)
+ {
+ return false;
+ }
+
+}
diff --git a/ihl/guidebook/IHLGuidebookSlot.java b/ihl/guidebook/IHLGuidebookSlot.java
new file mode 100644
index 0000000..b945ae3
--- /dev/null
+++ b/ihl/guidebook/IHLGuidebookSlot.java
@@ -0,0 +1,20 @@
+package ihl.guidebook;
+
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemStack;
+
+public class IHLGuidebookSlot extends Slot
+{
+ IHLGuidebookInventory inventory;
+ public IHLGuidebookSlot(IHLGuidebookInventory arg0, int arg1, int arg2, int arg3)
+ {
+ super(arg0, arg1, arg2, arg3);
+ inventory=arg0;
+ }
+
+ @Override
+ public boolean isItemValid(ItemStack itemstack)
+ {
+ return false;
+ }
+}