diff --git a/resources/assets/al/textures/gui/PROCESS.png b/resources/assets/al/textures/gui/PROCESS.png index 1db3b767c..06afe5f21 100644 Binary files a/resources/assets/al/textures/gui/PROCESS.png and b/resources/assets/al/textures/gui/PROCESS.png differ diff --git a/src/minecraft/dark/api/al/coding/ILogicTask.java b/src/minecraft/dark/api/al/coding/ILogicTask.java index 05e4207a1..8e6f7da6b 100644 --- a/src/minecraft/dark/api/al/coding/ILogicTask.java +++ b/src/minecraft/dark/api/al/coding/ILogicTask.java @@ -1,10 +1,14 @@ package dark.api.al.coding; +import java.util.List; + +import universalelectricity.core.vector.Vector2; + /** Task in which it doesn't go right to the next task in the row. In this case the task will store * the entry point, and exit points. As well handle anything in between. Examples are IF statements * and loops. Do your logic in the refresh method as it should be called each time a new task is * selected. - * + * * @author DarkGuardsman */ public interface ILogicTask extends ITask { @@ -13,6 +17,8 @@ public interface ILogicTask extends ITask * back to this task. */ public ITask getExitPoint(); + public List getExits(); + /** Mainly used by the encoder to understand the limit on connections */ public int getMaxExitPoints(); diff --git a/src/minecraft/dark/api/al/coding/ITask.java b/src/minecraft/dark/api/al/coding/ITask.java index e612ec6ab..f8d5f763e 100644 --- a/src/minecraft/dark/api/al/coding/ITask.java +++ b/src/minecraft/dark/api/al/coding/ITask.java @@ -74,7 +74,9 @@ public interface ITask extends Cloneable DATA("Data"), DEFINEDPROCESS("Defined Process"), PROCESS("Process"), - DECISION("Decision"); + DECISION("Decision"), + START("Start"), + END("End"); public String name; private TaskType(String name) diff --git a/src/minecraft/dark/assembly/client/gui/GuiEncoderCoder.java b/src/minecraft/dark/assembly/client/gui/GuiEncoderCoder.java index 8cc2b4238..c8d4929e8 100644 --- a/src/minecraft/dark/assembly/client/gui/GuiEncoderCoder.java +++ b/src/minecraft/dark/assembly/client/gui/GuiEncoderCoder.java @@ -34,7 +34,7 @@ public class GuiEncoderCoder extends GuiEncoderBase int containerWidth = (this.width - this.xSize) / 2; int containerHeight = (this.height - this.ySize) / 2; this.drawTexturedModalRect(containerWidth, containerHeight, 0, 0, this.xSize, this.ySize); - taskListGui.drawConsole(this.mc, (this.width - this.xSize) / 2 + 20, (this.height - this.ySize) / 2 + 40); + taskListGui.drawConsole(this.mc, (this.width - this.xSize) / 2 + 15, (this.height - this.ySize) / 2 + 20); } } diff --git a/src/minecraft/dark/assembly/client/gui/GuiTaskList.java b/src/minecraft/dark/assembly/client/gui/GuiTaskList.java index 633e52e4b..e5b21ccc4 100644 --- a/src/minecraft/dark/assembly/client/gui/GuiTaskList.java +++ b/src/minecraft/dark/assembly/client/gui/GuiTaskList.java @@ -1,22 +1,27 @@ package dark.assembly.client.gui; +import java.awt.Color; + import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; -import cpw.mods.fml.client.FMLClientHandler; - import universalelectricity.core.vector.Vector2; +import cpw.mods.fml.client.FMLClientHandler; +import dark.api.al.coding.ILogicTask; import dark.api.al.coding.IProgram; import dark.api.al.coding.IRedirectTask; import dark.api.al.coding.ITask; import dark.assembly.common.AssemblyLine; import dark.assembly.common.armbot.Program; +import dark.assembly.common.armbot.command.TaskEnd; +import dark.assembly.common.armbot.command.TaskGOTO; import dark.assembly.common.armbot.command.TaskGive; +import dark.assembly.common.armbot.command.TaskIF; +import dark.assembly.common.armbot.command.TaskStart; import dark.core.interfaces.IScroll; /** Not a gui itself but a component used to display task as a box inside of a gui @@ -27,6 +32,12 @@ public class GuiTaskList extends Gui implements IScroll protected IProgram program; protected int scroll = 0; + private final int desiredH = 240; + private final int desiredW = 427; + private final float scale = 0.52f; + + private int color = 14737632; + /** The string displayed on this control. */ public String displayString; @@ -36,7 +47,7 @@ public class GuiTaskList extends Gui implements IScroll { program = new Program(); program.setTaskAt(new Vector2(0, 0), new TaskGive()); - program.setTaskAt(new Vector2(0, 1), new TaskGive()); + program.setTaskAt(new Vector2(0, 1), new TaskIF(new Vector2(0, 2), new Vector2(1, 1))); program.setTaskAt(new Vector2(0, 2), new TaskGive()); program.setTaskAt(new Vector2(0, 3), new TaskGive()); program.setTaskAt(new Vector2(0, 4), new TaskGive()); @@ -45,6 +56,25 @@ public class GuiTaskList extends Gui implements IScroll program.setTaskAt(new Vector2(0, 7), new TaskGive()); program.setTaskAt(new Vector2(0, 8), new TaskGive()); program.setTaskAt(new Vector2(0, 9), new TaskGive()); + + program.setTaskAt(new Vector2(1, 1), new TaskGive()); + program.setTaskAt(new Vector2(1, 2), new TaskIF(new Vector2(1, 3), new Vector2(2, 2))); + program.setTaskAt(new Vector2(1, 3), new TaskGive()); + program.setTaskAt(new Vector2(1, 4), new TaskGive()); + program.setTaskAt(new Vector2(1, 5), new TaskGive()); + TaskGOTO ifEixt = new TaskGOTO(); + ifEixt.setExitPoint(0, new Vector2(0, 6)); + program.setTaskAt(new Vector2(1, 6), ifEixt); + + program.setTaskAt(new Vector2(2, 2), new TaskGive()); + program.setTaskAt(new Vector2(2, 3), new TaskGive()); + program.setTaskAt(new Vector2(2, 4), new TaskGive()); + program.setTaskAt(new Vector2(2, 5), new TaskGive()); + program.setTaskAt(new Vector2(2, 6), new TaskGive()); + program.setTaskAt(new Vector2(2, 7), new TaskGive()); + TaskGOTO ifEixt2 = new TaskGOTO(); + ifEixt2.setExitPoint(0, new Vector2(1, 8)); + program.setTaskAt(new Vector2(2, 8), ifEixt2); program.init(null); } @@ -74,37 +104,39 @@ public class GuiTaskList extends Gui implements IScroll public void drawConsole(Minecraft minecraft, int x, int y) { - int spacingY = 25; - int spacingX = 25; - int color = 14737632; - GL11.glPushMatrix(); //With everything scaled the gui will not align like a normal one so use a scaled distance from the main GUI - float scale = 0.52f; ScaledResolution scaledresolution = new ScaledResolution(minecraft.gameSettings, minecraft.displayWidth, minecraft.displayHeight); int scaleH = scaledresolution.getScaledHeight(); int scaleW = scaledresolution.getScaledWidth(); - this.drawCenteredString(minecraft.fontRenderer, "Scale - " + scaleW + "x " + scaleH + "y", 100, 100, color); - int desiredH = 240; - int desiredW = 427; + //this.drawCenteredString(minecraft.fontRenderer, "Scale - " + scaleW + "x " + scaleH + "y", 100, 100, color); + float sh = (scaleH / desiredH) / scale; float sW = (scaleW / desiredW) / scale; - spacingY = (int) (spacingY * sh); - spacingX = (int) (spacingX * sW); + int spacingY = (int) (40 * sh); + int spacingX = (int) (40 * sW); + //Start drawing after everying is scaled down GL11.glScalef(scale, scale, scale); - //TODO add zooming which will involve storing scales with distance translations factors + //Draw lines between tasks + color = Color.BLUE.getRGB(); for (int j = 0; j < 3; j++) { - for (int i = 0; i < 6; i++) + for (int i = 0; i < 4; i++) { - int currentLine = i + this.scroll; - - if (currentLine <= this.program.getSize().intY() && currentLine >= 0) + int currentLine = i + this.scroll - 1; + if (currentLine <= this.program.getSize().intY() + 1 && currentLine >= -1) { ITask task = this.program.getTaskAt(new Vector2(j, currentLine)); - + if (currentLine == -1 && j == 0) + { + task = new TaskStart(); + } + if (currentLine == this.program.getSize().intY() + 1 && j == 0) + { + task = new TaskEnd(); + } if (task != null) { if (task instanceof IRedirectTask && !((IRedirectTask) task).render()) @@ -130,13 +162,118 @@ public class GuiTaskList extends Gui implements IScroll case DECISION: xx = 50; yy = 50; - uu = 50; - vv = 0; + uu = 0; + vv = 78; + break; + case START: + case END: + xx = 39; + yy = 28; + uu = 0; + vv = 128; + break; + } + Vector2 center = new Vector2(((x + 35) - xx) * sW + (spacingX / 2), (y + 25 - (yy / 2)) * sh + (spacingY * i)); + if (task instanceof ILogicTask) + { + for (Vector2 vec : ((ILogicTask) task).getExits()) + { + //Task must be close so not to waste a shit ton of line rendering, as well it needs to stay on screen, and only be one column over + if (vec.distanceTo(task.getPosition()) < 5) + { + if (vec.x >= task.getPosition().x) + { + this.drawHorizontalLine(center.intX(), center.intY(), center.intX() + (spacingX / 2), color); + if (vec.y >= task.getPosition().y) + { + this.drawVerticalLine(center.intX() + (spacingX / 2), center.intY(), center.intY() + (spacingY * (vec.intY() - task.getPosition().intY())), color); + } + else if (vec.y < task.getPosition().y) + { + this.drawVerticalLine(center.intX() + (spacingX / 2), center.intY(), center.intY() - (spacingY * (task.getPosition().intY() - vec.intY())), color); + } + } + else if (vec.x < task.getPosition().x) + { + this.drawHorizontalLine(center.intX(), center.intY(), center.intX() - (spacingX / 2), color); + if (vec.y >= task.getPosition().y) + { + this.drawVerticalLine(center.intX() - (spacingX / 2), center.intY(), center.intY() + (spacingY * (vec.intY() - task.getPosition().intY())), color); + } + else if (vec.y < task.getPosition().y) + { + this.drawVerticalLine(center.intX() - (spacingX / 2), center.intY(), center.intY() - (spacingY * (task.getPosition().intY() - vec.intY())), color); + } + } + } + } + } + else + { + this.drawVerticalLine(center.intX(), center.intY(), center.intY() + spacingY, color); + } + } + } + } + + } + //Draw icons for task + color = 14737632; + for (int j = 0; j < 3; j++) + { + for (int i = 0; i < 4; i++) + { + int currentLine = i + this.scroll - 1; + if (currentLine <= this.program.getSize().intY() + 1 && currentLine >= -1) + { + ITask task = this.program.getTaskAt(new Vector2(j, currentLine)); + if (currentLine == -1 && j == 0) + { + task = new TaskStart(); + } + if (currentLine == this.program.getSize().intY() + 1 && j == 0) + { + task = new TaskEnd(); + } + if (task != null) + { + if (task instanceof IRedirectTask && !((IRedirectTask) task).render()) + { + continue; + } + int xx = 50; + int yy = 39; + int uu = 0; + int vv = 0; + switch (task.getType()) + { + case DATA: + break; + case PROCESS: + break; + case DEFINEDPROCESS: + xx = 50; + yy = 39; + uu = 0; + vv = 39; + break; + case DECISION: + xx = 50; + yy = 50; + uu = 0; + vv = 78; + break; + case START: + case END: + xx = 39; + yy = 28; + uu = 0; + vv = 128; break; } FMLClientHandler.instance().getClient().renderEngine.bindTexture(this.TEXTURE_PROCESS); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - Vector2 center = new Vector2(x * sW + (spacingX * j), y * sh + (spacingY * i)); + Vector2 center = new Vector2((x + 35 - (xx / 2)) * sW + (spacingX * j), (y + 25 - (yy / 2)) * sh + (spacingY * i)); this.drawTexturedModalRect(center.intX(), center.intY(), uu, vv, xx, yy); this.drawCenteredString(minecraft.fontRenderer, task.getMethodName(), center.intX() + (xx / 2), center.intY() + ((yy - 8) / 2), color); } diff --git a/src/minecraft/dark/assembly/common/armbot/command/TaskEnd.java b/src/minecraft/dark/assembly/common/armbot/command/TaskEnd.java new file mode 100644 index 000000000..704f3df33 --- /dev/null +++ b/src/minecraft/dark/assembly/common/armbot/command/TaskEnd.java @@ -0,0 +1,18 @@ +package dark.assembly.common.armbot.command; + +import dark.assembly.common.armbot.TaskBase; + +/** @author DarkGuardsman */ +public class TaskEnd extends TaskBase +{ + public TaskEnd() + { + super("end", TaskType.END); + } + + @Override + public TaskBase clone() + { + return new TaskEnd(); + } +} diff --git a/src/minecraft/dark/assembly/common/armbot/command/TaskGOTO.java b/src/minecraft/dark/assembly/common/armbot/command/TaskGOTO.java index 621520649..7d2d68bd4 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/TaskGOTO.java +++ b/src/minecraft/dark/assembly/common/armbot/command/TaskGOTO.java @@ -1,5 +1,8 @@ package dark.assembly.common.armbot.command; +import java.util.ArrayList; +import java.util.List; + import net.minecraft.nbt.NBTTagCompound; import universalelectricity.core.vector.Vector2; import dark.api.al.coding.IRedirectTask; @@ -12,6 +15,7 @@ public class TaskGOTO extends TaskBase implements IRedirectTask protected ITask task; protected Vector2 taskPos; protected boolean render = true; + protected List exits = new ArrayList(); public TaskGOTO() { @@ -30,6 +34,21 @@ public class TaskGOTO extends TaskBase implements IRedirectTask return task; } + @Override + public void refresh() + { + super.refresh(); + if(task == null && taskPos != null) + { + this.task = this.program.getTaskAt(taskPos); + } + this.exits.clear(); + if (this.task != null) + { + this.exits.add(this.task.getPosition()); + } + } + @Override public void setExitPoint(int i, ITask task) { @@ -39,6 +58,14 @@ public class TaskGOTO extends TaskBase implements IRedirectTask } } + public void setExitPoint(int i, Vector2 vector2) + { + if (i == 0) + { + this.taskPos = vector2; + } + } + @Override public int getMaxExitPoints() { @@ -77,4 +104,11 @@ public class TaskGOTO extends TaskBase implements IRedirectTask return new TaskGOTO(); } + @Override + public List getExits() + { + // TODO Auto-generated method stub + return exits; + } + } diff --git a/src/minecraft/dark/assembly/common/armbot/command/TaskIF.java b/src/minecraft/dark/assembly/common/armbot/command/TaskIF.java index fa20676a8..f90a6aa24 100644 --- a/src/minecraft/dark/assembly/common/armbot/command/TaskIF.java +++ b/src/minecraft/dark/assembly/common/armbot/command/TaskIF.java @@ -1,5 +1,8 @@ package dark.assembly.common.armbot.command; +import java.util.ArrayList; +import java.util.List; + import net.minecraft.nbt.NBTTagCompound; import universalelectricity.core.vector.Vector2; import dark.api.al.coding.IProgrammableMachine; @@ -12,6 +15,8 @@ public class TaskIF extends TaskBaseLogic { protected ITask exitTruePoint = null; protected ITask exitFalsePoint = null; + protected List exits = new ArrayList(); + protected Vector2 exitA, exitB; protected boolean isTrue = false; public TaskIF() @@ -29,6 +34,14 @@ public class TaskIF extends TaskBaseLogic } + public TaskIF(Vector2 exitA, Vector2 exitB) + { + this(); + this.exitA = exitA; + this.exitB = exitB; + + } + @Override public void refresh() { @@ -37,6 +50,24 @@ public class TaskIF extends TaskBaseLogic { this.isTrue = this.getArg("check").equals(this.getArg("compare")); } + if (exitTruePoint == null && exitA != null) + { + exitTruePoint = this.program.getTaskAt(exitA); + } + if (exitFalsePoint == null && exitB != null) + { + exitFalsePoint = this.program.getTaskAt(exitB); + } + + this.exits.clear(); + if (this.exitFalsePoint != null) + { + this.exits.add(this.exitFalsePoint.getPosition()); + } + if (this.exitTruePoint != null) + { + this.exits.add(this.exitTruePoint.getPosition()); + } } @Override @@ -106,4 +137,10 @@ public class TaskIF extends TaskBaseLogic return true; } + @Override + public List getExits() + { + return this.exits; + } + } diff --git a/src/minecraft/dark/assembly/common/armbot/command/TaskStart.java b/src/minecraft/dark/assembly/common/armbot/command/TaskStart.java new file mode 100644 index 000000000..5435f95a2 --- /dev/null +++ b/src/minecraft/dark/assembly/common/armbot/command/TaskStart.java @@ -0,0 +1,22 @@ +package dark.assembly.common.armbot.command; + +import dark.assembly.common.armbot.TaskBase; + +/** Fake task as the player can not create, edit, or do anything with this task. Its only used to + * allow the gui to render the task as an actual task instance + * + * @author DarkGaurdsman */ +public class TaskStart extends TaskBase +{ + public TaskStart() + { + super("Start", TaskType.START); + } + + @Override + public TaskBase clone() + { + return new TaskStart(); + } + +}