public Rect JobRect(TodoItem item, float y) { Rect rect = new Rect(); rect.x = (float)TimeStamp.DurationInMillis(item.startTime, startTime) * zoomFactor + xOffset; rect.width = (float)item.Duration() * zoomFactor; rect.height = 3 * height + 2 * separator + 2 * padding; rect.y = y; return(rect); }
private void WorkerStatusGUI() { EditorGUILayout.BeginVertical(); zoomFactor = EditorGUILayout.Slider("Zoom", zoomFactor, 0.000001f, 0.25f); autoScroll = EditorGUILayout.ToggleLeft("AutoScroll", autoScroll); #region StatusBar // Count number of Job-Todos int todoCount = 0; foreach (StatusUpdateMessage item in SimpleClient.jobStatus.Values) { foreach (TodoItem cildItem in item.childDict.Values) { foreach (TodoItem childTodo in cildItem.childDict.Values) { todoCount++; } todoCount++; } todoCount++; } // Calculate %-Step float step; if (SimpleClient.jobStatus.Values.Count > 0) { step = 1f / todoCount; } else { step = 0; } // Determine how many Job-Todos have been done float complete = 0; foreach (StatusUpdateMessage item in SimpleClient.jobStatus.Values) { foreach (TodoItem cildItem in item.childDict.Values) { foreach (TodoItem childTodo in cildItem.childDict.Values) { if (childTodo.status == Status.DONE) { complete += step; } } if (cildItem.status == Status.DONE) { complete += step; } } if (item.status == Status.DONE) { complete += step; } } EditorGUILayout.LabelField("", GUILayout.Height(20)); EditorGUI.ProgressBar(new Rect(0, 90, this.position.width - 200, 20), complete, (int)(complete * 100) + " % "); #endregion // Statusbar #region Timer string timer; if (stopTime == null) { timer = startTime != null?startTime.Duration() : "00:00:00.000"; } else { timer = TimeStamp.Duration(TimeStamp.Duration(startTime, stopTime)); } if (timerFontStyle == null) { timerFontStyle.font = (Font)Resources.Load("digitalmono"); timerFontStyle.fontSize = 34; } EditorGUI.LabelField(new Rect(this.position.width - 190, 85, 180, 20), timer, timerFontStyle); #endregion // Timer EditorGUILayout.EndVertical(); GUILayout.Space(10f); //Rect lastRect = GUILayoutUtility.GetLastRect(); //Debug.Log(lastRect); float panelOffset = 120; float autoScrollPosition = this.position.width - GoldenRatio.LongSideOf(this.position.width); float panelWidth = this.position.width - border; if (startTime != null) { panelWidth = Mathf.Max((float)TimeStamp.DurationInMillis(startTime, TimeStamp.Now()) * zoomFactor + autoScrollPosition, this.position.width - border); } if (stopTime != null) { panelWidth = Mathf.Min((float)TimeStamp.DurationInMillis(startTime, stopTime) * zoomFactor + autoScrollPosition, panelWidth); } int jobCount = SimpleClient.jobStatus.Values.Count; float panelHeight = jobCount * (4 * height + 4 * separator + 2 * padding) + yOffset; using (EditorGUILayout.ScrollViewScope scrollView = new EditorGUILayout.ScrollViewScope(scrollPos, false, false, GUILayout.Width(this.position.width), GUILayout.Height(this.position.height - panelOffset))) { scrollPos = scrollView.scrollPosition; EditorGUILayout.LabelField("", darkgrey, GUILayout.Width(panelWidth), GUILayout.Height(panelHeight)); if (autoScroll) { scrollPos.x = Mathf.Infinity; } float now = xOffset; if (startTime != null) { now = (float)TimeStamp.DurationInMillis(startTime, TimeStamp.Now()) * zoomFactor + xOffset; } if (generateLocal) { float y = 0f; y += yOffset; foreach (StatusUpdateMessage item in SimpleClient.jobStatus.Values) { y += separator; TodoItem worker = item.Get(Job.Worker); DrawJobItemBar(item, y); y += padding; y += height + separator; DrawTodoItemBar(worker, y); foreach (string todo in worker.childTodos) { DrawTodoItemBar(worker.childDict[todo], y); } y += height; y += padding; y += separator; } } else { float y = 0f; y += yOffset; foreach (StatusUpdateMessage item in SimpleClient.jobStatus.Values) { y += separator; TodoItem master = item.Get(Job.Master); TodoItem transfer = item.Get(Job.Transfer); TodoItem worker = item.Get(Job.Worker); DrawJobItemBar(item, y); y += padding; DrawTodoItemBar(master, y); foreach (string todo in master.childTodos) { DrawTodoItemBar(master.childDict[todo], y); } y += height + separator; foreach (string todo in transfer.childTodos) { DrawTodoItemBar(transfer.childDict[todo], y); } y += height + separator; DrawTodoItemBar(worker, y); foreach (string todo in worker.childTodos) { DrawTodoItemBar(worker.childDict[todo], y); } y += height; y += padding; y += separator; } } if (stopTime == null) { CustomGUIUtils.DrawBox(new Rect(now, 0, 1, panelHeight), Color.black); } #region Draw Time indicators if (1000 * zoomFactor > 20) { for (float x = 0; x < panelWidth; x += (1000 * zoomFactor)) { CustomGUIUtils.DrawBox(new Rect(x, 0, 1, panelHeight), Color.grey); } } if (15000 * zoomFactor > 20) { for (float x = 0; x < panelWidth; x += (15000 * zoomFactor)) { CustomGUIUtils.DrawBox(new Rect(x, 0, 1, panelHeight), XKCDColors.LightRed); } } for (float x = 0; x < panelWidth; x += (60000 * zoomFactor)) { CustomGUIUtils.DrawBox(new Rect(x, 0, 1, panelHeight), Color.red); } #endregion // Draw time indicators } Repaint(); }