Starting on encoder
This commit is contained in:
parent
8b41d7d6b2
commit
9fd3ddb66e
4 changed files with 41 additions and 274 deletions
Binary file not shown.
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.9 KiB |
|
@ -48,11 +48,8 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
|
|||
private int minCommand;
|
||||
private int selCommand;
|
||||
|
||||
private GuiButton addButton;
|
||||
private GuiButton delButton;
|
||||
private GuiButton pUpButton;
|
||||
private GuiButton pDnButton;
|
||||
private GuiTextField commandField;
|
||||
private GuiButton encodeButton;
|
||||
private GuiButton clearButton;
|
||||
|
||||
public GuiEncoder(InventoryPlayer playerInventory, TileEntityEncoder tileEntity)
|
||||
{
|
||||
|
@ -73,17 +70,11 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
|
|||
this.containerWidth = (this.width - this.xSize) / 2;
|
||||
this.containerHeight = (this.height - this.ySize) / 2;
|
||||
|
||||
this.addButton = new GuiButton(0, containerWidth + (xSize - 25), containerHeight + 128 + ContainerEncoder.Y_OFFSET, 18, 20, "+");
|
||||
this.delButton = new GuiButton(1, containerWidth + (xSize - 43), containerHeight + 128 + ContainerEncoder.Y_OFFSET, 18, 20, "-");
|
||||
this.pUpButton = new GuiButton(2, containerWidth + (xSize - 25), containerHeight + 46 + ContainerEncoder.Y_OFFSET, 18, 20, "");
|
||||
this.pDnButton = new GuiButton(3, containerWidth + (xSize - 25), containerHeight + 106 + ContainerEncoder.Y_OFFSET, 18, 20, "");
|
||||
this.commandField = new GuiTextField(fontRenderer, 8, 129 + ContainerEncoder.Y_OFFSET, xSize - 52, 18);
|
||||
// commandList = new GuiCommandList(mc, xSize - 7, 128, 7, 120, 170, 20);
|
||||
this.encodeButton = new GuiButton(0, containerWidth + (xSize - 25), containerHeight + 128 + ContainerEncoder.Y_OFFSET, 18, 20, "Code");
|
||||
this.clearButton = new GuiButton(1, containerWidth + (xSize - 43), containerHeight + 128 + ContainerEncoder.Y_OFFSET, 18, 20, "Erase");
|
||||
|
||||
this.buttonList.add(addButton);
|
||||
this.buttonList.add(delButton);
|
||||
this.buttonList.add(pUpButton);
|
||||
this.buttonList.add(pDnButton);
|
||||
this.buttonList.add(encodeButton);
|
||||
this.buttonList.add(clearButton);
|
||||
|
||||
this.commands = new ArrayList<String>();
|
||||
this.minCommand = 0;
|
||||
|
@ -93,61 +84,7 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
|
|||
@Override
|
||||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
// TODO: Add insert command to allow commands to be inserted between two existing commands.
|
||||
switch (button.id)
|
||||
{
|
||||
case 0: // add
|
||||
{
|
||||
if (!this.commandField.getText().equals(""))
|
||||
{
|
||||
if (this.tileEntity != null)
|
||||
{
|
||||
ItemStack disk = this.tileEntity.getStackInSlot(0);
|
||||
|
||||
if (disk != null)
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer(PacketHandler.instance().getPacket(DarkMain.CHANNEL, this.tileEntity, true, this.commandField.getText()));
|
||||
}
|
||||
}
|
||||
|
||||
this.minCommand = this.commands.size() - MAX_COMMANDS + 1;
|
||||
if (this.minCommand < 0)
|
||||
this.minCommand = 0;
|
||||
this.selCommand = -1;
|
||||
this.commandField.setText("");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 1: // remove
|
||||
{
|
||||
if (this.tileEntity != null)
|
||||
{
|
||||
ItemStack disk = this.tileEntity.getStackInSlot(0);
|
||||
|
||||
if (disk != null && this.selCommand >= 0 && this.selCommand < this.commands.size())
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer(PacketHandler.instance().getPacket(DarkMain.CHANNEL, this.tileEntity, false, this.selCommand));
|
||||
}
|
||||
|
||||
this.selCommand = -1;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 2: // page up
|
||||
{
|
||||
if (minCommand > 0)
|
||||
minCommand--;
|
||||
break;
|
||||
}
|
||||
case 3: // page down
|
||||
{
|
||||
if (minCommand + MAX_COMMANDS < this.commands.size())
|
||||
minCommand++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Draw the foreground layer for the GuiContainer (everything in front of the items) */
|
||||
|
@ -158,153 +95,27 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
|
|||
glDisable(GL_LIGHTING);
|
||||
this.fontRenderer.drawString(TranslationHelper.getLocal("tile.encoder.name"), 68, 8 + ContainerEncoder.Y_OFFSET, 4210752);
|
||||
this.fontRenderer.drawString("Disk:", 56, 28 + ContainerEncoder.Y_OFFSET, 4210752);
|
||||
|
||||
// render page up and page down buttons
|
||||
glPushMatrix();
|
||||
glTranslatef(pUpButton.xPosition - containerWidth + 6, pUpButton.yPosition - containerHeight + 7, 0);
|
||||
this.fontRenderer.drawString("^", 1, 1, 0x444444);
|
||||
this.fontRenderer.drawString("^", 0, 0, 0xFFFFFF);
|
||||
glPopMatrix();
|
||||
glPushMatrix();
|
||||
glTranslatef(pDnButton.xPosition - containerWidth + 6, pDnButton.yPosition - containerHeight + 7, 0);
|
||||
glRotatef(180, 0, 0, 1);
|
||||
glTranslatef(-5, -4, 0);
|
||||
this.fontRenderer.drawString("^", -1, -1, 0x444444);
|
||||
this.fontRenderer.drawString("^", 0, 0, 0xFFFFFF);
|
||||
glPopMatrix();
|
||||
|
||||
if (this.commands != null)
|
||||
{
|
||||
this.drawCommands();
|
||||
}
|
||||
|
||||
this.commandField.drawTextBox();
|
||||
}
|
||||
|
||||
private void drawCommands()
|
||||
{
|
||||
int relativeCommand;
|
||||
String command;
|
||||
|
||||
for (int i = minCommand; i < minCommand + MAX_COMMANDS; i++)
|
||||
{
|
||||
if (i >= 0 && i < this.commands.size())
|
||||
{
|
||||
relativeCommand = i - minCommand;
|
||||
command = this.commands.get(i).toUpperCase();
|
||||
drawCommand(command, 8, 47 + relativeCommand * (fontRenderer.FONT_HEIGHT + 4), this.selCommand == i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawCommand(String command, int x, int y, boolean selected)
|
||||
{
|
||||
if (selected)
|
||||
{
|
||||
drawOutlineRect(x, y, x + 142, y + fontRenderer.FONT_HEIGHT + 4, 0, 0, 0, 1f, 1f, 1f);
|
||||
}
|
||||
this.fontRenderer.drawString(command, x + 3, y + (fontRenderer.FONT_HEIGHT / 2) - 1, 0xFFFFFF, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int button)
|
||||
{
|
||||
super.mouseClicked(x, y, button);
|
||||
this.commandField.mouseClicked(x - containerWidth, y - containerHeight, button);
|
||||
if (button == 0)
|
||||
{
|
||||
if (x >= containerWidth + 8)
|
||||
{
|
||||
if (y >= containerHeight + 47 + ContainerEncoder.Y_OFFSET)
|
||||
{
|
||||
if (x <= containerWidth + (xSize - 25))
|
||||
{
|
||||
if (y <= containerHeight + 46 + 80 + ContainerEncoder.Y_OFFSET)
|
||||
{
|
||||
listClicked(x - (containerWidth + 8), y - (containerHeight + 47 + ContainerEncoder.Y_OFFSET));
|
||||
}
|
||||
else
|
||||
{
|
||||
selCommand = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
selCommand = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
selCommand = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
selCommand = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void listClicked(int relativeX, int relativeY)
|
||||
{
|
||||
int itemClicked = relativeY / 13;
|
||||
this.selCommand = itemClicked + this.minCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char character, int keycode)
|
||||
{
|
||||
if (character != 'e' && character != 'E') // Don't close GUI
|
||||
if (character != 'e' && character != 'E')
|
||||
{
|
||||
super.keyTyped(character, keycode);
|
||||
commandField.textboxKeyTyped(character, keycode);
|
||||
}
|
||||
|
||||
if (keycode == Keyboard.KEY_ESCAPE)
|
||||
{
|
||||
this.mc.thePlayer.closeScreen();
|
||||
}
|
||||
else if (keycode == Keyboard.KEY_RETURN)
|
||||
{
|
||||
if (this.commandField.isFocused())
|
||||
{
|
||||
actionPerformed(this.addButton);
|
||||
}
|
||||
}
|
||||
else if (keycode == Keyboard.KEY_DELETE)
|
||||
{
|
||||
actionPerformed(this.delButton);
|
||||
}
|
||||
else if (keycode == 201) // PAGE UP (no constant)
|
||||
{
|
||||
actionPerformed(this.pUpButton);
|
||||
}
|
||||
else if (keycode == 209) // PAGE DOWN (no constant)
|
||||
{
|
||||
actionPerformed(this.pDnButton);
|
||||
}
|
||||
else if (keycode == Keyboard.KEY_UP)
|
||||
{
|
||||
this.selCommand--;
|
||||
if (this.selCommand < -1)
|
||||
this.selCommand = this.commands.size() - 1;
|
||||
if (this.selCommand < minCommand)
|
||||
if (this.selCommand >= 0)
|
||||
this.minCommand = selCommand;
|
||||
if (this.selCommand >= this.minCommand + MAX_COMMANDS)
|
||||
if (this.selCommand < this.commands.size())
|
||||
this.minCommand = this.selCommand - MAX_COMMANDS + 1;
|
||||
}
|
||||
else if (keycode == Keyboard.KEY_DOWN)
|
||||
{
|
||||
this.selCommand++;
|
||||
if (this.selCommand >= this.commands.size())
|
||||
this.selCommand = -1;
|
||||
if (this.selCommand >= this.minCommand + MAX_COMMANDS)
|
||||
if (this.selCommand < this.commands.size())
|
||||
this.minCommand = this.selCommand - MAX_COMMANDS + 1;
|
||||
if (this.selCommand < minCommand)
|
||||
if (this.selCommand >= 0)
|
||||
this.minCommand = selCommand;
|
||||
}
|
||||
}
|
||||
|
||||
/** Draw the background layer for the GuiContainer (everything behind the items) */
|
||||
|
@ -315,75 +126,6 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
|
|||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
this.drawTexturedModalRect(containerWidth, containerHeight + ContainerEncoder.Y_OFFSET, 0, 0, this.xSize, this.ySize);
|
||||
drawOutlineRect(containerWidth + 7, containerHeight + 46 + ContainerEncoder.Y_OFFSET, containerWidth + (xSize - 25), containerHeight + 46 + 80 + ContainerEncoder.Y_OFFSET, 0, 0, 0, 0.5f, 0.5f, 0.5f);
|
||||
}
|
||||
|
||||
public static void drawOutlineRect(int x1, int y1, int x2, int y2, float rR, float rG, float rB, float lR, float lG, float lB)
|
||||
{
|
||||
Tessellator tesselator = Tessellator.instance;
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glColor4f(rR, rG, rB, 1f);
|
||||
if (rR >= 0 && rG >= 0 && rB >= 0)
|
||||
{
|
||||
// background
|
||||
tesselator.startDrawingQuads();
|
||||
tesselator.addVertex(x1, y2, 0.0D);
|
||||
tesselator.addVertex(x2, y2, 0.0D);
|
||||
tesselator.addVertex(x2, y1, 0.0D);
|
||||
tesselator.addVertex(x1, y1, 0.0D);
|
||||
tesselator.draw();
|
||||
}
|
||||
// outline
|
||||
GL11.glColor4f(lR, lG, lB, 1f);
|
||||
tesselator.startDrawingQuads();
|
||||
tesselator.addVertex(x1, y1, 0.0D);
|
||||
tesselator.addVertex(x1, y2, 0.0D);
|
||||
tesselator.addVertex((double) x1 + 1, y2, 0.0D);
|
||||
tesselator.addVertex((double) x1 + 1, y1, 0.0D);
|
||||
tesselator.draw();
|
||||
tesselator.startDrawingQuads();
|
||||
tesselator.addVertex((double) x2 - 1, y1, 0.0D);
|
||||
tesselator.addVertex((double) x2 - 1, y2, 0.0D);
|
||||
tesselator.addVertex(x2, y2, 0.0D);
|
||||
tesselator.addVertex(x2, y1, 0.0D);
|
||||
tesselator.draw();
|
||||
tesselator.startDrawingQuads();
|
||||
tesselator.addVertex(x1, y1, 0.0D);
|
||||
tesselator.addVertex(x1, (double) y1 + 1, 0.0D);
|
||||
tesselator.addVertex(x2, (double) y1 + 1, 0.0D);
|
||||
tesselator.addVertex(x2, y1, 0.0D);
|
||||
tesselator.draw();
|
||||
tesselator.startDrawingQuads();
|
||||
tesselator.addVertex(x1, (double) y2 - 1, 0.0D);
|
||||
tesselator.addVertex(x1, y2, 0.0D);
|
||||
tesselator.addVertex(x2, y2, 0.0D);
|
||||
tesselator.addVertex(x2, (double) y2 - 1, 0.0D);
|
||||
tesselator.draw();
|
||||
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
}
|
||||
|
||||
private void updateCommands()
|
||||
{
|
||||
if (commands != null)
|
||||
{
|
||||
commands.clear();
|
||||
if (tileEntity != null)
|
||||
{
|
||||
ItemStack disk = tileEntity.getStackInSlot(0);
|
||||
if (disk != null)
|
||||
{
|
||||
commands = ItemDisk.getCommands(disk);
|
||||
}
|
||||
}
|
||||
if (this.minCommand + MAX_COMMANDS >= this.commands.size())
|
||||
this.minCommand = this.commands.size() - MAX_COMMANDS;
|
||||
if (this.minCommand < 0)
|
||||
this.minCommand = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -396,6 +138,7 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
|
|||
@Override
|
||||
public void inventoryChanged()
|
||||
{
|
||||
this.updateCommands();
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
|
22
src/minecraft/dark/assembly/client/gui/GuiProgrammer.java
Normal file
22
src/minecraft/dark/assembly/client/gui/GuiProgrammer.java
Normal file
|
@ -0,0 +1,22 @@
|
|||
package dark.assembly.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Container;
|
||||
|
||||
public class GuiProgrammer extends GuiContainer
|
||||
{
|
||||
|
||||
public GuiProgrammer(Container par1Container)
|
||||
{
|
||||
super(par1Container);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int i, int j)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ package dark.assembly.common.machine;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
|
@ -20,7 +21,7 @@ import dark.core.registration.ModObjectRegistry.BlockBuildData;
|
|||
|
||||
/** A block that allows the placement of mass amount of a specific item within it. It will be allowed
|
||||
* to go on Conveyor Belts
|
||||
*
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class BlockCrate extends BlockAssembly
|
||||
{
|
||||
|
@ -216,7 +217,7 @@ public class BlockCrate extends BlockAssembly
|
|||
}
|
||||
|
||||
/** Inserts all items of the same type this player has into the crate.
|
||||
*
|
||||
*
|
||||
* @return True on success */
|
||||
public boolean insertAllItems(TileEntityCrate tileEntity, EntityPlayer player)
|
||||
{
|
||||
|
@ -261,7 +262,7 @@ public class BlockCrate extends BlockAssembly
|
|||
}
|
||||
|
||||
/** Ejects and item out of the crate and spawn it under the player entity.
|
||||
*
|
||||
*
|
||||
* @param tileEntity
|
||||
* @param player
|
||||
* @param requestSize - The maximum stack size to take out. Default should be 64.
|
||||
|
@ -313,7 +314,7 @@ public class BlockCrate extends BlockAssembly
|
|||
}
|
||||
|
||||
/** Puts an itemStack into the crate.
|
||||
*
|
||||
*
|
||||
* @param tileEntity
|
||||
* @param itemStack */
|
||||
public static ItemStack addStackToCrate(TileEntityCrate tileEntity, ItemStack itemStack)
|
||||
|
@ -410,9 +411,10 @@ public class BlockCrate extends BlockAssembly
|
|||
try
|
||||
{
|
||||
ItemStack stack = new ItemStack(this, 1, 2);
|
||||
ItemBlockCrate.setContainingItemStack(stack, new ItemStack(1, 2048, 0));
|
||||
ItemBlockCrate.setContainingItemStack(stack, new ItemStack(Block.cobblestone, 2048, 0));
|
||||
list.add(stack);
|
||||
ItemBlockCrate.setContainingItemStack(stack, new ItemStack(Item.coal, 2048, 1));
|
||||
ItemStack stack2 = new ItemStack(this, 1, 2);
|
||||
ItemBlockCrate.setContainingItemStack(stack2, new ItemStack(Item.coal, 2048, 1));
|
||||
list.add(stack);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
Loading…
Reference in a new issue