public void SetCourse(Course c)
    {
        course = Instantiate(DegreeTree.instance.courseNode);
        course.SetCourse(c);

        DegreeTree.instance.currentCourses.Add(c);

        course.transform.SetParent(assignedContainer, false);
        removeCourseButton.interactable = true;
    }
    public void AddCourse(Course course)
    {
        CourseNode cn = Instantiate(DegreeTree.instance.courseNode);

        cn.transform.SetParent(rect, false);

        cn.SetCourse(course);
        courses.Add(cn);

        Toggle t = Instantiate(togglePrefab);

        t.transform.SetParent(cn.transform, false);
        t.transform.position += (Vector3)toggleOffset;
        t.group = GetComponent <ToggleGroup>();
    }
Example #3
0
    void AddCourseNode(Course course, int columnID)
    {
        if (columnID >= columns.Count)
        {
            AddColumn(columnID - columns.Count + 1);
        }

        CourseNode cn = Instantiate(courseNode);

        cn.SetCourse(course);

        cn.rowID = columns[columnID].transform.childCount;
        cn.transform.SetParent(columns[columnID].transform, false);

        columns[columnID].GetComponent <VerticalLayoutGroup>().spacing += cn.rect.sizeDelta.y * 1.5f;

        cn.column   = columns[columnID].GetComponent <RectTransform>();
        cn.columnID = columnID;

        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;
                        }
                    }
                }
            }
        }
        else
        {
            //start a row if we are the only prereq for a course, and a row doesn't already exist for that req chain
        }
    }
Example #4
0
    // 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));
    }