diff --git a/src/main/java/com/portingdeadmods/researchd/client/screens/lines/ResearchLine.java b/src/main/java/com/portingdeadmods/researchd/client/screens/lines/ResearchLine.java index 1ae8b4c..feb3e82 100644 --- a/src/main/java/com/portingdeadmods/researchd/client/screens/lines/ResearchLine.java +++ b/src/main/java/com/portingdeadmods/researchd/client/screens/lines/ResearchLine.java @@ -1,14 +1,12 @@ package com.portingdeadmods.researchd.client.screens.lines; -import com.portingdeadmods.researchd.events.ResearchedEvents; +import com.portingdeadmods.researchd.client.screens.graph.ResearchNode; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.narration.NarrationElementOutput; import net.minecraft.network.chat.CommonComponents; -import net.minecraft.network.chat.Component; -import java.util.ArrayList; -import java.util.List; +import java.util.*; public class ResearchLine extends AbstractWidget { @@ -26,19 +24,77 @@ public LineCoordinates(int x1, int y1, int x2, int y2) { } } - public static ResearchLine INPUT_RESEARCH_HEAD(int x, int y) { - return new ResearchLine(new LineCoordinates(x, y - 20, x + 4, y)); + /** + * @param node - ResearchNode to get input heads for + * @return Set of LineCoordinates for every input head + */ + public static Set getInputHeadPositions(ResearchNode node) { + Set positions = new HashSet<>(); + int width = node.getWidth(); // Node width + int height = node.getHeight(); // Node height + int lineWidth = 4; // Line width + int inputs = 1; // TODO: Number of parents + + if (inputs == 1) { + int x = node.getX() + node.getWidth() / 2; + int y = node.getY(); + + positions.add(new LineCoordinates(x, y + 20,x + 4, y)); + return positions; + } + + for (int i = 0; i < inputs; i++) { + int x = node.getX() + (i * (width - lineWidth) / (inputs - 1)) + (lineWidth / 2); + int y = node.getY(); + + positions.add(new LineCoordinates(x, y + 20, x + 4, y)); + } + + return positions; + } + + /** + * @param node - ResearchNode to get output heads for + * @return Set of LineCoordinates for every output head + */ + public static Set getOutputHeadPositions(ResearchNode node) { + Set positions = new HashSet<>(); + int width = node.getWidth(); // Node width + int height = node.getHeight(); // Node height + int lineWidth = 4; // Line width + int inputs = 1; // TODO: Number of parents + + if (inputs == 1) { + int x = node.getX() + node.getWidth() / 2; + int y = node.getY() + height; + + positions.add(new LineCoordinates(x, y,x + 4, y + 20)); + return positions; + } + + for (int i = 0; i < inputs; i++) { + int x = node.getX() + (i * (width - lineWidth) / (inputs - 1)) + (lineWidth / 2); + int y = node.getY() + height; + + positions.add(new LineCoordinates(x, y, x + 4, y + 20)); + } + + return positions; + } + + public static ResearchLine getInputResearchHead(ResearchNode node) { + return new ResearchLine(getInputHeadPositions(node)); } - public static ResearchLine OUTPUT_RESEARCH_HEAD(int x, int y) { - return new ResearchLine(new LineCoordinates(x, y, x + 4, y + 20)); + public static ResearchLine getOutputResearchHead(ResearchNode node) { + return new ResearchLine(getOutputHeadPositions(node)); } public ArrayList lines; - public ResearchLine(LineCoordinates... lines) { + public ResearchLine(Collection lines) { super(getX(lines), getY(lines), getWidth(lines), getHeight(lines), CommonComponents.EMPTY); - this.lines = new ArrayList<>(); + this.lines = new ArrayList<>(lines); } @Override @@ -103,7 +159,7 @@ public int getY() { } // Static methods - public static int getWidth(LineCoordinates... lines) { + public static int getWidth(Iterable lines) { int xLeft = Integer.MAX_VALUE; int xRight = Integer.MIN_VALUE; @@ -115,7 +171,7 @@ public static int getWidth(LineCoordinates... lines) { return xRight - xLeft; } - public static int getHeight(LineCoordinates... lines) { + public static int getHeight(Iterable lines) { int yTop = Integer.MAX_VALUE; int yBottom = Integer.MIN_VALUE; @@ -127,7 +183,7 @@ public static int getHeight(LineCoordinates... lines) { return yBottom - yTop; } - public static int getX(LineCoordinates... lines) { + public static int getX(Iterable lines) { int xLeft = Integer.MAX_VALUE; for (LineCoordinates line : lines) { @@ -137,7 +193,7 @@ public static int getX(LineCoordinates... lines) { return xLeft; } - public static int getY(LineCoordinates... lines) { + public static int getY(Iterable lines) { int yTop = Integer.MAX_VALUE; for (LineCoordinates line : lines) {