work on the gui list

This commit is contained in:
modmuss50 2015-06-16 13:38:46 +01:00
parent 2bed98e6f0
commit 70fb58f704
4 changed files with 239 additions and 11 deletions

View file

@ -7,9 +7,11 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import techreborn.Core;
import techreborn.blocks.BlockMachineBase;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import techreborn.client.GuiHandler;
import techreborn.tiles.iesu.IDSUManager;
import techreborn.tiles.iesu.TileIDSU;
@ -57,15 +59,12 @@ public class BlockIDSU extends BlockMachineBase {
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitx, float hity, float hitz) {
if(world.isRemote){
return true;
}
if(player.isSneaking()){
player.addChatComponentMessage(new ChatComponentText(IDSUManager.INSTANCE.getSaveDataForWorld(world, 0).getStoredPower() + " eu"));
} else {
IDSUManager.INSTANCE.getSaveDataForWorld(world, 0).addEnergy(150);
}
public boolean onBlockActivated(World world, int x, int y, int z,
EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
if (!player.isSneaking())
player.openGui(Core.INSTANCE, GuiHandler.idsuID, world, x, y,
z);
return true;
}
}

View file

@ -8,6 +8,7 @@ import techreborn.client.gui.*;
import techreborn.pda.GuiPda;
import techreborn.tiles.*;
import cpw.mods.fml.common.network.IGuiHandler;
import techreborn.tiles.iesu.TileIDSU;
import techreborn.tiles.lesu.TileLesu;
public class GuiHandler implements IGuiHandler {
@ -38,6 +39,7 @@ public class GuiHandler implements IGuiHandler {
public static final int digitalChestID = 23;
public static final int destructoPackID = 25;
public static final int lesuID = 26;
public static final int idsuID = 27;
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world,
@ -142,7 +144,9 @@ public class GuiHandler implements IGuiHandler {
return new ContainerDestructoPack(player);
} else if (ID == lesuID) {
return new ContainerLesu((TileLesu) world.getTileEntity(x, y, z), player);
}
} else if (ID == idsuID) {
return new ContainerIDSU((TileIDSU) world.getTileEntity(x, y, z), player);
}
return null;
}
@ -250,7 +254,9 @@ public class GuiHandler implements IGuiHandler {
return new GuiDestructoPack(new ContainerDestructoPack(player));
} else if (ID == lesuID) {
return new GuiLesu(player, (TileLesu)world.getTileEntity(x, y, z));
}
} else if (ID == idsuID) {
return new GuiIDSU(player, (TileIDSU)world.getTileEntity(x, y, z));
}
return null;
}
}

View file

@ -0,0 +1,89 @@
package techreborn.client.container;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import techreborn.tiles.TileAesu;
import techreborn.tiles.iesu.TileIDSU;
public class ContainerIDSU extends TechRebornContainer {
EntityPlayer player;
TileIDSU tile;
@Override
public boolean canInteractWith(EntityPlayer player)
{
return true;
}
public int euOut;
public int storedEu;
public int euChange;
public ContainerIDSU(TileIDSU tileIDSU,
EntityPlayer player)
{
tile = tileIDSU;
this.player = player;
int i;
for (i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(player.inventory, j + i * 9
+ 9, 7 + j * 16, 84 + i * 18 + 30));
}
}
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(player.inventory, i, 7 + i * 16,
142 + 30));
}
}
//
// @Override
// public void detectAndSendChanges() {
// super.detectAndSendChanges();
// for (int i = 0; i < this.crafters.size(); i++) {
// ICrafting icrafting = (ICrafting)this.crafters.get(i);
// if(this.euOut != tile.output){
// icrafting.sendProgressBarUpdate(this, 0, tile.output);
// }
// if(this.storedEu != tile.energy){
// icrafting.sendProgressBarUpdate(this, 1, (int) tile.energy);
// }
// if(this.euChange != tile.getEuChange() && tile.getEuChange() != -1){
// icrafting.sendProgressBarUpdate(this, 2, (int) tile.getEuChange());
// }
// }
// }
//
// @Override
// public void addCraftingToCrafters(ICrafting crafting) {
// super.addCraftingToCrafters(crafting);
// crafting.sendProgressBarUpdate(this, 0, tile.output);
// crafting.sendProgressBarUpdate(this, 1, (int) tile.energy);
// crafting.sendProgressBarUpdate(this, 2 , (int) tile.getEuChange());
// }
//
// @SideOnly(Side.CLIENT)
// @Override
// public void updateProgressBar(int id, int value) {
// if(id == 0){
// this.euOut = value;
// } else if(id == 1){
// this.storedEu = value;
// } else if(id == 2){
// this.euChange = value;
// }
// }
}

View file

@ -0,0 +1,134 @@
package techreborn.client.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import techreborn.client.container.ContainerIDSU;
import techreborn.tiles.iesu.TileIDSU;
import java.awt.*;
import java.util.ArrayList;
public class GuiIDSU extends GuiContainer {
private static final ResourceLocation texture = new ResourceLocation(
"techreborn", "textures/gui/aesu.png");
TileIDSU idsu;
ContainerIDSU containerIDSU;
public ArrayList<String> names = new ArrayList<String>();
int scrollpos = 0;
int listSize = 5;
public GuiIDSU(EntityPlayer player,
TileIDSU tileIDSU)
{
super(new ContainerIDSU(tileIDSU, player));
this.xSize = 156;
this.ySize = 200;
idsu = tileIDSU;
this.containerIDSU = (ContainerIDSU) this.inventorySlots;
for (int i = 0; i < 15; i++) {
names.add(i + " name");
}
}
@Override
public void initGui() {
super.initGui();
this.buttonList.clear();
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.buttonList.add(new GuiButton(0, k + 96, l + 8, 18, 20, "++"));
this.buttonList.add(new GuiButton(1, k + 96, l + 8 + 22, 18, 20, "+"));
this.buttonList.add(new GuiButton(2, k + 96, l + 8 + (22*2), 18, 20, "-"));
this.buttonList.add(new GuiButton(3, k + 96, l + 8 + (22*3), 18, 20, "--"));
}
@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_,
int p_146976_2_, int p_146976_3_)
{
this.mc.getTextureManager().bindTexture(texture);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
}
protected void drawGuiContainerForegroundLayer(int p_146979_1_,
int p_146979_2_)
{
this.fontRendererObj.drawString(StatCollector.translateToLocal("tile.techreborn.aesu.name"), 40, 10, Color.WHITE.getRGB());
}
@Override
public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_) {
super.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
int listX = k + 20;
int listY = l + 20;
{
drawColourOnScreen(Color.lightGray.getRGB(), 255, listX - 2, listY -2 , 54, listSize * 10 + 12, 0);
for (int i = scrollpos; i < listSize; i++) {
if(names.size() >= i){
drawColourOnScreen(Color.gray.getRGB(), 255, listX, listY + (12 * i), 50, 10, 0);
fontRendererObj.drawString(names.get(i), listX + 1, listY + (12 * i), Color.WHITE.getRGB());
}
}
}
// int mouseScroll = Mouse.getDWheel();
// System.out.println(mouseScroll);
// if(mouseScroll > 0){
// if(scrollpos + mouseScroll < names.size()){
// scrollpos += Mouse.getDWheel();
// }
// } else {
// if(!(scrollpos + mouseScroll < 0)){
// scrollpos -= Mouse.getDWheel();
// }
// }
}
@Override
protected void actionPerformed(GuiButton button) {
super.actionPerformed(button);
}
public static void drawColourOnScreen(int colour, int alpha, double posX, double posY, double width, double height, double zLevel) {
int r = (colour >> 16 & 0xff);
int g = (colour >> 8 & 0xff);
int b = (colour & 0xff);
drawColourOnScreen(r, g, b, alpha, posX, posY, width, height, zLevel);
}
public static void drawColourOnScreen(int r, int g, int b, int alpha, double posX, double posY, double width, double height, double zLevel) {
if (width <= 0 || height <= 0) {
return;
}
GL11.glDisable(GL11.GL_TEXTURE_2D);
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setColorRGBA(r, g, b, alpha);
tessellator.addVertex(posX, posY + height, zLevel);
tessellator.addVertex(posX + width, posY + height, zLevel);
tessellator.addVertex(posX + width, posY, zLevel);
tessellator.addVertex(posX, posY, zLevel);
tessellator.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
}