public void ProcessElectives(List <Elective> electives) { CourseChain chain = Instantiate(treeRow).AddComponent <CourseChain>(); chain.transform.SetParent(content, false); chains.Add(chain); if (chain.GetComponent <HorizontalLayoutGroup>()) { chain.GetComponent <HorizontalLayoutGroup>().spacing = 300; } else if (chain.GetComponent <VerticalLayoutGroup>()) { chain.GetComponent <VerticalLayoutGroup>().spacing = 300; } foreach (Elective e in electives) { GameObject chainLink = Instantiate(treeColumn); chainLink.transform.SetParent(chain.transform, false); chain.chainLinks.Add(chainLink); if (chainLink.GetComponent <VerticalLayoutGroup>()) { chainLink.GetComponent <VerticalLayoutGroup>().spacing = 50; } else if (chainLink.GetComponent <HorizontalLayoutGroup>()) { chainLink.GetComponent <HorizontalLayoutGroup>().spacing = 50; } for (int i = 0; i < e.count; i++) { ElectiveNode eNode = Instantiate(electivePrefab); electiveNodes.Add(eNode); eNode.SetCriteria(e); //eNode.transform.SetParent(columns[0].transform, false); //columns[0].GetComponent<VerticalLayoutGroup>().spacing += eNode.rect.sizeDelta.y * 1.5f; eNode.transform.SetParent(chainLink.transform, false); } } }
// when adding courses, if they are the first in their column / row, make a layout group // can achieve ideal column / row setup? // -> add chain link when columnID = 0, if the course unlocks Vector2Int AddCourseNode(Course course, Vector2Int gridPos) { CourseNode cn = Instantiate(courseNode); cn.SetCourse(course); cn.columnID = gridPos.x; if (gridPos.x == 0) { //make a new chain CourseChain chain = Instantiate(treeRow).AddComponent <CourseChain>(); chain.head = cn; chain.transform.SetParent(content, false); chains.Add(chain); cn.rowID = chains.Count - 1; GameObject chainLink = Instantiate(treeColumn); chainLink.transform.SetParent(chain.transform, false); chains[chains.Count - 1].chainLinks.Add(chainLink); cn.transform.SetParent(chains[chains.Count - 1].chainLinks[0].transform, false); } else { cn.rowID = gridPos.y; //parent node to chain[gridPos.y].getchild(gridPos.x) while (gridPos.x >= chains[gridPos.y].chainLinks.Count) { GameObject chainLink = Instantiate(treeColumn); chainLink.transform.SetParent(chains[gridPos.y].transform, false); chains[gridPos.y].chainLinks.Add(chainLink); } cn.transform.SetParent(chains[gridPos.y].chainLinks[gridPos.x].transform, false); if (chains[gridPos.y].GetComponent <HorizontalLayoutGroup>()) { chains[gridPos.y].GetComponent <HorizontalLayoutGroup>().spacing += cn.rect.sizeDelta.x; } else if (chains[gridPos.y].GetComponent <VerticalLayoutGroup>()) { chains[gridPos.y].GetComponent <VerticalLayoutGroup>().spacing += cn.rect.sizeDelta.x; } if (chains[gridPos.y].chainLinks[gridPos.x].GetComponent <VerticalLayoutGroup>()) { chains[gridPos.y].chainLinks[gridPos.x].GetComponent <VerticalLayoutGroup>().spacing += cn.rect.sizeDelta.y; } else if (chains[gridPos.y].chainLinks[gridPos.x].GetComponent <HorizontalLayoutGroup>()) { chains[gridPos.y].chainLinks[gridPos.x].GetComponent <HorizontalLayoutGroup>().spacing += cn.rect.sizeDelta.y; } } nodes.Add(cn); currentCourses.Add(course); if (cn.course.prereqs.Count > 0) { //look for prereq and join their row List <Course> done = new List <Course>(); foreach (Prereq prereq in cn.course.prereqs) { foreach (Course c in prereq.equivalent) { bool skip = false; foreach (CourseNode node in nodes) { foreach (CourseNode checkEq in node.equivalent) { if (done.Contains(checkEq.course)) { skip = true; break; } } if (skip) { break; } if (node.course == c) { done.Add(c); if (node.equivalent.Count > 0) { UILineRenderer edge = DrawLine(node.rect.parent.GetComponent <RectTransform>(), cn.rect); cn.backEdge.Add(edge); node.rect.parent.GetComponent <OneOfNode>().forwardEdge.Add(edge); } else { UILineRenderer edge = DrawLine(node.rect, cn.rect); cn.backEdge.Add(edge); node.forwardEdge.Add(edge); } break; } } } } } return(new Vector2Int(cn.columnID, cn.rowID)); }
public void ProcessOneOfs(List <Prereq> oneOfs) { foreach (Prereq o in oneOfs) { OneOfNode oNode = Instantiate(oneOfPrefab); List <CourseNode> prereqNodes = new List <CourseNode>(); int colID = 0; List <int> rowID = new List <int>(); foreach (Course c in o.equivalent) { currentCourses.Add(c); oNode.AddCourse(c); /*int pId = ResolvePrereqs(c); * if (pId + 1 > colID) * colID = pId + 1;*/ Vector2Int gridPos = vResolvePrereqs(c); //if (gridPos.x >= 0) // AddCourseNode(c, gridPos); foreach (CourseNode cn in nodes) { foreach (Prereq cp in c.prereqs) { foreach (Course cpc in cp.equivalent) { bool skip = false; foreach (CourseNode checkNode in prereqNodes) { foreach (CourseNode checkEq in checkNode.equivalent) { if (checkEq.course == cpc) { skip = true; break; } } if (skip) { break; } } if (skip) { continue; } if (cpc == cn.course && !prereqNodes.Contains(cn)) { if (cn.columnID + 1 > colID) { colID = cn.columnID + 1; } rowID.Add(cn.rowID); prereqNodes.Add(cn); } } } } } /* * if (colID >= columns.Count) * AddColumn(colID - columns.Count + 1); * * oNode.rect.SetParent(columns[colID].transform, false); */ int row = 0; if (rowID.Count > 0) { int[] rowMode = new int[rowID.Count]; for (int i = 0; i < rowID.Count; i++) { for (int j = 0; j < rowID.Count; j++) { if (rowID[i] == rowID[j]) { rowMode[i]++; } } } row = Mathf.Max(rowMode); for (int i = 0; i < rowMode.Length; i++) { if (rowMode[i] == row) { row = i; } } row = rowID[row]; } if (colID == 0) { //make a new chain CourseChain chain = Instantiate(treeRow).AddComponent <CourseChain>(); chain.head = oNode.courses[0]; chain.transform.SetParent(content, false); chains.Add(chain); oNode.rowID = chains.Count - 1; GameObject chainLink = Instantiate(treeColumn); chainLink.transform.SetParent(chain.transform, false); chains[chains.Count - 1].chainLinks.Add(chainLink); oNode.transform.SetParent(chains[chains.Count - 1].chainLinks[0].transform, false); } else { oNode.rowID = row; //parent node to chain[gridPos.y].getchild(gridPos.x) while (colID >= chains[row].chainLinks.Count) { GameObject chainLink = Instantiate(treeColumn); chainLink.transform.SetParent(chains[row].transform, false); chains[row].chainLinks.Add(chainLink); } oNode.transform.SetParent(chains[row].chainLinks[colID].transform, false); if (chains[row].GetComponent <HorizontalLayoutGroup>()) { chains[row].GetComponent <HorizontalLayoutGroup>().spacing += oNode.rect.sizeDelta.x; } else if (chains[row].GetComponent <VerticalLayoutGroup>()) { chains[row].GetComponent <VerticalLayoutGroup>().spacing += oNode.rect.sizeDelta.x; } if (chains[row].chainLinks[colID].GetComponent <VerticalLayoutGroup>()) { chains[row].chainLinks[colID].GetComponent <VerticalLayoutGroup>().spacing += oNode.rect.sizeDelta.y; } else if (chains[row].chainLinks[colID].GetComponent <HorizontalLayoutGroup>()) { chains[row].chainLinks[colID].GetComponent <HorizontalLayoutGroup>().spacing += oNode.rect.sizeDelta.y; } } oNode.columnID = colID; foreach (CourseNode cn in oNode.courses) { nodes.Add(cn); foreach (CourseNode ocn in oNode.courses) { if (ocn != cn) { ocn.equivalent.Add(cn); } } } foreach (CourseNode cn in prereqNodes) { if (cn.equivalent.Count > 0) { oNode.backEdge.Add(DrawLine(oNode.rect, cn.rect.parent.GetComponent <RectTransform>())); } else { oNode.backEdge.Add(DrawLine(oNode.rect, cn.rect)); } } //columns[colID].GetComponent<VerticalLayoutGroup>().spacing += 32 * o.equivalent.Count; } }