You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
6.6 KiB
Java

package net.brokenmoon.afloydwiremod.gui;
import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity;
import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerPacket;
import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity;
import net.minecraft.client.Minecraft;
import net.minecraft.src.*;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
public class GuiProgrammer extends GuiScrollable {
private AbstractWireTileEntity wireEntity;
public int xSize = 100;
public int ySize = 180;
private int slot = 0;
@Override
public void initGui() {
//this.height - 240 is top
//This.width / 2
slot = 0;
this.controlList.add(new GuiButtonExtended(slot++, this.width, "Constant"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "Increment"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "Decrement"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "Increment/Decrement"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "Duplicate"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "Addition"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "Subtraction"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "Multiplication"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "Division"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "Memory"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "Pulse"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "TRUE"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "FALSE"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "AND"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "NAND"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "OR"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "NOR"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "XOR"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "XNOR"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "NOT"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "=="));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "!="));
this.controlList.add(new GuiButtonExtended(slot++, this.width, ">"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, ">="));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "<"));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "<="));
this.controlList.add(new GuiButtonExtended(slot++, this.width, "<=>"));
}
public GuiProgrammer(EntityPlayer player, ChipTileEntity wireEntity) {
super.initGui();
this.player = player;
this.wireEntity = wireEntity;
}
@Override
protected void actionPerformed(GuiButton guibutton) {
switch(guibutton.displayString){
case "Constant":
this.setMode("constant");
break;
case "Increment":
this.setMode("inc");
break;
case "Duplicate":
this.setMode("dup");
break;
case "Addition":
this.setMode("add");
break;
case "Subtraction":
this.setMode("sub");
break;
case "Multiplication":
this.setMode("mult");
break;
case "Division":
this.setMode("div");
break;
case "Decrement":
this.setMode("dec");
break;
case "Increment/Decrement":
this.setMode("incdec");
break;
case "Memory":
this.setMode("mem");
break;
case "TRUE":
case "FALSE":
case "NOT":
case "AND":
case "OR":
case "XOR":
case "NAND":
case "NOR":
case "XNOR":
case "==":
case "!=":
case ">":
case ">=":
case "<":
case "<=":
case "<=>":
case "Pulse":
this.setMode(guibutton.displayString);
break;
}
this.mc.displayGuiScreen(null);
}
public void setMode(String string){
if(this.player instanceof EntityClientPlayerMP){
NetClientHandler netclienthandler = ((EntityClientPlayerMP)this.mc.thePlayer).sendQueue;
netclienthandler.addToSendQueue(new WiremodProgrammerPacket(string, wireEntity.xCoord, wireEntity.yCoord, wireEntity.zCoord));
return;
}
((ChipTileEntity)Minecraft.getMinecraft().theWorld.getBlockTileEntity(wireEntity.xCoord, wireEntity.yCoord, wireEntity.zCoord)).setMode(string);
}
@Override
public void drawScreen(int x, int y, float renderPartialTicks){
this.drawDefaultBackground();
//Draw the overlay
this.drawGuiBackground(renderPartialTicks);
GL11.glPushMatrix();
GL11.glPopMatrix();
int k = (this.height - this.ySize) / 2;
int wheel = Mouse.getDWheel();
if(wheel > 0)
scroll++;
if (wheel < 0)
scroll--;
if(scroll > 0)
scroll = 0;
if(-scroll > slot - 16)
scroll = -(slot - 16);
for (int i = 0; i < this.controlList.size(); ++i) {
GuiButtonExtended guibutton = (GuiButtonExtended)this.controlList.get(i);
guibutton.yPosition = k + (guibutton.height * (guibutton.id + 1) + scroll * GuiButtonExtended.height);
if(guibutton.yPosition > k && guibutton.yPosition < k + 170){
guibutton.drawButton(this.mc, x, y);
}
}
}
protected void drawGuiBackground(float f) {
int guiTexture = this.mc.renderEngine.getTexture("/assets/afloydwiremod/gui/programmer.png");
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.renderEngine.bindTexture(guiTexture);
int j = (this.width - this.xSize) / 2;
int k = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(j, k, 0, 0, this.xSize, this.ySize);
}
}