From 05c78126859231a68e199dc34613689bd0978e2f Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Mon, 11 Apr 2016 19:44:54 +0300 Subject: Initial commit --- ihl/guidebook/IHLGuidebookContainer.java | 30 ++++ ihl/guidebook/IHLGuidebookGui.java | 288 +++++++++++++++++++++++++++++++ ihl/guidebook/IHLGuidebookInventory.java | 123 +++++++++++++ ihl/guidebook/IHLGuidebookItem.java | 63 +++++++ ihl/guidebook/IHLGuidebookSlot.java | 20 +++ 5 files changed, 524 insertions(+) create mode 100644 ihl/guidebook/IHLGuidebookContainer.java create mode 100644 ihl/guidebook/IHLGuidebookGui.java create mode 100644 ihl/guidebook/IHLGuidebookInventory.java create mode 100644 ihl/guidebook/IHLGuidebookItem.java create mode 100644 ihl/guidebook/IHLGuidebookSlot.java (limited to 'ihl/guidebook') 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 +{ + 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 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 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; + } +} -- cgit v1.2.3