void CalculateXSpace(Dictionary <int, TaskBundle> taskBundle, TaskPositionHelper taskHelper) { var data = taskHelper.Bundle; // calculate space of this task. // based on the children count. float childNum = 0; var taskChild = taskBundle.GetEnumerator(); while (taskChild.MoveNext()) { var dataChild = taskChild.Current.Value; if (dataChild != data && dataChild.Relation.ParentID == data.Data.TaskID) { ++childNum; } } if (childNum < 2) // child number 0 and 1 is treated as 0 (size 1) { childNum = 0; } taskHelper.XSpace = childNum + 1; }
void CalculateParentDepthTilParent(Dictionary <int, TaskPositionHelper> taskCalculaor , TaskPositionHelper helper, int tempDepth) { var tempTask = helper; var bottomDepth = tempDepth + 1; while (0 != tempTask.Bundle.Relation.ParentID) { if (taskCalculaor.ContainsKey(tempTask.Bundle.Relation.ParentID)) { var parent = taskCalculaor[tempTask.Bundle.Relation.ParentID]; if (tempDepth - 1 >= parent.DepthToRoot) { parent.DepthToRoot = tempDepth - 1; parent.ParentDepth = bottomDepth - parent.DepthToRoot; } --tempDepth; tempTask = parent; } else { break; } } }
void SetLocalPositionInArray(List <int> row, float yPos, out float maxYSpace) { maxYSpace = 0.0f; float tempX = 0; foreach (var taskID in row) { // calculate the size of each task TaskBundle task = m_TaskData[taskID]; TaskPositionHelper calculator = m_TaskCalculator[taskID]; TaskVisualObj visual = TryFindTaskVisual(taskID); if (null != visual && !calculator.IsSetPosition) { visual.m_3DObj.transform.localPosition = new Vector3(tempX, yPos, 0); } if (calculator.YSpace > maxYSpace) { maxYSpace = calculator.YSpace; } tempX += calculator.XSpace; } }
void SetParentAndLocalPositionInArray(Dictionary <int, TaskBundle> tasks, Dictionary <int, TaskPositionHelper> helpers, List <int> row) { float tempX = 0; foreach (var taskID in row) { // calculate the size of each task TaskBundle task = tasks[taskID]; TaskPositionHelper calculator = helpers[taskID]; TaskVisualObj visual = TryFindTaskVisual(taskID); TaskVisualObj visualParent = TryFindTaskVisual(task.Relation.ParentID); if (null != visual && null != visualParent) { visual.m_3DObj.transform.SetParent(visualParent.m_3DObj.transform); if (!calculator.IsSetPosition) { visual.m_3DObj.transform.localPosition = new Vector3(tempX, 0.7f, 1); } // Debug.LogWarning("visual.m_3DObj.transform.localPosition" + visual.m_3DObj.transform.localPosition ); } tempX += calculator.XSpace; } }
void AddTaskCalculatorFromTaskBundle(TaskBundle bundle) { TaskPositionHelper helper = InsertTaskPositionHelper(bundle); if (null != helper) { helper.DepthToRoot = FindDepthToRootByThisNode(m_TaskCalculator, bundle.Data.TaskID); CalculateParentDepthTilParent(m_TaskCalculator, helper, helper.DepthToRoot); CalculateYSpaceFromParentDepth(helper); CalculateXSpace(m_TaskData, helper); helper.IsSetPosition = (helper.Bundle.Visual.PositionStr != string.Empty); CheckAndAssignRowIndex(m_TaskCalculator, helper); List <int> sortingArray = new List <int>(); if (0 != bundle.Relation.ParentID) { // sor sortingArray = CreateSortingArrayForParentIDSet(m_TaskData, bundle.Relation.ParentID); SetParentAndLocalPositionInArray(m_TaskData, m_TaskCalculator, sortingArray); } else { Debug.Log("bundle.Visual.PositionStr=" + bundle.Visual.PositionStr); if (bundle.Visual.PositionStr != string.Empty) { TaskVisualObj visual = TryFindTaskVisual(bundle.Data.TaskID); if (null != visual) { SetTaskVisual3DFromBundle(visual.m_3DObj, bundle); } } else { bool addRowMaxY = false; sortingArray = CreateSortingArrayForEachRowIndex(m_TaskData, m_TaskCalculator, helper.RowIndex); if (!m_RowToPosY.ContainsKey(helper.RowIndex)) { addRowMaxY = true; m_RowToPosY.Add(helper.RowIndex, m_RowMaxYNow); } float maxYSpace = 0; SetLocalPositionInArray(sortingArray, m_RowToPosY[helper.RowIndex], out maxYSpace); if (addRowMaxY) { m_RowMaxYNow += maxYSpace; } } } } }
void CheckAndAssignRowIndex(Dictionary <int, TaskPositionHelper> taskHelperVec, TaskPositionHelper helper) { var data = helper.Bundle; { int rowIndex = CalculateRowIndex(data.Data.Assignee); // Debug.LogWarning("data.Data.Assignee="+data.Data.Assignee+" : rowIndex=" +rowIndex); helper.RowIndex = rowIndex; if (-1 == m_RowIndiceSet.IndexOf(rowIndex)) { m_RowIndiceSet.Add(rowIndex); } } }
int FindDepthToRootByThisNode(Dictionary <int, TaskPositionHelper> taskCalculatorMap, int id) { int ret = 0; TaskPositionHelper thisTask = taskCalculatorMap[id]; while (0 != thisTask.Bundle.Relation.ParentID && taskCalculatorMap.ContainsKey(thisTask.Bundle.Relation.ParentID)) { thisTask = taskCalculatorMap[thisTask.Bundle.Relation.ParentID]; ++ret; } return(ret); }
void CalculateYSpaceFromParentDepth(TaskPositionHelper helper) { helper.YSpace = helper.ParentDepth + 1; }